@spree/next 0.6.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.
@@ -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
  /**
@@ -181,12 +181,21 @@ declare function deleteAddress(id: string): Promise<void>;
181
181
  /**
182
182
  * List the authenticated customer's orders.
183
183
  */
184
- declare function listOrders(params?: Record<string, unknown>): Promise<PaginatedResponse<StoreOrder>>;
184
+ declare function listOrders(params?: OrderListParams): Promise<PaginatedResponse<StoreOrder>>;
185
185
  /**
186
186
  * Get a single order by ID or number.
187
187
  */
188
188
  declare function getOrder(idOrNumber: string, params?: Record<string, unknown>): Promise<StoreOrder>;
189
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
+
190
199
  /**
191
200
  * List the authenticated customer's credit cards.
192
201
  */
@@ -244,4 +253,4 @@ declare function getPaymentSetupSession(id: string): Promise<StorePaymentSetupSe
244
253
  */
245
254
  declare function completePaymentSetupSession(id: string, params?: CompletePaymentSetupSessionParams): Promise<StorePaymentSetupSession>;
246
255
 
247
- 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 };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createSpreeClient, SpreeError } from '@spree/sdk';
2
- import { revalidateTag } from 'next/cache';
3
2
  import { cookies } from 'next/headers';
3
+ import { revalidateTag } from 'next/cache';
4
4
 
5
5
  // src/config.ts
6
6
  var _client = null;
@@ -32,97 +32,84 @@ function getConfig() {
32
32
  }
33
33
  return _config;
34
34
  }
35
+ var DEFAULT_COUNTRY_COOKIE = "spree_country";
36
+ var DEFAULT_LOCALE_COOKIE = "spree_locale";
37
+ async function getLocaleOptions() {
38
+ const config = getConfig();
39
+ const cookieStore = await cookies();
40
+ const country = cookieStore.get(config.countryCookieName ?? DEFAULT_COUNTRY_COOKIE)?.value;
41
+ const locale = cookieStore.get(config.localeCookieName ?? DEFAULT_LOCALE_COOKIE)?.value;
42
+ return {
43
+ locale: locale || config.defaultLocale,
44
+ country: country || config.defaultCountry
45
+ // No currency — backend resolves from country via X-Spree-Country header
46
+ };
47
+ }
35
48
 
36
49
  // src/data/products.ts
37
50
  async function listProducts(params, options) {
38
- return getClient().store.products.list(params, {
39
- locale: options?.locale,
40
- currency: options?.currency
41
- });
51
+ const resolved = options ?? await getLocaleOptions();
52
+ return getClient().store.products.list(params, resolved);
42
53
  }
43
54
  async function getProduct(slugOrId, params, options) {
44
- return getClient().store.products.get(slugOrId, params, {
45
- locale: options?.locale,
46
- currency: options?.currency
47
- });
55
+ const resolved = options ?? await getLocaleOptions();
56
+ return getClient().store.products.get(slugOrId, params, resolved);
48
57
  }
49
58
  async function getProductFilters(params, options) {
50
- return getClient().store.products.filters(params, {
51
- locale: options?.locale,
52
- currency: options?.currency
53
- });
59
+ const resolved = options ?? await getLocaleOptions();
60
+ return getClient().store.products.filters(params, resolved);
54
61
  }
55
62
 
56
63
  // src/data/taxons.ts
57
64
  async function listTaxons(params, options) {
58
- return getClient().store.taxons.list(params, {
59
- locale: options?.locale,
60
- currency: options?.currency
61
- });
65
+ const resolved = options ?? await getLocaleOptions();
66
+ return getClient().store.taxons.list(params, resolved);
62
67
  }
63
68
  async function getTaxon(idOrPermalink, params, options) {
64
- return getClient().store.taxons.get(idOrPermalink, params, {
65
- locale: options?.locale,
66
- currency: options?.currency
67
- });
69
+ const resolved = options ?? await getLocaleOptions();
70
+ return getClient().store.taxons.get(idOrPermalink, params, resolved);
68
71
  }
69
72
  async function listTaxonProducts(taxonId, params, options) {
70
- return getClient().store.taxons.products.list(taxonId, params, {
71
- locale: options?.locale,
72
- currency: options?.currency
73
- });
73
+ const resolved = options ?? await getLocaleOptions();
74
+ return getClient().store.taxons.products.list(taxonId, params, resolved);
74
75
  }
75
76
 
76
77
  // src/data/taxonomies.ts
77
78
  async function listTaxonomies(params, options) {
78
- return getClient().store.taxonomies.list(params, {
79
- locale: options?.locale,
80
- currency: options?.currency
81
- });
79
+ const resolved = options ?? await getLocaleOptions();
80
+ return getClient().store.taxonomies.list(params, resolved);
82
81
  }
83
82
  async function getTaxonomy(id, params, options) {
84
- return getClient().store.taxonomies.get(id, params, {
85
- locale: options?.locale,
86
- currency: options?.currency
87
- });
83
+ const resolved = options ?? await getLocaleOptions();
84
+ return getClient().store.taxonomies.get(id, params, resolved);
88
85
  }
89
86
 
90
87
  // src/data/store.ts
91
88
  async function getStore(options) {
92
- return getClient().store.store.get({
93
- locale: options?.locale,
94
- currency: options?.currency
95
- });
89
+ const resolved = options ?? await getLocaleOptions();
90
+ return getClient().store.store.get(resolved);
96
91
  }
97
92
 
98
93
  // src/data/countries.ts
99
94
  async function listCountries(options) {
100
- return getClient().store.countries.list({
101
- locale: options?.locale,
102
- currency: options?.currency
103
- });
95
+ const resolved = options ?? await getLocaleOptions();
96
+ return getClient().store.countries.list(resolved);
104
97
  }
105
98
  async function getCountry(iso, params, options) {
106
- return getClient().store.countries.get(iso, params, {
107
- locale: options?.locale,
108
- currency: options?.currency
109
- });
99
+ const resolved = options ?? await getLocaleOptions();
100
+ return getClient().store.countries.get(iso, params, resolved);
110
101
  }
111
102
 
112
103
  // src/data/currencies.ts
113
104
  async function listCurrencies(options) {
114
- return getClient().store.currencies.list({
115
- locale: options?.locale,
116
- currency: options?.currency
117
- });
105
+ const resolved = options ?? await getLocaleOptions();
106
+ return getClient().store.currencies.list(resolved);
118
107
  }
119
108
 
120
109
  // src/data/locales.ts
121
110
  async function listLocales(options) {
122
- return getClient().store.locales.list({
123
- locale: options?.locale,
124
- currency: options?.currency
125
- });
111
+ const resolved = options ?? await getLocaleOptions();
112
+ return getClient().store.locales.list(resolved);
126
113
  }
127
114
  var DEFAULT_CART_COOKIE = "_spree_cart_token";
128
115
  var DEFAULT_ACCESS_TOKEN_COOKIE = "_spree_jwt";
@@ -498,6 +485,23 @@ async function getOrder(idOrNumber, params) {
498
485
  return getClient().store.orders.get(idOrNumber, params, options);
499
486
  });
500
487
  }
488
+ async function setLocale(params) {
489
+ const config = getConfig();
490
+ const cookieStore = await cookies();
491
+ const maxAge = 60 * 60 * 24 * 365;
492
+ if (params.country) {
493
+ cookieStore.set(config.countryCookieName ?? "spree_country", params.country, {
494
+ path: "/",
495
+ maxAge
496
+ });
497
+ }
498
+ if (params.locale) {
499
+ cookieStore.set(config.localeCookieName ?? "spree_locale", params.locale, {
500
+ path: "/",
501
+ maxAge
502
+ });
503
+ }
504
+ }
501
505
  async function listCreditCards() {
502
506
  return withAuthRefresh(async (options) => {
503
507
  return getClient().store.customer.creditCards.list(void 0, options);
@@ -566,6 +570,6 @@ async function completePaymentSetupSession(id, params) {
566
570
  });
567
571
  }
568
572
 
569
- export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getClient, getCountry, getCustomer, getGiftCard, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getProduct, getProductFilters, getShipments, getStore, getTaxon, getTaxonomy, initSpreeNext, listAddresses, listCountries, listCreditCards, listCurrencies, listGiftCards, listLocales, listOrders, listProducts, listTaxonProducts, listTaxonomies, listTaxons, login, logout, next, register, removeCoupon, removeItem, selectShippingRate, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };
573
+ export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getClient, getCountry, getCustomer, getGiftCard, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getProduct, getProductFilters, getShipments, getStore, getTaxon, getTaxonomy, initSpreeNext, listAddresses, listCountries, listCreditCards, listCurrencies, listGiftCards, listLocales, listOrders, listProducts, listTaxonProducts, listTaxonomies, listTaxons, login, logout, next, register, removeCoupon, removeItem, selectShippingRate, setLocale, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };
570
574
  //# sourceMappingURL=index.js.map
571
575
  //# sourceMappingURL=index.js.map