@spree/next 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -8
  3. package/dist/actions/cart.d.ts +18 -4
  4. package/dist/actions/cart.js +7 -6
  5. package/dist/actions/cart.js.map +1 -1
  6. package/dist/actions/locale.d.ts +10 -0
  7. package/dist/actions/locale.js +59 -0
  8. package/dist/actions/locale.js.map +1 -0
  9. package/dist/actions/orders.d.ts +2 -2
  10. package/dist/actions/orders.js.map +1 -1
  11. package/dist/data/countries.d.ts +2 -0
  12. package/dist/data/countries.js +26 -8
  13. package/dist/data/countries.js.map +1 -1
  14. package/dist/data/currencies.d.ts +1 -0
  15. package/dist/data/currencies.js +24 -4
  16. package/dist/data/currencies.js.map +1 -1
  17. package/dist/data/locales.d.ts +1 -0
  18. package/dist/data/locales.js +24 -4
  19. package/dist/data/locales.js.map +1 -1
  20. package/dist/data/products.d.ts +5 -2
  21. package/dist/data/products.js +28 -12
  22. package/dist/data/products.js.map +1 -1
  23. package/dist/data/store.d.ts +1 -0
  24. package/dist/data/store.js +24 -4
  25. package/dist/data/store.js.map +1 -1
  26. package/dist/data/taxonomies.d.ts +2 -0
  27. package/dist/data/taxonomies.js +26 -8
  28. package/dist/data/taxonomies.js.map +1 -1
  29. package/dist/data/taxons.d.ts +6 -3
  30. package/dist/data/taxons.js +28 -12
  31. package/dist/data/taxons.js.map +1 -1
  32. package/dist/index.d.ts +31 -8
  33. package/dist/index.js +65 -60
  34. package/dist/index.js.map +1 -1
  35. package/dist/locale.d.ts +12 -0
  36. package/dist/locale.js +52 -0
  37. package/dist/locale.js.map +1 -0
  38. package/dist/middleware.d.ts +26 -0
  39. package/dist/middleware.js +28 -0
  40. package/dist/middleware.js.map +1 -0
  41. package/dist/types.d.ts +8 -0
  42. package/package.json +10 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/locales.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,YACpB,OAAA,EACkC;AAClC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,IACpC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"locales.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreLocale } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List locales supported by the store (derived from markets).\n */\nexport async function listLocales(\n options?: SpreeNextOptions\n): Promise<{ data: StoreLocale[] }> {\n return getClient().store.locales.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/locales.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;AACT;AC5CA,IAAM,sBAAA,GAAyB,eAAA;AAC/B,IAAM,qBAAA,GAAwB,cAAA;AAO9B,eAAsB,gBAAA,GAInB;AACD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,MAAM,WAAA,GAAc,MAAM,OAAA,EAAQ;AAElC,EAAA,MAAM,UAAU,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,iBAAA,IAAqB,sBAAsB,CAAA,EAAG,KAAA;AACrF,EAAA,MAAM,SAAS,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,gBAAA,IAAoB,qBAAqB,CAAA,EAAG,KAAA;AAElF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,UAAU,MAAA,CAAO,aAAA;AAAA,IACzB,OAAA,EAAS,WAAW,MAAA,CAAO;AAAA;AAAA,GAE7B;AACF;;;AClBA,eAAsB,YACpB,OAAA,EACkC;AAClC,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,OAAA,CAAQ,KAAK,QAAQ,CAAA;AAChD","file":"locales.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { StoreLocale } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List locales supported by the store (derived from markets).\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listLocales(\n options?: SpreeNextOptions\n): Promise<{ data: StoreLocale[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.locales.list(resolved);\n}\n"]}
@@ -1,18 +1,21 @@
1
- import { StoreProduct, ProductFiltersResponse, PaginatedResponse } from '@spree/sdk';
1
+ import { StoreProduct, ProductFiltersResponse, ProductListParams, PaginatedResponse } from '@spree/sdk';
2
2
  import { SpreeNextOptions } from '../types.js';
3
3
 
4
4
  /**
5
5
  * List products with optional filtering, sorting, and pagination.
6
+ * Locale/country are auto-read from cookies when not provided.
6
7
  */
7
- declare function listProducts(params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreProduct>>;
8
+ declare function listProducts(params?: ProductListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreProduct>>;
8
9
  /**
9
10
  * Get a single product by slug or ID.
11
+ * Locale/country are auto-read from cookies when not provided.
10
12
  */
11
13
  declare function getProduct(slugOrId: string, params?: {
12
14
  includes?: string;
13
15
  }, options?: SpreeNextOptions): Promise<StoreProduct>;
14
16
  /**
15
17
  * Get available product filters (price ranges, option values, etc.).
18
+ * Locale/country are auto-read from cookies when not provided.
16
19
  */
17
20
  declare function getProductFilters(params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<ProductFiltersResponse>;
18
21
 
@@ -1,8 +1,11 @@
1
1
  import { createSpreeClient } from '@spree/sdk';
2
+ import { cookies } from 'next/headers';
2
3
 
3
4
  // src/config.ts
4
5
  var _client = null;
6
+ var _config = null;
5
7
  function initSpreeNext(config) {
8
+ _config = config;
6
9
  _client = createSpreeClient({
7
10
  baseUrl: config.baseUrl,
8
11
  publishableKey: config.publishableKey
@@ -22,25 +25,38 @@ function getClient() {
22
25
  }
23
26
  return _client;
24
27
  }
28
+ function getConfig() {
29
+ if (!_config) {
30
+ getClient();
31
+ }
32
+ return _config;
33
+ }
34
+ var DEFAULT_COUNTRY_COOKIE = "spree_country";
35
+ var DEFAULT_LOCALE_COOKIE = "spree_locale";
36
+ async function getLocaleOptions() {
37
+ const config = getConfig();
38
+ const cookieStore = await cookies();
39
+ const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;
40
+ const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;
41
+ return {
42
+ locale: locale || config.defaultLocale,
43
+ country: country || config.defaultCountry
44
+ // No currency — backend resolves from country via X-Spree-Country header
45
+ };
46
+ }
25
47
 
26
48
  // src/data/products.ts
27
49
  async function listProducts(params, options) {
28
- return getClient().store.products.list(params, {
29
- locale: options?.locale,
30
- currency: options?.currency
31
- });
50
+ const resolved = options ?? await getLocaleOptions();
51
+ return getClient().store.products.list(params, resolved);
32
52
  }
33
53
  async function getProduct(slugOrId, params, options) {
34
- return getClient().store.products.get(slugOrId, params, {
35
- locale: options?.locale,
36
- currency: options?.currency
37
- });
54
+ const resolved = options ?? await getLocaleOptions();
55
+ return getClient().store.products.get(slugOrId, params, resolved);
38
56
  }
39
57
  async function getProductFilters(params, options) {
40
- return getClient().store.products.filters(params, {
41
- locale: options?.locale,
42
- currency: options?.currency
43
- });
58
+ const resolved = options ?? await getLocaleOptions();
59
+ return getClient().store.products.filters(params, resolved);
44
60
  }
45
61
 
46
62
  export { getProduct, getProductFilters, listProducts };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/products.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,YAAA,CACpB,QACA,OAAA,EAC0C;AAC1C,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,QAAA,CAAS,KAAK,MAAA,EAAQ;AAAA,IAC7C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,UAAA,CACpB,QAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,QAAA,CAAS,GAAA,CAAI,UAAU,MAAA,EAAQ;AAAA,IACtD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,iBAAA,CACpB,QACA,OAAA,EACiC;AACjC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,QAAA,CAAS,QAAQ,MAAA,EAAQ;AAAA,IAChD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"products.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreProduct, PaginatedResponse, ProductFiltersResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n */\nexport async function listProducts(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.products.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single product by slug or ID.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n return getClient().store.products.get(slugOrId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n return getClient().store.products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/products.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;AACT;AC5CA,IAAM,sBAAA,GAAyB,eAAA;AAC/B,IAAM,qBAAA,GAAwB,cAAA;AAO9B,eAAsB,gBAAA,GAInB;AACD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,MAAM,WAAA,GAAc,MAAM,OAAA,EAAQ;AAElC,EAAA,MAAM,UAAU,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,iBAAA,IAAqB,sBAAsB,CAAA,EAAG,KAAA;AACrF,EAAA,MAAM,SAAS,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,gBAAA,IAAoB,qBAAqB,CAAA,EAAG,KAAA;AAElF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,UAAU,MAAA,CAAO,aAAA;AAAA,IACzB,OAAA,EAAS,WAAW,MAAA,CAAO;AAAA;AAAA,GAE7B;AACF;;;AClBA,eAAsB,YAAA,CACpB,QACA,OAAA,EAC0C;AAC1C,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,QAAA,CAAS,IAAA,CAAK,QAAQ,QAAQ,CAAA;AACzD;AAMA,eAAsB,UAAA,CACpB,QAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAS,GAAA,CAAI,QAAA,EAAU,QAAQ,QAAQ,CAAA;AAClE;AAMA,eAAsB,iBAAA,CACpB,QACA,OAAA,EACiC;AACjC,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,QAAA,CAAS,OAAA,CAAQ,QAAQ,QAAQ,CAAA;AAC5D","file":"products.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { StoreProduct, PaginatedResponse, ProductFiltersResponse, ProductListParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listProducts(\n params?: ProductListParams,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.products.list(params, resolved);\n}\n\n/**\n * Get a single product by slug or ID.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.products.get(slugOrId, params, resolved);\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.products.filters(params, resolved);\n}\n"]}
@@ -3,6 +3,7 @@ import { SpreeNextOptions } from '../types.js';
3
3
 
4
4
  /**
5
5
  * Get the current store configuration.
6
+ * Locale/country are auto-read from cookies when not provided.
6
7
  */
7
8
  declare function getStore(options?: SpreeNextOptions): Promise<StoreStore>;
8
9
 
@@ -1,8 +1,11 @@
1
1
  import { createSpreeClient } from '@spree/sdk';
2
+ import { cookies } from 'next/headers';
2
3
 
3
4
  // src/config.ts
4
5
  var _client = null;
6
+ var _config = null;
5
7
  function initSpreeNext(config) {
8
+ _config = config;
6
9
  _client = createSpreeClient({
7
10
  baseUrl: config.baseUrl,
8
11
  publishableKey: config.publishableKey
@@ -22,13 +25,30 @@ function getClient() {
22
25
  }
23
26
  return _client;
24
27
  }
28
+ function getConfig() {
29
+ if (!_config) {
30
+ getClient();
31
+ }
32
+ return _config;
33
+ }
34
+ var DEFAULT_COUNTRY_COOKIE = "spree_country";
35
+ var DEFAULT_LOCALE_COOKIE = "spree_locale";
36
+ async function getLocaleOptions() {
37
+ const config = getConfig();
38
+ const cookieStore = await cookies();
39
+ const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;
40
+ const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;
41
+ return {
42
+ locale: locale || config.defaultLocale,
43
+ country: country || config.defaultCountry
44
+ // No currency — backend resolves from country via X-Spree-Country header
45
+ };
46
+ }
25
47
 
26
48
  // src/data/store.ts
27
49
  async function getStore(options) {
28
- return getClient().store.store.get({
29
- locale: options?.locale,
30
- currency: options?.currency
31
- });
50
+ const resolved = options ?? await getLocaleOptions();
51
+ return getClient().store.store.get(resolved);
32
52
  }
33
53
 
34
54
  export { getStore };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/store.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,SAAS,OAAA,EAAiD;AAC9E,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI;AAAA,IACjC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"store.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/store.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;AACT;AC5CA,IAAM,sBAAA,GAAyB,eAAA;AAC/B,IAAM,qBAAA,GAAwB,cAAA;AAO9B,eAAsB,gBAAA,GAInB;AACD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,MAAM,WAAA,GAAc,MAAM,OAAA,EAAQ;AAElC,EAAA,MAAM,UAAU,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,iBAAA,IAAqB,sBAAsB,CAAA,EAAG,KAAA;AACrF,EAAA,MAAM,SAAS,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,gBAAA,IAAoB,qBAAqB,CAAA,EAAG,KAAA;AAElF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,UAAU,MAAA,CAAO,aAAA;AAAA,IACzB,OAAA,EAAS,WAAW,MAAA,CAAO;AAAA;AAAA,GAE7B;AACF;;;AClBA,eAAsB,SAAS,OAAA,EAAiD;AAC9E,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,IAAI,QAAQ,CAAA;AAC7C","file":"store.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.store.get(resolved);\n}\n"]}
@@ -3,10 +3,12 @@ import { SpreeNextOptions } from '../types.js';
3
3
 
4
4
  /**
5
5
  * List taxonomies with optional filtering and pagination.
6
+ * Locale/country are auto-read from cookies when not provided.
6
7
  */
7
8
  declare function listTaxonomies(params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreTaxonomy>>;
8
9
  /**
9
10
  * Get a single taxonomy by ID.
11
+ * Locale/country are auto-read from cookies when not provided.
10
12
  */
11
13
  declare function getTaxonomy(id: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<StoreTaxonomy>;
12
14
 
@@ -1,8 +1,11 @@
1
1
  import { createSpreeClient } from '@spree/sdk';
2
+ import { cookies } from 'next/headers';
2
3
 
3
4
  // src/config.ts
4
5
  var _client = null;
6
+ var _config = null;
5
7
  function initSpreeNext(config) {
8
+ _config = config;
6
9
  _client = createSpreeClient({
7
10
  baseUrl: config.baseUrl,
8
11
  publishableKey: config.publishableKey
@@ -22,19 +25,34 @@ function getClient() {
22
25
  }
23
26
  return _client;
24
27
  }
28
+ function getConfig() {
29
+ if (!_config) {
30
+ getClient();
31
+ }
32
+ return _config;
33
+ }
34
+ var DEFAULT_COUNTRY_COOKIE = "spree_country";
35
+ var DEFAULT_LOCALE_COOKIE = "spree_locale";
36
+ async function getLocaleOptions() {
37
+ const config = getConfig();
38
+ const cookieStore = await cookies();
39
+ const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;
40
+ const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;
41
+ return {
42
+ locale: locale || config.defaultLocale,
43
+ country: country || config.defaultCountry
44
+ // No currency — backend resolves from country via X-Spree-Country header
45
+ };
46
+ }
25
47
 
26
48
  // src/data/taxonomies.ts
27
49
  async function listTaxonomies(params, options) {
28
- return getClient().store.taxonomies.list(params, {
29
- locale: options?.locale,
30
- currency: options?.currency
31
- });
50
+ const resolved = options ?? await getLocaleOptions();
51
+ return getClient().store.taxonomies.list(params, resolved);
32
52
  }
33
53
  async function getTaxonomy(id, params, options) {
34
- return getClient().store.taxonomies.get(id, params, {
35
- locale: options?.locale,
36
- currency: options?.currency
37
- });
54
+ const resolved = options ?? await getLocaleOptions();
55
+ return getClient().store.taxonomies.get(id, params, resolved);
38
56
  }
39
57
 
40
58
  export { getTaxonomy, listTaxonomies };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/taxonomies.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,cAAA,CACpB,QACA,OAAA,EAC2C;AAC3C,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,UAAA,CAAW,KAAK,MAAA,EAAQ;AAAA,IAC/C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,WAAA,CACpB,EAAA,EACA,MAAA,EACA,OAAA,EACwB;AACxB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,UAAA,CAAW,GAAA,CAAI,IAAI,MAAA,EAAQ;AAAA,IAClD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"taxonomies.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().store.taxonomies.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxonomy by ID.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n return getClient().store.taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/taxonomies.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;AACT;AC5CA,IAAM,sBAAA,GAAyB,eAAA;AAC/B,IAAM,qBAAA,GAAwB,cAAA;AAO9B,eAAsB,gBAAA,GAInB;AACD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,MAAM,WAAA,GAAc,MAAM,OAAA,EAAQ;AAElC,EAAA,MAAM,UAAU,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,iBAAA,IAAqB,sBAAsB,CAAA,EAAG,KAAA;AACrF,EAAA,MAAM,SAAS,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,gBAAA,IAAoB,qBAAqB,CAAA,EAAG,KAAA;AAElF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,UAAU,MAAA,CAAO,aAAA;AAAA,IACzB,OAAA,EAAS,WAAW,MAAA,CAAO;AAAA;AAAA,GAE7B;AACF;;;AClBA,eAAsB,cAAA,CACpB,QACA,OAAA,EAC2C;AAC3C,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,UAAA,CAAW,IAAA,CAAK,QAAQ,QAAQ,CAAA;AAC3D;AAMA,eAAsB,WAAA,CACpB,EAAA,EACA,MAAA,EACA,OAAA,EACwB;AACxB,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,WAAW,GAAA,CAAI,EAAA,EAAI,QAAQ,QAAQ,CAAA;AAC9D","file":"taxonomies.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.taxonomies.list(params, resolved);\n}\n\n/**\n * Get a single taxonomy by ID.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.taxonomies.get(id, params, resolved);\n}\n"]}
@@ -1,17 +1,20 @@
1
- import { StoreTaxon, PaginatedResponse, StoreProduct } from '@spree/sdk';
1
+ import { StoreTaxon, ProductListParams, PaginatedResponse, StoreProduct, TaxonListParams } from '@spree/sdk';
2
2
  import { SpreeNextOptions } from '../types.js';
3
3
 
4
4
  /**
5
5
  * List taxons (categories) with optional filtering and pagination.
6
+ * Locale/country are auto-read from cookies when not provided.
6
7
  */
7
- declare function listTaxons(params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreTaxon>>;
8
+ declare function listTaxons(params?: TaxonListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreTaxon>>;
8
9
  /**
9
10
  * Get a single taxon by ID or permalink.
11
+ * Locale/country are auto-read from cookies when not provided.
10
12
  */
11
13
  declare function getTaxon(idOrPermalink: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<StoreTaxon>;
12
14
  /**
13
15
  * List products within a taxon.
16
+ * Locale/country are auto-read from cookies when not provided.
14
17
  */
15
- declare function listTaxonProducts(taxonId: string, params?: Record<string, unknown>, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreProduct>>;
18
+ declare function listTaxonProducts(taxonId: string, params?: ProductListParams, options?: SpreeNextOptions): Promise<PaginatedResponse<StoreProduct>>;
16
19
 
17
20
  export { getTaxon, listTaxonProducts, listTaxons };
@@ -1,8 +1,11 @@
1
1
  import { createSpreeClient } from '@spree/sdk';
2
+ import { cookies } from 'next/headers';
2
3
 
3
4
  // src/config.ts
4
5
  var _client = null;
6
+ var _config = null;
5
7
  function initSpreeNext(config) {
8
+ _config = config;
6
9
  _client = createSpreeClient({
7
10
  baseUrl: config.baseUrl,
8
11
  publishableKey: config.publishableKey
@@ -22,25 +25,38 @@ function getClient() {
22
25
  }
23
26
  return _client;
24
27
  }
28
+ function getConfig() {
29
+ if (!_config) {
30
+ getClient();
31
+ }
32
+ return _config;
33
+ }
34
+ var DEFAULT_COUNTRY_COOKIE = "spree_country";
35
+ var DEFAULT_LOCALE_COOKIE = "spree_locale";
36
+ async function getLocaleOptions() {
37
+ const config = getConfig();
38
+ const cookieStore = await cookies();
39
+ const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;
40
+ const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;
41
+ return {
42
+ locale: locale || config.defaultLocale,
43
+ country: country || config.defaultCountry
44
+ // No currency — backend resolves from country via X-Spree-Country header
45
+ };
46
+ }
25
47
 
26
48
  // src/data/taxons.ts
27
49
  async function listTaxons(params, options) {
28
- return getClient().store.taxons.list(params, {
29
- locale: options?.locale,
30
- currency: options?.currency
31
- });
50
+ const resolved = options ?? await getLocaleOptions();
51
+ return getClient().store.taxons.list(params, resolved);
32
52
  }
33
53
  async function getTaxon(idOrPermalink, params, options) {
34
- return getClient().store.taxons.get(idOrPermalink, params, {
35
- locale: options?.locale,
36
- currency: options?.currency
37
- });
54
+ const resolved = options ?? await getLocaleOptions();
55
+ return getClient().store.taxons.get(idOrPermalink, params, resolved);
38
56
  }
39
57
  async function listTaxonProducts(taxonId, params, options) {
40
- return getClient().store.taxons.products.list(taxonId, params, {
41
- locale: options?.locale,
42
- currency: options?.currency
43
- });
58
+ const resolved = options ?? await getLocaleOptions();
59
+ return getClient().store.taxons.products.list(taxonId, params, resolved);
44
60
  }
45
61
 
46
62
  export { getTaxon, listTaxonProducts, listTaxons };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/taxons.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,UAAA,CACpB,QACA,OAAA,EACwC;AACxC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,MAAA,CAAO,KAAK,MAAA,EAAQ;AAAA,IAC3C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,QAAA,CACpB,aAAA,EACA,MAAA,EACA,OAAA,EACqB;AACrB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,MAAA,CAAO,GAAA,CAAI,eAAe,MAAA,EAAQ;AAAA,IACzD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,iBAAA,CACpB,OAAA,EACA,MAAA,EACA,OAAA,EAC0C;AAC1C,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,OAAO,QAAA,CAAS,IAAA,CAAK,SAAS,MAAA,EAAQ;AAAA,IAC7D,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"taxons.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreTaxon, StoreProduct, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n */\nexport async function listTaxons(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxon>> {\n return getClient().store.taxons.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxon by ID or permalink.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxon> {\n return getClient().store.taxons.get(idOrPermalink, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List products within a taxon.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.taxons.products.list(taxonId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/taxons.ts"],"names":[],"mappings":";;;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;AACT;AC5CA,IAAM,sBAAA,GAAyB,eAAA;AAC/B,IAAM,qBAAA,GAAwB,cAAA;AAO9B,eAAsB,gBAAA,GAInB;AACD,EAAA,MAAM,SAAS,SAAA,EAAU;AACzB,EAAA,MAAM,WAAA,GAAc,MAAM,OAAA,EAAQ;AAElC,EAAA,MAAM,UAAU,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,iBAAA,IAAqB,sBAAsB,CAAA,EAAG,KAAA;AACrF,EAAA,MAAM,SAAS,WAAA,CAAY,GAAA,CAAI,MAAA,CAAO,gBAAA,IAAoB,qBAAqB,CAAA,EAAG,KAAA;AAElF,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,UAAU,MAAA,CAAO,aAAA;AAAA,IACzB,OAAA,EAAS,WAAW,MAAA,CAAO;AAAA;AAAA,GAE7B;AACF;;;AClBA,eAAsB,UAAA,CACpB,QACA,OAAA,EACwC;AACxC,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,MAAA,CAAO,IAAA,CAAK,QAAQ,QAAQ,CAAA;AACvD;AAMA,eAAsB,QAAA,CACpB,aAAA,EACA,MAAA,EACA,OAAA,EACqB;AACrB,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,OAAO,GAAA,CAAI,aAAA,EAAe,QAAQ,QAAQ,CAAA;AACrE;AAMA,eAAsB,iBAAA,CACpB,OAAA,EACA,MAAA,EACA,OAAA,EAC0C;AAC1C,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,SAAA,GAAY,KAAA,CAAM,MAAA,CAAO,SAAS,IAAA,CAAK,OAAA,EAAS,QAAQ,QAAQ,CAAA;AACzE","file":"taxons.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_COUNTRY_COOKIE = 'spree_country';\nconst DEFAULT_LOCALE_COOKIE = 'spree_locale';\n\n/**\n * Read locale/currency/country from cookies (set by middleware).\n * Falls back to config defaults.\n * @internal\n */\nexport async function getLocaleOptions(): Promise<{\n locale?: string;\n currency?: string;\n country?: string;\n}> {\n const config = getConfig();\n const cookieStore = await cookies();\n\n const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;\n const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;\n\n return {\n locale: locale || config.defaultLocale,\n country: country || config.defaultCountry,\n // No currency — backend resolves from country via X-Spree-Country header\n };\n}\n","import type { StoreTaxon, StoreProduct, PaginatedResponse, TaxonListParams, ProductListParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listTaxons(\n params?: TaxonListParams,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxon>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.taxons.list(params, resolved);\n}\n\n/**\n * Get a single taxon by ID or permalink.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxon> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.taxons.get(idOrPermalink, params, resolved);\n}\n\n/**\n * List products within a taxon.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: ProductListParams,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.taxons.products.list(taxonId, params, resolved);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { getStore } from './data/store.js';
7
7
  export { getCountry, listCountries } from './data/countries.js';
8
8
  export { listCurrencies } from './data/currencies.js';
9
9
  export { listLocales } from './data/locales.js';
10
- import { StoreOrder, StoreShipment, AddressParams, StoreCustomer, StoreAddress, PaginatedResponse, StoreCreditCard, StoreGiftCard, CompletePaymentSessionParams, StorePaymentSession, CreatePaymentSessionParams, UpdatePaymentSessionParams, CompletePaymentSetupSessionParams, StorePaymentSetupSession, CreatePaymentSetupSessionParams } from '@spree/sdk';
10
+ import { StoreOrder, StoreShipment, AddressParams, StoreCustomer, StoreAddress, OrderListParams, PaginatedResponse, StoreCreditCard, StoreGiftCard, CompletePaymentSessionParams, StorePaymentSession, CreatePaymentSessionParams, UpdatePaymentSessionParams, CompletePaymentSetupSessionParams, StorePaymentSetupSession, CreatePaymentSetupSessionParams } from '@spree/sdk';
11
11
  export { AddressParams, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, PaginatedResponse, ProductFiltersResponse, SpreeError, StoreAddress, StoreCountry, StoreCreditCard, StoreCurrency, StoreCustomer, StoreDigitalLink, StoreGiftCard, StoreImage, StoreLineItem, StoreLocale, StoreOptionType, StoreOptionValue, StoreOrder, StoreOrderPromotion, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StorePrice, StoreProduct, StoreShipment, StoreShippingRate, StoreStore, StoreTaxon, StoreTaxonomy, StoreVariant, UpdatePaymentSessionParams } from '@spree/sdk';
12
12
 
13
13
  /**
@@ -18,20 +18,34 @@ declare function getCart(): Promise<(StoreOrder & {
18
18
  }) | null>;
19
19
  /**
20
20
  * Get existing cart or create a new one.
21
+ * @param metadata - Optional metadata to set on the cart when creating a new one
21
22
  */
22
- declare function getOrCreateCart(): Promise<StoreOrder & {
23
+ declare function getOrCreateCart(metadata?: Record<string, unknown>): Promise<StoreOrder & {
23
24
  token: string;
24
25
  }>;
25
26
  /**
26
27
  * Add an item to the cart. Creates a cart if none exists.
27
28
  * Returns the updated order with recalculated totals.
28
29
  */
29
- declare function addItem(variantId: string, quantity?: number): Promise<StoreOrder>;
30
+ declare function addItem(variantId: string, quantity?: number, metadata?: Record<string, unknown>): Promise<StoreOrder>;
30
31
  /**
31
- * Update a line item quantity in the cart.
32
+ * Update a line item in the cart (quantity and/or metadata).
32
33
  * Returns the updated order with recalculated totals.
33
- */
34
- declare function updateItem(lineItemId: string, quantity: number): Promise<StoreOrder>;
34
+ *
35
+ * @example
36
+ * // Update quantity only
37
+ * await updateItem(lineItemId, { quantity: 3 })
38
+ *
39
+ * // Update metadata only
40
+ * await updateItem(lineItemId, { metadata: { gift_message: 'Happy Birthday!' } })
41
+ *
42
+ * // Update both
43
+ * await updateItem(lineItemId, { quantity: 2, metadata: { engraving: 'J.D.' } })
44
+ */
45
+ declare function updateItem(lineItemId: string, params: {
46
+ quantity?: number;
47
+ metadata?: Record<string, unknown>;
48
+ }): Promise<StoreOrder>;
35
49
  /**
36
50
  * Remove a line item from the cart.
37
51
  * Returns the updated order with recalculated totals.
@@ -167,12 +181,21 @@ declare function deleteAddress(id: string): Promise<void>;
167
181
  /**
168
182
  * List the authenticated customer's orders.
169
183
  */
170
- declare function listOrders(params?: Record<string, unknown>): Promise<PaginatedResponse<StoreOrder>>;
184
+ declare function listOrders(params?: OrderListParams): Promise<PaginatedResponse<StoreOrder>>;
171
185
  /**
172
186
  * Get a single order by ID or number.
173
187
  */
174
188
  declare function getOrder(idOrNumber: string, params?: Record<string, unknown>): Promise<StoreOrder>;
175
189
 
190
+ /**
191
+ * Set locale/country cookies for subsequent requests.
192
+ * Use this in country/language switchers instead of manipulating cookies directly.
193
+ */
194
+ declare function setLocale(params: {
195
+ country?: string;
196
+ locale?: string;
197
+ }): Promise<void>;
198
+
176
199
  /**
177
200
  * List the authenticated customer's credit cards.
178
201
  */
@@ -230,4 +253,4 @@ declare function getPaymentSetupSession(id: string): Promise<StorePaymentSetupSe
230
253
  */
231
254
  declare function completePaymentSetupSession(id: string, params?: CompletePaymentSetupSessionParams): Promise<StorePaymentSetupSession>;
232
255
 
233
- export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getCustomer, getGiftCard, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getShipments, listAddresses, listCreditCards, listGiftCards, listOrders, login, logout, next, register, removeCoupon, removeItem, selectShippingRate, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };
256
+ export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getCustomer, getGiftCard, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getShipments, listAddresses, listCreditCards, listGiftCards, listOrders, login, logout, next, register, removeCoupon, removeItem, selectShippingRate, setLocale, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };