@spree/next 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,18 +14,18 @@ function initSpreeNext(config) {
14
14
  _config = config;
15
15
  _client = createSpreeClient({
16
16
  baseUrl: config.baseUrl,
17
- apiKey: config.apiKey
17
+ publishableKey: config.publishableKey
18
18
  });
19
19
  }
20
20
  function getClient() {
21
21
  if (!_client) {
22
22
  const baseUrl = process.env.SPREE_API_URL;
23
- const apiKey = process.env.SPREE_API_KEY;
24
- if (baseUrl && apiKey) {
25
- initSpreeNext({ baseUrl, apiKey });
23
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
24
+ if (baseUrl && publishableKey) {
25
+ initSpreeNext({ baseUrl, publishableKey });
26
26
  } else {
27
27
  throw new Error(
28
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
28
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
29
29
  );
30
30
  }
31
31
  }
@@ -84,7 +84,7 @@ async function getAuthOptions() {
84
84
  const now = Math.floor(Date.now() / 1e3);
85
85
  if (exp && exp - now < 3600) {
86
86
  try {
87
- const refreshed = await getClient().auth.refresh({ token });
87
+ const refreshed = await getClient().store.auth.refresh({ token });
88
88
  await setAccessToken(refreshed.token);
89
89
  return { token: refreshed.token };
90
90
  } catch {
@@ -104,7 +104,7 @@ async function withAuthRefresh(fn) {
104
104
  } catch (error) {
105
105
  if (error instanceof SpreeError && error.status === 401) {
106
106
  try {
107
- const refreshed = await getClient().auth.refresh({ token: options.token });
107
+ const refreshed = await getClient().store.auth.refresh({ token: options.token });
108
108
  await setAccessToken(refreshed.token);
109
109
  return await fn({ token: refreshed.token });
110
110
  } catch {
@@ -119,12 +119,12 @@ async function withAuthRefresh(fn) {
119
119
  // src/actions/credit-cards.ts
120
120
  async function listCreditCards() {
121
121
  return withAuthRefresh(async (options) => {
122
- return getClient().customer.creditCards.list(void 0, options);
122
+ return getClient().store.customer.creditCards.list(void 0, options);
123
123
  });
124
124
  }
125
125
  async function deleteCreditCard(id) {
126
126
  await withAuthRefresh(async (options) => {
127
- return getClient().customer.creditCards.delete(id, options);
127
+ return getClient().store.customer.creditCards.delete(id, options);
128
128
  });
129
129
  revalidateTag("credit-cards");
130
130
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/actions/credit-cards.ts","../../src/auth-helpers.ts","../../src/config.ts","../../src/cookies.ts"],"sourcesContent":["'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().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().customer.creditCards.delete(id, options);\n });\n revalidateTag('credit-cards');\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().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().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","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_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_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(getAccessT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wD;AAC5E,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,SAAS,YAAY,KAAK,QAAW,OAAO;AAAA,EACjE,CAAC;AACH;AAKA,eAAsB,iBAAiB,IAA2B;AAChE,QAAM,gBAAgB,OAAO,YAAY;AACvC,WAAO,UAAU,EAAE,SAAS,YAAY,OAAO,IAAI,OAAO;AAAA,EAC5D,CAAC;AACD,gBAAc,cAAc;AAC9B;","names":[]}
1
+ {"version":3,"sources":["../../src/actions/credit-cards.ts","../../src/auth-helpers.ts","../../src/config.ts","../../src/cookies.ts"],"sourcesContent":["'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","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","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,kBAAkB;;;ACA3B,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;AAIxB,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAU5C,SAAS,2BAAmC;AAC1C,MAAI;AACF,WAAO,UAAU,EAAE,yBAAyB;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA8BA,eAAsB,iBAA8C;AAClE,QAAM,cAAc,MAAM,QAAQ;AAClC,SAAO,YAAY,IAAI,yBAAyB,CAAC,GAAG;AACtD;AAEA,eAAsB,eAAe,OAA8B;AACjE,QAAM,cAAc,MAAM,QAAQ;AAClC,cAAY,IAAI,yBAAyB,GAAG,OAAO;AAAA,IACjD,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,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B;AACvB,cAAM;AAAA,MACR;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACF;;;AD5DA,eAAsB,kBAAwD;AAC5E,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,SAAS,YAAY,KAAK,QAAW,OAAO;AAAA,EACvE,CAAC;AACH;AAKA,eAAsB,iBAAiB,IAA2B;AAChE,QAAM,gBAAgB,OAAO,YAAY;AACvC,WAAO,UAAU,EAAE,MAAM,SAAS,YAAY,OAAO,IAAI,OAAO;AAAA,EAClE,CAAC;AACD,gBAAc,cAAc;AAC9B;","names":[]}
@@ -11,18 +11,18 @@ function initSpreeNext(config) {
11
11
  _config = config;
12
12
  _client = createSpreeClient({
13
13
  baseUrl: config.baseUrl,
14
- apiKey: config.apiKey
14
+ publishableKey: config.publishableKey
15
15
  });
16
16
  }
17
17
  function getClient() {
18
18
  if (!_client) {
19
19
  const baseUrl = process.env.SPREE_API_URL;
20
- const apiKey = process.env.SPREE_API_KEY;
21
- if (baseUrl && apiKey) {
22
- initSpreeNext({ baseUrl, apiKey });
20
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
21
+ if (baseUrl && publishableKey) {
22
+ initSpreeNext({ baseUrl, publishableKey });
23
23
  } else {
24
24
  throw new Error(
25
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
25
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
26
26
  );
27
27
  }
28
28
  }
@@ -81,7 +81,7 @@ async function getAuthOptions() {
81
81
  const now = Math.floor(Date.now() / 1e3);
82
82
  if (exp && exp - now < 3600) {
83
83
  try {
84
- const refreshed = await getClient().auth.refresh({ token });
84
+ const refreshed = await getClient().store.auth.refresh({ token });
85
85
  await setAccessToken(refreshed.token);
86
86
  return { token: refreshed.token };
87
87
  } catch {
@@ -101,7 +101,7 @@ async function withAuthRefresh(fn) {
101
101
  } catch (error) {
102
102
  if (error instanceof SpreeError && error.status === 401) {
103
103
  try {
104
- const refreshed = await getClient().auth.refresh({ token: options.token });
104
+ const refreshed = await getClient().store.auth.refresh({ token: options.token });
105
105
  await setAccessToken(refreshed.token);
106
106
  return await fn({ token: refreshed.token });
107
107
  } catch {
@@ -116,12 +116,12 @@ async function withAuthRefresh(fn) {
116
116
  // src/actions/gift-cards.ts
117
117
  async function listGiftCards() {
118
118
  return withAuthRefresh(async (options) => {
119
- return getClient().customer.giftCards.list(void 0, options);
119
+ return getClient().store.customer.giftCards.list(void 0, options);
120
120
  });
121
121
  }
122
122
  async function getGiftCard(id) {
123
123
  return withAuthRefresh(async (options) => {
124
- return getClient().customer.giftCards.get(id, options);
124
+ return getClient().store.customer.giftCards.get(id, options);
125
125
  });
126
126
  }
127
127
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/auth-helpers.ts","../../src/config.ts","../../src/cookies.ts","../../src/actions/gift-cards.ts"],"sourcesContent":["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().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().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","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_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_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","'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().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().customer.giftCards.get(id, options);\n });\n}\n"],"mappings":";;;AAAA,SAAS,kBAAkB;;;ACA3B,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,QAAQ,OAAO;AAAA,EACjB,CAAC;AACH;AAMO,SAAS,YAAyB;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,UAAU,QAAQ,IAAI;AAC5B,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,WAAW,QAAQ;AACrB,oBAAc,EAAE,SAAS,OAAO,CAAC;AAAA,IACnC,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;AAIxB,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAU5C,SAAS,2BAAmC;AAC1C,MAAI;AACF,WAAO,UAAU,EAAE,yBAAyB;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA8BA,eAAsB,iBAA8C;AAClE,QAAM,cAAc,MAAM,QAAQ;AAClC,SAAO,YAAY,IAAI,yBAAyB,CAAC,GAAG;AACtD;AAEA,eAAsB,eAAe,OAA8B;AACjE,QAAM,cAAc,MAAM,QA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eAAe,UAAU,KAAK;AACpC,eAAO,MAAM,GAAG,EAAE,OAAO,UAAU,MAAM,CAAC;AAAA,MAC5C,QAAQ;AAEN,cAAM,iBAAiB;AACvB,cAAM;AAAA,MACR;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACF;;;AG7DA,eAAsB,gBAAoD;AACxE,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,SAAS,UAAU,KAAK,QAAW,OAAO;AAAA,EAC/D,CAAC;AACH;AAKA,eAAsB,YAAY,IAAoC;AACpE,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,SAAS,UAAU,IAAI,IAAI,OAAO;AAAA,EACvD,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/auth-helpers.ts","../../src/config.ts","../../src/cookies.ts","../../src/actions/gift-cards.ts"],"sourcesContent":["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","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","'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"],"mappings":";;;AAAA,SAAS,kBAAkB;;;ACA3B,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;AAIxB,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAU5C,SAAS,2BAAmC;AAC1C,MAAI;AACF,WAAO,UAAU,EAAE,yBAAyB;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA8BA,eAAsB,iBAA8C;AAClE,QAAM,cAAc,MAAM,QAAQ;AAClC,SAAO,YAAY,IAAI,yBAAyB,CAAC,GAAG;AACtD;AAEA,eAAsB,eAAe,OAA8B;AACjE,QAAM,cAAc,MAAM,QAAQ;AAClC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M,eAAe,UAAU,KAAK;AACpC,eAAO,MAAM,GAAG,EAAE,OAAO,UAAU,MAAM,CAAC;AAAA,MAC5C,QAAQ;AAEN,cAAM,iBAAiB;AACvB,cAAM;AAAA,MACR;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACF;;;AG7DA,eAAsB,gBAAoD;AACxE,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,SAAS,UAAU,KAAK,QAAW,OAAO;AAAA,EACrE,CAAC;AACH;AAKA,eAAsB,YAAY,IAAoC;AACpE,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,SAAS,UAAU,IAAI,IAAI,OAAO;AAAA,EAC7D,CAAC;AACH;","names":[]}
@@ -11,18 +11,18 @@ function initSpreeNext(config) {
11
11
  _config = config;
12
12
  _client = createSpreeClient({
13
13
  baseUrl: config.baseUrl,
14
- apiKey: config.apiKey
14
+ publishableKey: config.publishableKey
15
15
  });
16
16
  }
17
17
  function getClient() {
18
18
  if (!_client) {
19
19
  const baseUrl = process.env.SPREE_API_URL;
20
- const apiKey = process.env.SPREE_API_KEY;
21
- if (baseUrl && apiKey) {
22
- initSpreeNext({ baseUrl, apiKey });
20
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
21
+ if (baseUrl && publishableKey) {
22
+ initSpreeNext({ baseUrl, publishableKey });
23
23
  } else {
24
24
  throw new Error(
25
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
25
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
26
26
  );
27
27
  }
28
28
  }
@@ -81,7 +81,7 @@ async function getAuthOptions() {
81
81
  const now = Math.floor(Date.now() / 1e3);
82
82
  if (exp && exp - now < 3600) {
83
83
  try {
84
- const refreshed = await getClient().auth.refresh({ token });
84
+ const refreshed = await getClient().store.auth.refresh({ token });
85
85
  await setAccessToken(refreshed.token);
86
86
  return { token: refreshed.token };
87
87
  } catch {
@@ -101,7 +101,7 @@ async function withAuthRefresh(fn) {
101
101
  } catch (error) {
102
102
  if (error instanceof SpreeError && error.status === 401) {
103
103
  try {
104
- const refreshed = await getClient().auth.refresh({ token: options.token });
104
+ const refreshed = await getClient().store.auth.refresh({ token: options.token });
105
105
  await setAccessToken(refreshed.token);
106
106
  return await fn({ token: refreshed.token });
107
107
  } catch {
@@ -116,12 +116,12 @@ async function withAuthRefresh(fn) {
116
116
  // src/actions/orders.ts
117
117
  async function listOrders(params) {
118
118
  return withAuthRefresh(async (options) => {
119
- return getClient().orders.list(params, options);
119
+ return getClient().store.orders.list(params, options);
120
120
  });
121
121
  }
122
122
  async function getOrder(idOrNumber, params) {
123
123
  return withAuthRefresh(async (options) => {
124
- return getClient().orders.get(idOrNumber, params, options);
124
+ return getClient().store.orders.get(idOrNumber, params, options);
125
125
  });
126
126
  }
127
127
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/auth-helpers.ts","../../src/config.ts","../../src/cookies.ts","../../src/actions/orders.ts"],"sourcesContent":["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().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().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","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_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_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","'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().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().orders.get(idOrNumber, params, options);\n });\n}\n"],"mappings":";;;AAAA,SAAS,kBAAkB;;;ACA3B,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,QAAQ,OAAO;AAAA,EACjB,CAAC;AACH;AAMO,SAAS,YAAyB;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,UAAU,QAAQ,IAAI;AAC5B,UAAM,SAAS,QAAQ,IAAI;AAC3B,QAAI,WAAW,QAAQ;AACrB,oBAAc,EAAE,SAAS,OAAO,CAAC;AAAA,IACnC,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;AAIxB,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAU5C,SAAS,2BAAmC;AAC1C,MAAI;AACF,WAAO,UAAU,EAAE,yBAAyB;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA8BA,eAAsB,iBAA8C;AAClE,QAAM,cAA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AM,WAAW,KAAK;AACvD,UAAI;AACF,cAAM,YAAY,MAAM,UAAU,EAAE,KAAK,QAAQ,EAAE,OAAO,QAAQ,MAAM,CAAC;AACzE,cAAM,eAAe,UAAU,KAAK;AACpC,eAAO,MAAM,GAAG,EAAE,OAAO,UAAU,MAAM,CAAC;AAAA,MAC5C,QAAQ;AAEN,cAAM,iBAAiB;AACvB,cAAM;AAAA,MACR;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACF;;;AG7DA,eAAsB,WACpB,QACwC;AACxC,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,OAAO,KAAK,QAAQ,OAAO;AAAA,EAChD,CAAC;AACH;AAKA,eAAsB,SACpB,YACA,QACqB;AACrB,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,OAAO,IAAI,YAAY,QAAQ,OAAO;AAAA,EAC3D,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../src/auth-helpers.ts","../../src/config.ts","../../src/cookies.ts","../../src/actions/orders.ts"],"sourcesContent":["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","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","'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.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"],"mappings":";;;AAAA,SAAS,kBAAkB;;;ACA3B,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;AAIxB,IAAM,8BAA8B;AACpC,IAAM,qBAAqB,KAAK,KAAK,KAAK;AAC1C,IAAM,uBAAuB,KAAK,KAAK,KAAK;AAU5C,SAAS,2BAAmC;AAC1C,MAAI;AACF,WAAO,UAAU,EAAE,yBAAyB;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AA8BA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OAAgB;AAEvB,QAAI,iBAAiB,cAAc,MAAM,WAAW,KAAK;AACvD,UAAI;AACF,cAAM,YAAY,MAAM,UAAU,EAAE,MAAM,KAAK,QAAQ,EAAE,OAAO,QAAQ,MAAM,CAAC;AAC/E,cAAM,eAAe,UAAU,KAAK;AACpC,eAAO,MAAM,GAAG,EAAE,OAAO,UAAU,MAAM,CAAC;AAAA,MAC5C,QAAQ;AAEN,cAAM,iBAAiB;AACvB,cAAM;AAAA,MACR;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACF;;;AG7DA,eAAsB,WACpB,QACwC;AACxC,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,OAAO,KAAK,QAAQ,OAAO;AAAA,EACtD,CAAC;AACH;AAKA,eAAsB,SACpB,YACA,QACqB;AACrB,SAAO,gBAAgB,OAAO,YAAY;AACxC,WAAO,UAAU,EAAE,MAAM,OAAO,IAAI,YAAY,QAAQ,OAAO;AAAA,EACjE,CAAC;AACH;","names":[]}
package/dist/config.d.ts CHANGED
@@ -4,7 +4,7 @@ import { SpreeNextConfig } from './types.js';
4
4
  /**
5
5
  * Initialize the Spree Next.js integration.
6
6
  * Call this once in your app (e.g., in `lib/storefront.ts`).
7
- * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.
7
+ * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.
8
8
  */
9
9
  declare function initSpreeNext(config: SpreeNextConfig): void;
10
10
  /**
package/dist/config.js CHANGED
@@ -7,18 +7,18 @@ function initSpreeNext(config) {
7
7
  _config = config;
8
8
  _client = createSpreeClient({
9
9
  baseUrl: config.baseUrl,
10
- apiKey: config.apiKey
10
+ publishableKey: config.publishableKey
11
11
  });
12
12
  }
13
13
  function getClient() {
14
14
  if (!_client) {
15
15
  const baseUrl = process.env.SPREE_API_URL;
16
- const apiKey = process.env.SPREE_API_KEY;
17
- if (baseUrl && apiKey) {
18
- initSpreeNext({ baseUrl, apiKey });
16
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
17
+ if (baseUrl && publishableKey) {
18
+ initSpreeNext({ baseUrl, publishableKey });
19
19
  } else {
20
20
  throw new Error(
21
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
21
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
22
22
  );
23
23
  }
24
24
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ,CAAA;AAAA,IACnC,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;AAMO,SAAS,WAAA,GAAoB;AAClC,EAAA,OAAA,GAAU,IAAA;AACV,EAAA,OAAA,GAAU,IAAA;AACZ","file":"config.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_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_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"]}
1
+ {"version":3,"sources":["../src/config.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAClC,IAAI,OAAA,GAAkC,IAAA;AAO/B,SAAS,cAAc,MAAA,EAA+B;AAC3D,EAAA,OAAA,GAAU,MAAA;AACV,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,SAAA,GAA6B;AAC3C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,SAAA,EAAU;AAAA,EACZ;AACA,EAAA,OAAO,OAAA;AACT;AAMO,SAAS,WAAA,GAAoB;AAClC,EAAA,OAAA,GAAU,IAAA;AACV,EAAA,OAAA,GAAU,IAAA;AACZ","file":"config.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"]}
@@ -5,18 +5,18 @@ var _client = null;
5
5
  function initSpreeNext(config) {
6
6
  _client = createSpreeClient({
7
7
  baseUrl: config.baseUrl,
8
- apiKey: config.apiKey
8
+ publishableKey: config.publishableKey
9
9
  });
10
10
  }
11
11
  function getClient() {
12
12
  if (!_client) {
13
13
  const baseUrl = process.env.SPREE_API_URL;
14
- const apiKey = process.env.SPREE_API_KEY;
15
- if (baseUrl && apiKey) {
16
- initSpreeNext({ baseUrl, apiKey });
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
17
  } else {
18
18
  throw new Error(
19
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
20
  );
21
21
  }
22
22
  }
@@ -25,13 +25,13 @@ function getClient() {
25
25
 
26
26
  // src/data/countries.ts
27
27
  async function listCountries(options) {
28
- return getClient().countries.list({
28
+ return getClient().store.countries.list({
29
29
  locale: options?.locale,
30
30
  currency: options?.currency
31
31
  });
32
32
  }
33
33
  async function getCountry(iso, options) {
34
- return getClient().countries.get(iso, {
34
+ return getClient().store.countries.get(iso, {
35
35
  locale: options?.locale,
36
36
  currency: options?.currency
37
37
  });
@@ -1 +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,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ,CAAA;AAAA,IACnC,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,cACpB,OAAA,EACmC;AACnC,EAAA,OAAO,SAAA,EAAU,CAAE,SAAA,CAAU,IAAA,CAAK;AAAA,IAChC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,UAAA,CACpB,KACA,OAAA,EACuB;AACvB,EAAA,OAAO,SAAA,EAAU,CAAE,SAAA,CAAU,GAAA,CAAI,GAAA,EAAK;AAAA,IACpC,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_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_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 all available countries.\n */\nexport async function listCountries(\n options?: SpreeNextOptions\n): Promise<{ data: StoreCountry[] }> {\n return getClient().countries.list({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single country by ISO code.\n */\nexport async function getCountry(\n iso: string,\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().countries.get(iso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
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;;;AC7BA,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;AAKA,eAAsB,UAAA,CACpB,KACA,OAAA,EACuB;AACvB,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,SAAA,CAAU,IAAI,GAAA,EAAK;AAAA,IAC1C,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 all available countries.\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 single country by ISO code.\n */\nexport async function getCountry(\n iso: string,\n options?: SpreeNextOptions\n): Promise<StoreCountry> {\n return getClient().store.countries.get(iso, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
@@ -5,18 +5,18 @@ var _client = null;
5
5
  function initSpreeNext(config) {
6
6
  _client = createSpreeClient({
7
7
  baseUrl: config.baseUrl,
8
- apiKey: config.apiKey
8
+ publishableKey: config.publishableKey
9
9
  });
10
10
  }
11
11
  function getClient() {
12
12
  if (!_client) {
13
13
  const baseUrl = process.env.SPREE_API_URL;
14
- const apiKey = process.env.SPREE_API_KEY;
15
- if (baseUrl && apiKey) {
16
- initSpreeNext({ baseUrl, apiKey });
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
17
  } else {
18
18
  throw new Error(
19
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
20
  );
21
21
  }
22
22
  }
@@ -25,19 +25,19 @@ function getClient() {
25
25
 
26
26
  // src/data/products.ts
27
27
  async function listProducts(params, options) {
28
- return getClient().products.list(params, {
28
+ return getClient().store.products.list(params, {
29
29
  locale: options?.locale,
30
30
  currency: options?.currency
31
31
  });
32
32
  }
33
33
  async function getProduct(slugOrId, params, options) {
34
- return getClient().products.get(slugOrId, params, {
34
+ return getClient().store.products.get(slugOrId, params, {
35
35
  locale: options?.locale,
36
36
  currency: options?.currency
37
37
  });
38
38
  }
39
39
  async function getProductFilters(params, options) {
40
- return getClient().products.filters(params, {
40
+ return getClient().store.products.filters(params, {
41
41
  locale: options?.locale,
42
42
  currency: options?.currency
43
43
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/products.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ,CAAA;AAAA,IACnC,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,YAAA,CACpB,QACA,OAAA,EAC0C;AAC1C,EAAA,OAAO,SAAA,EAAU,CAAE,QAAA,CAAS,IAAA,CAAK,MAAA,EAAQ;AAAA,IACvC,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,SAAA,EAAU,CAAE,QAAA,CAAS,GAAA,CAAI,UAAU,MAAA,EAAQ;AAAA,IAChD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,iBAAA,CACpB,QACA,OAAA,EACiC;AACjC,EAAA,OAAO,SAAA,EAAU,CAAE,QAAA,CAAS,OAAA,CAAQ,MAAA,EAAQ;AAAA,IAC1C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"products.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_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().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().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().products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/data/products.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,YAAA,CACpB,QACA,OAAA,EAC0C;AAC1C,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,QAAA,CAAS,KAAK,MAAA,EAAQ;AAAA,IAC7C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,UAAA,CACpB,QAAA,EACA,MAAA,EACA,OAAA,EACuB;AACvB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,QAAA,CAAS,GAAA,CAAI,UAAU,MAAA,EAAQ;AAAA,IACtD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,iBAAA,CACpB,QACA,OAAA,EACiC;AACjC,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,QAAA,CAAS,QAAQ,MAAA,EAAQ;AAAA,IAChD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"products.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreProduct, PaginatedResponse, ProductFiltersResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List products with optional filtering, sorting, and pagination.\n */\nexport async function listProducts(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreProduct>> {\n return getClient().store.products.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single product by slug or ID.\n */\nexport async function getProduct(\n slugOrId: string,\n params?: { includes?: string },\n options?: SpreeNextOptions\n): Promise<StoreProduct> {\n return getClient().store.products.get(slugOrId, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get available product filters (price ranges, option values, etc.).\n */\nexport async function getProductFilters(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<ProductFiltersResponse> {\n return getClient().store.products.filters(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
@@ -5,18 +5,18 @@ var _client = null;
5
5
  function initSpreeNext(config) {
6
6
  _client = createSpreeClient({
7
7
  baseUrl: config.baseUrl,
8
- apiKey: config.apiKey
8
+ publishableKey: config.publishableKey
9
9
  });
10
10
  }
11
11
  function getClient() {
12
12
  if (!_client) {
13
13
  const baseUrl = process.env.SPREE_API_URL;
14
- const apiKey = process.env.SPREE_API_KEY;
15
- if (baseUrl && apiKey) {
16
- initSpreeNext({ baseUrl, apiKey });
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
17
  } else {
18
18
  throw new Error(
19
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
20
  );
21
21
  }
22
22
  }
@@ -25,7 +25,7 @@ function getClient() {
25
25
 
26
26
  // src/data/store.ts
27
27
  async function getStore(options) {
28
- return getClient().store.get({
28
+ return getClient().store.store.get({
29
29
  locale: options?.locale,
30
30
  currency: options?.currency
31
31
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/store.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ,CAAA;AAAA,IACnC,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,SAAS,OAAA,EAAiD;AAC9E,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,GAAA,CAAI;AAAA,IAC3B,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"store.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/data/store.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,SAAS,OAAA,EAAiD;AAC9E,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,KAAA,CAAM,GAAA,CAAI;AAAA,IACjC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"store.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreStore } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * Get the current store configuration.\n */\nexport async function getStore(options?: SpreeNextOptions): Promise<StoreStore> {\n return getClient().store.store.get({\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
@@ -5,18 +5,18 @@ var _client = null;
5
5
  function initSpreeNext(config) {
6
6
  _client = createSpreeClient({
7
7
  baseUrl: config.baseUrl,
8
- apiKey: config.apiKey
8
+ publishableKey: config.publishableKey
9
9
  });
10
10
  }
11
11
  function getClient() {
12
12
  if (!_client) {
13
13
  const baseUrl = process.env.SPREE_API_URL;
14
- const apiKey = process.env.SPREE_API_KEY;
15
- if (baseUrl && apiKey) {
16
- initSpreeNext({ baseUrl, apiKey });
14
+ const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;
15
+ if (baseUrl && publishableKey) {
16
+ initSpreeNext({ baseUrl, publishableKey });
17
17
  } else {
18
18
  throw new Error(
19
- "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables."
19
+ "@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables."
20
20
  );
21
21
  }
22
22
  }
@@ -25,13 +25,13 @@ function getClient() {
25
25
 
26
26
  // src/data/taxonomies.ts
27
27
  async function listTaxonomies(params, options) {
28
- return getClient().taxonomies.list(params, {
28
+ return getClient().store.taxonomies.list(params, {
29
29
  locale: options?.locale,
30
30
  currency: options?.currency
31
31
  });
32
32
  }
33
33
  async function getTaxonomy(id, params, options) {
34
- return getClient().taxonomies.get(id, params, {
34
+ return getClient().store.taxonomies.get(id, params, {
35
35
  locale: options?.locale,
36
36
  currency: options?.currency
37
37
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts","../../src/data/taxonomies.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO;AAAA,GAChB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,MAAA,GAAS,QAAQ,GAAA,CAAI,aAAA;AAC3B,IAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,MAAA,EAAQ,CAAA;AAAA,IACnC,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,cAAA,CACpB,QACA,OAAA,EAC2C;AAC3C,EAAA,OAAO,SAAA,EAAU,CAAE,UAAA,CAAW,IAAA,CAAK,MAAA,EAAQ;AAAA,IACzC,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,WAAA,CACpB,EAAA,EACA,MAAA,EACA,OAAA,EACwB;AACxB,EAAA,OAAO,SAAA,EAAU,CAAE,UAAA,CAAW,GAAA,CAAI,IAAI,MAAA,EAAQ;AAAA,IAC5C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"taxonomies.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_API_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\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 apiKey = process.env.SPREE_API_KEY;\n if (baseUrl && apiKey) {\n initSpreeNext({ baseUrl, apiKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_API_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().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().taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/config.ts","../../src/data/taxonomies.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAA8B,IAAA;AAQ3B,SAAS,cAAc,MAAA,EAA+B;AAE3D,EAAA,OAAA,GAAU,iBAAA,CAAkB;AAAA,IAC1B,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,gBAAgB,MAAA,CAAO;AAAA,GACxB,CAAA;AACH;AAMO,SAAS,SAAA,GAAyB;AACvC,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,OAAA,GAAU,QAAQ,GAAA,CAAI,aAAA;AAC5B,IAAA,MAAM,cAAA,GAAiB,QAAQ,GAAA,CAAI,qBAAA;AACnC,IAAA,IAAI,WAAW,cAAA,EAAgB;AAC7B,MAAA,aAAA,CAAc,EAAE,OAAA,EAAS,cAAA,EAAgB,CAAA;AAAA,IAC3C,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;AC7BA,eAAsB,cAAA,CACpB,QACA,OAAA,EAC2C;AAC3C,EAAA,OAAO,SAAA,EAAU,CAAE,KAAA,CAAM,UAAA,CAAW,KAAK,MAAA,EAAQ;AAAA,IAC/C,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH;AAKA,eAAsB,WAAA,CACpB,EAAA,EACA,MAAA,EACA,OAAA,EACwB;AACxB,EAAA,OAAO,WAAU,CAAE,KAAA,CAAM,UAAA,CAAW,GAAA,CAAI,IAAI,MAAA,EAAQ;AAAA,IAClD,QAAQ,OAAA,EAAS,MAAA;AAAA,IACjB,UAAU,OAAA,EAAS;AAAA,GACpB,CAAA;AACH","file":"taxonomies.js","sourcesContent":["import { createSpreeClient, type SpreeClient } from '@spree/sdk';\nimport type { SpreeNextConfig } from './types';\n\nlet _client: SpreeClient | null = null;\nlet _config: SpreeNextConfig | null = null;\n\n/**\n * Initialize the Spree Next.js integration.\n * Call this once in your app (e.g., in `lib/storefront.ts`).\n * If not called, the client will auto-initialize from SPREE_API_URL and SPREE_PUBLISHABLE_KEY env vars.\n */\nexport function initSpreeNext(config: SpreeNextConfig): void {\n _config = config;\n _client = createSpreeClient({\n baseUrl: config.baseUrl,\n publishableKey: config.publishableKey,\n });\n}\n\n/**\n * Get the SpreeClient instance. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getClient(): SpreeClient {\n if (!_client) {\n const baseUrl = process.env.SPREE_API_URL;\n const publishableKey = process.env.SPREE_PUBLISHABLE_KEY;\n if (baseUrl && publishableKey) {\n initSpreeNext({ baseUrl, publishableKey });\n } else {\n throw new Error(\n '@spree/next is not configured. Either call initSpreeNext() or set SPREE_API_URL and SPREE_PUBLISHABLE_KEY environment variables.'\n );\n }\n }\n return _client!;\n}\n\n/**\n * Get the current config. Auto-initializes from env vars if needed.\n * @internal\n */\nexport function getConfig(): SpreeNextConfig {\n if (!_config) {\n getClient(); // triggers auto-init\n }\n return _config!;\n}\n\n/**\n * Reset the client (useful for testing).\n * @internal\n */\nexport function resetClient(): void {\n _client = null;\n _config = null;\n}\n","import type { StoreTaxonomy, PaginatedResponse } from '@spree/sdk';\nimport { getClient } from '../config';\nimport type { SpreeNextOptions } from '../types';\n\n/**\n * List taxonomies with optional filtering and pagination.\n */\nexport async function listTaxonomies(\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<PaginatedResponse<StoreTaxonomy>> {\n return getClient().store.taxonomies.list(params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n\n/**\n * Get a single taxonomy by ID.\n */\nexport async function getTaxonomy(\n id: string,\n params?: Record<string, unknown>,\n options?: SpreeNextOptions\n): Promise<StoreTaxonomy> {\n return getClient().store.taxonomies.get(id, params, {\n locale: options?.locale,\n currency: options?.currency,\n });\n}\n"]}