From accb778039a52fae8eefbada77044c527b136114 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 16 Dec 2025 12:11:49 +0200 Subject: [PATCH] feat(js-sdk,types,medusa): add list locales store method to JS SDK (#14314) * feat(js-sdk,types,medusa): add list locales store method to JS SDK * add missing locale parameter --- .changeset/happy-jobs-hear.md | 7 +++++ packages/core/js-sdk/src/store/index.ts | 29 +++++++++++++++++++ packages/core/types/src/http/locale/index.ts | 1 + .../types/src/http/locale/store/entities.ts | 3 ++ .../core/types/src/http/locale/store/index.ts | 2 ++ .../types/src/http/locale/store/responses.ts | 5 ++++ .../types/src/http/order/admin/payload.ts | 6 ++++ .../medusa/src/api/store/locales/route.ts | 6 +++- 8 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .changeset/happy-jobs-hear.md create mode 100644 packages/core/types/src/http/locale/store/entities.ts create mode 100644 packages/core/types/src/http/locale/store/index.ts create mode 100644 packages/core/types/src/http/locale/store/responses.ts diff --git a/.changeset/happy-jobs-hear.md b/.changeset/happy-jobs-hear.md new file mode 100644 index 0000000000..48ec4ce4f7 --- /dev/null +++ b/.changeset/happy-jobs-hear.md @@ -0,0 +1,7 @@ +--- +"@medusajs/js-sdk": patch +"@medusajs/types": patch +"@medusajs/medusa": patch +--- + +feat(js-sdk,types,medusa): add list locales store method to JS SDK diff --git a/packages/core/js-sdk/src/store/index.ts b/packages/core/js-sdk/src/store/index.ts index f1842f9b6f..367f75cbdd 100644 --- a/packages/core/js-sdk/src/store/index.ts +++ b/packages/core/js-sdk/src/store/index.ts @@ -1654,4 +1654,33 @@ export class Store { ) }, } + + /** + * @tags locale + */ + public locale = { + /** + * This method retrieves the list of supported locales in the store. It sends a request to the + * [List Locales](https://docs.medusajs.com/api/store#locales_getlocales) API route. + * + * @param headers - Headers to pass in the request. + * @returns The list of supported locales. + * + * @example + * sdk.store.locale.list() + * .then(({ locales }) => { + * console.log(locales) + * }) + */ + list: async ( + headers?: ClientHeaders + ) => { + return this.client.fetch( + `/store/locales`, + { + headers, + } + ) + }, + } } diff --git a/packages/core/types/src/http/locale/index.ts b/packages/core/types/src/http/locale/index.ts index 1b64bd005a..b80569ce53 100644 --- a/packages/core/types/src/http/locale/index.ts +++ b/packages/core/types/src/http/locale/index.ts @@ -1,2 +1,3 @@ export * from "./admin" +export * from "./store" export * from "./common" diff --git a/packages/core/types/src/http/locale/store/entities.ts b/packages/core/types/src/http/locale/store/entities.ts new file mode 100644 index 0000000000..cc15cde0a1 --- /dev/null +++ b/packages/core/types/src/http/locale/store/entities.ts @@ -0,0 +1,3 @@ +import { BaseLocale } from "../common"; + +export interface StoreLocale extends Pick {} \ No newline at end of file diff --git a/packages/core/types/src/http/locale/store/index.ts b/packages/core/types/src/http/locale/store/index.ts new file mode 100644 index 0000000000..57fa23181b --- /dev/null +++ b/packages/core/types/src/http/locale/store/index.ts @@ -0,0 +1,2 @@ +export * from "./entities" +export * from "./responses" \ No newline at end of file diff --git a/packages/core/types/src/http/locale/store/responses.ts b/packages/core/types/src/http/locale/store/responses.ts new file mode 100644 index 0000000000..288b4bf2e4 --- /dev/null +++ b/packages/core/types/src/http/locale/store/responses.ts @@ -0,0 +1,5 @@ +import { StoreLocale } from "./entities"; + +export interface StoreLocaleListResponse { + locales: StoreLocale[] +} \ No newline at end of file diff --git a/packages/core/types/src/http/order/admin/payload.ts b/packages/core/types/src/http/order/admin/payload.ts index 9f60f9a851..68f141e0af 100644 --- a/packages/core/types/src/http/order/admin/payload.ts +++ b/packages/core/types/src/http/order/admin/payload.ts @@ -11,6 +11,12 @@ export interface AdminUpdateOrder { * The order's billing address. */ billing_address?: OrderAddress + /** + * The order's locale code. Items in the + * order will be translated to the given locale, + * if translations are available. + */ + locale?: string | null /** * The order's metadata. */ diff --git a/packages/medusa/src/api/store/locales/route.ts b/packages/medusa/src/api/store/locales/route.ts index 715363de6d..deb5e8e6c7 100644 --- a/packages/medusa/src/api/store/locales/route.ts +++ b/packages/medusa/src/api/store/locales/route.ts @@ -1,7 +1,11 @@ import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" import { ContainerRegistrationKeys } from "@medusajs/framework/utils" +import { HttpTypes } from "@medusajs/framework/types" -export const GET = async (req: MedusaRequest, res: MedusaResponse) => { +export const GET = async ( + req: MedusaRequest, + res: MedusaResponse +) => { const query = req.scope.resolve(ContainerRegistrationKeys.QUERY) const {