@01.software/sdk 0.46.1 → 0.49.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/CHANGELOG.md +96 -1
- package/README.md +145 -14
- package/dist/client.cjs +485 -81
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +7 -6
- package/dist/client.d.ts +7 -6
- package/dist/client.js +485 -81
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-BEGXnfQe.d.ts → collection-client-DnDt6EQz.d.ts} +4 -4
- package/dist/{collection-client-L2rEgBaR.d.cts → collection-client-XfGLPuTf.d.cts} +4 -4
- package/dist/{const-y0eipvnQ.d.cts → const-CBba4lDo.d.cts} +4 -4
- package/dist/{const-GYVwlXLr.d.ts → const-DCNV5Kq7.d.ts} +4 -4
- package/dist/errors.cjs +112 -16
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +13 -4
- package/dist/errors.d.ts +13 -4
- package/dist/errors.js +112 -16
- package/dist/errors.js.map +1 -1
- package/dist/{index-BfYL6Qb1.d.cts → index-CbKyoEzy.d.cts} +3 -3
- package/dist/{index-Bei4WlVw.d.ts → index-DUuIqUS8.d.ts} +3 -3
- package/dist/index.cjs +452 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +452 -104
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-3WNyC0gk.d.cts → payload-types-MKbx5MuJ.d.cts} +309 -17
- package/dist/{payload-types-3WNyC0gk.d.ts → payload-types-MKbx5MuJ.d.ts} +309 -17
- package/dist/query.cjs +165 -43
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- package/dist/query.js +165 -43
- package/dist/query.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/server.cjs +566 -81
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +8 -7
- package/dist/server.d.ts +8 -7
- package/dist/server.js +566 -81
- package/dist/server.js.map +1 -1
- package/dist/storefront-cache.cjs +70 -1
- package/dist/storefront-cache.cjs.map +1 -1
- package/dist/storefront-cache.js +70 -1
- package/dist/storefront-cache.js.map +1 -1
- package/dist/{types-mIROvhhP.d.ts → types-1UeOk1Uy.d.cts} +110 -8
- package/dist/{types-CAicTn-o.d.cts → types-BKr_2avj.d.cts} +2 -2
- package/dist/{types-CDJ2M-MJ.d.cts → types-Du4s5anw.d.ts} +110 -8
- package/dist/{types-DpSyNTxy.d.ts → types-L_nh-ED7.d.ts} +2 -2
- 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.cts +4 -4
- package/dist/webhook.d.ts +4 -4
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -89,6 +89,7 @@ __export(src_exports, {
|
|
|
89
89
|
getImageSrcSet: () => getImageSrcSet,
|
|
90
90
|
getImageUrl: () => getImageUrl,
|
|
91
91
|
getProductSelectionImages: () => getProductSelectionImages,
|
|
92
|
+
getSDKErrorReason: () => getSDKErrorReason,
|
|
92
93
|
getSelectedValueByOptionId: () => getSelectedValueByOptionId,
|
|
93
94
|
getVariantAvailableForSale: () => getVariantAvailableForSale,
|
|
94
95
|
getVariantAvailableStock: () => getVariantAvailableStock,
|
|
@@ -147,6 +148,24 @@ module.exports = __toCommonJS(src_exports);
|
|
|
147
148
|
var import_qs_esm = require("qs-esm");
|
|
148
149
|
|
|
149
150
|
// src/core/errors.ts
|
|
151
|
+
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
152
|
+
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
153
|
+
function defineSDKErrorBrand(error) {
|
|
154
|
+
Object.defineProperty(error, SDK_ERROR_BRAND, {
|
|
155
|
+
value: true,
|
|
156
|
+
enumerable: false,
|
|
157
|
+
configurable: false,
|
|
158
|
+
writable: false
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function defineSDKErrorType(error, type) {
|
|
162
|
+
Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
|
|
163
|
+
value: type,
|
|
164
|
+
enumerable: false,
|
|
165
|
+
configurable: false,
|
|
166
|
+
writable: false
|
|
167
|
+
});
|
|
168
|
+
}
|
|
150
169
|
var SDKError = class extends Error {
|
|
151
170
|
constructor(code, message, status, details, userMessage, suggestion, requestId) {
|
|
152
171
|
super(message);
|
|
@@ -157,6 +176,7 @@ var SDKError = class extends Error {
|
|
|
157
176
|
this.userMessage = userMessage;
|
|
158
177
|
this.suggestion = suggestion;
|
|
159
178
|
this.requestId = requestId;
|
|
179
|
+
defineSDKErrorBrand(this);
|
|
160
180
|
if (Error.captureStackTrace) {
|
|
161
181
|
Error.captureStackTrace(this, new.target);
|
|
162
182
|
}
|
|
@@ -177,6 +197,7 @@ var SDKError = class extends Error {
|
|
|
177
197
|
...this.kind !== void 0 && { kind: this.kind },
|
|
178
198
|
...this.reason !== void 0 && { reason: this.reason },
|
|
179
199
|
...this.rawReason !== void 0 && { rawReason: this.rawReason },
|
|
200
|
+
...this.apiReason !== void 0 && { apiReason: this.apiReason },
|
|
180
201
|
...this.retryable !== void 0 && { retryable: this.retryable },
|
|
181
202
|
...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
|
|
182
203
|
};
|
|
@@ -184,34 +205,78 @@ var SDKError = class extends Error {
|
|
|
184
205
|
};
|
|
185
206
|
var COMMERCE_ERROR_CODES = [
|
|
186
207
|
"validation_failed",
|
|
208
|
+
"bad_request",
|
|
187
209
|
"unauthorized",
|
|
188
210
|
"forbidden",
|
|
211
|
+
"account_suspended",
|
|
212
|
+
"key_invalid",
|
|
213
|
+
"pat_tenant_header_forbidden",
|
|
214
|
+
"tenant_mismatch",
|
|
215
|
+
"test_tenant_expired",
|
|
216
|
+
"token_invalid",
|
|
189
217
|
"token_expired",
|
|
190
218
|
"origin_not_allowed",
|
|
191
219
|
"server_credentials_required",
|
|
220
|
+
"role_denied",
|
|
221
|
+
"scope_denied",
|
|
222
|
+
"feature_disabled",
|
|
192
223
|
"not_found",
|
|
193
224
|
"conflict",
|
|
225
|
+
"locked",
|
|
194
226
|
"cart_revision_conflict",
|
|
195
227
|
"rate_limit_exceeded",
|
|
196
228
|
"usage_limit_exceeded",
|
|
197
229
|
"service_unavailable",
|
|
198
230
|
"idempotency_conflict",
|
|
199
231
|
"idempotency_in_progress",
|
|
232
|
+
"idempotency_key_required",
|
|
233
|
+
"invalid_idempotency_key",
|
|
200
234
|
"cart_not_active",
|
|
201
235
|
"cart_locked",
|
|
202
236
|
"cart_empty",
|
|
203
237
|
"cart_market_unavailable",
|
|
204
238
|
"cart_market_mismatch",
|
|
205
239
|
"checkout_not_open",
|
|
240
|
+
"checkout_already_open",
|
|
206
241
|
"payment_slot_held",
|
|
207
242
|
"reservation_expired",
|
|
208
243
|
"payment_session_not_cancelable",
|
|
244
|
+
"payment_session_conflict",
|
|
209
245
|
"provider_identity_mismatch",
|
|
246
|
+
"payment_method_unavailable",
|
|
210
247
|
"provider_unavailable",
|
|
211
248
|
"lock_timeout",
|
|
212
249
|
"price_changed",
|
|
213
250
|
"pricing_fact_in_use",
|
|
214
251
|
"insufficient_stock",
|
|
252
|
+
"reservation_conflict",
|
|
253
|
+
"stock_lock_unavailable",
|
|
254
|
+
"variant_not_found",
|
|
255
|
+
"variant_stock_write_failed",
|
|
256
|
+
"stock_invariant_violation",
|
|
257
|
+
"payment_confirmation_in_flight",
|
|
258
|
+
"checkout_reservation_release_requires_transaction",
|
|
259
|
+
"admission_metadata_invalid",
|
|
260
|
+
"admission_metadata_required",
|
|
261
|
+
"capacity_exceeded",
|
|
262
|
+
"occurrence_lock_unavailable",
|
|
263
|
+
"occurrence_not_open",
|
|
264
|
+
"admission_type_capacity_exceeded",
|
|
265
|
+
"admission_type_occurrence_mismatch",
|
|
266
|
+
"admission_hold_expired",
|
|
267
|
+
"admission_hold_checkout_item_conflict",
|
|
268
|
+
"admission_hold_checkout_conflict",
|
|
269
|
+
"admission_hold_quantity_mismatch",
|
|
270
|
+
"admission_hold_unbound",
|
|
271
|
+
"admission_hold_missing",
|
|
272
|
+
"admission_hold_checkout_item_missing",
|
|
273
|
+
"admission_hold_expiry_failed",
|
|
274
|
+
"admission_hold_expiry_requires_transaction",
|
|
275
|
+
"admission_hold_line_item_mismatch",
|
|
276
|
+
"admission_materialization_failed",
|
|
277
|
+
"variant_inactive",
|
|
278
|
+
"variant_product_mismatch",
|
|
279
|
+
"product_not_public",
|
|
215
280
|
"market_not_found",
|
|
216
281
|
"market_shipping_currency_unsupported",
|
|
217
282
|
"missing_market_rate",
|
|
@@ -236,7 +301,11 @@ var COMMERCE_ERROR_CODES = [
|
|
|
236
301
|
"discount_min_order_amount",
|
|
237
302
|
"discount_currency_scope_required",
|
|
238
303
|
"discount_allocation_method_unsupported",
|
|
239
|
-
"currency_mismatch"
|
|
304
|
+
"currency_mismatch",
|
|
305
|
+
"customer_token_required",
|
|
306
|
+
"market_required",
|
|
307
|
+
"server_derived",
|
|
308
|
+
"internal_error"
|
|
240
309
|
];
|
|
241
310
|
var COMMERCE_ERROR_CODE_SET = new Set(
|
|
242
311
|
COMMERCE_ERROR_CODES
|
|
@@ -262,6 +331,12 @@ function commerceProtocolError(issue, trustedRequestId) {
|
|
|
262
331
|
);
|
|
263
332
|
}
|
|
264
333
|
function parseCommerceErrorEnvelope(body, headerRequestId) {
|
|
334
|
+
if (headerRequestId === void 0) {
|
|
335
|
+
throw commerceProtocolError("missing_request_id_header");
|
|
336
|
+
}
|
|
337
|
+
if (headerRequestId.length === 0) {
|
|
338
|
+
throw commerceProtocolError("empty_request_id_header");
|
|
339
|
+
}
|
|
265
340
|
if (!isPlainRecord(body)) {
|
|
266
341
|
throw commerceProtocolError("expected_object", headerRequestId);
|
|
267
342
|
}
|
|
@@ -271,7 +346,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
|
|
|
271
346
|
if (typeof body.error !== "string" || body.error.length === 0 || typeof body.reason !== "string" || body.reason.length === 0 || typeof body.requestId !== "string" || body.requestId.length === 0 || body.retryable !== void 0 && typeof body.retryable !== "boolean" || body.details !== void 0 && !isPlainRecord(body.details)) {
|
|
272
347
|
throw commerceProtocolError("invalid_field", headerRequestId);
|
|
273
348
|
}
|
|
274
|
-
if (headerRequestId && headerRequestId !== body.requestId) {
|
|
349
|
+
if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
|
|
275
350
|
throw commerceProtocolError("request_id_mismatch", headerRequestId);
|
|
276
351
|
}
|
|
277
352
|
return {
|
|
@@ -296,8 +371,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
|
|
|
296
371
|
});
|
|
297
372
|
return error;
|
|
298
373
|
}
|
|
374
|
+
function enhanceNonCommerceError(error, reason) {
|
|
375
|
+
if (typeof reason === "string") Object.assign(error, { apiReason: reason });
|
|
376
|
+
return error;
|
|
377
|
+
}
|
|
378
|
+
function getSDKErrorReason(error) {
|
|
379
|
+
if (error.kind !== "commerce") return error.apiReason;
|
|
380
|
+
return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
|
|
381
|
+
}
|
|
299
382
|
function isCommerceSDKError(error) {
|
|
300
|
-
if (!(error
|
|
383
|
+
if (!isSDKError(error) || error.kind !== "commerce") return false;
|
|
301
384
|
if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
|
|
302
385
|
return false;
|
|
303
386
|
}
|
|
@@ -307,12 +390,14 @@ var NetworkError = class extends SDKError {
|
|
|
307
390
|
constructor(message, status, details, userMessage, suggestion) {
|
|
308
391
|
super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
|
|
309
392
|
this.name = "NetworkError";
|
|
393
|
+
defineSDKErrorType(this, "NetworkError");
|
|
310
394
|
}
|
|
311
395
|
};
|
|
312
396
|
var ValidationError = class extends SDKError {
|
|
313
397
|
constructor(message, details, userMessage, suggestion, status = 400) {
|
|
314
398
|
super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
|
|
315
399
|
this.name = "ValidationError";
|
|
400
|
+
defineSDKErrorType(this, "ValidationError");
|
|
316
401
|
}
|
|
317
402
|
};
|
|
318
403
|
var ApiError = class extends SDKError {
|
|
@@ -327,24 +412,28 @@ var ApiError = class extends SDKError {
|
|
|
327
412
|
requestId
|
|
328
413
|
);
|
|
329
414
|
this.name = "ApiError";
|
|
415
|
+
defineSDKErrorType(this, "ApiError");
|
|
330
416
|
}
|
|
331
417
|
};
|
|
332
418
|
var ConfigError = class extends SDKError {
|
|
333
419
|
constructor(message, details, userMessage, suggestion) {
|
|
334
420
|
super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
|
|
335
421
|
this.name = "ConfigError";
|
|
422
|
+
defineSDKErrorType(this, "ConfigError");
|
|
336
423
|
}
|
|
337
424
|
};
|
|
338
425
|
var TimeoutError = class extends SDKError {
|
|
339
426
|
constructor(message = "Request timed out.", details, userMessage, suggestion) {
|
|
340
427
|
super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
|
|
341
428
|
this.name = "TimeoutError";
|
|
429
|
+
defineSDKErrorType(this, "TimeoutError");
|
|
342
430
|
}
|
|
343
431
|
};
|
|
344
432
|
var GoneError = class extends SDKError {
|
|
345
433
|
constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
|
|
346
434
|
super("GONE_ERROR", message, 410, details, userMessage, suggestion);
|
|
347
435
|
this.name = "GoneError";
|
|
436
|
+
defineSDKErrorType(this, "GoneError");
|
|
348
437
|
}
|
|
349
438
|
};
|
|
350
439
|
var ServiceUnavailableError = class extends SDKError {
|
|
@@ -359,6 +448,7 @@ var ServiceUnavailableError = class extends SDKError {
|
|
|
359
448
|
);
|
|
360
449
|
this.name = "ServiceUnavailableError";
|
|
361
450
|
this.retryAfter = retryAfter;
|
|
451
|
+
defineSDKErrorType(this, "ServiceUnavailableError");
|
|
362
452
|
}
|
|
363
453
|
};
|
|
364
454
|
var UsageLimitError = class extends SDKError {
|
|
@@ -366,6 +456,7 @@ var UsageLimitError = class extends SDKError {
|
|
|
366
456
|
super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
|
|
367
457
|
this.name = "UsageLimitError";
|
|
368
458
|
this.usage = usage;
|
|
459
|
+
defineSDKErrorType(this, "UsageLimitError");
|
|
369
460
|
}
|
|
370
461
|
toJSON() {
|
|
371
462
|
return {
|
|
@@ -386,6 +477,7 @@ var AuthError = class extends SDKError {
|
|
|
386
477
|
requestId
|
|
387
478
|
);
|
|
388
479
|
this.name = "AuthError";
|
|
480
|
+
defineSDKErrorType(this, "AuthError");
|
|
389
481
|
}
|
|
390
482
|
};
|
|
391
483
|
var PermissionError = class extends SDKError {
|
|
@@ -400,6 +492,7 @@ var PermissionError = class extends SDKError {
|
|
|
400
492
|
requestId
|
|
401
493
|
);
|
|
402
494
|
this.name = "PermissionError";
|
|
495
|
+
defineSDKErrorType(this, "PermissionError");
|
|
403
496
|
}
|
|
404
497
|
};
|
|
405
498
|
var NotFoundError = class extends SDKError {
|
|
@@ -414,12 +507,14 @@ var NotFoundError = class extends SDKError {
|
|
|
414
507
|
requestId
|
|
415
508
|
);
|
|
416
509
|
this.name = "NotFoundError";
|
|
510
|
+
defineSDKErrorType(this, "NotFoundError");
|
|
417
511
|
}
|
|
418
512
|
};
|
|
419
513
|
var ConflictError = class extends SDKError {
|
|
420
514
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
421
515
|
super("conflict", message, 409, details, userMessage, suggestion, requestId);
|
|
422
516
|
this.name = "ConflictError";
|
|
517
|
+
defineSDKErrorType(this, "ConflictError");
|
|
423
518
|
}
|
|
424
519
|
};
|
|
425
520
|
var RateLimitError = class extends SDKError {
|
|
@@ -435,52 +530,63 @@ var RateLimitError = class extends SDKError {
|
|
|
435
530
|
);
|
|
436
531
|
this.name = "RateLimitError";
|
|
437
532
|
this.retryAfter = retryAfter;
|
|
533
|
+
defineSDKErrorType(this, "RateLimitError");
|
|
438
534
|
}
|
|
439
535
|
};
|
|
536
|
+
function hasBrandedSDKErrorShape(error) {
|
|
537
|
+
if (error === null || typeof error !== "object") return false;
|
|
538
|
+
const candidate = error;
|
|
539
|
+
return candidate[SDK_ERROR_BRAND] === true && typeof candidate.name === "string" && typeof candidate.code === "string" && typeof candidate.message === "string" && (candidate.status === void 0 || typeof candidate.status === "number") && (candidate.userMessage === void 0 || typeof candidate.userMessage === "string") && (candidate.suggestion === void 0 || typeof candidate.suggestion === "string") && (candidate.requestId === void 0 || typeof candidate.requestId === "string") && (candidate.kind === void 0 || candidate.kind === "commerce") && (candidate.reason === void 0 || typeof candidate.reason === "string") && (candidate.rawReason === void 0 || typeof candidate.rawReason === "string") && (candidate.apiReason === void 0 || typeof candidate.apiReason === "string") && (candidate.retryable === void 0 || typeof candidate.retryable === "boolean") && (candidate.retryAfter === void 0 || typeof candidate.retryAfter === "number") && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
540
|
+
}
|
|
541
|
+
function hasSDKErrorType(error, type) {
|
|
542
|
+
return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
|
|
543
|
+
}
|
|
440
544
|
function isSDKError(error) {
|
|
441
|
-
return error instanceof SDKError;
|
|
545
|
+
return error instanceof SDKError || hasBrandedSDKErrorShape(error);
|
|
442
546
|
}
|
|
443
547
|
function isNetworkError(error) {
|
|
444
|
-
return error instanceof NetworkError;
|
|
548
|
+
return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
|
|
445
549
|
}
|
|
446
550
|
function isValidationError(error) {
|
|
447
|
-
if (error instanceof ValidationError)
|
|
551
|
+
if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
|
|
552
|
+
return true;
|
|
553
|
+
}
|
|
448
554
|
if (error == null || typeof error !== "object") return false;
|
|
449
555
|
const candidate = error;
|
|
450
556
|
return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
451
557
|
}
|
|
452
558
|
function isApiError(error) {
|
|
453
|
-
return error instanceof ApiError;
|
|
559
|
+
return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
|
|
454
560
|
}
|
|
455
561
|
function isConfigError(error) {
|
|
456
|
-
return error instanceof ConfigError;
|
|
562
|
+
return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
|
|
457
563
|
}
|
|
458
564
|
function isTimeoutError(error) {
|
|
459
|
-
return error instanceof TimeoutError;
|
|
565
|
+
return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
|
|
460
566
|
}
|
|
461
567
|
function isGoneError(error) {
|
|
462
|
-
return error instanceof GoneError;
|
|
568
|
+
return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
|
|
463
569
|
}
|
|
464
570
|
function isServiceUnavailableError(error) {
|
|
465
|
-
return error instanceof ServiceUnavailableError;
|
|
571
|
+
return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
|
|
466
572
|
}
|
|
467
573
|
function isUsageLimitError(error) {
|
|
468
|
-
return error instanceof UsageLimitError;
|
|
574
|
+
return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
|
|
469
575
|
}
|
|
470
576
|
function isAuthError(error) {
|
|
471
|
-
return error instanceof AuthError;
|
|
577
|
+
return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
|
|
472
578
|
}
|
|
473
579
|
function isPermissionError(error) {
|
|
474
|
-
return error instanceof PermissionError;
|
|
580
|
+
return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
|
|
475
581
|
}
|
|
476
582
|
function isNotFoundError(error) {
|
|
477
|
-
return error instanceof NotFoundError;
|
|
583
|
+
return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
|
|
478
584
|
}
|
|
479
585
|
function isConflictError(error) {
|
|
480
|
-
return error instanceof ConflictError;
|
|
586
|
+
return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
|
|
481
587
|
}
|
|
482
588
|
function isRateLimitError(error) {
|
|
483
|
-
return error instanceof RateLimitError;
|
|
589
|
+
return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
|
|
484
590
|
}
|
|
485
591
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
486
592
|
var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
|
|
@@ -691,7 +797,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
|
|
|
691
797
|
if (retryAfter !== void 0) {
|
|
692
798
|
Object.assign(withRequestId, { retryAfter });
|
|
693
799
|
}
|
|
694
|
-
return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
|
|
800
|
+
return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
|
|
695
801
|
};
|
|
696
802
|
if (status === 400 || status === 422) {
|
|
697
803
|
return finalize(
|
|
@@ -878,7 +984,7 @@ async function httpFetch(url, options) {
|
|
|
878
984
|
),
|
|
879
985
|
requestId
|
|
880
986
|
);
|
|
881
|
-
throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
|
|
987
|
+
throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
|
|
882
988
|
}
|
|
883
989
|
if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
|
|
884
990
|
hasRetried401 = true;
|
|
@@ -1300,7 +1406,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1300
1406
|
return parsed;
|
|
1301
1407
|
}
|
|
1302
1408
|
const data = parsed;
|
|
1303
|
-
|
|
1409
|
+
const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
|
|
1410
|
+
(key) => Object.prototype.hasOwnProperty.call(data, key)
|
|
1411
|
+
);
|
|
1412
|
+
if (data.error || hasCommerceEnvelopeSignal) {
|
|
1304
1413
|
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
1305
1414
|
const reason = typeof data.reason === "string" ? data.reason : void 0;
|
|
1306
1415
|
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
@@ -1329,19 +1438,21 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1329
1438
|
}
|
|
1330
1439
|
const withRequestId = attachRequestId(error, requestId);
|
|
1331
1440
|
if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
|
|
1332
|
-
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
|
|
1441
|
+
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
|
|
1333
1442
|
}
|
|
1334
1443
|
return data;
|
|
1335
1444
|
}
|
|
1336
1445
|
|
|
1337
1446
|
// ../../internal/http-contracts/src/index.ts
|
|
1338
1447
|
var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
|
|
1339
|
-
var operation = (collection, method, path) => Object.freeze({
|
|
1448
|
+
var operation = (collection, method, path, errorFamily) => Object.freeze({
|
|
1340
1449
|
[operationBrand]: true,
|
|
1341
1450
|
collection,
|
|
1342
1451
|
method,
|
|
1343
|
-
path
|
|
1452
|
+
path,
|
|
1453
|
+
...errorFamily && { errorFamily }
|
|
1344
1454
|
});
|
|
1455
|
+
var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
|
|
1345
1456
|
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
1346
1457
|
products: {
|
|
1347
1458
|
detail: operation("products", "get", "/detail"),
|
|
@@ -1374,13 +1485,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1374
1485
|
byPayment: operation("orders", "get", "/by-payment"),
|
|
1375
1486
|
cancel: operation("orders", "post", "/cancel"),
|
|
1376
1487
|
resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
|
|
1377
|
-
checkout:
|
|
1488
|
+
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
1378
1489
|
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
1379
1490
|
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
1380
1491
|
},
|
|
1381
1492
|
checkouts: {
|
|
1382
|
-
detail:
|
|
1383
|
-
query:
|
|
1493
|
+
detail: strictCommerceOperation("checkouts", "post", "/detail"),
|
|
1494
|
+
query: strictCommerceOperation("checkouts", "post", "/query")
|
|
1384
1495
|
},
|
|
1385
1496
|
transactions: {
|
|
1386
1497
|
update: operation("transactions", "post", "/update")
|
|
@@ -1401,29 +1512,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1401
1512
|
bulkImport: operation("fulfillments", "post", "/bulk-import")
|
|
1402
1513
|
},
|
|
1403
1514
|
carts: {
|
|
1404
|
-
create:
|
|
1405
|
-
retrieve:
|
|
1406
|
-
mine:
|
|
1407
|
-
merge:
|
|
1408
|
-
addItem:
|
|
1409
|
-
updateItem:
|
|
1410
|
-
removeItem:
|
|
1411
|
-
updateDiscountCodes:
|
|
1412
|
-
|
|
1413
|
-
|
|
1515
|
+
create: strictCommerceOperation("carts", "post", "/create"),
|
|
1516
|
+
retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
|
|
1517
|
+
mine: strictCommerceOperation("carts", "post", "/mine"),
|
|
1518
|
+
merge: strictCommerceOperation("carts", "post", "/merge"),
|
|
1519
|
+
addItem: strictCommerceOperation("carts", "post", "/add-item"),
|
|
1520
|
+
updateItem: strictCommerceOperation("carts", "post", "/update-item"),
|
|
1521
|
+
removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
|
|
1522
|
+
updateDiscountCodes: strictCommerceOperation(
|
|
1523
|
+
"carts",
|
|
1524
|
+
"post",
|
|
1525
|
+
"/update-discount-codes"
|
|
1526
|
+
),
|
|
1527
|
+
updateAttributes: strictCommerceOperation(
|
|
1528
|
+
"carts",
|
|
1529
|
+
"post",
|
|
1530
|
+
"/update-attributes"
|
|
1531
|
+
),
|
|
1532
|
+
clear: strictCommerceOperation("carts", "post", "/clear")
|
|
1414
1533
|
},
|
|
1415
1534
|
paymentSessions: {
|
|
1416
|
-
create:
|
|
1417
|
-
retrieve:
|
|
1418
|
-
cancel:
|
|
1535
|
+
create: strictCommerceOperation("payment-sessions", "post", "/create"),
|
|
1536
|
+
retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
|
|
1537
|
+
cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
|
|
1419
1538
|
server: {
|
|
1420
|
-
create:
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1539
|
+
create: strictCommerceOperation(
|
|
1540
|
+
"payment-sessions",
|
|
1541
|
+
"post",
|
|
1542
|
+
"/server/create"
|
|
1543
|
+
),
|
|
1544
|
+
retrieve: strictCommerceOperation(
|
|
1545
|
+
"payment-sessions",
|
|
1546
|
+
"post",
|
|
1547
|
+
"/server/retrieve"
|
|
1548
|
+
),
|
|
1549
|
+
cancel: strictCommerceOperation(
|
|
1550
|
+
"payment-sessions",
|
|
1551
|
+
"post",
|
|
1552
|
+
"/server/cancel"
|
|
1553
|
+
),
|
|
1554
|
+
confirm: strictCommerceOperation(
|
|
1555
|
+
"payment-sessions",
|
|
1556
|
+
"post",
|
|
1557
|
+
"/server/confirm"
|
|
1558
|
+
)
|
|
1424
1559
|
},
|
|
1425
1560
|
custom: {
|
|
1426
1561
|
create: operation("orders", "post", "/custom-payment-sessions"),
|
|
1562
|
+
retrieve: operation(
|
|
1563
|
+
"orders",
|
|
1564
|
+
"post",
|
|
1565
|
+
"/custom-payment-sessions/retrieve"
|
|
1566
|
+
),
|
|
1427
1567
|
confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
|
|
1428
1568
|
}
|
|
1429
1569
|
},
|
|
@@ -1449,6 +1589,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
|
|
|
1449
1589
|
)
|
|
1450
1590
|
}
|
|
1451
1591
|
};
|
|
1592
|
+
var COMMUNITY_ENDPOINT_OPERATIONS = {
|
|
1593
|
+
posts: {
|
|
1594
|
+
detail: operation("posts", "get", "/detail")
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1452
1597
|
function resolveOperationTemplate(descriptor) {
|
|
1453
1598
|
return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
|
|
1454
1599
|
}
|
|
@@ -1480,6 +1625,9 @@ var sharedEndpoint = (descriptor) => descriptor;
|
|
|
1480
1625
|
function resolveOperationMethod2(descriptor) {
|
|
1481
1626
|
return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
|
|
1482
1627
|
}
|
|
1628
|
+
function resolveOperationErrorFamily(descriptor) {
|
|
1629
|
+
return "collection" in descriptor ? descriptor.errorFamily : void 0;
|
|
1630
|
+
}
|
|
1483
1631
|
function resolveOperationPath2(descriptor, options) {
|
|
1484
1632
|
if ("collection" in descriptor) {
|
|
1485
1633
|
return resolveOperationPath(descriptor, options);
|
|
@@ -1514,12 +1662,12 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1514
1662
|
updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
|
|
1515
1663
|
},
|
|
1516
1664
|
checkouts: {
|
|
1517
|
-
create:
|
|
1518
|
-
retrieve:
|
|
1665
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1666
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1519
1667
|
server: {
|
|
1520
|
-
create:
|
|
1521
|
-
retrieve:
|
|
1522
|
-
query:
|
|
1668
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1669
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1670
|
+
query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
|
|
1523
1671
|
}
|
|
1524
1672
|
},
|
|
1525
1673
|
returns: {
|
|
@@ -1537,10 +1685,10 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1537
1685
|
bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
|
|
1538
1686
|
},
|
|
1539
1687
|
carts: {
|
|
1540
|
-
create:
|
|
1688
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
|
|
1541
1689
|
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
|
|
1542
|
-
mine:
|
|
1543
|
-
merge:
|
|
1690
|
+
mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
|
|
1691
|
+
merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
|
|
1544
1692
|
server: {
|
|
1545
1693
|
// Server credentials are an authorization lane, not a second Cart
|
|
1546
1694
|
// transport. These must stay bound to the registered shared operations.
|
|
@@ -1560,29 +1708,46 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1560
1708
|
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1561
1709
|
},
|
|
1562
1710
|
addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
|
|
1563
|
-
updateItem:
|
|
1564
|
-
removeItem:
|
|
1565
|
-
updateDiscountCodes:
|
|
1566
|
-
|
|
1567
|
-
|
|
1711
|
+
updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
|
|
1712
|
+
removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
|
|
1713
|
+
updateDiscountCodes: sharedEndpoint(
|
|
1714
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
|
|
1715
|
+
),
|
|
1716
|
+
updateAttributes: sharedEndpoint(
|
|
1717
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
|
|
1718
|
+
),
|
|
1719
|
+
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1568
1720
|
},
|
|
1569
1721
|
paymentSessions: {
|
|
1570
|
-
create:
|
|
1571
|
-
retrieve:
|
|
1572
|
-
|
|
1722
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
|
|
1723
|
+
retrieve: sharedEndpoint(
|
|
1724
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
|
|
1725
|
+
),
|
|
1726
|
+
cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
|
|
1573
1727
|
custom: {
|
|
1574
1728
|
create: sharedEndpoint(
|
|
1575
1729
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
|
|
1576
1730
|
),
|
|
1731
|
+
retrieve: sharedEndpoint(
|
|
1732
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
|
|
1733
|
+
),
|
|
1577
1734
|
confirm: sharedEndpoint(
|
|
1578
1735
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
|
|
1579
1736
|
)
|
|
1580
1737
|
},
|
|
1581
1738
|
server: {
|
|
1582
|
-
create:
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1739
|
+
create: sharedEndpoint(
|
|
1740
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
|
|
1741
|
+
),
|
|
1742
|
+
retrieve: sharedEndpoint(
|
|
1743
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
1744
|
+
),
|
|
1745
|
+
cancel: sharedEndpoint(
|
|
1746
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
|
|
1747
|
+
),
|
|
1748
|
+
confirm: sharedEndpoint(
|
|
1749
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
|
|
1750
|
+
)
|
|
1586
1751
|
}
|
|
1587
1752
|
},
|
|
1588
1753
|
shippingPolicies: {
|
|
@@ -1673,7 +1838,8 @@ var CustomerScopedApi = class {
|
|
|
1673
1838
|
return this.transport.request(resolveOperationPath2(endpoint2, options), {
|
|
1674
1839
|
method: resolveOperationMethod2(endpoint2),
|
|
1675
1840
|
body,
|
|
1676
|
-
headers: options?.headers
|
|
1841
|
+
headers: options?.headers,
|
|
1842
|
+
errorFamily: resolveOperationErrorFamily(endpoint2)
|
|
1677
1843
|
});
|
|
1678
1844
|
}
|
|
1679
1845
|
};
|
|
@@ -1695,15 +1861,33 @@ function unwrapPayloadDoc(value) {
|
|
|
1695
1861
|
}
|
|
1696
1862
|
return value;
|
|
1697
1863
|
}
|
|
1864
|
+
function hasCanonicalNotFoundReason(error) {
|
|
1865
|
+
return getSDKErrorReason(error) === "not_found";
|
|
1866
|
+
}
|
|
1698
1867
|
var CommunityClient = class extends RawCustomerScopedApi {
|
|
1699
1868
|
constructor(options) {
|
|
1700
1869
|
super("CommunityClient", { ...options, requiresCredential: false });
|
|
1870
|
+
this.requiresSafePublicRawReads = !options.secretKey;
|
|
1701
1871
|
}
|
|
1702
1872
|
buildQuery(params) {
|
|
1703
1873
|
if (!params) return "";
|
|
1704
1874
|
const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
|
|
1705
1875
|
return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
|
|
1706
1876
|
}
|
|
1877
|
+
withSafePublicRawReadQuery(query) {
|
|
1878
|
+
if (!this.requiresSafePublicRawReads) return query;
|
|
1879
|
+
if (!query) return "?depth=0&joins=false";
|
|
1880
|
+
return `?depth=0&joins=false&${query.slice(1)}`;
|
|
1881
|
+
}
|
|
1882
|
+
buildSafePublicRawListQuery(params) {
|
|
1883
|
+
if (!this.requiresSafePublicRawReads) {
|
|
1884
|
+
return this.buildQuery(params);
|
|
1885
|
+
}
|
|
1886
|
+
const queryParams = {};
|
|
1887
|
+
if (params?.page !== void 0) queryParams.page = params.page;
|
|
1888
|
+
if (params?.limit !== void 0) queryParams.limit = params.limit;
|
|
1889
|
+
return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
|
|
1890
|
+
}
|
|
1707
1891
|
buildPostsListQuery(params) {
|
|
1708
1892
|
const urlParams = new URLSearchParams();
|
|
1709
1893
|
const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
|
|
@@ -1763,15 +1947,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1763
1947
|
"GET"
|
|
1764
1948
|
);
|
|
1765
1949
|
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Public post detail projected by the same allowlist as the public feed.
|
|
1952
|
+
* Missing, hidden, and cross-tenant posts all resolve to `null`.
|
|
1953
|
+
*/
|
|
1954
|
+
async getPost(params) {
|
|
1955
|
+
const query = new URLSearchParams({ postId: params.postId });
|
|
1956
|
+
try {
|
|
1957
|
+
return await this.execute(
|
|
1958
|
+
resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
|
|
1959
|
+
query
|
|
1960
|
+
}),
|
|
1961
|
+
resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
|
|
1962
|
+
);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
|
|
1965
|
+
return null;
|
|
1966
|
+
}
|
|
1967
|
+
throw error;
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1766
1970
|
listPostCategories(params) {
|
|
1767
1971
|
return this.execute(
|
|
1768
|
-
`/api/post-categories${this.
|
|
1972
|
+
`/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
|
|
1769
1973
|
"GET"
|
|
1770
1974
|
);
|
|
1771
1975
|
}
|
|
1772
1976
|
listPostTags(params) {
|
|
1773
1977
|
return this.execute(
|
|
1774
|
-
`/api/post-tags${this.
|
|
1978
|
+
`/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
|
|
1775
1979
|
"GET"
|
|
1776
1980
|
);
|
|
1777
1981
|
}
|
|
@@ -1937,7 +2141,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1937
2141
|
}
|
|
1938
2142
|
getReactionTypes() {
|
|
1939
2143
|
return this.execute(
|
|
1940
|
-
|
|
2144
|
+
`/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
|
|
1941
2145
|
"GET"
|
|
1942
2146
|
);
|
|
1943
2147
|
}
|
|
@@ -1965,11 +2169,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1965
2169
|
}
|
|
1966
2170
|
// Profiles
|
|
1967
2171
|
listProfileLists(params) {
|
|
1968
|
-
return this.execute(
|
|
2172
|
+
return this.execute(
|
|
2173
|
+
`/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
|
|
2174
|
+
"GET"
|
|
2175
|
+
);
|
|
1969
2176
|
}
|
|
1970
2177
|
async getProfileList(params) {
|
|
1971
2178
|
const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
|
|
1972
|
-
const res = await this.execute(
|
|
2179
|
+
const res = await this.execute(
|
|
2180
|
+
`/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
|
|
2181
|
+
"GET"
|
|
2182
|
+
);
|
|
1973
2183
|
return res.docs[0] ?? null;
|
|
1974
2184
|
}
|
|
1975
2185
|
updatePublicProfile(body) {
|
|
@@ -2082,7 +2292,7 @@ var ORDER_PRIMARY_DISPLAY_STATUSES = [
|
|
|
2082
2292
|
];
|
|
2083
2293
|
var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
|
|
2084
2294
|
var ABANDONED_REASONS = ["expired", "customer", "operator"];
|
|
2085
|
-
var PAYMENT_PROVIDERS = ["toss"];
|
|
2295
|
+
var PAYMENT_PROVIDERS = ["toss", "portone"];
|
|
2086
2296
|
var PAYMENT_PROVIDER_STATUSES = [
|
|
2087
2297
|
"requires_payment_method",
|
|
2088
2298
|
"requires_action",
|
|
@@ -3255,8 +3465,101 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
|
|
|
3255
3465
|
previous = current;
|
|
3256
3466
|
});
|
|
3257
3467
|
}
|
|
3258
|
-
function validateNextAction(value, resource, path) {
|
|
3468
|
+
function validateNextAction(value, provider, resource, path) {
|
|
3259
3469
|
const action = record(value, resource, path);
|
|
3470
|
+
if (provider === "portone") {
|
|
3471
|
+
if (action.type === "portone_sdk") {
|
|
3472
|
+
exact(
|
|
3473
|
+
action,
|
|
3474
|
+
[
|
|
3475
|
+
"type",
|
|
3476
|
+
"version",
|
|
3477
|
+
"storeId",
|
|
3478
|
+
"channelKey",
|
|
3479
|
+
"paymentId",
|
|
3480
|
+
"orderName",
|
|
3481
|
+
"totalAmount",
|
|
3482
|
+
"currency",
|
|
3483
|
+
"payMethod",
|
|
3484
|
+
"redirectUrl"
|
|
3485
|
+
],
|
|
3486
|
+
[],
|
|
3487
|
+
resource,
|
|
3488
|
+
path
|
|
3489
|
+
);
|
|
3490
|
+
if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
|
|
3491
|
+
for (const key of ["storeId", "channelKey"]) {
|
|
3492
|
+
boundedString(action[key], 255, resource, `${path}.${key}`);
|
|
3493
|
+
}
|
|
3494
|
+
const paymentId = boundedString(
|
|
3495
|
+
action.paymentId,
|
|
3496
|
+
40,
|
|
3497
|
+
resource,
|
|
3498
|
+
`${path}.paymentId`
|
|
3499
|
+
);
|
|
3500
|
+
if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
|
|
3501
|
+
fail(
|
|
3502
|
+
resource,
|
|
3503
|
+
`${path}.paymentId`,
|
|
3504
|
+
"6-40 ASCII alphanumeric characters"
|
|
3505
|
+
);
|
|
3506
|
+
}
|
|
3507
|
+
boundedString(
|
|
3508
|
+
action.orderName,
|
|
3509
|
+
MAX_COMMERCE_SHORT_TEXT_LENGTH,
|
|
3510
|
+
resource,
|
|
3511
|
+
`${path}.orderName`
|
|
3512
|
+
);
|
|
3513
|
+
positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
|
|
3514
|
+
if (action.currency !== "CURRENCY_KRW") {
|
|
3515
|
+
fail(resource, `${path}.currency`, "CURRENCY_KRW");
|
|
3516
|
+
}
|
|
3517
|
+
if (action.payMethod !== "CARD")
|
|
3518
|
+
fail(resource, `${path}.payMethod`, "CARD");
|
|
3519
|
+
const redirectUrl = boundedString(
|
|
3520
|
+
action.redirectUrl,
|
|
3521
|
+
2048,
|
|
3522
|
+
resource,
|
|
3523
|
+
`${path}.redirectUrl`
|
|
3524
|
+
);
|
|
3525
|
+
try {
|
|
3526
|
+
const parsed = new URL(redirectUrl);
|
|
3527
|
+
const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
|
|
3528
|
+
if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
|
|
3529
|
+
throw new Error("unsafe redirect URL");
|
|
3530
|
+
} catch {
|
|
3531
|
+
fail(
|
|
3532
|
+
resource,
|
|
3533
|
+
`${path}.redirectUrl`,
|
|
3534
|
+
"HTTPS or loopback URL without embedded credentials"
|
|
3535
|
+
);
|
|
3536
|
+
}
|
|
3537
|
+
return;
|
|
3538
|
+
}
|
|
3539
|
+
exact(action, ["type", "checkoutUrl"], [], resource, path);
|
|
3540
|
+
if (action.type !== "portone_checkout") {
|
|
3541
|
+
fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
|
|
3542
|
+
}
|
|
3543
|
+
const checkoutUrl = boundedString(
|
|
3544
|
+
action.checkoutUrl,
|
|
3545
|
+
2048,
|
|
3546
|
+
resource,
|
|
3547
|
+
`${path}.checkoutUrl`
|
|
3548
|
+
);
|
|
3549
|
+
try {
|
|
3550
|
+
const parsed = new URL(checkoutUrl);
|
|
3551
|
+
if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
|
|
3552
|
+
throw new Error("unsafe checkout URL");
|
|
3553
|
+
}
|
|
3554
|
+
} catch {
|
|
3555
|
+
fail(
|
|
3556
|
+
resource,
|
|
3557
|
+
`${path}.checkoutUrl`,
|
|
3558
|
+
"absolute HTTPS URL without embedded credentials"
|
|
3559
|
+
);
|
|
3560
|
+
}
|
|
3561
|
+
return;
|
|
3562
|
+
}
|
|
3260
3563
|
exact(
|
|
3261
3564
|
action,
|
|
3262
3565
|
[
|
|
@@ -3307,10 +3610,18 @@ function validateNextAction(value, resource, path) {
|
|
|
3307
3610
|
if (action.customerEmail !== void 0)
|
|
3308
3611
|
validateCustomer({ email: action.customerEmail }, resource, path);
|
|
3309
3612
|
}
|
|
3310
|
-
function validatePublicPaymentSession(value) {
|
|
3613
|
+
function validatePublicPaymentSession(value, expectedProvider) {
|
|
3311
3614
|
const resource = "PaymentSession";
|
|
3312
3615
|
const session = record(value, resource, "$");
|
|
3313
|
-
|
|
3616
|
+
const provider = enumValue(
|
|
3617
|
+
session.provider,
|
|
3618
|
+
PAYMENT_PROVIDERS,
|
|
3619
|
+
resource,
|
|
3620
|
+
"$.provider"
|
|
3621
|
+
);
|
|
3622
|
+
if (expectedProvider !== void 0 && provider !== expectedProvider) {
|
|
3623
|
+
fail(resource, "$.provider", expectedProvider);
|
|
3624
|
+
}
|
|
3314
3625
|
const status = enumValue(
|
|
3315
3626
|
session.providerStatus,
|
|
3316
3627
|
PAYMENT_PROVIDER_STATUSES,
|
|
@@ -3347,7 +3658,12 @@ function validatePublicPaymentSession(value) {
|
|
|
3347
3658
|
}
|
|
3348
3659
|
if (!("nextAction" in session))
|
|
3349
3660
|
fail(resource, "$.nextAction", "required field");
|
|
3350
|
-
validateNextAction(
|
|
3661
|
+
validateNextAction(
|
|
3662
|
+
session.nextAction,
|
|
3663
|
+
provider,
|
|
3664
|
+
resource,
|
|
3665
|
+
"$.nextAction"
|
|
3666
|
+
);
|
|
3351
3667
|
} else if (session.sessionRole === "residual") {
|
|
3352
3668
|
if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
|
|
3353
3669
|
fail(resource, "$", "suppressed residual not-ready state");
|
|
@@ -4090,8 +4406,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
4090
4406
|
}
|
|
4091
4407
|
});
|
|
4092
4408
|
}
|
|
4093
|
-
async paymentSession(result) {
|
|
4094
|
-
return validatePublicPaymentSession(await result);
|
|
4409
|
+
async paymentSession(result, expectedProvider) {
|
|
4410
|
+
return validatePublicPaymentSession(await result, expectedProvider);
|
|
4095
4411
|
}
|
|
4096
4412
|
create(params) {
|
|
4097
4413
|
const { idempotencyKey, ...body } = params;
|
|
@@ -4101,18 +4417,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
4101
4417
|
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
4102
4418
|
body,
|
|
4103
4419
|
idempotencyKey
|
|
4104
|
-
)
|
|
4420
|
+
),
|
|
4421
|
+
"toss"
|
|
4422
|
+
);
|
|
4423
|
+
}
|
|
4424
|
+
createPortOne(params) {
|
|
4425
|
+
const { idempotencyKey, ...body } = params;
|
|
4426
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4427
|
+
return this.paymentSession(
|
|
4428
|
+
this.post(
|
|
4429
|
+
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
4430
|
+
body,
|
|
4431
|
+
idempotencyKey
|
|
4432
|
+
),
|
|
4433
|
+
"portone"
|
|
4105
4434
|
);
|
|
4106
4435
|
}
|
|
4107
4436
|
retrieve(params) {
|
|
4108
4437
|
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
4109
|
-
return this.paymentSession(
|
|
4438
|
+
return this.paymentSession(
|
|
4439
|
+
this.post(endpoint2, params),
|
|
4440
|
+
"toss"
|
|
4441
|
+
);
|
|
4442
|
+
}
|
|
4443
|
+
retrievePortOne(params) {
|
|
4444
|
+
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
4445
|
+
return this.paymentSession(
|
|
4446
|
+
this.post(endpoint2, params),
|
|
4447
|
+
"portone"
|
|
4448
|
+
);
|
|
4110
4449
|
}
|
|
4111
4450
|
cancel(params) {
|
|
4112
4451
|
const { idempotencyKey, ...body } = params;
|
|
4113
4452
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4114
4453
|
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
4115
|
-
return this.paymentSession(
|
|
4454
|
+
return this.paymentSession(
|
|
4455
|
+
this.post(endpoint2, body, idempotencyKey),
|
|
4456
|
+
"toss"
|
|
4457
|
+
);
|
|
4458
|
+
}
|
|
4459
|
+
cancelPortOne(params) {
|
|
4460
|
+
const { idempotencyKey, ...body } = params;
|
|
4461
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4462
|
+
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
4463
|
+
return this.paymentSession(
|
|
4464
|
+
this.post(endpoint2, body, idempotencyKey),
|
|
4465
|
+
"portone"
|
|
4466
|
+
);
|
|
4116
4467
|
}
|
|
4117
4468
|
confirm(params) {
|
|
4118
4469
|
const { idempotencyKey, ...body } = params;
|
|
@@ -4122,7 +4473,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
4122
4473
|
COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
|
|
4123
4474
|
body,
|
|
4124
4475
|
idempotencyKey
|
|
4125
|
-
)
|
|
4476
|
+
),
|
|
4477
|
+
"toss"
|
|
4126
4478
|
);
|
|
4127
4479
|
}
|
|
4128
4480
|
};
|
|
@@ -5861,21 +6213,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
|
|
|
5861
6213
|
"not_published",
|
|
5862
6214
|
"feature_disabled"
|
|
5863
6215
|
]);
|
|
5864
|
-
function isRecord(value) {
|
|
5865
|
-
return typeof value === "object" && value !== null;
|
|
5866
|
-
}
|
|
5867
|
-
function readProductDetailUnavailableReason(value) {
|
|
5868
|
-
if (!isRecord(value)) return void 0;
|
|
5869
|
-
const directReason = value.reason ?? value.code;
|
|
5870
|
-
if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
|
|
5871
|
-
return directReason;
|
|
5872
|
-
}
|
|
5873
|
-
return readProductDetailUnavailableReason(value.body);
|
|
5874
|
-
}
|
|
5875
6216
|
function productDetailResultFromError(error) {
|
|
5876
6217
|
if (!(error instanceof SDKError) || error.status !== 404) return void 0;
|
|
5877
|
-
const reason =
|
|
5878
|
-
if (!reason
|
|
6218
|
+
const reason = getSDKErrorReason(error);
|
|
6219
|
+
if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
|
|
6220
|
+
return void 0;
|
|
5879
6221
|
return { found: false, reason };
|
|
5880
6222
|
}
|
|
5881
6223
|
var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
|
|
@@ -6092,8 +6434,11 @@ var CommerceClient = class {
|
|
|
6092
6434
|
};
|
|
6093
6435
|
this.paymentSessions = {
|
|
6094
6436
|
create: paymentSessionApi.create.bind(paymentSessionApi),
|
|
6437
|
+
createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
|
|
6095
6438
|
retrieve: (params) => paymentSessionApi.retrieve(params),
|
|
6096
|
-
|
|
6439
|
+
retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
|
|
6440
|
+
cancel: (params) => paymentSessionApi.cancel(params),
|
|
6441
|
+
cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params)
|
|
6097
6442
|
};
|
|
6098
6443
|
this.discounts = {
|
|
6099
6444
|
validate: (params) => api.requestEndpoint(
|
|
@@ -6469,7 +6814,7 @@ function isStringOrNumber(value) {
|
|
|
6469
6814
|
return typeof value === "string" || typeof value === "number";
|
|
6470
6815
|
}
|
|
6471
6816
|
function isWebhookOrderScope(value) {
|
|
6472
|
-
if (!
|
|
6817
|
+
if (!isRecord(value)) return false;
|
|
6473
6818
|
if (value.kind === "collection") {
|
|
6474
6819
|
return typeof value.collection === "string";
|
|
6475
6820
|
}
|
|
@@ -6479,14 +6824,14 @@ function isWebhookOrderScope(value) {
|
|
|
6479
6824
|
return false;
|
|
6480
6825
|
}
|
|
6481
6826
|
function isWebhookOrderMoved(value) {
|
|
6482
|
-
if (!
|
|
6827
|
+
if (!isRecord(value)) return false;
|
|
6483
6828
|
return typeof value.collection === "string" && isStringOrNumber(value.id) && (value.relatedCollection === void 0 || typeof value.relatedCollection === "string") && (value.relatedId === void 0 || isStringOrNumber(value.relatedId));
|
|
6484
6829
|
}
|
|
6485
6830
|
function hasOptionalOrderValue(value, key) {
|
|
6486
6831
|
return value[key] === void 0 || value[key] === null || typeof value[key] === "string";
|
|
6487
6832
|
}
|
|
6488
6833
|
function isWebhookOrderChange(value) {
|
|
6489
|
-
if (!
|
|
6834
|
+
if (!isRecord(value)) return false;
|
|
6490
6835
|
return value.type === "order" && value.source === "payload-orderable" && (value.orderableFieldName === void 0 || typeof value.orderableFieldName === "string") && hasOptionalOrderValue(value, "previousOrder") && hasOptionalOrderValue(value, "nextOrder") && isWebhookOrderScope(value.scope) && isWebhookOrderMoved(value.moved);
|
|
6491
6836
|
}
|
|
6492
6837
|
function isCommerceNotificationEventName(value) {
|
|
@@ -6496,18 +6841,18 @@ function isCommerceNotificationSourceCollection(value) {
|
|
|
6496
6841
|
return value === "orders" || value === "fulfillments" || value === "returns";
|
|
6497
6842
|
}
|
|
6498
6843
|
function isCommerceNotificationData(value) {
|
|
6499
|
-
if (!
|
|
6500
|
-
if (value.source !== void 0 && (!
|
|
6844
|
+
if (!isRecord(value)) return false;
|
|
6845
|
+
if (value.source !== void 0 && (!isRecord(value.source) || !isCommerceNotificationSourceCollection(value.source.collection) || !isStringOrNumber(value.source.id))) {
|
|
6501
6846
|
return false;
|
|
6502
6847
|
}
|
|
6503
6848
|
return (value.orderId === void 0 || isStringOrNumber(value.orderId)) && (value.orderNumber === void 0 || typeof value.orderNumber === "string") && (value.status === void 0 || typeof value.status === "string") && (value.totalAmount === void 0 || typeof value.totalAmount === "number") && (value.currency === void 0 || typeof value.currency === "string") && (value.fulfillmentId === void 0 || isStringOrNumber(value.fulfillmentId)) && (value.fulfillmentStatus === void 0 || typeof value.fulfillmentStatus === "string") && (value.shippedAt === void 0 || typeof value.shippedAt === "string") && (value.returnId === void 0 || isStringOrNumber(value.returnId)) && (value.returnStatus === void 0 || typeof value.returnStatus === "string") && (value.refundAmount === void 0 || typeof value.refundAmount === "number") && (value.completedAt === void 0 || typeof value.completedAt === "string");
|
|
6504
6849
|
}
|
|
6505
6850
|
function isCommerceNotification(value) {
|
|
6506
|
-
if (!
|
|
6851
|
+
if (!isRecord(value)) return false;
|
|
6507
6852
|
return isCommerceNotificationEventName(value.event) && typeof value.intentId === "string" && value.intentId.length > 0 && typeof value.dedupeKey === "string" && value.dedupeKey.length > 0 && (value.orderId === void 0 || typeof value.orderId === "string") && (value.fulfillmentId === void 0 || typeof value.fulfillmentId === "string") && (value.returnId === void 0 || typeof value.returnId === "string");
|
|
6508
6853
|
}
|
|
6509
6854
|
function isWebhookCommerceNotificationChange(value) {
|
|
6510
|
-
if (!
|
|
6855
|
+
if (!isRecord(value)) return false;
|
|
6511
6856
|
return value.type === "notification" && value.source === "commerce-notifications" && isCommerceNotificationEventName(value.event) && isCommerceNotificationSourceCollection(value.sourceCollection) && isStringOrNumber(value.sourceId);
|
|
6512
6857
|
}
|
|
6513
6858
|
function matchesOptionalId(actual, expected) {
|
|
@@ -6589,7 +6934,7 @@ function isWebhookOperation(event, operation2) {
|
|
|
6589
6934
|
return isValidWebhookEvent(event) && event.operation === operation2;
|
|
6590
6935
|
}
|
|
6591
6936
|
var CUSTOMER_PASSWORD_RESET_OPERATION = "password-reset";
|
|
6592
|
-
function
|
|
6937
|
+
function isRecord(value) {
|
|
6593
6938
|
return typeof value === "object" && value !== null;
|
|
6594
6939
|
}
|
|
6595
6940
|
function hasString(value, key) {
|
|
@@ -6599,7 +6944,7 @@ function hasStringOrNumber(value, key) {
|
|
|
6599
6944
|
return typeof value[key] === "string" || typeof value[key] === "number";
|
|
6600
6945
|
}
|
|
6601
6946
|
function isCustomerPasswordResetWebhookEvent(event) {
|
|
6602
|
-
if (event.collection !== "customers" || event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION || !
|
|
6947
|
+
if (event.collection !== "customers" || event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION || !isRecord(event.data)) {
|
|
6603
6948
|
return false;
|
|
6604
6949
|
}
|
|
6605
6950
|
return hasStringOrNumber(event.data, "customerId") && hasString(event.data, "email") && hasString(event.data, "name") && hasString(event.data, "resetPasswordToken") && hasString(event.data, "resetPasswordExpiresAt");
|
|
@@ -6754,7 +7099,6 @@ var INTERNAL_COLLECTIONS = [
|
|
|
6754
7099
|
"payment-provider-customer-aliases"
|
|
6755
7100
|
];
|
|
6756
7101
|
var COLLECTIONS = [
|
|
6757
|
-
"tenants",
|
|
6758
7102
|
"tenant-metadata",
|
|
6759
7103
|
"products",
|
|
6760
7104
|
"product-variants",
|
|
@@ -6814,6 +7158,10 @@ var COLLECTIONS = [
|
|
|
6814
7158
|
"customer-memberships"
|
|
6815
7159
|
];
|
|
6816
7160
|
var SERVER_ONLY_COLLECTIONS = [
|
|
7161
|
+
// The tenant record itself denies reads without an authenticated user, so a
|
|
7162
|
+
// publishable key never reaches it; `tenant-metadata` is the browser-public
|
|
7163
|
+
// tenant identity surface.
|
|
7164
|
+
"tenants",
|
|
6817
7165
|
"tenant-logos",
|
|
6818
7166
|
"brand-logos",
|
|
6819
7167
|
"images",
|