@commercengine/storefront-sdk-nextjs 0.1.13 → 0.2.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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  **Production-ready Next.js wrapper** for the CommerceEngine Storefront SDK. Provides the perfect developer experience with automatic context detection, universal API, and zero configuration complexity.
4
4
 
5
+ Built on [`@commercengine/ssr-utils`](../ssr-utils) for robust server-side token management.
6
+
5
7
  **✨ Perfect DX Pattern:**
6
8
  - **🎯 One Config File** - Single `lib/storefront.ts` using `createStorefront()`
7
9
  - **🌍 Universal API** - Same `storefront()` import works everywhere
@@ -622,13 +624,18 @@ For complete API documentation of all available endpoints, visit [SDK DOCS REFER
622
624
  The Next.js SDK provides access to all the same endpoints as the core SDK:
623
625
 
624
626
  - `sdk.auth.*` - Authentication and user management
625
- - `sdk.customer.*` - Customer profiles and preferences
627
+ - `sdk.customer.*` - Customer profiles and preferences
626
628
  - `sdk.catalog.*` - Products, categories, and search
627
629
  - `sdk.cart.*` - Shopping cart management
628
630
  - `sdk.order.*` - Order creation and tracking
629
- - `sdk.shipping.*` - Shipping methods and rates
631
+ - `sdk.payments.*` - Payment methods and processing
632
+ - `sdk.store.*` - Store configuration
630
633
  - `sdk.helpers.*` - Countries, currencies, utilities
631
634
 
635
+ ## Related Packages
636
+
637
+ - [`@commercengine/storefront-sdk`](../storefront-sdk) - Core Storefront SDK
638
+
632
639
  ## License
633
640
 
634
641
  All Rights Reserved
package/dist/client.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as ClientTokenStorage, i as initializeStorefrontSDK, n as StorefrontRuntimeConfig, o as NextJSTokenStorageOptions, r as getStorefrontSDK, t as NextJSSDKConfig } from "./sdk-manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKOptions, TokenStorage } from "@commercengine/storefront-sdk";
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";
3
3
 
4
- //#region src/init-client.d.ts
4
+ //#region src/initializer.d.ts
5
5
  interface StorefrontSDKInitializerProps {
6
6
  /**
7
7
  * Optional runtime configuration overrides for client-side API calls
@@ -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, ResponseUtils, ShippingClient, 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, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, type StorefrontSDKOptions, type TokenStorage, getStorefrontSDK, initializeStorefrontSDK };
package/dist/client.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
- import { i as ClientTokenStorage, n as initializeStorefrontSDK, t as getStorefrontSDK } from "./sdk-manager.mjs";
3
+ import { a as ClientTokenStorage, n as initializeStorefrontSDK, t as getStorefrontSDK } from "./manager.mjs";
4
4
  import { useEffect } from "react";
5
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
5
+ import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
6
6
 
7
- //#region src/init-client.ts
7
+ //#region src/initializer.tsx
8
8
  /**
9
9
  * Client-side initialization component
10
10
  * Use this in your root layout to initialize the SDK once
@@ -38,4 +38,4 @@ function StorefrontSDKInitializer({ runtimeConfig } = {}) {
38
38
  }
39
39
 
40
40
  //#endregion
41
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, getStorefrontSDK, initializeStorefrontSDK };
41
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, ClientTokenStorage, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDKInitializer, getStorefrontSDK, initializeStorefrontSDK };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { n as StorefrontRuntimeConfig } from "./sdk-manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDK as StorefrontSDK$1 } from "@commercengine/storefront-sdk";
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";
3
3
  export * from "@commercengine/storefront-sdk";
4
4
 
5
- //#region src/create-storefront.d.ts
5
+ //#region src/storefront.d.ts
6
6
  type NextCookieStore = {
7
7
  get: (name: string) => {
8
8
  name: string;
@@ -39,4 +39,4 @@ declare function createStorefront(config?: StorefrontRuntimeConfig): {
39
39
  }): StorefrontSDK$1;
40
40
  };
41
41
  //#endregion
42
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, type StorefrontRuntimeConfig, StorefrontSDK, createStorefront };
42
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, type StorefrontRuntimeConfig, StorefrontSDK, createStorefront };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { r as setGlobalStorefrontConfig, t as getStorefrontSDK } from "./sdk-manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
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";
3
3
 
4
- //#region src/create-storefront.ts
4
+ //#region src/storefront.ts
5
5
  /**
6
6
  * Creates a configured storefront function that works universally across all Next.js contexts
7
7
  *
@@ -53,4 +53,4 @@ function createStorefront(config) {
53
53
  }
54
54
 
55
55
  //#endregion
56
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, createStorefront };
56
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, createStorefront };
@@ -1,44 +1,31 @@
1
1
  import { DebugLoggerFn, Environment, StorefrontSDK, StorefrontSDKOptions, SupportedDefaultHeaders, TokenStorage } from "@commercengine/storefront-sdk";
2
+ import { SSRTokenStorageOptions, ServerTokenStorage } from "@commercengine/ssr-utils";
2
3
 
3
- //#region src/token-storage.d.ts
4
+ //#region src/client-storage.d.ts
4
5
 
5
6
  /**
6
- * Configuration options for NextJSTokenStorage
7
+ * Configuration options for NextJS token storage
8
+ * Re-exported from ssr-utils for convenience
7
9
  */
8
- interface NextJSTokenStorageOptions {
9
- /**
10
- * Prefix for cookie names (default: "ce_")
11
- */
12
- prefix?: string;
13
- /**
14
- * Maximum age of cookies in seconds (default: 30 days)
15
- */
16
- maxAge?: number;
17
- /**
18
- * Cookie path (default: "/")
19
- */
20
- path?: string;
21
- /**
22
- * Cookie domain (default: current domain)
23
- */
24
- domain?: string;
25
- /**
26
- * Whether cookies should be secure (default: auto-detect based on environment)
27
- */
28
- secure?: boolean;
29
- /**
30
- * SameSite cookie attribute (default: "Lax")
31
- */
32
- sameSite?: "Strict" | "Lax" | "None";
33
- }
10
+ type NextJSTokenStorageOptions$1 = SSRTokenStorageOptions;
34
11
  /**
35
12
  * Client-side token storage that uses document.cookie
13
+ *
14
+ * This is Next.js specific because it needs to work with the same cookie
15
+ * format as the server-side storage for seamless SSR/client hydration.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { ClientTokenStorage } from '@commercengine/storefront-sdk-nextjs/client';
20
+ *
21
+ * const storage = new ClientTokenStorage();
22
+ * ```
36
23
  */
37
24
  declare class ClientTokenStorage implements TokenStorage {
38
25
  private accessTokenKey;
39
26
  private refreshTokenKey;
40
27
  private options;
41
- constructor(options?: NextJSTokenStorageOptions);
28
+ constructor(options?: NextJSTokenStorageOptions$1);
42
29
  getAccessToken(): Promise<string | null>;
43
30
  setAccessToken(token: string): Promise<void>;
44
31
  getRefreshToken(): Promise<string | null>;
@@ -48,30 +35,41 @@ declare class ClientTokenStorage implements TokenStorage {
48
35
  private setCookie;
49
36
  private deleteCookie;
50
37
  }
51
- type NextCookieStore$1 = {
38
+ //#endregion
39
+ //#region src/server-storage.d.ts
40
+ /**
41
+ * Configuration options for NextJS token storage
42
+ * Re-exported from ssr-utils for convenience
43
+ */
44
+ type NextJSTokenStorageOptions = SSRTokenStorageOptions;
45
+ /**
46
+ * Type for Next.js cookies (from next/headers)
47
+ */
48
+ type NextCookieStore = {
52
49
  get: (name: string) => {
53
50
  value: string;
54
51
  } | undefined;
55
- set: (name: string, value: string, options?: any) => void;
52
+ set: (name: string, value: string, options?: Record<string, unknown>) => void;
56
53
  delete: (name: string) => void;
57
54
  };
58
55
  /**
59
- * Server-side token storage that uses Next.js cookies API
56
+ * Server-side token storage for Next.js using the cookies() API
57
+ *
58
+ * This wraps the ssr-utils ServerTokenStorage with a Next.js-specific adapter.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * import { cookies } from 'next/headers';
63
+ * import { ServerTokenStorage } from '@commercengine/storefront-sdk-nextjs/server';
64
+ *
65
+ * const storage = new ServerTokenStorage(cookies());
66
+ * ```
60
67
  */
61
- declare class ServerTokenStorage implements TokenStorage {
62
- private accessTokenKey;
63
- private refreshTokenKey;
64
- private options;
65
- private cookieStore;
66
- constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
67
- getAccessToken(): Promise<string | null>;
68
- setAccessToken(token: string): Promise<void>;
69
- getRefreshToken(): Promise<string | null>;
70
- setRefreshToken(token: string): Promise<void>;
71
- clearTokens(): Promise<void>;
68
+ declare class ServerTokenStorage$1 extends ServerTokenStorage {
69
+ constructor(cookieStore: NextCookieStore, options?: NextJSTokenStorageOptions);
72
70
  }
73
71
  //#endregion
74
- //#region src/sdk-manager.d.ts
72
+ //#region src/manager.d.ts
75
73
  /**
76
74
  * Configuration for the NextJS SDK wrapper
77
75
  */
@@ -79,7 +77,7 @@ interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
79
77
  /**
80
78
  * Token storage configuration options
81
79
  */
82
- tokenStorageOptions?: NextJSTokenStorageOptions;
80
+ tokenStorageOptions?: NextJSTokenStorageOptions$1;
83
81
  }
84
82
  /**
85
83
  * Runtime configuration overrides that can be passed to storefront() function
@@ -107,15 +105,8 @@ interface StorefrontRuntimeConfig {
107
105
  /**
108
106
  * Token storage configuration
109
107
  */
110
- tokenStorageOptions?: NextJSTokenStorageOptions;
108
+ tokenStorageOptions?: NextJSTokenStorageOptions$1;
111
109
  }
112
- type NextCookieStore = {
113
- get: (name: string) => {
114
- value: string;
115
- } | undefined;
116
- set: (name: string, value: string, options?: any) => void;
117
- delete: (name: string) => void;
118
- };
119
110
  /**
120
111
  * Smart SDK getter that automatically detects environment
121
112
  *
@@ -132,4 +123,4 @@ declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
132
123
  */
133
124
  declare function initializeStorefrontSDK(): void;
134
125
  //#endregion
135
- export { ClientTokenStorage as a, initializeStorefrontSDK as i, StorefrontRuntimeConfig as n, NextJSTokenStorageOptions as o, getStorefrontSDK as r, ServerTokenStorage as s, NextJSSDKConfig as t };
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 };
@@ -1,9 +1,20 @@
1
1
  import { cache } from "react";
2
2
  import { Environment, MemoryTokenStorage, StorefrontSDK } from "@commercengine/storefront-sdk";
3
+ import { BuildCachingTokenStorage, ServerTokenStorage, isBuildContext } from "@commercengine/ssr-utils";
3
4
 
4
- //#region src/token-storage.ts
5
+ //#region src/client-storage.ts
5
6
  /**
6
7
  * Client-side token storage that uses document.cookie
8
+ *
9
+ * This is Next.js specific because it needs to work with the same cookie
10
+ * format as the server-side storage for seamless SSR/client hydration.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { ClientTokenStorage } from '@commercengine/storefront-sdk-nextjs/client';
15
+ *
16
+ * const storage = new ClientTokenStorage();
17
+ * ```
7
18
  */
8
19
  var ClientTokenStorage = class {
9
20
  accessTokenKey;
@@ -13,12 +24,17 @@ var ClientTokenStorage = class {
13
24
  const prefix = options.prefix || "ce_";
14
25
  this.accessTokenKey = `${prefix}access_token`;
15
26
  this.refreshTokenKey = `${prefix}refresh_token`;
27
+ const normalizedSameSite = options.sameSite ? {
28
+ strict: "Strict",
29
+ lax: "Lax",
30
+ none: "None"
31
+ }[options.sameSite] : "Lax";
16
32
  this.options = {
17
33
  maxAge: options.maxAge || 720 * 60 * 60,
18
34
  path: options.path || "/",
19
35
  domain: options.domain,
20
36
  secure: options.secure ?? (typeof window !== "undefined" && window.location?.protocol === "https:"),
21
- sameSite: options.sameSite || "Lax"
37
+ sameSite: normalizedSameSite
22
38
  };
23
39
  }
24
40
  async getAccessToken() {
@@ -64,157 +80,47 @@ var ClientTokenStorage = class {
64
80
  document.cookie = cookieString;
65
81
  }
66
82
  };
83
+
84
+ //#endregion
85
+ //#region src/server-storage.ts
67
86
  /**
68
- * Server-side token storage that uses Next.js cookies API
87
+ * Server-side token storage for Next.js using the cookies() API
88
+ *
89
+ * This wraps the ssr-utils ServerTokenStorage with a Next.js-specific adapter.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * import { cookies } from 'next/headers';
94
+ * import { ServerTokenStorage } from '@commercengine/storefront-sdk-nextjs/server';
95
+ *
96
+ * const storage = new ServerTokenStorage(cookies());
97
+ * ```
69
98
  */
70
- var ServerTokenStorage = class {
71
- accessTokenKey;
72
- refreshTokenKey;
73
- options;
74
- cookieStore;
99
+ var ServerTokenStorage$1 = class extends ServerTokenStorage {
75
100
  constructor(cookieStore, options = {}) {
76
- const prefix = options.prefix || "ce_";
77
- this.accessTokenKey = `${prefix}access_token`;
78
- this.refreshTokenKey = `${prefix}refresh_token`;
79
- this.cookieStore = cookieStore;
80
- this.options = {
81
- maxAge: options.maxAge || 720 * 60 * 60,
82
- path: options.path || "/",
83
- domain: options.domain,
84
- secure: options.secure ?? process.env.NODE_ENV === "production",
85
- sameSite: options.sameSite || "Lax"
86
- };
87
- }
88
- async getAccessToken() {
89
- try {
90
- return this.cookieStore.get(this.accessTokenKey)?.value || null;
91
- } catch (error) {
92
- console.warn(`Could not get access token from server cookies:`, error);
93
- return null;
94
- }
95
- }
96
- async setAccessToken(token) {
97
- try {
98
- this.cookieStore.set(this.accessTokenKey, token, {
99
- maxAge: this.options.maxAge,
100
- path: this.options.path,
101
- domain: this.options.domain,
102
- secure: this.options.secure,
103
- sameSite: this.options.sameSite?.toLowerCase(),
104
- httpOnly: false
105
- });
106
- } catch (error) {
107
- console.warn(`Could not set access token on server:`, error);
108
- }
109
- }
110
- async getRefreshToken() {
111
- try {
112
- return this.cookieStore.get(this.refreshTokenKey)?.value || null;
113
- } catch (error) {
114
- console.warn(`Could not get refresh token from server cookies:`, error);
115
- return null;
116
- }
117
- }
118
- async setRefreshToken(token) {
119
- try {
120
- this.cookieStore.set(this.refreshTokenKey, token, {
121
- maxAge: this.options.maxAge,
122
- path: this.options.path,
123
- domain: this.options.domain,
124
- secure: this.options.secure,
125
- sameSite: this.options.sameSite?.toLowerCase(),
126
- httpOnly: false
127
- });
128
- } catch (error) {
129
- console.warn(`Could not set refresh token on server:`, error);
130
- }
131
- }
132
- async clearTokens() {
133
- try {
134
- this.cookieStore.delete(this.accessTokenKey);
135
- this.cookieStore.delete(this.refreshTokenKey);
136
- } catch (error) {
137
- console.warn(`Could not clear tokens on server:`, error);
138
- }
101
+ super({
102
+ get: (name) => cookieStore.get(name)?.value ?? null,
103
+ set: (name, value, opts) => cookieStore.set(name, value, opts),
104
+ delete: (name) => cookieStore.delete(name)
105
+ }, options);
139
106
  }
140
107
  };
141
108
 
142
109
  //#endregion
143
- //#region src/build-token-cache.ts
144
- const store = /* @__PURE__ */ new Map();
145
- function isExpired(token) {
146
- if (!token) return true;
147
- if (!token.expiresAt) return false;
148
- return Date.now() > token.expiresAt - 3e4;
149
- }
150
- function getCachedToken(key) {
151
- const token = store.get(key);
152
- return isExpired(token) ? null : token;
153
- }
154
- function setCachedToken(key, token) {
155
- const expiresAt = token.ttlSeconds != null ? Date.now() + token.ttlSeconds * 1e3 : void 0;
156
- store.set(key, {
157
- accessToken: token.accessToken,
158
- refreshToken: token.refreshToken ?? null,
159
- expiresAt
160
- });
161
- }
162
- function clearCachedToken(key) {
163
- store.delete(key);
164
- }
165
-
166
- //#endregion
167
- //#region src/build-caching-memory-storage.ts
168
- const DEFAULT_TTL_SECONDS = 300;
110
+ //#region src/manager.ts
169
111
  /**
170
- * Memory token storage that reuses tokens across the build process
171
- * via an in-process cache. Only used during SSG/ISR builds.
112
+ * Global runtime configuration storage
113
+ * This gets bundled into both client and server bundles
172
114
  */
173
- var BuildCachingMemoryTokenStorage = class {
174
- access = null;
175
- refresh = null;
176
- constructor(cacheKey, ttlSeconds = DEFAULT_TTL_SECONDS) {
177
- this.cacheKey = cacheKey;
178
- this.ttlSeconds = ttlSeconds;
179
- }
180
- async getAccessToken() {
181
- if (this.access) return this.access;
182
- const cached = getCachedToken(this.cacheKey);
183
- if (cached?.accessToken) {
184
- this.access = cached.accessToken;
185
- this.refresh = cached.refreshToken ?? null;
186
- return this.access;
187
- }
188
- return null;
189
- }
190
- async setAccessToken(token) {
191
- this.access = token;
192
- setCachedToken(this.cacheKey, {
193
- accessToken: token,
194
- refreshToken: this.refresh,
195
- ttlSeconds: this.ttlSeconds
196
- });
197
- }
198
- async getRefreshToken() {
199
- return this.refresh;
200
- }
201
- async setRefreshToken(token) {
202
- this.refresh = token;
203
- setCachedToken(this.cacheKey, {
204
- accessToken: this.access ?? "",
205
- refreshToken: token,
206
- ttlSeconds: this.ttlSeconds
207
- });
208
- }
209
- async clearTokens() {
210
- this.access = null;
211
- this.refresh = null;
212
- clearCachedToken(this.cacheKey);
213
- }
214
- };
215
-
216
- //#endregion
217
- //#region src/sdk-manager.ts
115
+ let globalStorefrontConfig = null;
116
+ /**
117
+ * Client-side SDK singleton (only lives in browser)
118
+ */
119
+ let clientSDK = null;
120
+ /**
121
+ * Memory-based SDK for SSG/build contexts (no request isolation needed)
122
+ */
123
+ let buildTimeSDK = null;
218
124
  /**
219
125
  * Get configuration from environment variables merged with global config
220
126
  * Precedence order: environment variables < global config
@@ -269,21 +175,15 @@ These variables are required for both client and server contexts to work.`);
269
175
  return config;
270
176
  }
271
177
  /**
272
- * Global runtime configuration storage
273
- * This gets bundled into both client and server bundles
274
- */
275
- let globalStorefrontConfig = null;
276
- /**
277
- * Client-side SDK singleton (only lives in browser)
278
- */
279
- let clientSDK = null;
280
- /**
281
178
  * Create appropriate token storage based on environment
282
179
  */
283
180
  function createTokenStorage(cookieStore, options, config) {
284
181
  if (typeof window !== "undefined") return new ClientTokenStorage(options);
285
- if (cookieStore) return new ServerTokenStorage(cookieStore, options);
286
- if (process.env.NEXT_BUILD_CACHE_TOKENS === "true" && config) return new BuildCachingMemoryTokenStorage(`${config.storeId}:${config.environment || "production"}`);
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
186
+ });
287
187
  return new MemoryTokenStorage();
288
188
  }
289
189
  /**
@@ -297,9 +197,8 @@ const getServerSDKCached = cache((cookieStore) => {
297
197
  });
298
198
  });
299
199
  /**
300
- * Memory-based SDK for SSG/build contexts (no request isolation needed)
200
+ * Get or create build-time SDK singleton
301
201
  */
302
- let buildTimeSDK = null;
303
202
  function getBuildTimeSDK() {
304
203
  const config = getConfig();
305
204
  if (!buildTimeSDK) buildTimeSDK = new StorefrontSDK({
@@ -340,4 +239,4 @@ function initializeStorefrontSDK() {
340
239
  }
341
240
 
342
241
  //#endregion
343
- export { ServerTokenStorage as a, ClientTokenStorage as i, initializeStorefrontSDK as n, setGlobalStorefrontConfig as r, getStorefrontSDK as t };
242
+ export { ClientTokenStorage as a, ServerTokenStorage$1 as i, initializeStorefrontSDK as n, setGlobalStorefrontConfig as r, getStorefrontSDK as t };
package/dist/server.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as initializeStorefrontSDK, o as NextJSTokenStorageOptions, r as getStorefrontSDK, s as ServerTokenStorage, t as NextJSSDKConfig } from "./sdk-manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
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";
3
3
  export * from "@commercengine/storefront-sdk";
4
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, ResponseUtils, ServerTokenStorage, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, getStorefrontSDK, initializeStorefrontSDK };
4
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, OrderClient, PaymentsClient, ResponseUtils, ServerTokenStorage, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, getStorefrontSDK, initializeStorefrontSDK };
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { a as ServerTokenStorage, n as initializeStorefrontSDK, t as getStorefrontSDK } from "./sdk-manager.mjs";
2
- import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK } from "@commercengine/storefront-sdk";
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";
3
3
 
4
4
  export * from "@commercengine/storefront-sdk"
5
5
 
6
- export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ServerTokenStorage, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, getStorefrontSDK, initializeStorefrontSDK };
6
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, ServerTokenStorage, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, getStorefrontSDK, initializeStorefrontSDK };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercengine/storefront-sdk-nextjs",
3
- "version": "0.1.13",
3
+ "version": "0.2.0",
4
4
  "description": "Next.js wrapper for the Commerce Engine Storefront SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -43,7 +43,8 @@
43
43
  "react-dom": ">=19.0.0"
44
44
  },
45
45
  "dependencies": {
46
- "@commercengine/storefront-sdk": "0.12.1"
46
+ "@commercengine/storefront-sdk": "0.12.1",
47
+ "@commercengine/ssr-utils": "0.1.0"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@types/node": "^24.10.4",