@commercengine/storefront-sdk-nextjs 0.1.0-alpha.1 → 1.0.0-alpha.2

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.
@@ -0,0 +1,182 @@
1
+ import { TokenStorage, StorefrontSDK, Environment, SupportedDefaultHeaders, DebugLoggerFn, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
2
+
3
+ /**
4
+ * Configuration options for NextJSTokenStorage
5
+ */
6
+ interface NextJSTokenStorageOptions {
7
+ /**
8
+ * Prefix for cookie names (default: "ce_")
9
+ */
10
+ prefix?: string;
11
+ /**
12
+ * Maximum age of cookies in seconds (default: 30 days)
13
+ */
14
+ maxAge?: number;
15
+ /**
16
+ * Cookie path (default: "/")
17
+ */
18
+ path?: string;
19
+ /**
20
+ * Cookie domain (default: current domain)
21
+ */
22
+ domain?: string;
23
+ /**
24
+ * Whether cookies should be secure (default: auto-detect based on environment)
25
+ */
26
+ secure?: boolean;
27
+ /**
28
+ * SameSite cookie attribute (default: "Lax")
29
+ */
30
+ sameSite?: "Strict" | "Lax" | "None";
31
+ }
32
+ /**
33
+ * Client-side token storage that uses document.cookie
34
+ */
35
+ declare class ClientTokenStorage implements TokenStorage {
36
+ private accessTokenKey;
37
+ private refreshTokenKey;
38
+ private options;
39
+ constructor(options?: NextJSTokenStorageOptions);
40
+ getAccessToken(): Promise<string | null>;
41
+ setAccessToken(token: string): Promise<void>;
42
+ getRefreshToken(): Promise<string | null>;
43
+ setRefreshToken(token: string): Promise<void>;
44
+ clearTokens(): Promise<void>;
45
+ private getCookie;
46
+ private setCookie;
47
+ private deleteCookie;
48
+ }
49
+ type NextCookieStore$2 = {
50
+ get: (name: string) => {
51
+ value: string;
52
+ } | undefined;
53
+ set: (name: string, value: string, options?: any) => void;
54
+ delete: (name: string) => void;
55
+ };
56
+ /**
57
+ * Server-side token storage that uses Next.js cookies API
58
+ */
59
+ declare class ServerTokenStorage implements TokenStorage {
60
+ private accessTokenKey;
61
+ private refreshTokenKey;
62
+ private options;
63
+ private cookieStore;
64
+ constructor(cookieStore: NextCookieStore$2, options?: NextJSTokenStorageOptions);
65
+ getAccessToken(): Promise<string | null>;
66
+ setAccessToken(token: string): Promise<void>;
67
+ getRefreshToken(): Promise<string | null>;
68
+ setRefreshToken(token: string): Promise<void>;
69
+ clearTokens(): Promise<void>;
70
+ }
71
+
72
+ /**
73
+ * Configuration for the NextJS SDK wrapper
74
+ */
75
+ interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
76
+ /**
77
+ * Token storage configuration options
78
+ */
79
+ tokenStorageOptions?: NextJSTokenStorageOptions;
80
+ }
81
+ /**
82
+ * Runtime configuration overrides that can be passed to storefront() function
83
+ * These override environment variables for that specific request
84
+ */
85
+ interface StorefrontRuntimeConfig {
86
+ /**
87
+ * Override environment variables
88
+ */
89
+ storeId?: string;
90
+ apiKey?: string;
91
+ environment?: Environment;
92
+ baseUrl?: string;
93
+ timeout?: number;
94
+ debug?: boolean;
95
+ /**
96
+ * Advanced options not available via environment variables
97
+ */
98
+ accessToken?: string;
99
+ refreshToken?: string;
100
+ defaultHeaders?: SupportedDefaultHeaders;
101
+ logger?: DebugLoggerFn;
102
+ onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
103
+ onTokensCleared?: () => void;
104
+ /**
105
+ * Token storage configuration
106
+ */
107
+ tokenStorageOptions?: NextJSTokenStorageOptions;
108
+ }
109
+ type NextCookieStore$1 = {
110
+ get: (name: string) => {
111
+ value: string;
112
+ } | undefined;
113
+ set: (name: string, value: string, options?: any) => void;
114
+ delete: (name: string) => void;
115
+ };
116
+ /**
117
+ * Smart SDK getter that automatically detects environment
118
+ *
119
+ * Usage:
120
+ * - Client-side: getStorefrontSDK()
121
+ * - Server-side with request context: getStorefrontSDK(await cookies())
122
+ * - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
123
+ */
124
+ declare function getStorefrontSDK(): StorefrontSDK;
125
+ declare function getStorefrontSDK(cookieStore: NextCookieStore$1): StorefrontSDK;
126
+ declare function getStorefrontSDK(cookieStore: NextCookieStore$1, requestConfig?: StorefrontRuntimeConfig): StorefrontSDK;
127
+ /**
128
+ * Set global storefront configuration that applies to all SDK instances
129
+ * This gets bundled into both client and server contexts automatically
130
+ */
131
+ declare function setGlobalStorefrontConfig(config: StorefrontRuntimeConfig | null): void;
132
+ /**
133
+ * Get the current global storefront configuration
134
+ */
135
+ declare function getGlobalStorefrontConfig(): StorefrontRuntimeConfig | null;
136
+ /**
137
+ * Initialize the SDK (internal use)
138
+ * This should be called once in your app via StorefrontSDKInitializer
139
+ */
140
+ declare function initializeStorefrontSDK(): void;
141
+
142
+ /**
143
+ * Universal storefront SDK export
144
+ *
145
+ * This provides a simple unified interface that works in all Next.js contexts:
146
+ * - Client components: automatically uses client token storage
147
+ * - Server components: requires cookies() to be passed
148
+ * - SSG/ISR: automatically uses memory storage with optional build caching
149
+ *
150
+ * Usage:
151
+ * ```typescript
152
+ * // Client-side
153
+ * import { storefront } from '@commercengine/storefront-sdk-nextjs/storefront'
154
+ * const products = await storefront().catalog.listProducts()
155
+ *
156
+ * // Server-side
157
+ * import { storefront } from '@commercengine/storefront-sdk-nextjs/storefront'
158
+ * import { cookies } from 'next/headers'
159
+ * const products = await storefront(cookies()).catalog.listProducts()
160
+ * ```
161
+ */
162
+
163
+ type NextCookieStore = {
164
+ get: (name: string) => {
165
+ value: string;
166
+ } | undefined;
167
+ set: (name: string, value: string, options?: any) => void;
168
+ delete: (name: string) => void;
169
+ };
170
+ /**
171
+ * Universal storefront SDK accessor
172
+ *
173
+ * @param cookieStore - Next.js cookie store (required on server-side)
174
+ * @param config - Optional per-request configuration overrides
175
+ * @returns StorefrontSDK instance configured for the current environment
176
+ */
177
+ declare function storefront(): StorefrontSDK;
178
+ declare function storefront(cookieStore: NextCookieStore): StorefrontSDK;
179
+ declare function storefront(config: StorefrontRuntimeConfig): StorefrontSDK;
180
+ declare function storefront(cookieStore: NextCookieStore, config: StorefrontRuntimeConfig): StorefrontSDK;
181
+
182
+ export { ClientTokenStorage as C, type NextJSSDKConfig as N, type StorefrontRuntimeConfig as S, getGlobalStorefrontConfig as a, storefront as b, ServerTokenStorage as c, type NextJSTokenStorageOptions as d, getStorefrontSDK as g, initializeStorefrontSDK as i, setGlobalStorefrontConfig as s };
@@ -0,0 +1,115 @@
1
+ import { TokenStorage, Environment, SupportedDefaultHeaders, DebugLoggerFn, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
2
+
3
+ /**
4
+ * Configuration options for NextJSTokenStorage
5
+ */
6
+ interface NextJSTokenStorageOptions {
7
+ /**
8
+ * Prefix for cookie names (default: "ce_")
9
+ */
10
+ prefix?: string;
11
+ /**
12
+ * Maximum age of cookies in seconds (default: 30 days)
13
+ */
14
+ maxAge?: number;
15
+ /**
16
+ * Cookie path (default: "/")
17
+ */
18
+ path?: string;
19
+ /**
20
+ * Cookie domain (default: current domain)
21
+ */
22
+ domain?: string;
23
+ /**
24
+ * Whether cookies should be secure (default: auto-detect based on environment)
25
+ */
26
+ secure?: boolean;
27
+ /**
28
+ * SameSite cookie attribute (default: "Lax")
29
+ */
30
+ sameSite?: "Strict" | "Lax" | "None";
31
+ }
32
+ type NextCookieStore$1 = {
33
+ get: (name: string) => {
34
+ value: string;
35
+ } | undefined;
36
+ set: (name: string, value: string, options?: any) => void;
37
+ delete: (name: string) => void;
38
+ };
39
+ /**
40
+ * Server-side token storage that uses Next.js cookies API
41
+ */
42
+ declare class ServerTokenStorage implements TokenStorage {
43
+ private accessTokenKey;
44
+ private refreshTokenKey;
45
+ private options;
46
+ private cookieStore;
47
+ constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
48
+ getAccessToken(): Promise<string | null>;
49
+ setAccessToken(token: string): Promise<void>;
50
+ getRefreshToken(): Promise<string | null>;
51
+ setRefreshToken(token: string): Promise<void>;
52
+ clearTokens(): Promise<void>;
53
+ }
54
+
55
+ /**
56
+ * Configuration for the NextJS SDK wrapper
57
+ */
58
+ interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
59
+ /**
60
+ * Token storage configuration options
61
+ */
62
+ tokenStorageOptions?: NextJSTokenStorageOptions;
63
+ }
64
+ /**
65
+ * Runtime configuration overrides that can be passed to storefront() function
66
+ * These override environment variables for that specific request
67
+ */
68
+ interface StorefrontRuntimeConfig {
69
+ /**
70
+ * Override environment variables
71
+ */
72
+ storeId?: string;
73
+ apiKey?: string;
74
+ environment?: Environment;
75
+ baseUrl?: string;
76
+ timeout?: number;
77
+ debug?: boolean;
78
+ /**
79
+ * Advanced options not available via environment variables
80
+ */
81
+ accessToken?: string;
82
+ refreshToken?: string;
83
+ defaultHeaders?: SupportedDefaultHeaders;
84
+ logger?: DebugLoggerFn;
85
+ onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
86
+ onTokensCleared?: () => void;
87
+ /**
88
+ * Token storage configuration
89
+ */
90
+ tokenStorageOptions?: NextJSTokenStorageOptions;
91
+ }
92
+ type NextCookieStore = {
93
+ get: (name: string) => {
94
+ value: string;
95
+ } | undefined;
96
+ set: (name: string, value: string, options?: any) => void;
97
+ delete: (name: string) => void;
98
+ };
99
+ /**
100
+ * Smart SDK getter that automatically detects environment
101
+ *
102
+ * Usage:
103
+ * - Client-side: getStorefrontSDK()
104
+ * - Server-side with request context: getStorefrontSDK(await cookies())
105
+ * - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
106
+ */
107
+ declare function getStorefrontSDK(): StorefrontSDK;
108
+ declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
109
+ /**
110
+ * Initialize the SDK (internal use)
111
+ * This should be called once in your app via StorefrontSDKInitializer
112
+ */
113
+ declare function initializeStorefrontSDK(): void;
114
+
115
+ export { type NextJSSDKConfig as N, type StorefrontRuntimeConfig as S, ServerTokenStorage as a, type NextJSTokenStorageOptions as b, getStorefrontSDK as g, initializeStorefrontSDK as i };
@@ -0,0 +1,115 @@
1
+ import { TokenStorage, Environment, SupportedDefaultHeaders, DebugLoggerFn, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
2
+
3
+ /**
4
+ * Configuration options for NextJSTokenStorage
5
+ */
6
+ interface NextJSTokenStorageOptions {
7
+ /**
8
+ * Prefix for cookie names (default: "ce_")
9
+ */
10
+ prefix?: string;
11
+ /**
12
+ * Maximum age of cookies in seconds (default: 30 days)
13
+ */
14
+ maxAge?: number;
15
+ /**
16
+ * Cookie path (default: "/")
17
+ */
18
+ path?: string;
19
+ /**
20
+ * Cookie domain (default: current domain)
21
+ */
22
+ domain?: string;
23
+ /**
24
+ * Whether cookies should be secure (default: auto-detect based on environment)
25
+ */
26
+ secure?: boolean;
27
+ /**
28
+ * SameSite cookie attribute (default: "Lax")
29
+ */
30
+ sameSite?: "Strict" | "Lax" | "None";
31
+ }
32
+ type NextCookieStore$1 = {
33
+ get: (name: string) => {
34
+ value: string;
35
+ } | undefined;
36
+ set: (name: string, value: string, options?: any) => void;
37
+ delete: (name: string) => void;
38
+ };
39
+ /**
40
+ * Server-side token storage that uses Next.js cookies API
41
+ */
42
+ declare class ServerTokenStorage implements TokenStorage {
43
+ private accessTokenKey;
44
+ private refreshTokenKey;
45
+ private options;
46
+ private cookieStore;
47
+ constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
48
+ getAccessToken(): Promise<string | null>;
49
+ setAccessToken(token: string): Promise<void>;
50
+ getRefreshToken(): Promise<string | null>;
51
+ setRefreshToken(token: string): Promise<void>;
52
+ clearTokens(): Promise<void>;
53
+ }
54
+
55
+ /**
56
+ * Configuration for the NextJS SDK wrapper
57
+ */
58
+ interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
59
+ /**
60
+ * Token storage configuration options
61
+ */
62
+ tokenStorageOptions?: NextJSTokenStorageOptions;
63
+ }
64
+ /**
65
+ * Runtime configuration overrides that can be passed to storefront() function
66
+ * These override environment variables for that specific request
67
+ */
68
+ interface StorefrontRuntimeConfig {
69
+ /**
70
+ * Override environment variables
71
+ */
72
+ storeId?: string;
73
+ apiKey?: string;
74
+ environment?: Environment;
75
+ baseUrl?: string;
76
+ timeout?: number;
77
+ debug?: boolean;
78
+ /**
79
+ * Advanced options not available via environment variables
80
+ */
81
+ accessToken?: string;
82
+ refreshToken?: string;
83
+ defaultHeaders?: SupportedDefaultHeaders;
84
+ logger?: DebugLoggerFn;
85
+ onTokensUpdated?: (accessToken: string, refreshToken: string) => void;
86
+ onTokensCleared?: () => void;
87
+ /**
88
+ * Token storage configuration
89
+ */
90
+ tokenStorageOptions?: NextJSTokenStorageOptions;
91
+ }
92
+ type NextCookieStore = {
93
+ get: (name: string) => {
94
+ value: string;
95
+ } | undefined;
96
+ set: (name: string, value: string, options?: any) => void;
97
+ delete: (name: string) => void;
98
+ };
99
+ /**
100
+ * Smart SDK getter that automatically detects environment
101
+ *
102
+ * Usage:
103
+ * - Client-side: getStorefrontSDK()
104
+ * - Server-side with request context: getStorefrontSDK(await cookies())
105
+ * - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
106
+ */
107
+ declare function getStorefrontSDK(): StorefrontSDK;
108
+ declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
109
+ /**
110
+ * Initialize the SDK (internal use)
111
+ * This should be called once in your app via StorefrontSDKInitializer
112
+ */
113
+ declare function initializeStorefrontSDK(): void;
114
+
115
+ export { type NextJSSDKConfig as N, type StorefrontRuntimeConfig as S, ServerTokenStorage as a, type NextJSTokenStorageOptions as b, getStorefrontSDK as g, initializeStorefrontSDK as i };
package/dist/server.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
18
16
  return to;
19
17
  };
20
18
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
 
31
21
  // src/server.ts
@@ -33,8 +23,7 @@ var server_exports = {};
33
23
  __export(server_exports, {
34
24
  ServerTokenStorage: () => ServerTokenStorage,
35
25
  getStorefrontSDK: () => getStorefrontSDK,
36
- initializeStorefrontSDK: () => initializeStorefrontSDK,
37
- storefront: () => storefront
26
+ initializeStorefrontSDK: () => initializeStorefrontSDK
38
27
  });
39
28
  module.exports = __toCommonJS(server_exports);
40
29
 
@@ -221,21 +210,17 @@ var BuildCachingMemoryTokenStorage = class {
221
210
  }
222
211
  async getAccessToken() {
223
212
  if (this.access) {
224
- console.log(`\u{1F535} [BuildCache] Using instance token for key: ${this.cacheKey}`);
225
213
  return this.access;
226
214
  }
227
215
  const cached = getCachedToken(this.cacheKey);
228
216
  if (cached?.accessToken) {
229
- console.log(`\u{1F7E2} [BuildCache] Using cached token for key: ${this.cacheKey}`);
230
217
  this.access = cached.accessToken;
231
218
  this.refresh = cached.refreshToken ?? null;
232
219
  return this.access;
233
220
  }
234
- console.log(`\u{1F7E1} [BuildCache] No cached token found for key: ${this.cacheKey}`);
235
221
  return null;
236
222
  }
237
223
  async setAccessToken(token) {
238
- console.log(`\u{1F7E0} [BuildCache] Caching new access token for key: ${this.cacheKey}`);
239
224
  this.access = token;
240
225
  setCachedToken(this.cacheKey, {
241
226
  accessToken: token,
@@ -262,30 +247,63 @@ var BuildCachingMemoryTokenStorage = class {
262
247
  };
263
248
 
264
249
  // src/sdk-manager.ts
265
- var globalConfig = null;
266
- function getEnvConfig() {
267
- return {
268
- storeId: process.env.NEXT_PUBLIC_STORE_ID || "",
269
- environment: process.env.NEXT_PUBLIC_ENVIRONMENT === "production" ? import_storefront_sdk.Environment.Production : import_storefront_sdk.Environment.Staging,
270
- apiKey: process.env.NEXT_PUBLIC_API_KEY
271
- };
272
- }
273
250
  function getConfig() {
274
- if (globalConfig) {
275
- return globalConfig;
251
+ const envStoreId = process.env.NEXT_PUBLIC_STORE_ID;
252
+ const envApiKey = process.env.NEXT_PUBLIC_API_KEY;
253
+ const envEnvironment = process.env.NEXT_PUBLIC_ENVIRONMENT;
254
+ const envBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
255
+ const envTimeout = process.env.NEXT_PUBLIC_API_TIMEOUT ? parseInt(process.env.NEXT_PUBLIC_API_TIMEOUT, 10) : void 0;
256
+ const envDebug = process.env.NEXT_PUBLIC_DEBUG_MODE === "true";
257
+ const envDefaultHeaders = {};
258
+ if (process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_GROUP_ID) {
259
+ envDefaultHeaders.customer_group_id = process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_GROUP_ID;
276
260
  }
277
- return getEnvConfig();
278
- }
279
- var clientSDK = null;
280
- function hasRequestContext() {
281
- try {
282
- const { cookies } = require("next/headers");
283
- cookies();
284
- return true;
285
- } catch {
286
- return false;
261
+ const storeId = globalStorefrontConfig?.storeId || envStoreId;
262
+ const apiKey = globalStorefrontConfig?.apiKey || envApiKey;
263
+ const environment = globalStorefrontConfig?.environment || (envEnvironment === "production" ? import_storefront_sdk.Environment.Production : import_storefront_sdk.Environment.Staging);
264
+ const baseUrl = globalStorefrontConfig?.baseUrl || envBaseUrl;
265
+ const timeout = globalStorefrontConfig?.timeout || envTimeout;
266
+ const debug = globalStorefrontConfig?.debug !== void 0 ? globalStorefrontConfig.debug : envDebug;
267
+ const defaultHeaders = {
268
+ ...envDefaultHeaders,
269
+ ...globalStorefrontConfig?.defaultHeaders
270
+ };
271
+ if (!storeId || !apiKey) {
272
+ throw new Error(
273
+ `StorefrontSDK configuration missing! Please set the following environment variables:
274
+
275
+ NEXT_PUBLIC_STORE_ID=your-store-id
276
+ NEXT_PUBLIC_API_KEY=your-api-key
277
+ NEXT_PUBLIC_ENVIRONMENT=staging (or production)
278
+
279
+ These variables are required for both client and server contexts to work.`
280
+ );
287
281
  }
282
+ const config = {
283
+ storeId,
284
+ apiKey,
285
+ environment
286
+ };
287
+ if (baseUrl) config.baseUrl = baseUrl;
288
+ if (timeout) config.timeout = timeout;
289
+ if (debug) config.debug = debug;
290
+ const logger = globalStorefrontConfig?.logger;
291
+ const accessToken = globalStorefrontConfig?.accessToken;
292
+ const refreshToken = globalStorefrontConfig?.refreshToken;
293
+ const onTokensUpdated = globalStorefrontConfig?.onTokensUpdated;
294
+ const onTokensCleared = globalStorefrontConfig?.onTokensCleared;
295
+ const tokenStorageOptions = globalStorefrontConfig?.tokenStorageOptions;
296
+ if (logger) config.logger = logger;
297
+ if (accessToken) config.accessToken = accessToken;
298
+ if (refreshToken) config.refreshToken = refreshToken;
299
+ if (onTokensUpdated) config.onTokensUpdated = onTokensUpdated;
300
+ if (onTokensCleared) config.onTokensCleared = onTokensCleared;
301
+ if (Object.keys(defaultHeaders).length > 0) config.defaultHeaders = defaultHeaders;
302
+ if (tokenStorageOptions) config.tokenStorageOptions = tokenStorageOptions;
303
+ return config;
288
304
  }
305
+ var globalStorefrontConfig = null;
306
+ var clientSDK = null;
289
307
  function createTokenStorage(cookieStore, options, config) {
290
308
  if (typeof window !== "undefined") {
291
309
  return new ClientTokenStorage(options);
@@ -296,14 +314,12 @@ function createTokenStorage(cookieStore, options, config) {
296
314
  const shouldCache = process.env.NEXT_BUILD_CACHE_TOKENS === "true";
297
315
  if (shouldCache && config) {
298
316
  const cacheKey = `${config.storeId}:${config.environment || "production"}`;
299
- console.log(`\u{1F680} [BuildCache] Using BuildCachingMemoryTokenStorage with key: ${cacheKey}`);
300
317
  return new BuildCachingMemoryTokenStorage(cacheKey);
301
318
  }
302
- console.log(`\u{1F504} [Build] Using standard MemoryTokenStorage (caching disabled)`);
303
319
  return new import_storefront_sdk.MemoryTokenStorage();
304
320
  }
305
321
  var getServerSDKCached = (0, import_react.cache)((cookieStore) => {
306
- const config = getEnvConfig();
322
+ const config = getConfig();
307
323
  return new import_storefront_sdk.StorefrontSDK({
308
324
  ...config,
309
325
  tokenStorage: createTokenStorage(
@@ -315,7 +331,7 @@ var getServerSDKCached = (0, import_react.cache)((cookieStore) => {
315
331
  });
316
332
  var buildTimeSDK = null;
317
333
  function getBuildTimeSDK() {
318
- const config = getEnvConfig();
334
+ const config = getConfig();
319
335
  if (!buildTimeSDK) {
320
336
  buildTimeSDK = new import_storefront_sdk.StorefrontSDK({
321
337
  ...config,
@@ -351,59 +367,13 @@ function getStorefrontSDK(cookieStore) {
351
367
  if (cookieStore) {
352
368
  return getServerSDKCached(cookieStore);
353
369
  }
354
- if (hasRequestContext()) {
355
- let autoDetectMessage = "";
356
- try {
357
- require.resolve("next/headers");
358
- autoDetectMessage = `
359
-
360
- \u{1F50D} Auto-detection attempted but failed. You may be in:
361
- - Server Action (use: const sdk = getStorefrontSDK(await cookies()))
362
- - API Route (use: const sdk = getStorefrontSDK(cookies()))
363
- - Server Component in App Router (use: const sdk = getStorefrontSDK(cookies()))
364
- `;
365
- } catch {
366
- autoDetectMessage = `
367
-
368
- \u{1F4A1} Make sure you have Next.js installed and are in a server context.
369
- `;
370
- }
371
- throw new Error(
372
- `
373
- \u{1F6A8} Server Environment Detected!
374
-
375
- You're calling getStorefrontSDK() on the server without cookies.
376
- Please pass the Next.js cookie store:
377
-
378
- \u2705 Correct usage:
379
- import { cookies } from 'next/headers';
380
-
381
- // Server Actions & Route Handlers
382
- const sdk = getStorefrontSDK(await cookies());
383
-
384
- // API Routes & Server Components (App Router)
385
- const sdk = getStorefrontSDK(cookies());
386
-
387
- \u274C Your current usage:
388
- const sdk = getStorefrontSDK(); // Missing cookies!
389
- ${autoDetectMessage}
390
- This is required for server-side token access.
391
- `.trim()
392
- );
393
- }
394
370
  return getBuildTimeSDK();
395
371
  }
396
- function initializeStorefrontSDK(config) {
397
- globalConfig = config;
372
+ function initializeStorefrontSDK() {
398
373
  clientSDK = null;
399
374
  buildTimeSDK = null;
400
375
  }
401
376
 
402
- // src/storefront.ts
403
- function storefront(cookieStore) {
404
- return getStorefrontSDK(cookieStore);
405
- }
406
-
407
377
  // src/server.ts
408
378
  __reExport(server_exports, require("@commercengine/storefront-sdk"), module.exports);
409
379
  // Annotate the CommonJS export names for ESM import in node:
@@ -411,6 +381,5 @@ __reExport(server_exports, require("@commercengine/storefront-sdk"), module.expo
411
381
  ServerTokenStorage,
412
382
  getStorefrontSDK,
413
383
  initializeStorefrontSDK,
414
- storefront,
415
384
  ...require("@commercengine/storefront-sdk")
416
385
  });
package/dist/server.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- export { NextJSSDKConfig, NextJSTokenStorageOptions, ServerTokenStorage, getStorefrontSDK, i as initializeStorefrontSDK } from './index.cjs';
2
- export { default as storefront } from './storefront.cjs';
1
+ export { N as NextJSSDKConfig, b as NextJSTokenStorageOptions, a as ServerTokenStorage, g as getStorefrontSDK, i as initializeStorefrontSDK } from './server-CwxgXezP.cjs';
3
2
  export * from '@commercengine/storefront-sdk';
4
3
  export { StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
package/dist/server.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { NextJSSDKConfig, NextJSTokenStorageOptions, ServerTokenStorage, getStorefrontSDK, i as initializeStorefrontSDK } from './index.js';
2
- export { default as storefront } from './storefront.js';
1
+ export { N as NextJSSDKConfig, b as NextJSTokenStorageOptions, a as ServerTokenStorage, g as getStorefrontSDK, i as initializeStorefrontSDK } from './server-CwxgXezP.js';
3
2
  export * from '@commercengine/storefront-sdk';
4
3
  export { StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';