@commercengine/storefront-sdk-nextjs 0.1.0-alpha.1 → 0.1.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 +333 -440
- package/dist/client.cjs +113 -407
- package/dist/client.d.cts +14 -135
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +14 -135
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +40 -394
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +126 -391
- package/dist/index.d.cts +36 -100
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +36 -100
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -380
- package/dist/index.js.map +1 -0
- package/dist/sdk-manager-B9xDQQuv.d.ts +141 -0
- package/dist/sdk-manager-B9xDQQuv.d.ts.map +1 -0
- package/dist/sdk-manager-CdgrfSVp.js +343 -0
- package/dist/sdk-manager-CdgrfSVp.js.map +1 -0
- package/dist/sdk-manager-D2ktqPrp.d.cts +141 -0
- package/dist/sdk-manager-D2ktqPrp.d.cts.map +1 -0
- package/dist/sdk-manager-NWADjRFW.cjs +400 -0
- package/dist/server.cjs +84 -398
- package/dist/server.d.cts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +4 -383
- package/package.json +4 -4
- package/dist/middleware.cjs +0 -66
- package/dist/middleware.d.cts +0 -38
- package/dist/middleware.d.ts +0 -38
- package/dist/middleware.js +0 -39
- package/dist/server-D-pFrx8J.d.cts +0 -105
- package/dist/server-DaDfTjsO.d.cts +0 -103
- package/dist/server-DaDfTjsO.d.ts +0 -103
- package/dist/server-DjlQVC11.d.ts +0 -105
- package/dist/storefront.cjs +0 -402
- package/dist/storefront.d.cts +0 -40
- package/dist/storefront.d.ts +0 -40
- package/dist/storefront.js +0 -376
package/dist/client.cjs
CHANGED
|
@@ -1,430 +1,136 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
-
mod
|
|
29
|
-
));
|
|
30
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
-
|
|
32
|
-
// src/client.ts
|
|
33
|
-
var client_exports = {};
|
|
34
|
-
__export(client_exports, {
|
|
35
|
-
ClientTokenStorage: () => ClientTokenStorage,
|
|
36
|
-
StorefrontSDKInitializer: () => StorefrontSDKInitializer,
|
|
37
|
-
getStorefrontSDK: () => getStorefrontSDK,
|
|
38
|
-
initializeStorefrontSDK: () => initializeStorefrontSDK,
|
|
39
|
-
storefront: () => storefront
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(client_exports);
|
|
42
2
|
|
|
43
|
-
// src/sdk-manager.ts
|
|
44
|
-
var import_react = require("react");
|
|
45
|
-
var import_storefront_sdk = require("@commercengine/storefront-sdk");
|
|
46
3
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.deleteCookie(this.refreshTokenKey);
|
|
77
|
-
}
|
|
78
|
-
getCookie(name) {
|
|
79
|
-
if (typeof document === "undefined") return null;
|
|
80
|
-
const value = `; ${document.cookie}`;
|
|
81
|
-
const parts = value.split(`; ${name}=`);
|
|
82
|
-
if (parts.length === 2) {
|
|
83
|
-
const cookieValue = parts.pop()?.split(";").shift();
|
|
84
|
-
return cookieValue ? decodeURIComponent(cookieValue) : null;
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
setCookie(name, value) {
|
|
89
|
-
if (typeof document === "undefined") return;
|
|
90
|
-
const encodedValue = encodeURIComponent(value);
|
|
91
|
-
let cookieString = `${name}=${encodedValue}`;
|
|
92
|
-
if (this.options.maxAge) {
|
|
93
|
-
cookieString += `; Max-Age=${this.options.maxAge}`;
|
|
94
|
-
}
|
|
95
|
-
if (this.options.path) {
|
|
96
|
-
cookieString += `; Path=${this.options.path}`;
|
|
97
|
-
}
|
|
98
|
-
if (this.options.domain) {
|
|
99
|
-
cookieString += `; Domain=${this.options.domain}`;
|
|
100
|
-
}
|
|
101
|
-
if (this.options.secure) {
|
|
102
|
-
cookieString += `; Secure`;
|
|
103
|
-
}
|
|
104
|
-
if (this.options.sameSite) {
|
|
105
|
-
cookieString += `; SameSite=${this.options.sameSite}`;
|
|
106
|
-
}
|
|
107
|
-
document.cookie = cookieString;
|
|
108
|
-
}
|
|
109
|
-
deleteCookie(name) {
|
|
110
|
-
if (typeof document === "undefined") return;
|
|
111
|
-
let cookieString = `${name}=; Max-Age=0`;
|
|
112
|
-
if (this.options.path) {
|
|
113
|
-
cookieString += `; Path=${this.options.path}`;
|
|
114
|
-
}
|
|
115
|
-
if (this.options.domain) {
|
|
116
|
-
cookieString += `; Domain=${this.options.domain}`;
|
|
117
|
-
}
|
|
118
|
-
document.cookie = cookieString;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
var ServerTokenStorage = class {
|
|
122
|
-
constructor(cookieStore, options = {}) {
|
|
123
|
-
const prefix = options.prefix || "ce_";
|
|
124
|
-
this.accessTokenKey = `${prefix}access_token`;
|
|
125
|
-
this.refreshTokenKey = `${prefix}refresh_token`;
|
|
126
|
-
this.cookieStore = cookieStore;
|
|
127
|
-
this.options = {
|
|
128
|
-
maxAge: options.maxAge || 30 * 24 * 60 * 60,
|
|
129
|
-
// 30 days default
|
|
130
|
-
path: options.path || "/",
|
|
131
|
-
domain: options.domain,
|
|
132
|
-
secure: options.secure ?? process.env.NODE_ENV === "production",
|
|
133
|
-
sameSite: options.sameSite || "Lax"
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
async getAccessToken() {
|
|
137
|
-
try {
|
|
138
|
-
return this.cookieStore.get(this.accessTokenKey)?.value || null;
|
|
139
|
-
} catch (error) {
|
|
140
|
-
console.warn(`Could not get access token from server cookies:`, error);
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
async setAccessToken(token) {
|
|
145
|
-
try {
|
|
146
|
-
this.cookieStore.set(this.accessTokenKey, token, {
|
|
147
|
-
maxAge: this.options.maxAge,
|
|
148
|
-
path: this.options.path,
|
|
149
|
-
domain: this.options.domain,
|
|
150
|
-
secure: this.options.secure,
|
|
151
|
-
sameSite: this.options.sameSite?.toLowerCase(),
|
|
152
|
-
httpOnly: false
|
|
153
|
-
// Allow client-side access for SDK flexibility
|
|
154
|
-
});
|
|
155
|
-
} catch (error) {
|
|
156
|
-
console.warn(`Could not set access token on server:`, error);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async getRefreshToken() {
|
|
160
|
-
try {
|
|
161
|
-
return this.cookieStore.get(this.refreshTokenKey)?.value || null;
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.warn(`Could not get refresh token from server cookies:`, error);
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
async setRefreshToken(token) {
|
|
168
|
-
try {
|
|
169
|
-
this.cookieStore.set(this.refreshTokenKey, token, {
|
|
170
|
-
maxAge: this.options.maxAge,
|
|
171
|
-
path: this.options.path,
|
|
172
|
-
domain: this.options.domain,
|
|
173
|
-
secure: this.options.secure,
|
|
174
|
-
sameSite: this.options.sameSite?.toLowerCase(),
|
|
175
|
-
httpOnly: false
|
|
176
|
-
// Allow client-side access for SDK flexibility
|
|
177
|
-
});
|
|
178
|
-
} catch (error) {
|
|
179
|
-
console.warn(`Could not set refresh token on server:`, error);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
async clearTokens() {
|
|
183
|
-
try {
|
|
184
|
-
this.cookieStore.delete(this.accessTokenKey);
|
|
185
|
-
this.cookieStore.delete(this.refreshTokenKey);
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.warn(`Could not clear tokens on server:`, error);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// src/build-token-cache.ts
|
|
193
|
-
var store = /* @__PURE__ */ new Map();
|
|
194
|
-
function isExpired(token) {
|
|
195
|
-
if (!token) return true;
|
|
196
|
-
if (!token.expiresAt) return false;
|
|
197
|
-
return Date.now() > token.expiresAt - 3e4;
|
|
198
|
-
}
|
|
199
|
-
function getCachedToken(key) {
|
|
200
|
-
const token = store.get(key);
|
|
201
|
-
return isExpired(token) ? null : token;
|
|
202
|
-
}
|
|
203
|
-
function setCachedToken(key, token) {
|
|
204
|
-
const expiresAt = token.ttlSeconds != null ? Date.now() + token.ttlSeconds * 1e3 : void 0;
|
|
205
|
-
store.set(key, {
|
|
206
|
-
accessToken: token.accessToken,
|
|
207
|
-
refreshToken: token.refreshToken ?? null,
|
|
208
|
-
expiresAt
|
|
209
|
-
});
|
|
4
|
+
const require_sdk_manager = require('./sdk-manager-NWADjRFW.cjs');
|
|
5
|
+
const react = require_sdk_manager.__toESM(require("react"));
|
|
6
|
+
const __commercengine_storefront_sdk = require_sdk_manager.__toESM(require("@commercengine/storefront-sdk"));
|
|
7
|
+
|
|
8
|
+
//#region src/init-client.ts
|
|
9
|
+
/**
|
|
10
|
+
* Client-side initialization component
|
|
11
|
+
* Use this in your root layout to initialize the SDK once
|
|
12
|
+
*
|
|
13
|
+
* Configuration is handled via environment variables:
|
|
14
|
+
* - NEXT_PUBLIC_STORE_ID
|
|
15
|
+
* - NEXT_PUBLIC_API_KEY
|
|
16
|
+
* - NEXT_PUBLIC_ENVIRONMENT (optional, defaults to staging)
|
|
17
|
+
*
|
|
18
|
+
* The core SDK middleware automatically handles everything:
|
|
19
|
+
* - Creates anonymous tokens automatically on first API request (if no tokens exist)
|
|
20
|
+
* - Token state assessment and cleanup on first request per page load
|
|
21
|
+
* - Expired token refresh with automatic anonymous fallback
|
|
22
|
+
* - Graceful handling of partial token states
|
|
23
|
+
*
|
|
24
|
+
* No manual token creation needed - just make API calls and everything works!
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Bootstrap tokens by checking if access token exists and creating anonymous token if needed
|
|
28
|
+
*/
|
|
29
|
+
async function bootstrapTokens() {
|
|
30
|
+
const sdk = require_sdk_manager.getStorefrontSDK();
|
|
31
|
+
const accessToken = await sdk.getAccessToken();
|
|
32
|
+
if (!accessToken) await sdk.auth.getAnonymousToken();
|
|
210
33
|
}
|
|
211
|
-
function
|
|
212
|
-
|
|
34
|
+
function StorefrontSDKInitializer({ runtimeConfig } = {}) {
|
|
35
|
+
(0, react.useEffect)(() => {
|
|
36
|
+
require_sdk_manager.initializeStorefrontSDK();
|
|
37
|
+
bootstrapTokens().catch(console.error);
|
|
38
|
+
}, [runtimeConfig]);
|
|
39
|
+
return null;
|
|
213
40
|
}
|
|
214
41
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.ttlSeconds = ttlSeconds;
|
|
221
|
-
this.access = null;
|
|
222
|
-
this.refresh = null;
|
|
42
|
+
//#endregion
|
|
43
|
+
Object.defineProperty(exports, 'AuthClient', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return __commercengine_storefront_sdk.AuthClient;
|
|
223
47
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const cached = getCachedToken(this.cacheKey);
|
|
230
|
-
if (cached?.accessToken) {
|
|
231
|
-
console.log(`\u{1F7E2} [BuildCache] Using cached token for key: ${this.cacheKey}`);
|
|
232
|
-
this.access = cached.accessToken;
|
|
233
|
-
this.refresh = cached.refreshToken ?? null;
|
|
234
|
-
return this.access;
|
|
235
|
-
}
|
|
236
|
-
console.log(`\u{1F7E1} [BuildCache] No cached token found for key: ${this.cacheKey}`);
|
|
237
|
-
return null;
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, 'BrowserTokenStorage', {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return __commercengine_storefront_sdk.BrowserTokenStorage;
|
|
238
53
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
refreshToken: this.refresh,
|
|
245
|
-
ttlSeconds: this.ttlSeconds
|
|
246
|
-
});
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, 'CartClient', {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return __commercengine_storefront_sdk.CartClient;
|
|
247
59
|
}
|
|
248
|
-
|
|
249
|
-
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, 'CatalogClient', {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return __commercengine_storefront_sdk.CatalogClient;
|
|
250
65
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
});
|
|
66
|
+
});
|
|
67
|
+
exports.ClientTokenStorage = require_sdk_manager.ClientTokenStorage;
|
|
68
|
+
Object.defineProperty(exports, 'CookieTokenStorage', {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () {
|
|
71
|
+
return __commercengine_storefront_sdk.CookieTokenStorage;
|
|
258
72
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, 'CustomerClient', {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function () {
|
|
77
|
+
return __commercengine_storefront_sdk.CustomerClient;
|
|
263
78
|
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
return {
|
|
270
|
-
storeId: process.env.NEXT_PUBLIC_STORE_ID || "",
|
|
271
|
-
environment: process.env.NEXT_PUBLIC_ENVIRONMENT === "production" ? import_storefront_sdk.Environment.Production : import_storefront_sdk.Environment.Staging,
|
|
272
|
-
apiKey: process.env.NEXT_PUBLIC_API_KEY
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
function getConfig() {
|
|
276
|
-
if (globalConfig) {
|
|
277
|
-
return globalConfig;
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, 'Environment', {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return __commercengine_storefront_sdk.Environment;
|
|
278
84
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
function
|
|
283
|
-
|
|
284
|
-
const { cookies } = require("next/headers");
|
|
285
|
-
cookies();
|
|
286
|
-
return true;
|
|
287
|
-
} catch {
|
|
288
|
-
return false;
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, 'HelpersClient', {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () {
|
|
89
|
+
return __commercengine_storefront_sdk.HelpersClient;
|
|
289
90
|
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, 'MemoryTokenStorage', {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () {
|
|
95
|
+
return __commercengine_storefront_sdk.MemoryTokenStorage;
|
|
294
96
|
}
|
|
295
|
-
|
|
296
|
-
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, 'OrderClient', {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return __commercengine_storefront_sdk.OrderClient;
|
|
297
102
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
return
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, 'ResponseUtils', {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () {
|
|
107
|
+
return __commercengine_storefront_sdk.ResponseUtils;
|
|
303
108
|
}
|
|
304
|
-
console.log(`\u{1F504} [Build] Using standard MemoryTokenStorage (caching disabled)`);
|
|
305
|
-
return new import_storefront_sdk.MemoryTokenStorage();
|
|
306
|
-
}
|
|
307
|
-
var getServerSDKCached = (0, import_react.cache)((cookieStore) => {
|
|
308
|
-
const config = getEnvConfig();
|
|
309
|
-
return new import_storefront_sdk.StorefrontSDK({
|
|
310
|
-
...config,
|
|
311
|
-
tokenStorage: createTokenStorage(
|
|
312
|
-
cookieStore,
|
|
313
|
-
config.tokenStorageOptions,
|
|
314
|
-
config
|
|
315
|
-
)
|
|
316
|
-
});
|
|
317
109
|
});
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
buildTimeSDK = new import_storefront_sdk.StorefrontSDK({
|
|
323
|
-
...config,
|
|
324
|
-
tokenStorage: createTokenStorage(
|
|
325
|
-
void 0,
|
|
326
|
-
config.tokenStorageOptions,
|
|
327
|
-
config
|
|
328
|
-
)
|
|
329
|
-
});
|
|
110
|
+
Object.defineProperty(exports, 'ShippingClient', {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function () {
|
|
113
|
+
return __commercengine_storefront_sdk.ShippingClient;
|
|
330
114
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
console.warn(
|
|
337
|
-
"Cookie store passed in client environment - this will be ignored"
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
const config = getConfig();
|
|
341
|
-
if (!clientSDK) {
|
|
342
|
-
clientSDK = new import_storefront_sdk.StorefrontSDK({
|
|
343
|
-
...config,
|
|
344
|
-
tokenStorage: createTokenStorage(
|
|
345
|
-
void 0,
|
|
346
|
-
config.tokenStorageOptions,
|
|
347
|
-
config
|
|
348
|
-
)
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
return clientSDK;
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, 'StoreConfigClient', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return __commercengine_storefront_sdk.StoreConfigClient;
|
|
352
120
|
}
|
|
353
|
-
|
|
354
|
-
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, 'StorefrontAPIClient', {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return __commercengine_storefront_sdk.StorefrontAPIClient;
|
|
355
126
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
\u{1F50D} Auto-detection attempted but failed. You may be in:
|
|
363
|
-
- Server Action (use: const sdk = getStorefrontSDK(await cookies()))
|
|
364
|
-
- API Route (use: const sdk = getStorefrontSDK(cookies()))
|
|
365
|
-
- Server Component in App Router (use: const sdk = getStorefrontSDK(cookies()))
|
|
366
|
-
`;
|
|
367
|
-
} catch {
|
|
368
|
-
autoDetectMessage = `
|
|
369
|
-
|
|
370
|
-
\u{1F4A1} Make sure you have Next.js installed and are in a server context.
|
|
371
|
-
`;
|
|
372
|
-
}
|
|
373
|
-
throw new Error(
|
|
374
|
-
`
|
|
375
|
-
\u{1F6A8} Server Environment Detected!
|
|
376
|
-
|
|
377
|
-
You're calling getStorefrontSDK() on the server without cookies.
|
|
378
|
-
Please pass the Next.js cookie store:
|
|
379
|
-
|
|
380
|
-
\u2705 Correct usage:
|
|
381
|
-
import { cookies } from 'next/headers';
|
|
382
|
-
|
|
383
|
-
// Server Actions & Route Handlers
|
|
384
|
-
const sdk = getStorefrontSDK(await cookies());
|
|
385
|
-
|
|
386
|
-
// API Routes & Server Components (App Router)
|
|
387
|
-
const sdk = getStorefrontSDK(cookies());
|
|
388
|
-
|
|
389
|
-
\u274C Your current usage:
|
|
390
|
-
const sdk = getStorefrontSDK(); // Missing cookies!
|
|
391
|
-
${autoDetectMessage}
|
|
392
|
-
This is required for server-side token access.
|
|
393
|
-
`.trim()
|
|
394
|
-
);
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, 'StorefrontSDK', {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return __commercengine_storefront_sdk.StorefrontSDK;
|
|
395
132
|
}
|
|
396
|
-
return getBuildTimeSDK();
|
|
397
|
-
}
|
|
398
|
-
function initializeStorefrontSDK(config) {
|
|
399
|
-
globalConfig = config;
|
|
400
|
-
clientSDK = null;
|
|
401
|
-
buildTimeSDK = null;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// src/storefront.ts
|
|
405
|
-
function storefront(cookieStore) {
|
|
406
|
-
return getStorefrontSDK(cookieStore);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// src/init-client.ts
|
|
410
|
-
var import_react2 = require("react");
|
|
411
|
-
function StorefrontSDKInitializer({
|
|
412
|
-
config
|
|
413
|
-
}) {
|
|
414
|
-
(0, import_react2.useEffect)(() => {
|
|
415
|
-
initializeStorefrontSDK(config);
|
|
416
|
-
}, [config]);
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// src/client.ts
|
|
421
|
-
__reExport(client_exports, require("@commercengine/storefront-sdk"), module.exports);
|
|
422
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
423
|
-
0 && (module.exports = {
|
|
424
|
-
ClientTokenStorage,
|
|
425
|
-
StorefrontSDKInitializer,
|
|
426
|
-
getStorefrontSDK,
|
|
427
|
-
initializeStorefrontSDK,
|
|
428
|
-
storefront,
|
|
429
|
-
...require("@commercengine/storefront-sdk")
|
|
430
133
|
});
|
|
134
|
+
exports.StorefrontSDKInitializer = StorefrontSDKInitializer;
|
|
135
|
+
exports.getStorefrontSDK = require_sdk_manager.getStorefrontSDK;
|
|
136
|
+
exports.initializeStorefrontSDK = require_sdk_manager.initializeStorefrontSDK;
|