1 import { HttpTypes } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class Currency {
6 /**
7 * @ignore
8 */
9 private client: Client
10 /**
11 * @ignore
12 */
13 constructor(client: Client) {
14 this.client = client
15 }
16
17 /**
18 * This method retrieves a paginated list of currencies. It sends a request to the
19 * [List Currencies](https://docs.medusajs.com/api/admin/currencies/list-currencies)
20 * API route.
21 *
22 * @param query - Filters and pagination configurations.
23 * @param headers - Headers to pass in the request.
24 * @returns The paginated list of currencies.
25 *
26 * @example
27 * To retrieve the list of currencies:
28 *
29 * ```ts
30 * sdk.admin.currency.list()
31 * .then(({ currencies, count, limit, offset }) => {
32 * console.log(currencies)
33 * })
34 * ```
35 *
36 * To configure the pagination, pass the `limit` and `offset` query parameters.
37 *
38 * For example, to retrieve only 10 items and skip 10 items:
39 *
40 * ```ts
41 * sdk.admin.currency.list({
42 * limit: 10,
43 * offset: 10
44 * })
45 * .then(({ currencies, count, limit, offset }) => {
46 * console.log(currencies)
47 * })
48 * ```
49 *
50 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
51 * in each currency:
52 *
53 * ```ts
54 * sdk.admin.currency.list({
55 * fields: "code,symbol"
56 * })
57 * .then(({ currencies, count, limit, offset }) => {
58 * console.log(currencies)
59 * })
60 * ```
61 *
62 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
63 */
64 async list(
65 query?: HttpTypes.AdminCurrencyListParams,
66 headers?: ClientHeaders
67 ) {
68 return this.client.fetch<HttpTypes.AdminCurrencyListResponse>(
69 `/admin/currencies`,
70 {
71 headers,
72 query,
73 }
74 )
75 }
76
77 /**
78 * This method retrieves a currency by its code. It sends a request to the
79 * [Get Currency](https://docs.medusajs.com/api/admin/currencies/get-a-currency) API route.
80 *
81 * @param code - The currency's code.
82 * @param query - Configure the fields to retrieve in the currency.
83 * @param headers - Headers to pass in the request
84 * @returns The currency's details.
85 *
86 * @example
87 * To retrieve a currency by its code:
88 *
89 * ```ts
90 * sdk.admin.currency.retrieve("usd")
91 * .then(({ currency }) => {
92 * console.log(currency)
93 * })
94 * ```
95 *
96 * To specify the fields and relations to retrieve:
97 *
98 * ```ts
99 * sdk.admin.currency.retrieve("usd", {
100 * fields: "code,symbol"
101 * })
102 * .then(({ currency }) => {
103 * console.log(currency)
104 * })
105 * ```
106 *
107 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
108 */
109 async retrieve(
110 code: string,
111 query?: HttpTypes.AdminCurrencyParams,
112 headers?: ClientHeaders
113 ) {
114 return this.client.fetch<HttpTypes.AdminCurrencyResponse>(
115 `/admin/currencies/${code}`,
116 {
117 headers,
118 query,
119 }
120 )
121 }
122 }