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

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/index.d.ts CHANGED
@@ -1,107 +1,42 @@
1
- import { TokenStorage, StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
1
+ import { StorefrontSDK } from '@commercengine/storefront-sdk';
2
2
  export * from '@commercengine/storefront-sdk';
3
- export { StorefrontSDK, StorefrontSDKOptions } from '@commercengine/storefront-sdk';
4
- export { default as storefront } from './storefront.js';
3
+ export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, TokenStorage } from '@commercengine/storefront-sdk';
4
+ import { S as StorefrontRuntimeConfig } from './server-CwxgXezP.js';
5
5
 
6
- /**
7
- * Configuration options for NextJSTokenStorage
8
- */
9
- interface NextJSTokenStorageOptions {
10
- /**
11
- * Prefix for cookie names (default: "ce_")
12
- */
13
- prefix?: string;
14
- /**
15
- * Maximum age of cookies in seconds (default: 30 days)
16
- */
17
- maxAge?: number;
18
- /**
19
- * Cookie path (default: "/")
20
- */
21
- path?: string;
22
- /**
23
- * Cookie domain (default: current domain)
24
- */
25
- domain?: string;
26
- /**
27
- * Whether cookies should be secure (default: auto-detect based on environment)
28
- */
29
- secure?: boolean;
30
- /**
31
- * SameSite cookie attribute (default: "Lax")
32
- */
33
- sameSite?: "Strict" | "Lax" | "None";
34
- }
35
- /**
36
- * Client-side token storage that uses document.cookie
37
- */
38
- declare class ClientTokenStorage implements TokenStorage {
39
- private accessTokenKey;
40
- private refreshTokenKey;
41
- private options;
42
- constructor(options?: NextJSTokenStorageOptions);
43
- getAccessToken(): Promise<string | null>;
44
- setAccessToken(token: string): Promise<void>;
45
- getRefreshToken(): Promise<string | null>;
46
- setRefreshToken(token: string): Promise<void>;
47
- clearTokens(): Promise<void>;
48
- private getCookie;
49
- private setCookie;
50
- private deleteCookie;
51
- }
52
- type NextCookieStore$1 = {
53
- get: (name: string) => {
54
- value: string;
55
- } | undefined;
56
- set: (name: string, value: string, options?: any) => void;
57
- delete: (name: string) => void;
58
- };
59
- /**
60
- * Server-side token storage that uses Next.js cookies API
61
- */
62
- declare class ServerTokenStorage implements TokenStorage {
63
- private accessTokenKey;
64
- private refreshTokenKey;
65
- private options;
66
- private cookieStore;
67
- constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
68
- getAccessToken(): Promise<string | null>;
69
- setAccessToken(token: string): Promise<void>;
70
- getRefreshToken(): Promise<string | null>;
71
- setRefreshToken(token: string): Promise<void>;
72
- clearTokens(): Promise<void>;
73
- }
74
-
75
- /**
76
- * Configuration for the NextJS SDK wrapper
77
- */
78
- interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
79
- /**
80
- * Token storage configuration options
81
- */
82
- tokenStorageOptions?: NextJSTokenStorageOptions;
83
- }
84
6
  type NextCookieStore = {
85
7
  get: (name: string) => {
8
+ name: string;
86
9
  value: string;
87
10
  } | undefined;
88
- set: (name: string, value: string, options?: any) => void;
11
+ set: (name: string, value: string, opts?: Record<string, unknown>) => void;
89
12
  delete: (name: string) => void;
90
13
  };
91
14
  /**
92
- * Smart SDK getter that automatically detects environment
15
+ * Creates a configured storefront function that works universally across all Next.js contexts
93
16
  *
94
17
  * Usage:
95
- * - Client-side: getStorefrontSDK()
96
- * - Server-side with request context: getStorefrontSDK(await cookies())
97
- * - SSG/ISR (no request context): getStorefrontSDK() (uses memory storage)
98
- */
99
- declare function getStorefrontSDK(): StorefrontSDK;
100
- declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
101
- /**
102
- * Initialize the SDK with configuration (internal use)
103
- * This should be called once in your app via StorefrontSDKInitializer
18
+ * ```typescript
19
+ * // lib/storefront.ts
20
+ * import { createStorefront } from "@commercengine/storefront-sdk-nextjs";
21
+ *
22
+ * export const storefront = createStorefront({
23
+ * debug: true,
24
+ * logger: (msg, ...args) => console.log('[DEBUG]', msg, ...args)
25
+ * });
26
+ * ```
27
+ *
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
104
30
  */
105
- declare function initializeStorefrontSDK(config: NextJSSDKConfig): void;
31
+ declare function createStorefront(config?: StorefrontRuntimeConfig): {
32
+ (): StorefrontSDK;
33
+ (cookieStore: NextCookieStore): StorefrontSDK;
34
+ (options: {
35
+ isRootLayout: true;
36
+ }): StorefrontSDK;
37
+ (cookieStore: NextCookieStore, options: {
38
+ isRootLayout?: boolean;
39
+ }): StorefrontSDK;
40
+ };
106
41
 
107
- export { ClientTokenStorage, type NextJSSDKConfig, type NextJSTokenStorageOptions, ServerTokenStorage, getStorefrontSDK, initializeStorefrontSDK as i };
42
+ export { StorefrontRuntimeConfig, createStorefront };
package/dist/index.js CHANGED
@@ -1,9 +1,23 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
1
+ // src/index.ts
2
+ import { StorefrontSDK as StorefrontSDK2, Environment as Environment2 } from "@commercengine/storefront-sdk";
3
+ import {
4
+ StorefrontAPIClient,
5
+ AuthClient,
6
+ CartClient,
7
+ CatalogClient,
8
+ CustomerClient,
9
+ HelpersClient,
10
+ ShippingClient,
11
+ OrderClient,
12
+ StoreConfigClient,
13
+ ResponseUtils
14
+ } from "@commercengine/storefront-sdk";
15
+ import {
16
+ TokenStorage,
17
+ MemoryTokenStorage as MemoryTokenStorage2,
18
+ BrowserTokenStorage,
19
+ CookieTokenStorage
20
+ } from "@commercengine/storefront-sdk";
7
21
 
8
22
  // src/sdk-manager.ts
9
23
  import { cache } from "react";
@@ -192,21 +206,17 @@ var BuildCachingMemoryTokenStorage = class {
192
206
  }
193
207
  async getAccessToken() {
194
208
  if (this.access) {
195
- console.log(`\u{1F535} [BuildCache] Using instance token for key: ${this.cacheKey}`);
196
209
  return this.access;
197
210
  }
198
211
  const cached = getCachedToken(this.cacheKey);
199
212
  if (cached?.accessToken) {
200
- console.log(`\u{1F7E2} [BuildCache] Using cached token for key: ${this.cacheKey}`);
201
213
  this.access = cached.accessToken;
202
214
  this.refresh = cached.refreshToken ?? null;
203
215
  return this.access;
204
216
  }
205
- console.log(`\u{1F7E1} [BuildCache] No cached token found for key: ${this.cacheKey}`);
206
217
  return null;
207
218
  }
208
219
  async setAccessToken(token) {
209
- console.log(`\u{1F7E0} [BuildCache] Caching new access token for key: ${this.cacheKey}`);
210
220
  this.access = token;
211
221
  setCachedToken(this.cacheKey, {
212
222
  accessToken: token,
@@ -233,30 +243,63 @@ var BuildCachingMemoryTokenStorage = class {
233
243
  };
234
244
 
235
245
  // src/sdk-manager.ts
236
- var globalConfig = null;
237
- function getEnvConfig() {
238
- return {
239
- storeId: process.env.NEXT_PUBLIC_STORE_ID || "",
240
- environment: process.env.NEXT_PUBLIC_ENVIRONMENT === "production" ? Environment.Production : Environment.Staging,
241
- apiKey: process.env.NEXT_PUBLIC_API_KEY
242
- };
243
- }
244
246
  function getConfig() {
245
- if (globalConfig) {
246
- return globalConfig;
247
+ const envStoreId = process.env.NEXT_PUBLIC_STORE_ID;
248
+ const envApiKey = process.env.NEXT_PUBLIC_API_KEY;
249
+ const envEnvironment = process.env.NEXT_PUBLIC_ENVIRONMENT;
250
+ const envBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
251
+ const envTimeout = process.env.NEXT_PUBLIC_API_TIMEOUT ? parseInt(process.env.NEXT_PUBLIC_API_TIMEOUT, 10) : void 0;
252
+ const envDebug = process.env.NEXT_PUBLIC_DEBUG_MODE === "true";
253
+ const envDefaultHeaders = {};
254
+ if (process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_GROUP_ID) {
255
+ envDefaultHeaders.customer_group_id = process.env.NEXT_PUBLIC_DEFAULT_CUSTOMER_GROUP_ID;
247
256
  }
248
- return getEnvConfig();
249
- }
250
- var clientSDK = null;
251
- function hasRequestContext() {
252
- try {
253
- const { cookies } = __require("next/headers");
254
- cookies();
255
- return true;
256
- } catch {
257
- return false;
257
+ const storeId = globalStorefrontConfig?.storeId || envStoreId;
258
+ const apiKey = globalStorefrontConfig?.apiKey || envApiKey;
259
+ const environment = globalStorefrontConfig?.environment || (envEnvironment === "production" ? Environment.Production : Environment.Staging);
260
+ const baseUrl = globalStorefrontConfig?.baseUrl || envBaseUrl;
261
+ const timeout = globalStorefrontConfig?.timeout || envTimeout;
262
+ const debug = globalStorefrontConfig?.debug !== void 0 ? globalStorefrontConfig.debug : envDebug;
263
+ const defaultHeaders = {
264
+ ...envDefaultHeaders,
265
+ ...globalStorefrontConfig?.defaultHeaders
266
+ };
267
+ if (!storeId || !apiKey) {
268
+ throw new Error(
269
+ `StorefrontSDK configuration missing! Please set the following environment variables:
270
+
271
+ NEXT_PUBLIC_STORE_ID=your-store-id
272
+ NEXT_PUBLIC_API_KEY=your-api-key
273
+ NEXT_PUBLIC_ENVIRONMENT=staging (or production)
274
+
275
+ These variables are required for both client and server contexts to work.`
276
+ );
258
277
  }
278
+ const config = {
279
+ storeId,
280
+ apiKey,
281
+ environment
282
+ };
283
+ if (baseUrl) config.baseUrl = baseUrl;
284
+ if (timeout) config.timeout = timeout;
285
+ if (debug) config.debug = debug;
286
+ const logger = globalStorefrontConfig?.logger;
287
+ const accessToken = globalStorefrontConfig?.accessToken;
288
+ const refreshToken = globalStorefrontConfig?.refreshToken;
289
+ const onTokensUpdated = globalStorefrontConfig?.onTokensUpdated;
290
+ const onTokensCleared = globalStorefrontConfig?.onTokensCleared;
291
+ const tokenStorageOptions = globalStorefrontConfig?.tokenStorageOptions;
292
+ if (logger) config.logger = logger;
293
+ if (accessToken) config.accessToken = accessToken;
294
+ if (refreshToken) config.refreshToken = refreshToken;
295
+ if (onTokensUpdated) config.onTokensUpdated = onTokensUpdated;
296
+ if (onTokensCleared) config.onTokensCleared = onTokensCleared;
297
+ if (Object.keys(defaultHeaders).length > 0) config.defaultHeaders = defaultHeaders;
298
+ if (tokenStorageOptions) config.tokenStorageOptions = tokenStorageOptions;
299
+ return config;
259
300
  }
301
+ var globalStorefrontConfig = null;
302
+ var clientSDK = null;
260
303
  function createTokenStorage(cookieStore, options, config) {
261
304
  if (typeof window !== "undefined") {
262
305
  return new ClientTokenStorage(options);
@@ -267,14 +310,12 @@ function createTokenStorage(cookieStore, options, config) {
267
310
  const shouldCache = process.env.NEXT_BUILD_CACHE_TOKENS === "true";
268
311
  if (shouldCache && config) {
269
312
  const cacheKey = `${config.storeId}:${config.environment || "production"}`;
270
- console.log(`\u{1F680} [BuildCache] Using BuildCachingMemoryTokenStorage with key: ${cacheKey}`);
271
313
  return new BuildCachingMemoryTokenStorage(cacheKey);
272
314
  }
273
- console.log(`\u{1F504} [Build] Using standard MemoryTokenStorage (caching disabled)`);
274
315
  return new MemoryTokenStorage();
275
316
  }
276
317
  var getServerSDKCached = cache((cookieStore) => {
277
- const config = getEnvConfig();
318
+ const config = getConfig();
278
319
  return new StorefrontSDK({
279
320
  ...config,
280
321
  tokenStorage: createTokenStorage(
@@ -286,7 +327,7 @@ var getServerSDKCached = cache((cookieStore) => {
286
327
  });
287
328
  var buildTimeSDK = null;
288
329
  function getBuildTimeSDK() {
289
- const config = getEnvConfig();
330
+ const config = getConfig();
290
331
  if (!buildTimeSDK) {
291
332
  buildTimeSDK = new StorefrontSDK({
292
333
  ...config,
@@ -322,59 +363,78 @@ function getStorefrontSDK(cookieStore) {
322
363
  if (cookieStore) {
323
364
  return getServerSDKCached(cookieStore);
324
365
  }
325
- if (hasRequestContext()) {
326
- let autoDetectMessage = "";
327
- try {
328
- __require.resolve("next/headers");
329
- autoDetectMessage = `
330
-
331
- \u{1F50D} Auto-detection attempted but failed. You may be in:
332
- - Server Action (use: const sdk = getStorefrontSDK(await cookies()))
333
- - API Route (use: const sdk = getStorefrontSDK(cookies()))
334
- - Server Component in App Router (use: const sdk = getStorefrontSDK(cookies()))
335
- `;
336
- } catch {
337
- autoDetectMessage = `
366
+ return getBuildTimeSDK();
367
+ }
368
+ function setGlobalStorefrontConfig(config) {
369
+ globalStorefrontConfig = config;
370
+ clientSDK = null;
371
+ buildTimeSDK = null;
372
+ }
338
373
 
339
- \u{1F4A1} Make sure you have Next.js installed and are in a server context.
340
- `;
374
+ // src/create-storefront.ts
375
+ function createStorefront(config) {
376
+ if (config) {
377
+ setGlobalStorefrontConfig(config);
378
+ }
379
+ function storefront(cookieStoreOrOptions, options) {
380
+ if (typeof window !== "undefined") {
381
+ return getStorefrontSDK();
382
+ }
383
+ let cookieStore;
384
+ let isRootLayout = false;
385
+ if (cookieStoreOrOptions) {
386
+ if ("isRootLayout" in cookieStoreOrOptions) {
387
+ isRootLayout = cookieStoreOrOptions.isRootLayout;
388
+ } else {
389
+ cookieStore = cookieStoreOrOptions;
390
+ isRootLayout = options?.isRootLayout || false;
391
+ }
392
+ }
393
+ if (cookieStore) {
394
+ return getStorefrontSDK(cookieStore);
395
+ }
396
+ if (process.env.NEXT_IS_BUILD === "true" || process.env.NEXT_BUILD_CACHE_TOKENS === "true") {
397
+ return getStorefrontSDK();
398
+ }
399
+ if (isRootLayout) {
400
+ return getStorefrontSDK();
341
401
  }
342
402
  throw new Error(
343
- `
344
- \u{1F6A8} Server Environment Detected!
345
-
346
- You're calling getStorefrontSDK() on the server without cookies.
347
- Please pass the Next.js cookie store:
348
-
349
- \u2705 Correct usage:
350
- import { cookies } from 'next/headers';
351
-
352
- // Server Actions & Route Handlers
353
- const sdk = getStorefrontSDK(await cookies());
354
-
355
- // API Routes & Server Components (App Router)
356
- const sdk = getStorefrontSDK(cookies());
357
-
358
- \u274C Your current usage:
359
- const sdk = getStorefrontSDK(); // Missing cookies!
360
- ${autoDetectMessage}
361
- This is required for server-side token access.
362
- `.trim()
403
+ [
404
+ "\u{1F6A8} Server context requires cookies for user continuity!",
405
+ "",
406
+ "You're calling storefront() on the server without cookies.",
407
+ "This breaks user session continuity and analytics tracking.",
408
+ "",
409
+ "\u2705 Correct usage:",
410
+ " import { cookies } from 'next/headers'",
411
+ " const sdk = storefront(cookies())",
412
+ "",
413
+ "\u{1F4CD} Root Layout exception:",
414
+ " const sdk = storefront({ isRootLayout: true })",
415
+ "",
416
+ "This is required to maintain consistent user identity across requests."
417
+ ].join("\n")
363
418
  );
364
419
  }
365
- return getBuildTimeSDK();
420
+ return storefront;
366
421
  }
367
-
368
- // src/storefront.ts
369
- function storefront(cookieStore) {
370
- return getStorefrontSDK(cookieStore);
371
- }
372
-
373
- // src/index.ts
374
- export * from "@commercengine/storefront-sdk";
375
422
  export {
376
- ClientTokenStorage,
377
- ServerTokenStorage,
378
- getStorefrontSDK,
379
- storefront
423
+ AuthClient,
424
+ BrowserTokenStorage,
425
+ CartClient,
426
+ CatalogClient,
427
+ CookieTokenStorage,
428
+ CustomerClient,
429
+ Environment2 as Environment,
430
+ HelpersClient,
431
+ MemoryTokenStorage2 as MemoryTokenStorage,
432
+ OrderClient,
433
+ ResponseUtils,
434
+ ShippingClient,
435
+ StoreConfigClient,
436
+ StorefrontAPIClient,
437
+ StorefrontSDK2 as StorefrontSDK,
438
+ TokenStorage,
439
+ createStorefront
380
440
  };
@@ -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 };