@spree/next 0.4.0 → 0.6.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vendo Connect Inc., Vendo Sp. z o.o.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -94,7 +94,7 @@ Plain async functions for reading data in Server Components. Wrap with `"use cac
94
94
  import { listProducts, getProduct, getProductFilters } from '@spree/next';
95
95
 
96
96
  const products = await listProducts({ per_page: 25, includes: 'variants,images' });
97
- const product = await getProduct('ruby-on-rails-tote');
97
+ const product = await getProduct('spree-tote');
98
98
  const filters = await getProductFilters({ taxon_id: 'txn_123' });
99
99
  ```
100
100
 
@@ -133,8 +133,9 @@ import { getCart, getOrCreateCart, addItem, updateItem, removeItem, clearCart }
133
133
 
134
134
  const cart = await getCart();
135
135
  const cart = await getOrCreateCart();
136
- await addItem(variantId, quantity);
137
- await updateItem(lineItemId, quantity);
136
+ await addItem(variantId, quantity, { gift_message: 'Happy Birthday!' });
137
+ await updateItem(lineItemId, { quantity: 3 });
138
+ await updateItem(lineItemId, { metadata: { engraving: 'J.D.' } });
138
139
  await removeItem(lineItemId);
139
140
  await clearCart();
140
141
  ```
@@ -8,20 +8,34 @@ declare function getCart(): Promise<(StoreOrder & {
8
8
  }) | null>;
9
9
  /**
10
10
  * Get existing cart or create a new one.
11
+ * @param metadata - Optional metadata to set on the cart when creating a new one
11
12
  */
12
- declare function getOrCreateCart(): Promise<StoreOrder & {
13
+ declare function getOrCreateCart(metadata?: Record<string, unknown>): Promise<StoreOrder & {
13
14
  token: string;
14
15
  }>;
15
16
  /**
16
17
  * Add an item to the cart. Creates a cart if none exists.
17
18
  * Returns the updated order with recalculated totals.
18
19
  */
19
- declare function addItem(variantId: string, quantity?: number): Promise<StoreOrder>;
20
+ declare function addItem(variantId: string, quantity?: number, metadata?: Record<string, unknown>): Promise<StoreOrder>;
20
21
  /**
21
- * Update a line item quantity in the cart.
22
+ * Update a line item in the cart (quantity and/or metadata).
22
23
  * Returns the updated order with recalculated totals.
24
+ *
25
+ * @example
26
+ * // Update quantity only
27
+ * await updateItem(lineItemId, { quantity: 3 })
28
+ *
29
+ * // Update metadata only
30
+ * await updateItem(lineItemId, { metadata: { gift_message: 'Happy Birthday!' } })
31
+ *
32
+ * // Update both
33
+ * await updateItem(lineItemId, { quantity: 2, metadata: { engraving: 'J.D.' } })
23
34
  */
24
- declare function updateItem(lineItemId: string, quantity: number): Promise<StoreOrder>;
35
+ declare function updateItem(lineItemId: string, params: {
36
+ quantity?: number;
37
+ metadata?: Record<string, unknown>;
38
+ }): Promise<StoreOrder>;
25
39
  /**
26
40
  * Remove a line item from the cart.
27
41
  * Returns the updated order with recalculated totals.
@@ -95,30 +95,31 @@ async function getCart() {
95
95
  return null;
96
96
  }
97
97
  }
98
- async function getOrCreateCart() {
98
+ async function getOrCreateCart(metadata) {
99
99
  const existing = await getCart();
100
100
  if (existing) return existing;
101
101
  const token = await getAccessToken();
102
- const cart = await getClient().store.cart.create(token ? { token } : void 0);
102
+ const cartParams = metadata ? { metadata } : void 0;
103
+ const cart = await getClient().store.cart.create(cartParams, token ? { token } : void 0);
103
104
  if (cart.token) {
104
105
  await setCartToken(cart.token);
105
106
  }
106
107
  revalidateTag("cart");
107
108
  return cart;
108
109
  }
109
- async function addItem(variantId, quantity = 1) {
110
+ async function addItem(variantId, quantity = 1, metadata) {
110
111
  const cart = await getOrCreateCart();
111
112
  const orderToken = cart.token;
112
113
  const token = await getAccessToken();
113
114
  const order = await getClient().store.orders.lineItems.create(
114
115
  cart.id,
115
- { variant_id: variantId, quantity },
116
+ { variant_id: variantId, quantity, metadata },
116
117
  { orderToken, token }
117
118
  );
118
119
  revalidateTag("cart");
119
120
  return order;
120
121
  }
121
- async function updateItem(lineItemId, quantity) {
122
+ async function updateItem(lineItemId, params) {
122
123
  const orderToken = await getCartToken();
123
124
  const token = await getAccessToken();
124
125
  if (!orderToken && !token) throw new Error("No cart found");
@@ -126,7 +127,7 @@ async function updateItem(lineItemId, quantity) {
126
127
  const order = await getClient().store.orders.lineItems.update(
127
128
  cart.id,
128
129
  lineItemId,
129
- { quantity },
130
+ params,
130
131
  { orderToken, token }
131
132
  );
132
133
  revalidateTag("cart");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/actions/cart.ts","../../src/config.ts","../../src/cookies.ts"],"sourcesContent":["'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 */\nexport async function getOrCreateCart(): Promise<StoreOrder & { token: string }> {\n const existing = await getCart();\n if (existing) return existing;\n\n const token = await getAccessToken();\n const cart = await getClient().store.cart.create(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): 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 },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Update a line item quantity in the cart.\n * Returns the updated order with recalculated totals.\n */\nexport async function updateItem(\n lineItemId: string,\n quantity: number\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 { quantity },\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","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_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"],"mappings":";;;AAEA,SAAS,qBAAqB;;;ACF9B,SAAS,yBAA2C;AAGpD,IAAI,UAA8B;AAClC,IAAI,UAAkC;AAO/B,SAAS,cAAc,QAA+B;AAC3D,YAAU;AACV,YAAU,kBAAkB;AAAA,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,UAAU,EAAE,MAAM,KAAK,IAAI,EAAE,YAAY,MAAM,CAAC;AAEnE,QAAM,QAAQ,MAAM,UAAU,EAAE,MAAM,OAAO,UAAU;AAAA,IACrD,KAAK;AAAA,IACL;AAAA,IACA,EAAE,SAAS;AAAA,IACX,EAAE,YAAY,MAAM;AAAA,EACtB;AAEA,gBAAc,MAAM;AACpB,SAAO;AACT;AAMA,eAAsB,WAAW,YAAyC;AACxE,QAAM,aAAa,MAAM,aAAa;AACtC,QAAM,QAAQ,MAAM,eAAe;AACnC,MAAI,CAAC,cAAc,CAAC,MAAO,OAAM,IAAI,MAAM,eAAe;AAE1D,QAAM,OAAO,MAAM,UAAU,EAAE,MAAM,KAAK,IAAI,EAAE,YAAY,MAAM,CAAC;AAEnE,QAAM,QAAQ,MAAM,UAAU,EAAE,MAAM,OAAO,UAAU,OAAO,KAAK,IAAI,YAAY;AAAA,IACjF;AAAA,IACA;AAAA,EACF,CAAC;AAED,gBAAc,MAAM;AACpB,SAAO;AACT;AAKA,eAAsB,YAA2B;AAC/C,QAAM,eAAe;AACrB,gBAAc,MAAM;AACtB;AAMA,eAAsB,gBAAkE;AACtF,QAAM,aAAa,MAAM,aAAa;AACtC,QAAM,QAAQ,MAAM,eAAe;AACnC,MAAI,CAAC,cAAc,CAAC,MAAO,QAAO;AAElC,MAAI;AACF,UAAM,SAAS,MAAM,UAAU,EAAE,MAAM,KAAK,UAAU,EAAE,YAAY,MAAM,CAAC;AAC3E,kBAAc,MAAM;AACpB,WAAO;AAAA,EACT,QAAQ;AAEN,UAAM,eAAe;AACrB,kBAAc,MAAM;AACpB,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/actions/cart.ts","../../src/config.ts","../../src/cookies.ts"],"sourcesContent":["'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","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_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"],"mappings":";;;AAEA,SAAS,qBAAqB;;;ACF9B,SAAS,yBAA2C;AAGpD,IAAI,UAA8B;AAClC,IAAI,UAAkC;AAO/B,SAAS,cAAc,QAA+B;AAC3D,YAAU;AACV,YAAU,kBAAkB;AAAA,IAC1B,SAAS,OAAO;AAAA,IAChB,gBAAgB,OAAO;AAAA,EACzB,CAAC;AACH;AAMO,SAAS,YAAyB;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,UAAU,QAAQ,IAAI;AAC5B,UAAM,iBAAiB,QAAQ,IAAI;AACnC,QAAI,WAAW,gBAAgB;AAC7B,oBAAc,EAAE,SAAS,eAAe,CAAC;AAAA,IAC3C,OAAO;AACL,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAMO,SAAS,YAA6B;AAC3C,MAAI,CAAC,SAAS;AACZ,cAAU;AAAA,EACZ;AACA,SAAO;AACT;;;AC/CA,SAAS,eAAe;AAGxB,IAAM,sBAAsB;AAC5B,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAE5C,SAAS,oBAA4B;AACnC,MAAI;AACF,WAAO,UAAU,EAAE,kBAAkB;AAAA,EACvC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,2BAAmC;AAC1C,MAAI;AACF,WAAO,UAAU,EAAE,yBAAyB;AAAA,EAC9C,QAAQ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BAAkE;AACtF,QAAM,aAAa,MAAM,aAAa;AACtC,QAAM,QAAQ,MAAM,eAAe;AACnC,MAAI,CAAC,cAAc,CAAC,MAAO,QAAO;AAElC,MAAI;AACF,UAAM,SAAS,MAAM,UAAU,EAAE,MAAM,KAAK,UAAU,EAAE,YAAY,MAAM,CAAC;AAC3E,kBAAc,MAAM;AACpB,WAAO;AAAA,EACT,QAAQ;AAEN,UAAM,eAAe;AACrB,kBAAc,MAAM;AACpB,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,20 @@
1
+ import { StoreCountry } from '@spree/sdk';
2
+ import { SpreeNextOptions } from '../types.js';
3
+
4
+ /**
5
+ * List countries available in the store.
6
+ * Each country includes currency and default_locale derived from its market.
7
+ */
8
+ declare function listCountries(options?: SpreeNextOptions): Promise<{
9
+ data: StoreCountry[];
10
+ }>;
11
+ /**
12
+ * Get a country by ISO code.
13
+ * @param iso - ISO 3166-1 alpha-2 code (e.g., "US", "DE")
14
+ * @param params - Optional params (e.g., { include: 'states' } for address forms)
15
+ */
16
+ declare function getCountry(iso: string, params?: {
17
+ include?: string;
18
+ }, options?: SpreeNextOptions): Promise<StoreCountry>;
19
+
20
+ export { getCountry, listCountries };
@@ -0,0 +1,42 @@
1
+ import { createSpreeClient } from '@spree/sdk';
2
+
3
+ // src/config.ts
4
+ var _client = null;
5
+ function initSpreeNext(config) {
6
+ _client = createSpreeClient({
7
+ baseUrl: config.baseUrl,
8
+ publishableKey: config.publishableKey
9
+ });
10
+ }
11
+ function getClient() {
12
+ if (!_client) {
13
+ const baseUrl = process.env.SPREE_API_URL;
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
+ } else {
18
+ throw new Error(
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
+ );
21
+ }
22
+ }
23
+ return _client;
24
+ }
25
+
26
+ // src/data/countries.ts
27
+ async function listCountries(options) {
28
+ return getClient().store.countries.list({
29
+ locale: options?.locale,
30
+ currency: options?.currency
31
+ });
32
+ }
33
+ async function getCountry(iso, params, options) {
34
+ return getClient().store.countries.get(iso, params, {
35
+ locale: options?.locale,
36
+ currency: options?.currency
37
+ });
38
+ }
39
+
40
+ export { getCountry, listCountries };
41
+ //# sourceMappingURL=countries.js.map
42
+ //# sourceMappingURL=countries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config.ts","../../src/data/countries.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC5BA,eAAsB,cACpB,OAAA,EACmC;AACnC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,SAAA,CAAU,IAAA,CAAK;AAAA,IACtC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAOA,eAAsB,UAAA,CACpB,GAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,SAAA,CAAU,GAAA,CAAI,KAAK,MAAA,EAAQ;AAAA,IAClD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","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 type { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\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 */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().store.countries.list({\n locale: options?.locale,\n currency: options?.currency,\n });\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 */\nexport async function getCountry(\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().store.countries.get(iso, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { StoreCurrency } from '@spree/sdk';
2
+ import { SpreeNextOptions } from '../types.js';
3
+
4
+ /**
5
+ * List currencies supported by the store (derived from markets).
6
+ */
7
+ declare function listCurrencies(options?: SpreeNextOptions): Promise<{
8
+ data: StoreCurrency[];
9
+ }>;
10
+
11
+ export { listCurrencies };
@@ -0,0 +1,36 @@
1
+ import { createSpreeClient } from '@spree/sdk';
2
+
3
+ // src/config.ts
4
+ var _client = null;
5
+ function initSpreeNext(config) {
6
+ _client = createSpreeClient({
7
+ baseUrl: config.baseUrl,
8
+ publishableKey: config.publishableKey
9
+ });
10
+ }
11
+ function getClient() {
12
+ if (!_client) {
13
+ const baseUrl = process.env.SPREE_API_URL;
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
+ } else {
18
+ throw new Error(
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
+ );
21
+ }
22
+ }
23
+ return _client;
24
+ }
25
+
26
+ // src/data/currencies.ts
27
+ async function listCurrencies(options) {
28
+ return getClient().store.currencies.list({
29
+ locale: options?.locale,
30
+ currency: options?.currency
31
+ });
32
+ }
33
+
34
+ export { listCurrencies };
35
+ //# sourceMappingURL=currencies.js.map
36
+ //# sourceMappingURL=currencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config.ts","../../src/data/currencies.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,eACpB,OAAA,EACoC;AACpC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,UAAA,CAAW,IAAA,CAAK;AAAA,IACvC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"currencies.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreCurrency } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List currencies supported by the store (derived from markets).\n */\nexport async function listCurrencies(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCurrency[] }> {\n return getClient().store.currencies.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { StoreLocale } from '@spree/sdk';
2
+ import { SpreeNextOptions } from '../types.js';
3
+
4
+ /**
5
+ * List locales supported by the store (derived from markets).
6
+ */
7
+ declare function listLocales(options?: SpreeNextOptions): Promise<{
8
+ data: StoreLocale[];
9
+ }>;
10
+
11
+ export { listLocales };
@@ -0,0 +1,36 @@
1
+ import { createSpreeClient } from '@spree/sdk';
2
+
3
+ // src/config.ts
4
+ var _client = null;
5
+ function initSpreeNext(config) {
6
+ _client = createSpreeClient({
7
+ baseUrl: config.baseUrl,
8
+ publishableKey: config.publishableKey
9
+ });
10
+ }
11
+ function getClient() {
12
+ if (!_client) {
13
+ const baseUrl = process.env.SPREE_API_URL;
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
+ } else {
18
+ throw new Error(
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
+ );
21
+ }
22
+ }
23
+ return _client;
24
+ }
25
+
26
+ // src/data/locales.ts
27
+ async function listLocales(options) {
28
+ return getClient().store.locales.list({
29
+ locale: options?.locale,
30
+ currency: options?.currency
31
+ });
32
+ }
33
+
34
+ export { listLocales };
35
+ //# sourceMappingURL=locales.js.map
36
+ //# sourceMappingURL=locales.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config.ts","../../src/data/locales.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,YACpB,OAAA,EACkC;AAClC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK;AAAA,IACpC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"locales.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreLocale } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List locales supported by the store (derived from markets).\n */\nexport async function listLocales(\n options?: SpreeNextOptions\n): Promise<{ data: StoreLocale[] }> {\n return getClient().store.locales.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -4,9 +4,11 @@ export { getProduct, getProductFilters, listProducts } from './data/products.js'
4
4
  export { getTaxon, listTaxonProducts, listTaxons } from './data/taxons.js';
5
5
  export { getTaxonomy, listTaxonomies } from './data/taxonomies.js';
6
6
  export { getStore } from './data/store.js';
7
- export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket } from './data/markets.js';
7
+ export { getCountry, listCountries } from './data/countries.js';
8
+ export { listCurrencies } from './data/currencies.js';
9
+ export { listLocales } from './data/locales.js';
8
10
  import { StoreOrder, StoreShipment, AddressParams, StoreCustomer, StoreAddress, PaginatedResponse, StoreCreditCard, StoreGiftCard, CompletePaymentSessionParams, StorePaymentSession, CreatePaymentSessionParams, UpdatePaymentSessionParams, CompletePaymentSetupSessionParams, StorePaymentSetupSession, CreatePaymentSetupSessionParams } from '@spree/sdk';
9
- export { AddressParams, CompletePaymentSessionParams, CompletePaymentSetupSessionParams, CreatePaymentSessionParams, CreatePaymentSetupSessionParams, PaginatedResponse, ProductFiltersResponse, SpreeError, StoreAddress, StoreCountry, StoreCreditCard, StoreCustomer, StoreDigitalLink, StoreGiftCard, StoreImage, StoreLineItem, StoreMarket, StoreOptionType, StoreOptionValue, StoreOrder, StoreOrderPromotion, StorePayment, StorePaymentMethod, StorePaymentSession, StorePaymentSetupSession, StorePrice, StoreProduct, StoreShipment, StoreShippingRate, StoreStore, StoreTaxon, StoreTaxonomy, StoreVariant, UpdatePaymentSessionParams } 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';
10
12
 
11
13
  /**
12
14
  * Get the current cart. Returns null if no cart exists.
@@ -16,20 +18,34 @@ declare function getCart(): Promise<(StoreOrder & {
16
18
  }) | null>;
17
19
  /**
18
20
  * Get existing cart or create a new one.
21
+ * @param metadata - Optional metadata to set on the cart when creating a new one
19
22
  */
20
- declare function getOrCreateCart(): Promise<StoreOrder & {
23
+ declare function getOrCreateCart(metadata?: Record<string, unknown>): Promise<StoreOrder & {
21
24
  token: string;
22
25
  }>;
23
26
  /**
24
27
  * Add an item to the cart. Creates a cart if none exists.
25
28
  * Returns the updated order with recalculated totals.
26
29
  */
27
- declare function addItem(variantId: string, quantity?: number): Promise<StoreOrder>;
30
+ declare function addItem(variantId: string, quantity?: number, metadata?: Record<string, unknown>): Promise<StoreOrder>;
28
31
  /**
29
- * Update a line item quantity in the cart.
32
+ * Update a line item in the cart (quantity and/or metadata).
30
33
  * Returns the updated order with recalculated totals.
31
- */
32
- declare function updateItem(lineItemId: string, quantity: number): Promise<StoreOrder>;
34
+ *
35
+ * @example
36
+ * // Update quantity only
37
+ * await updateItem(lineItemId, { quantity: 3 })
38
+ *
39
+ * // Update metadata only
40
+ * await updateItem(lineItemId, { metadata: { gift_message: 'Happy Birthday!' } })
41
+ *
42
+ * // Update both
43
+ * await updateItem(lineItemId, { quantity: 2, metadata: { engraving: 'J.D.' } })
44
+ */
45
+ declare function updateItem(lineItemId: string, params: {
46
+ quantity?: number;
47
+ metadata?: Record<string, unknown>;
48
+ }): Promise<StoreOrder>;
33
49
  /**
34
50
  * Remove a line item from the cart.
35
51
  * Returns the updated order with recalculated totals.
package/dist/index.js CHANGED
@@ -95,33 +95,31 @@ async function getStore(options) {
95
95
  });
96
96
  }
97
97
 
98
- // src/data/markets.ts
99
- async function listMarkets(options) {
100
- return getClient().store.markets.list({
98
+ // src/data/countries.ts
99
+ async function listCountries(options) {
100
+ return getClient().store.countries.list({
101
101
  locale: options?.locale,
102
102
  currency: options?.currency
103
103
  });
104
104
  }
105
- async function getMarket(id, options) {
106
- return getClient().store.markets.get(id, {
105
+ async function getCountry(iso, params, options) {
106
+ return getClient().store.countries.get(iso, params, {
107
107
  locale: options?.locale,
108
108
  currency: options?.currency
109
109
  });
110
110
  }
111
- async function resolveMarket(countryIso, options) {
112
- return getClient().store.markets.resolve(countryIso, {
113
- locale: options?.locale,
114
- currency: options?.currency
115
- });
116
- }
117
- async function listMarketCountries(marketId, options) {
118
- return getClient().store.markets.countries.list(marketId, {
111
+
112
+ // src/data/currencies.ts
113
+ async function listCurrencies(options) {
114
+ return getClient().store.currencies.list({
119
115
  locale: options?.locale,
120
116
  currency: options?.currency
121
117
  });
122
118
  }
123
- async function getMarketCountry(marketId, iso, options) {
124
- return getClient().store.markets.countries.get(marketId, iso, {
119
+
120
+ // src/data/locales.ts
121
+ async function listLocales(options) {
122
+ return getClient().store.locales.list({
125
123
  locale: options?.locale,
126
124
  currency: options?.currency
127
125
  });
@@ -201,30 +199,31 @@ async function getCart() {
201
199
  return null;
202
200
  }
203
201
  }
204
- async function getOrCreateCart() {
202
+ async function getOrCreateCart(metadata) {
205
203
  const existing = await getCart();
206
204
  if (existing) return existing;
207
205
  const token = await getAccessToken();
208
- const cart = await getClient().store.cart.create(token ? { token } : void 0);
206
+ const cartParams = metadata ? { metadata } : void 0;
207
+ const cart = await getClient().store.cart.create(cartParams, token ? { token } : void 0);
209
208
  if (cart.token) {
210
209
  await setCartToken(cart.token);
211
210
  }
212
211
  revalidateTag("cart");
213
212
  return cart;
214
213
  }
215
- async function addItem(variantId, quantity = 1) {
214
+ async function addItem(variantId, quantity = 1, metadata) {
216
215
  const cart = await getOrCreateCart();
217
216
  const orderToken = cart.token;
218
217
  const token = await getAccessToken();
219
218
  const order = await getClient().store.orders.lineItems.create(
220
219
  cart.id,
221
- { variant_id: variantId, quantity },
220
+ { variant_id: variantId, quantity, metadata },
222
221
  { orderToken, token }
223
222
  );
224
223
  revalidateTag("cart");
225
224
  return order;
226
225
  }
227
- async function updateItem(lineItemId, quantity) {
226
+ async function updateItem(lineItemId, params) {
228
227
  const orderToken = await getCartToken();
229
228
  const token = await getAccessToken();
230
229
  if (!orderToken && !token) throw new Error("No cart found");
@@ -232,7 +231,7 @@ async function updateItem(lineItemId, quantity) {
232
231
  const order = await getClient().store.orders.lineItems.update(
233
232
  cart.id,
234
233
  lineItemId,
235
- { quantity },
234
+ params,
236
235
  { orderToken, token }
237
236
  );
238
237
  revalidateTag("cart");
@@ -567,6 +566,6 @@ async function completePaymentSetupSession(id, params) {
567
566
  });
568
567
  }
569
568
 
570
- export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getClient, getCustomer, getGiftCard, getMarket, getMarketCountry, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getProduct, getProductFilters, getShipments, getStore, getTaxon, getTaxonomy, initSpreeNext, listAddresses, listCreditCards, listGiftCards, listMarketCountries, listMarkets, listOrders, listProducts, listTaxonProducts, listTaxonomies, listTaxons, login, logout, next, register, removeCoupon, removeItem, resolveMarket, selectShippingRate, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };
569
+ export { addItem, advance, applyCoupon, associateCart, clearCart, complete, completePaymentSession, completePaymentSetupSession, createAddress, createPaymentSession, createPaymentSetupSession, deleteAddress, deleteCreditCard, getAddress, getCart, getCheckout, getClient, getCountry, getCustomer, getGiftCard, getOrCreateCart, getOrder, getPaymentSession, getPaymentSetupSession, getProduct, getProductFilters, getShipments, getStore, getTaxon, getTaxonomy, initSpreeNext, listAddresses, listCountries, listCreditCards, listCurrencies, listGiftCards, listLocales, listOrders, listProducts, listTaxonProducts, listTaxonomies, listTaxons, login, logout, next, register, removeCoupon, removeItem, selectShippingRate, updateAddress, updateAddresses, updateCustomer, updateItem, updatePaymentSession };
571
570
  //# sourceMappingURL=index.js.map
572
571
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts","../src/data/products.ts","../src/data/taxons.ts","../src/data/taxonomies.ts","../src/data/store.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/credit-cards.ts","../src/actions/gift-cards.ts","../src/actions/payment-sessions.ts","../src/actions/payment-setup-sessions.ts"],"names":["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;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;;;ACxCA,eAAsB,YAAA,CACpB,QACA,OAAA,EAC0C;AAC1C,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,QAAA,CAAS,KAAK,MAAA,EAAQ;AAAA,IAC7C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,UAAA,CACpB,QAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,OAAO,W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AM,SAAA,EAAU,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 type { StoreProduct, PaginatedResponse, ProductFiltersResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n */\nexport async function listProducts(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.products.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single product by slug or ID.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n return getClient().store.products.get(slugOrId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n return getClient().store.products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxon, StoreProduct, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n */\nexport async function listTaxons(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxon>> {\n return getClient().store.taxons.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxon by ID or permalink.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxon> {\n return getClient().store.taxons.get(idOrPermalink, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List products within a taxon.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.taxons.products.list(taxonId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().store.taxonomies.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxonomy by ID.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n return getClient().store.taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreMarket, StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List all markets with their countries.\n * Used to build a country/currency switcher.\n */\nexport async function listMarkets(\n options?: SpreeNextOptions\n): Promise<{ data: StoreMarket[] }> {\n return getClient().store.markets.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single market by prefixed ID.\n */\nexport async function getMarket(\n id: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n return getClient().store.markets.get(id, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Resolve which market a country belongs to.\n * @param countryIso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n */\nexport async function resolveMarket(\n countryIso: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n return getClient().store.markets.resolve(countryIso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List countries in a market's zone (for checkout address forms).\n */\nexport async function listMarketCountries(\n marketId: string,\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().store.markets.countries.list(marketId, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a country by ISO code with states (for address form validation).\n */\nexport async function getMarketCountry(\n marketId: string,\n iso: string,\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().store.markets.countries.get(marketId, iso, {\n locale: options?.locale,\n currency: options?.currency,\n });\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 */\nexport async function getOrCreateCart(): Promise<StoreOrder & { token: string }> {\n const existing = await getCart();\n if (existing) return existing;\n\n const token = await getAccessToken();\n const cart = await getClient().store.cart.create(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): 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 },\n { orderToken, token }\n );\n\n revalidateTag('cart');\n return order;\n}\n\n/**\n * Update a line item quantity in the cart.\n * Returns the updated order with recalculated totals.\n */\nexport async function updateItem(\n lineItemId: string,\n quantity: number\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 { quantity },\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 } 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?: Record<string, unknown>\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 { 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/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/credit-cards.ts","../src/actions/gift-cards.ts","../src/actions/payment-sessions.ts","../src/actions/payment-setup-sessions.ts"],"names":["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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gB,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 type { StoreProduct, PaginatedResponse, ProductFiltersResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n */\nexport async function listProducts(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.products.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single product by slug or ID.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n return getClient().store.products.get(slugOrId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n return getClient().store.products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxon, StoreProduct, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxons (categories) with optional filtering and pagination.\n */\nexport async function listTaxons(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxon>> {\n return getClient().store.taxons.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxon by ID or permalink.\n */\nexport async function getTaxon(\n idOrPermalink: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxon> {\n return getClient().store.taxons.get(idOrPermalink, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List products within a taxon.\n */\nexport async function listTaxonProducts(\n taxonId: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.taxons.products.list(taxonId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().store.taxonomies.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxonomy by ID.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n return getClient().store.taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\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 */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().store.countries.list({\n locale: options?.locale,\n currency: options?.currency,\n });\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 */\nexport async function getCountry(\n iso: string,\n params?: { include?: string },\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().store.countries.get(iso, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreCurrency } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List currencies supported by the store (derived from markets).\n */\nexport async function listCurrencies(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCurrency[] }> {\n return getClient().store.currencies.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","import type { StoreLocale } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List locales supported by the store (derived from markets).\n */\nexport async function listLocales(\n options?: SpreeNextOptions\n): Promise<{ data: StoreLocale[] }> {\n return getClient().store.locales.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n","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 } 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?: Record<string, unknown>\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 { 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.4.0",
3
+ "version": "0.6.0",
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",
@@ -55,7 +55,7 @@
55
55
  "url": "https://github.com/spree/spree/issues"
56
56
  },
57
57
  "peerDependencies": {
58
- "@spree/sdk": ">=0.4.0",
58
+ "@spree/sdk": ">=0.6.0",
59
59
  "next": ">=15.0.0",
60
60
  "react": ">=19.0.0"
61
61
  },
@@ -1,31 +0,0 @@
1
- import { StoreMarket, StoreCountry } from '@spree/sdk';
2
- import { SpreeNextOptions } from '../types.js';
3
-
4
- /**
5
- * List all markets with their countries.
6
- * Used to build a country/currency switcher.
7
- */
8
- declare function listMarkets(options?: SpreeNextOptions): Promise<{
9
- data: StoreMarket[];
10
- }>;
11
- /**
12
- * Get a single market by prefixed ID.
13
- */
14
- declare function getMarket(id: string, options?: SpreeNextOptions): Promise<StoreMarket>;
15
- /**
16
- * Resolve which market a country belongs to.
17
- * @param countryIso - ISO 3166-1 alpha-2 code (e.g., "US", "DE")
18
- */
19
- declare function resolveMarket(countryIso: string, options?: SpreeNextOptions): Promise<StoreMarket>;
20
- /**
21
- * List countries in a market's zone (for checkout address forms).
22
- */
23
- declare function listMarketCountries(marketId: string, options?: SpreeNextOptions): Promise<{
24
- data: StoreCountry[];
25
- }>;
26
- /**
27
- * Get a country by ISO code with states (for address form validation).
28
- */
29
- declare function getMarketCountry(marketId: string, iso: string, options?: SpreeNextOptions): Promise<StoreCountry>;
30
-
31
- export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket };
@@ -1,60 +0,0 @@
1
- import { createSpreeClient } from '@spree/sdk';
2
-
3
- // src/config.ts
4
- var _client = null;
5
- function initSpreeNext(config) {
6
- _client = createSpreeClient({
7
- baseUrl: config.baseUrl,
8
- publishableKey: config.publishableKey
9
- });
10
- }
11
- function getClient() {
12
- if (!_client) {
13
- const baseUrl = process.env.SPREE_API_URL;
14
- const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
- if (baseUrl && publishableKey) {
16
- initSpreeNext({ baseUrl, publishableKey });
17
- } else {
18
- throw new Error(
19
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
- );
21
- }
22
- }
23
- return _client;
24
- }
25
-
26
- // src/data/markets.ts
27
- async function listMarkets(options) {
28
- return getClient().store.markets.list({
29
- locale: options?.locale,
30
- currency: options?.currency
31
- });
32
- }
33
- async function getMarket(id, options) {
34
- return getClient().store.markets.get(id, {
35
- locale: options?.locale,
36
- currency: options?.currency
37
- });
38
- }
39
- async function resolveMarket(countryIso, options) {
40
- return getClient().store.markets.resolve(countryIso, {
41
- locale: options?.locale,
42
- currency: options?.currency
43
- });
44
- }
45
- async function listMarketCountries(marketId, options) {
46
- return getClient().store.markets.countries.list(marketId, {
47
- locale: options?.locale,
48
- currency: options?.currency
49
- });
50
- }
51
- async function getMarketCountry(marketId, iso, options) {
52
- return getClient().store.markets.countries.get(marketId, iso, {
53
- locale: options?.locale,
54
- currency: options?.currency
55
- });
56
- }
57
-
58
- export { getMarket, getMarketCountry, listMarketCountries, listMarkets, resolveMarket };
59
- //# sourceMappingURL=markets.js.map
60
- //# sourceMappingURL=markets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/markets.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;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,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,gBAAA,CACpB,QAAA,EACA,GAAA,EACA,OAAA,EACuB;AACvB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,QAAQ,SAAA,CAAU,GAAA,CAAI,UAAU,GAAA,EAAK;AAAA,IAC5D,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","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 type { StoreMarket, StoreCountry } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List all markets with their countries.\n * Used to build a country/currency switcher.\n */\nexport async function listMarkets(\n options?: SpreeNextOptions\n): Promise<{ data: StoreMarket[] }> {\n return getClient().store.markets.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single market by prefixed ID.\n */\nexport async function getMarket(\n id: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n return getClient().store.markets.get(id, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Resolve which market a country belongs to.\n * @param countryIso - ISO 3166-1 alpha-2 code (e.g., \"US\", \"DE\")\n */\nexport async function resolveMarket(\n countryIso: string,\n options?: SpreeNextOptions\n): Promise<StoreMarket> {\n return getClient().store.markets.resolve(countryIso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * List countries in a market's zone (for checkout address forms).\n */\nexport async function listMarketCountries(\n marketId: string,\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().store.markets.countries.list(marketId, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a country by ISO code with states (for address form validation).\n */\nexport async function getMarketCountry(\n marketId: string,\n iso: string,\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().store.markets.countries.get(marketId, iso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}