@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/index.cjs
CHANGED
|
@@ -1,411 +1,146 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var index_exports = {};
|
|
33
|
-
__export(index_exports, {
|
|
34
|
-
ClientTokenStorage: () => ClientTokenStorage,
|
|
35
|
-
ServerTokenStorage: () => ServerTokenStorage,
|
|
36
|
-
getStorefrontSDK: () => getStorefrontSDK,
|
|
37
|
-
storefront: () => storefront
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(index_exports);
|
|
40
|
-
|
|
41
|
-
// src/sdk-manager.ts
|
|
42
|
-
var import_react = require("react");
|
|
43
|
-
var import_storefront_sdk = require("@commercengine/storefront-sdk");
|
|
1
|
+
const require_sdk_manager = require('./sdk-manager-NWADjRFW.cjs');
|
|
2
|
+
const __commercengine_storefront_sdk = require_sdk_manager.__toESM(require("@commercengine/storefront-sdk"));
|
|
44
3
|
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
cookieString += `; Path=${this.options.path}`;
|
|
95
|
-
}
|
|
96
|
-
if (this.options.domain) {
|
|
97
|
-
cookieString += `; Domain=${this.options.domain}`;
|
|
98
|
-
}
|
|
99
|
-
if (this.options.secure) {
|
|
100
|
-
cookieString += `; Secure`;
|
|
101
|
-
}
|
|
102
|
-
if (this.options.sameSite) {
|
|
103
|
-
cookieString += `; SameSite=${this.options.sameSite}`;
|
|
104
|
-
}
|
|
105
|
-
document.cookie = cookieString;
|
|
106
|
-
}
|
|
107
|
-
deleteCookie(name) {
|
|
108
|
-
if (typeof document === "undefined") return;
|
|
109
|
-
let cookieString = `${name}=; Max-Age=0`;
|
|
110
|
-
if (this.options.path) {
|
|
111
|
-
cookieString += `; Path=${this.options.path}`;
|
|
112
|
-
}
|
|
113
|
-
if (this.options.domain) {
|
|
114
|
-
cookieString += `; Domain=${this.options.domain}`;
|
|
115
|
-
}
|
|
116
|
-
document.cookie = cookieString;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var ServerTokenStorage = class {
|
|
120
|
-
constructor(cookieStore, options = {}) {
|
|
121
|
-
const prefix = options.prefix || "ce_";
|
|
122
|
-
this.accessTokenKey = `${prefix}access_token`;
|
|
123
|
-
this.refreshTokenKey = `${prefix}refresh_token`;
|
|
124
|
-
this.cookieStore = cookieStore;
|
|
125
|
-
this.options = {
|
|
126
|
-
maxAge: options.maxAge || 30 * 24 * 60 * 60,
|
|
127
|
-
// 30 days default
|
|
128
|
-
path: options.path || "/",
|
|
129
|
-
domain: options.domain,
|
|
130
|
-
secure: options.secure ?? process.env.NODE_ENV === "production",
|
|
131
|
-
sameSite: options.sameSite || "Lax"
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
async getAccessToken() {
|
|
135
|
-
try {
|
|
136
|
-
return this.cookieStore.get(this.accessTokenKey)?.value || null;
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.warn(`Could not get access token from server cookies:`, error);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async setAccessToken(token) {
|
|
143
|
-
try {
|
|
144
|
-
this.cookieStore.set(this.accessTokenKey, token, {
|
|
145
|
-
maxAge: this.options.maxAge,
|
|
146
|
-
path: this.options.path,
|
|
147
|
-
domain: this.options.domain,
|
|
148
|
-
secure: this.options.secure,
|
|
149
|
-
sameSite: this.options.sameSite?.toLowerCase(),
|
|
150
|
-
httpOnly: false
|
|
151
|
-
// Allow client-side access for SDK flexibility
|
|
152
|
-
});
|
|
153
|
-
} catch (error) {
|
|
154
|
-
console.warn(`Could not set access token on server:`, error);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
async getRefreshToken() {
|
|
158
|
-
try {
|
|
159
|
-
return this.cookieStore.get(this.refreshTokenKey)?.value || null;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.warn(`Could not get refresh token from server cookies:`, error);
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async setRefreshToken(token) {
|
|
166
|
-
try {
|
|
167
|
-
this.cookieStore.set(this.refreshTokenKey, token, {
|
|
168
|
-
maxAge: this.options.maxAge,
|
|
169
|
-
path: this.options.path,
|
|
170
|
-
domain: this.options.domain,
|
|
171
|
-
secure: this.options.secure,
|
|
172
|
-
sameSite: this.options.sameSite?.toLowerCase(),
|
|
173
|
-
httpOnly: false
|
|
174
|
-
// Allow client-side access for SDK flexibility
|
|
175
|
-
});
|
|
176
|
-
} catch (error) {
|
|
177
|
-
console.warn(`Could not set refresh token on server:`, error);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
async clearTokens() {
|
|
181
|
-
try {
|
|
182
|
-
this.cookieStore.delete(this.accessTokenKey);
|
|
183
|
-
this.cookieStore.delete(this.refreshTokenKey);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.warn(`Could not clear tokens on server:`, error);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// src/build-token-cache.ts
|
|
191
|
-
var store = /* @__PURE__ */ new Map();
|
|
192
|
-
function isExpired(token) {
|
|
193
|
-
if (!token) return true;
|
|
194
|
-
if (!token.expiresAt) return false;
|
|
195
|
-
return Date.now() > token.expiresAt - 3e4;
|
|
196
|
-
}
|
|
197
|
-
function getCachedToken(key) {
|
|
198
|
-
const token = store.get(key);
|
|
199
|
-
return isExpired(token) ? null : token;
|
|
200
|
-
}
|
|
201
|
-
function setCachedToken(key, token) {
|
|
202
|
-
const expiresAt = token.ttlSeconds != null ? Date.now() + token.ttlSeconds * 1e3 : void 0;
|
|
203
|
-
store.set(key, {
|
|
204
|
-
accessToken: token.accessToken,
|
|
205
|
-
refreshToken: token.refreshToken ?? null,
|
|
206
|
-
expiresAt
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function clearCachedToken(key) {
|
|
210
|
-
store.delete(key);
|
|
4
|
+
//#region src/create-storefront.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a configured storefront function that works universally across all Next.js contexts
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // lib/storefront.ts
|
|
11
|
+
* import { createStorefront } from "@commercengine/storefront-sdk-nextjs";
|
|
12
|
+
*
|
|
13
|
+
* export const storefront = createStorefront({
|
|
14
|
+
* debug: true,
|
|
15
|
+
* logger: (msg, ...args) => console.log('[DEBUG]', msg, ...args)
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param config Optional configuration for advanced options (defaults to empty if not provided)
|
|
20
|
+
* @returns A storefront function that works in all Next.js contexts
|
|
21
|
+
*/
|
|
22
|
+
function createStorefront(config) {
|
|
23
|
+
if (config) require_sdk_manager.setGlobalStorefrontConfig(config);
|
|
24
|
+
function storefront(cookieStoreOrOptions, options) {
|
|
25
|
+
if (typeof window !== "undefined") return require_sdk_manager.getStorefrontSDK();
|
|
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 require_sdk_manager.getStorefrontSDK(cookieStore);
|
|
34
|
+
if (process.env.NEXT_IS_BUILD === "true" || process.env.NEXT_BUILD_CACHE_TOKENS === "true") return require_sdk_manager.getStorefrontSDK();
|
|
35
|
+
if (isRootLayout) return require_sdk_manager.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"));
|
|
51
|
+
}
|
|
52
|
+
return storefront;
|
|
211
53
|
}
|
|
212
54
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.ttlSeconds = ttlSeconds;
|
|
219
|
-
this.access = null;
|
|
220
|
-
this.refresh = null;
|
|
55
|
+
//#endregion
|
|
56
|
+
Object.defineProperty(exports, 'AuthClient', {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () {
|
|
59
|
+
return __commercengine_storefront_sdk.AuthClient;
|
|
221
60
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const cached = getCachedToken(this.cacheKey);
|
|
228
|
-
if (cached?.accessToken) {
|
|
229
|
-
console.log(`\u{1F7E2} [BuildCache] Using cached token for key: ${this.cacheKey}`);
|
|
230
|
-
this.access = cached.accessToken;
|
|
231
|
-
this.refresh = cached.refreshToken ?? null;
|
|
232
|
-
return this.access;
|
|
233
|
-
}
|
|
234
|
-
console.log(`\u{1F7E1} [BuildCache] No cached token found for key: ${this.cacheKey}`);
|
|
235
|
-
return null;
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(exports, 'BrowserTokenStorage', {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () {
|
|
65
|
+
return __commercengine_storefront_sdk.BrowserTokenStorage;
|
|
236
66
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
refreshToken: this.refresh,
|
|
243
|
-
ttlSeconds: this.ttlSeconds
|
|
244
|
-
});
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, 'CartClient', {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () {
|
|
71
|
+
return __commercengine_storefront_sdk.CartClient;
|
|
245
72
|
}
|
|
246
|
-
|
|
247
|
-
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, 'CatalogClient', {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function () {
|
|
77
|
+
return __commercengine_storefront_sdk.CatalogClient;
|
|
248
78
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
ttlSeconds: this.ttlSeconds
|
|
255
|
-
});
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, 'CookieTokenStorage', {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return __commercengine_storefront_sdk.CookieTokenStorage;
|
|
256
84
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, 'CustomerClient', {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () {
|
|
89
|
+
return __commercengine_storefront_sdk.CustomerClient;
|
|
261
90
|
}
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
function getConfig() {
|
|
274
|
-
if (globalConfig) {
|
|
275
|
-
return globalConfig;
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, 'Environment', {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () {
|
|
95
|
+
return __commercengine_storefront_sdk.Environment;
|
|
276
96
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
function
|
|
281
|
-
|
|
282
|
-
const { cookies } = require("next/headers");
|
|
283
|
-
cookies();
|
|
284
|
-
return true;
|
|
285
|
-
} catch {
|
|
286
|
-
return false;
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, 'HelpersClient', {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return __commercengine_storefront_sdk.HelpersClient;
|
|
287
102
|
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, 'MemoryTokenStorage', {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () {
|
|
107
|
+
return __commercengine_storefront_sdk.MemoryTokenStorage;
|
|
292
108
|
}
|
|
293
|
-
|
|
294
|
-
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, 'OrderClient', {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function () {
|
|
113
|
+
return __commercengine_storefront_sdk.OrderClient;
|
|
295
114
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, 'ResponseUtils', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return __commercengine_storefront_sdk.ResponseUtils;
|
|
301
120
|
}
|
|
302
|
-
console.log(`\u{1F504} [Build] Using standard MemoryTokenStorage (caching disabled)`);
|
|
303
|
-
return new import_storefront_sdk.MemoryTokenStorage();
|
|
304
|
-
}
|
|
305
|
-
var getServerSDKCached = (0, import_react.cache)((cookieStore) => {
|
|
306
|
-
const config = getEnvConfig();
|
|
307
|
-
return new import_storefront_sdk.StorefrontSDK({
|
|
308
|
-
...config,
|
|
309
|
-
tokenStorage: createTokenStorage(
|
|
310
|
-
cookieStore,
|
|
311
|
-
config.tokenStorageOptions,
|
|
312
|
-
config
|
|
313
|
-
)
|
|
314
|
-
});
|
|
315
121
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
buildTimeSDK = new import_storefront_sdk.StorefrontSDK({
|
|
321
|
-
...config,
|
|
322
|
-
tokenStorage: createTokenStorage(
|
|
323
|
-
void 0,
|
|
324
|
-
config.tokenStorageOptions,
|
|
325
|
-
config
|
|
326
|
-
)
|
|
327
|
-
});
|
|
122
|
+
Object.defineProperty(exports, 'ShippingClient', {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return __commercengine_storefront_sdk.ShippingClient;
|
|
328
126
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
console.warn(
|
|
335
|
-
"Cookie store passed in client environment - this will be ignored"
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
const config = getConfig();
|
|
339
|
-
if (!clientSDK) {
|
|
340
|
-
clientSDK = new import_storefront_sdk.StorefrontSDK({
|
|
341
|
-
...config,
|
|
342
|
-
tokenStorage: createTokenStorage(
|
|
343
|
-
void 0,
|
|
344
|
-
config.tokenStorageOptions,
|
|
345
|
-
config
|
|
346
|
-
)
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
return clientSDK;
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, 'StoreConfigClient', {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return __commercengine_storefront_sdk.StoreConfigClient;
|
|
350
132
|
}
|
|
351
|
-
|
|
352
|
-
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, 'StorefrontAPIClient', {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function () {
|
|
137
|
+
return __commercengine_storefront_sdk.StorefrontAPIClient;
|
|
353
138
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
-
);
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(exports, 'StorefrontSDK', {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function () {
|
|
143
|
+
return __commercengine_storefront_sdk.StorefrontSDK;
|
|
393
144
|
}
|
|
394
|
-
return getBuildTimeSDK();
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// src/storefront.ts
|
|
398
|
-
function storefront(cookieStore) {
|
|
399
|
-
return getStorefrontSDK(cookieStore);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// src/index.ts
|
|
403
|
-
__reExport(index_exports, require("@commercengine/storefront-sdk"), module.exports);
|
|
404
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
405
|
-
0 && (module.exports = {
|
|
406
|
-
ClientTokenStorage,
|
|
407
|
-
ServerTokenStorage,
|
|
408
|
-
getStorefrontSDK,
|
|
409
|
-
storefront,
|
|
410
|
-
...require("@commercengine/storefront-sdk")
|
|
411
145
|
});
|
|
146
|
+
exports.createStorefront = createStorefront;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,107 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export { default as storefront } from './storefront.cjs';
|
|
1
|
+
import { StorefrontRuntimeConfig } from "./sdk-manager-D2ktqPrp.cjs";
|
|
2
|
+
import { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, StorefrontSDK as StorefrontSDK$1 } from "@commercengine/storefront-sdk";
|
|
3
|
+
export * from "@commercengine/storefront-sdk";
|
|
5
4
|
|
|
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
|
-
}
|
|
5
|
+
//#region src/create-storefront.d.ts
|
|
84
6
|
type NextCookieStore = {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
7
|
+
get: (name: string) => {
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
} | undefined;
|
|
11
|
+
set: (name: string, value: string, opts?: Record<string, unknown>) => void;
|
|
12
|
+
delete: (name: string) => void;
|
|
90
13
|
};
|
|
91
14
|
/**
|
|
92
|
-
*
|
|
15
|
+
* Creates a configured storefront function that works universally across all Next.js contexts
|
|
93
16
|
*
|
|
94
17
|
* Usage:
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
*
|
|
103
|
-
*
|
|
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
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, type StorefrontRuntimeConfig, StorefrontSDK, createStorefront };
|
|
43
|
+
//# sourceMappingURL=index.d.cts.map
|