@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/client.cjs
CHANGED
|
@@ -22,7 +22,22 @@ var client_exports = {};
|
|
|
22
22
|
__export(client_exports, {
|
|
23
23
|
Client: () => Client,
|
|
24
24
|
ContentClient: () => ContentClient,
|
|
25
|
-
createClient: () => createClient
|
|
25
|
+
createClient: () => createClient,
|
|
26
|
+
isApiError: () => isApiError,
|
|
27
|
+
isAuthError: () => isAuthError,
|
|
28
|
+
isCommerceSDKError: () => isCommerceSDKError,
|
|
29
|
+
isConfigError: () => isConfigError,
|
|
30
|
+
isConflictError: () => isConflictError,
|
|
31
|
+
isGoneError: () => isGoneError,
|
|
32
|
+
isNetworkError: () => isNetworkError,
|
|
33
|
+
isNotFoundError: () => isNotFoundError,
|
|
34
|
+
isPermissionError: () => isPermissionError,
|
|
35
|
+
isRateLimitError: () => isRateLimitError,
|
|
36
|
+
isSDKError: () => isSDKError,
|
|
37
|
+
isServiceUnavailableError: () => isServiceUnavailableError,
|
|
38
|
+
isTimeoutError: () => isTimeoutError,
|
|
39
|
+
isUsageLimitError: () => isUsageLimitError,
|
|
40
|
+
isValidationError: () => isValidationError
|
|
26
41
|
});
|
|
27
42
|
module.exports = __toCommonJS(client_exports);
|
|
28
43
|
|
|
@@ -30,6 +45,24 @@ module.exports = __toCommonJS(client_exports);
|
|
|
30
45
|
var import_qs_esm = require("qs-esm");
|
|
31
46
|
|
|
32
47
|
// src/core/errors.ts
|
|
48
|
+
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
49
|
+
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
50
|
+
function defineSDKErrorBrand(error) {
|
|
51
|
+
Object.defineProperty(error, SDK_ERROR_BRAND, {
|
|
52
|
+
value: true,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
configurable: false,
|
|
55
|
+
writable: false
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function defineSDKErrorType(error, type) {
|
|
59
|
+
Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
|
|
60
|
+
value: type,
|
|
61
|
+
enumerable: false,
|
|
62
|
+
configurable: false,
|
|
63
|
+
writable: false
|
|
64
|
+
});
|
|
65
|
+
}
|
|
33
66
|
var SDKError = class extends Error {
|
|
34
67
|
constructor(code, message, status, details, userMessage, suggestion, requestId) {
|
|
35
68
|
super(message);
|
|
@@ -40,6 +73,7 @@ var SDKError = class extends Error {
|
|
|
40
73
|
this.userMessage = userMessage;
|
|
41
74
|
this.suggestion = suggestion;
|
|
42
75
|
this.requestId = requestId;
|
|
76
|
+
defineSDKErrorBrand(this);
|
|
43
77
|
if (Error.captureStackTrace) {
|
|
44
78
|
Error.captureStackTrace(this, new.target);
|
|
45
79
|
}
|
|
@@ -60,6 +94,7 @@ var SDKError = class extends Error {
|
|
|
60
94
|
...this.kind !== void 0 && { kind: this.kind },
|
|
61
95
|
...this.reason !== void 0 && { reason: this.reason },
|
|
62
96
|
...this.rawReason !== void 0 && { rawReason: this.rawReason },
|
|
97
|
+
...this.apiReason !== void 0 && { apiReason: this.apiReason },
|
|
63
98
|
...this.retryable !== void 0 && { retryable: this.retryable },
|
|
64
99
|
...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
|
|
65
100
|
};
|
|
@@ -67,34 +102,78 @@ var SDKError = class extends Error {
|
|
|
67
102
|
};
|
|
68
103
|
var COMMERCE_ERROR_CODES = [
|
|
69
104
|
"validation_failed",
|
|
105
|
+
"bad_request",
|
|
70
106
|
"unauthorized",
|
|
71
107
|
"forbidden",
|
|
108
|
+
"account_suspended",
|
|
109
|
+
"key_invalid",
|
|
110
|
+
"pat_tenant_header_forbidden",
|
|
111
|
+
"tenant_mismatch",
|
|
112
|
+
"test_tenant_expired",
|
|
113
|
+
"token_invalid",
|
|
72
114
|
"token_expired",
|
|
73
115
|
"origin_not_allowed",
|
|
74
116
|
"server_credentials_required",
|
|
117
|
+
"role_denied",
|
|
118
|
+
"scope_denied",
|
|
119
|
+
"feature_disabled",
|
|
75
120
|
"not_found",
|
|
76
121
|
"conflict",
|
|
122
|
+
"locked",
|
|
77
123
|
"cart_revision_conflict",
|
|
78
124
|
"rate_limit_exceeded",
|
|
79
125
|
"usage_limit_exceeded",
|
|
80
126
|
"service_unavailable",
|
|
81
127
|
"idempotency_conflict",
|
|
82
128
|
"idempotency_in_progress",
|
|
129
|
+
"idempotency_key_required",
|
|
130
|
+
"invalid_idempotency_key",
|
|
83
131
|
"cart_not_active",
|
|
84
132
|
"cart_locked",
|
|
85
133
|
"cart_empty",
|
|
86
134
|
"cart_market_unavailable",
|
|
87
135
|
"cart_market_mismatch",
|
|
88
136
|
"checkout_not_open",
|
|
137
|
+
"checkout_already_open",
|
|
89
138
|
"payment_slot_held",
|
|
90
139
|
"reservation_expired",
|
|
91
140
|
"payment_session_not_cancelable",
|
|
141
|
+
"payment_session_conflict",
|
|
92
142
|
"provider_identity_mismatch",
|
|
143
|
+
"payment_method_unavailable",
|
|
93
144
|
"provider_unavailable",
|
|
94
145
|
"lock_timeout",
|
|
95
146
|
"price_changed",
|
|
96
147
|
"pricing_fact_in_use",
|
|
97
148
|
"insufficient_stock",
|
|
149
|
+
"reservation_conflict",
|
|
150
|
+
"stock_lock_unavailable",
|
|
151
|
+
"variant_not_found",
|
|
152
|
+
"variant_stock_write_failed",
|
|
153
|
+
"stock_invariant_violation",
|
|
154
|
+
"payment_confirmation_in_flight",
|
|
155
|
+
"checkout_reservation_release_requires_transaction",
|
|
156
|
+
"admission_metadata_invalid",
|
|
157
|
+
"admission_metadata_required",
|
|
158
|
+
"capacity_exceeded",
|
|
159
|
+
"occurrence_lock_unavailable",
|
|
160
|
+
"occurrence_not_open",
|
|
161
|
+
"admission_type_capacity_exceeded",
|
|
162
|
+
"admission_type_occurrence_mismatch",
|
|
163
|
+
"admission_hold_expired",
|
|
164
|
+
"admission_hold_checkout_item_conflict",
|
|
165
|
+
"admission_hold_checkout_conflict",
|
|
166
|
+
"admission_hold_quantity_mismatch",
|
|
167
|
+
"admission_hold_unbound",
|
|
168
|
+
"admission_hold_missing",
|
|
169
|
+
"admission_hold_checkout_item_missing",
|
|
170
|
+
"admission_hold_expiry_failed",
|
|
171
|
+
"admission_hold_expiry_requires_transaction",
|
|
172
|
+
"admission_hold_line_item_mismatch",
|
|
173
|
+
"admission_materialization_failed",
|
|
174
|
+
"variant_inactive",
|
|
175
|
+
"variant_product_mismatch",
|
|
176
|
+
"product_not_public",
|
|
98
177
|
"market_not_found",
|
|
99
178
|
"market_shipping_currency_unsupported",
|
|
100
179
|
"missing_market_rate",
|
|
@@ -119,7 +198,11 @@ var COMMERCE_ERROR_CODES = [
|
|
|
119
198
|
"discount_min_order_amount",
|
|
120
199
|
"discount_currency_scope_required",
|
|
121
200
|
"discount_allocation_method_unsupported",
|
|
122
|
-
"currency_mismatch"
|
|
201
|
+
"currency_mismatch",
|
|
202
|
+
"customer_token_required",
|
|
203
|
+
"market_required",
|
|
204
|
+
"server_derived",
|
|
205
|
+
"internal_error"
|
|
123
206
|
];
|
|
124
207
|
var COMMERCE_ERROR_CODE_SET = new Set(
|
|
125
208
|
COMMERCE_ERROR_CODES
|
|
@@ -145,6 +228,12 @@ function commerceProtocolError(issue, trustedRequestId) {
|
|
|
145
228
|
);
|
|
146
229
|
}
|
|
147
230
|
function parseCommerceErrorEnvelope(body, headerRequestId) {
|
|
231
|
+
if (headerRequestId === void 0) {
|
|
232
|
+
throw commerceProtocolError("missing_request_id_header");
|
|
233
|
+
}
|
|
234
|
+
if (headerRequestId.length === 0) {
|
|
235
|
+
throw commerceProtocolError("empty_request_id_header");
|
|
236
|
+
}
|
|
148
237
|
if (!isPlainRecord(body)) {
|
|
149
238
|
throw commerceProtocolError("expected_object", headerRequestId);
|
|
150
239
|
}
|
|
@@ -154,7 +243,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
|
|
|
154
243
|
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)) {
|
|
155
244
|
throw commerceProtocolError("invalid_field", headerRequestId);
|
|
156
245
|
}
|
|
157
|
-
if (headerRequestId && headerRequestId !== body.requestId) {
|
|
246
|
+
if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
|
|
158
247
|
throw commerceProtocolError("request_id_mismatch", headerRequestId);
|
|
159
248
|
}
|
|
160
249
|
return {
|
|
@@ -179,8 +268,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
|
|
|
179
268
|
});
|
|
180
269
|
return error;
|
|
181
270
|
}
|
|
271
|
+
function enhanceNonCommerceError(error, reason) {
|
|
272
|
+
if (typeof reason === "string") Object.assign(error, { apiReason: reason });
|
|
273
|
+
return error;
|
|
274
|
+
}
|
|
275
|
+
function getSDKErrorReason(error) {
|
|
276
|
+
if (error.kind !== "commerce") return error.apiReason;
|
|
277
|
+
return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
|
|
278
|
+
}
|
|
182
279
|
function isCommerceSDKError(error) {
|
|
183
|
-
if (!(error
|
|
280
|
+
if (!isSDKError(error) || error.kind !== "commerce") return false;
|
|
184
281
|
if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
|
|
185
282
|
return false;
|
|
186
283
|
}
|
|
@@ -190,12 +287,14 @@ var NetworkError = class extends SDKError {
|
|
|
190
287
|
constructor(message, status, details, userMessage, suggestion) {
|
|
191
288
|
super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
|
|
192
289
|
this.name = "NetworkError";
|
|
290
|
+
defineSDKErrorType(this, "NetworkError");
|
|
193
291
|
}
|
|
194
292
|
};
|
|
195
293
|
var ValidationError = class extends SDKError {
|
|
196
294
|
constructor(message, details, userMessage, suggestion, status = 400) {
|
|
197
295
|
super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
|
|
198
296
|
this.name = "ValidationError";
|
|
297
|
+
defineSDKErrorType(this, "ValidationError");
|
|
199
298
|
}
|
|
200
299
|
};
|
|
201
300
|
var ApiError = class extends SDKError {
|
|
@@ -210,24 +309,28 @@ var ApiError = class extends SDKError {
|
|
|
210
309
|
requestId
|
|
211
310
|
);
|
|
212
311
|
this.name = "ApiError";
|
|
312
|
+
defineSDKErrorType(this, "ApiError");
|
|
213
313
|
}
|
|
214
314
|
};
|
|
215
315
|
var ConfigError = class extends SDKError {
|
|
216
316
|
constructor(message, details, userMessage, suggestion) {
|
|
217
317
|
super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
|
|
218
318
|
this.name = "ConfigError";
|
|
319
|
+
defineSDKErrorType(this, "ConfigError");
|
|
219
320
|
}
|
|
220
321
|
};
|
|
221
322
|
var TimeoutError = class extends SDKError {
|
|
222
323
|
constructor(message = "Request timed out.", details, userMessage, suggestion) {
|
|
223
324
|
super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
|
|
224
325
|
this.name = "TimeoutError";
|
|
326
|
+
defineSDKErrorType(this, "TimeoutError");
|
|
225
327
|
}
|
|
226
328
|
};
|
|
227
329
|
var GoneError = class extends SDKError {
|
|
228
330
|
constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
|
|
229
331
|
super("GONE_ERROR", message, 410, details, userMessage, suggestion);
|
|
230
332
|
this.name = "GoneError";
|
|
333
|
+
defineSDKErrorType(this, "GoneError");
|
|
231
334
|
}
|
|
232
335
|
};
|
|
233
336
|
var ServiceUnavailableError = class extends SDKError {
|
|
@@ -242,6 +345,7 @@ var ServiceUnavailableError = class extends SDKError {
|
|
|
242
345
|
);
|
|
243
346
|
this.name = "ServiceUnavailableError";
|
|
244
347
|
this.retryAfter = retryAfter;
|
|
348
|
+
defineSDKErrorType(this, "ServiceUnavailableError");
|
|
245
349
|
}
|
|
246
350
|
};
|
|
247
351
|
var UsageLimitError = class extends SDKError {
|
|
@@ -249,6 +353,7 @@ var UsageLimitError = class extends SDKError {
|
|
|
249
353
|
super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
|
|
250
354
|
this.name = "UsageLimitError";
|
|
251
355
|
this.usage = usage;
|
|
356
|
+
defineSDKErrorType(this, "UsageLimitError");
|
|
252
357
|
}
|
|
253
358
|
toJSON() {
|
|
254
359
|
return {
|
|
@@ -269,6 +374,7 @@ var AuthError = class extends SDKError {
|
|
|
269
374
|
requestId
|
|
270
375
|
);
|
|
271
376
|
this.name = "AuthError";
|
|
377
|
+
defineSDKErrorType(this, "AuthError");
|
|
272
378
|
}
|
|
273
379
|
};
|
|
274
380
|
var PermissionError = class extends SDKError {
|
|
@@ -283,6 +389,7 @@ var PermissionError = class extends SDKError {
|
|
|
283
389
|
requestId
|
|
284
390
|
);
|
|
285
391
|
this.name = "PermissionError";
|
|
392
|
+
defineSDKErrorType(this, "PermissionError");
|
|
286
393
|
}
|
|
287
394
|
};
|
|
288
395
|
var NotFoundError = class extends SDKError {
|
|
@@ -297,12 +404,14 @@ var NotFoundError = class extends SDKError {
|
|
|
297
404
|
requestId
|
|
298
405
|
);
|
|
299
406
|
this.name = "NotFoundError";
|
|
407
|
+
defineSDKErrorType(this, "NotFoundError");
|
|
300
408
|
}
|
|
301
409
|
};
|
|
302
410
|
var ConflictError = class extends SDKError {
|
|
303
411
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
304
412
|
super("conflict", message, 409, details, userMessage, suggestion, requestId);
|
|
305
413
|
this.name = "ConflictError";
|
|
414
|
+
defineSDKErrorType(this, "ConflictError");
|
|
306
415
|
}
|
|
307
416
|
};
|
|
308
417
|
var RateLimitError = class extends SDKError {
|
|
@@ -318,8 +427,64 @@ var RateLimitError = class extends SDKError {
|
|
|
318
427
|
);
|
|
319
428
|
this.name = "RateLimitError";
|
|
320
429
|
this.retryAfter = retryAfter;
|
|
430
|
+
defineSDKErrorType(this, "RateLimitError");
|
|
321
431
|
}
|
|
322
432
|
};
|
|
433
|
+
function hasBrandedSDKErrorShape(error) {
|
|
434
|
+
if (error === null || typeof error !== "object") return false;
|
|
435
|
+
const candidate = error;
|
|
436
|
+
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";
|
|
437
|
+
}
|
|
438
|
+
function hasSDKErrorType(error, type) {
|
|
439
|
+
return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
|
|
440
|
+
}
|
|
441
|
+
function isSDKError(error) {
|
|
442
|
+
return error instanceof SDKError || hasBrandedSDKErrorShape(error);
|
|
443
|
+
}
|
|
444
|
+
function isNetworkError(error) {
|
|
445
|
+
return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
|
|
446
|
+
}
|
|
447
|
+
function isValidationError(error) {
|
|
448
|
+
if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
if (error == null || typeof error !== "object") return false;
|
|
452
|
+
const candidate = error;
|
|
453
|
+
return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
454
|
+
}
|
|
455
|
+
function isApiError(error) {
|
|
456
|
+
return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
|
|
457
|
+
}
|
|
458
|
+
function isConfigError(error) {
|
|
459
|
+
return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
|
|
460
|
+
}
|
|
461
|
+
function isTimeoutError(error) {
|
|
462
|
+
return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
|
|
463
|
+
}
|
|
464
|
+
function isGoneError(error) {
|
|
465
|
+
return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
|
|
466
|
+
}
|
|
467
|
+
function isServiceUnavailableError(error) {
|
|
468
|
+
return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
|
|
469
|
+
}
|
|
470
|
+
function isUsageLimitError(error) {
|
|
471
|
+
return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
|
|
472
|
+
}
|
|
473
|
+
function isAuthError(error) {
|
|
474
|
+
return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
|
|
475
|
+
}
|
|
476
|
+
function isPermissionError(error) {
|
|
477
|
+
return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
|
|
478
|
+
}
|
|
479
|
+
function isNotFoundError(error) {
|
|
480
|
+
return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
|
|
481
|
+
}
|
|
482
|
+
function isConflictError(error) {
|
|
483
|
+
return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
|
|
484
|
+
}
|
|
485
|
+
function isRateLimitError(error) {
|
|
486
|
+
return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
|
|
487
|
+
}
|
|
323
488
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
324
489
|
var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
|
|
325
490
|
var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
|
|
@@ -529,7 +694,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
|
|
|
529
694
|
if (retryAfter !== void 0) {
|
|
530
695
|
Object.assign(withRequestId, { retryAfter });
|
|
531
696
|
}
|
|
532
|
-
return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
|
|
697
|
+
return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
|
|
533
698
|
};
|
|
534
699
|
if (status === 400 || status === 422) {
|
|
535
700
|
return finalize(
|
|
@@ -716,7 +881,7 @@ async function httpFetch(url, options) {
|
|
|
716
881
|
),
|
|
717
882
|
requestId
|
|
718
883
|
);
|
|
719
|
-
throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
|
|
884
|
+
throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
|
|
720
885
|
}
|
|
721
886
|
if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
|
|
722
887
|
hasRetried401 = true;
|
|
@@ -1131,7 +1296,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1131
1296
|
return parsed;
|
|
1132
1297
|
}
|
|
1133
1298
|
const data = parsed;
|
|
1134
|
-
|
|
1299
|
+
const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
|
|
1300
|
+
(key) => Object.prototype.hasOwnProperty.call(data, key)
|
|
1301
|
+
);
|
|
1302
|
+
if (data.error || hasCommerceEnvelopeSignal) {
|
|
1135
1303
|
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
1136
1304
|
const reason = typeof data.reason === "string" ? data.reason : void 0;
|
|
1137
1305
|
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
@@ -1160,19 +1328,21 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1160
1328
|
}
|
|
1161
1329
|
const withRequestId = attachRequestId(error, requestId);
|
|
1162
1330
|
if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
|
|
1163
|
-
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
|
|
1331
|
+
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
|
|
1164
1332
|
}
|
|
1165
1333
|
return data;
|
|
1166
1334
|
}
|
|
1167
1335
|
|
|
1168
1336
|
// ../../internal/http-contracts/src/index.ts
|
|
1169
1337
|
var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
|
|
1170
|
-
var operation = (collection, method, path) => Object.freeze({
|
|
1338
|
+
var operation = (collection, method, path, errorFamily) => Object.freeze({
|
|
1171
1339
|
[operationBrand]: true,
|
|
1172
1340
|
collection,
|
|
1173
1341
|
method,
|
|
1174
|
-
path
|
|
1342
|
+
path,
|
|
1343
|
+
...errorFamily && { errorFamily }
|
|
1175
1344
|
});
|
|
1345
|
+
var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
|
|
1176
1346
|
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
1177
1347
|
products: {
|
|
1178
1348
|
detail: operation("products", "get", "/detail"),
|
|
@@ -1205,13 +1375,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1205
1375
|
byPayment: operation("orders", "get", "/by-payment"),
|
|
1206
1376
|
cancel: operation("orders", "post", "/cancel"),
|
|
1207
1377
|
resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
|
|
1208
|
-
checkout:
|
|
1378
|
+
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
1209
1379
|
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
1210
1380
|
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
1211
1381
|
},
|
|
1212
1382
|
checkouts: {
|
|
1213
|
-
detail:
|
|
1214
|
-
query:
|
|
1383
|
+
detail: strictCommerceOperation("checkouts", "post", "/detail"),
|
|
1384
|
+
query: strictCommerceOperation("checkouts", "post", "/query")
|
|
1215
1385
|
},
|
|
1216
1386
|
transactions: {
|
|
1217
1387
|
update: operation("transactions", "post", "/update")
|
|
@@ -1232,29 +1402,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1232
1402
|
bulkImport: operation("fulfillments", "post", "/bulk-import")
|
|
1233
1403
|
},
|
|
1234
1404
|
carts: {
|
|
1235
|
-
create:
|
|
1236
|
-
retrieve:
|
|
1237
|
-
mine:
|
|
1238
|
-
merge:
|
|
1239
|
-
addItem:
|
|
1240
|
-
updateItem:
|
|
1241
|
-
removeItem:
|
|
1242
|
-
updateDiscountCodes:
|
|
1243
|
-
|
|
1244
|
-
|
|
1405
|
+
create: strictCommerceOperation("carts", "post", "/create"),
|
|
1406
|
+
retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
|
|
1407
|
+
mine: strictCommerceOperation("carts", "post", "/mine"),
|
|
1408
|
+
merge: strictCommerceOperation("carts", "post", "/merge"),
|
|
1409
|
+
addItem: strictCommerceOperation("carts", "post", "/add-item"),
|
|
1410
|
+
updateItem: strictCommerceOperation("carts", "post", "/update-item"),
|
|
1411
|
+
removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
|
|
1412
|
+
updateDiscountCodes: strictCommerceOperation(
|
|
1413
|
+
"carts",
|
|
1414
|
+
"post",
|
|
1415
|
+
"/update-discount-codes"
|
|
1416
|
+
),
|
|
1417
|
+
updateAttributes: strictCommerceOperation(
|
|
1418
|
+
"carts",
|
|
1419
|
+
"post",
|
|
1420
|
+
"/update-attributes"
|
|
1421
|
+
),
|
|
1422
|
+
clear: strictCommerceOperation("carts", "post", "/clear")
|
|
1245
1423
|
},
|
|
1246
1424
|
paymentSessions: {
|
|
1247
|
-
create:
|
|
1248
|
-
retrieve:
|
|
1249
|
-
cancel:
|
|
1425
|
+
create: strictCommerceOperation("payment-sessions", "post", "/create"),
|
|
1426
|
+
retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
|
|
1427
|
+
cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
|
|
1250
1428
|
server: {
|
|
1251
|
-
create:
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1429
|
+
create: strictCommerceOperation(
|
|
1430
|
+
"payment-sessions",
|
|
1431
|
+
"post",
|
|
1432
|
+
"/server/create"
|
|
1433
|
+
),
|
|
1434
|
+
retrieve: strictCommerceOperation(
|
|
1435
|
+
"payment-sessions",
|
|
1436
|
+
"post",
|
|
1437
|
+
"/server/retrieve"
|
|
1438
|
+
),
|
|
1439
|
+
cancel: strictCommerceOperation(
|
|
1440
|
+
"payment-sessions",
|
|
1441
|
+
"post",
|
|
1442
|
+
"/server/cancel"
|
|
1443
|
+
),
|
|
1444
|
+
confirm: strictCommerceOperation(
|
|
1445
|
+
"payment-sessions",
|
|
1446
|
+
"post",
|
|
1447
|
+
"/server/confirm"
|
|
1448
|
+
)
|
|
1255
1449
|
},
|
|
1256
1450
|
custom: {
|
|
1257
1451
|
create: operation("orders", "post", "/custom-payment-sessions"),
|
|
1452
|
+
retrieve: operation(
|
|
1453
|
+
"orders",
|
|
1454
|
+
"post",
|
|
1455
|
+
"/custom-payment-sessions/retrieve"
|
|
1456
|
+
),
|
|
1258
1457
|
confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
|
|
1259
1458
|
}
|
|
1260
1459
|
},
|
|
@@ -1280,6 +1479,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
|
|
|
1280
1479
|
)
|
|
1281
1480
|
}
|
|
1282
1481
|
};
|
|
1482
|
+
var COMMUNITY_ENDPOINT_OPERATIONS = {
|
|
1483
|
+
posts: {
|
|
1484
|
+
detail: operation("posts", "get", "/detail")
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1283
1487
|
function resolveOperationTemplate(descriptor) {
|
|
1284
1488
|
return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
|
|
1285
1489
|
}
|
|
@@ -1311,6 +1515,9 @@ var sharedEndpoint = (descriptor) => descriptor;
|
|
|
1311
1515
|
function resolveOperationMethod2(descriptor) {
|
|
1312
1516
|
return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
|
|
1313
1517
|
}
|
|
1518
|
+
function resolveOperationErrorFamily(descriptor) {
|
|
1519
|
+
return "collection" in descriptor ? descriptor.errorFamily : void 0;
|
|
1520
|
+
}
|
|
1314
1521
|
function resolveOperationPath2(descriptor, options) {
|
|
1315
1522
|
if ("collection" in descriptor) {
|
|
1316
1523
|
return resolveOperationPath(descriptor, options);
|
|
@@ -1345,12 +1552,12 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1345
1552
|
updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
|
|
1346
1553
|
},
|
|
1347
1554
|
checkouts: {
|
|
1348
|
-
create:
|
|
1349
|
-
retrieve:
|
|
1555
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1556
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1350
1557
|
server: {
|
|
1351
|
-
create:
|
|
1352
|
-
retrieve:
|
|
1353
|
-
query:
|
|
1558
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1559
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1560
|
+
query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
|
|
1354
1561
|
}
|
|
1355
1562
|
},
|
|
1356
1563
|
returns: {
|
|
@@ -1368,10 +1575,10 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1368
1575
|
bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
|
|
1369
1576
|
},
|
|
1370
1577
|
carts: {
|
|
1371
|
-
create:
|
|
1578
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
|
|
1372
1579
|
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
|
|
1373
|
-
mine:
|
|
1374
|
-
merge:
|
|
1580
|
+
mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
|
|
1581
|
+
merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
|
|
1375
1582
|
server: {
|
|
1376
1583
|
// Server credentials are an authorization lane, not a second Cart
|
|
1377
1584
|
// transport. These must stay bound to the registered shared operations.
|
|
@@ -1391,29 +1598,46 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1391
1598
|
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1392
1599
|
},
|
|
1393
1600
|
addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
|
|
1394
|
-
updateItem:
|
|
1395
|
-
removeItem:
|
|
1396
|
-
updateDiscountCodes:
|
|
1397
|
-
|
|
1398
|
-
|
|
1601
|
+
updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
|
|
1602
|
+
removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
|
|
1603
|
+
updateDiscountCodes: sharedEndpoint(
|
|
1604
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
|
|
1605
|
+
),
|
|
1606
|
+
updateAttributes: sharedEndpoint(
|
|
1607
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
|
|
1608
|
+
),
|
|
1609
|
+
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1399
1610
|
},
|
|
1400
1611
|
paymentSessions: {
|
|
1401
|
-
create:
|
|
1402
|
-
retrieve:
|
|
1403
|
-
|
|
1612
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
|
|
1613
|
+
retrieve: sharedEndpoint(
|
|
1614
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
|
|
1615
|
+
),
|
|
1616
|
+
cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
|
|
1404
1617
|
custom: {
|
|
1405
1618
|
create: sharedEndpoint(
|
|
1406
1619
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
|
|
1407
1620
|
),
|
|
1621
|
+
retrieve: sharedEndpoint(
|
|
1622
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
|
|
1623
|
+
),
|
|
1408
1624
|
confirm: sharedEndpoint(
|
|
1409
1625
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
|
|
1410
1626
|
)
|
|
1411
1627
|
},
|
|
1412
1628
|
server: {
|
|
1413
|
-
create:
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1629
|
+
create: sharedEndpoint(
|
|
1630
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
|
|
1631
|
+
),
|
|
1632
|
+
retrieve: sharedEndpoint(
|
|
1633
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
1634
|
+
),
|
|
1635
|
+
cancel: sharedEndpoint(
|
|
1636
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
|
|
1637
|
+
),
|
|
1638
|
+
confirm: sharedEndpoint(
|
|
1639
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
|
|
1640
|
+
)
|
|
1417
1641
|
}
|
|
1418
1642
|
},
|
|
1419
1643
|
shippingPolicies: {
|
|
@@ -1504,7 +1728,8 @@ var CustomerScopedApi = class {
|
|
|
1504
1728
|
return this.transport.request(resolveOperationPath2(endpoint2, options), {
|
|
1505
1729
|
method: resolveOperationMethod2(endpoint2),
|
|
1506
1730
|
body,
|
|
1507
|
-
headers: options?.headers
|
|
1731
|
+
headers: options?.headers,
|
|
1732
|
+
errorFamily: resolveOperationErrorFamily(endpoint2)
|
|
1508
1733
|
});
|
|
1509
1734
|
}
|
|
1510
1735
|
};
|
|
@@ -1526,15 +1751,33 @@ function unwrapPayloadDoc(value) {
|
|
|
1526
1751
|
}
|
|
1527
1752
|
return value;
|
|
1528
1753
|
}
|
|
1754
|
+
function hasCanonicalNotFoundReason(error) {
|
|
1755
|
+
return getSDKErrorReason(error) === "not_found";
|
|
1756
|
+
}
|
|
1529
1757
|
var CommunityClient = class extends RawCustomerScopedApi {
|
|
1530
1758
|
constructor(options) {
|
|
1531
1759
|
super("CommunityClient", { ...options, requiresCredential: false });
|
|
1760
|
+
this.requiresSafePublicRawReads = !options.secretKey;
|
|
1532
1761
|
}
|
|
1533
1762
|
buildQuery(params) {
|
|
1534
1763
|
if (!params) return "";
|
|
1535
1764
|
const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
|
|
1536
1765
|
return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
|
|
1537
1766
|
}
|
|
1767
|
+
withSafePublicRawReadQuery(query) {
|
|
1768
|
+
if (!this.requiresSafePublicRawReads) return query;
|
|
1769
|
+
if (!query) return "?depth=0&joins=false";
|
|
1770
|
+
return `?depth=0&joins=false&${query.slice(1)}`;
|
|
1771
|
+
}
|
|
1772
|
+
buildSafePublicRawListQuery(params) {
|
|
1773
|
+
if (!this.requiresSafePublicRawReads) {
|
|
1774
|
+
return this.buildQuery(params);
|
|
1775
|
+
}
|
|
1776
|
+
const queryParams = {};
|
|
1777
|
+
if (params?.page !== void 0) queryParams.page = params.page;
|
|
1778
|
+
if (params?.limit !== void 0) queryParams.limit = params.limit;
|
|
1779
|
+
return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
|
|
1780
|
+
}
|
|
1538
1781
|
buildPostsListQuery(params) {
|
|
1539
1782
|
const urlParams = new URLSearchParams();
|
|
1540
1783
|
const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
|
|
@@ -1594,15 +1837,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1594
1837
|
"GET"
|
|
1595
1838
|
);
|
|
1596
1839
|
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Public post detail projected by the same allowlist as the public feed.
|
|
1842
|
+
* Missing, hidden, and cross-tenant posts all resolve to `null`.
|
|
1843
|
+
*/
|
|
1844
|
+
async getPost(params) {
|
|
1845
|
+
const query = new URLSearchParams({ postId: params.postId });
|
|
1846
|
+
try {
|
|
1847
|
+
return await this.execute(
|
|
1848
|
+
resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
|
|
1849
|
+
query
|
|
1850
|
+
}),
|
|
1851
|
+
resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
|
|
1852
|
+
);
|
|
1853
|
+
} catch (error) {
|
|
1854
|
+
if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
|
|
1855
|
+
return null;
|
|
1856
|
+
}
|
|
1857
|
+
throw error;
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1597
1860
|
listPostCategories(params) {
|
|
1598
1861
|
return this.execute(
|
|
1599
|
-
`/api/post-categories${this.
|
|
1862
|
+
`/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
|
|
1600
1863
|
"GET"
|
|
1601
1864
|
);
|
|
1602
1865
|
}
|
|
1603
1866
|
listPostTags(params) {
|
|
1604
1867
|
return this.execute(
|
|
1605
|
-
`/api/post-tags${this.
|
|
1868
|
+
`/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
|
|
1606
1869
|
"GET"
|
|
1607
1870
|
);
|
|
1608
1871
|
}
|
|
@@ -1768,7 +2031,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1768
2031
|
}
|
|
1769
2032
|
getReactionTypes() {
|
|
1770
2033
|
return this.execute(
|
|
1771
|
-
|
|
2034
|
+
`/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
|
|
1772
2035
|
"GET"
|
|
1773
2036
|
);
|
|
1774
2037
|
}
|
|
@@ -1796,11 +2059,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1796
2059
|
}
|
|
1797
2060
|
// Profiles
|
|
1798
2061
|
listProfileLists(params) {
|
|
1799
|
-
return this.execute(
|
|
2062
|
+
return this.execute(
|
|
2063
|
+
`/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
|
|
2064
|
+
"GET"
|
|
2065
|
+
);
|
|
1800
2066
|
}
|
|
1801
2067
|
async getProfileList(params) {
|
|
1802
2068
|
const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
|
|
1803
|
-
const res = await this.execute(
|
|
2069
|
+
const res = await this.execute(
|
|
2070
|
+
`/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
|
|
2071
|
+
"GET"
|
|
2072
|
+
);
|
|
1804
2073
|
return res.docs[0] ?? null;
|
|
1805
2074
|
}
|
|
1806
2075
|
updatePublicProfile(body) {
|
|
@@ -1913,7 +2182,7 @@ var ORDER_PRIMARY_DISPLAY_STATUSES = [
|
|
|
1913
2182
|
];
|
|
1914
2183
|
var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
|
|
1915
2184
|
var ABANDONED_REASONS = ["expired", "customer", "operator"];
|
|
1916
|
-
var PAYMENT_PROVIDERS = ["toss"];
|
|
2185
|
+
var PAYMENT_PROVIDERS = ["toss", "portone"];
|
|
1917
2186
|
var PAYMENT_PROVIDER_STATUSES = [
|
|
1918
2187
|
"requires_payment_method",
|
|
1919
2188
|
"requires_action",
|
|
@@ -3086,8 +3355,101 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
|
|
|
3086
3355
|
previous = current;
|
|
3087
3356
|
});
|
|
3088
3357
|
}
|
|
3089
|
-
function validateNextAction(value, resource, path) {
|
|
3358
|
+
function validateNextAction(value, provider, resource, path) {
|
|
3090
3359
|
const action = record(value, resource, path);
|
|
3360
|
+
if (provider === "portone") {
|
|
3361
|
+
if (action.type === "portone_sdk") {
|
|
3362
|
+
exact(
|
|
3363
|
+
action,
|
|
3364
|
+
[
|
|
3365
|
+
"type",
|
|
3366
|
+
"version",
|
|
3367
|
+
"storeId",
|
|
3368
|
+
"channelKey",
|
|
3369
|
+
"paymentId",
|
|
3370
|
+
"orderName",
|
|
3371
|
+
"totalAmount",
|
|
3372
|
+
"currency",
|
|
3373
|
+
"payMethod",
|
|
3374
|
+
"redirectUrl"
|
|
3375
|
+
],
|
|
3376
|
+
[],
|
|
3377
|
+
resource,
|
|
3378
|
+
path
|
|
3379
|
+
);
|
|
3380
|
+
if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
|
|
3381
|
+
for (const key of ["storeId", "channelKey"]) {
|
|
3382
|
+
boundedString(action[key], 255, resource, `${path}.${key}`);
|
|
3383
|
+
}
|
|
3384
|
+
const paymentId = boundedString(
|
|
3385
|
+
action.paymentId,
|
|
3386
|
+
40,
|
|
3387
|
+
resource,
|
|
3388
|
+
`${path}.paymentId`
|
|
3389
|
+
);
|
|
3390
|
+
if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
|
|
3391
|
+
fail(
|
|
3392
|
+
resource,
|
|
3393
|
+
`${path}.paymentId`,
|
|
3394
|
+
"6-40 ASCII alphanumeric characters"
|
|
3395
|
+
);
|
|
3396
|
+
}
|
|
3397
|
+
boundedString(
|
|
3398
|
+
action.orderName,
|
|
3399
|
+
MAX_COMMERCE_SHORT_TEXT_LENGTH,
|
|
3400
|
+
resource,
|
|
3401
|
+
`${path}.orderName`
|
|
3402
|
+
);
|
|
3403
|
+
positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
|
|
3404
|
+
if (action.currency !== "CURRENCY_KRW") {
|
|
3405
|
+
fail(resource, `${path}.currency`, "CURRENCY_KRW");
|
|
3406
|
+
}
|
|
3407
|
+
if (action.payMethod !== "CARD")
|
|
3408
|
+
fail(resource, `${path}.payMethod`, "CARD");
|
|
3409
|
+
const redirectUrl = boundedString(
|
|
3410
|
+
action.redirectUrl,
|
|
3411
|
+
2048,
|
|
3412
|
+
resource,
|
|
3413
|
+
`${path}.redirectUrl`
|
|
3414
|
+
);
|
|
3415
|
+
try {
|
|
3416
|
+
const parsed = new URL(redirectUrl);
|
|
3417
|
+
const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
|
|
3418
|
+
if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
|
|
3419
|
+
throw new Error("unsafe redirect URL");
|
|
3420
|
+
} catch {
|
|
3421
|
+
fail(
|
|
3422
|
+
resource,
|
|
3423
|
+
`${path}.redirectUrl`,
|
|
3424
|
+
"HTTPS or loopback URL without embedded credentials"
|
|
3425
|
+
);
|
|
3426
|
+
}
|
|
3427
|
+
return;
|
|
3428
|
+
}
|
|
3429
|
+
exact(action, ["type", "checkoutUrl"], [], resource, path);
|
|
3430
|
+
if (action.type !== "portone_checkout") {
|
|
3431
|
+
fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
|
|
3432
|
+
}
|
|
3433
|
+
const checkoutUrl = boundedString(
|
|
3434
|
+
action.checkoutUrl,
|
|
3435
|
+
2048,
|
|
3436
|
+
resource,
|
|
3437
|
+
`${path}.checkoutUrl`
|
|
3438
|
+
);
|
|
3439
|
+
try {
|
|
3440
|
+
const parsed = new URL(checkoutUrl);
|
|
3441
|
+
if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
|
|
3442
|
+
throw new Error("unsafe checkout URL");
|
|
3443
|
+
}
|
|
3444
|
+
} catch {
|
|
3445
|
+
fail(
|
|
3446
|
+
resource,
|
|
3447
|
+
`${path}.checkoutUrl`,
|
|
3448
|
+
"absolute HTTPS URL without embedded credentials"
|
|
3449
|
+
);
|
|
3450
|
+
}
|
|
3451
|
+
return;
|
|
3452
|
+
}
|
|
3091
3453
|
exact(
|
|
3092
3454
|
action,
|
|
3093
3455
|
[
|
|
@@ -3138,10 +3500,18 @@ function validateNextAction(value, resource, path) {
|
|
|
3138
3500
|
if (action.customerEmail !== void 0)
|
|
3139
3501
|
validateCustomer({ email: action.customerEmail }, resource, path);
|
|
3140
3502
|
}
|
|
3141
|
-
function validatePublicPaymentSession(value) {
|
|
3503
|
+
function validatePublicPaymentSession(value, expectedProvider) {
|
|
3142
3504
|
const resource = "PaymentSession";
|
|
3143
3505
|
const session = record(value, resource, "$");
|
|
3144
|
-
|
|
3506
|
+
const provider = enumValue(
|
|
3507
|
+
session.provider,
|
|
3508
|
+
PAYMENT_PROVIDERS,
|
|
3509
|
+
resource,
|
|
3510
|
+
"$.provider"
|
|
3511
|
+
);
|
|
3512
|
+
if (expectedProvider !== void 0 && provider !== expectedProvider) {
|
|
3513
|
+
fail(resource, "$.provider", expectedProvider);
|
|
3514
|
+
}
|
|
3145
3515
|
const status = enumValue(
|
|
3146
3516
|
session.providerStatus,
|
|
3147
3517
|
PAYMENT_PROVIDER_STATUSES,
|
|
@@ -3178,7 +3548,12 @@ function validatePublicPaymentSession(value) {
|
|
|
3178
3548
|
}
|
|
3179
3549
|
if (!("nextAction" in session))
|
|
3180
3550
|
fail(resource, "$.nextAction", "required field");
|
|
3181
|
-
validateNextAction(
|
|
3551
|
+
validateNextAction(
|
|
3552
|
+
session.nextAction,
|
|
3553
|
+
provider,
|
|
3554
|
+
resource,
|
|
3555
|
+
"$.nextAction"
|
|
3556
|
+
);
|
|
3182
3557
|
} else if (session.sessionRole === "residual") {
|
|
3183
3558
|
if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
|
|
3184
3559
|
fail(resource, "$", "suppressed residual not-ready state");
|
|
@@ -3917,8 +4292,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
3917
4292
|
}
|
|
3918
4293
|
});
|
|
3919
4294
|
}
|
|
3920
|
-
async paymentSession(result) {
|
|
3921
|
-
return validatePublicPaymentSession(await result);
|
|
4295
|
+
async paymentSession(result, expectedProvider) {
|
|
4296
|
+
return validatePublicPaymentSession(await result, expectedProvider);
|
|
3922
4297
|
}
|
|
3923
4298
|
create(params) {
|
|
3924
4299
|
const { idempotencyKey, ...body } = params;
|
|
@@ -3928,18 +4303,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
3928
4303
|
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
3929
4304
|
body,
|
|
3930
4305
|
idempotencyKey
|
|
3931
|
-
)
|
|
4306
|
+
),
|
|
4307
|
+
"toss"
|
|
4308
|
+
);
|
|
4309
|
+
}
|
|
4310
|
+
createPortOne(params) {
|
|
4311
|
+
const { idempotencyKey, ...body } = params;
|
|
4312
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4313
|
+
return this.paymentSession(
|
|
4314
|
+
this.post(
|
|
4315
|
+
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
4316
|
+
body,
|
|
4317
|
+
idempotencyKey
|
|
4318
|
+
),
|
|
4319
|
+
"portone"
|
|
3932
4320
|
);
|
|
3933
4321
|
}
|
|
3934
4322
|
retrieve(params) {
|
|
3935
4323
|
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
3936
|
-
return this.paymentSession(
|
|
4324
|
+
return this.paymentSession(
|
|
4325
|
+
this.post(endpoint2, params),
|
|
4326
|
+
"toss"
|
|
4327
|
+
);
|
|
4328
|
+
}
|
|
4329
|
+
retrievePortOne(params) {
|
|
4330
|
+
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
4331
|
+
return this.paymentSession(
|
|
4332
|
+
this.post(endpoint2, params),
|
|
4333
|
+
"portone"
|
|
4334
|
+
);
|
|
3937
4335
|
}
|
|
3938
4336
|
cancel(params) {
|
|
3939
4337
|
const { idempotencyKey, ...body } = params;
|
|
3940
4338
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
3941
4339
|
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
3942
|
-
return this.paymentSession(
|
|
4340
|
+
return this.paymentSession(
|
|
4341
|
+
this.post(endpoint2, body, idempotencyKey),
|
|
4342
|
+
"toss"
|
|
4343
|
+
);
|
|
4344
|
+
}
|
|
4345
|
+
cancelPortOne(params) {
|
|
4346
|
+
const { idempotencyKey, ...body } = params;
|
|
4347
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4348
|
+
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
4349
|
+
return this.paymentSession(
|
|
4350
|
+
this.post(endpoint2, body, idempotencyKey),
|
|
4351
|
+
"portone"
|
|
4352
|
+
);
|
|
3943
4353
|
}
|
|
3944
4354
|
confirm(params) {
|
|
3945
4355
|
const { idempotencyKey, ...body } = params;
|
|
@@ -3949,7 +4359,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
3949
4359
|
COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
|
|
3950
4360
|
body,
|
|
3951
4361
|
idempotencyKey
|
|
3952
|
-
)
|
|
4362
|
+
),
|
|
4363
|
+
"toss"
|
|
3953
4364
|
);
|
|
3954
4365
|
}
|
|
3955
4366
|
};
|
|
@@ -4980,21 +5391,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
|
|
|
4980
5391
|
"not_published",
|
|
4981
5392
|
"feature_disabled"
|
|
4982
5393
|
]);
|
|
4983
|
-
function isRecord(value) {
|
|
4984
|
-
return typeof value === "object" && value !== null;
|
|
4985
|
-
}
|
|
4986
|
-
function readProductDetailUnavailableReason(value) {
|
|
4987
|
-
if (!isRecord(value)) return void 0;
|
|
4988
|
-
const directReason = value.reason ?? value.code;
|
|
4989
|
-
if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
|
|
4990
|
-
return directReason;
|
|
4991
|
-
}
|
|
4992
|
-
return readProductDetailUnavailableReason(value.body);
|
|
4993
|
-
}
|
|
4994
5394
|
function productDetailResultFromError(error) {
|
|
4995
5395
|
if (!(error instanceof SDKError) || error.status !== 404) return void 0;
|
|
4996
|
-
const reason =
|
|
4997
|
-
if (!reason
|
|
5396
|
+
const reason = getSDKErrorReason(error);
|
|
5397
|
+
if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
|
|
5398
|
+
return void 0;
|
|
4998
5399
|
return { found: false, reason };
|
|
4999
5400
|
}
|
|
5000
5401
|
var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
|
|
@@ -5203,8 +5604,11 @@ var CommerceClient = class {
|
|
|
5203
5604
|
};
|
|
5204
5605
|
this.paymentSessions = {
|
|
5205
5606
|
create: paymentSessionApi.create.bind(paymentSessionApi),
|
|
5607
|
+
createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
|
|
5206
5608
|
retrieve: (params) => paymentSessionApi.retrieve(params),
|
|
5207
|
-
|
|
5609
|
+
retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
|
|
5610
|
+
cancel: (params) => paymentSessionApi.cancel(params),
|
|
5611
|
+
cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params)
|
|
5208
5612
|
};
|
|
5209
5613
|
this.discounts = {
|
|
5210
5614
|
validate: (params) => api.requestEndpoint(
|