Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Update SDK and next packages
Damian Legawiec6e894986ed14
diff --git a/packages/next/.changeset/add-markets-api.md b/packages/next/.changeset/add-markets-api.mdnew file mode 100644index 0000000000..32a357e884--- /dev/null+++ b/packages/next/.changeset/add-markets-api.md@@ -0,0 +1,9 @@+---+"@spree/next": patch+---++Add Markets data functions and update country types++- Add `listMarkets()`, `getMarket(id)`, `resolveMarket(country)`, `listMarketCountries(marketId)`, `getMarketCountry(marketId, iso)` data functions+- Export `StoreMarket` type+- **Breaking:** `StoreCountry` no longer includes `currency`, `default_locale`, `supported_locales` — use the markets API or `?include=market` on countriesdiff --git a/packages/next/src/data/countries.ts b/packages/next/src/data/countries.tsindex 8754dcde8b..15d2926b61 100644--- a/packages/next/src/data/countries.ts+++ b/packages/next/src/data/countries.ts@@ -5,8 +5,7 @@ import type { SpreeNextOptions } from '../types';/*** List countries available in the store.- * Each country includes currency and default_locale derived from its market.- * Locale/country are auto-read from cookies when not provided.+ * Use ?include=market to include market details (currency, locale, tax_inclusive).*/export async function listCountries(options?: SpreeNextOptions@@ -18,8 +17,7 @@ export async function listCountries(/*** Get a country by ISO code.* @param iso - ISO 3166-1 alpha-2 code (e.g., "US", "DE")- * @param params - Optional params (e.g., { include: 'states' } for address forms)- * Locale/country are auto-read from cookies when not provided.+ * @param params - Optional params (e.g., { include: 'states' } or { include: 'market' })*/export async function getCountry(iso: string,diff --git a/packages/next/src/data/markets.ts b/packages/next/src/data/markets.tsnew file mode 100644index 0000000000..e55c091736--- /dev/null+++ b/packages/next/src/data/markets.ts@@ -0,0 +1,66 @@+import type { StoreMarket, StoreCountry } from '@spree/sdk';+import { getClient } from '../config';+import { getLocaleOptions } from '../locale';+import type { SpreeNextOptions } from '../types';++/**+ * List all markets for the current store.+ * Each market includes currency, locales, tax_inclusive flag, and countries.+ */+export async function listMarkets(+ options?: SpreeNextOptions+): Promise<{ data: StoreMarket[] }> {+ const resolved = options ?? await getLocaleOptions();+ return getClient().store.markets.list(resolved);+}++/**+ * Get a market by prefixed ID.+ * @param id - Market prefixed ID (e.g., "mkt_k5nR8xLq")+ */+export async function getMarket(+ id: string,+ options?: SpreeNextOptions+): Promise<StoreMarket> {+ const resolved = options ?? await getLocaleOptions();+ return getClient().store.markets.get(id, resolved);+}++/**+ * Resolve which market applies for a given country.+ * @param country - ISO 3166-1 alpha-2 code (e.g., "DE", "US")+ */+export async function resolveMarket(+ country: string,+ options?: SpreeNextOptions+): Promise<StoreMarket> {+ const resolved = options ?? await getLocaleOptions();+ return getClient().store.markets.resolve(country, resolved);+}++/**+ * List countries belonging to a market.+ * @param marketId - Market prefixed ID+ */+export async function listMarketCountries(+ marketId: string,+ options?: SpreeNextOptions+): Promise<{ data: StoreCountry[] }> {+ const resolved = options ?? await getLocaleOptions();+ return getClient().store.markets.countries.list(marketId, resolved);+}++/**+ * Get a country by ISO code within a market.+ * @param marketId - Market prefixed ID+ * @param iso - Country ISO code (e.g., "DE")+ */+export async function getMarketCountry(+ marketId: string,+ iso: string,+ params?: { include?: string },+ options?: SpreeNextOptions+): Promise<StoreCountry> {+ const resolved = options ?? await getLocaleOptions();+ return getClient().store.markets.countries.get(marketId, iso, params, resolved);+}diff --git a/packages/next/src/index.ts b/packages/next/src/index.tsindex 581b90b427..65debee48f 100644--- a/packages/next/src/index.ts+++ b/packages/next/src/index.ts@@ -10,6 +10,7 @@ export { getStore } from './data/store';export { listCountries, getCountry } from './data/countries';export { listCurrencies } from './data/currencies';export { listLocales } from './data/locales';+export { listMarkets, getMarket, resolveMarket, listMarketCountries, getMarketCountry } from './data/markets';// Server actions (mutations + auth-dependent reads)export {@@ -79,6 +80,7 @@ export type {StoreCountry,StoreCurrency,StoreLocale,+ StoreMarket,StoreStore,StoreAddress,StoreCustomer,diff --git a/packages/next/tsup.config.ts b/packages/next/tsup.config.tsindex 1226d9480e..2194baff13 100644--- a/packages/next/tsup.config.ts+++ b/packages/next/tsup.config.ts@@ -15,6 +15,7 @@ export default defineConfig(['data/countries': 'src/data/countries.ts','data/currencies': 'src/data/currencies.ts','data/locales': 'src/data/locales.ts',+ 'data/markets': 'src/data/markets.ts',},format: ['esm'],dts: true,diff --git a/packages/sdk/.changeset/add-markets-api.md b/packages/sdk/.changeset/add-markets-api.mdnew file mode 100644index 0000000000..57adc40a4e--- /dev/null+++ b/packages/sdk/.changeset/add-markets-api.md@@ -0,0 +1,10 @@+---+"@spree/sdk": patch+---++Add Markets API support and simplify Country type++- Add `StoreMarket` type with `id`, `name`, `currency`, `default_locale`, `supported_locales`, `tax_inclusive`, `default`, and optional `countries`+- Add `client.store.markets` with `list()`, `get(id)`, `resolve(country)`, and nested `countries.list(marketId)` / `countries.get(marketId, iso)`+- **Breaking:** Remove `currency`, `default_locale`, `supported_locales` from `StoreCountry` — these now live on `StoreMarket`. Use `?include=market` on the countries endpoint or the markets endpoint directly+- Add optional `market?: StoreMarket` field to `StoreCountry` (populated when `?include=market` is passed)diff --git a/packages/sdk/src/store-client.ts b/packages/sdk/src/store-client.tsindex e8ff3b5bd1..96c152477e 100644--- a/packages/sdk/src/store-client.ts+++ b/packages/sdk/src/store-client.ts@@ -28,6 +28,7 @@ import type {StoreCountry,StoreCurrency,StoreLocale,+ StoreMarket,StoreTaxonomy,StoreTaxon,StorePayment,@@ -254,6 +255,71 @@ export class StoreClient {this.request<{ data: StoreLocale[] }>('GET', '/locales', options),};+ // ============================================+ // Markets+ // ============================================++ readonly markets = {+ /**+ * List all markets for the current store+ */+ list: (options?: RequestOptions): Promise<{ data: StoreMarket[] }> =>+ this.request<{ data: StoreMarket[] }>('GET', '/markets', options),++ /**+ * Get a market by prefixed ID+ * @param id - Market prefixed ID (e.g., "mkt_k5nR8xLq")+ */+ get: (id: string, options?: RequestOptions): Promise<StoreMarket> =>+ this.request<StoreMarket>('GET', `/markets/${id}`, options),++ /**+ * Resolve which market applies for a given country+ * @param country - ISO 3166-1 alpha-2 code (e.g., "DE", "US")+ */+ resolve: (country: string, options?: RequestOptions): Promise<StoreMarket> =>+ this.request<StoreMarket>('GET', '/markets/resolve', {+ ...options,+ params: { country },+ }),++ /**+ * Nested resource: Countries in a market+ */+ countries: {+ /**+ * List countries belonging to a market+ * @param marketId - Market prefixed ID+ */+ list: (+ marketId: string,+ options?: RequestOptions+ ): Promise<{ data: StoreCountry[] }> =>+ this.request<{ data: StoreCountry[] }>(+ 'GET',+ `/markets/${marketId}/countries`,+ options+ ),++ /**+ * Get a country by ISO code within a market+ * @param marketId - Market prefixed ID+ * @param iso - Country ISO code (e.g., "DE")+ */+ get: (+ marketId: string,+ iso: string,+ params?: { include?: string },+ options?: RequestOptions+ ): Promise<StoreCountry> =>+ this.request<StoreCountry>(+ 'GET',+ `/markets/${marketId}/countries/${iso}`,+ { ...options, params }+ ),+ },+ };+// ============================================// Cart (convenience wrapper for current incomplete order)// ============================================diff --git a/packages/sdk/tests/markets.test.ts b/packages/sdk/tests/markets.test.tsindex 4bb147cf9f..13d671df9d 100644--- a/packages/sdk/tests/markets.test.ts+++ b/packages/sdk/tests/markets.test.ts@@ -13,8 +13,7 @@ describe('countries', () => {expect(result.data).toHaveLength(1);expect(result.data[0].iso).toBe('US');- expect(result.data[0].currency).toBe('USD');- expect(result.data[0].default_locale).toBe('en');+ expect(result.data[0].name).toBe('United States');});});@@ -22,8 +21,7 @@ describe('countries', () => {it('returns a country by ISO code', async () => {const result = await client.store.countries.get('US');expect(result.iso).toBe(fixtures.country.iso);- expect(result.currency).toBe('USD');- expect(result.default_locale).toBe('en');+ expect(result.name).toBe('United States');});});});@@ -58,3 +56,58 @@ describe('locales', () => {});});});++describe('markets', () => {+ let client: SpreeClient;+ beforeAll(() => { client = createTestClient(); });++ describe('list', () => {+ it('returns all markets', async () => {+ const result = await client.store.markets.list();++ expect(result.data).toHaveLength(1);+ expect(result.data[0].id).toBe('mkt_1');+ expect(result.data[0].name).toBe('North America');+ expect(result.data[0].currency).toBe('USD');+ expect(result.data[0].default_locale).toBe('en');+ expect(result.data[0].supported_locales).toEqual(['en', 'es']);+ expect(result.data[0].tax_inclusive).toBe(false);+ expect(result.data[0].default).toBe(true);+ expect(result.data[0].countries).toHaveLength(1);+ });+ });++ describe('get', () => {+ it('returns a market by prefixed ID', async () => {+ const result = await client.store.markets.get('mkt_1');++ expect(result.id).toBe('mkt_1');+ expect(result.name).toBe('North America');+ expect(result.currency).toBe('USD');+ });+ });++ describe('resolve', () => {+ it('resolves a market by country ISO', async () => {+ const result = await client.store.markets.resolve('US');++ expect(result.id).toBe('mkt_1');+ expect(result.currency).toBe('USD');+ });+ });++ describe('countries', () => {+ it('lists countries in a market', async () => {+ const result = await client.store.markets.countries.list('mkt_1');++ expect(result.data).toHaveLength(1);+ expect(result.data[0].iso).toBe('US');+ });++ it('gets a country in a market', async () => {+ const result = await client.store.markets.countries.get('mkt_1', 'US');++ expect(result.iso).toBe('US');+ });+ });+});diff --git a/packages/sdk/tests/mocks/handlers.ts b/packages/sdk/tests/mocks/handlers.tsindex c397256cc7..dd6e4e4e89 100644--- a/packages/sdk/tests/mocks/handlers.ts+++ b/packages/sdk/tests/mocks/handlers.ts@@ -70,9 +70,18 @@ export const fixtures = {name: 'United States',states_required: true,zipcode_required: true,+ },+ market: {+ id: 'mkt_1',+ name: 'North America',currency: 'USD',default_locale: 'en',supported_locales: ['en', 'es'],+ tax_inclusive: false,+ default: true,+ countries: [+ { iso: 'US', iso3: 'USA', name: 'United States', states_required: true, zipcode_required: true },+ ],},currency: {iso_code: 'USD',@@ -176,6 +185,27 @@ export const handlers = [HttpResponse.json({ data: [fixtures.locale] })),+ // Markets+ http.get(`${API_PREFIX}/markets`, () =>+ HttpResponse.json({ data: [fixtures.market] })+ ),++ http.get(`${API_PREFIX}/markets/resolve`, () =>+ HttpResponse.json(fixtures.market)+ ),++ http.get(`${API_PREFIX}/markets/:id/countries`, () =>+ HttpResponse.json({ data: [fixtures.country] })+ ),++ http.get(`${API_PREFIX}/markets/:id/countries/:iso`, () =>+ HttpResponse.json(fixtures.country)+ ),++ http.get(`${API_PREFIX}/markets/:id`, () =>+ HttpResponse.json(fixtures.market)+ ),+// Carthttp.get(`${API_PREFIX}/cart`, () =>HttpResponse.json({ ...fixtures.order, token: 'guest-order-token' })