@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.js
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
import { stringify } from "qs-esm";
|
|
3
3
|
|
|
4
4
|
// src/core/errors.ts
|
|
5
|
+
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
6
|
+
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
7
|
+
function defineSDKErrorBrand(error) {
|
|
8
|
+
Object.defineProperty(error, SDK_ERROR_BRAND, {
|
|
9
|
+
value: true,
|
|
10
|
+
enumerable: false,
|
|
11
|
+
configurable: false,
|
|
12
|
+
writable: false
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function defineSDKErrorType(error, type) {
|
|
16
|
+
Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
|
|
17
|
+
value: type,
|
|
18
|
+
enumerable: false,
|
|
19
|
+
configurable: false,
|
|
20
|
+
writable: false
|
|
21
|
+
});
|
|
22
|
+
}
|
|
5
23
|
var SDKError = class extends Error {
|
|
6
24
|
constructor(code, message, status, details, userMessage, suggestion, requestId) {
|
|
7
25
|
super(message);
|
|
@@ -12,6 +30,7 @@ var SDKError = class extends Error {
|
|
|
12
30
|
this.userMessage = userMessage;
|
|
13
31
|
this.suggestion = suggestion;
|
|
14
32
|
this.requestId = requestId;
|
|
33
|
+
defineSDKErrorBrand(this);
|
|
15
34
|
if (Error.captureStackTrace) {
|
|
16
35
|
Error.captureStackTrace(this, new.target);
|
|
17
36
|
}
|
|
@@ -32,6 +51,7 @@ var SDKError = class extends Error {
|
|
|
32
51
|
...this.kind !== void 0 && { kind: this.kind },
|
|
33
52
|
...this.reason !== void 0 && { reason: this.reason },
|
|
34
53
|
...this.rawReason !== void 0 && { rawReason: this.rawReason },
|
|
54
|
+
...this.apiReason !== void 0 && { apiReason: this.apiReason },
|
|
35
55
|
...this.retryable !== void 0 && { retryable: this.retryable },
|
|
36
56
|
...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
|
|
37
57
|
};
|
|
@@ -39,34 +59,78 @@ var SDKError = class extends Error {
|
|
|
39
59
|
};
|
|
40
60
|
var COMMERCE_ERROR_CODES = [
|
|
41
61
|
"validation_failed",
|
|
62
|
+
"bad_request",
|
|
42
63
|
"unauthorized",
|
|
43
64
|
"forbidden",
|
|
65
|
+
"account_suspended",
|
|
66
|
+
"key_invalid",
|
|
67
|
+
"pat_tenant_header_forbidden",
|
|
68
|
+
"tenant_mismatch",
|
|
69
|
+
"test_tenant_expired",
|
|
70
|
+
"token_invalid",
|
|
44
71
|
"token_expired",
|
|
45
72
|
"origin_not_allowed",
|
|
46
73
|
"server_credentials_required",
|
|
74
|
+
"role_denied",
|
|
75
|
+
"scope_denied",
|
|
76
|
+
"feature_disabled",
|
|
47
77
|
"not_found",
|
|
48
78
|
"conflict",
|
|
79
|
+
"locked",
|
|
49
80
|
"cart_revision_conflict",
|
|
50
81
|
"rate_limit_exceeded",
|
|
51
82
|
"usage_limit_exceeded",
|
|
52
83
|
"service_unavailable",
|
|
53
84
|
"idempotency_conflict",
|
|
54
85
|
"idempotency_in_progress",
|
|
86
|
+
"idempotency_key_required",
|
|
87
|
+
"invalid_idempotency_key",
|
|
55
88
|
"cart_not_active",
|
|
56
89
|
"cart_locked",
|
|
57
90
|
"cart_empty",
|
|
58
91
|
"cart_market_unavailable",
|
|
59
92
|
"cart_market_mismatch",
|
|
60
93
|
"checkout_not_open",
|
|
94
|
+
"checkout_already_open",
|
|
61
95
|
"payment_slot_held",
|
|
62
96
|
"reservation_expired",
|
|
63
97
|
"payment_session_not_cancelable",
|
|
98
|
+
"payment_session_conflict",
|
|
64
99
|
"provider_identity_mismatch",
|
|
100
|
+
"payment_method_unavailable",
|
|
65
101
|
"provider_unavailable",
|
|
66
102
|
"lock_timeout",
|
|
67
103
|
"price_changed",
|
|
68
104
|
"pricing_fact_in_use",
|
|
69
105
|
"insufficient_stock",
|
|
106
|
+
"reservation_conflict",
|
|
107
|
+
"stock_lock_unavailable",
|
|
108
|
+
"variant_not_found",
|
|
109
|
+
"variant_stock_write_failed",
|
|
110
|
+
"stock_invariant_violation",
|
|
111
|
+
"payment_confirmation_in_flight",
|
|
112
|
+
"checkout_reservation_release_requires_transaction",
|
|
113
|
+
"admission_metadata_invalid",
|
|
114
|
+
"admission_metadata_required",
|
|
115
|
+
"capacity_exceeded",
|
|
116
|
+
"occurrence_lock_unavailable",
|
|
117
|
+
"occurrence_not_open",
|
|
118
|
+
"admission_type_capacity_exceeded",
|
|
119
|
+
"admission_type_occurrence_mismatch",
|
|
120
|
+
"admission_hold_expired",
|
|
121
|
+
"admission_hold_checkout_item_conflict",
|
|
122
|
+
"admission_hold_checkout_conflict",
|
|
123
|
+
"admission_hold_quantity_mismatch",
|
|
124
|
+
"admission_hold_unbound",
|
|
125
|
+
"admission_hold_missing",
|
|
126
|
+
"admission_hold_checkout_item_missing",
|
|
127
|
+
"admission_hold_expiry_failed",
|
|
128
|
+
"admission_hold_expiry_requires_transaction",
|
|
129
|
+
"admission_hold_line_item_mismatch",
|
|
130
|
+
"admission_materialization_failed",
|
|
131
|
+
"variant_inactive",
|
|
132
|
+
"variant_product_mismatch",
|
|
133
|
+
"product_not_public",
|
|
70
134
|
"market_not_found",
|
|
71
135
|
"market_shipping_currency_unsupported",
|
|
72
136
|
"missing_market_rate",
|
|
@@ -91,7 +155,11 @@ var COMMERCE_ERROR_CODES = [
|
|
|
91
155
|
"discount_min_order_amount",
|
|
92
156
|
"discount_currency_scope_required",
|
|
93
157
|
"discount_allocation_method_unsupported",
|
|
94
|
-
"currency_mismatch"
|
|
158
|
+
"currency_mismatch",
|
|
159
|
+
"customer_token_required",
|
|
160
|
+
"market_required",
|
|
161
|
+
"server_derived",
|
|
162
|
+
"internal_error"
|
|
95
163
|
];
|
|
96
164
|
var COMMERCE_ERROR_CODE_SET = new Set(
|
|
97
165
|
COMMERCE_ERROR_CODES
|
|
@@ -117,6 +185,12 @@ function commerceProtocolError(issue, trustedRequestId) {
|
|
|
117
185
|
);
|
|
118
186
|
}
|
|
119
187
|
function parseCommerceErrorEnvelope(body, headerRequestId) {
|
|
188
|
+
if (headerRequestId === void 0) {
|
|
189
|
+
throw commerceProtocolError("missing_request_id_header");
|
|
190
|
+
}
|
|
191
|
+
if (headerRequestId.length === 0) {
|
|
192
|
+
throw commerceProtocolError("empty_request_id_header");
|
|
193
|
+
}
|
|
120
194
|
if (!isPlainRecord(body)) {
|
|
121
195
|
throw commerceProtocolError("expected_object", headerRequestId);
|
|
122
196
|
}
|
|
@@ -126,7 +200,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
|
|
|
126
200
|
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)) {
|
|
127
201
|
throw commerceProtocolError("invalid_field", headerRequestId);
|
|
128
202
|
}
|
|
129
|
-
if (headerRequestId && headerRequestId !== body.requestId) {
|
|
203
|
+
if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
|
|
130
204
|
throw commerceProtocolError("request_id_mismatch", headerRequestId);
|
|
131
205
|
}
|
|
132
206
|
return {
|
|
@@ -151,8 +225,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
|
|
|
151
225
|
});
|
|
152
226
|
return error;
|
|
153
227
|
}
|
|
228
|
+
function enhanceNonCommerceError(error, reason) {
|
|
229
|
+
if (typeof reason === "string") Object.assign(error, { apiReason: reason });
|
|
230
|
+
return error;
|
|
231
|
+
}
|
|
232
|
+
function getSDKErrorReason(error) {
|
|
233
|
+
if (error.kind !== "commerce") return error.apiReason;
|
|
234
|
+
return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
|
|
235
|
+
}
|
|
154
236
|
function isCommerceSDKError(error) {
|
|
155
|
-
if (!(error
|
|
237
|
+
if (!isSDKError(error) || error.kind !== "commerce") return false;
|
|
156
238
|
if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
|
|
157
239
|
return false;
|
|
158
240
|
}
|
|
@@ -162,12 +244,14 @@ var NetworkError = class extends SDKError {
|
|
|
162
244
|
constructor(message, status, details, userMessage, suggestion) {
|
|
163
245
|
super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
|
|
164
246
|
this.name = "NetworkError";
|
|
247
|
+
defineSDKErrorType(this, "NetworkError");
|
|
165
248
|
}
|
|
166
249
|
};
|
|
167
250
|
var ValidationError = class extends SDKError {
|
|
168
251
|
constructor(message, details, userMessage, suggestion, status = 400) {
|
|
169
252
|
super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
|
|
170
253
|
this.name = "ValidationError";
|
|
254
|
+
defineSDKErrorType(this, "ValidationError");
|
|
171
255
|
}
|
|
172
256
|
};
|
|
173
257
|
var ApiError = class extends SDKError {
|
|
@@ -182,24 +266,28 @@ var ApiError = class extends SDKError {
|
|
|
182
266
|
requestId
|
|
183
267
|
);
|
|
184
268
|
this.name = "ApiError";
|
|
269
|
+
defineSDKErrorType(this, "ApiError");
|
|
185
270
|
}
|
|
186
271
|
};
|
|
187
272
|
var ConfigError = class extends SDKError {
|
|
188
273
|
constructor(message, details, userMessage, suggestion) {
|
|
189
274
|
super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
|
|
190
275
|
this.name = "ConfigError";
|
|
276
|
+
defineSDKErrorType(this, "ConfigError");
|
|
191
277
|
}
|
|
192
278
|
};
|
|
193
279
|
var TimeoutError = class extends SDKError {
|
|
194
280
|
constructor(message = "Request timed out.", details, userMessage, suggestion) {
|
|
195
281
|
super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
|
|
196
282
|
this.name = "TimeoutError";
|
|
283
|
+
defineSDKErrorType(this, "TimeoutError");
|
|
197
284
|
}
|
|
198
285
|
};
|
|
199
286
|
var GoneError = class extends SDKError {
|
|
200
287
|
constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
|
|
201
288
|
super("GONE_ERROR", message, 410, details, userMessage, suggestion);
|
|
202
289
|
this.name = "GoneError";
|
|
290
|
+
defineSDKErrorType(this, "GoneError");
|
|
203
291
|
}
|
|
204
292
|
};
|
|
205
293
|
var ServiceUnavailableError = class extends SDKError {
|
|
@@ -214,6 +302,7 @@ var ServiceUnavailableError = class extends SDKError {
|
|
|
214
302
|
);
|
|
215
303
|
this.name = "ServiceUnavailableError";
|
|
216
304
|
this.retryAfter = retryAfter;
|
|
305
|
+
defineSDKErrorType(this, "ServiceUnavailableError");
|
|
217
306
|
}
|
|
218
307
|
};
|
|
219
308
|
var UsageLimitError = class extends SDKError {
|
|
@@ -221,6 +310,7 @@ var UsageLimitError = class extends SDKError {
|
|
|
221
310
|
super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
|
|
222
311
|
this.name = "UsageLimitError";
|
|
223
312
|
this.usage = usage;
|
|
313
|
+
defineSDKErrorType(this, "UsageLimitError");
|
|
224
314
|
}
|
|
225
315
|
toJSON() {
|
|
226
316
|
return {
|
|
@@ -241,6 +331,7 @@ var AuthError = class extends SDKError {
|
|
|
241
331
|
requestId
|
|
242
332
|
);
|
|
243
333
|
this.name = "AuthError";
|
|
334
|
+
defineSDKErrorType(this, "AuthError");
|
|
244
335
|
}
|
|
245
336
|
};
|
|
246
337
|
var PermissionError = class extends SDKError {
|
|
@@ -255,6 +346,7 @@ var PermissionError = class extends SDKError {
|
|
|
255
346
|
requestId
|
|
256
347
|
);
|
|
257
348
|
this.name = "PermissionError";
|
|
349
|
+
defineSDKErrorType(this, "PermissionError");
|
|
258
350
|
}
|
|
259
351
|
};
|
|
260
352
|
var NotFoundError = class extends SDKError {
|
|
@@ -269,12 +361,14 @@ var NotFoundError = class extends SDKError {
|
|
|
269
361
|
requestId
|
|
270
362
|
);
|
|
271
363
|
this.name = "NotFoundError";
|
|
364
|
+
defineSDKErrorType(this, "NotFoundError");
|
|
272
365
|
}
|
|
273
366
|
};
|
|
274
367
|
var ConflictError = class extends SDKError {
|
|
275
368
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
276
369
|
super("conflict", message, 409, details, userMessage, suggestion, requestId);
|
|
277
370
|
this.name = "ConflictError";
|
|
371
|
+
defineSDKErrorType(this, "ConflictError");
|
|
278
372
|
}
|
|
279
373
|
};
|
|
280
374
|
var RateLimitError = class extends SDKError {
|
|
@@ -290,52 +384,63 @@ var RateLimitError = class extends SDKError {
|
|
|
290
384
|
);
|
|
291
385
|
this.name = "RateLimitError";
|
|
292
386
|
this.retryAfter = retryAfter;
|
|
387
|
+
defineSDKErrorType(this, "RateLimitError");
|
|
293
388
|
}
|
|
294
389
|
};
|
|
390
|
+
function hasBrandedSDKErrorShape(error) {
|
|
391
|
+
if (error === null || typeof error !== "object") return false;
|
|
392
|
+
const candidate = error;
|
|
393
|
+
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";
|
|
394
|
+
}
|
|
395
|
+
function hasSDKErrorType(error, type) {
|
|
396
|
+
return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
|
|
397
|
+
}
|
|
295
398
|
function isSDKError(error) {
|
|
296
|
-
return error instanceof SDKError;
|
|
399
|
+
return error instanceof SDKError || hasBrandedSDKErrorShape(error);
|
|
297
400
|
}
|
|
298
401
|
function isNetworkError(error) {
|
|
299
|
-
return error instanceof NetworkError;
|
|
402
|
+
return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
|
|
300
403
|
}
|
|
301
404
|
function isValidationError(error) {
|
|
302
|
-
if (error instanceof ValidationError)
|
|
405
|
+
if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
303
408
|
if (error == null || typeof error !== "object") return false;
|
|
304
409
|
const candidate = error;
|
|
305
410
|
return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
306
411
|
}
|
|
307
412
|
function isApiError(error) {
|
|
308
|
-
return error instanceof ApiError;
|
|
413
|
+
return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
|
|
309
414
|
}
|
|
310
415
|
function isConfigError(error) {
|
|
311
|
-
return error instanceof ConfigError;
|
|
416
|
+
return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
|
|
312
417
|
}
|
|
313
418
|
function isTimeoutError(error) {
|
|
314
|
-
return error instanceof TimeoutError;
|
|
419
|
+
return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
|
|
315
420
|
}
|
|
316
421
|
function isGoneError(error) {
|
|
317
|
-
return error instanceof GoneError;
|
|
422
|
+
return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
|
|
318
423
|
}
|
|
319
424
|
function isServiceUnavailableError(error) {
|
|
320
|
-
return error instanceof ServiceUnavailableError;
|
|
425
|
+
return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
|
|
321
426
|
}
|
|
322
427
|
function isUsageLimitError(error) {
|
|
323
|
-
return error instanceof UsageLimitError;
|
|
428
|
+
return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
|
|
324
429
|
}
|
|
325
430
|
function isAuthError(error) {
|
|
326
|
-
return error instanceof AuthError;
|
|
431
|
+
return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
|
|
327
432
|
}
|
|
328
433
|
function isPermissionError(error) {
|
|
329
|
-
return error instanceof PermissionError;
|
|
434
|
+
return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
|
|
330
435
|
}
|
|
331
436
|
function isNotFoundError(error) {
|
|
332
|
-
return error instanceof NotFoundError;
|
|
437
|
+
return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
|
|
333
438
|
}
|
|
334
439
|
function isConflictError(error) {
|
|
335
|
-
return error instanceof ConflictError;
|
|
440
|
+
return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
|
|
336
441
|
}
|
|
337
442
|
function isRateLimitError(error) {
|
|
338
|
-
return error instanceof RateLimitError;
|
|
443
|
+
return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
|
|
339
444
|
}
|
|
340
445
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
341
446
|
var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
|
|
@@ -546,7 +651,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
|
|
|
546
651
|
if (retryAfter !== void 0) {
|
|
547
652
|
Object.assign(withRequestId, { retryAfter });
|
|
548
653
|
}
|
|
549
|
-
return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
|
|
654
|
+
return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
|
|
550
655
|
};
|
|
551
656
|
if (status === 400 || status === 422) {
|
|
552
657
|
return finalize(
|
|
@@ -733,7 +838,7 @@ async function httpFetch(url, options) {
|
|
|
733
838
|
),
|
|
734
839
|
requestId
|
|
735
840
|
);
|
|
736
|
-
throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
|
|
841
|
+
throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
|
|
737
842
|
}
|
|
738
843
|
if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
|
|
739
844
|
hasRetried401 = true;
|
|
@@ -1155,7 +1260,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1155
1260
|
return parsed;
|
|
1156
1261
|
}
|
|
1157
1262
|
const data = parsed;
|
|
1158
|
-
|
|
1263
|
+
const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
|
|
1264
|
+
(key) => Object.prototype.hasOwnProperty.call(data, key)
|
|
1265
|
+
);
|
|
1266
|
+
if (data.error || hasCommerceEnvelopeSignal) {
|
|
1159
1267
|
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
1160
1268
|
const reason = typeof data.reason === "string" ? data.reason : void 0;
|
|
1161
1269
|
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
@@ -1184,19 +1292,21 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1184
1292
|
}
|
|
1185
1293
|
const withRequestId = attachRequestId(error, requestId);
|
|
1186
1294
|
if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
|
|
1187
|
-
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
|
|
1295
|
+
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
|
|
1188
1296
|
}
|
|
1189
1297
|
return data;
|
|
1190
1298
|
}
|
|
1191
1299
|
|
|
1192
1300
|
// ../../internal/http-contracts/src/index.ts
|
|
1193
1301
|
var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
|
|
1194
|
-
var operation = (collection, method, path) => Object.freeze({
|
|
1302
|
+
var operation = (collection, method, path, errorFamily) => Object.freeze({
|
|
1195
1303
|
[operationBrand]: true,
|
|
1196
1304
|
collection,
|
|
1197
1305
|
method,
|
|
1198
|
-
path
|
|
1306
|
+
path,
|
|
1307
|
+
...errorFamily && { errorFamily }
|
|
1199
1308
|
});
|
|
1309
|
+
var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
|
|
1200
1310
|
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
1201
1311
|
products: {
|
|
1202
1312
|
detail: operation("products", "get", "/detail"),
|
|
@@ -1229,13 +1339,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1229
1339
|
byPayment: operation("orders", "get", "/by-payment"),
|
|
1230
1340
|
cancel: operation("orders", "post", "/cancel"),
|
|
1231
1341
|
resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
|
|
1232
|
-
checkout:
|
|
1342
|
+
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
1233
1343
|
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
1234
1344
|
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
1235
1345
|
},
|
|
1236
1346
|
checkouts: {
|
|
1237
|
-
detail:
|
|
1238
|
-
query:
|
|
1347
|
+
detail: strictCommerceOperation("checkouts", "post", "/detail"),
|
|
1348
|
+
query: strictCommerceOperation("checkouts", "post", "/query")
|
|
1239
1349
|
},
|
|
1240
1350
|
transactions: {
|
|
1241
1351
|
update: operation("transactions", "post", "/update")
|
|
@@ -1256,29 +1366,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1256
1366
|
bulkImport: operation("fulfillments", "post", "/bulk-import")
|
|
1257
1367
|
},
|
|
1258
1368
|
carts: {
|
|
1259
|
-
create:
|
|
1260
|
-
retrieve:
|
|
1261
|
-
mine:
|
|
1262
|
-
merge:
|
|
1263
|
-
addItem:
|
|
1264
|
-
updateItem:
|
|
1265
|
-
removeItem:
|
|
1266
|
-
updateDiscountCodes:
|
|
1267
|
-
|
|
1268
|
-
|
|
1369
|
+
create: strictCommerceOperation("carts", "post", "/create"),
|
|
1370
|
+
retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
|
|
1371
|
+
mine: strictCommerceOperation("carts", "post", "/mine"),
|
|
1372
|
+
merge: strictCommerceOperation("carts", "post", "/merge"),
|
|
1373
|
+
addItem: strictCommerceOperation("carts", "post", "/add-item"),
|
|
1374
|
+
updateItem: strictCommerceOperation("carts", "post", "/update-item"),
|
|
1375
|
+
removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
|
|
1376
|
+
updateDiscountCodes: strictCommerceOperation(
|
|
1377
|
+
"carts",
|
|
1378
|
+
"post",
|
|
1379
|
+
"/update-discount-codes"
|
|
1380
|
+
),
|
|
1381
|
+
updateAttributes: strictCommerceOperation(
|
|
1382
|
+
"carts",
|
|
1383
|
+
"post",
|
|
1384
|
+
"/update-attributes"
|
|
1385
|
+
),
|
|
1386
|
+
clear: strictCommerceOperation("carts", "post", "/clear")
|
|
1269
1387
|
},
|
|
1270
1388
|
paymentSessions: {
|
|
1271
|
-
create:
|
|
1272
|
-
retrieve:
|
|
1273
|
-
cancel:
|
|
1389
|
+
create: strictCommerceOperation("payment-sessions", "post", "/create"),
|
|
1390
|
+
retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
|
|
1391
|
+
cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
|
|
1274
1392
|
server: {
|
|
1275
|
-
create:
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1393
|
+
create: strictCommerceOperation(
|
|
1394
|
+
"payment-sessions",
|
|
1395
|
+
"post",
|
|
1396
|
+
"/server/create"
|
|
1397
|
+
),
|
|
1398
|
+
retrieve: strictCommerceOperation(
|
|
1399
|
+
"payment-sessions",
|
|
1400
|
+
"post",
|
|
1401
|
+
"/server/retrieve"
|
|
1402
|
+
),
|
|
1403
|
+
cancel: strictCommerceOperation(
|
|
1404
|
+
"payment-sessions",
|
|
1405
|
+
"post",
|
|
1406
|
+
"/server/cancel"
|
|
1407
|
+
),
|
|
1408
|
+
confirm: strictCommerceOperation(
|
|
1409
|
+
"payment-sessions",
|
|
1410
|
+
"post",
|
|
1411
|
+
"/server/confirm"
|
|
1412
|
+
)
|
|
1279
1413
|
},
|
|
1280
1414
|
custom: {
|
|
1281
1415
|
create: operation("orders", "post", "/custom-payment-sessions"),
|
|
1416
|
+
retrieve: operation(
|
|
1417
|
+
"orders",
|
|
1418
|
+
"post",
|
|
1419
|
+
"/custom-payment-sessions/retrieve"
|
|
1420
|
+
),
|
|
1282
1421
|
confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
|
|
1283
1422
|
}
|
|
1284
1423
|
},
|
|
@@ -1304,6 +1443,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
|
|
|
1304
1443
|
)
|
|
1305
1444
|
}
|
|
1306
1445
|
};
|
|
1446
|
+
var COMMUNITY_ENDPOINT_OPERATIONS = {
|
|
1447
|
+
posts: {
|
|
1448
|
+
detail: operation("posts", "get", "/detail")
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1307
1451
|
function resolveOperationTemplate(descriptor) {
|
|
1308
1452
|
return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
|
|
1309
1453
|
}
|
|
@@ -1335,6 +1479,9 @@ var sharedEndpoint = (descriptor) => descriptor;
|
|
|
1335
1479
|
function resolveOperationMethod2(descriptor) {
|
|
1336
1480
|
return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
|
|
1337
1481
|
}
|
|
1482
|
+
function resolveOperationErrorFamily(descriptor) {
|
|
1483
|
+
return "collection" in descriptor ? descriptor.errorFamily : void 0;
|
|
1484
|
+
}
|
|
1338
1485
|
function resolveOperationPath2(descriptor, options) {
|
|
1339
1486
|
if ("collection" in descriptor) {
|
|
1340
1487
|
return resolveOperationPath(descriptor, options);
|
|
@@ -1369,12 +1516,12 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1369
1516
|
updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
|
|
1370
1517
|
},
|
|
1371
1518
|
checkouts: {
|
|
1372
|
-
create:
|
|
1373
|
-
retrieve:
|
|
1519
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1520
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1374
1521
|
server: {
|
|
1375
|
-
create:
|
|
1376
|
-
retrieve:
|
|
1377
|
-
query:
|
|
1522
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1523
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1524
|
+
query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
|
|
1378
1525
|
}
|
|
1379
1526
|
},
|
|
1380
1527
|
returns: {
|
|
@@ -1392,10 +1539,10 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1392
1539
|
bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
|
|
1393
1540
|
},
|
|
1394
1541
|
carts: {
|
|
1395
|
-
create:
|
|
1542
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
|
|
1396
1543
|
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
|
|
1397
|
-
mine:
|
|
1398
|
-
merge:
|
|
1544
|
+
mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
|
|
1545
|
+
merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
|
|
1399
1546
|
server: {
|
|
1400
1547
|
// Server credentials are an authorization lane, not a second Cart
|
|
1401
1548
|
// transport. These must stay bound to the registered shared operations.
|
|
@@ -1415,29 +1562,46 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1415
1562
|
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1416
1563
|
},
|
|
1417
1564
|
addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
|
|
1418
|
-
updateItem:
|
|
1419
|
-
removeItem:
|
|
1420
|
-
updateDiscountCodes:
|
|
1421
|
-
|
|
1422
|
-
|
|
1565
|
+
updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
|
|
1566
|
+
removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
|
|
1567
|
+
updateDiscountCodes: sharedEndpoint(
|
|
1568
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
|
|
1569
|
+
),
|
|
1570
|
+
updateAttributes: sharedEndpoint(
|
|
1571
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
|
|
1572
|
+
),
|
|
1573
|
+
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1423
1574
|
},
|
|
1424
1575
|
paymentSessions: {
|
|
1425
|
-
create:
|
|
1426
|
-
retrieve:
|
|
1427
|
-
|
|
1576
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
|
|
1577
|
+
retrieve: sharedEndpoint(
|
|
1578
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
|
|
1579
|
+
),
|
|
1580
|
+
cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
|
|
1428
1581
|
custom: {
|
|
1429
1582
|
create: sharedEndpoint(
|
|
1430
1583
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
|
|
1431
1584
|
),
|
|
1585
|
+
retrieve: sharedEndpoint(
|
|
1586
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
|
|
1587
|
+
),
|
|
1432
1588
|
confirm: sharedEndpoint(
|
|
1433
1589
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
|
|
1434
1590
|
)
|
|
1435
1591
|
},
|
|
1436
1592
|
server: {
|
|
1437
|
-
create:
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1593
|
+
create: sharedEndpoint(
|
|
1594
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
|
|
1595
|
+
),
|
|
1596
|
+
retrieve: sharedEndpoint(
|
|
1597
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
1598
|
+
),
|
|
1599
|
+
cancel: sharedEndpoint(
|
|
1600
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
|
|
1601
|
+
),
|
|
1602
|
+
confirm: sharedEndpoint(
|
|
1603
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
|
|
1604
|
+
)
|
|
1441
1605
|
}
|
|
1442
1606
|
},
|
|
1443
1607
|
shippingPolicies: {
|
|
@@ -1528,7 +1692,8 @@ var CustomerScopedApi = class {
|
|
|
1528
1692
|
return this.transport.request(resolveOperationPath2(endpoint2, options), {
|
|
1529
1693
|
method: resolveOperationMethod2(endpoint2),
|
|
1530
1694
|
body,
|
|
1531
|
-
headers: options?.headers
|
|
1695
|
+
headers: options?.headers,
|
|
1696
|
+
errorFamily: resolveOperationErrorFamily(endpoint2)
|
|
1532
1697
|
});
|
|
1533
1698
|
}
|
|
1534
1699
|
};
|
|
@@ -1550,15 +1715,33 @@ function unwrapPayloadDoc(value) {
|
|
|
1550
1715
|
}
|
|
1551
1716
|
return value;
|
|
1552
1717
|
}
|
|
1718
|
+
function hasCanonicalNotFoundReason(error) {
|
|
1719
|
+
return getSDKErrorReason(error) === "not_found";
|
|
1720
|
+
}
|
|
1553
1721
|
var CommunityClient = class extends RawCustomerScopedApi {
|
|
1554
1722
|
constructor(options) {
|
|
1555
1723
|
super("CommunityClient", { ...options, requiresCredential: false });
|
|
1724
|
+
this.requiresSafePublicRawReads = !options.secretKey;
|
|
1556
1725
|
}
|
|
1557
1726
|
buildQuery(params) {
|
|
1558
1727
|
if (!params) return "";
|
|
1559
1728
|
const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
|
|
1560
1729
|
return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
|
|
1561
1730
|
}
|
|
1731
|
+
withSafePublicRawReadQuery(query) {
|
|
1732
|
+
if (!this.requiresSafePublicRawReads) return query;
|
|
1733
|
+
if (!query) return "?depth=0&joins=false";
|
|
1734
|
+
return `?depth=0&joins=false&${query.slice(1)}`;
|
|
1735
|
+
}
|
|
1736
|
+
buildSafePublicRawListQuery(params) {
|
|
1737
|
+
if (!this.requiresSafePublicRawReads) {
|
|
1738
|
+
return this.buildQuery(params);
|
|
1739
|
+
}
|
|
1740
|
+
const queryParams = {};
|
|
1741
|
+
if (params?.page !== void 0) queryParams.page = params.page;
|
|
1742
|
+
if (params?.limit !== void 0) queryParams.limit = params.limit;
|
|
1743
|
+
return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
|
|
1744
|
+
}
|
|
1562
1745
|
buildPostsListQuery(params) {
|
|
1563
1746
|
const urlParams = new URLSearchParams();
|
|
1564
1747
|
const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
|
|
@@ -1618,15 +1801,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1618
1801
|
"GET"
|
|
1619
1802
|
);
|
|
1620
1803
|
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Public post detail projected by the same allowlist as the public feed.
|
|
1806
|
+
* Missing, hidden, and cross-tenant posts all resolve to `null`.
|
|
1807
|
+
*/
|
|
1808
|
+
async getPost(params) {
|
|
1809
|
+
const query = new URLSearchParams({ postId: params.postId });
|
|
1810
|
+
try {
|
|
1811
|
+
return await this.execute(
|
|
1812
|
+
resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
|
|
1813
|
+
query
|
|
1814
|
+
}),
|
|
1815
|
+
resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
|
|
1816
|
+
);
|
|
1817
|
+
} catch (error) {
|
|
1818
|
+
if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
|
|
1819
|
+
return null;
|
|
1820
|
+
}
|
|
1821
|
+
throw error;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1621
1824
|
listPostCategories(params) {
|
|
1622
1825
|
return this.execute(
|
|
1623
|
-
`/api/post-categories${this.
|
|
1826
|
+
`/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
|
|
1624
1827
|
"GET"
|
|
1625
1828
|
);
|
|
1626
1829
|
}
|
|
1627
1830
|
listPostTags(params) {
|
|
1628
1831
|
return this.execute(
|
|
1629
|
-
`/api/post-tags${this.
|
|
1832
|
+
`/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
|
|
1630
1833
|
"GET"
|
|
1631
1834
|
);
|
|
1632
1835
|
}
|
|
@@ -1792,7 +1995,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1792
1995
|
}
|
|
1793
1996
|
getReactionTypes() {
|
|
1794
1997
|
return this.execute(
|
|
1795
|
-
|
|
1998
|
+
`/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
|
|
1796
1999
|
"GET"
|
|
1797
2000
|
);
|
|
1798
2001
|
}
|
|
@@ -1820,11 +2023,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1820
2023
|
}
|
|
1821
2024
|
// Profiles
|
|
1822
2025
|
listProfileLists(params) {
|
|
1823
|
-
return this.execute(
|
|
2026
|
+
return this.execute(
|
|
2027
|
+
`/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
|
|
2028
|
+
"GET"
|
|
2029
|
+
);
|
|
1824
2030
|
}
|
|
1825
2031
|
async getProfileList(params) {
|
|
1826
2032
|
const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
|
|
1827
|
-
const res = await this.execute(
|
|
2033
|
+
const res = await this.execute(
|
|
2034
|
+
`/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
|
|
2035
|
+
"GET"
|
|
2036
|
+
);
|
|
1828
2037
|
return res.docs[0] ?? null;
|
|
1829
2038
|
}
|
|
1830
2039
|
updatePublicProfile(body) {
|
|
@@ -1937,7 +2146,7 @@ var ORDER_PRIMARY_DISPLAY_STATUSES = [
|
|
|
1937
2146
|
];
|
|
1938
2147
|
var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
|
|
1939
2148
|
var ABANDONED_REASONS = ["expired", "customer", "operator"];
|
|
1940
|
-
var PAYMENT_PROVIDERS = ["toss"];
|
|
2149
|
+
var PAYMENT_PROVIDERS = ["toss", "portone"];
|
|
1941
2150
|
var PAYMENT_PROVIDER_STATUSES = [
|
|
1942
2151
|
"requires_payment_method",
|
|
1943
2152
|
"requires_action",
|
|
@@ -3110,8 +3319,101 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
|
|
|
3110
3319
|
previous = current;
|
|
3111
3320
|
});
|
|
3112
3321
|
}
|
|
3113
|
-
function validateNextAction(value, resource, path) {
|
|
3322
|
+
function validateNextAction(value, provider, resource, path) {
|
|
3114
3323
|
const action = record(value, resource, path);
|
|
3324
|
+
if (provider === "portone") {
|
|
3325
|
+
if (action.type === "portone_sdk") {
|
|
3326
|
+
exact(
|
|
3327
|
+
action,
|
|
3328
|
+
[
|
|
3329
|
+
"type",
|
|
3330
|
+
"version",
|
|
3331
|
+
"storeId",
|
|
3332
|
+
"channelKey",
|
|
3333
|
+
"paymentId",
|
|
3334
|
+
"orderName",
|
|
3335
|
+
"totalAmount",
|
|
3336
|
+
"currency",
|
|
3337
|
+
"payMethod",
|
|
3338
|
+
"redirectUrl"
|
|
3339
|
+
],
|
|
3340
|
+
[],
|
|
3341
|
+
resource,
|
|
3342
|
+
path
|
|
3343
|
+
);
|
|
3344
|
+
if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
|
|
3345
|
+
for (const key of ["storeId", "channelKey"]) {
|
|
3346
|
+
boundedString(action[key], 255, resource, `${path}.${key}`);
|
|
3347
|
+
}
|
|
3348
|
+
const paymentId = boundedString(
|
|
3349
|
+
action.paymentId,
|
|
3350
|
+
40,
|
|
3351
|
+
resource,
|
|
3352
|
+
`${path}.paymentId`
|
|
3353
|
+
);
|
|
3354
|
+
if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
|
|
3355
|
+
fail(
|
|
3356
|
+
resource,
|
|
3357
|
+
`${path}.paymentId`,
|
|
3358
|
+
"6-40 ASCII alphanumeric characters"
|
|
3359
|
+
);
|
|
3360
|
+
}
|
|
3361
|
+
boundedString(
|
|
3362
|
+
action.orderName,
|
|
3363
|
+
MAX_COMMERCE_SHORT_TEXT_LENGTH,
|
|
3364
|
+
resource,
|
|
3365
|
+
`${path}.orderName`
|
|
3366
|
+
);
|
|
3367
|
+
positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
|
|
3368
|
+
if (action.currency !== "CURRENCY_KRW") {
|
|
3369
|
+
fail(resource, `${path}.currency`, "CURRENCY_KRW");
|
|
3370
|
+
}
|
|
3371
|
+
if (action.payMethod !== "CARD")
|
|
3372
|
+
fail(resource, `${path}.payMethod`, "CARD");
|
|
3373
|
+
const redirectUrl = boundedString(
|
|
3374
|
+
action.redirectUrl,
|
|
3375
|
+
2048,
|
|
3376
|
+
resource,
|
|
3377
|
+
`${path}.redirectUrl`
|
|
3378
|
+
);
|
|
3379
|
+
try {
|
|
3380
|
+
const parsed = new URL(redirectUrl);
|
|
3381
|
+
const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
|
|
3382
|
+
if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
|
|
3383
|
+
throw new Error("unsafe redirect URL");
|
|
3384
|
+
} catch {
|
|
3385
|
+
fail(
|
|
3386
|
+
resource,
|
|
3387
|
+
`${path}.redirectUrl`,
|
|
3388
|
+
"HTTPS or loopback URL without embedded credentials"
|
|
3389
|
+
);
|
|
3390
|
+
}
|
|
3391
|
+
return;
|
|
3392
|
+
}
|
|
3393
|
+
exact(action, ["type", "checkoutUrl"], [], resource, path);
|
|
3394
|
+
if (action.type !== "portone_checkout") {
|
|
3395
|
+
fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
|
|
3396
|
+
}
|
|
3397
|
+
const checkoutUrl = boundedString(
|
|
3398
|
+
action.checkoutUrl,
|
|
3399
|
+
2048,
|
|
3400
|
+
resource,
|
|
3401
|
+
`${path}.checkoutUrl`
|
|
3402
|
+
);
|
|
3403
|
+
try {
|
|
3404
|
+
const parsed = new URL(checkoutUrl);
|
|
3405
|
+
if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
|
|
3406
|
+
throw new Error("unsafe checkout URL");
|
|
3407
|
+
}
|
|
3408
|
+
} catch {
|
|
3409
|
+
fail(
|
|
3410
|
+
resource,
|
|
3411
|
+
`${path}.checkoutUrl`,
|
|
3412
|
+
"absolute HTTPS URL without embedded credentials"
|
|
3413
|
+
);
|
|
3414
|
+
}
|
|
3415
|
+
return;
|
|
3416
|
+
}
|
|
3115
3417
|
exact(
|
|
3116
3418
|
action,
|
|
3117
3419
|
[
|
|
@@ -3162,10 +3464,18 @@ function validateNextAction(value, resource, path) {
|
|
|
3162
3464
|
if (action.customerEmail !== void 0)
|
|
3163
3465
|
validateCustomer({ email: action.customerEmail }, resource, path);
|
|
3164
3466
|
}
|
|
3165
|
-
function validatePublicPaymentSession(value) {
|
|
3467
|
+
function validatePublicPaymentSession(value, expectedProvider) {
|
|
3166
3468
|
const resource = "PaymentSession";
|
|
3167
3469
|
const session = record(value, resource, "$");
|
|
3168
|
-
|
|
3470
|
+
const provider = enumValue(
|
|
3471
|
+
session.provider,
|
|
3472
|
+
PAYMENT_PROVIDERS,
|
|
3473
|
+
resource,
|
|
3474
|
+
"$.provider"
|
|
3475
|
+
);
|
|
3476
|
+
if (expectedProvider !== void 0 && provider !== expectedProvider) {
|
|
3477
|
+
fail(resource, "$.provider", expectedProvider);
|
|
3478
|
+
}
|
|
3169
3479
|
const status = enumValue(
|
|
3170
3480
|
session.providerStatus,
|
|
3171
3481
|
PAYMENT_PROVIDER_STATUSES,
|
|
@@ -3202,7 +3512,12 @@ function validatePublicPaymentSession(value) {
|
|
|
3202
3512
|
}
|
|
3203
3513
|
if (!("nextAction" in session))
|
|
3204
3514
|
fail(resource, "$.nextAction", "required field");
|
|
3205
|
-
validateNextAction(
|
|
3515
|
+
validateNextAction(
|
|
3516
|
+
session.nextAction,
|
|
3517
|
+
provider,
|
|
3518
|
+
resource,
|
|
3519
|
+
"$.nextAction"
|
|
3520
|
+
);
|
|
3206
3521
|
} else if (session.sessionRole === "residual") {
|
|
3207
3522
|
if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
|
|
3208
3523
|
fail(resource, "$", "suppressed residual not-ready state");
|
|
@@ -3945,8 +4260,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
3945
4260
|
}
|
|
3946
4261
|
});
|
|
3947
4262
|
}
|
|
3948
|
-
async paymentSession(result) {
|
|
3949
|
-
return validatePublicPaymentSession(await result);
|
|
4263
|
+
async paymentSession(result, expectedProvider) {
|
|
4264
|
+
return validatePublicPaymentSession(await result, expectedProvider);
|
|
3950
4265
|
}
|
|
3951
4266
|
create(params) {
|
|
3952
4267
|
const { idempotencyKey, ...body } = params;
|
|
@@ -3956,18 +4271,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
3956
4271
|
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
3957
4272
|
body,
|
|
3958
4273
|
idempotencyKey
|
|
3959
|
-
)
|
|
4274
|
+
),
|
|
4275
|
+
"toss"
|
|
4276
|
+
);
|
|
4277
|
+
}
|
|
4278
|
+
createPortOne(params) {
|
|
4279
|
+
const { idempotencyKey, ...body } = params;
|
|
4280
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4281
|
+
return this.paymentSession(
|
|
4282
|
+
this.post(
|
|
4283
|
+
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
4284
|
+
body,
|
|
4285
|
+
idempotencyKey
|
|
4286
|
+
),
|
|
4287
|
+
"portone"
|
|
3960
4288
|
);
|
|
3961
4289
|
}
|
|
3962
4290
|
retrieve(params) {
|
|
3963
4291
|
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
3964
|
-
return this.paymentSession(
|
|
4292
|
+
return this.paymentSession(
|
|
4293
|
+
this.post(endpoint2, params),
|
|
4294
|
+
"toss"
|
|
4295
|
+
);
|
|
4296
|
+
}
|
|
4297
|
+
retrievePortOne(params) {
|
|
4298
|
+
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
4299
|
+
return this.paymentSession(
|
|
4300
|
+
this.post(endpoint2, params),
|
|
4301
|
+
"portone"
|
|
4302
|
+
);
|
|
3965
4303
|
}
|
|
3966
4304
|
cancel(params) {
|
|
3967
4305
|
const { idempotencyKey, ...body } = params;
|
|
3968
4306
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
3969
4307
|
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
3970
|
-
return this.paymentSession(
|
|
4308
|
+
return this.paymentSession(
|
|
4309
|
+
this.post(endpoint2, body, idempotencyKey),
|
|
4310
|
+
"toss"
|
|
4311
|
+
);
|
|
4312
|
+
}
|
|
4313
|
+
cancelPortOne(params) {
|
|
4314
|
+
const { idempotencyKey, ...body } = params;
|
|
4315
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
4316
|
+
const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
4317
|
+
return this.paymentSession(
|
|
4318
|
+
this.post(endpoint2, body, idempotencyKey),
|
|
4319
|
+
"portone"
|
|
4320
|
+
);
|
|
3971
4321
|
}
|
|
3972
4322
|
confirm(params) {
|
|
3973
4323
|
const { idempotencyKey, ...body } = params;
|
|
@@ -3977,7 +4327,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
3977
4327
|
COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
|
|
3978
4328
|
body,
|
|
3979
4329
|
idempotencyKey
|
|
3980
|
-
)
|
|
4330
|
+
),
|
|
4331
|
+
"toss"
|
|
3981
4332
|
);
|
|
3982
4333
|
}
|
|
3983
4334
|
};
|
|
@@ -5716,21 +6067,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
|
|
|
5716
6067
|
"not_published",
|
|
5717
6068
|
"feature_disabled"
|
|
5718
6069
|
]);
|
|
5719
|
-
function isRecord(value) {
|
|
5720
|
-
return typeof value === "object" && value !== null;
|
|
5721
|
-
}
|
|
5722
|
-
function readProductDetailUnavailableReason(value) {
|
|
5723
|
-
if (!isRecord(value)) return void 0;
|
|
5724
|
-
const directReason = value.reason ?? value.code;
|
|
5725
|
-
if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
|
|
5726
|
-
return directReason;
|
|
5727
|
-
}
|
|
5728
|
-
return readProductDetailUnavailableReason(value.body);
|
|
5729
|
-
}
|
|
5730
6070
|
function productDetailResultFromError(error) {
|
|
5731
6071
|
if (!(error instanceof SDKError) || error.status !== 404) return void 0;
|
|
5732
|
-
const reason =
|
|
5733
|
-
if (!reason
|
|
6072
|
+
const reason = getSDKErrorReason(error);
|
|
6073
|
+
if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
|
|
6074
|
+
return void 0;
|
|
5734
6075
|
return { found: false, reason };
|
|
5735
6076
|
}
|
|
5736
6077
|
var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
|
|
@@ -5947,8 +6288,11 @@ var CommerceClient = class {
|
|
|
5947
6288
|
};
|
|
5948
6289
|
this.paymentSessions = {
|
|
5949
6290
|
create: paymentSessionApi.create.bind(paymentSessionApi),
|
|
6291
|
+
createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
|
|
5950
6292
|
retrieve: (params) => paymentSessionApi.retrieve(params),
|
|
5951
|
-
|
|
6293
|
+
retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
|
|
6294
|
+
cancel: (params) => paymentSessionApi.cancel(params),
|
|
6295
|
+
cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params)
|
|
5952
6296
|
};
|
|
5953
6297
|
this.discounts = {
|
|
5954
6298
|
validate: (params) => api.requestEndpoint(
|
|
@@ -6324,7 +6668,7 @@ function isStringOrNumber(value) {
|
|
|
6324
6668
|
return typeof value === "string" || typeof value === "number";
|
|
6325
6669
|
}
|
|
6326
6670
|
function isWebhookOrderScope(value) {
|
|
6327
|
-
if (!
|
|
6671
|
+
if (!isRecord(value)) return false;
|
|
6328
6672
|
if (value.kind === "collection") {
|
|
6329
6673
|
return typeof value.collection === "string";
|
|
6330
6674
|
}
|
|
@@ -6334,14 +6678,14 @@ function isWebhookOrderScope(value) {
|
|
|
6334
6678
|
return false;
|
|
6335
6679
|
}
|
|
6336
6680
|
function isWebhookOrderMoved(value) {
|
|
6337
|
-
if (!
|
|
6681
|
+
if (!isRecord(value)) return false;
|
|
6338
6682
|
return typeof value.collection === "string" && isStringOrNumber(value.id) && (value.relatedCollection === void 0 || typeof value.relatedCollection === "string") && (value.relatedId === void 0 || isStringOrNumber(value.relatedId));
|
|
6339
6683
|
}
|
|
6340
6684
|
function hasOptionalOrderValue(value, key) {
|
|
6341
6685
|
return value[key] === void 0 || value[key] === null || typeof value[key] === "string";
|
|
6342
6686
|
}
|
|
6343
6687
|
function isWebhookOrderChange(value) {
|
|
6344
|
-
if (!
|
|
6688
|
+
if (!isRecord(value)) return false;
|
|
6345
6689
|
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);
|
|
6346
6690
|
}
|
|
6347
6691
|
function isCommerceNotificationEventName(value) {
|
|
@@ -6351,18 +6695,18 @@ function isCommerceNotificationSourceCollection(value) {
|
|
|
6351
6695
|
return value === "orders" || value === "fulfillments" || value === "returns";
|
|
6352
6696
|
}
|
|
6353
6697
|
function isCommerceNotificationData(value) {
|
|
6354
|
-
if (!
|
|
6355
|
-
if (value.source !== void 0 && (!
|
|
6698
|
+
if (!isRecord(value)) return false;
|
|
6699
|
+
if (value.source !== void 0 && (!isRecord(value.source) || !isCommerceNotificationSourceCollection(value.source.collection) || !isStringOrNumber(value.source.id))) {
|
|
6356
6700
|
return false;
|
|
6357
6701
|
}
|
|
6358
6702
|
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");
|
|
6359
6703
|
}
|
|
6360
6704
|
function isCommerceNotification(value) {
|
|
6361
|
-
if (!
|
|
6705
|
+
if (!isRecord(value)) return false;
|
|
6362
6706
|
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");
|
|
6363
6707
|
}
|
|
6364
6708
|
function isWebhookCommerceNotificationChange(value) {
|
|
6365
|
-
if (!
|
|
6709
|
+
if (!isRecord(value)) return false;
|
|
6366
6710
|
return value.type === "notification" && value.source === "commerce-notifications" && isCommerceNotificationEventName(value.event) && isCommerceNotificationSourceCollection(value.sourceCollection) && isStringOrNumber(value.sourceId);
|
|
6367
6711
|
}
|
|
6368
6712
|
function matchesOptionalId(actual, expected) {
|
|
@@ -6444,7 +6788,7 @@ function isWebhookOperation(event, operation2) {
|
|
|
6444
6788
|
return isValidWebhookEvent(event) && event.operation === operation2;
|
|
6445
6789
|
}
|
|
6446
6790
|
var CUSTOMER_PASSWORD_RESET_OPERATION = "password-reset";
|
|
6447
|
-
function
|
|
6791
|
+
function isRecord(value) {
|
|
6448
6792
|
return typeof value === "object" && value !== null;
|
|
6449
6793
|
}
|
|
6450
6794
|
function hasString(value, key) {
|
|
@@ -6454,7 +6798,7 @@ function hasStringOrNumber(value, key) {
|
|
|
6454
6798
|
return typeof value[key] === "string" || typeof value[key] === "number";
|
|
6455
6799
|
}
|
|
6456
6800
|
function isCustomerPasswordResetWebhookEvent(event) {
|
|
6457
|
-
if (event.collection !== "customers" || event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION || !
|
|
6801
|
+
if (event.collection !== "customers" || event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION || !isRecord(event.data)) {
|
|
6458
6802
|
return false;
|
|
6459
6803
|
}
|
|
6460
6804
|
return hasStringOrNumber(event.data, "customerId") && hasString(event.data, "email") && hasString(event.data, "name") && hasString(event.data, "resetPasswordToken") && hasString(event.data, "resetPasswordExpiresAt");
|
|
@@ -6609,7 +6953,6 @@ var INTERNAL_COLLECTIONS = [
|
|
|
6609
6953
|
"payment-provider-customer-aliases"
|
|
6610
6954
|
];
|
|
6611
6955
|
var COLLECTIONS = [
|
|
6612
|
-
"tenants",
|
|
6613
6956
|
"tenant-metadata",
|
|
6614
6957
|
"products",
|
|
6615
6958
|
"product-variants",
|
|
@@ -6669,6 +7012,10 @@ var COLLECTIONS = [
|
|
|
6669
7012
|
"customer-memberships"
|
|
6670
7013
|
];
|
|
6671
7014
|
var SERVER_ONLY_COLLECTIONS = [
|
|
7015
|
+
// The tenant record itself denies reads without an authenticated user, so a
|
|
7016
|
+
// publishable key never reaches it; `tenant-metadata` is the browser-public
|
|
7017
|
+
// tenant identity surface.
|
|
7018
|
+
"tenants",
|
|
6672
7019
|
"tenant-logos",
|
|
6673
7020
|
"brand-logos",
|
|
6674
7021
|
"images",
|
|
@@ -7404,6 +7751,7 @@ export {
|
|
|
7404
7751
|
getImageSrcSet,
|
|
7405
7752
|
getImageUrl,
|
|
7406
7753
|
getProductSelectionImages,
|
|
7754
|
+
getSDKErrorReason,
|
|
7407
7755
|
getSelectedValueByOptionId,
|
|
7408
7756
|
getVariantAvailableForSale,
|
|
7409
7757
|
getVariantAvailableStock,
|