@01.software/sdk 0.12.1 → 0.14.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 +102 -57
- package/dist/analytics.cjs +207 -0
- package/dist/analytics.cjs.map +1 -0
- package/dist/analytics.d.cts +20 -0
- package/dist/analytics.d.ts +20 -0
- package/dist/analytics.js +184 -0
- package/dist/analytics.js.map +1 -0
- package/dist/{const-CRjjFJ3o.d.ts → const-CigSm8e_.d.ts} +1 -1
- package/dist/{const-CZOY2tsf.d.cts → const-CxpAy8X_.d.cts} +1 -1
- package/dist/index.cjs +946 -485
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +640 -439
- package/dist/index.d.ts +640 -439
- package/dist/index.js +946 -485
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-D4IWd3ZB.d.cts → payload-types-DH1fKdM3.d.cts} +94 -1
- package/dist/{payload-types-D4IWd3ZB.d.ts → payload-types-DH1fKdM3.d.ts} +94 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js.map +1 -1
- package/dist/{server-JR9TvKZ5.d.cts → server-DLdbWJVv.d.cts} +5 -3
- package/dist/{server-JR9TvKZ5.d.ts → server-DLdbWJVv.d.ts} +5 -3
- package/dist/ui/canvas/server.cjs +4 -4
- package/dist/ui/canvas/server.cjs.map +1 -1
- package/dist/ui/canvas/server.d.cts +1 -1
- package/dist/ui/canvas/server.d.ts +1 -1
- package/dist/ui/canvas/server.js +4 -4
- package/dist/ui/canvas/server.js.map +1 -1
- package/dist/ui/canvas.cjs +4 -4
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.d.cts +2 -2
- package/dist/ui/canvas.d.ts +2 -2
- package/dist/ui/canvas.js +4 -4
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/{webhook-D_7bYIKj.d.ts → webhook-CmJWfLjs.d.ts} +2 -2
- package/dist/{webhook-C1q3iC6W.d.cts → webhook-IX2MGQj2.d.cts} +2 -2
- package/dist/webhook.d.cts +3 -3
- package/dist/webhook.d.ts +3 -3
- package/package.json +11 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
ApiError: () => ApiError,
|
|
24
|
+
AuthError: () => AuthError,
|
|
24
25
|
BaseApi: () => BaseApi,
|
|
25
26
|
COLLECTIONS: () => COLLECTIONS,
|
|
26
27
|
CartApi: () => CartApi,
|
|
@@ -28,20 +29,30 @@ __export(src_exports, {
|
|
|
28
29
|
CollectionClient: () => CollectionClient,
|
|
29
30
|
CollectionHooks: () => CollectionHooks,
|
|
30
31
|
CollectionQueryBuilder: () => CollectionQueryBuilder,
|
|
32
|
+
CommerceClient: () => CommerceClient,
|
|
31
33
|
CommunityClient: () => CommunityClient,
|
|
32
34
|
ConfigError: () => ConfigError,
|
|
35
|
+
ConflictError: () => ConflictError,
|
|
33
36
|
CustomerAuth: () => CustomerAuth,
|
|
34
37
|
CustomerHooks: () => CustomerHooks,
|
|
38
|
+
CustomerNamespace: () => CustomerNamespace,
|
|
39
|
+
DiscountApi: () => DiscountApi,
|
|
35
40
|
GoneError: () => GoneError,
|
|
36
41
|
IMAGE_SIZES: () => IMAGE_SIZES,
|
|
42
|
+
ModerationApi: () => ModerationApi,
|
|
37
43
|
NetworkError: () => NetworkError,
|
|
44
|
+
NotFoundError: () => NotFoundError,
|
|
38
45
|
OrderApi: () => OrderApi,
|
|
46
|
+
PermissionError: () => PermissionError,
|
|
39
47
|
ProductApi: () => ProductApi,
|
|
40
48
|
QueryHooks: () => QueryHooks,
|
|
49
|
+
RateLimitError: () => RateLimitError,
|
|
41
50
|
RealtimeConnection: () => RealtimeConnection,
|
|
42
51
|
SDKError: () => SDKError,
|
|
43
52
|
ServerClient: () => ServerClient,
|
|
53
|
+
ServerCommerceClient: () => ServerCommerceClient,
|
|
44
54
|
ServiceUnavailableError: () => ServiceUnavailableError,
|
|
55
|
+
ShippingApi: () => ShippingApi,
|
|
45
56
|
TimeoutError: () => TimeoutError,
|
|
46
57
|
UsageLimitError: () => UsageLimitError,
|
|
47
58
|
ValidationError: () => ValidationError,
|
|
@@ -49,7 +60,13 @@ __export(src_exports, {
|
|
|
49
60
|
buildProductListingProjection: () => buildProductListingProjection,
|
|
50
61
|
buildProductOptionMatrix: () => buildProductOptionMatrix,
|
|
51
62
|
collectionKeys: () => collectionKeys,
|
|
63
|
+
createAnalytics: () => createAnalytics,
|
|
64
|
+
createAuthError: () => createAuthError,
|
|
52
65
|
createClient: () => createClient,
|
|
66
|
+
createConflictError: () => createConflictError,
|
|
67
|
+
createNotFoundError: () => createNotFoundError,
|
|
68
|
+
createPermissionError: () => createPermissionError,
|
|
69
|
+
createRateLimitError: () => createRateLimitError,
|
|
53
70
|
createServerClient: () => createServerClient,
|
|
54
71
|
createTypedWebhookHandler: () => createTypedWebhookHandler,
|
|
55
72
|
customerKeys: () => customerKeys,
|
|
@@ -70,9 +87,14 @@ __export(src_exports, {
|
|
|
70
87
|
getVideoThumbnail: () => getVideoThumbnail,
|
|
71
88
|
handleWebhook: () => handleWebhook,
|
|
72
89
|
isApiError: () => isApiError,
|
|
90
|
+
isAuthError: () => isAuthError,
|
|
73
91
|
isConfigError: () => isConfigError,
|
|
92
|
+
isConflictError: () => isConflictError,
|
|
74
93
|
isGoneError: () => isGoneError,
|
|
75
94
|
isNetworkError: () => isNetworkError,
|
|
95
|
+
isNotFoundError: () => isNotFoundError,
|
|
96
|
+
isPermissionError: () => isPermissionError,
|
|
97
|
+
isRateLimitError: () => isRateLimitError,
|
|
76
98
|
isSDKError: () => isSDKError,
|
|
77
99
|
isServiceUnavailableError: () => isServiceUnavailableError,
|
|
78
100
|
isTimeoutError: () => isTimeoutError,
|
|
@@ -86,9 +108,209 @@ __export(src_exports, {
|
|
|
86
108
|
});
|
|
87
109
|
module.exports = __toCommonJS(src_exports);
|
|
88
110
|
|
|
111
|
+
// src/utils/types.ts
|
|
112
|
+
var resolveRelation = (ref) => {
|
|
113
|
+
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
114
|
+
return null;
|
|
115
|
+
return ref;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/core/metadata/index.ts
|
|
119
|
+
function extractSeo(doc) {
|
|
120
|
+
const seo = doc.seo ?? {};
|
|
121
|
+
const og = seo.openGraph ?? {};
|
|
122
|
+
return {
|
|
123
|
+
title: seo.title ?? doc.title ?? null,
|
|
124
|
+
description: seo.description ?? null,
|
|
125
|
+
noIndex: seo.noIndex ?? null,
|
|
126
|
+
canonical: seo.canonical ?? null,
|
|
127
|
+
openGraph: {
|
|
128
|
+
title: og.title ?? null,
|
|
129
|
+
description: og.description ?? null,
|
|
130
|
+
image: og.image ?? null
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function generateMetadata(input, options) {
|
|
135
|
+
const title = input.title ?? void 0;
|
|
136
|
+
const description = input.description ?? void 0;
|
|
137
|
+
const ogTitle = input.openGraph?.title ?? title;
|
|
138
|
+
const ogDescription = input.openGraph?.description ?? description;
|
|
139
|
+
const image = resolveMetaImage(input.openGraph?.image);
|
|
140
|
+
return {
|
|
141
|
+
title,
|
|
142
|
+
description,
|
|
143
|
+
...input.noIndex && { robots: { index: false, follow: false } },
|
|
144
|
+
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
145
|
+
openGraph: {
|
|
146
|
+
...ogTitle && { title: ogTitle },
|
|
147
|
+
...ogDescription && { description: ogDescription },
|
|
148
|
+
...options?.siteName && { siteName: options.siteName },
|
|
149
|
+
...image && { images: [image] }
|
|
150
|
+
},
|
|
151
|
+
twitter: {
|
|
152
|
+
card: image ? "summary_large_image" : "summary",
|
|
153
|
+
...ogTitle && { title: ogTitle },
|
|
154
|
+
...ogDescription && { description: ogDescription },
|
|
155
|
+
...image && { images: [image.url] }
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function resolveMetaImage(ref) {
|
|
160
|
+
const image = resolveRelation(ref);
|
|
161
|
+
if (!image) return null;
|
|
162
|
+
const sized = image.sizes?.["1536"];
|
|
163
|
+
const url = sized?.url || image.url;
|
|
164
|
+
if (!url) return null;
|
|
165
|
+
const width = sized?.url ? sized.width : image.width;
|
|
166
|
+
const height = sized?.url ? sized.height : image.height;
|
|
167
|
+
return {
|
|
168
|
+
url,
|
|
169
|
+
...width && { width },
|
|
170
|
+
...height && { height },
|
|
171
|
+
...image.alt && { alt: image.alt }
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/core/collection/query-builder.ts
|
|
176
|
+
var CollectionQueryBuilder = class {
|
|
177
|
+
constructor(api, collection) {
|
|
178
|
+
this.api = api;
|
|
179
|
+
this.collection = collection;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Find documents (list query)
|
|
183
|
+
* GET /api/{collection}
|
|
184
|
+
* @returns Payload CMS find response with docs array and pagination
|
|
185
|
+
*/
|
|
186
|
+
async find(options) {
|
|
187
|
+
return this.api.requestFind(
|
|
188
|
+
`/api/${String(this.collection)}`,
|
|
189
|
+
options
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Find document by ID
|
|
194
|
+
* GET /api/{collection}/{id}
|
|
195
|
+
* @returns Document object directly (no wrapper)
|
|
196
|
+
*/
|
|
197
|
+
async findById(id, options) {
|
|
198
|
+
return this.api.requestFindById(
|
|
199
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
200
|
+
options
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create a new document
|
|
205
|
+
* POST /api/{collection}
|
|
206
|
+
* @returns Payload CMS mutation response with doc and message
|
|
207
|
+
*/
|
|
208
|
+
async create(data, options) {
|
|
209
|
+
const endpoint = `/api/${String(this.collection)}`;
|
|
210
|
+
if (options?.file) {
|
|
211
|
+
return this.api.requestCreateWithFile(
|
|
212
|
+
endpoint,
|
|
213
|
+
data,
|
|
214
|
+
options.file,
|
|
215
|
+
options.filename
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
return this.api.requestCreate(endpoint, data);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Update a document by ID
|
|
222
|
+
* PATCH /api/{collection}/{id}
|
|
223
|
+
* @returns Payload CMS mutation response with doc and message
|
|
224
|
+
*/
|
|
225
|
+
async update(id, data, options) {
|
|
226
|
+
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
227
|
+
if (options?.file) {
|
|
228
|
+
return this.api.requestUpdateWithFile(
|
|
229
|
+
endpoint,
|
|
230
|
+
data,
|
|
231
|
+
options.file,
|
|
232
|
+
options.filename
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
return this.api.requestUpdate(endpoint, data);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Count documents
|
|
239
|
+
* GET /api/{collection}/count
|
|
240
|
+
* @returns Count response with totalDocs
|
|
241
|
+
*/
|
|
242
|
+
async count(options) {
|
|
243
|
+
return this.api.requestCount(
|
|
244
|
+
`/api/${String(this.collection)}/count`,
|
|
245
|
+
options
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Find first matching document and return its Next.js Metadata.
|
|
250
|
+
* Applies depth: 1 (SEO image populate) and limit: 1 automatically.
|
|
251
|
+
* @returns Metadata or null if no document matches
|
|
252
|
+
*/
|
|
253
|
+
async findMetadata(options, metadataOptions) {
|
|
254
|
+
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
255
|
+
const doc = docs[0];
|
|
256
|
+
if (!doc) return null;
|
|
257
|
+
return generateMetadata(
|
|
258
|
+
extractSeo(doc),
|
|
259
|
+
metadataOptions
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Find document by ID and return its Next.js Metadata.
|
|
264
|
+
* Applies depth: 1 (SEO image populate) automatically.
|
|
265
|
+
* @returns Metadata (throws on 404)
|
|
266
|
+
*/
|
|
267
|
+
async findMetadataById(id, metadataOptions) {
|
|
268
|
+
const doc = await this.findById(id, { depth: 1 });
|
|
269
|
+
return generateMetadata(
|
|
270
|
+
extractSeo(doc),
|
|
271
|
+
metadataOptions
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Update multiple documents (bulk update)
|
|
276
|
+
* PATCH /api/{collection}
|
|
277
|
+
* @returns Payload CMS find response with updated docs
|
|
278
|
+
*/
|
|
279
|
+
async updateMany(where, data) {
|
|
280
|
+
return this.api.requestUpdateMany(
|
|
281
|
+
`/api/${String(this.collection)}`,
|
|
282
|
+
{ where, data }
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Delete a document by ID
|
|
287
|
+
* DELETE /api/{collection}/{id}
|
|
288
|
+
* @returns Deleted document object directly (no wrapper)
|
|
289
|
+
*/
|
|
290
|
+
async remove(id) {
|
|
291
|
+
return this.api.requestDelete(
|
|
292
|
+
`/api/${String(this.collection)}/${String(id)}`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Delete multiple documents (bulk delete)
|
|
297
|
+
* DELETE /api/{collection}
|
|
298
|
+
* @returns Payload CMS find response with deleted docs
|
|
299
|
+
*/
|
|
300
|
+
async removeMany(where) {
|
|
301
|
+
return this.api.requestDeleteMany(
|
|
302
|
+
`/api/${String(this.collection)}`,
|
|
303
|
+
{ where }
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// src/core/collection/http-client.ts
|
|
309
|
+
var import_qs_esm = require("qs-esm");
|
|
310
|
+
|
|
89
311
|
// src/core/internal/errors/index.ts
|
|
90
312
|
var SDKError = class extends Error {
|
|
91
|
-
constructor(code, message, status, details, userMessage, suggestion) {
|
|
313
|
+
constructor(code, message, status, details, userMessage, suggestion, requestId) {
|
|
92
314
|
super(message);
|
|
93
315
|
this.name = "SDKError";
|
|
94
316
|
this.code = code;
|
|
@@ -96,6 +318,7 @@ var SDKError = class extends Error {
|
|
|
96
318
|
this.details = details;
|
|
97
319
|
this.userMessage = userMessage;
|
|
98
320
|
this.suggestion = suggestion;
|
|
321
|
+
this.requestId = requestId;
|
|
99
322
|
if (Error.captureStackTrace) {
|
|
100
323
|
Error.captureStackTrace(this, new.target);
|
|
101
324
|
}
|
|
@@ -111,7 +334,8 @@ var SDKError = class extends Error {
|
|
|
111
334
|
status: this.status,
|
|
112
335
|
details: this.details,
|
|
113
336
|
userMessage: this.userMessage,
|
|
114
|
-
suggestion: this.suggestion
|
|
337
|
+
suggestion: this.suggestion,
|
|
338
|
+
...this.requestId !== void 0 && { requestId: this.requestId }
|
|
115
339
|
};
|
|
116
340
|
}
|
|
117
341
|
};
|
|
@@ -178,6 +402,37 @@ var UsageLimitError = class extends SDKError {
|
|
|
178
402
|
};
|
|
179
403
|
}
|
|
180
404
|
};
|
|
405
|
+
var AuthError = class extends SDKError {
|
|
406
|
+
constructor(message, details, userMessage, suggestion, requestId) {
|
|
407
|
+
super("auth_error", message, 401, details, userMessage, suggestion, requestId);
|
|
408
|
+
this.name = "AuthError";
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var PermissionError = class extends SDKError {
|
|
412
|
+
constructor(message, details, userMessage, suggestion, requestId) {
|
|
413
|
+
super("permission_error", message, 403, details, userMessage, suggestion, requestId);
|
|
414
|
+
this.name = "PermissionError";
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
var NotFoundError = class extends SDKError {
|
|
418
|
+
constructor(message, details, userMessage, suggestion, requestId) {
|
|
419
|
+
super("not_found", message, 404, details, userMessage, suggestion, requestId);
|
|
420
|
+
this.name = "NotFoundError";
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var ConflictError = class extends SDKError {
|
|
424
|
+
constructor(message, details, userMessage, suggestion, requestId) {
|
|
425
|
+
super("conflict", message, 409, details, userMessage, suggestion, requestId);
|
|
426
|
+
this.name = "ConflictError";
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
var RateLimitError = class extends SDKError {
|
|
430
|
+
constructor(message, retryAfter, details, userMessage, suggestion, requestId) {
|
|
431
|
+
super("rate_limit_exceeded", message, 429, details, userMessage, suggestion, requestId);
|
|
432
|
+
this.name = "RateLimitError";
|
|
433
|
+
this.retryAfter = retryAfter;
|
|
434
|
+
}
|
|
435
|
+
};
|
|
181
436
|
function isSDKError(error) {
|
|
182
437
|
return error instanceof SDKError;
|
|
183
438
|
}
|
|
@@ -205,11 +460,32 @@ function isServiceUnavailableError(error) {
|
|
|
205
460
|
function isUsageLimitError(error) {
|
|
206
461
|
return error instanceof UsageLimitError;
|
|
207
462
|
}
|
|
463
|
+
function isAuthError(error) {
|
|
464
|
+
return error instanceof AuthError;
|
|
465
|
+
}
|
|
466
|
+
function isPermissionError(error) {
|
|
467
|
+
return error instanceof PermissionError;
|
|
468
|
+
}
|
|
469
|
+
function isNotFoundError(error) {
|
|
470
|
+
return error instanceof NotFoundError;
|
|
471
|
+
}
|
|
472
|
+
function isConflictError(error) {
|
|
473
|
+
return error instanceof ConflictError;
|
|
474
|
+
}
|
|
475
|
+
function isRateLimitError(error) {
|
|
476
|
+
return error instanceof RateLimitError;
|
|
477
|
+
}
|
|
208
478
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
479
|
+
var createValidationError = (message, details, userMessage, suggestion) => new ValidationError(message, details, userMessage, suggestion);
|
|
209
480
|
var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
|
|
210
481
|
var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
|
|
211
482
|
var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
|
|
212
483
|
var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
|
|
484
|
+
var createAuthError = (message, details, userMessage, suggestion, requestId) => new AuthError(message, details, userMessage, suggestion, requestId);
|
|
485
|
+
var createPermissionError = (message, details, userMessage, suggestion, requestId) => new PermissionError(message, details, userMessage, suggestion, requestId);
|
|
486
|
+
var createNotFoundError = (message, details, userMessage, suggestion, requestId) => new NotFoundError(message, details, userMessage, suggestion, requestId);
|
|
487
|
+
var createConflictError = (message, details, userMessage, suggestion, requestId) => new ConflictError(message, details, userMessage, suggestion, requestId);
|
|
488
|
+
var createRateLimitError = (message, retryAfter, details, userMessage, suggestion, requestId) => new RateLimitError(message, retryAfter, details, userMessage, suggestion, requestId);
|
|
213
489
|
|
|
214
490
|
// src/core/client/types.ts
|
|
215
491
|
function resolveApiUrl() {
|
|
@@ -252,6 +528,7 @@ async function parseErrorBody(response) {
|
|
|
252
528
|
};
|
|
253
529
|
try {
|
|
254
530
|
const body = await response.json();
|
|
531
|
+
const reason = typeof body.reason === "string" ? body.reason : void 0;
|
|
255
532
|
if (body.errors && Array.isArray(body.errors)) {
|
|
256
533
|
const fieldErrors = [];
|
|
257
534
|
for (const e of body.errors) {
|
|
@@ -273,6 +550,7 @@ async function parseErrorBody(response) {
|
|
|
273
550
|
return {
|
|
274
551
|
errorMessage: `HTTP ${response.status}: ${details}`,
|
|
275
552
|
userMessage: details,
|
|
553
|
+
reason,
|
|
276
554
|
errors: fieldErrors.length > 0 ? fieldErrors : body.errors
|
|
277
555
|
};
|
|
278
556
|
}
|
|
@@ -280,16 +558,18 @@ async function parseErrorBody(response) {
|
|
|
280
558
|
if (typeof body.error === "string") {
|
|
281
559
|
return {
|
|
282
560
|
errorMessage: `HTTP ${response.status}: ${body.error}`,
|
|
283
|
-
userMessage: body.error
|
|
561
|
+
userMessage: body.error,
|
|
562
|
+
reason
|
|
284
563
|
};
|
|
285
564
|
}
|
|
286
565
|
if (body.message) {
|
|
287
566
|
return {
|
|
288
567
|
errorMessage: `HTTP ${response.status}: ${body.message}`,
|
|
289
|
-
userMessage: body.message
|
|
568
|
+
userMessage: body.message,
|
|
569
|
+
reason
|
|
290
570
|
};
|
|
291
571
|
}
|
|
292
|
-
return fallback;
|
|
572
|
+
return { ...fallback, reason };
|
|
293
573
|
} catch {
|
|
294
574
|
return fallback;
|
|
295
575
|
}
|
|
@@ -297,11 +577,16 @@ async function parseErrorBody(response) {
|
|
|
297
577
|
async function delay(ms) {
|
|
298
578
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
299
579
|
}
|
|
580
|
+
function attachRequestId(err, id) {
|
|
581
|
+
if (id) err.requestId = id;
|
|
582
|
+
return err;
|
|
583
|
+
}
|
|
300
584
|
async function httpFetch(url, options) {
|
|
301
585
|
const {
|
|
302
586
|
publishableKey,
|
|
303
587
|
secretKey,
|
|
304
588
|
customerToken,
|
|
589
|
+
tenantId,
|
|
305
590
|
timeout = DEFAULT_TIMEOUT,
|
|
306
591
|
debug,
|
|
307
592
|
retry,
|
|
@@ -331,6 +616,9 @@ async function httpFetch(url, options) {
|
|
|
331
616
|
if (authToken) {
|
|
332
617
|
headers.set("Authorization", `Bearer ${authToken}`);
|
|
333
618
|
}
|
|
619
|
+
if (tenantId) {
|
|
620
|
+
headers.set("X-Tenant-Id", tenantId);
|
|
621
|
+
}
|
|
334
622
|
if (!headers.has("Content-Type") && requestInit.body && !(requestInit.body instanceof FormData)) {
|
|
335
623
|
headers.set("Content-Type", "application/json");
|
|
336
624
|
}
|
|
@@ -352,6 +640,7 @@ async function httpFetch(url, options) {
|
|
|
352
640
|
signal: controller.signal
|
|
353
641
|
});
|
|
354
642
|
clearTimeout(timeoutId);
|
|
643
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
355
644
|
debugLog(debug, "response", url, {
|
|
356
645
|
status: response.status,
|
|
357
646
|
statusText: response.statusText,
|
|
@@ -371,15 +660,19 @@ async function httpFetch(url, options) {
|
|
|
371
660
|
response.headers.get("X-Usage-Remaining") || "0",
|
|
372
661
|
10
|
|
373
662
|
);
|
|
374
|
-
throw
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
663
|
+
throw attachRequestId(
|
|
664
|
+
createUsageLimitError(
|
|
665
|
+
`Monthly API usage limit exceeded (${current.toLocaleString()}/${limit.toLocaleString()})`,
|
|
666
|
+
{ limit, current, remaining },
|
|
667
|
+
{ url, method: requestInit.method || "GET", attempt: attempt + 1 },
|
|
668
|
+
"Monthly API call limit exceeded. Please upgrade your plan.",
|
|
669
|
+
"Upgrade your tenant plan to increase the monthly API call limit."
|
|
670
|
+
),
|
|
671
|
+
requestId
|
|
380
672
|
);
|
|
381
673
|
}
|
|
382
|
-
|
|
674
|
+
const parsed = await parseErrorBody(response);
|
|
675
|
+
if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && parsed.reason === "token_expired") {
|
|
383
676
|
hasRetried401 = true;
|
|
384
677
|
try {
|
|
385
678
|
const newToken = await onUnauthorized();
|
|
@@ -390,29 +683,32 @@ async function httpFetch(url, options) {
|
|
|
390
683
|
} catch {
|
|
391
684
|
}
|
|
392
685
|
}
|
|
686
|
+
const details = {
|
|
687
|
+
url,
|
|
688
|
+
method: requestInit.method || "GET",
|
|
689
|
+
attempt: attempt + 1
|
|
690
|
+
};
|
|
393
691
|
if (NON_RETRYABLE_STATUSES.includes(response.status)) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
692
|
+
throw attachRequestId(
|
|
693
|
+
createNetworkError(
|
|
694
|
+
parsed.errorMessage,
|
|
695
|
+
response.status,
|
|
696
|
+
{ ...details, ...parsed.errors && { errors: parsed.errors } },
|
|
697
|
+
parsed.userMessage,
|
|
698
|
+
getErrorSuggestion(response.status)
|
|
699
|
+
),
|
|
700
|
+
requestId
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
const error = attachRequestId(
|
|
704
|
+
createNetworkError(
|
|
705
|
+
parsed.errorMessage,
|
|
403
706
|
response.status,
|
|
404
707
|
details,
|
|
405
|
-
|
|
708
|
+
parsed.userMessage,
|
|
406
709
|
getErrorSuggestion(response.status)
|
|
407
|
-
)
|
|
408
|
-
|
|
409
|
-
const parsed = await parseErrorBody(response);
|
|
410
|
-
const error = createNetworkError(
|
|
411
|
-
parsed.errorMessage,
|
|
412
|
-
response.status,
|
|
413
|
-
{ url, method: requestInit.method || "GET", attempt: attempt + 1 },
|
|
414
|
-
parsed.userMessage,
|
|
415
|
-
getErrorSuggestion(response.status)
|
|
710
|
+
),
|
|
711
|
+
requestId
|
|
416
712
|
);
|
|
417
713
|
const method = (requestInit.method || "GET").toUpperCase();
|
|
418
714
|
if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method) && retryConfig.retryableStatuses.includes(response.status)) {
|
|
@@ -487,390 +783,24 @@ async function httpFetch(url, options) {
|
|
|
487
783
|
throw lastError ?? new NetworkError("Request failed after retries");
|
|
488
784
|
}
|
|
489
785
|
|
|
490
|
-
// src/core/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
void 0,
|
|
500
|
-
"Server returned an invalid response.",
|
|
501
|
-
"Check if the API endpoint is available."
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
if (data.error) {
|
|
505
|
-
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
506
|
-
throw createApiError(
|
|
507
|
-
errorMessage,
|
|
508
|
-
response.status,
|
|
509
|
-
data,
|
|
510
|
-
errorMessage,
|
|
511
|
-
"An error occurred while processing the request."
|
|
512
|
-
);
|
|
513
|
-
}
|
|
514
|
-
return data;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// src/core/api/base-api.ts
|
|
518
|
-
var BaseApi = class {
|
|
519
|
-
constructor(apiName, options) {
|
|
520
|
-
if (!options.secretKey) {
|
|
521
|
-
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
522
|
-
}
|
|
523
|
-
this.publishableKey = options.publishableKey ?? "";
|
|
524
|
-
this.secretKey = options.secretKey;
|
|
525
|
-
}
|
|
526
|
-
async request(endpoint, body, options) {
|
|
527
|
-
const method = options?.method ?? "POST";
|
|
528
|
-
const response = await httpFetch(endpoint, {
|
|
529
|
-
method,
|
|
530
|
-
publishableKey: this.publishableKey,
|
|
531
|
-
secretKey: this.secretKey,
|
|
532
|
-
...body !== void 0 && { body: JSON.stringify(body) },
|
|
533
|
-
...options?.headers && { headers: options.headers }
|
|
534
|
-
});
|
|
535
|
-
return parseApiResponse(response, endpoint);
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
// src/core/api/order-api.ts
|
|
540
|
-
var OrderApi = class extends BaseApi {
|
|
541
|
-
constructor(options) {
|
|
542
|
-
super("OrderApi", options);
|
|
543
|
-
}
|
|
544
|
-
createOrder(params) {
|
|
545
|
-
return this.request("/api/orders/create", params);
|
|
546
|
-
}
|
|
547
|
-
updateOrder(params) {
|
|
548
|
-
return this.request("/api/orders/update", params);
|
|
549
|
-
}
|
|
550
|
-
getOrder(params) {
|
|
551
|
-
return this.request("/api/orders/get", params);
|
|
552
|
-
}
|
|
553
|
-
updateTransaction(params) {
|
|
554
|
-
return this.request("/api/transactions/update", params);
|
|
555
|
-
}
|
|
556
|
-
checkout(params) {
|
|
557
|
-
return this.request("/api/orders/checkout", params);
|
|
558
|
-
}
|
|
559
|
-
createFulfillment(params) {
|
|
560
|
-
return this.request("/api/orders/create-fulfillment", params);
|
|
561
|
-
}
|
|
562
|
-
updateFulfillment(params) {
|
|
563
|
-
return this.request("/api/orders/update-fulfillment", params);
|
|
564
|
-
}
|
|
565
|
-
returnWithRefund(params) {
|
|
566
|
-
return this.request(
|
|
567
|
-
"/api/returns/return-refund",
|
|
568
|
-
params
|
|
569
|
-
);
|
|
570
|
-
}
|
|
571
|
-
createReturn(params) {
|
|
572
|
-
return this.request("/api/returns/create", params);
|
|
573
|
-
}
|
|
574
|
-
updateReturn(params) {
|
|
575
|
-
return this.request("/api/returns/update", params);
|
|
576
|
-
}
|
|
577
|
-
validateDiscount(params) {
|
|
578
|
-
return this.request(
|
|
579
|
-
"/api/discounts/validate",
|
|
580
|
-
params
|
|
581
|
-
);
|
|
582
|
-
}
|
|
583
|
-
calculateShipping(params) {
|
|
584
|
-
return this.request(
|
|
585
|
-
"/api/shipping-policies/calculate",
|
|
586
|
-
params
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
// src/core/api/cart-api.ts
|
|
592
|
-
var CartApi = class {
|
|
593
|
-
constructor(options) {
|
|
594
|
-
if (!options.secretKey && !options.customerToken) {
|
|
595
|
-
throw createConfigError(
|
|
596
|
-
"Either secretKey or customerToken is required for CartApi."
|
|
597
|
-
);
|
|
598
|
-
}
|
|
599
|
-
this.publishableKey = options.publishableKey ?? "";
|
|
600
|
-
this.secretKey = options.secretKey;
|
|
601
|
-
this.customerToken = options.customerToken;
|
|
602
|
-
this.onUnauthorized = options.onUnauthorized;
|
|
603
|
-
}
|
|
604
|
-
async execute(endpoint, method, body) {
|
|
605
|
-
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
606
|
-
const response = await httpFetch(endpoint, {
|
|
607
|
-
method,
|
|
608
|
-
publishableKey: this.publishableKey,
|
|
609
|
-
secretKey: this.secretKey,
|
|
610
|
-
customerToken: token ?? void 0,
|
|
611
|
-
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
612
|
-
...body !== void 0 && { body: JSON.stringify(body) }
|
|
613
|
-
});
|
|
614
|
-
return parseApiResponse(response, endpoint);
|
|
615
|
-
}
|
|
616
|
-
getCart(cartId) {
|
|
617
|
-
return this.execute(`/api/carts/${cartId}`, "GET");
|
|
618
|
-
}
|
|
619
|
-
addItem(params) {
|
|
620
|
-
return this.execute("/api/carts/add-item", "POST", params);
|
|
621
|
-
}
|
|
622
|
-
updateItem(params) {
|
|
623
|
-
return this.execute("/api/carts/update-item", "POST", params);
|
|
624
|
-
}
|
|
625
|
-
removeItem(params) {
|
|
626
|
-
return this.execute(
|
|
627
|
-
"/api/carts/remove-item",
|
|
628
|
-
"POST",
|
|
629
|
-
params
|
|
630
|
-
);
|
|
631
|
-
}
|
|
632
|
-
applyDiscount(params) {
|
|
633
|
-
return this.execute("/api/carts/apply-discount", "POST", params);
|
|
634
|
-
}
|
|
635
|
-
removeDiscount(params) {
|
|
636
|
-
return this.execute("/api/carts/remove-discount", "POST", params);
|
|
637
|
-
}
|
|
638
|
-
clearCart(params) {
|
|
639
|
-
return this.execute(
|
|
640
|
-
"/api/carts/clear",
|
|
641
|
-
"POST",
|
|
642
|
-
params
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
// src/core/api/product-api.ts
|
|
648
|
-
var ProductApi = class extends BaseApi {
|
|
649
|
-
constructor(options) {
|
|
650
|
-
super("ProductApi", options);
|
|
651
|
-
}
|
|
652
|
-
stockCheck(params) {
|
|
653
|
-
return this.request("/api/products/stock-check", params);
|
|
654
|
-
}
|
|
655
|
-
listingGroups(params) {
|
|
656
|
-
return this.request(
|
|
657
|
-
"/api/products/listing-groups",
|
|
658
|
-
params
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
// src/utils/types.ts
|
|
664
|
-
var resolveRelation = (ref) => {
|
|
665
|
-
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
666
|
-
return null;
|
|
667
|
-
return ref;
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
// src/core/metadata/index.ts
|
|
671
|
-
function extractSeo(doc) {
|
|
672
|
-
const seo = doc.seo ?? {};
|
|
673
|
-
const og = seo.openGraph ?? {};
|
|
674
|
-
return {
|
|
675
|
-
title: seo.title ?? doc.title ?? null,
|
|
676
|
-
description: seo.description ?? null,
|
|
677
|
-
noIndex: seo.noIndex ?? null,
|
|
678
|
-
canonical: seo.canonical ?? null,
|
|
679
|
-
openGraph: {
|
|
680
|
-
title: og.title ?? null,
|
|
681
|
-
description: og.description ?? null,
|
|
682
|
-
image: og.image ?? null
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
function generateMetadata(input, options) {
|
|
687
|
-
const title = input.title ?? void 0;
|
|
688
|
-
const description = input.description ?? void 0;
|
|
689
|
-
const ogTitle = input.openGraph?.title ?? title;
|
|
690
|
-
const ogDescription = input.openGraph?.description ?? description;
|
|
691
|
-
const image = resolveMetaImage(input.openGraph?.image);
|
|
692
|
-
return {
|
|
693
|
-
title,
|
|
694
|
-
description,
|
|
695
|
-
...input.noIndex && { robots: { index: false, follow: false } },
|
|
696
|
-
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
697
|
-
openGraph: {
|
|
698
|
-
...ogTitle && { title: ogTitle },
|
|
699
|
-
...ogDescription && { description: ogDescription },
|
|
700
|
-
...options?.siteName && { siteName: options.siteName },
|
|
701
|
-
...image && { images: [image] }
|
|
702
|
-
},
|
|
703
|
-
twitter: {
|
|
704
|
-
card: image ? "summary_large_image" : "summary",
|
|
705
|
-
...ogTitle && { title: ogTitle },
|
|
706
|
-
...ogDescription && { description: ogDescription },
|
|
707
|
-
...image && { images: [image.url] }
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
function resolveMetaImage(ref) {
|
|
712
|
-
const image = resolveRelation(ref);
|
|
713
|
-
if (!image) return null;
|
|
714
|
-
const sized = image.sizes?.["1536"];
|
|
715
|
-
const url = sized?.url || image.url;
|
|
716
|
-
if (!url) return null;
|
|
717
|
-
const width = sized?.url ? sized.width : image.width;
|
|
718
|
-
const height = sized?.url ? sized.height : image.height;
|
|
719
|
-
return {
|
|
720
|
-
url,
|
|
721
|
-
...width && { width },
|
|
722
|
-
...height && { height },
|
|
723
|
-
...image.alt && { alt: image.alt }
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// src/core/collection/query-builder.ts
|
|
728
|
-
var CollectionQueryBuilder = class {
|
|
729
|
-
constructor(api, collection) {
|
|
730
|
-
this.api = api;
|
|
731
|
-
this.collection = collection;
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Find documents (list query)
|
|
735
|
-
* GET /api/{collection}
|
|
736
|
-
* @returns Payload CMS find response with docs array and pagination
|
|
737
|
-
*/
|
|
738
|
-
async find(options) {
|
|
739
|
-
return this.api.requestFind(
|
|
740
|
-
`/api/${String(this.collection)}`,
|
|
741
|
-
options
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Find document by ID
|
|
746
|
-
* GET /api/{collection}/{id}
|
|
747
|
-
* @returns Document object directly (no wrapper)
|
|
748
|
-
*/
|
|
749
|
-
async findById(id, options) {
|
|
750
|
-
return this.api.requestFindById(
|
|
751
|
-
`/api/${String(this.collection)}/${String(id)}`,
|
|
752
|
-
options
|
|
753
|
-
);
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* Create a new document
|
|
757
|
-
* POST /api/{collection}
|
|
758
|
-
* @returns Payload CMS mutation response with doc and message
|
|
759
|
-
*/
|
|
760
|
-
async create(data, options) {
|
|
761
|
-
const endpoint = `/api/${String(this.collection)}`;
|
|
762
|
-
if (options?.file) {
|
|
763
|
-
return this.api.requestCreateWithFile(
|
|
764
|
-
endpoint,
|
|
765
|
-
data,
|
|
766
|
-
options.file,
|
|
767
|
-
options.filename
|
|
768
|
-
);
|
|
769
|
-
}
|
|
770
|
-
return this.api.requestCreate(endpoint, data);
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* Update a document by ID
|
|
774
|
-
* PATCH /api/{collection}/{id}
|
|
775
|
-
* @returns Payload CMS mutation response with doc and message
|
|
776
|
-
*/
|
|
777
|
-
async update(id, data, options) {
|
|
778
|
-
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
779
|
-
if (options?.file) {
|
|
780
|
-
return this.api.requestUpdateWithFile(
|
|
781
|
-
endpoint,
|
|
782
|
-
data,
|
|
783
|
-
options.file,
|
|
784
|
-
options.filename
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
return this.api.requestUpdate(endpoint, data);
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Count documents
|
|
791
|
-
* GET /api/{collection}/count
|
|
792
|
-
* @returns Count response with totalDocs
|
|
793
|
-
*/
|
|
794
|
-
async count(options) {
|
|
795
|
-
return this.api.requestCount(
|
|
796
|
-
`/api/${String(this.collection)}/count`,
|
|
797
|
-
options
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Find first matching document and return its Next.js Metadata.
|
|
802
|
-
* Applies depth: 1 (SEO image populate) and limit: 1 automatically.
|
|
803
|
-
* @returns Metadata or null if no document matches
|
|
804
|
-
*/
|
|
805
|
-
async findMetadata(options, metadataOptions) {
|
|
806
|
-
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
807
|
-
const doc = docs[0];
|
|
808
|
-
if (!doc) return null;
|
|
809
|
-
return generateMetadata(
|
|
810
|
-
extractSeo(doc),
|
|
811
|
-
metadataOptions
|
|
812
|
-
);
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Find document by ID and return its Next.js Metadata.
|
|
816
|
-
* Applies depth: 1 (SEO image populate) automatically.
|
|
817
|
-
* @returns Metadata (throws on 404)
|
|
818
|
-
*/
|
|
819
|
-
async findMetadataById(id, metadataOptions) {
|
|
820
|
-
const doc = await this.findById(id, { depth: 1 });
|
|
821
|
-
return generateMetadata(
|
|
822
|
-
extractSeo(doc),
|
|
823
|
-
metadataOptions
|
|
824
|
-
);
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Update multiple documents (bulk update)
|
|
828
|
-
* PATCH /api/{collection}
|
|
829
|
-
* @returns Payload CMS find response with updated docs
|
|
830
|
-
*/
|
|
831
|
-
async updateMany(where, data) {
|
|
832
|
-
return this.api.requestUpdateMany(
|
|
833
|
-
`/api/${String(this.collection)}`,
|
|
834
|
-
{ where, data }
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Delete a document by ID
|
|
839
|
-
* DELETE /api/{collection}/{id}
|
|
840
|
-
* @returns Deleted document object directly (no wrapper)
|
|
841
|
-
*/
|
|
842
|
-
async remove(id) {
|
|
843
|
-
return this.api.requestDelete(
|
|
844
|
-
`/api/${String(this.collection)}/${String(id)}`
|
|
845
|
-
);
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Delete multiple documents (bulk delete)
|
|
849
|
-
* DELETE /api/{collection}
|
|
850
|
-
* @returns Payload CMS find response with deleted docs
|
|
851
|
-
*/
|
|
852
|
-
async removeMany(where) {
|
|
853
|
-
return this.api.requestDeleteMany(
|
|
854
|
-
`/api/${String(this.collection)}`,
|
|
855
|
-
{ where }
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
// src/core/collection/http-client.ts
|
|
861
|
-
var import_qs_esm = require("qs-esm");
|
|
862
|
-
var HttpClient = class {
|
|
863
|
-
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized) {
|
|
864
|
-
this.publishableKey = publishableKey;
|
|
865
|
-
this.secretKey = secretKey;
|
|
866
|
-
this.getCustomerToken = getCustomerToken;
|
|
867
|
-
this.onUnauthorized = onUnauthorized;
|
|
786
|
+
// src/core/collection/http-client.ts
|
|
787
|
+
var HttpClient = class {
|
|
788
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, tenantId) {
|
|
789
|
+
this.publishableKey = publishableKey;
|
|
790
|
+
this.secretKey = secretKey;
|
|
791
|
+
this.tenantId = tenantId;
|
|
792
|
+
this.getCustomerToken = getCustomerToken;
|
|
793
|
+
this.onUnauthorized = onUnauthorized;
|
|
794
|
+
this.onRequestId = onRequestId;
|
|
868
795
|
}
|
|
869
796
|
get defaultOptions() {
|
|
870
797
|
const opts = {
|
|
871
798
|
publishableKey: this.publishableKey,
|
|
872
799
|
secretKey: this.secretKey
|
|
873
800
|
};
|
|
801
|
+
if (this.secretKey?.startsWith("pat01_") && this.tenantId) {
|
|
802
|
+
opts.tenantId = this.tenantId;
|
|
803
|
+
}
|
|
874
804
|
const token = this.getCustomerToken?.();
|
|
875
805
|
if (token) {
|
|
876
806
|
opts.customerToken = token;
|
|
@@ -880,6 +810,17 @@ var HttpClient = class {
|
|
|
880
810
|
}
|
|
881
811
|
return opts;
|
|
882
812
|
}
|
|
813
|
+
async fetchWithTracking(url, opts) {
|
|
814
|
+
try {
|
|
815
|
+
const response = await httpFetch(url, opts);
|
|
816
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
817
|
+
return response;
|
|
818
|
+
} catch (err) {
|
|
819
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
820
|
+
this.onRequestId?.(id);
|
|
821
|
+
throw err;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
883
824
|
buildUrl(endpoint, options) {
|
|
884
825
|
if (!options) return endpoint;
|
|
885
826
|
const queryString = (0, import_qs_esm.stringify)(options, { addQueryPrefix: true });
|
|
@@ -996,7 +937,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
996
937
|
*/
|
|
997
938
|
async requestFind(endpoint, options) {
|
|
998
939
|
const url = this.buildUrl(endpoint, options);
|
|
999
|
-
const response = await
|
|
940
|
+
const response = await this.fetchWithTracking(url, {
|
|
1000
941
|
...this.defaultOptions,
|
|
1001
942
|
method: "GET"
|
|
1002
943
|
});
|
|
@@ -1007,7 +948,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1007
948
|
* POST /api/...custom-endpoint
|
|
1008
949
|
*/
|
|
1009
950
|
async requestFindEndpoint(endpoint, data) {
|
|
1010
|
-
const response = await
|
|
951
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1011
952
|
...this.defaultOptions,
|
|
1012
953
|
method: "POST",
|
|
1013
954
|
body: data ? JSON.stringify(data) : void 0
|
|
@@ -1020,7 +961,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1020
961
|
*/
|
|
1021
962
|
async requestFindById(endpoint, options) {
|
|
1022
963
|
const url = this.buildUrl(endpoint, options);
|
|
1023
|
-
const response = await
|
|
964
|
+
const response = await this.fetchWithTracking(url, {
|
|
1024
965
|
...this.defaultOptions,
|
|
1025
966
|
method: "GET"
|
|
1026
967
|
});
|
|
@@ -1031,7 +972,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1031
972
|
* POST /api/{collection}
|
|
1032
973
|
*/
|
|
1033
974
|
async requestCreate(endpoint, data) {
|
|
1034
|
-
const response = await
|
|
975
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1035
976
|
...this.defaultOptions,
|
|
1036
977
|
method: "POST",
|
|
1037
978
|
body: data ? JSON.stringify(data) : void 0
|
|
@@ -1043,7 +984,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1043
984
|
* PATCH /api/{collection}/{id}
|
|
1044
985
|
*/
|
|
1045
986
|
async requestUpdate(endpoint, data) {
|
|
1046
|
-
const response = await
|
|
987
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1047
988
|
...this.defaultOptions,
|
|
1048
989
|
method: "PATCH",
|
|
1049
990
|
body: data ? JSON.stringify(data) : void 0
|
|
@@ -1056,7 +997,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1056
997
|
*/
|
|
1057
998
|
async requestCount(endpoint, options) {
|
|
1058
999
|
const url = this.buildUrl(endpoint, options);
|
|
1059
|
-
const response = await
|
|
1000
|
+
const response = await this.fetchWithTracking(url, {
|
|
1060
1001
|
...this.defaultOptions,
|
|
1061
1002
|
method: "GET"
|
|
1062
1003
|
});
|
|
@@ -1067,7 +1008,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1067
1008
|
* PATCH /api/{collection}
|
|
1068
1009
|
*/
|
|
1069
1010
|
async requestUpdateMany(endpoint, data) {
|
|
1070
|
-
const response = await
|
|
1011
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1071
1012
|
...this.defaultOptions,
|
|
1072
1013
|
method: "PATCH",
|
|
1073
1014
|
body: JSON.stringify(data)
|
|
@@ -1079,7 +1020,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1079
1020
|
* DELETE /api/{collection}/{id}
|
|
1080
1021
|
*/
|
|
1081
1022
|
async requestDelete(endpoint) {
|
|
1082
|
-
const response = await
|
|
1023
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1083
1024
|
...this.defaultOptions,
|
|
1084
1025
|
method: "DELETE"
|
|
1085
1026
|
});
|
|
@@ -1090,7 +1031,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1090
1031
|
* DELETE /api/{collection}
|
|
1091
1032
|
*/
|
|
1092
1033
|
async requestDeleteMany(endpoint, data) {
|
|
1093
|
-
const response = await
|
|
1034
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1094
1035
|
...this.defaultOptions,
|
|
1095
1036
|
method: "DELETE",
|
|
1096
1037
|
body: JSON.stringify(data)
|
|
@@ -1102,7 +1043,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1102
1043
|
* POST /api/{collection} (multipart/form-data)
|
|
1103
1044
|
*/
|
|
1104
1045
|
async requestCreateWithFile(endpoint, data, file, filename) {
|
|
1105
|
-
const response = await
|
|
1046
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1106
1047
|
...this.defaultOptions,
|
|
1107
1048
|
method: "POST",
|
|
1108
1049
|
body: buildPayloadFormData(data, file, filename)
|
|
@@ -1114,7 +1055,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1114
1055
|
* PATCH /api/{collection}/{id} (multipart/form-data)
|
|
1115
1056
|
*/
|
|
1116
1057
|
async requestUpdateWithFile(endpoint, data, file, filename) {
|
|
1117
|
-
const response = await
|
|
1058
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1118
1059
|
...this.defaultOptions,
|
|
1119
1060
|
method: "PATCH",
|
|
1120
1061
|
body: buildPayloadFormData(data, file, filename)
|
|
@@ -1194,49 +1135,101 @@ var COLLECTIONS = [
|
|
|
1194
1135
|
"community-bans"
|
|
1195
1136
|
];
|
|
1196
1137
|
|
|
1138
|
+
// src/core/api/parse-response.ts
|
|
1139
|
+
async function parseApiResponse(response, endpoint) {
|
|
1140
|
+
let data;
|
|
1141
|
+
try {
|
|
1142
|
+
data = await response.json();
|
|
1143
|
+
} catch {
|
|
1144
|
+
throw createApiError(
|
|
1145
|
+
`Invalid JSON response from ${endpoint}`,
|
|
1146
|
+
response.status,
|
|
1147
|
+
void 0,
|
|
1148
|
+
"Server returned an invalid response.",
|
|
1149
|
+
"Check if the API endpoint is available."
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
if (data.error) {
|
|
1153
|
+
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
1154
|
+
const reason = typeof data.reason === "string" ? data.reason : void 0;
|
|
1155
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
1156
|
+
const retryAfterRaw = response.headers.get("Retry-After");
|
|
1157
|
+
const retryAfter = retryAfterRaw ? parseInt(retryAfterRaw, 10) || void 0 : void 0;
|
|
1158
|
+
if (reason === "validation_failed") {
|
|
1159
|
+
throw attachRequestId(createValidationError(errorMessage, data, errorMessage), requestId);
|
|
1160
|
+
}
|
|
1161
|
+
if (reason === "token_expired" || reason === "token_invalid" || reason === "key_invalid" || reason === "key_revoked") {
|
|
1162
|
+
throw attachRequestId(createAuthError(errorMessage, data, errorMessage), requestId);
|
|
1163
|
+
}
|
|
1164
|
+
if (reason === "forbidden") {
|
|
1165
|
+
throw attachRequestId(createPermissionError(errorMessage, data, errorMessage), requestId);
|
|
1166
|
+
}
|
|
1167
|
+
if (reason === "rate_limit_exceeded") {
|
|
1168
|
+
throw attachRequestId(createRateLimitError(errorMessage, retryAfter, data, errorMessage), requestId);
|
|
1169
|
+
}
|
|
1170
|
+
if (reason === "not_found") {
|
|
1171
|
+
throw attachRequestId(createNotFoundError(errorMessage, data, errorMessage), requestId);
|
|
1172
|
+
}
|
|
1173
|
+
if (reason === "conflict") {
|
|
1174
|
+
throw attachRequestId(createConflictError(errorMessage, data, errorMessage), requestId);
|
|
1175
|
+
}
|
|
1176
|
+
throw attachRequestId(
|
|
1177
|
+
createApiError(errorMessage, response.status, data, errorMessage, "An error occurred while processing the request."),
|
|
1178
|
+
requestId
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
return data;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1197
1184
|
// src/core/community/community-client.ts
|
|
1198
1185
|
var CommunityClient = class {
|
|
1199
1186
|
constructor(options) {
|
|
1200
1187
|
this.publishableKey = options.publishableKey ?? "";
|
|
1201
1188
|
this.secretKey = options.secretKey;
|
|
1189
|
+
this.tenantId = options.tenantId;
|
|
1202
1190
|
this.customerToken = options.customerToken;
|
|
1203
1191
|
this.onUnauthorized = options.onUnauthorized;
|
|
1192
|
+
this.onRequestId = options.onRequestId;
|
|
1193
|
+
}
|
|
1194
|
+
buildQuery(params) {
|
|
1195
|
+
if (!params) return "";
|
|
1196
|
+
const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
|
|
1197
|
+
return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
|
|
1204
1198
|
}
|
|
1205
1199
|
async execute(endpoint, method, body) {
|
|
1206
1200
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1201
|
+
const tenantId = this.secretKey?.startsWith("pat01_") && this.tenantId ? this.tenantId : void 0;
|
|
1202
|
+
try {
|
|
1203
|
+
const response = await httpFetch(endpoint, {
|
|
1204
|
+
method,
|
|
1205
|
+
publishableKey: this.publishableKey,
|
|
1206
|
+
secretKey: this.secretKey,
|
|
1207
|
+
tenantId,
|
|
1208
|
+
customerToken: token ?? void 0,
|
|
1209
|
+
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1210
|
+
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1211
|
+
});
|
|
1212
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1213
|
+
return parseApiResponse(response, endpoint);
|
|
1214
|
+
} catch (err) {
|
|
1215
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1216
|
+
this.onRequestId?.(id);
|
|
1217
|
+
throw err;
|
|
1218
|
+
}
|
|
1216
1219
|
}
|
|
1217
1220
|
// Threads
|
|
1218
1221
|
createThread(params) {
|
|
1219
1222
|
return this.execute("/api/threads", "POST", params);
|
|
1220
1223
|
}
|
|
1221
1224
|
getMyThreads(params) {
|
|
1222
|
-
const query = params ? `?${new URLSearchParams(
|
|
1223
|
-
Object.fromEntries(
|
|
1224
|
-
Object.entries(params).map(([k, v]) => [k, String(v)])
|
|
1225
|
-
)
|
|
1226
|
-
).toString()}` : "";
|
|
1227
1225
|
return this.execute(
|
|
1228
|
-
`/api/threads/my${
|
|
1226
|
+
`/api/threads/my${this.buildQuery(params)}`,
|
|
1229
1227
|
"GET"
|
|
1230
1228
|
);
|
|
1231
1229
|
}
|
|
1232
1230
|
getTrending(params) {
|
|
1233
|
-
const query = params ? `?${new URLSearchParams(
|
|
1234
|
-
Object.fromEntries(
|
|
1235
|
-
Object.entries(params).map(([k, v]) => [k, String(v)])
|
|
1236
|
-
)
|
|
1237
|
-
).toString()}` : "";
|
|
1238
1231
|
return this.execute(
|
|
1239
|
-
`/api/threads/trending${
|
|
1232
|
+
`/api/threads/trending${this.buildQuery(params)}`,
|
|
1240
1233
|
"GET"
|
|
1241
1234
|
);
|
|
1242
1235
|
}
|
|
@@ -1352,26 +1345,56 @@ var CommunityClient = class {
|
|
|
1352
1345
|
);
|
|
1353
1346
|
}
|
|
1354
1347
|
getMyBookmarks(params) {
|
|
1355
|
-
const query = params ? `?${new URLSearchParams(
|
|
1356
|
-
Object.fromEntries(
|
|
1357
|
-
Object.entries(params).map(([k, v]) => [k, String(v)])
|
|
1358
|
-
)
|
|
1359
|
-
).toString()}` : "";
|
|
1360
1348
|
return this.execute(
|
|
1361
|
-
`/api/bookmarks/my${
|
|
1349
|
+
`/api/bookmarks/my${this.buildQuery(params)}`,
|
|
1362
1350
|
"GET"
|
|
1363
1351
|
);
|
|
1364
1352
|
}
|
|
1365
|
-
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
// src/core/api/base-api.ts
|
|
1356
|
+
var BaseApi = class {
|
|
1357
|
+
constructor(apiName, options) {
|
|
1358
|
+
if (!options.secretKey) {
|
|
1359
|
+
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
1360
|
+
}
|
|
1361
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
1362
|
+
this.secretKey = options.secretKey;
|
|
1363
|
+
this.tenantId = options.tenantId;
|
|
1364
|
+
this.onRequestId = options.onRequestId;
|
|
1365
|
+
}
|
|
1366
|
+
async request(endpoint, body, options) {
|
|
1367
|
+
const method = options?.method ?? "POST";
|
|
1368
|
+
const tenantId = this.secretKey.startsWith("pat01_") && this.tenantId ? this.tenantId : void 0;
|
|
1369
|
+
try {
|
|
1370
|
+
const response = await httpFetch(endpoint, {
|
|
1371
|
+
method,
|
|
1372
|
+
publishableKey: this.publishableKey,
|
|
1373
|
+
secretKey: this.secretKey,
|
|
1374
|
+
tenantId,
|
|
1375
|
+
...body !== void 0 && { body: JSON.stringify(body) },
|
|
1376
|
+
...options?.headers && { headers: options.headers }
|
|
1377
|
+
});
|
|
1378
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1379
|
+
return parseApiResponse(response, endpoint);
|
|
1380
|
+
} catch (err) {
|
|
1381
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1382
|
+
this.onRequestId?.(id);
|
|
1383
|
+
throw err;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
// src/core/community/moderation-api.ts
|
|
1389
|
+
var ModerationApi = class extends BaseApi {
|
|
1390
|
+
constructor(options) {
|
|
1391
|
+
super("ModerationApi", options);
|
|
1392
|
+
}
|
|
1366
1393
|
banCustomer(params) {
|
|
1367
|
-
return this.
|
|
1394
|
+
return this.request("/api/community-bans/ban", params);
|
|
1368
1395
|
}
|
|
1369
1396
|
unbanCustomer(params) {
|
|
1370
|
-
return this.
|
|
1371
|
-
"/api/community-bans/unban",
|
|
1372
|
-
"DELETE",
|
|
1373
|
-
params
|
|
1374
|
-
);
|
|
1397
|
+
return this.request("/api/community-bans/unban", params);
|
|
1375
1398
|
}
|
|
1376
1399
|
};
|
|
1377
1400
|
|
|
@@ -1626,6 +1649,265 @@ var CustomerAuth = class {
|
|
|
1626
1649
|
}
|
|
1627
1650
|
};
|
|
1628
1651
|
|
|
1652
|
+
// src/core/customer/customer-namespace.ts
|
|
1653
|
+
var CustomerNamespace = class {
|
|
1654
|
+
constructor(publishableKey, options) {
|
|
1655
|
+
this.auth = new CustomerAuth(publishableKey, options);
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
// src/core/api/cart-api.ts
|
|
1660
|
+
var CartApi = class {
|
|
1661
|
+
constructor(options) {
|
|
1662
|
+
if (!options.secretKey && !options.customerToken) {
|
|
1663
|
+
throw createConfigError(
|
|
1664
|
+
"Either secretKey or customerToken is required for CartApi."
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
1668
|
+
this.secretKey = options.secretKey;
|
|
1669
|
+
this.tenantId = options.tenantId;
|
|
1670
|
+
this.customerToken = options.customerToken;
|
|
1671
|
+
this.onUnauthorized = options.onUnauthorized;
|
|
1672
|
+
this.onRequestId = options.onRequestId;
|
|
1673
|
+
}
|
|
1674
|
+
async execute(endpoint, method, body) {
|
|
1675
|
+
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1676
|
+
const tenantId = this.secretKey?.startsWith("pat01_") && this.tenantId ? this.tenantId : void 0;
|
|
1677
|
+
try {
|
|
1678
|
+
const response = await httpFetch(endpoint, {
|
|
1679
|
+
method,
|
|
1680
|
+
publishableKey: this.publishableKey,
|
|
1681
|
+
secretKey: this.secretKey,
|
|
1682
|
+
tenantId,
|
|
1683
|
+
customerToken: token ?? void 0,
|
|
1684
|
+
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1685
|
+
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1686
|
+
});
|
|
1687
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1688
|
+
return parseApiResponse(response, endpoint);
|
|
1689
|
+
} catch (err) {
|
|
1690
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1691
|
+
this.onRequestId?.(id);
|
|
1692
|
+
throw err;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
getCart(cartId) {
|
|
1696
|
+
return this.execute(`/api/carts/${cartId}`, "GET");
|
|
1697
|
+
}
|
|
1698
|
+
addItem(params) {
|
|
1699
|
+
return this.execute("/api/carts/add-item", "POST", params);
|
|
1700
|
+
}
|
|
1701
|
+
updateItem(params) {
|
|
1702
|
+
return this.execute("/api/carts/update-item", "POST", params);
|
|
1703
|
+
}
|
|
1704
|
+
removeItem(params) {
|
|
1705
|
+
return this.execute(
|
|
1706
|
+
"/api/carts/remove-item",
|
|
1707
|
+
"POST",
|
|
1708
|
+
params
|
|
1709
|
+
);
|
|
1710
|
+
}
|
|
1711
|
+
applyDiscount(params) {
|
|
1712
|
+
return this.execute("/api/carts/apply-discount", "POST", params);
|
|
1713
|
+
}
|
|
1714
|
+
removeDiscount(params) {
|
|
1715
|
+
return this.execute("/api/carts/remove-discount", "POST", params);
|
|
1716
|
+
}
|
|
1717
|
+
clearCart(params) {
|
|
1718
|
+
return this.execute(
|
|
1719
|
+
"/api/carts/clear",
|
|
1720
|
+
"POST",
|
|
1721
|
+
params
|
|
1722
|
+
);
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
// src/core/commerce/commerce-client.ts
|
|
1727
|
+
var CommerceClient = class {
|
|
1728
|
+
constructor(options) {
|
|
1729
|
+
const cartApi = new CartApi({
|
|
1730
|
+
publishableKey: options.publishableKey,
|
|
1731
|
+
customerToken: options.customerToken,
|
|
1732
|
+
onUnauthorized: options.onUnauthorized,
|
|
1733
|
+
onRequestId: options.onRequestId
|
|
1734
|
+
});
|
|
1735
|
+
const execute = async (endpoint, body) => {
|
|
1736
|
+
const token = options.customerToken();
|
|
1737
|
+
try {
|
|
1738
|
+
const response = await httpFetch(endpoint, {
|
|
1739
|
+
method: "POST",
|
|
1740
|
+
publishableKey: options.publishableKey,
|
|
1741
|
+
customerToken: token ?? void 0,
|
|
1742
|
+
...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
|
|
1743
|
+
body: JSON.stringify(body)
|
|
1744
|
+
});
|
|
1745
|
+
options.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1746
|
+
return parseApiResponse(response, endpoint);
|
|
1747
|
+
} catch (err) {
|
|
1748
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1749
|
+
options.onRequestId?.(id);
|
|
1750
|
+
throw err;
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
this.product = {
|
|
1754
|
+
stockCheck: (params) => execute("/api/products/stock-check", params),
|
|
1755
|
+
listingGroups: (params) => execute("/api/products/listing-groups", params)
|
|
1756
|
+
};
|
|
1757
|
+
this.cart = {
|
|
1758
|
+
get: cartApi.getCart.bind(cartApi),
|
|
1759
|
+
addItem: cartApi.addItem.bind(cartApi),
|
|
1760
|
+
updateItem: cartApi.updateItem.bind(cartApi),
|
|
1761
|
+
removeItem: cartApi.removeItem.bind(cartApi),
|
|
1762
|
+
applyDiscount: cartApi.applyDiscount.bind(cartApi),
|
|
1763
|
+
removeDiscount: cartApi.removeDiscount.bind(cartApi),
|
|
1764
|
+
clear: cartApi.clearCart.bind(cartApi)
|
|
1765
|
+
};
|
|
1766
|
+
this.orders = {
|
|
1767
|
+
checkout: (params) => execute("/api/orders/checkout", params),
|
|
1768
|
+
listMine: (params) => options.customerAuth.getMyOrders(params)
|
|
1769
|
+
};
|
|
1770
|
+
this.discounts = {
|
|
1771
|
+
validate: (params) => execute("/api/discounts/validate", params)
|
|
1772
|
+
};
|
|
1773
|
+
this.shipping = {
|
|
1774
|
+
calculate: (params) => execute("/api/shipping-policies/calculate", params)
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1779
|
+
// src/core/api/product-api.ts
|
|
1780
|
+
var ProductApi = class extends BaseApi {
|
|
1781
|
+
constructor(options) {
|
|
1782
|
+
super("ProductApi", options);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Check point-in-time stock availability for one or more product variants.
|
|
1786
|
+
* Results reflect available stock at the moment of the call and are not guaranteed
|
|
1787
|
+
* to remain available by the time an order is placed.
|
|
1788
|
+
*/
|
|
1789
|
+
stockCheck(params) {
|
|
1790
|
+
return this.request("/api/products/stock-check", params);
|
|
1791
|
+
}
|
|
1792
|
+
listingGroups(params) {
|
|
1793
|
+
return this.request(
|
|
1794
|
+
"/api/products/listing-groups",
|
|
1795
|
+
params
|
|
1796
|
+
);
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
|
|
1800
|
+
// src/core/api/discount-api.ts
|
|
1801
|
+
var DiscountApi = class extends BaseApi {
|
|
1802
|
+
constructor(options) {
|
|
1803
|
+
super("DiscountApi", options);
|
|
1804
|
+
}
|
|
1805
|
+
validate(params) {
|
|
1806
|
+
return this.request("/api/discounts/validate", params);
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
|
|
1810
|
+
// src/core/api/shipping-api.ts
|
|
1811
|
+
var ShippingApi = class extends BaseApi {
|
|
1812
|
+
constructor(options) {
|
|
1813
|
+
super("ShippingApi", options);
|
|
1814
|
+
}
|
|
1815
|
+
calculate(params) {
|
|
1816
|
+
return this.request("/api/shipping-policies/calculate", params);
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1820
|
+
// src/core/api/order-api.ts
|
|
1821
|
+
var OrderApi = class extends BaseApi {
|
|
1822
|
+
constructor(options) {
|
|
1823
|
+
super("OrderApi", options);
|
|
1824
|
+
}
|
|
1825
|
+
createOrder(params) {
|
|
1826
|
+
return this.request("/api/orders/create", params);
|
|
1827
|
+
}
|
|
1828
|
+
updateOrder(params) {
|
|
1829
|
+
return this.request("/api/orders/update", params);
|
|
1830
|
+
}
|
|
1831
|
+
updateTransaction(params) {
|
|
1832
|
+
return this.request("/api/transactions/update", params);
|
|
1833
|
+
}
|
|
1834
|
+
checkout(params) {
|
|
1835
|
+
return this.request("/api/orders/checkout", params);
|
|
1836
|
+
}
|
|
1837
|
+
createFulfillment(params) {
|
|
1838
|
+
return this.request("/api/orders/create-fulfillment", params);
|
|
1839
|
+
}
|
|
1840
|
+
updateFulfillment(params) {
|
|
1841
|
+
return this.request("/api/orders/update-fulfillment", params);
|
|
1842
|
+
}
|
|
1843
|
+
bulkImportFulfillments(params) {
|
|
1844
|
+
return this.request(
|
|
1845
|
+
"/api/orders/bulk-import-fulfillments",
|
|
1846
|
+
params
|
|
1847
|
+
);
|
|
1848
|
+
}
|
|
1849
|
+
returnWithRefund(params) {
|
|
1850
|
+
return this.request(
|
|
1851
|
+
"/api/returns/return-refund",
|
|
1852
|
+
params
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1855
|
+
createReturn(params) {
|
|
1856
|
+
return this.request("/api/returns/create", params);
|
|
1857
|
+
}
|
|
1858
|
+
updateReturn(params) {
|
|
1859
|
+
return this.request("/api/returns/update", params);
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
// src/core/commerce/server-commerce-client.ts
|
|
1864
|
+
var ServerCommerceClient = class {
|
|
1865
|
+
constructor(options) {
|
|
1866
|
+
const serverOptions = {
|
|
1867
|
+
publishableKey: options.publishableKey,
|
|
1868
|
+
secretKey: options.secretKey,
|
|
1869
|
+
tenantId: options.tenantId,
|
|
1870
|
+
onRequestId: options.onRequestId
|
|
1871
|
+
};
|
|
1872
|
+
const productApi = new ProductApi(serverOptions);
|
|
1873
|
+
const cartApi = new CartApi(serverOptions);
|
|
1874
|
+
const discountApi = new DiscountApi(serverOptions);
|
|
1875
|
+
const shippingApi = new ShippingApi(serverOptions);
|
|
1876
|
+
const orderApi = new OrderApi(serverOptions);
|
|
1877
|
+
this.product = {
|
|
1878
|
+
stockCheck: productApi.stockCheck.bind(productApi),
|
|
1879
|
+
listingGroups: productApi.listingGroups.bind(productApi)
|
|
1880
|
+
};
|
|
1881
|
+
this.cart = {
|
|
1882
|
+
get: cartApi.getCart.bind(cartApi),
|
|
1883
|
+
addItem: cartApi.addItem.bind(cartApi),
|
|
1884
|
+
updateItem: cartApi.updateItem.bind(cartApi),
|
|
1885
|
+
removeItem: cartApi.removeItem.bind(cartApi),
|
|
1886
|
+
applyDiscount: cartApi.applyDiscount.bind(cartApi),
|
|
1887
|
+
removeDiscount: cartApi.removeDiscount.bind(cartApi),
|
|
1888
|
+
clear: cartApi.clearCart.bind(cartApi)
|
|
1889
|
+
};
|
|
1890
|
+
this.orders = {
|
|
1891
|
+
checkout: orderApi.checkout.bind(orderApi),
|
|
1892
|
+
create: orderApi.createOrder.bind(orderApi),
|
|
1893
|
+
update: orderApi.updateOrder.bind(orderApi),
|
|
1894
|
+
updateTransaction: orderApi.updateTransaction.bind(orderApi),
|
|
1895
|
+
createFulfillment: orderApi.createFulfillment.bind(orderApi),
|
|
1896
|
+
updateFulfillment: orderApi.updateFulfillment.bind(orderApi),
|
|
1897
|
+
bulkImportFulfillments: orderApi.bulkImportFulfillments.bind(orderApi),
|
|
1898
|
+
createReturn: orderApi.createReturn.bind(orderApi),
|
|
1899
|
+
updateReturn: orderApi.updateReturn.bind(orderApi),
|
|
1900
|
+
returnWithRefund: orderApi.returnWithRefund.bind(orderApi)
|
|
1901
|
+
};
|
|
1902
|
+
this.discounts = {
|
|
1903
|
+
validate: discountApi.validate.bind(discountApi)
|
|
1904
|
+
};
|
|
1905
|
+
this.shipping = {
|
|
1906
|
+
calculate: shippingApi.calculate.bind(shippingApi)
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1629
1911
|
// src/core/query/get-query-client.ts
|
|
1630
1912
|
var import_react_query = require("@tanstack/react-query");
|
|
1631
1913
|
function makeQueryClient() {
|
|
@@ -2153,6 +2435,7 @@ var QueryHooks = class extends CollectionHooks {
|
|
|
2153
2435
|
// src/core/client/client.ts
|
|
2154
2436
|
var Client = class {
|
|
2155
2437
|
constructor(options) {
|
|
2438
|
+
this.lastRequestId = null;
|
|
2156
2439
|
const publishableKey = options.publishableKey;
|
|
2157
2440
|
if (!publishableKey) {
|
|
2158
2441
|
throw createConfigError("publishableKey is required.");
|
|
@@ -2164,43 +2447,47 @@ var Client = class {
|
|
|
2164
2447
|
};
|
|
2165
2448
|
this.state = { metadata };
|
|
2166
2449
|
this.queryClient = getQueryClient();
|
|
2167
|
-
this.customer = new
|
|
2450
|
+
this.customer = new CustomerNamespace(
|
|
2168
2451
|
this.config.publishableKey,
|
|
2169
2452
|
options.customer
|
|
2170
2453
|
);
|
|
2171
2454
|
const onUnauthorized = async () => {
|
|
2172
2455
|
try {
|
|
2173
|
-
const result = await this.customer.refreshToken();
|
|
2456
|
+
const result = await this.customer.auth.refreshToken();
|
|
2174
2457
|
return result.token ?? null;
|
|
2175
2458
|
} catch {
|
|
2176
2459
|
return null;
|
|
2177
2460
|
}
|
|
2178
2461
|
};
|
|
2179
|
-
|
|
2462
|
+
const onRequestId = (id) => {
|
|
2463
|
+
this.lastRequestId = id;
|
|
2464
|
+
};
|
|
2465
|
+
this.commerce = new CommerceClient({
|
|
2180
2466
|
publishableKey: this.config.publishableKey,
|
|
2181
|
-
customerToken: () => this.customer.getToken(),
|
|
2182
|
-
onUnauthorized
|
|
2467
|
+
customerToken: () => this.customer.auth.getToken(),
|
|
2468
|
+
onUnauthorized,
|
|
2469
|
+
onRequestId,
|
|
2470
|
+
customerAuth: this.customer.auth
|
|
2183
2471
|
});
|
|
2184
2472
|
this.community = new CommunityClient({
|
|
2185
2473
|
publishableKey: this.config.publishableKey,
|
|
2186
|
-
customerToken: () => this.customer.getToken(),
|
|
2187
|
-
onUnauthorized
|
|
2474
|
+
customerToken: () => this.customer.auth.getToken(),
|
|
2475
|
+
onUnauthorized,
|
|
2476
|
+
onRequestId
|
|
2188
2477
|
});
|
|
2189
2478
|
this.collections = new CollectionClient(
|
|
2190
2479
|
this.config.publishableKey,
|
|
2191
2480
|
void 0,
|
|
2192
|
-
() => this.customer.getToken(),
|
|
2193
|
-
onUnauthorized
|
|
2481
|
+
() => this.customer.auth.getToken(),
|
|
2482
|
+
onUnauthorized,
|
|
2483
|
+
onRequestId
|
|
2194
2484
|
);
|
|
2195
2485
|
this.query = new QueryHooks(
|
|
2196
2486
|
this.queryClient,
|
|
2197
2487
|
this.collections,
|
|
2198
|
-
this.customer
|
|
2488
|
+
this.customer.auth
|
|
2199
2489
|
);
|
|
2200
2490
|
}
|
|
2201
|
-
from(collection) {
|
|
2202
|
-
return this.collections.from(collection);
|
|
2203
|
-
}
|
|
2204
2491
|
getState() {
|
|
2205
2492
|
return { ...this.state };
|
|
2206
2493
|
}
|
|
@@ -2215,6 +2502,7 @@ function createClient(options) {
|
|
|
2215
2502
|
// src/core/client/client.server.ts
|
|
2216
2503
|
var ServerClient = class {
|
|
2217
2504
|
constructor(options) {
|
|
2505
|
+
this.lastRequestId = null;
|
|
2218
2506
|
if (typeof window !== "undefined") {
|
|
2219
2507
|
throw createConfigError(
|
|
2220
2508
|
"ServerClient must not be used in a browser environment. This risks exposing your secretKey in client bundles. Use createClient() for browser code instead."
|
|
@@ -2234,32 +2522,35 @@ var ServerClient = class {
|
|
|
2234
2522
|
userAgent: "Node.js"
|
|
2235
2523
|
};
|
|
2236
2524
|
this.state = { metadata };
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
this.cart = new CartApi({
|
|
2242
|
-
publishableKey: this.config.publishableKey,
|
|
2243
|
-
secretKey: this.config.secretKey
|
|
2244
|
-
});
|
|
2245
|
-
this.community = new CommunityClient({
|
|
2246
|
-
publishableKey: this.config.publishableKey,
|
|
2247
|
-
secretKey: this.config.secretKey
|
|
2248
|
-
});
|
|
2249
|
-
this.product = new ProductApi({
|
|
2525
|
+
const onRequestId = (id) => {
|
|
2526
|
+
this.lastRequestId = id;
|
|
2527
|
+
};
|
|
2528
|
+
const serverOptions = {
|
|
2250
2529
|
publishableKey: this.config.publishableKey,
|
|
2251
|
-
secretKey: this.config.secretKey
|
|
2530
|
+
secretKey: this.config.secretKey,
|
|
2531
|
+
tenantId: this.config.tenantId,
|
|
2532
|
+
onRequestId
|
|
2533
|
+
};
|
|
2534
|
+
this.commerce = new ServerCommerceClient(serverOptions);
|
|
2535
|
+
const communityClient = new CommunityClient(serverOptions);
|
|
2536
|
+
const moderationApi = new ModerationApi(serverOptions);
|
|
2537
|
+
this.community = Object.assign(communityClient, {
|
|
2538
|
+
moderation: {
|
|
2539
|
+
banCustomer: moderationApi.banCustomer.bind(moderationApi),
|
|
2540
|
+
unbanCustomer: moderationApi.unbanCustomer.bind(moderationApi)
|
|
2541
|
+
}
|
|
2252
2542
|
});
|
|
2253
2543
|
this.collections = new CollectionClient(
|
|
2254
2544
|
this.config.publishableKey,
|
|
2255
|
-
this.config.secretKey
|
|
2545
|
+
this.config.secretKey,
|
|
2546
|
+
void 0,
|
|
2547
|
+
void 0,
|
|
2548
|
+
onRequestId,
|
|
2549
|
+
this.config.tenantId
|
|
2256
2550
|
);
|
|
2257
2551
|
this.queryClient = getQueryClient();
|
|
2258
2552
|
this.query = new QueryHooks(this.queryClient, this.collections);
|
|
2259
2553
|
}
|
|
2260
|
-
from(collection) {
|
|
2261
|
-
return this.collections.from(collection);
|
|
2262
|
-
}
|
|
2263
2554
|
getState() {
|
|
2264
2555
|
return { ...this.state };
|
|
2265
2556
|
}
|
|
@@ -2836,4 +3127,174 @@ function getVideoStreamUrl(playbackId) {
|
|
|
2836
3127
|
function getVideoMp4Url(playbackId, resolution = "high") {
|
|
2837
3128
|
return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`;
|
|
2838
3129
|
}
|
|
3130
|
+
|
|
3131
|
+
// src/analytics.ts
|
|
3132
|
+
function createAnalytics(config) {
|
|
3133
|
+
if (typeof window === "undefined") {
|
|
3134
|
+
return { pageview() {
|
|
3135
|
+
}, track() {
|
|
3136
|
+
}, destroy() {
|
|
3137
|
+
} };
|
|
3138
|
+
}
|
|
3139
|
+
const endpoint = config.endpoint ?? `${resolveApiUrl()}/api/analytics/collect`;
|
|
3140
|
+
const respectDnt = config.respectDnt !== false;
|
|
3141
|
+
function isDntActive() {
|
|
3142
|
+
if (!respectDnt) return false;
|
|
3143
|
+
const nav = navigator;
|
|
3144
|
+
return nav.doNotTrack === "1" || nav.globalPrivacyControl === true;
|
|
3145
|
+
}
|
|
3146
|
+
let lastPath = null;
|
|
3147
|
+
let lastAt = 0;
|
|
3148
|
+
const autoTrack = config.autoTrack !== false;
|
|
3149
|
+
const originalPushState = history.pushState;
|
|
3150
|
+
const originalReplaceState = history.replaceState;
|
|
3151
|
+
let destroyed = false;
|
|
3152
|
+
function newEventId() {
|
|
3153
|
+
return typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : String(Date.now()) + String(Math.random());
|
|
3154
|
+
}
|
|
3155
|
+
function sendBeaconOrFetch(body) {
|
|
3156
|
+
try {
|
|
3157
|
+
if (typeof navigator.sendBeacon === "function") {
|
|
3158
|
+
const blob = new Blob([body], { type: "text/plain" });
|
|
3159
|
+
const sent = navigator.sendBeacon(endpoint, blob);
|
|
3160
|
+
if (sent) return;
|
|
3161
|
+
}
|
|
3162
|
+
fetch(endpoint, {
|
|
3163
|
+
method: "POST",
|
|
3164
|
+
keepalive: true,
|
|
3165
|
+
headers: { "Content-Type": "application/json" },
|
|
3166
|
+
body
|
|
3167
|
+
}).catch(() => {
|
|
3168
|
+
});
|
|
3169
|
+
} catch {
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
function sendPageview(pathname) {
|
|
3173
|
+
if (isDntActive()) return;
|
|
3174
|
+
const doc = document;
|
|
3175
|
+
if (doc.prerendering === true || document.visibilityState === "prerender") return;
|
|
3176
|
+
const now = Date.now();
|
|
3177
|
+
if (pathname === lastPath && now - lastAt < 500) return;
|
|
3178
|
+
lastPath = pathname;
|
|
3179
|
+
lastAt = now;
|
|
3180
|
+
const body = JSON.stringify({
|
|
3181
|
+
publishableKey: config.publishableKey,
|
|
3182
|
+
pathname,
|
|
3183
|
+
referrer: document.referrer || "",
|
|
3184
|
+
eventId: newEventId()
|
|
3185
|
+
});
|
|
3186
|
+
sendBeaconOrFetch(body);
|
|
3187
|
+
}
|
|
3188
|
+
function trackCurrentPath() {
|
|
3189
|
+
if (destroyed) return;
|
|
3190
|
+
sendPageview(location.pathname);
|
|
3191
|
+
}
|
|
3192
|
+
function patchedPushState(data, unused, url) {
|
|
3193
|
+
originalPushState.apply(this, [data, unused, url]);
|
|
3194
|
+
if (!destroyed) setTimeout(trackCurrentPath, 0);
|
|
3195
|
+
}
|
|
3196
|
+
function patchedReplaceState(data, unused, url) {
|
|
3197
|
+
originalReplaceState.apply(this, [data, unused, url]);
|
|
3198
|
+
if (!destroyed) setTimeout(trackCurrentPath, 0);
|
|
3199
|
+
}
|
|
3200
|
+
if (autoTrack) {
|
|
3201
|
+
history.pushState = patchedPushState;
|
|
3202
|
+
history.replaceState = patchedReplaceState;
|
|
3203
|
+
window.addEventListener("popstate", trackCurrentPath);
|
|
3204
|
+
if (document.readyState === "complete") {
|
|
3205
|
+
trackCurrentPath();
|
|
3206
|
+
} else {
|
|
3207
|
+
window.addEventListener("load", trackCurrentPath, { once: true });
|
|
3208
|
+
}
|
|
3209
|
+
}
|
|
3210
|
+
const isProduction = (() => {
|
|
3211
|
+
try {
|
|
3212
|
+
const hostname = location.hostname;
|
|
3213
|
+
return hostname !== "localhost" && hostname !== "127.0.0.1" && !hostname.endsWith(".local");
|
|
3214
|
+
} catch {
|
|
3215
|
+
return true;
|
|
3216
|
+
}
|
|
3217
|
+
})();
|
|
3218
|
+
const warnedReasons = /* @__PURE__ */ new Set();
|
|
3219
|
+
function devWarn(name, reason) {
|
|
3220
|
+
if (isProduction) return;
|
|
3221
|
+
if (warnedReasons.has(reason)) return;
|
|
3222
|
+
warnedReasons.add(reason);
|
|
3223
|
+
console.warn(`[01 analytics] dropped event ${name}: ${reason}`);
|
|
3224
|
+
}
|
|
3225
|
+
const EVENT_NAME_RE = /^[a-zA-Z][a-zA-Z0-9_:-]{0,49}$/;
|
|
3226
|
+
const RESERVED_PREFIXES = ["__", "_pv_"];
|
|
3227
|
+
function validateEventName(name) {
|
|
3228
|
+
if (!name || typeof name !== "string") return "name-empty";
|
|
3229
|
+
for (const prefix of RESERVED_PREFIXES) {
|
|
3230
|
+
if (name.startsWith(prefix)) return "name-reserved";
|
|
3231
|
+
}
|
|
3232
|
+
if (!EVENT_NAME_RE.test(name)) return "name-regex";
|
|
3233
|
+
return null;
|
|
3234
|
+
}
|
|
3235
|
+
const PROP_KEY_RE = /^[a-zA-Z_][a-zA-Z0-9_]{0,31}$/;
|
|
3236
|
+
function validateEventProps(props) {
|
|
3237
|
+
if (props === void 0 || props === null) return null;
|
|
3238
|
+
if (typeof props !== "object" || Array.isArray(props)) return "props-value-type";
|
|
3239
|
+
const keys = Object.keys(props);
|
|
3240
|
+
if (keys.length > 10) return "props-too-many-keys";
|
|
3241
|
+
for (const k of keys) {
|
|
3242
|
+
const v = props[k];
|
|
3243
|
+
if (!PROP_KEY_RE.test(k)) return "props-key-regex";
|
|
3244
|
+
if (typeof v === "string") {
|
|
3245
|
+
if (v.length > 80) return "props-value-too-long";
|
|
3246
|
+
} else if (typeof v === "number") {
|
|
3247
|
+
if (!isFinite(v)) return "props-value-not-finite";
|
|
3248
|
+
} else if (typeof v === "boolean") {
|
|
3249
|
+
} else {
|
|
3250
|
+
return "props-value-type";
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
return null;
|
|
3254
|
+
}
|
|
3255
|
+
return {
|
|
3256
|
+
pageview(path) {
|
|
3257
|
+
if (destroyed) return;
|
|
3258
|
+
sendPageview(path ?? location.pathname);
|
|
3259
|
+
},
|
|
3260
|
+
track(name, props) {
|
|
3261
|
+
if (destroyed) return;
|
|
3262
|
+
if (isDntActive()) return;
|
|
3263
|
+
const doc = document;
|
|
3264
|
+
if (doc.prerendering === true || document.visibilityState === "prerender") return;
|
|
3265
|
+
const nameErr = validateEventName(name);
|
|
3266
|
+
if (nameErr) {
|
|
3267
|
+
devWarn(name, nameErr);
|
|
3268
|
+
return;
|
|
3269
|
+
}
|
|
3270
|
+
if (props !== void 0) {
|
|
3271
|
+
const propsErr = validateEventProps(props);
|
|
3272
|
+
if (propsErr) {
|
|
3273
|
+
devWarn(name, propsErr);
|
|
3274
|
+
return;
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
const body = JSON.stringify({
|
|
3278
|
+
publishableKey: config.publishableKey,
|
|
3279
|
+
pathname: location.pathname,
|
|
3280
|
+
referrer: document.referrer || "",
|
|
3281
|
+
eventId: newEventId(),
|
|
3282
|
+
eventName: name,
|
|
3283
|
+
eventProps: props
|
|
3284
|
+
});
|
|
3285
|
+
sendBeaconOrFetch(body);
|
|
3286
|
+
},
|
|
3287
|
+
destroy() {
|
|
3288
|
+
if (destroyed) return;
|
|
3289
|
+
destroyed = true;
|
|
3290
|
+
if (autoTrack) {
|
|
3291
|
+
history.pushState = originalPushState;
|
|
3292
|
+
history.replaceState = originalReplaceState;
|
|
3293
|
+
window.removeEventListener("popstate", trackCurrentPath);
|
|
3294
|
+
}
|
|
3295
|
+
lastPath = null;
|
|
3296
|
+
lastAt = 0;
|
|
3297
|
+
}
|
|
3298
|
+
};
|
|
3299
|
+
}
|
|
2839
3300
|
//# sourceMappingURL=index.cjs.map
|