@spree/next 0.6.2 → 0.6.3

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.
@@ -3,8 +3,7 @@ import { SpreeNextOptions } from '../types.js';
3
3
 
4
4
  /**
5
5
  * List countries available in the store.
6
- * Each country includes currency and default_locale derived from its market.
7
- * Locale/country are auto-read from cookies when not provided.
6
+ * Use ?include=market to include market details (currency, locale, tax_inclusive).
8
7
  */
9
8
  declare function listCountries(options?: SpreeNextOptions): Promise<{
10
9
  data: StoreCountry[];
@@ -12,8 +11,7 @@ declare function listCountries(options?: SpreeNextOptions): Promise<{
12
11
  /**
13
12
  * Get a country by ISO code.
14
13
  * @param iso - ISO 3166-1 alpha-2 code (e.g., "US", "DE")
15
- * @param params - Optional params (e.g., { include: 'states' } for address forms)
16
- * Locale/country are auto-read from cookies when not provided.
14
+ * @param params - Optional params (e.g., { include: 'states' } or { include: 'market' })
17
15
  */
18
16
  declare function getCountry(iso: string, params?: {
19
17
  include?: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/countries.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,EAA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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 { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List countries available in the store.\n * Each country includes currency and default_locale derived from its market.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.list(resolved);\n}\n\n/**\n * Get a country by ISO code.\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n * @param params - Optional params (e.g., { include: 'states' } for address forms)\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getCountry(\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.get(iso, params, resolved);\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/countries.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,cACpB,OAAA,EACmC;AACnC,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,SAAA,CAAU,KAAK,QAAQ,CAAA;AAClD;AAOA,eAAsB,UAAA,CACpB,GAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,UAAU,GAAA,CAAI,GAAA,EAAK,QAAQ,QAAQ,CAAA;AAC9D","file":"countries.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 { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List countries available in the store.\n * Use ?include=market to include market details (currency, locale, tax_inclusive).\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.list(resolved);\n}\n\n/**\n * Get a country by ISO code.\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n * @param params - Optional params (e.g., { include: 'states' } or { include: 'market' })\n */\nexport async function getCountry(\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.get(iso, params, resolved);\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { StoreMarket, StoreCountry } from '@spree/sdk';
2
+ import { SpreeNextOptions } from '../types.js';
3
+
4
+ /**
5
+ * List all markets for the current store.
6
+ * Each market includes currency, locales, tax_inclusive flag, and countries.
7
+ */
8
+ declare function listMarkets(options?: SpreeNextOptions): Promise<{
9
+ data: StoreMarket[];
10
+ }>;
11
+ /**
12
+ * Get a market by prefixed ID.
13
+ * @param id - Market prefixed ID (e.g., "mkt_k5nR8xLq")
14
+ */
15
+ declare function getMarket(id: string, options?: SpreeNextOptions): Promise<StoreMarket>;
16
+ /**
17
+ * Resolve which market applies for a given country.
18
+ * @param country - ISO 3166-1 alpha-2 code (e.g., "DE", "US")
19
+ */
20
+ declare function resolveMarket(country: string, options?: SpreeNextOptions): Promise<StoreMarket>;
21
+ /**
22
+ * List countries belonging to a market.
23
+ * @param marketId - Market prefixed ID
24
+ */
25
+ declare function listMarketCountries(marketId: string, options?: SpreeNextOptions): Promise<{
26
+ data: StoreCountry[];
27
+ }>;
28
+ /**
29
+ * Get a country by ISO code within a market.
30
+ * @param marketId - Market prefixed ID
31
+ * @param iso - Country ISO code (e.g., "DE")
32
+ */
33
+ declare function getMarketCountry(marketId: string, iso: string, params?: {
34
+ include?: string;
35
+ }, options?: SpreeNextOptions): Promise<StoreCountry>;
36
+
37
+ export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket };
@@ -0,0 +1,72 @@
1
+ import { createSpreeClient } from '@spree/sdk';
2
+ import { cookies } from 'next/headers';
3
+
4
+ // src/config.ts
5
+ var _client = null;
6
+ var _config = null;
7
+ function initSpreeNext(config) {
8
+ _config = config;
9
+ _client = createSpreeClient({
10
+ baseUrl: config.baseUrl,
11
+ publishableKey: config.publishableKey
12
+ });
13
+ }
14
+ function getClient() {
15
+ if (!_client) {
16
+ const baseUrl = process.env.SPREE_API_URL;
17
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
18
+ if (baseUrl && publishableKey) {
19
+ initSpreeNext({ baseUrl, publishableKey });
20
+ } else {
21
+ throw new Error(
22
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
23
+ );
24
+ }
25
+ }
26
+ return _client;
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
+ }
47
+
48
+ // src/data/markets.ts
49
+ async function listMarkets(options) {
50
+ const resolved = options ?? await getLocaleOptions();
51
+ return getClient().store.markets.list(resolved);
52
+ }
53
+ async function getMarket(id, options) {
54
+ const resolved = options ?? await getLocaleOptions();
55
+ return getClient().store.markets.get(id, resolved);
56
+ }
57
+ async function resolveMarket(country, options) {
58
+ const resolved = options ?? await getLocaleOptions();
59
+ return getClient().store.markets.resolve(country, resolved);
60
+ }
61
+ async function listMarketCountries(marketId, options) {
62
+ const resolved = options ?? await getLocaleOptions();
63
+ return getClient().store.markets.countries.list(marketId, resolved);
64
+ }
65
+ async function getMarketCountry(marketId, iso, params, options) {
66
+ const resolved = options ?? await getLocaleOptions();
67
+ return getClient().store.markets.countries.get(marketId, iso, params, resolved);
68
+ }
69
+
70
+ export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket };
71
+ //# sourceMappingURL=markets.js.map
72
+ //# sourceMappingURL=markets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config.ts","../../src/locale.ts","../../src/data/markets.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,EA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W,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,QAAQ,SAAA,CAAU,IAAA,CAAK,UAAU,QAAQ,CAAA;AACpE;AAOA,eAAsB,gBAAA,CACpB,QAAA,EACA,GAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,MAAM,QAAA,GAAW,OAAA,IAAW,MAAM,gBAAA,EAAiB;AACnD,EAAA,OAAO,SAAA,GAAY,KAAA,CAAM,OAAA,CAAQ,UAAU,GAAA,CAAI,QAAA,EAAU,GAAA,EAAK,MAAA,EAAQ,QAAQ,CAAA;AAChF","file":"markets.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 { StoreMarket, StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List all markets for the current store.\n * Each market includes currency, locales, tax_inclusive flag, and countries.\n */\nexport async function listMarkets(\n options?: SpreeNextOptions\n): Promise<{ data: StoreMarket[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.list(resolved);\n}\n\n/**\n * Get a market by prefixed ID.\n * @param id - Market prefixed ID (e.g., \"mkt_k5nR8xLq\")\n */\nexport async function getMarket(\n id: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.get(id, resolved);\n}\n\n/**\n * Resolve which market applies for a given country.\n * @param country - ISO 3166-1 alpha-2 code (e.g., \"DE\", \"US\")\n */\nexport async function resolveMarket(\n country: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.resolve(country, resolved);\n}\n\n/**\n * List countries belonging to a market.\n * @param marketId - Market prefixed ID\n */\nexport async function listMarketCountries(\n marketId: string,\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.countries.list(marketId, resolved);\n}\n\n/**\n * Get a country by ISO code within a market.\n * @param marketId - Market prefixed ID\n * @param iso - Country ISO code (e.g., \"DE\")\n */\nexport async function getMarketCountry(\n marketId: string,\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.countries.get(marketId, iso, params, resolved);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -7,8 +7,9 @@ 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
+ export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket } from './data/markets.js';
10
11
  import { StoreOrder, StoreShipment, AddressParams, StoreCustomer, StoreAddress, OrderListParams, PaginatedResponse, StoreCreditCard, StoreGiftCard, CompletePaymentSessionParams, StorePaymentSession, CreatePaymentSessionParams, UpdatePaymentSessionParams, CompletePaymentSetupSessionParams, StorePaymentSetupSession, CreatePaymentSetupSessionParams } from '@spree/sdk';
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
+ export { AddressParams, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, PaginatedResponse, ProductFiltersResponse, SpreeError, StoreAddress, StoreCountry, StoreCreditCard, StoreCurrency, StoreCustomer, StoreDigitalLink, StoreGiftCard, StoreImage, StoreLineItem, StoreLocale, StoreMarket, StoreOptionType, StoreOptionValue, StoreOrder, StoreOrderPromotion, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StorePrice, StoreProduct, StoreShipment, StoreShippingRate, StoreStore, StoreTaxon, StoreTaxonomy, StoreVariant, UpdatePaymentSessionParams } from '@spree/sdk';
12
13
 
13
14
  /**
14
15
  * Get the current cart. Returns null if no cart exists.
package/dist/index.js CHANGED
@@ -111,6 +111,28 @@ async function listLocales(options) {
111
111
  const resolved = options ?? await getLocaleOptions();
112
112
  return getClient().store.locales.list(resolved);
113
113
  }
114
+
115
+ // src/data/markets.ts
116
+ async function listMarkets(options) {
117
+ const resolved = options ?? await getLocaleOptions();
118
+ return getClient().store.markets.list(resolved);
119
+ }
120
+ async function getMarket(id, options) {
121
+ const resolved = options ?? await getLocaleOptions();
122
+ return getClient().store.markets.get(id, resolved);
123
+ }
124
+ async function resolveMarket(country, options) {
125
+ const resolved = options ?? await getLocaleOptions();
126
+ return getClient().store.markets.resolve(country, resolved);
127
+ }
128
+ async function listMarketCountries(marketId, options) {
129
+ const resolved = options ?? await getLocaleOptions();
130
+ return getClient().store.markets.countries.list(marketId, resolved);
131
+ }
132
+ async function getMarketCountry(marketId, iso, params, options) {
133
+ const resolved = options ?? await getLocaleOptions();
134
+ return getClient().store.markets.countries.get(marketId, iso, params, resolved);
135
+ }
114
136
  var DEFAULT_CART_COOKIE = "_spree_cart_token";
115
137
  var DEFAULT_ACCESS_TOKEN_COOKIE = "_spree_jwt";
116
138
  var CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30;
@@ -570,6 +592,6 @@ async function completePaymentSetupSession(id, params) {
570
592
  });
571
593
  }
572
594
 
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 };
595
+ export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getClient, getCountry, getCustomer, getGiftCard, getMarket, getMarketCountry, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getProduct, getProductFilters, getShipments, getStore, getTaxon, getTaxonomy, initSpreeNext, listAddresses, listCountries, listCreditCards, listCurrencies, listGiftCards, listLocales, listMarketCountries, listMarkets, listOrders, listProducts, listTaxonProducts, listTaxonomies, listTaxons, login, logout, next, register, removeCoupon, removeItem, resolveMarket, selectShippingRate, setLocale, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };
574
596
  //# sourceMappingURL=index.js.map
575
597
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts","../src/locale.ts","../src/data/products.ts","../src/data/taxons.ts","../src/data/taxonomies.ts","../src/data/store.ts","../src/data/countries.ts","../src/data/currencies.ts","../src/data/locales.ts","../src/cookies.ts","../src/actions/cart.ts","../src/actions/checkout.ts","../src/auth-helpers.ts","../src/actions/auth.ts","../src/actions/addresses.ts","../src/actions/orders.ts","../src/actions/locale.ts","../src/actions/credit-cards.ts","../src/actions/gift-cards.ts","../src/actions/payment-sessions.ts","../src/actions/payment-setup-sessions.ts"],"names":["cookies","revalidateTag","getCheckoutOptions"],"mappings":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AACH;AAMA,eAAsB,2BAAA,CACpB,IACA,MAAA,EACmC;AACnC,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,SAAA,GAAY,KAAA,CAAM,QAAA,CAAS,qBAAqB,QAAA,CAAS,EAAA,EAAI,QAAQ,OAAO,CAAA;AAAA,EACrF,CAAC,CAAA;AACH","file":"index.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","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","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","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","import type { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List countries available in the store.\n * Each country includes currency and default_locale derived from its market.\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.list(resolved);\n}\n\n/**\n * Get a country by ISO code.\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n * @param params - Optional params (e.g., { include: 'states' } for address forms)\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function getCountry(\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.get(iso, params, resolved);\n}\n","import type { StoreCurrency } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List currencies supported by the store (derived from markets).\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listCurrencies(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCurrency[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.currencies.list(resolved);\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","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_CART_COOKIE = '_spree_cart_token';\nconst DEFAULT_ACCESS_TOKEN_COOKIE = '_spree_jwt';\nconst CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\nconst ACCESS_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days\n\nfunction getCartCookieName(): string {\n try {\n return getConfig().cartCookieName ?? DEFAULT_CART_COOKIE;\n } catch {\n return DEFAULT_CART_COOKIE;\n }\n}\n\nfunction getAccessTokenCookieName(): string {\n try {\n return getConfig().accessTokenCookieName ?? DEFAULT_ACCESS_TOKEN_COOKIE;\n } catch {\n return DEFAULT_ACCESS_TOKEN_COOKIE;\n }\n}\n\n// --- Cart Token ---\n\nexport async function getCartToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getCartCookieName())?.value;\n}\n\nexport async function setCartToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: CART_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearCartToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n\n// --- Access Token (JWT) ---\n\nexport async function getAccessToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getAccessTokenCookieName())?.value;\n}\n\nexport async function setAccessToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: ACCESS_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearAccessToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, setCartToken, clearCartToken, getAccessToken } from '../cookies';\n\n/**\n * Get the current cart. Returns null if no cart exists.\n */\nexport async function getCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) return null;\n\n try {\n return await getClient().store.cart.get({ orderToken, token });\n } catch {\n // Cart not found (e.g., order was completed) — clear stale token\n if (orderToken) {\n await clearCartToken();\n }\n return null;\n }\n}\n\n/**\n * Get existing cart or create a new one.\n * @param metadata - Optional metadata to set on the cart when creating a new one\n */\nexport async function getOrCreateCart(\n metadata?: Record<string, unknown>\n): Promise<StoreOrder & { token: string }> {\n const existing = await getCart();\n if (existing) return existing;\n\n const token = await getAccessToken();\n const cartParams = metadata ? { metadata } : undefined;\n const cart = await getClient().store.cart.create(cartParams, token ? { token } : undefined);\n\n if (cart.token) {\n await setCartToken(cart.token);\n }\n\n revalidateTag('cart');\n return cart;\n}\n\n/**\n * Add an item to the cart. Creates a cart if none exists.\n * Returns the updated order with recalculated totals.\n */\nexport async function addItem(\n variantId: string,\n quantity: number = 1,\n metadata?: Record<string, unknown>\n): Promise<StoreOrder> {\n const cart = await getOrCreateCart();\n const orderToken = cart.token;\n const token = await getAccessToken();\n\n const order = await getClient().store.orders.lineItems.create(\n cart.id,\n { variant_id: variantId, quantity, metadata },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Update a line item in the cart (quantity and/or metadata).\n * Returns the updated order with recalculated totals.\n *\n * @example\n * // Update quantity only\n * await updateItem(lineItemId, { quantity: 3 })\n *\n * // Update metadata only\n * await updateItem(lineItemId, { metadata: { gift_message: 'Happy Birthday!' } })\n *\n * // Update both\n * await updateItem(lineItemId, { quantity: 2, metadata: { engraving: 'J.D.' } })\n */\nexport async function updateItem(\n lineItemId: string,\n params: { quantity?: number; metadata?: Record<string, unknown> }\n): Promise<StoreOrder> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().store.cart.get({ orderToken, token });\n\n const order = await getClient().store.orders.lineItems.update(\n cart.id,\n lineItemId,\n params,\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Remove a line item from the cart.\n * Returns the updated order with recalculated totals.\n */\nexport async function removeItem(lineItemId: string): Promise<StoreOrder> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().store.cart.get({ orderToken, token });\n\n const order = await getClient().store.orders.lineItems.delete(cart.id, lineItemId, {\n orderToken,\n token,\n });\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Clear the cart (abandons the current cart).\n */\nexport async function clearCart(): Promise<void> {\n await clearCartToken();\n revalidateTag('cart');\n}\n\n/**\n * Associate a guest cart with the currently authenticated user.\n * Call this after login/register when the user has an existing guest cart.\n */\nexport async function associateCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken || !token) return null;\n\n try {\n const result = await getClient().store.cart.associate({ orderToken, token });\n revalidateTag('cart');\n return result;\n } catch {\n // Cart might already belong to another user — clear it\n await clearCartToken();\n revalidateTag('cart');\n return null;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder, StoreShipment, AddressParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, getAccessToken } from '../cookies';\n\nasync function getCheckoutOptions() {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n return { orderToken, token };\n}\n\n/**\n * Get the current checkout order state.\n * Includes line_items, shipments, and addresses by default.\n */\nexport async function getCheckout(\n orderId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n return getClient().store.orders.get(\n orderId,\n { includes: 'line_items,shipments,ship_address,bill_address' },\n options\n );\n}\n\n/**\n * Update shipping and/or billing addresses on the order.\n */\nexport async function updateAddresses(\n orderId: string,\n params: {\n email?: string;\n ship_address?: AddressParams;\n bill_address?: AddressParams;\n ship_address_id?: string;\n bill_address_id?: string;\n }\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.update(orderId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Advance the checkout to the next step.\n */\nexport async function advance(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.advance(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Move the checkout to the next step (alias for advance).\n */\nexport async function next(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.next(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Get shipments for the order (includes available shipping rates).\n */\nexport async function getShipments(\n orderId: string\n): Promise<{ data: StoreShipment[] }> {\n const options = await getCheckoutOptions();\n return getClient().store.orders.shipments.list(orderId, options);\n}\n\n/**\n * Select a shipping rate for a shipment.\n * Returns the updated order with recalculated totals.\n */\nexport async function selectShippingRate(\n orderId: string,\n shipmentId: string,\n shippingRateId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.shipments.update(\n orderId,\n shipmentId,\n { selected_shipping_rate_id: shippingRateId },\n options\n );\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Apply a coupon code to the order.\n */\nexport async function applyCoupon(\n orderId: string,\n code: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.couponCodes.apply(orderId, code, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Remove a coupon/promotion from the order.\n */\nexport async function removeCoupon(\n orderId: string,\n promotionId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.couponCodes.remove(orderId, promotionId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Complete the checkout and place the order.\n */\nexport async function complete(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.complete(orderId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n","import { SpreeError } from '@spree/sdk';\nimport type { RequestOptions } from '@spree/sdk';\nimport { getClient } from './config';\nimport { getAccessToken, setAccessToken, clearAccessToken } from './cookies';\n\n/**\n * Get auth request options from the current JWT token.\n * Proactively refreshes the token if it expires within 1 hour.\n */\nexport async function getAuthOptions(): Promise<RequestOptions> {\n const token = await getAccessToken();\n if (!token) {\n return {};\n }\n\n // Check if token is close to expiry by decoding JWT payload\n try {\n const payload = JSON.parse(atob(token.split('.')[1]));\n const exp = payload.exp;\n const now = Math.floor(Date.now() / 1000);\n\n // Refresh if token expires in less than 1 hour\n if (exp && exp - now < 3600) {\n try {\n const refreshed = await getClient().store.auth.refresh({ token });\n await setAccessToken(refreshed.token);\n return { token: refreshed.token };\n } catch {\n // Refresh failed — use existing token, it might still work\n }\n }\n } catch {\n // Can't decode JWT — use it as-is, the server will reject if invalid\n }\n\n return { token };\n}\n\n/**\n * Execute an authenticated request with automatic token refresh on 401.\n * @param fn - Function that takes RequestOptions and returns a promise\n * @returns The result of the function\n * @throws SpreeError if auth fails after refresh attempt\n */\nexport async function withAuthRefresh<T>(\n fn: (options: RequestOptions) => Promise<T>\n): Promise<T> {\n const options = await getAuthOptions();\n\n if (!options.token) {\n throw new Error('Not authenticated');\n }\n\n try {\n return await fn(options);\n } catch (error: unknown) {\n // If 401, try refreshing the token once\n if (error instanceof SpreeError && error.status === 401) {\n try {\n const refreshed = await getClient().store.auth.refresh({ token: options.token });\n await setAccessToken(refreshed.token);\n return await fn({ token: refreshed.token });\n } catch {\n // Refresh failed — clear token and rethrow\n await clearAccessToken();\n throw error;\n }\n }\n throw error;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCustomer } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { setAccessToken, clearAccessToken, getAccessToken, getCartToken } from '../cookies';\nimport { withAuthRefresh } from '../auth-helpers';\n\n/**\n * Login with email and password.\n * Automatically associates any guest cart with the authenticated user.\n */\nexport async function login(\n email: string,\n password: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().store.auth.login({ email, password });\n await setAccessToken(result.token);\n\n // Associate guest cart if one exists\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().store.cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Cart association failure is non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid email or password',\n };\n }\n}\n\n/**\n * Register a new customer account.\n * Automatically associates any guest cart with the new account.\n */\nexport async function register(\n email: string,\n password: string,\n passwordConfirmation: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().store.auth.register({\n email,\n password,\n password_confirmation: passwordConfirmation,\n });\n await setAccessToken(result.token);\n\n // Associate guest cart\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().store.cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Registration failed',\n };\n }\n}\n\n/**\n * Logout the current user.\n */\nexport async function logout(): Promise<void> {\n await clearAccessToken();\n revalidateTag('customer');\n revalidateTag('cart');\n revalidateTag('addresses');\n revalidateTag('credit-cards');\n}\n\n/**\n * Get the currently authenticated customer. Returns null if not logged in.\n */\nexport async function getCustomer(): Promise<StoreCustomer | null> {\n const token = await getAccessToken();\n if (!token) return null;\n\n try {\n return await withAuthRefresh(async (options) => {\n return getClient().store.customer.get(options);\n });\n } catch {\n await clearAccessToken();\n return null;\n }\n}\n\n/**\n * Update the current customer's profile.\n */\nexport async function updateCustomer(\n data: { first_name?: string; last_name?: string; email?: string }\n): Promise<StoreCustomer> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().store.customer.update(data, options);\n });\n revalidateTag('customer');\n return result;\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreAddress, AddressParams } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's addresses.\n */\nexport async function listAddresses(): Promise<{ data: StoreAddress[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.list(undefined, options);\n });\n}\n\n/**\n * Get a single address by ID.\n */\nexport async function getAddress(id: string): Promise<StoreAddress> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.get(id, options);\n });\n}\n\n/**\n * Create a new address for the customer.\n */\nexport async function createAddress(params: AddressParams): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.create(params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Update an existing address.\n */\nexport async function updateAddress(\n id: string,\n params: Partial<AddressParams>\n): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.update(id, params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Delete an address.\n */\nexport async function deleteAddress(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.delete(id, options);\n });\n revalidateTag('addresses');\n}\n","'use server';\n\nimport type { StoreOrder, PaginatedResponse, OrderListParams } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's orders.\n */\nexport async function listOrders(\n params?: OrderListParams\n): Promise<PaginatedResponse<StoreOrder>> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.orders.list(params, options);\n });\n}\n\n/**\n * Get a single order by ID or number.\n */\nexport async function getOrder(\n idOrNumber: string,\n params?: Record<string, unknown>\n): Promise<StoreOrder> {\n return withAuthRefresh(async (options) => {\n return getClient().store.orders.get(idOrNumber, params, options);\n });\n}\n","'use server';\n\nimport { cookies } from 'next/headers';\nimport { getConfig } from '../config';\n\n/**\n * Set locale/country cookies for subsequent requests.\n * Use this in country/language switchers instead of manipulating cookies directly.\n */\nexport async function setLocale(params: {\n country?: string;\n locale?: string;\n}): Promise<void> {\n const config = getConfig();\n const cookieStore = await cookies();\n const maxAge = 60 * 60 * 24 * 365; // 1 year\n\n if (params.country) {\n cookieStore.set(config.countryCookieName ?? 'spree_country', params.country, {\n path: '/',\n maxAge,\n });\n }\n if (params.locale) {\n cookieStore.set(config.localeCookieName ?? 'spree_locale', params.locale, {\n path: '/',\n maxAge,\n });\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCreditCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's credit cards.\n */\nexport async function listCreditCards(): Promise<{ data: StoreCreditCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.creditCards.list(undefined, options);\n });\n}\n\n/**\n * Delete a credit card.\n */\nexport async function deleteCreditCard(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().store.customer.creditCards.delete(id, options);\n });\n revalidateTag('credit-cards');\n}\n","'use server';\n\nimport type { StoreGiftCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's gift cards.\n */\nexport async function listGiftCards(): Promise<{ data: StoreGiftCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.giftCards.list(undefined, options);\n });\n}\n\n/**\n * Get a single gift card by ID.\n */\nexport async function getGiftCard(id: string): Promise<StoreGiftCard> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.giftCards.get(id, options);\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type {\n StorePaymentSession,\n CreatePaymentSessionParams,\n UpdatePaymentSessionParams,\n CompletePaymentSessionParams,\n} from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, getAccessToken } from '../cookies';\n\nasync function getCheckoutOptions() {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n return { orderToken, token };\n}\n\n/**\n * Create a payment session for an order.\n * Delegates to the payment gateway to initialize a provider-specific session.\n */\nexport async function createPaymentSession(\n orderId: string,\n params: CreatePaymentSessionParams\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.paymentSessions.create(orderId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Get a payment session by ID.\n */\nexport async function getPaymentSession(\n orderId: string,\n sessionId: string\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n return getClient().store.orders.paymentSessions.get(orderId, sessionId, options);\n}\n\n/**\n * Update a payment session.\n * Delegates to the payment gateway to sync changes with the provider.\n */\nexport async function updatePaymentSession(\n orderId: string,\n sessionId: string,\n params: UpdatePaymentSessionParams\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.paymentSessions.update(orderId, sessionId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Complete a payment session.\n * Confirms the payment with the provider, triggering capture/authorization.\n */\nexport async function completePaymentSession(\n orderId: string,\n sessionId: string,\n params?: CompletePaymentSessionParams\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.paymentSessions.complete(orderId, sessionId, params, options);\n revalidateTag('checkout');\n return result;\n}\n","'use server';\n\nimport type {\n StorePaymentSetupSession,\n CreatePaymentSetupSessionParams,\n CompletePaymentSetupSessionParams,\n} from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * Create a payment setup session for saving a payment method.\n * Delegates to the payment gateway to initialize a setup flow.\n */\nexport async function createPaymentSetupSession(\n params: CreatePaymentSetupSessionParams\n): Promise<StorePaymentSetupSession> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.paymentSetupSessions.create(params, options);\n });\n}\n\n/**\n * Get a payment setup session by ID.\n */\nexport async function getPaymentSetupSession(\n id: string\n): Promise<StorePaymentSetupSession> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.paymentSetupSessions.get(id, options);\n });\n}\n\n/**\n * Complete a payment setup session.\n * Confirms the setup with the provider, resulting in a saved payment method.\n */\nexport async function completePaymentSetupSession(\n id: string,\n params?: CompletePaymentSetupSessionParams\n): Promise<StorePaymentSetupSession> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.paymentSetupSessions.complete(id, params, options);\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/config.ts","../src/locale.ts","../src/data/products.ts","../src/data/taxons.ts","../src/data/taxonomies.ts","../src/data/store.ts","../src/data/countries.ts","../src/data/currencies.ts","../src/data/locales.ts","../src/data/markets.ts","../src/cookies.ts","../src/actions/cart.ts","../src/actions/checkout.ts","../src/auth-helpers.ts","../src/actions/auth.ts","../src/actions/addresses.ts","../src/actions/orders.ts","../src/actions/locale.ts","../src/actions/credit-cards.ts","../src/actions/gift-cards.ts","../src/actions/payment-sessions.ts","../src/actions/payment-setup-sessions.ts"],"names":["cookies","revalidateTag","getCheckoutOptions"],"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;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CAAE,KAAA,CAAM,MAAA,CAAO,eAAA,CAAgB,QAAA,CAAS,OAAA,EAAS,SAAA,EAAW,MAAA,EAAQ,OAAO,CAAA;AAC1G,EAAAD,cAAc,UAAU,CAAA;AACxB,EAAA,OAAO,MAAA;AACT;;;ACzDA,eAAsB,0BACpB,MAAA,EACmC;AACnC,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAS,oBAAA,CAAqB,MAAA,CAAO,QAAQ,OAAO,CAAA;AAAA,EAC/E,CAAC,CAAA;AACH;AAKA,eAAsB,uBACpB,EAAA,EACmC;AACnC,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAS,oBAAA,CAAqB,GAAA,CAAI,IAAI,OAAO,CAAA;AAAA,EACxE,CAAC,CAAA;AACH;AAMA,eAAsB,2BAAA,CACpB,IACA,MAAA,EACmC;AACnC,EAAA,OAAO,eAAA,CAAgB,OAAO,OAAA,KAAY;AACxC,IAAA,OAAO,SAAA,GAAY,KAAA,CAAM,QAAA,CAAS,qBAAqB,QAAA,CAAS,EAAA,EAAI,QAAQ,OAAO,CAAA;AAAA,EACrF,CAAC,CAAA;AACH","file":"index.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","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","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","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","import type { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List countries available in the store.\n * Use ?include=market to include market details (currency, locale, tax_inclusive).\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.list(resolved);\n}\n\n/**\n * Get a country by ISO code.\n * @param iso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n * @param params - Optional params (e.g., { include: 'states' } or { include: 'market' })\n */\nexport async function getCountry(\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.countries.get(iso, params, resolved);\n}\n","import type { StoreCurrency } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List currencies supported by the store (derived from markets).\n * Locale/country are auto-read from cookies when not provided.\n */\nexport async function listCurrencies(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCurrency[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.currencies.list(resolved);\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","import type { StoreMarket, StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getLocaleOptions } from '../locale';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List all markets for the current store.\n * Each market includes currency, locales, tax_inclusive flag, and countries.\n */\nexport async function listMarkets(\n options?: SpreeNextOptions\n): Promise<{ data: StoreMarket[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.list(resolved);\n}\n\n/**\n * Get a market by prefixed ID.\n * @param id - Market prefixed ID (e.g., \"mkt_k5nR8xLq\")\n */\nexport async function getMarket(\n id: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.get(id, resolved);\n}\n\n/**\n * Resolve which market applies for a given country.\n * @param country - ISO 3166-1 alpha-2 code (e.g., \"DE\", \"US\")\n */\nexport async function resolveMarket(\n country: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.resolve(country, resolved);\n}\n\n/**\n * List countries belonging to a market.\n * @param marketId - Market prefixed ID\n */\nexport async function listMarketCountries(\n marketId: string,\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.countries.list(marketId, resolved);\n}\n\n/**\n * Get a country by ISO code within a market.\n * @param marketId - Market prefixed ID\n * @param iso - Country ISO code (e.g., \"DE\")\n */\nexport async function getMarketCountry(\n marketId: string,\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n const resolved = options ?? await getLocaleOptions();\n return getClient().store.markets.countries.get(marketId, iso, params, resolved);\n}\n","import { cookies } from 'next/headers';\nimport { getConfig } from './config';\n\nconst DEFAULT_CART_COOKIE = '_spree_cart_token';\nconst DEFAULT_ACCESS_TOKEN_COOKIE = '_spree_jwt';\nconst CART_TOKEN_MAX_AGE = 60 * 60 * 24 * 30; // 30 days\nconst ACCESS_TOKEN_MAX_AGE = 60 * 60 * 24 * 7; // 7 days\n\nfunction getCartCookieName(): string {\n try {\n return getConfig().cartCookieName ?? DEFAULT_CART_COOKIE;\n } catch {\n return DEFAULT_CART_COOKIE;\n }\n}\n\nfunction getAccessTokenCookieName(): string {\n try {\n return getConfig().accessTokenCookieName ?? DEFAULT_ACCESS_TOKEN_COOKIE;\n } catch {\n return DEFAULT_ACCESS_TOKEN_COOKIE;\n }\n}\n\n// --- Cart Token ---\n\nexport async function getCartToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getCartCookieName())?.value;\n}\n\nexport async function setCartToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: CART_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearCartToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getCartCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n\n// --- Access Token (JWT) ---\n\nexport async function getAccessToken(): Promise<string | undefined> {\n const cookieStore = await cookies();\n return cookieStore.get(getAccessTokenCookieName())?.value;\n}\n\nexport async function setAccessToken(token: string): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), token, {\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: ACCESS_TOKEN_MAX_AGE,\n });\n}\n\nexport async function clearAccessToken(): Promise<void> {\n const cookieStore = await cookies();\n cookieStore.set(getAccessTokenCookieName(), '', {\n maxAge: -1,\n path: '/',\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, setCartToken, clearCartToken, getAccessToken } from '../cookies';\n\n/**\n * Get the current cart. Returns null if no cart exists.\n */\nexport async function getCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) return null;\n\n try {\n return await getClient().store.cart.get({ orderToken, token });\n } catch {\n // Cart not found (e.g., order was completed) — clear stale token\n if (orderToken) {\n await clearCartToken();\n }\n return null;\n }\n}\n\n/**\n * Get existing cart or create a new one.\n * @param metadata - Optional metadata to set on the cart when creating a new one\n */\nexport async function getOrCreateCart(\n metadata?: Record<string, unknown>\n): Promise<StoreOrder & { token: string }> {\n const existing = await getCart();\n if (existing) return existing;\n\n const token = await getAccessToken();\n const cartParams = metadata ? { metadata } : undefined;\n const cart = await getClient().store.cart.create(cartParams, token ? { token } : undefined);\n\n if (cart.token) {\n await setCartToken(cart.token);\n }\n\n revalidateTag('cart');\n return cart;\n}\n\n/**\n * Add an item to the cart. Creates a cart if none exists.\n * Returns the updated order with recalculated totals.\n */\nexport async function addItem(\n variantId: string,\n quantity: number = 1,\n metadata?: Record<string, unknown>\n): Promise<StoreOrder> {\n const cart = await getOrCreateCart();\n const orderToken = cart.token;\n const token = await getAccessToken();\n\n const order = await getClient().store.orders.lineItems.create(\n cart.id,\n { variant_id: variantId, quantity, metadata },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Update a line item in the cart (quantity and/or metadata).\n * Returns the updated order with recalculated totals.\n *\n * @example\n * // Update quantity only\n * await updateItem(lineItemId, { quantity: 3 })\n *\n * // Update metadata only\n * await updateItem(lineItemId, { metadata: { gift_message: 'Happy Birthday!' } })\n *\n * // Update both\n * await updateItem(lineItemId, { quantity: 2, metadata: { engraving: 'J.D.' } })\n */\nexport async function updateItem(\n lineItemId: string,\n params: { quantity?: number; metadata?: Record<string, unknown> }\n): Promise<StoreOrder> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().store.cart.get({ orderToken, token });\n\n const order = await getClient().store.orders.lineItems.update(\n cart.id,\n lineItemId,\n params,\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Remove a line item from the cart.\n * Returns the updated order with recalculated totals.\n */\nexport async function removeItem(lineItemId: string): Promise<StoreOrder> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken && !token) throw new Error('No cart found');\n\n const cart = await getClient().store.cart.get({ orderToken, token });\n\n const order = await getClient().store.orders.lineItems.delete(cart.id, lineItemId, {\n orderToken,\n token,\n });\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Clear the cart (abandons the current cart).\n */\nexport async function clearCart(): Promise<void> {\n await clearCartToken();\n revalidateTag('cart');\n}\n\n/**\n * Associate a guest cart with the currently authenticated user.\n * Call this after login/register when the user has an existing guest cart.\n */\nexport async function associateCart(): Promise<(StoreOrder & { token: string }) | null> {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n if (!orderToken || !token) return null;\n\n try {\n const result = await getClient().store.cart.associate({ orderToken, token });\n revalidateTag('cart');\n return result;\n } catch {\n // Cart might already belong to another user — clear it\n await clearCartToken();\n revalidateTag('cart');\n return null;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreOrder, StoreShipment, AddressParams } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, getAccessToken } from '../cookies';\n\nasync function getCheckoutOptions() {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n return { orderToken, token };\n}\n\n/**\n * Get the current checkout order state.\n * Includes line_items, shipments, and addresses by default.\n */\nexport async function getCheckout(\n orderId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n return getClient().store.orders.get(\n orderId,\n { includes: 'line_items,shipments,ship_address,bill_address' },\n options\n );\n}\n\n/**\n * Update shipping and/or billing addresses on the order.\n */\nexport async function updateAddresses(\n orderId: string,\n params: {\n email?: string;\n ship_address?: AddressParams;\n bill_address?: AddressParams;\n ship_address_id?: string;\n bill_address_id?: string;\n }\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.update(orderId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Advance the checkout to the next step.\n */\nexport async function advance(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.advance(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Move the checkout to the next step (alias for advance).\n */\nexport async function next(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.next(orderId, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Get shipments for the order (includes available shipping rates).\n */\nexport async function getShipments(\n orderId: string\n): Promise<{ data: StoreShipment[] }> {\n const options = await getCheckoutOptions();\n return getClient().store.orders.shipments.list(orderId, options);\n}\n\n/**\n * Select a shipping rate for a shipment.\n * Returns the updated order with recalculated totals.\n */\nexport async function selectShippingRate(\n orderId: string,\n shipmentId: string,\n shippingRateId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.shipments.update(\n orderId,\n shipmentId,\n { selected_shipping_rate_id: shippingRateId },\n options\n );\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Apply a coupon code to the order.\n */\nexport async function applyCoupon(\n orderId: string,\n code: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.couponCodes.apply(orderId, code, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Remove a coupon/promotion from the order.\n */\nexport async function removeCoupon(\n orderId: string,\n promotionId: string\n): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.couponCodes.remove(orderId, promotionId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n\n/**\n * Complete the checkout and place the order.\n */\nexport async function complete(orderId: string): Promise<StoreOrder> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.complete(orderId, options);\n revalidateTag('checkout');\n revalidateTag('cart');\n return result;\n}\n","import { SpreeError } from '@spree/sdk';\nimport type { RequestOptions } from '@spree/sdk';\nimport { getClient } from './config';\nimport { getAccessToken, setAccessToken, clearAccessToken } from './cookies';\n\n/**\n * Get auth request options from the current JWT token.\n * Proactively refreshes the token if it expires within 1 hour.\n */\nexport async function getAuthOptions(): Promise<RequestOptions> {\n const token = await getAccessToken();\n if (!token) {\n return {};\n }\n\n // Check if token is close to expiry by decoding JWT payload\n try {\n const payload = JSON.parse(atob(token.split('.')[1]));\n const exp = payload.exp;\n const now = Math.floor(Date.now() / 1000);\n\n // Refresh if token expires in less than 1 hour\n if (exp && exp - now < 3600) {\n try {\n const refreshed = await getClient().store.auth.refresh({ token });\n await setAccessToken(refreshed.token);\n return { token: refreshed.token };\n } catch {\n // Refresh failed — use existing token, it might still work\n }\n }\n } catch {\n // Can't decode JWT — use it as-is, the server will reject if invalid\n }\n\n return { token };\n}\n\n/**\n * Execute an authenticated request with automatic token refresh on 401.\n * @param fn - Function that takes RequestOptions and returns a promise\n * @returns The result of the function\n * @throws SpreeError if auth fails after refresh attempt\n */\nexport async function withAuthRefresh<T>(\n fn: (options: RequestOptions) => Promise<T>\n): Promise<T> {\n const options = await getAuthOptions();\n\n if (!options.token) {\n throw new Error('Not authenticated');\n }\n\n try {\n return await fn(options);\n } catch (error: unknown) {\n // If 401, try refreshing the token once\n if (error instanceof SpreeError && error.status === 401) {\n try {\n const refreshed = await getClient().store.auth.refresh({ token: options.token });\n await setAccessToken(refreshed.token);\n return await fn({ token: refreshed.token });\n } catch {\n // Refresh failed — clear token and rethrow\n await clearAccessToken();\n throw error;\n }\n }\n throw error;\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCustomer } from '@spree/sdk';\nimport { getClient } from '../config';\nimport { setAccessToken, clearAccessToken, getAccessToken, getCartToken } from '../cookies';\nimport { withAuthRefresh } from '../auth-helpers';\n\n/**\n * Login with email and password.\n * Automatically associates any guest cart with the authenticated user.\n */\nexport async function login(\n email: string,\n password: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().store.auth.login({ email, password });\n await setAccessToken(result.token);\n\n // Associate guest cart if one exists\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().store.cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Cart association failure is non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Invalid email or password',\n };\n }\n}\n\n/**\n * Register a new customer account.\n * Automatically associates any guest cart with the new account.\n */\nexport async function register(\n email: string,\n password: string,\n passwordConfirmation: string\n): Promise<{ success: boolean; user?: { id: string; email: string; first_name?: string | null; last_name?: string | null }; error?: string }> {\n try {\n const result = await getClient().store.auth.register({\n email,\n password,\n password_confirmation: passwordConfirmation,\n });\n await setAccessToken(result.token);\n\n // Associate guest cart\n const cartToken = await getCartToken();\n if (cartToken) {\n try {\n await getClient().store.cart.associate({\n token: result.token,\n orderToken: cartToken,\n });\n } catch {\n // Non-fatal\n }\n }\n\n revalidateTag('customer');\n revalidateTag('cart');\n return { success: true, user: result.user };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : 'Registration failed',\n };\n }\n}\n\n/**\n * Logout the current user.\n */\nexport async function logout(): Promise<void> {\n await clearAccessToken();\n revalidateTag('customer');\n revalidateTag('cart');\n revalidateTag('addresses');\n revalidateTag('credit-cards');\n}\n\n/**\n * Get the currently authenticated customer. Returns null if not logged in.\n */\nexport async function getCustomer(): Promise<StoreCustomer | null> {\n const token = await getAccessToken();\n if (!token) return null;\n\n try {\n return await withAuthRefresh(async (options) => {\n return getClient().store.customer.get(options);\n });\n } catch {\n await clearAccessToken();\n return null;\n }\n}\n\n/**\n * Update the current customer's profile.\n */\nexport async function updateCustomer(\n data: { first_name?: string; last_name?: string; email?: string }\n): Promise<StoreCustomer> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().store.customer.update(data, options);\n });\n revalidateTag('customer');\n return result;\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreAddress, AddressParams } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's addresses.\n */\nexport async function listAddresses(): Promise<{ data: StoreAddress[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.list(undefined, options);\n });\n}\n\n/**\n * Get a single address by ID.\n */\nexport async function getAddress(id: string): Promise<StoreAddress> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.get(id, options);\n });\n}\n\n/**\n * Create a new address for the customer.\n */\nexport async function createAddress(params: AddressParams): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.create(params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Update an existing address.\n */\nexport async function updateAddress(\n id: string,\n params: Partial<AddressParams>\n): Promise<StoreAddress> {\n const result = await withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.update(id, params, options);\n });\n revalidateTag('addresses');\n return result;\n}\n\n/**\n * Delete an address.\n */\nexport async function deleteAddress(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().store.customer.addresses.delete(id, options);\n });\n revalidateTag('addresses');\n}\n","'use server';\n\nimport type { StoreOrder, PaginatedResponse, OrderListParams } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's orders.\n */\nexport async function listOrders(\n params?: OrderListParams\n): Promise<PaginatedResponse<StoreOrder>> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.orders.list(params, options);\n });\n}\n\n/**\n * Get a single order by ID or number.\n */\nexport async function getOrder(\n idOrNumber: string,\n params?: Record<string, unknown>\n): Promise<StoreOrder> {\n return withAuthRefresh(async (options) => {\n return getClient().store.orders.get(idOrNumber, params, options);\n });\n}\n","'use server';\n\nimport { cookies } from 'next/headers';\nimport { getConfig } from '../config';\n\n/**\n * Set locale/country cookies for subsequent requests.\n * Use this in country/language switchers instead of manipulating cookies directly.\n */\nexport async function setLocale(params: {\n country?: string;\n locale?: string;\n}): Promise<void> {\n const config = getConfig();\n const cookieStore = await cookies();\n const maxAge = 60 * 60 * 24 * 365; // 1 year\n\n if (params.country) {\n cookieStore.set(config.countryCookieName ?? 'spree_country', params.country, {\n path: '/',\n maxAge,\n });\n }\n if (params.locale) {\n cookieStore.set(config.localeCookieName ?? 'spree_locale', params.locale, {\n path: '/',\n maxAge,\n });\n }\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type { StoreCreditCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's credit cards.\n */\nexport async function listCreditCards(): Promise<{ data: StoreCreditCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.creditCards.list(undefined, options);\n });\n}\n\n/**\n * Delete a credit card.\n */\nexport async function deleteCreditCard(id: string): Promise<void> {\n await withAuthRefresh(async (options) => {\n return getClient().store.customer.creditCards.delete(id, options);\n });\n revalidateTag('credit-cards');\n}\n","'use server';\n\nimport type { StoreGiftCard } from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * List the authenticated customer's gift cards.\n */\nexport async function listGiftCards(): Promise<{ data: StoreGiftCard[] }> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.giftCards.list(undefined, options);\n });\n}\n\n/**\n * Get a single gift card by ID.\n */\nexport async function getGiftCard(id: string): Promise<StoreGiftCard> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.giftCards.get(id, options);\n });\n}\n","'use server';\n\nimport { revalidateTag } from 'next/cache';\nimport type {\n StorePaymentSession,\n CreatePaymentSessionParams,\n UpdatePaymentSessionParams,\n CompletePaymentSessionParams,\n} from '@spree/sdk';\nimport { getClient } from '../config';\nimport { getCartToken, getAccessToken } from '../cookies';\n\nasync function getCheckoutOptions() {\n const orderToken = await getCartToken();\n const token = await getAccessToken();\n return { orderToken, token };\n}\n\n/**\n * Create a payment session for an order.\n * Delegates to the payment gateway to initialize a provider-specific session.\n */\nexport async function createPaymentSession(\n orderId: string,\n params: CreatePaymentSessionParams\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.paymentSessions.create(orderId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Get a payment session by ID.\n */\nexport async function getPaymentSession(\n orderId: string,\n sessionId: string\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n return getClient().store.orders.paymentSessions.get(orderId, sessionId, options);\n}\n\n/**\n * Update a payment session.\n * Delegates to the payment gateway to sync changes with the provider.\n */\nexport async function updatePaymentSession(\n orderId: string,\n sessionId: string,\n params: UpdatePaymentSessionParams\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.paymentSessions.update(orderId, sessionId, params, options);\n revalidateTag('checkout');\n return result;\n}\n\n/**\n * Complete a payment session.\n * Confirms the payment with the provider, triggering capture/authorization.\n */\nexport async function completePaymentSession(\n orderId: string,\n sessionId: string,\n params?: CompletePaymentSessionParams\n): Promise<StorePaymentSession> {\n const options = await getCheckoutOptions();\n const result = await getClient().store.orders.paymentSessions.complete(orderId, sessionId, params, options);\n revalidateTag('checkout');\n return result;\n}\n","'use server';\n\nimport type {\n StorePaymentSetupSession,\n CreatePaymentSetupSessionParams,\n CompletePaymentSetupSessionParams,\n} from '@spree/sdk';\nimport { withAuthRefresh } from '../auth-helpers';\nimport { getClient } from '../config';\n\n/**\n * Create a payment setup session for saving a payment method.\n * Delegates to the payment gateway to initialize a setup flow.\n */\nexport async function createPaymentSetupSession(\n params: CreatePaymentSetupSessionParams\n): Promise<StorePaymentSetupSession> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.paymentSetupSessions.create(params, options);\n });\n}\n\n/**\n * Get a payment setup session by ID.\n */\nexport async function getPaymentSetupSession(\n id: string\n): Promise<StorePaymentSetupSession> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.paymentSetupSessions.get(id, options);\n });\n}\n\n/**\n * Complete a payment setup session.\n * Confirms the setup with the provider, resulting in a saved payment method.\n */\nexport async function completePaymentSetupSession(\n id: string,\n params?: CompletePaymentSetupSessionParams\n): Promise<StorePaymentSetupSession> {\n return withAuthRefresh(async (options) => {\n return getClient().store.customer.paymentSetupSessions.complete(id, params, options);\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spree/next",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Next.js integration for Spree Commerce — server actions, caching, and cookie-based auth",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,7 +62,7 @@
62
62
  "url": "https://github.com/spree/spree/issues"
63
63
  },
64
64
  "peerDependencies": {
65
- "@spree/sdk": ">=0.6.2",
65
+ "@spree/sdk": ">=0.6.3",
66
66
  "next": ">=15.0.0",
67
67
  "react": ">=19.0.0"
68
68
  },