1 import { HttpTypes } from "@medusajs/types"
2 import { Client } from "../client.js"
3 import { ClientHeaders } from "../types.js"
4
5 export class Locale {
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 locales. It sends a request to the
19 * [List Locales](https://docs.medusajs.com/api/admin/locales/list-locales)
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 locales.
25 *
26 * @example
27 * To retrieve the list of locales:
28 *
29 * ```ts
30 * sdk.admin.locale.list()
31 * .then(({ locales, count, limit, offset }) => {
32 * console.log(locales)
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.locale.list({
42 * limit: 10,
43 * offset: 10
44 * })
45 * .then(({ locales, count, limit, offset }) => {
46 * console.log(locales)
47 * })
48 * ```
49 *
50 * Using the `fields` query parameter, you can specify the fields and relations to retrieve
51 * in each locale:
52 *
53 * ```ts
54 * sdk.admin.locale.list({
55 * fields: "code,name"
56 * })
57 * .then(({ locales, count, limit, offset }) => {
58 * console.log(locales)
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(query?: HttpTypes.AdminLocaleListParams, headers?: ClientHeaders) {
65 return this.client.fetch<HttpTypes.AdminLocaleListResponse>(
66 `/admin/locales`,
67 {
68 headers,
69 query,
70 }
71 )
72 }
73
74 /**
75 * This method retrieves a locale by its code. It sends a request to the
76 * [Get Locale](https://docs.medusajs.com/api/admin/locales/get-locale) API route.
77 *
78 * @param code - The locale's code in BCP 47 format.
79 * @param query - Configure the fields to retrieve in the locale.
80 * @param headers - Headers to pass in the request
81 * @returns The locale's details.
82 *
83 * @example
84 * To retrieve a locale by its code:
85 *
86 * ```ts
87 * sdk.admin.locale.retrieve("en-US")
88 * .then(({ locale }) => {
89 * console.log(locale)
90 * })
91 * ```
92 *
93 * To specify the fields and relations to retrieve:
94 *
95 * ```ts
96 * sdk.admin.locale.retrieve("en-US", {
97 * fields: "code,name"
98 * })
99 * .then(({ locale }) => {
100 * console.log(locale)
101 * })
102 * ```
103 *
104 * Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store/select-fields-and-relations).
105 */
106 async retrieve(
107 code: string,
108 query?: HttpTypes.AdminLocaleParams,
109 headers?: ClientHeaders
110 ) {
111 return this.client.fetch<HttpTypes.AdminLocaleResponse>(
112 `/admin/locales/${code}`,
113 {
114 headers,
115 query,
116 }
117 )
118 }
119 }