@commercengine/storefront-sdk-nextjs 0.1.0-alpha.0 → 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 +534 -139
- package/dist/client.cjs +136 -0
- package/dist/client.d.cts +17 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +17 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +44 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +128 -319
- package/dist/index.d.cts +34 -107
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +34 -107
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -303
- 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 +102 -0
- package/dist/server.d.cts +4 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +6 -0
- package/package.json +21 -11
package/dist/index.cjs
CHANGED
|
@@ -1,337 +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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
ClientTokenStorage: () => ClientTokenStorage,
|
|
34
|
-
Environment: () => import_storefront_sdk2.Environment,
|
|
35
|
-
ServerTokenStorage: () => ServerTokenStorage,
|
|
36
|
-
StorefrontSDKInitializer: () => StorefrontSDKInitializer,
|
|
37
|
-
getStorefrontSDK: () => getStorefrontSDK
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
const require_sdk_manager = require('./sdk-manager-NWADjRFW.cjs');
|
|
2
|
+
const __commercengine_storefront_sdk = require_sdk_manager.__toESM(require("@commercengine/storefront-sdk"));
|
|
40
3
|
|
|
41
|
-
|
|
42
|
-
|
|
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;
|
|
53
|
+
}
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.refreshTokenKey = `${prefix}refresh_token`;
|
|
50
|
-
this.options = {
|
|
51
|
-
maxAge: options.maxAge || 30 * 24 * 60 * 60,
|
|
52
|
-
// 30 days default
|
|
53
|
-
path: options.path || "/",
|
|
54
|
-
domain: options.domain,
|
|
55
|
-
secure: options.secure ?? (typeof window !== "undefined" && window.location?.protocol === "https:"),
|
|
56
|
-
sameSite: options.sameSite || "Lax"
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async getAccessToken() {
|
|
60
|
-
return this.getCookie(this.accessTokenKey);
|
|
61
|
-
}
|
|
62
|
-
async setAccessToken(token) {
|
|
63
|
-
this.setCookie(this.accessTokenKey, token);
|
|
64
|
-
}
|
|
65
|
-
async getRefreshToken() {
|
|
66
|
-
return this.getCookie(this.refreshTokenKey);
|
|
67
|
-
}
|
|
68
|
-
async setRefreshToken(token) {
|
|
69
|
-
this.setCookie(this.refreshTokenKey, token);
|
|
70
|
-
}
|
|
71
|
-
async clearTokens() {
|
|
72
|
-
this.deleteCookie(this.accessTokenKey);
|
|
73
|
-
this.deleteCookie(this.refreshTokenKey);
|
|
74
|
-
}
|
|
75
|
-
getCookie(name) {
|
|
76
|
-
if (typeof document === "undefined") return null;
|
|
77
|
-
const value = `; ${document.cookie}`;
|
|
78
|
-
const parts = value.split(`; ${name}=`);
|
|
79
|
-
if (parts.length === 2) {
|
|
80
|
-
const cookieValue = parts.pop()?.split(";").shift();
|
|
81
|
-
return cookieValue ? decodeURIComponent(cookieValue) : null;
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
setCookie(name, value) {
|
|
86
|
-
if (typeof document === "undefined") return;
|
|
87
|
-
const encodedValue = encodeURIComponent(value);
|
|
88
|
-
let cookieString = `${name}=${encodedValue}`;
|
|
89
|
-
if (this.options.maxAge) {
|
|
90
|
-
cookieString += `; Max-Age=${this.options.maxAge}`;
|
|
91
|
-
}
|
|
92
|
-
if (this.options.path) {
|
|
93
|
-
cookieString += `; Path=${this.options.path}`;
|
|
94
|
-
}
|
|
95
|
-
if (this.options.domain) {
|
|
96
|
-
cookieString += `; Domain=${this.options.domain}`;
|
|
97
|
-
}
|
|
98
|
-
if (this.options.secure) {
|
|
99
|
-
cookieString += `; Secure`;
|
|
100
|
-
}
|
|
101
|
-
if (this.options.sameSite) {
|
|
102
|
-
cookieString += `; SameSite=${this.options.sameSite}`;
|
|
103
|
-
}
|
|
104
|
-
document.cookie = cookieString;
|
|
55
|
+
//#endregion
|
|
56
|
+
Object.defineProperty(exports, 'AuthClient', {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () {
|
|
59
|
+
return __commercengine_storefront_sdk.AuthClient;
|
|
105
60
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
if (this.options.domain) {
|
|
113
|
-
cookieString += `; Domain=${this.options.domain}`;
|
|
114
|
-
}
|
|
115
|
-
document.cookie = cookieString;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var ServerTokenStorage = class {
|
|
119
|
-
constructor(cookieStore, options = {}) {
|
|
120
|
-
const prefix = options.prefix || "ce_";
|
|
121
|
-
this.accessTokenKey = `${prefix}access_token`;
|
|
122
|
-
this.refreshTokenKey = `${prefix}refresh_token`;
|
|
123
|
-
this.cookieStore = cookieStore;
|
|
124
|
-
this.options = {
|
|
125
|
-
maxAge: options.maxAge || 30 * 24 * 60 * 60,
|
|
126
|
-
// 30 days default
|
|
127
|
-
path: options.path || "/",
|
|
128
|
-
domain: options.domain,
|
|
129
|
-
secure: options.secure ?? process.env.NODE_ENV === "production",
|
|
130
|
-
sameSite: options.sameSite || "Lax"
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
async getAccessToken() {
|
|
134
|
-
try {
|
|
135
|
-
return this.cookieStore.get(this.accessTokenKey)?.value || null;
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.warn(`Could not get access token from server cookies:`, error);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async setAccessToken(token) {
|
|
142
|
-
try {
|
|
143
|
-
this.cookieStore.set(this.accessTokenKey, token, {
|
|
144
|
-
maxAge: this.options.maxAge,
|
|
145
|
-
path: this.options.path,
|
|
146
|
-
domain: this.options.domain,
|
|
147
|
-
secure: this.options.secure,
|
|
148
|
-
sameSite: this.options.sameSite?.toLowerCase(),
|
|
149
|
-
httpOnly: false
|
|
150
|
-
// Must be false for client-side access
|
|
151
|
-
});
|
|
152
|
-
} catch (error) {
|
|
153
|
-
console.warn(`Could not set access token on server:`, error);
|
|
154
|
-
}
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(exports, 'BrowserTokenStorage', {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () {
|
|
65
|
+
return __commercengine_storefront_sdk.BrowserTokenStorage;
|
|
155
66
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, 'CartClient', {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () {
|
|
71
|
+
return __commercengine_storefront_sdk.CartClient;
|
|
163
72
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
domain: this.options.domain,
|
|
170
|
-
secure: this.options.secure,
|
|
171
|
-
sameSite: this.options.sameSite?.toLowerCase(),
|
|
172
|
-
httpOnly: false
|
|
173
|
-
// Must be false for client-side access
|
|
174
|
-
});
|
|
175
|
-
} catch (error) {
|
|
176
|
-
console.warn(`Could not set refresh token on server:`, error);
|
|
177
|
-
}
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, 'CatalogClient', {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function () {
|
|
77
|
+
return __commercengine_storefront_sdk.CatalogClient;
|
|
178
78
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
console.warn(`Could not clear tokens on server:`, error);
|
|
185
|
-
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, 'CookieTokenStorage', {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return __commercengine_storefront_sdk.CookieTokenStorage;
|
|
186
84
|
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this.clientSDK = null;
|
|
193
|
-
this.config = null;
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, 'CustomerClient', {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () {
|
|
89
|
+
return __commercengine_storefront_sdk.CustomerClient;
|
|
194
90
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, 'Environment', {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () {
|
|
95
|
+
return __commercengine_storefront_sdk.Environment;
|
|
200
96
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (typeof window !== "undefined" && !this.clientSDK) {
|
|
207
|
-
this.clientSDK = this.createClientSDK();
|
|
208
|
-
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, 'HelpersClient', {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return __commercengine_storefront_sdk.HelpersClient;
|
|
209
102
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
throw new Error("SDK not initialized. Call initialize() first.");
|
|
216
|
-
}
|
|
217
|
-
if (!this.clientSDK) {
|
|
218
|
-
this.clientSDK = this.createClientSDK();
|
|
219
|
-
}
|
|
220
|
-
return this.clientSDK;
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, 'MemoryTokenStorage', {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () {
|
|
107
|
+
return __commercengine_storefront_sdk.MemoryTokenStorage;
|
|
221
108
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
throw new Error("SDK not initialized. Call initialize() first.");
|
|
228
|
-
}
|
|
229
|
-
return new import_storefront_sdk.StorefrontSDK({
|
|
230
|
-
...this.config,
|
|
231
|
-
tokenStorage: new ServerTokenStorage(
|
|
232
|
-
cookieStore,
|
|
233
|
-
this.config.tokenStorageOptions
|
|
234
|
-
)
|
|
235
|
-
});
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, 'OrderClient', {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function () {
|
|
113
|
+
return __commercengine_storefront_sdk.OrderClient;
|
|
236
114
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return
|
|
242
|
-
...this.config,
|
|
243
|
-
tokenStorage: new ClientTokenStorage(this.config.tokenStorageOptions)
|
|
244
|
-
});
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, 'ResponseUtils', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return __commercengine_storefront_sdk.ResponseUtils;
|
|
245
120
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, 'ShippingClient', {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () {
|
|
125
|
+
return __commercengine_storefront_sdk.ShippingClient;
|
|
251
126
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
this.config = null;
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, 'StoreConfigClient', {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return __commercengine_storefront_sdk.StoreConfigClient;
|
|
258
132
|
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
console.warn(
|
|
265
|
-
"Cookie store passed in client environment - this will be ignored"
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
return manager.getClientSDK();
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, 'StorefrontAPIClient', {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function () {
|
|
137
|
+
return __commercengine_storefront_sdk.StorefrontAPIClient;
|
|
269
138
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
\u{1F50D} Auto-detection attempted but failed. You may be in:
|
|
277
|
-
- Server Action (use: const sdk = getStorefrontSDK(await cookies()))
|
|
278
|
-
- API Route (use: const sdk = getStorefrontSDK(cookies()))
|
|
279
|
-
- Middleware (token access limited)
|
|
280
|
-
`;
|
|
281
|
-
} catch {
|
|
282
|
-
autoDetectMessage = `
|
|
283
|
-
|
|
284
|
-
\u{1F4A1} Make sure you have Next.js installed and are in a server context.
|
|
285
|
-
`;
|
|
286
|
-
}
|
|
287
|
-
throw new Error(
|
|
288
|
-
`
|
|
289
|
-
\u{1F6A8} Server Environment Detected!
|
|
290
|
-
|
|
291
|
-
You're calling getStorefrontSDK() on the server without cookies.
|
|
292
|
-
Please pass the Next.js cookie store:
|
|
293
|
-
|
|
294
|
-
\u2705 Correct usage:
|
|
295
|
-
import { cookies } from 'next/headers';
|
|
296
|
-
|
|
297
|
-
// Server Actions & Route Handlers
|
|
298
|
-
const sdk = getStorefrontSDK(await cookies());
|
|
299
|
-
|
|
300
|
-
// API Routes (Next.js 12)
|
|
301
|
-
const sdk = getStorefrontSDK(cookies());
|
|
302
|
-
|
|
303
|
-
\u274C Your current usage:
|
|
304
|
-
const sdk = getStorefrontSDK(); // Missing cookies!
|
|
305
|
-
${autoDetectMessage}
|
|
306
|
-
This is required for server-side token access.
|
|
307
|
-
`.trim()
|
|
308
|
-
);
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(exports, 'StorefrontSDK', {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function () {
|
|
143
|
+
return __commercengine_storefront_sdk.StorefrontSDK;
|
|
309
144
|
}
|
|
310
|
-
return manager.getServerSDK(cookieStore);
|
|
311
|
-
}
|
|
312
|
-
function initializeStorefrontSDK(config) {
|
|
313
|
-
const manager = NextJSSDKManager.getInstance();
|
|
314
|
-
manager.initialize(config);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// src/init-client.ts
|
|
318
|
-
var import_react = require("react");
|
|
319
|
-
function StorefrontSDKInitializer({
|
|
320
|
-
config
|
|
321
|
-
}) {
|
|
322
|
-
(0, import_react.useEffect)(() => {
|
|
323
|
-
initializeStorefrontSDK(config);
|
|
324
|
-
}, [config]);
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// src/index.ts
|
|
329
|
-
var import_storefront_sdk2 = require("@commercengine/storefront-sdk");
|
|
330
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
331
|
-
0 && (module.exports = {
|
|
332
|
-
ClientTokenStorage,
|
|
333
|
-
Environment,
|
|
334
|
-
ServerTokenStorage,
|
|
335
|
-
StorefrontSDKInitializer,
|
|
336
|
-
getStorefrontSDK
|
|
337
145
|
});
|
|
146
|
+
exports.createStorefront = createStorefront;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,116 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
* Configuration options for NextJSTokenStorage
|
|
6
|
-
*/
|
|
7
|
-
interface NextJSTokenStorageOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Prefix for cookie names (default: "ce_")
|
|
10
|
-
*/
|
|
11
|
-
prefix?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Maximum age of cookies in seconds (default: 30 days)
|
|
14
|
-
*/
|
|
15
|
-
maxAge?: number;
|
|
16
|
-
/**
|
|
17
|
-
* Cookie path (default: "/")
|
|
18
|
-
*/
|
|
19
|
-
path?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Cookie domain (default: current domain)
|
|
22
|
-
*/
|
|
23
|
-
domain?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Whether cookies should be secure (default: auto-detect based on environment)
|
|
26
|
-
*/
|
|
27
|
-
secure?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* SameSite cookie attribute (default: "Lax")
|
|
30
|
-
*/
|
|
31
|
-
sameSite?: "Strict" | "Lax" | "None";
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Client-side token storage that uses document.cookie
|
|
35
|
-
*/
|
|
36
|
-
declare class ClientTokenStorage implements TokenStorage {
|
|
37
|
-
private accessTokenKey;
|
|
38
|
-
private refreshTokenKey;
|
|
39
|
-
private options;
|
|
40
|
-
constructor(options?: NextJSTokenStorageOptions);
|
|
41
|
-
getAccessToken(): Promise<string | null>;
|
|
42
|
-
setAccessToken(token: string): Promise<void>;
|
|
43
|
-
getRefreshToken(): Promise<string | null>;
|
|
44
|
-
setRefreshToken(token: string): Promise<void>;
|
|
45
|
-
clearTokens(): Promise<void>;
|
|
46
|
-
private getCookie;
|
|
47
|
-
private setCookie;
|
|
48
|
-
private deleteCookie;
|
|
49
|
-
}
|
|
50
|
-
type NextCookieStore$1 = {
|
|
51
|
-
get: (name: string) => {
|
|
52
|
-
value: string;
|
|
53
|
-
} | undefined;
|
|
54
|
-
set: (name: string, value: string, options?: any) => void;
|
|
55
|
-
delete: (name: string) => void;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Server-side token storage that uses Next.js cookies API
|
|
59
|
-
*/
|
|
60
|
-
declare class ServerTokenStorage implements TokenStorage {
|
|
61
|
-
private accessTokenKey;
|
|
62
|
-
private refreshTokenKey;
|
|
63
|
-
private options;
|
|
64
|
-
private cookieStore;
|
|
65
|
-
constructor(cookieStore: NextCookieStore$1, options?: NextJSTokenStorageOptions);
|
|
66
|
-
getAccessToken(): Promise<string | null>;
|
|
67
|
-
setAccessToken(token: string): Promise<void>;
|
|
68
|
-
getRefreshToken(): Promise<string | null>;
|
|
69
|
-
setRefreshToken(token: string): Promise<void>;
|
|
70
|
-
clearTokens(): Promise<void>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Configuration for the NextJS SDK wrapper
|
|
75
|
-
*/
|
|
76
|
-
interface NextJSSDKConfig extends Omit<StorefrontSDKOptions, "tokenStorage"> {
|
|
77
|
-
/**
|
|
78
|
-
* Token storage configuration options
|
|
79
|
-
*/
|
|
80
|
-
tokenStorageOptions?: NextJSTokenStorageOptions;
|
|
81
|
-
}
|
|
5
|
+
//#region src/create-storefront.d.ts
|
|
82
6
|
type NextCookieStore = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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;
|
|
88
13
|
};
|
|
89
14
|
/**
|
|
90
|
-
*
|
|
15
|
+
* Creates a configured storefront function that works universally across all Next.js contexts
|
|
91
16
|
*
|
|
92
17
|
* Usage:
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
|
|
96
|
-
declare function getStorefrontSDK(): StorefrontSDK;
|
|
97
|
-
declare function getStorefrontSDK(cookieStore: NextCookieStore): StorefrontSDK;
|
|
98
|
-
|
|
99
|
-
interface StorefrontSDKInitializerProps {
|
|
100
|
-
config: NextJSSDKConfig;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Client-side initialization component
|
|
104
|
-
* Use this in your root layout to initialize the SDK once
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // lib/storefront.ts
|
|
20
|
+
* import { createStorefront } from "@commercengine/storefront-sdk-nextjs";
|
|
105
21
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
22
|
+
* export const storefront = createStorefront({
|
|
23
|
+
* debug: true,
|
|
24
|
+
* logger: (msg, ...args) => console.log('[DEBUG]', msg, ...args)
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
111
27
|
*
|
|
112
|
-
*
|
|
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
|
|
113
30
|
*/
|
|
114
|
-
declare function
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/create-storefront.ts"],"sourcesContent":[],"mappings":";;;;;KAQK,eAAA;;;;EAAA,CAAA,GAAA,SAAA;EAwBW,GAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAgB,KAAA,EAAA,MAAA,EAAA,IAAA,CAAA,EAtBY,MAsBZ,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,IAAA;EAAA,MAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAAA,IAAA;;;;;;;;;;;;;;;;;;;iBAAhB,gBAAA,UAA0B;MAKjB;gBACU,kBAAkB;;;MACG;gBACrB;;MAAuD"}
|