@commercengine/storefront-sdk-nextjs 0.2.9 → 0.3.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/dist/client.d.mts CHANGED
@@ -1,11 +1,11 @@
1
- import { c as NextJSTokenStorageOptions, i as initializeStorefrontSDK, n as StorefrontRuntimeConfig, r as getStorefrontSDK, s as ClientTokenStorage, t as NextJSSDKConfig } from "./manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKOptions, TokenStorage } from "@commercengine/storefront-sdk";
1
+ import { a as initializeStorefrontSDK, i as getSessionStorefrontSDK, l as ClientTokenStorage, n as StorefrontRuntimeConfig, r as getPublicStorefrontSDK, t as NextJSSDKConfig, u as NextJSTokenStorageOptions } from "./manager.mjs";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, SessionStorefrontSDKOptions, StoreConfigClient, TokenStorage } from "@commercengine/storefront-sdk";
3
3
 
4
4
  //#region src/initializer.d.ts
5
5
  interface StorefrontSDKInitializerProps {
6
6
  /**
7
7
  * Optional runtime configuration overrides for client-side API calls
8
- * These settings will apply to all client-side storefront() calls
8
+ * These settings will apply to all client-side `storefront.session()` calls
9
9
  */
10
10
  runtimeConfig?: StorefrontRuntimeConfig;
11
11
  }
@@ -13,4 +13,4 @@ declare function StorefrontSDKInitializer({
13
13
  runtimeConfig
14
14
  }?: StorefrontSDKInitializerProps): null;
15
15
  //#endregion
16
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, type StorefrontSDKOptions, type TokenStorage, getStorefrontSDK, initializeStorefrontSDK };
16
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, type SessionStorefrontSDKOptions, StoreConfigClient, StorefrontSDKInitializer, type TokenStorage, getPublicStorefrontSDK, getSessionStorefrontSDK, initializeStorefrontSDK };
package/dist/client.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
 
3
- import { a as ClientTokenStorage, n as initializeStorefrontSDK, t as getStorefrontSDK } from "./manager.mjs";
3
+ import { i as setGlobalStorefrontConfig, n as getSessionStorefrontSDK, o as ClientTokenStorage, r as initializeStorefrontSDK, t as getPublicStorefrontSDK } from "./manager.mjs";
4
4
  import { useEffect } from "react";
5
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
5
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient } from "@commercengine/storefront-sdk";
6
6
 
7
7
  //#region src/initializer.tsx
8
8
  /**
@@ -23,19 +23,19 @@ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieToken
23
23
  * No manual token creation needed - just make API calls and everything works!
24
24
  */
25
25
  /**
26
- * Bootstrap tokens by checking if access token exists and creating anonymous token if needed
26
+ * Bootstrap the client-side session if no access token exists yet.
27
27
  */
28
- async function bootstrapTokens() {
29
- const sdk = getStorefrontSDK();
30
- if (!await sdk.getAccessToken()) await sdk.auth.getAnonymousToken();
28
+ async function bootstrapSession() {
29
+ await getSessionStorefrontSDK().ensureAccessToken();
31
30
  }
32
31
  function StorefrontSDKInitializer({ runtimeConfig } = {}) {
33
32
  useEffect(() => {
34
- initializeStorefrontSDK();
35
- bootstrapTokens().catch(console.error);
33
+ if (runtimeConfig) setGlobalStorefrontConfig(runtimeConfig);
34
+ else initializeStorefrontSDK();
35
+ bootstrapSession().catch(console.error);
36
36
  }, [runtimeConfig]);
37
37
  return null;
38
38
  }
39
39
 
40
40
  //#endregion
41
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, getStorefrontSDK, initializeStorefrontSDK };
41
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient, StorefrontSDKInitializer, getPublicStorefrontSDK, getSessionStorefrontSDK, initializeStorefrontSDK };
package/dist/index.d.mts CHANGED
@@ -1,18 +1,26 @@
1
- import { n as StorefrontRuntimeConfig } from "./manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDK as StorefrontSDK$1 } from "@commercengine/storefront-sdk";
1
+ import { n as StorefrontRuntimeConfig, o as NextCookieStore } from "./manager.mjs";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, PublicStorefrontSDK as PublicStorefrontSDK$1, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, SessionStorefrontSDK as SessionStorefrontSDK$1, StoreConfigClient } from "@commercengine/storefront-sdk";
3
3
  export * from "@commercengine/storefront-sdk";
4
4
 
5
5
  //#region src/storefront.d.ts
6
- type NextCookieStore = {
7
- get: (name: string) => {
8
- name: string;
9
- value: string;
10
- } | undefined;
11
- set: (name: string, value: string, opts?: Record<string, unknown>) => void;
12
- delete: (name: string) => void;
6
+
7
+ /**
8
+ * Next.js storefront factory returned by `createStorefront()`.
9
+ *
10
+ * Usage:
11
+ * - `storefront.public()` for build/prerender-safe public reads
12
+ * - `storefront.session()` in Client Components
13
+ * - `storefront.session(cookies())` in server request contexts
14
+ */
15
+ type NextJSStorefront = {
16
+ public: () => PublicStorefrontSDK$1;
17
+ session: {
18
+ (): SessionStorefrontSDK$1;
19
+ (cookieStore: NextCookieStore): SessionStorefrontSDK$1;
20
+ };
13
21
  };
14
22
  /**
15
- * Creates a configured storefront function that works universally across all Next.js contexts
23
+ * Creates a configured storefront factory for Next.js.
16
24
  *
17
25
  * Usage:
18
26
  * ```typescript
@@ -21,22 +29,13 @@ type NextCookieStore = {
21
29
  *
22
30
  * export const storefront = createStorefront({
23
31
  * debug: true,
24
- * logger: (msg, ...args) => console.log('[DEBUG]', msg, ...args)
32
+ * logger: (msg, ...args) => console.log("[DEBUG]", msg, ...args),
25
33
  * });
26
34
  * ```
27
35
  *
28
- * @param config Optional configuration for advanced options (defaults to empty if not provided)
29
- * @returns A storefront function that works in all Next.js contexts
36
+ * @param config Optional configuration for advanced options
37
+ * @returns A storefront factory with explicit public and session accessors
30
38
  */
31
- declare function createStorefront(config?: StorefrontRuntimeConfig): {
32
- (): StorefrontSDK$1;
33
- (cookieStore: NextCookieStore): StorefrontSDK$1;
34
- (options: {
35
- isRootLayout: true;
36
- }): StorefrontSDK$1;
37
- (cookieStore: NextCookieStore, options: {
38
- isRootLayout?: boolean;
39
- }): StorefrontSDK$1;
40
- };
39
+ declare function createStorefront(config?: StorefrontRuntimeConfig): NextJSStorefront;
41
40
  //#endregion
42
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, type StorefrontRuntimeConfig, StorefrontSDK, createStorefront };
41
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSStorefront, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient, type StorefrontRuntimeConfig, createStorefront };
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { r as setGlobalStorefrontConfig, t as getStorefrontSDK } from "./manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
1
+ import { i as setGlobalStorefrontConfig, n as getSessionStorefrontSDK, t as getPublicStorefrontSDK } from "./manager.mjs";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient } from "@commercengine/storefront-sdk";
3
3
 
4
4
  //#region src/storefront.ts
5
5
  /**
6
- * Creates a configured storefront function that works universally across all Next.js contexts
6
+ * Creates a configured storefront factory for Next.js.
7
7
  *
8
8
  * Usage:
9
9
  * ```typescript
@@ -12,45 +12,23 @@ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieToken
12
12
  *
13
13
  * export const storefront = createStorefront({
14
14
  * debug: true,
15
- * logger: (msg, ...args) => console.log('[DEBUG]', msg, ...args)
15
+ * logger: (msg, ...args) => console.log("[DEBUG]", msg, ...args),
16
16
  * });
17
17
  * ```
18
18
  *
19
- * @param config Optional configuration for advanced options (defaults to empty if not provided)
20
- * @returns A storefront function that works in all Next.js contexts
19
+ * @param config Optional configuration for advanced options
20
+ * @returns A storefront factory with explicit public and session accessors
21
21
  */
22
22
  function createStorefront(config) {
23
23
  if (config) setGlobalStorefrontConfig(config);
24
- function storefront(cookieStoreOrOptions, options) {
25
- if (typeof window !== "undefined") return getStorefrontSDK();
26
- let cookieStore;
27
- let isRootLayout = false;
28
- if (cookieStoreOrOptions) if ("isRootLayout" in cookieStoreOrOptions) isRootLayout = cookieStoreOrOptions.isRootLayout;
29
- else {
30
- cookieStore = cookieStoreOrOptions;
31
- isRootLayout = options?.isRootLayout || false;
32
- }
33
- if (cookieStore) return getStorefrontSDK(cookieStore);
34
- if (process.env.NEXT_IS_BUILD === "true" || process.env.NEXT_BUILD_CACHE_TOKENS === "true") return getStorefrontSDK();
35
- if (isRootLayout) return getStorefrontSDK();
36
- throw new Error([
37
- "🚨 Server context requires cookies for user continuity!",
38
- "",
39
- "You're calling storefront() on the server without cookies.",
40
- "This breaks user session continuity and analytics tracking.",
41
- "",
42
- "✅ Correct usage:",
43
- " import { cookies } from 'next/headers'",
44
- " const sdk = storefront(cookies())",
45
- "",
46
- "📍 Root Layout exception:",
47
- " const sdk = storefront({ isRootLayout: true })",
48
- "",
49
- "This is required to maintain consistent user identity across requests."
50
- ].join("\n"));
24
+ function session(cookieStore) {
25
+ return cookieStore ? getSessionStorefrontSDK(cookieStore) : getSessionStorefrontSDK();
51
26
  }
52
- return storefront;
27
+ return {
28
+ public: () => getPublicStorefrontSDK(),
29
+ session
30
+ };
53
31
  }
54
32
 
55
33
  //#endregion
56
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, createStorefront };
34
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient, createStorefront };
@@ -1,4 +1,4 @@
1
- import { DebugLoggerFn, Environment, StorefrontSDK, StorefrontSDKOptions, SupportedDefaultHeaders, TokenStorage } from "@commercengine/storefront-sdk";
1
+ import { DebugLoggerFn, Environment, PublicStorefrontSDK, SessionStorefrontSDK, SessionStorefrontSDKOptions, SupportedDefaultHeaders, TokenStorage } from "@commercengine/storefront-sdk";
2
2
  import { SSRTokenStorageOptions, ServerTokenStorage } from "@commercengine/ssr-utils";
3
3
 
4
4
  //#region src/client-storage.d.ts
@@ -73,15 +73,15 @@ declare class ServerTokenStorage$1 extends ServerTokenStorage {
73
73
  /**
74
74
  * Configuration for the NextJS SDK wrapper
75
75
  */
76
- interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
76
+ interface NextJSSDKConfig extends Omit<SessionStorefrontSDKOptions, "tokenStorage"> {
77
77
  /**
78
78
  * Token storage configuration options
79
79
  */
80
80
  tokenStorageOptions?: NextJSTokenStorageOptions$1;
81
81
  }
82
82
  /**
83
- * Runtime configuration overrides that can be passed to storefront() function
84
- * These override environment variables for that specific request
83
+ * Runtime configuration overrides that can be passed to `createStorefront()`
84
+ * These override environment variables for that specific app instance.
85
85
  */
86
86
  interface StorefrontRuntimeConfig {
87
87
  /**
@@ -108,19 +108,24 @@ interface StorefrontRuntimeConfig {
108
108
  tokenStorageOptions?: NextJSTokenStorageOptions$1;
109
109
  }
110
110
  /**
111
- * Smart SDK getter that automatically detects environment
111
+ * Get or create the public SDK singleton.
112
+ *
113
+ * This SDK is intended for build/prerender-safe public reads and does not
114
+ * participate in session bootstrap, refresh, or storage writes.
115
+ */
116
+ declare function getPublicStorefrontSDK(): PublicStorefrontSDK;
117
+ /**
118
+ * Get or create a session-aware SDK.
112
119
  *
113
120
  * Usage:
114
- * - Client-side: getStorefrontSDK()
115
- * - Server-side with request context: getStorefrontSDK(await cookies())
116
- * - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
121
+ * - Client-side: `getSessionStorefrontSDK()`
122
+ * - Server-side with request context: `getSessionStorefrontSDK(cookies())`
117
123
  */
118
- declare function getStorefrontSDK(): StorefrontSDK;
119
- declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
124
+ declare function getSessionStorefrontSDK(): SessionStorefrontSDK;
125
+ declare function getSessionStorefrontSDK(cookieStore: NextCookieStore): SessionStorefrontSDK;
120
126
  /**
121
- * Initialize the SDK (internal use)
122
- * This should be called once in your app via StorefrontSDKInitializer
127
+ * Reset instantiated SDK singletons so they pick up current configuration.
123
128
  */
124
129
  declare function initializeStorefrontSDK(): void;
125
130
  //#endregion
126
- export { NextJSTokenStorageOptions as a, NextJSTokenStorageOptions$1 as c, initializeStorefrontSDK as i, StorefrontRuntimeConfig as n, ServerTokenStorage$1 as o, getStorefrontSDK as r, ClientTokenStorage as s, NextJSSDKConfig as t };
131
+ export { initializeStorefrontSDK as a, ServerTokenStorage$1 as c, getSessionStorefrontSDK as i, ClientTokenStorage as l, StorefrontRuntimeConfig as n, NextCookieStore as o, getPublicStorefrontSDK as r, NextJSTokenStorageOptions as s, NextJSSDKConfig as t, NextJSTokenStorageOptions$1 as u };
package/dist/manager.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { cache } from "react";
2
- import { Environment, MemoryTokenStorage, StorefrontSDK } from "@commercengine/storefront-sdk";
3
- import { BuildCachingTokenStorage, ServerTokenStorage, isBuildContext } from "@commercengine/ssr-utils";
2
+ import { Environment, PublicStorefrontSDK, SessionStorefrontSDK } from "@commercengine/storefront-sdk";
3
+ import { ServerTokenStorage } from "@commercengine/ssr-utils";
4
4
 
5
5
  //#region src/client-storage.ts
6
6
  /**
@@ -110,19 +110,19 @@ var ServerTokenStorage$1 = class extends ServerTokenStorage {
110
110
  //#region src/manager.ts
111
111
  /**
112
112
  * Global runtime configuration storage
113
- * This gets bundled into both client and server bundles
113
+ * This gets bundled into both client and server bundles.
114
114
  */
115
115
  let globalStorefrontConfig = null;
116
116
  /**
117
- * Client-side SDK singleton (only lives in browser)
117
+ * Client-side session SDK singleton (only lives in browser)
118
118
  */
119
- let clientSDK = null;
119
+ let clientSessionSDK = null;
120
120
  /**
121
- * Memory-based SDK for SSG/build contexts (no request isolation needed)
121
+ * Public SDK singleton shared by non-session reads
122
122
  */
123
- let buildTimeSDK = null;
123
+ let publicSDK = null;
124
124
  /**
125
- * Get configuration from environment variables merged with global config
125
+ * Get configuration from environment variables merged with global config.
126
126
  * Precedence order: environment variables < global config
127
127
  */
128
128
  function getConfig() {
@@ -144,7 +144,7 @@ function getConfig() {
144
144
  ...envDefaultHeaders,
145
145
  ...globalStorefrontConfig?.defaultHeaders
146
146
  };
147
- if (!storeId || !apiKey) throw new Error(`StorefrontSDK configuration missing! Please set the following environment variables:
147
+ if (!storeId || !apiKey) throw new Error(`Storefront SDK configuration missing! Please set the following environment variables:
148
148
 
149
149
  NEXT_PUBLIC_STORE_ID=your-store-id
150
150
  NEXT_PUBLIC_API_KEY=your-api-key
@@ -174,69 +174,86 @@ These variables are required for both client and server contexts to work.`);
174
174
  if (tokenStorageOptions) config.tokenStorageOptions = tokenStorageOptions;
175
175
  return config;
176
176
  }
177
- /**
178
- * Create appropriate token storage based on environment
179
- */
180
- function createTokenStorage(cookieStore, options, config) {
181
- if (typeof window !== "undefined") return new ClientTokenStorage(options);
182
- if (cookieStore) return new ServerTokenStorage$1(cookieStore, options);
183
- if ((process.env.NEXT_BUILD_CACHE_TOKENS === "true" || isBuildContext({ envVars: ["NEXT_IS_BUILD", "NEXT_BUILD_CACHE_TOKENS"] })) && config) return new BuildCachingTokenStorage({
184
- cacheKey: `${config.storeId}:${config.environment || "production"}`,
185
- ttlSeconds: 300
177
+ function buildPublicSDKConfig(config) {
178
+ const publicConfig = {
179
+ storeId: config.storeId,
180
+ apiKey: config.apiKey,
181
+ environment: config.environment
182
+ };
183
+ if (config.baseUrl) publicConfig.baseUrl = config.baseUrl;
184
+ if (config.timeout) publicConfig.timeout = config.timeout;
185
+ if (config.debug) publicConfig.debug = config.debug;
186
+ if (config.logger) publicConfig.logger = config.logger;
187
+ if (config.defaultHeaders) publicConfig.defaultHeaders = config.defaultHeaders;
188
+ return publicConfig;
189
+ }
190
+ function createClientSessionSDK(config) {
191
+ return new SessionStorefrontSDK({
192
+ ...config,
193
+ tokenStorage: new ClientTokenStorage(config.tokenStorageOptions)
186
194
  });
187
- return new MemoryTokenStorage();
188
195
  }
189
- /**
190
- * Request-scoped server SDK factory using React cache
191
- */
192
- const getServerSDKCached = cache((cookieStore) => {
193
- const config = getConfig();
194
- return new StorefrontSDK({
196
+ function createServerSessionSDK(cookieStore, config) {
197
+ return new SessionStorefrontSDK({
195
198
  ...config,
196
- tokenStorage: createTokenStorage(cookieStore, config.tokenStorageOptions, config)
199
+ tokenStorage: new ServerTokenStorage$1(cookieStore, config.tokenStorageOptions)
197
200
  });
201
+ }
202
+ /**
203
+ * Request-scoped server session SDK factory using React cache
204
+ */
205
+ const getServerSessionSDKCached = cache((cookieStore) => {
206
+ return createServerSessionSDK(cookieStore, getConfig());
198
207
  });
199
208
  /**
200
- * Get or create build-time SDK singleton
209
+ * Get or create the public SDK singleton.
210
+ *
211
+ * This SDK is intended for build/prerender-safe public reads and does not
212
+ * participate in session bootstrap, refresh, or storage writes.
201
213
  */
202
- function getBuildTimeSDK() {
214
+ function getPublicStorefrontSDK() {
203
215
  const config = getConfig();
204
- if (!buildTimeSDK) buildTimeSDK = new StorefrontSDK({
205
- ...config,
206
- tokenStorage: createTokenStorage(void 0, config.tokenStorageOptions, config)
207
- });
208
- return buildTimeSDK;
216
+ if (!publicSDK) publicSDK = new PublicStorefrontSDK(buildPublicSDKConfig(config));
217
+ return publicSDK;
209
218
  }
210
- function getStorefrontSDK(cookieStore) {
219
+ function getSessionStorefrontSDK(cookieStore) {
211
220
  if (typeof window !== "undefined") {
212
221
  if (cookieStore) console.warn("Cookie store passed in client environment - this will be ignored");
213
222
  const config = getConfig();
214
- if (!clientSDK) clientSDK = new StorefrontSDK({
215
- ...config,
216
- tokenStorage: createTokenStorage(void 0, config.tokenStorageOptions, config)
217
- });
218
- return clientSDK;
223
+ if (!clientSessionSDK) clientSessionSDK = createClientSessionSDK(config);
224
+ return clientSessionSDK;
219
225
  }
220
- if (cookieStore) return getServerSDKCached(cookieStore);
221
- return getBuildTimeSDK();
226
+ if (cookieStore) return getServerSessionSDKCached(cookieStore);
227
+ throw new Error([
228
+ "🚨 Server session access requires cookies!",
229
+ "",
230
+ "You're calling the session SDK on the server without cookies.",
231
+ "",
232
+ "✅ Correct usage for user/session-aware requests:",
233
+ " import { cookies } from 'next/headers'",
234
+ " const sdk = storefront.session(cookies())",
235
+ "",
236
+ "✅ Correct usage for build/prerender-safe public reads:",
237
+ " const sdk = storefront.public()",
238
+ "",
239
+ "This keeps public rendering separate from real user session continuity."
240
+ ].join("\n"));
222
241
  }
223
242
  /**
224
- * Set global storefront configuration that applies to all SDK instances
225
- * This gets bundled into both client and server contexts automatically
243
+ * Set global storefront configuration that applies to all SDK instances.
226
244
  */
227
245
  function setGlobalStorefrontConfig(config) {
228
246
  globalStorefrontConfig = config;
229
- clientSDK = null;
230
- buildTimeSDK = null;
247
+ clientSessionSDK = null;
248
+ publicSDK = null;
231
249
  }
232
250
  /**
233
- * Initialize the SDK (internal use)
234
- * This should be called once in your app via StorefrontSDKInitializer
251
+ * Reset instantiated SDK singletons so they pick up current configuration.
235
252
  */
236
253
  function initializeStorefrontSDK() {
237
- clientSDK = null;
238
- buildTimeSDK = null;
254
+ clientSessionSDK = null;
255
+ publicSDK = null;
239
256
  }
240
257
 
241
258
  //#endregion
242
- export { ClientTokenStorage as a, ServerTokenStorage$1 as i, initializeStorefrontSDK as n, setGlobalStorefrontConfig as r, getStorefrontSDK as t };
259
+ export { ServerTokenStorage$1 as a, setGlobalStorefrontConfig as i, getSessionStorefrontSDK as n, ClientTokenStorage as o, initializeStorefrontSDK as r, getPublicStorefrontSDK as t };
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as NextJSTokenStorageOptions, i as initializeStorefrontSDK, o as ServerTokenStorage, r as getStorefrontSDK, t as NextJSSDKConfig } from "./manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
1
+ import { a as initializeStorefrontSDK, c as ServerTokenStorage, i as getSessionStorefrontSDK, r as getPublicStorefrontSDK, s as NextJSTokenStorageOptions, t as NextJSSDKConfig } from "./manager.mjs";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient } from "@commercengine/storefront-sdk";
3
3
  export * from "@commercengine/storefront-sdk";
4
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, PaymentsClient, ResponseUtils, ServerTokenStorage, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, getStorefrontSDK, initializeStorefrontSDK };
4
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, ServerTokenStorage, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient, getPublicStorefrontSDK, getSessionStorefrontSDK, initializeStorefrontSDK };
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { i as ServerTokenStorage, n as initializeStorefrontSDK, t as getStorefrontSDK } from "./manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
1
+ import { a as ServerTokenStorage, n as getSessionStorefrontSDK, r as initializeStorefrontSDK, t as getPublicStorefrontSDK } from "./manager.mjs";
2
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient } from "@commercengine/storefront-sdk";
3
3
 
4
4
  export * from "@commercengine/storefront-sdk"
5
5
 
6
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, ServerTokenStorage, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, getStorefrontSDK, initializeStorefrontSDK };
6
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, ServerTokenStorage, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient, getPublicStorefrontSDK, getSessionStorefrontSDK, initializeStorefrontSDK };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercengine/storefront-sdk-nextjs",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "description": "Next.js wrapper for the Commerce Engine Storefront SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -25,7 +25,8 @@
25
25
  },
26
26
  "files": [
27
27
  "dist",
28
- "README.md"
28
+ "README.md",
29
+ "MIGRATION.md"
29
30
  ],
30
31
  "keywords": [
31
32
  "commerce engine",
@@ -43,8 +44,8 @@
43
44
  "react-dom": ">=19.0.0"
44
45
  },
45
46
  "dependencies": {
46
- "@commercengine/storefront-sdk": "0.13.3",
47
- "@commercengine/ssr-utils": "0.1.0"
47
+ "@commercengine/storefront-sdk": "0.14.0",
48
+ "@commercengine/ssr-utils": "0.2.0"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/node": "^24.10.4",