@commercengine/storefront-sdk-nextjs 0.2.10 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +89 -0
- package/README.md +180 -440
- package/dist/client.d.mts +4 -4
- package/dist/client.mjs +9 -9
- package/dist/index.d.mts +23 -24
- package/dist/index.mjs +13 -35
- package/dist/manager.d.mts +18 -13
- package/dist/manager.mjs +67 -50
- package/dist/server.d.mts +3 -3
- package/dist/server.mjs +3 -3
- package/package.json +5 -4
package/dist/client.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils,
|
|
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,
|
|
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 {
|
|
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,
|
|
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
|
|
26
|
+
* Bootstrap the client-side session if no access token exists yet.
|
|
27
27
|
*/
|
|
28
|
-
async function
|
|
29
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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,
|
|
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,
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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(
|
|
32
|
+
* logger: (msg, ...args) => console.log("[DEBUG]", msg, ...args),
|
|
25
33
|
* });
|
|
26
34
|
* ```
|
|
27
35
|
*
|
|
28
|
-
* @param config Optional configuration for advanced options
|
|
29
|
-
* @returns A storefront
|
|
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,
|
|
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 {
|
|
2
|
-
import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils,
|
|
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
|
|
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(
|
|
15
|
+
* logger: (msg, ...args) => console.log("[DEBUG]", msg, ...args),
|
|
16
16
|
* });
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
|
-
* @param config Optional configuration for advanced options
|
|
20
|
-
* @returns A storefront
|
|
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
|
|
25
|
-
|
|
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
|
|
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,
|
|
34
|
+
export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, PublicCatalogClient, PublicHelpersClient, PublicStoreConfigClient, PublicStorefrontAPIClient, PublicStorefrontSDK, ResponseUtils, SessionStorefrontAPIClient, SessionStorefrontSDK, StoreConfigClient, createStorefront };
|
package/dist/manager.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DebugLoggerFn, Environment,
|
|
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<
|
|
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
|
|
84
|
-
* These override environment variables for that specific
|
|
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
|
-
*
|
|
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:
|
|
115
|
-
* - Server-side with request context:
|
|
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
|
|
119
|
-
declare function
|
|
124
|
+
declare function getSessionStorefrontSDK(): SessionStorefrontSDK;
|
|
125
|
+
declare function getSessionStorefrontSDK(cookieStore: NextCookieStore): SessionStorefrontSDK;
|
|
120
126
|
/**
|
|
121
|
-
*
|
|
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 {
|
|
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,
|
|
3
|
-
import {
|
|
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
|
|
119
|
+
let clientSessionSDK = null;
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
121
|
+
* Public SDK singleton shared by non-session reads
|
|
122
122
|
*/
|
|
123
|
-
let
|
|
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(`
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
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
|
|
214
|
+
function getPublicStorefrontSDK() {
|
|
203
215
|
const config = getConfig();
|
|
204
|
-
if (!
|
|
205
|
-
|
|
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
|
|
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 (!
|
|
215
|
-
|
|
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
|
|
221
|
-
|
|
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
|
-
|
|
230
|
-
|
|
247
|
+
clientSessionSDK = null;
|
|
248
|
+
publicSDK = null;
|
|
231
249
|
}
|
|
232
250
|
/**
|
|
233
|
-
*
|
|
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
|
-
|
|
238
|
-
|
|
254
|
+
clientSessionSDK = null;
|
|
255
|
+
publicSDK = null;
|
|
239
256
|
}
|
|
240
257
|
|
|
241
258
|
//#endregion
|
|
242
|
-
export {
|
|
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
|
|
2
|
-
import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils,
|
|
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,
|
|
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 {
|
|
2
|
-
import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils,
|
|
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,
|
|
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.
|
|
3
|
+
"version": "0.3.1",
|
|
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.
|
|
47
|
-
"@commercengine/ssr-utils": "0.
|
|
47
|
+
"@commercengine/storefront-sdk": "0.14.1",
|
|
48
|
+
"@commercengine/ssr-utils": "0.2.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@types/node": "^24.10.4",
|