@01.software/sdk 0.48.0 → 0.51.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 +157 -1
- package/MIGRATION.md +56 -0
- package/README.md +276 -49
- package/dist/client.cjs +375 -161
- 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 +375 -161
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-CBup9yOx.d.cts → collection-client-CWAeuzV4.d.cts} +6 -4
- package/dist/{collection-client-D3ExJU-7.d.ts → collection-client-hYvVfHIm.d.ts} +6 -4
- package/dist/{const-k9gHylYa.d.ts → const-D8LixhAJ.d.cts} +5 -5
- package/dist/{const-BXEi1Kix.d.cts → const-JD8obaKg.d.ts} +5 -5
- package/dist/embedded-admin/server.cjs +306 -0
- package/dist/embedded-admin/server.cjs.map +1 -0
- package/dist/embedded-admin/server.d.cts +33 -0
- package/dist/embedded-admin/server.d.ts +33 -0
- package/dist/embedded-admin/server.js +288 -0
- package/dist/embedded-admin/server.js.map +1 -0
- package/dist/embedded-admin.cjs +400 -0
- package/dist/embedded-admin.cjs.map +1 -0
- package/dist/embedded-admin.d.cts +61 -0
- package/dist/embedded-admin.d.ts +61 -0
- package/dist/embedded-admin.js +377 -0
- package/dist/embedded-admin.js.map +1 -0
- package/dist/errors.cjs +64 -15
- 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 +64 -15
- package/dist/errors.js.map +1 -1
- package/dist/{index-BCM9CTL7.d.cts → index-B0Hjh3Ey.d.ts} +72 -10
- package/dist/{index-CHGGkcLj.d.ts → index-Bu0kCc6o.d.cts} +72 -10
- package/dist/index.cjs +470 -429
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -67
- package/dist/index.d.ts +9 -67
- package/dist/index.js +470 -429
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-B6AZQcB7.d.cts → payload-types-BOsckg8B.d.cts} +396 -57
- package/dist/{payload-types-B6AZQcB7.d.ts → payload-types-BOsckg8B.d.ts} +396 -57
- package/dist/query.cjs +115 -70
- 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 +115 -70
- 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 +591 -186
- 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 +591 -186
- package/dist/server.js.map +1 -1
- package/dist/storefront-cache.cjs +22 -0
- package/dist/storefront-cache.cjs.map +1 -1
- package/dist/storefront-cache.js +22 -0
- package/dist/storefront-cache.js.map +1 -1
- package/dist/{types-ByD2zii1.d.ts → types-5ZlcAFuU.d.ts} +2 -2
- package/dist/{types-8us-_C-Q.d.cts → types-B14sEt1z.d.cts} +2 -2
- package/dist/{types-CM2je9Kw.d.cts → types-Bj8j7VHU.d.ts} +107 -26
- package/dist/{types-DbA5V3mt.d.ts → types-CM5qiR2k.d.cts} +107 -26
- 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.cjs +124 -80
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +21 -5
- package/dist/webhook.d.ts +21 -5
- package/dist/webhook.js +124 -80
- package/dist/webhook.js.map +1 -1
- package/package.json +27 -5
package/dist/server.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
|
};
|
|
@@ -77,6 +97,7 @@ var COMMERCE_ERROR_CODES = [
|
|
|
77
97
|
"payment_session_not_cancelable",
|
|
78
98
|
"payment_session_conflict",
|
|
79
99
|
"provider_identity_mismatch",
|
|
100
|
+
"managed_refund_attestation_forbidden",
|
|
80
101
|
"payment_method_unavailable",
|
|
81
102
|
"provider_unavailable",
|
|
82
103
|
"lock_timeout",
|
|
@@ -205,8 +226,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
|
|
|
205
226
|
});
|
|
206
227
|
return error;
|
|
207
228
|
}
|
|
229
|
+
function enhanceNonCommerceError(error, reason) {
|
|
230
|
+
if (typeof reason === "string") Object.assign(error, { apiReason: reason });
|
|
231
|
+
return error;
|
|
232
|
+
}
|
|
233
|
+
function getSDKErrorReason(error) {
|
|
234
|
+
if (error.kind !== "commerce") return error.apiReason;
|
|
235
|
+
return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
|
|
236
|
+
}
|
|
208
237
|
function isCommerceSDKError(error) {
|
|
209
|
-
if (!(error
|
|
238
|
+
if (!isSDKError(error) || error.kind !== "commerce") return false;
|
|
210
239
|
if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
|
|
211
240
|
return false;
|
|
212
241
|
}
|
|
@@ -216,12 +245,14 @@ var NetworkError = class extends SDKError {
|
|
|
216
245
|
constructor(message, status, details, userMessage, suggestion) {
|
|
217
246
|
super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
|
|
218
247
|
this.name = "NetworkError";
|
|
248
|
+
defineSDKErrorType(this, "NetworkError");
|
|
219
249
|
}
|
|
220
250
|
};
|
|
221
251
|
var ValidationError = class extends SDKError {
|
|
222
252
|
constructor(message, details, userMessage, suggestion, status = 400) {
|
|
223
253
|
super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
|
|
224
254
|
this.name = "ValidationError";
|
|
255
|
+
defineSDKErrorType(this, "ValidationError");
|
|
225
256
|
}
|
|
226
257
|
};
|
|
227
258
|
var ApiError = class extends SDKError {
|
|
@@ -236,24 +267,28 @@ var ApiError = class extends SDKError {
|
|
|
236
267
|
requestId
|
|
237
268
|
);
|
|
238
269
|
this.name = "ApiError";
|
|
270
|
+
defineSDKErrorType(this, "ApiError");
|
|
239
271
|
}
|
|
240
272
|
};
|
|
241
273
|
var ConfigError = class extends SDKError {
|
|
242
274
|
constructor(message, details, userMessage, suggestion) {
|
|
243
275
|
super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
|
|
244
276
|
this.name = "ConfigError";
|
|
277
|
+
defineSDKErrorType(this, "ConfigError");
|
|
245
278
|
}
|
|
246
279
|
};
|
|
247
280
|
var TimeoutError = class extends SDKError {
|
|
248
281
|
constructor(message = "Request timed out.", details, userMessage, suggestion) {
|
|
249
282
|
super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
|
|
250
283
|
this.name = "TimeoutError";
|
|
284
|
+
defineSDKErrorType(this, "TimeoutError");
|
|
251
285
|
}
|
|
252
286
|
};
|
|
253
287
|
var GoneError = class extends SDKError {
|
|
254
288
|
constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
|
|
255
289
|
super("GONE_ERROR", message, 410, details, userMessage, suggestion);
|
|
256
290
|
this.name = "GoneError";
|
|
291
|
+
defineSDKErrorType(this, "GoneError");
|
|
257
292
|
}
|
|
258
293
|
};
|
|
259
294
|
var ServiceUnavailableError = class extends SDKError {
|
|
@@ -268,6 +303,7 @@ var ServiceUnavailableError = class extends SDKError {
|
|
|
268
303
|
);
|
|
269
304
|
this.name = "ServiceUnavailableError";
|
|
270
305
|
this.retryAfter = retryAfter;
|
|
306
|
+
defineSDKErrorType(this, "ServiceUnavailableError");
|
|
271
307
|
}
|
|
272
308
|
};
|
|
273
309
|
var UsageLimitError = class extends SDKError {
|
|
@@ -275,6 +311,7 @@ var UsageLimitError = class extends SDKError {
|
|
|
275
311
|
super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
|
|
276
312
|
this.name = "UsageLimitError";
|
|
277
313
|
this.usage = usage;
|
|
314
|
+
defineSDKErrorType(this, "UsageLimitError");
|
|
278
315
|
}
|
|
279
316
|
toJSON() {
|
|
280
317
|
return {
|
|
@@ -295,6 +332,7 @@ var AuthError = class extends SDKError {
|
|
|
295
332
|
requestId
|
|
296
333
|
);
|
|
297
334
|
this.name = "AuthError";
|
|
335
|
+
defineSDKErrorType(this, "AuthError");
|
|
298
336
|
}
|
|
299
337
|
};
|
|
300
338
|
var PermissionError = class extends SDKError {
|
|
@@ -309,6 +347,7 @@ var PermissionError = class extends SDKError {
|
|
|
309
347
|
requestId
|
|
310
348
|
);
|
|
311
349
|
this.name = "PermissionError";
|
|
350
|
+
defineSDKErrorType(this, "PermissionError");
|
|
312
351
|
}
|
|
313
352
|
};
|
|
314
353
|
var NotFoundError = class extends SDKError {
|
|
@@ -323,12 +362,14 @@ var NotFoundError = class extends SDKError {
|
|
|
323
362
|
requestId
|
|
324
363
|
);
|
|
325
364
|
this.name = "NotFoundError";
|
|
365
|
+
defineSDKErrorType(this, "NotFoundError");
|
|
326
366
|
}
|
|
327
367
|
};
|
|
328
368
|
var ConflictError = class extends SDKError {
|
|
329
369
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
330
370
|
super("conflict", message, 409, details, userMessage, suggestion, requestId);
|
|
331
371
|
this.name = "ConflictError";
|
|
372
|
+
defineSDKErrorType(this, "ConflictError");
|
|
332
373
|
}
|
|
333
374
|
};
|
|
334
375
|
var RateLimitError = class extends SDKError {
|
|
@@ -344,8 +385,64 @@ var RateLimitError = class extends SDKError {
|
|
|
344
385
|
);
|
|
345
386
|
this.name = "RateLimitError";
|
|
346
387
|
this.retryAfter = retryAfter;
|
|
388
|
+
defineSDKErrorType(this, "RateLimitError");
|
|
347
389
|
}
|
|
348
390
|
};
|
|
391
|
+
function hasBrandedSDKErrorShape(error) {
|
|
392
|
+
if (error === null || typeof error !== "object") return false;
|
|
393
|
+
const candidate = error;
|
|
394
|
+
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";
|
|
395
|
+
}
|
|
396
|
+
function hasSDKErrorType(error, type) {
|
|
397
|
+
return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
|
|
398
|
+
}
|
|
399
|
+
function isSDKError(error) {
|
|
400
|
+
return error instanceof SDKError || hasBrandedSDKErrorShape(error);
|
|
401
|
+
}
|
|
402
|
+
function isNetworkError(error) {
|
|
403
|
+
return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
|
|
404
|
+
}
|
|
405
|
+
function isValidationError(error) {
|
|
406
|
+
if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
if (error == null || typeof error !== "object") return false;
|
|
410
|
+
const candidate = error;
|
|
411
|
+
return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
|
|
412
|
+
}
|
|
413
|
+
function isApiError(error) {
|
|
414
|
+
return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
|
|
415
|
+
}
|
|
416
|
+
function isConfigError(error) {
|
|
417
|
+
return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
|
|
418
|
+
}
|
|
419
|
+
function isTimeoutError(error) {
|
|
420
|
+
return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
|
|
421
|
+
}
|
|
422
|
+
function isGoneError(error) {
|
|
423
|
+
return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
|
|
424
|
+
}
|
|
425
|
+
function isServiceUnavailableError(error) {
|
|
426
|
+
return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
|
|
427
|
+
}
|
|
428
|
+
function isUsageLimitError(error) {
|
|
429
|
+
return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
|
|
430
|
+
}
|
|
431
|
+
function isAuthError(error) {
|
|
432
|
+
return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
|
|
433
|
+
}
|
|
434
|
+
function isPermissionError(error) {
|
|
435
|
+
return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
|
|
436
|
+
}
|
|
437
|
+
function isNotFoundError(error) {
|
|
438
|
+
return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
|
|
439
|
+
}
|
|
440
|
+
function isConflictError(error) {
|
|
441
|
+
return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
|
|
442
|
+
}
|
|
443
|
+
function isRateLimitError(error) {
|
|
444
|
+
return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
|
|
445
|
+
}
|
|
349
446
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
350
447
|
var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
|
|
351
448
|
var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
|
|
@@ -543,11 +640,11 @@ function parseRetryAfter(response) {
|
|
|
543
640
|
permitsAutomaticRetry: seconds <= MAX_AUTOMATIC_RETRY_AFTER_SECONDS
|
|
544
641
|
};
|
|
545
642
|
}
|
|
546
|
-
function mapResponseToError(status, parsed, details, requestId, retryAfter,
|
|
643
|
+
function mapResponseToError(status, parsed, details, requestId, retryAfter, canonicalCommerceError) {
|
|
547
644
|
const errorDetails = {
|
|
548
645
|
...details,
|
|
549
646
|
...parsed.errors && { errors: parsed.errors },
|
|
550
|
-
|
|
647
|
+
...!canonicalCommerceError && parsed.body && { body: parsed.body }
|
|
551
648
|
};
|
|
552
649
|
const suggestion = getParsedErrorSuggestion(status, parsed);
|
|
553
650
|
const finalize = (error) => {
|
|
@@ -555,7 +652,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
|
|
|
555
652
|
if (retryAfter !== void 0) {
|
|
556
653
|
Object.assign(withRequestId, { retryAfter });
|
|
557
654
|
}
|
|
558
|
-
return
|
|
655
|
+
return canonicalCommerceError ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
|
|
559
656
|
};
|
|
560
657
|
if (status === 400 || status === 422) {
|
|
561
658
|
return finalize(
|
|
@@ -661,6 +758,7 @@ async function httpFetch(url, options) {
|
|
|
661
758
|
retry,
|
|
662
759
|
onUnauthorized,
|
|
663
760
|
errorFamily,
|
|
761
|
+
typedCommerceErrorReasons,
|
|
664
762
|
...requestInit
|
|
665
763
|
} = options || {};
|
|
666
764
|
const baseUrl = resolveApiUrl(apiUrl);
|
|
@@ -714,7 +812,8 @@ async function httpFetch(url, options) {
|
|
|
714
812
|
});
|
|
715
813
|
if (!response.ok) {
|
|
716
814
|
const parsed = await parseErrorBody(response);
|
|
717
|
-
const
|
|
815
|
+
const canonicalCommerceError = errorFamily === "commerce" || typeof parsed.reason === "string" && typedCommerceErrorReasons?.includes(parsed.reason) === true;
|
|
816
|
+
const commerceEnvelope = canonicalCommerceError ? parseCommerceErrorEnvelope(parsed.body, requestId) : void 0;
|
|
718
817
|
if (isUsageLimitExceededResponse(response)) {
|
|
719
818
|
const limit = parseInt(
|
|
720
819
|
response.headers.get("X-Usage-Limit") || "0",
|
|
@@ -742,7 +841,7 @@ async function httpFetch(url, options) {
|
|
|
742
841
|
),
|
|
743
842
|
requestId
|
|
744
843
|
);
|
|
745
|
-
throw
|
|
844
|
+
throw canonicalCommerceError ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
|
|
746
845
|
}
|
|
747
846
|
if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
|
|
748
847
|
hasRetried401 = true;
|
|
@@ -767,7 +866,7 @@ async function httpFetch(url, options) {
|
|
|
767
866
|
details,
|
|
768
867
|
requestId,
|
|
769
868
|
retryAfter.seconds,
|
|
770
|
-
|
|
869
|
+
canonicalCommerceError
|
|
771
870
|
);
|
|
772
871
|
const method2 = (requestInit.method || "GET").toUpperCase();
|
|
773
872
|
const isTerminal = error instanceof RateLimitError || error instanceof UsageLimitError;
|
|
@@ -945,15 +1044,15 @@ var HttpClient = class {
|
|
|
945
1044
|
throw err;
|
|
946
1045
|
}
|
|
947
1046
|
}
|
|
948
|
-
buildUrl(
|
|
949
|
-
if (!options) return
|
|
1047
|
+
buildUrl(endpoint, options) {
|
|
1048
|
+
if (!options) return endpoint;
|
|
950
1049
|
const { fallbackLocale, ...rest } = options;
|
|
951
1050
|
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
952
1051
|
...rest,
|
|
953
1052
|
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
954
1053
|
};
|
|
955
1054
|
const queryString = stringify(queryOptions, { addQueryPrefix: true });
|
|
956
|
-
return queryString ? `${
|
|
1055
|
+
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
957
1056
|
}
|
|
958
1057
|
assertJsonResponse(response) {
|
|
959
1058
|
const contentType = response.headers.get("content-type");
|
|
@@ -1144,16 +1243,16 @@ var CollectionQueryBuilder = class {
|
|
|
1144
1243
|
* @returns Payload CMS mutation response with doc and message
|
|
1145
1244
|
*/
|
|
1146
1245
|
async create(data, options) {
|
|
1147
|
-
const
|
|
1246
|
+
const endpoint = `/api/${String(this.collection)}`;
|
|
1148
1247
|
if (options?.file) {
|
|
1149
1248
|
return this.api.requestCreateWithFile(
|
|
1150
|
-
|
|
1249
|
+
endpoint,
|
|
1151
1250
|
data,
|
|
1152
1251
|
options.file,
|
|
1153
1252
|
options.filename
|
|
1154
1253
|
);
|
|
1155
1254
|
}
|
|
1156
|
-
return this.api.requestCreate(
|
|
1255
|
+
return this.api.requestCreate(endpoint, data);
|
|
1157
1256
|
}
|
|
1158
1257
|
/**
|
|
1159
1258
|
* Update a document by ID
|
|
@@ -1161,16 +1260,16 @@ var CollectionQueryBuilder = class {
|
|
|
1161
1260
|
* @returns Payload CMS mutation response with doc and message
|
|
1162
1261
|
*/
|
|
1163
1262
|
async update(id, data, options) {
|
|
1164
|
-
const
|
|
1263
|
+
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
1165
1264
|
if (options?.file) {
|
|
1166
1265
|
return this.api.requestUpdateWithFile(
|
|
1167
|
-
|
|
1266
|
+
endpoint,
|
|
1168
1267
|
data,
|
|
1169
1268
|
options.file,
|
|
1170
1269
|
options.filename
|
|
1171
1270
|
);
|
|
1172
1271
|
}
|
|
1173
|
-
return this.api.requestUpdate(
|
|
1272
|
+
return this.api.requestUpdate(endpoint, data);
|
|
1174
1273
|
}
|
|
1175
1274
|
/**
|
|
1176
1275
|
* Count documents
|
|
@@ -1266,8 +1365,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1266
1365
|
* Find documents (list query)
|
|
1267
1366
|
* GET /api/{collection}
|
|
1268
1367
|
*/
|
|
1269
|
-
async requestFind(
|
|
1270
|
-
const url = this.buildUrl(
|
|
1368
|
+
async requestFind(endpoint, options) {
|
|
1369
|
+
const url = this.buildUrl(endpoint, options);
|
|
1271
1370
|
const response = await this.fetchWithTracking(url, {
|
|
1272
1371
|
...this.defaultOptions,
|
|
1273
1372
|
method: "GET"
|
|
@@ -1278,8 +1377,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1278
1377
|
* Find-like response from a custom endpoint
|
|
1279
1378
|
* POST /api/...custom-endpoint
|
|
1280
1379
|
*/
|
|
1281
|
-
async requestFindEndpoint(
|
|
1282
|
-
const response = await this.fetchWithTracking(
|
|
1380
|
+
async requestFindEndpoint(endpoint, data) {
|
|
1381
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1283
1382
|
...this.defaultOptions,
|
|
1284
1383
|
method: "POST",
|
|
1285
1384
|
body: data ? JSON.stringify(data) : void 0
|
|
@@ -1289,8 +1388,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1289
1388
|
/**
|
|
1290
1389
|
* Find-like response from a cacheable GET custom endpoint.
|
|
1291
1390
|
*/
|
|
1292
|
-
async requestFindEndpointGet(
|
|
1293
|
-
const response = await this.fetchWithTracking(
|
|
1391
|
+
async requestFindEndpointGet(endpoint) {
|
|
1392
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1294
1393
|
...this.defaultOptions,
|
|
1295
1394
|
method: "GET"
|
|
1296
1395
|
});
|
|
@@ -1300,8 +1399,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1300
1399
|
* Find document by ID
|
|
1301
1400
|
* GET /api/{collection}/{id}
|
|
1302
1401
|
*/
|
|
1303
|
-
async requestFindById(
|
|
1304
|
-
const url = this.buildUrl(
|
|
1402
|
+
async requestFindById(endpoint, options) {
|
|
1403
|
+
const url = this.buildUrl(endpoint, options);
|
|
1305
1404
|
const response = await this.fetchWithTracking(url, {
|
|
1306
1405
|
...this.defaultOptions,
|
|
1307
1406
|
method: "GET"
|
|
@@ -1312,8 +1411,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1312
1411
|
* Create document
|
|
1313
1412
|
* POST /api/{collection}
|
|
1314
1413
|
*/
|
|
1315
|
-
async requestCreate(
|
|
1316
|
-
const response = await this.fetchWithTracking(
|
|
1414
|
+
async requestCreate(endpoint, data) {
|
|
1415
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1317
1416
|
...this.defaultOptions,
|
|
1318
1417
|
method: "POST",
|
|
1319
1418
|
body: data ? JSON.stringify(data) : void 0
|
|
@@ -1324,8 +1423,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1324
1423
|
* Update document
|
|
1325
1424
|
* PATCH /api/{collection}/{id}
|
|
1326
1425
|
*/
|
|
1327
|
-
async requestUpdate(
|
|
1328
|
-
const response = await this.fetchWithTracking(
|
|
1426
|
+
async requestUpdate(endpoint, data) {
|
|
1427
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1329
1428
|
...this.defaultOptions,
|
|
1330
1429
|
method: "PATCH",
|
|
1331
1430
|
body: data ? JSON.stringify(data) : void 0
|
|
@@ -1336,8 +1435,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1336
1435
|
* Count documents
|
|
1337
1436
|
* GET /api/{collection}/count
|
|
1338
1437
|
*/
|
|
1339
|
-
async requestCount(
|
|
1340
|
-
const url = this.buildUrl(
|
|
1438
|
+
async requestCount(endpoint, options) {
|
|
1439
|
+
const url = this.buildUrl(endpoint, options);
|
|
1341
1440
|
const response = await this.fetchWithTracking(url, {
|
|
1342
1441
|
...this.defaultOptions,
|
|
1343
1442
|
method: "GET"
|
|
@@ -1348,8 +1447,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1348
1447
|
* Update multiple documents (bulk update)
|
|
1349
1448
|
* PATCH /api/{collection}
|
|
1350
1449
|
*/
|
|
1351
|
-
async requestUpdateMany(
|
|
1352
|
-
const response = await this.fetchWithTracking(
|
|
1450
|
+
async requestUpdateMany(endpoint, data) {
|
|
1451
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1353
1452
|
...this.defaultOptions,
|
|
1354
1453
|
method: "PATCH",
|
|
1355
1454
|
body: JSON.stringify(data)
|
|
@@ -1360,8 +1459,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1360
1459
|
* Delete document
|
|
1361
1460
|
* DELETE /api/{collection}/{id}
|
|
1362
1461
|
*/
|
|
1363
|
-
async requestDelete(
|
|
1364
|
-
const url = this.buildUrl(
|
|
1462
|
+
async requestDelete(endpoint, options) {
|
|
1463
|
+
const url = this.buildUrl(endpoint, options);
|
|
1365
1464
|
const response = await this.fetchWithTracking(url, {
|
|
1366
1465
|
...this.defaultOptions,
|
|
1367
1466
|
method: "DELETE"
|
|
@@ -1372,8 +1471,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1372
1471
|
* Delete multiple documents (bulk delete)
|
|
1373
1472
|
* DELETE /api/{collection}
|
|
1374
1473
|
*/
|
|
1375
|
-
async requestDeleteMany(
|
|
1376
|
-
const response = await this.fetchWithTracking(
|
|
1474
|
+
async requestDeleteMany(endpoint, data) {
|
|
1475
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1377
1476
|
...this.defaultOptions,
|
|
1378
1477
|
method: "DELETE",
|
|
1379
1478
|
body: JSON.stringify(data)
|
|
@@ -1384,8 +1483,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1384
1483
|
* Create document with file upload
|
|
1385
1484
|
* POST /api/{collection} (multipart/form-data)
|
|
1386
1485
|
*/
|
|
1387
|
-
async requestCreateWithFile(
|
|
1388
|
-
const response = await this.fetchWithTracking(
|
|
1486
|
+
async requestCreateWithFile(endpoint, data, file, filename) {
|
|
1487
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1389
1488
|
...this.defaultOptions,
|
|
1390
1489
|
method: "POST",
|
|
1391
1490
|
body: buildPayloadFormData(data, file, filename)
|
|
@@ -1396,8 +1495,8 @@ var CollectionClient = class extends HttpClient {
|
|
|
1396
1495
|
* Update document with file upload
|
|
1397
1496
|
* PATCH /api/{collection}/{id} (multipart/form-data)
|
|
1398
1497
|
*/
|
|
1399
|
-
async requestUpdateWithFile(
|
|
1400
|
-
const response = await this.fetchWithTracking(
|
|
1498
|
+
async requestUpdateWithFile(endpoint, data, file, filename) {
|
|
1499
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1401
1500
|
...this.defaultOptions,
|
|
1402
1501
|
method: "PATCH",
|
|
1403
1502
|
body: buildPayloadFormData(data, file, filename)
|
|
@@ -1412,7 +1511,7 @@ var ServerCollectionClient = class extends CollectionClient {
|
|
|
1412
1511
|
};
|
|
1413
1512
|
|
|
1414
1513
|
// src/core/api/parse-response.ts
|
|
1415
|
-
async function parseApiResponse(response,
|
|
1514
|
+
async function parseApiResponse(response, endpoint, options = {}) {
|
|
1416
1515
|
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
1417
1516
|
return void 0;
|
|
1418
1517
|
}
|
|
@@ -1421,7 +1520,7 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1421
1520
|
parsed = await response.json();
|
|
1422
1521
|
} catch {
|
|
1423
1522
|
throw createApiError(
|
|
1424
|
-
`Invalid JSON response from ${
|
|
1523
|
+
`Invalid JSON response from ${endpoint}`,
|
|
1425
1524
|
response.status,
|
|
1426
1525
|
void 0,
|
|
1427
1526
|
"Server returned an invalid response.",
|
|
@@ -1464,13 +1563,14 @@ async function parseApiResponse(response, endpoint2, options = {}) {
|
|
|
1464
1563
|
}
|
|
1465
1564
|
const withRequestId = attachRequestId(error, requestId);
|
|
1466
1565
|
if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
|
|
1467
|
-
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
|
|
1566
|
+
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
|
|
1468
1567
|
}
|
|
1469
1568
|
return data;
|
|
1470
1569
|
}
|
|
1471
1570
|
|
|
1472
1571
|
// ../../internal/http-contracts/src/index.ts
|
|
1473
1572
|
var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
|
|
1573
|
+
var PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE = "application/vnd.01software.portone-action-capabilities.v1+json";
|
|
1474
1574
|
var operation = (collection, method, path, errorFamily) => Object.freeze({
|
|
1475
1575
|
[operationBrand]: true,
|
|
1476
1576
|
collection,
|
|
@@ -1479,6 +1579,10 @@ var operation = (collection, method, path, errorFamily) => Object.freeze({
|
|
|
1479
1579
|
...errorFamily && { errorFamily }
|
|
1480
1580
|
});
|
|
1481
1581
|
var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
|
|
1582
|
+
var selectiveCommerceOperation = (collection, method, path, typedCommerceErrorReasons) => Object.freeze({
|
|
1583
|
+
...operation(collection, method, path),
|
|
1584
|
+
typedCommerceErrorReasons: Object.freeze([...typedCommerceErrorReasons])
|
|
1585
|
+
});
|
|
1482
1586
|
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
1483
1587
|
products: {
|
|
1484
1588
|
detail: operation("products", "get", "/detail"),
|
|
@@ -1510,7 +1614,12 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1510
1614
|
confirmPayment: operation("orders", "post", "/confirm-payment"),
|
|
1511
1615
|
byPayment: operation("orders", "get", "/by-payment"),
|
|
1512
1616
|
cancel: operation("orders", "post", "/cancel"),
|
|
1513
|
-
resolveCancelRefund:
|
|
1617
|
+
resolveCancelRefund: selectiveCommerceOperation(
|
|
1618
|
+
"orders",
|
|
1619
|
+
"post",
|
|
1620
|
+
"/resolve-cancel-refund",
|
|
1621
|
+
["managed_refund_attestation_forbidden"]
|
|
1622
|
+
),
|
|
1514
1623
|
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
1515
1624
|
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
1516
1625
|
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
@@ -1581,6 +1690,16 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1581
1690
|
"payment-sessions",
|
|
1582
1691
|
"post",
|
|
1583
1692
|
"/server/confirm"
|
|
1693
|
+
),
|
|
1694
|
+
findPortOne: strictCommerceOperation(
|
|
1695
|
+
"payment-sessions",
|
|
1696
|
+
"post",
|
|
1697
|
+
"/server/portone/find"
|
|
1698
|
+
),
|
|
1699
|
+
reconcilePortOne: strictCommerceOperation(
|
|
1700
|
+
"payment-sessions",
|
|
1701
|
+
"post",
|
|
1702
|
+
"/server/portone/reconcile"
|
|
1584
1703
|
)
|
|
1585
1704
|
},
|
|
1586
1705
|
custom: {
|
|
@@ -1600,12 +1719,26 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1600
1719
|
validate: operation("discounts", "post", "/validate")
|
|
1601
1720
|
}
|
|
1602
1721
|
};
|
|
1722
|
+
var portOneStandardActionCapabilityOperations = /* @__PURE__ */ new Set([
|
|
1723
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create,
|
|
1724
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve,
|
|
1725
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create,
|
|
1726
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
1727
|
+
]);
|
|
1603
1728
|
var MEMBERSHIP_ENDPOINT_OPERATIONS = {
|
|
1604
1729
|
subscribe: operation(null, "post", "/memberships/subscribe"),
|
|
1605
1730
|
cancel: operation(null, "post", "/memberships/:id/cancel"),
|
|
1606
1731
|
me: operation(null, "get", "/memberships/me")
|
|
1607
1732
|
};
|
|
1733
|
+
var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
|
|
1734
|
+
show: operation("tenants", "get", "/embedded-admin-app"),
|
|
1735
|
+
configure: operation("tenants", "patch", "/embedded-admin-app"),
|
|
1736
|
+
disable: operation("tenants", "delete", "/embedded-admin-app")
|
|
1737
|
+
};
|
|
1608
1738
|
var EVENTS_ENDPOINT_OPERATIONS = {
|
|
1739
|
+
events: {
|
|
1740
|
+
convertSchedule: operation("events", "post", "/:id/schedule")
|
|
1741
|
+
},
|
|
1609
1742
|
occurrences: {
|
|
1610
1743
|
range: operation("event-occurrences", "get", "/range"),
|
|
1611
1744
|
admissionAvailability: operation(
|
|
@@ -1646,46 +1779,54 @@ function resolveOperationMethod(descriptor) {
|
|
|
1646
1779
|
}
|
|
1647
1780
|
|
|
1648
1781
|
// src/core/api/endpoints.ts
|
|
1649
|
-
var endpoint = (method, path) => ({ method, path });
|
|
1650
1782
|
var sharedEndpoint = (descriptor) => descriptor;
|
|
1651
|
-
function resolveOperationMethod2(descriptor) {
|
|
1652
|
-
return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
|
|
1653
|
-
}
|
|
1654
1783
|
function resolveOperationErrorFamily(descriptor) {
|
|
1655
|
-
return
|
|
1784
|
+
return descriptor.errorFamily;
|
|
1656
1785
|
}
|
|
1657
|
-
function
|
|
1658
|
-
|
|
1659
|
-
return resolveOperationPath(descriptor, options);
|
|
1660
|
-
}
|
|
1661
|
-
const query = options?.query?.toString().replace(/^\?/, "");
|
|
1662
|
-
return query ? `${descriptor.path}?${query}` : descriptor.path;
|
|
1786
|
+
function resolveOperationTypedCommerceErrorReasons(descriptor) {
|
|
1787
|
+
return descriptor.typedCommerceErrorReasons;
|
|
1663
1788
|
}
|
|
1664
1789
|
var COMMERCE_ENDPOINTS = {
|
|
1665
1790
|
products: {
|
|
1666
|
-
detail:
|
|
1667
|
-
detailCatalog:
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1791
|
+
detail: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.detail),
|
|
1792
|
+
detailCatalog: sharedEndpoint(
|
|
1793
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.detailCatalog
|
|
1794
|
+
),
|
|
1795
|
+
listingGroups: sharedEndpoint(
|
|
1796
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroups
|
|
1797
|
+
),
|
|
1798
|
+
listingGroupsCatalog: sharedEndpoint(
|
|
1799
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsCatalog
|
|
1672
1800
|
),
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1801
|
+
// The manifest keeps the GET read and the POST body-query apart; this
|
|
1802
|
+
// semantic name has always resolved to the GET one.
|
|
1803
|
+
listingGroupsQuery: sharedEndpoint(
|
|
1804
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryGet
|
|
1677
1805
|
),
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1806
|
+
listingGroupsQueryCatalog: sharedEndpoint(
|
|
1807
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryCatalog
|
|
1808
|
+
),
|
|
1809
|
+
stockCheck: sharedEndpoint(
|
|
1810
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.stockCheck
|
|
1811
|
+
),
|
|
1812
|
+
stockSnapshot: sharedEndpoint(
|
|
1813
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.stockSnapshot
|
|
1814
|
+
),
|
|
1815
|
+
upsert: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.upsert)
|
|
1681
1816
|
},
|
|
1682
1817
|
orders: {
|
|
1683
|
-
update:
|
|
1684
|
-
byPayment:
|
|
1685
|
-
cancel:
|
|
1686
|
-
resolveCancelRefund:
|
|
1687
|
-
|
|
1688
|
-
|
|
1818
|
+
update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.update),
|
|
1819
|
+
byPayment: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.byPayment),
|
|
1820
|
+
cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.cancel),
|
|
1821
|
+
resolveCancelRefund: sharedEndpoint(
|
|
1822
|
+
COMMERCE_ENDPOINT_OPERATIONS.orders.resolveCancelRefund
|
|
1823
|
+
),
|
|
1824
|
+
createFulfillment: sharedEndpoint(
|
|
1825
|
+
COMMERCE_ENDPOINT_OPERATIONS.orders.createFulfillment
|
|
1826
|
+
),
|
|
1827
|
+
updateFulfillment: sharedEndpoint(
|
|
1828
|
+
COMMERCE_ENDPOINT_OPERATIONS.orders.updateFulfillment
|
|
1829
|
+
)
|
|
1689
1830
|
},
|
|
1690
1831
|
checkouts: {
|
|
1691
1832
|
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
@@ -1697,18 +1838,21 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1697
1838
|
}
|
|
1698
1839
|
},
|
|
1699
1840
|
returns: {
|
|
1700
|
-
create:
|
|
1701
|
-
update:
|
|
1702
|
-
returnRefund:
|
|
1841
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.create),
|
|
1842
|
+
update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.update),
|
|
1843
|
+
returnRefund: sharedEndpoint(
|
|
1844
|
+
COMMERCE_ENDPOINT_OPERATIONS.returns.returnRefund
|
|
1845
|
+
)
|
|
1703
1846
|
},
|
|
1704
1847
|
fulfillmentOrders: {
|
|
1705
|
-
prepare:
|
|
1706
|
-
|
|
1707
|
-
"/api/fulfillment-orders/prepare-fulfillment-order"
|
|
1848
|
+
prepare: sharedEndpoint(
|
|
1849
|
+
COMMERCE_ENDPOINT_OPERATIONS.fulfillmentOrders.prepare
|
|
1708
1850
|
)
|
|
1709
1851
|
},
|
|
1710
1852
|
fulfillments: {
|
|
1711
|
-
bulkImport:
|
|
1853
|
+
bulkImport: sharedEndpoint(
|
|
1854
|
+
COMMERCE_ENDPOINT_OPERATIONS.fulfillments.bulkImport
|
|
1855
|
+
)
|
|
1712
1856
|
},
|
|
1713
1857
|
carts: {
|
|
1714
1858
|
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
|
|
@@ -1773,42 +1917,21 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1773
1917
|
),
|
|
1774
1918
|
confirm: sharedEndpoint(
|
|
1775
1919
|
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
|
|
1920
|
+
),
|
|
1921
|
+
findPortOne: sharedEndpoint(
|
|
1922
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.findPortOne
|
|
1923
|
+
),
|
|
1924
|
+
reconcilePortOne: sharedEndpoint(
|
|
1925
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.reconcilePortOne
|
|
1776
1926
|
)
|
|
1777
1927
|
}
|
|
1778
1928
|
},
|
|
1779
1929
|
shippingPolicies: {
|
|
1780
|
-
calculate:
|
|
1930
|
+
calculate: sharedEndpoint(
|
|
1931
|
+
COMMERCE_ENDPOINT_OPERATIONS.shippingPolicies.calculate
|
|
1932
|
+
)
|
|
1781
1933
|
}
|
|
1782
1934
|
};
|
|
1783
|
-
function isCommerceEndpointDescriptor(value) {
|
|
1784
|
-
if (!value || typeof value !== "object") return false;
|
|
1785
|
-
const candidate = value;
|
|
1786
|
-
return typeof candidate.method === "string" && typeof candidate.path === "string";
|
|
1787
|
-
}
|
|
1788
|
-
function flattenEndpointPaths(value) {
|
|
1789
|
-
if (isCommerceEndpointDescriptor(value)) return [resolveOperationPath2(value)];
|
|
1790
|
-
if (!value || typeof value !== "object") return [];
|
|
1791
|
-
return Object.values(value).flatMap((entry) => flattenEndpointPaths(entry));
|
|
1792
|
-
}
|
|
1793
|
-
function flattenEndpointDescriptors(value) {
|
|
1794
|
-
if (isCommerceEndpointDescriptor(value)) return [value];
|
|
1795
|
-
if (!value || typeof value !== "object") return [];
|
|
1796
|
-
return Object.values(value).flatMap(
|
|
1797
|
-
(entry) => flattenEndpointDescriptors(entry)
|
|
1798
|
-
);
|
|
1799
|
-
}
|
|
1800
|
-
var COMMERCE_ENDPOINT_PATHS = flattenEndpointPaths(COMMERCE_ENDPOINTS);
|
|
1801
|
-
var COMMERCE_ENDPOINT_DESCRIPTORS = flattenEndpointDescriptors(COMMERCE_ENDPOINTS);
|
|
1802
|
-
var MEMBERSHIP_ENDPOINTS = {
|
|
1803
|
-
subscribe: "/api/memberships/subscribe",
|
|
1804
|
-
cancel: (id) => `/api/memberships/${id}/cancel`,
|
|
1805
|
-
me: "/api/memberships/me"
|
|
1806
|
-
};
|
|
1807
|
-
var MEMBERSHIP_ENDPOINT_PATHS = [
|
|
1808
|
-
MEMBERSHIP_ENDPOINTS.subscribe,
|
|
1809
|
-
MEMBERSHIP_ENDPOINTS.cancel(":id"),
|
|
1810
|
-
MEMBERSHIP_ENDPOINTS.me
|
|
1811
|
-
];
|
|
1812
1935
|
|
|
1813
1936
|
// src/core/api/customer-scoped-api.ts
|
|
1814
1937
|
var CustomerScopedTransport = class {
|
|
@@ -1829,10 +1952,10 @@ var CustomerScopedTransport = class {
|
|
|
1829
1952
|
this.onUnauthorized = options.onUnauthorized;
|
|
1830
1953
|
this.onRequestId = options.onRequestId;
|
|
1831
1954
|
}
|
|
1832
|
-
async request(
|
|
1955
|
+
async request(endpoint, options) {
|
|
1833
1956
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1834
1957
|
try {
|
|
1835
|
-
const response = await httpFetch(
|
|
1958
|
+
const response = await httpFetch(endpoint, {
|
|
1836
1959
|
method: options.method,
|
|
1837
1960
|
apiUrl: this.apiUrl,
|
|
1838
1961
|
publishableKey: this.publishableKey,
|
|
@@ -1846,7 +1969,7 @@ var CustomerScopedTransport = class {
|
|
|
1846
1969
|
...options.errorFamily && { errorFamily: options.errorFamily }
|
|
1847
1970
|
});
|
|
1848
1971
|
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1849
|
-
return parseApiResponse(response,
|
|
1972
|
+
return parseApiResponse(response, endpoint, {
|
|
1850
1973
|
errorFamily: options.errorFamily
|
|
1851
1974
|
});
|
|
1852
1975
|
} catch (err) {
|
|
@@ -1860,12 +1983,12 @@ var CustomerScopedApi = class {
|
|
|
1860
1983
|
constructor(apiName, options) {
|
|
1861
1984
|
this.transport = new CustomerScopedTransport(apiName, options);
|
|
1862
1985
|
}
|
|
1863
|
-
requestEndpoint(
|
|
1864
|
-
return this.transport.request(
|
|
1865
|
-
method:
|
|
1986
|
+
requestEndpoint(endpoint, body, options) {
|
|
1987
|
+
return this.transport.request(resolveOperationPath(endpoint, options), {
|
|
1988
|
+
method: resolveOperationMethod(endpoint),
|
|
1866
1989
|
body,
|
|
1867
1990
|
headers: options?.headers,
|
|
1868
|
-
errorFamily: resolveOperationErrorFamily(
|
|
1991
|
+
errorFamily: resolveOperationErrorFamily(endpoint)
|
|
1869
1992
|
});
|
|
1870
1993
|
}
|
|
1871
1994
|
};
|
|
@@ -1873,8 +1996,8 @@ var RawCustomerScopedApi = class {
|
|
|
1873
1996
|
constructor(apiName, options) {
|
|
1874
1997
|
this.transport = new CustomerScopedTransport(apiName, options);
|
|
1875
1998
|
}
|
|
1876
|
-
request(
|
|
1877
|
-
return this.transport.request(
|
|
1999
|
+
request(endpoint, options) {
|
|
2000
|
+
return this.transport.request(endpoint, options);
|
|
1878
2001
|
}
|
|
1879
2002
|
};
|
|
1880
2003
|
|
|
@@ -1888,13 +2011,7 @@ function unwrapPayloadDoc(value) {
|
|
|
1888
2011
|
return value;
|
|
1889
2012
|
}
|
|
1890
2013
|
function hasCanonicalNotFoundReason(error) {
|
|
1891
|
-
|
|
1892
|
-
if (typeof details !== "object" || details === null) return false;
|
|
1893
|
-
if ("reason" in details && details.reason === "not_found") return true;
|
|
1894
|
-
if (!("body" in details) || typeof details.body !== "object" || details.body === null) {
|
|
1895
|
-
return false;
|
|
1896
|
-
}
|
|
1897
|
-
return "reason" in details.body && details.body.reason === "not_found";
|
|
2014
|
+
return getSDKErrorReason(error) === "not_found";
|
|
1898
2015
|
}
|
|
1899
2016
|
var CommunityClient = class extends RawCustomerScopedApi {
|
|
1900
2017
|
constructor(options) {
|
|
@@ -1955,11 +2072,11 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
1955
2072
|
if (params.page !== void 0) urlParams.set("page", String(params.page));
|
|
1956
2073
|
return `/api/comments/public?${urlParams.toString()}`;
|
|
1957
2074
|
}
|
|
1958
|
-
async execute(
|
|
1959
|
-
return this.request(
|
|
2075
|
+
async execute(endpoint, method, body) {
|
|
2076
|
+
return this.request(endpoint, { method, body });
|
|
1960
2077
|
}
|
|
1961
|
-
async executeDoc(
|
|
1962
|
-
const response = await this.execute(
|
|
2078
|
+
async executeDoc(endpoint, method, body) {
|
|
2079
|
+
const response = await this.execute(endpoint, method, body);
|
|
1963
2080
|
return unwrapPayloadDoc(response);
|
|
1964
2081
|
}
|
|
1965
2082
|
createPost(params) {
|
|
@@ -2238,20 +2355,23 @@ var ServerApiTransport = class {
|
|
|
2238
2355
|
this.apiUrl = options.apiUrl;
|
|
2239
2356
|
this.onRequestId = options.onRequestId;
|
|
2240
2357
|
}
|
|
2241
|
-
async request(
|
|
2358
|
+
async request(endpoint, body, options) {
|
|
2242
2359
|
const method = options?.method ?? "POST";
|
|
2243
2360
|
try {
|
|
2244
|
-
const response = await httpFetch(
|
|
2361
|
+
const response = await httpFetch(endpoint, {
|
|
2245
2362
|
method,
|
|
2246
2363
|
apiUrl: this.apiUrl,
|
|
2247
2364
|
publishableKey: this.publishableKey,
|
|
2248
2365
|
secretKey: this.secretKey,
|
|
2249
2366
|
...body !== void 0 && { body: JSON.stringify(body) },
|
|
2250
2367
|
...options?.headers && { headers: options.headers },
|
|
2251
|
-
...options?.errorFamily && { errorFamily: options.errorFamily }
|
|
2368
|
+
...options?.errorFamily && { errorFamily: options.errorFamily },
|
|
2369
|
+
...options?.typedCommerceErrorReasons && {
|
|
2370
|
+
typedCommerceErrorReasons: options.typedCommerceErrorReasons
|
|
2371
|
+
}
|
|
2252
2372
|
});
|
|
2253
2373
|
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
2254
|
-
return parseApiResponse(response,
|
|
2374
|
+
return parseApiResponse(response, endpoint, {
|
|
2255
2375
|
errorFamily: options?.errorFamily
|
|
2256
2376
|
});
|
|
2257
2377
|
} catch (err) {
|
|
@@ -2265,14 +2385,15 @@ var BaseApi = class {
|
|
|
2265
2385
|
constructor(apiName, options) {
|
|
2266
2386
|
this.transport = new ServerApiTransport(apiName, options);
|
|
2267
2387
|
}
|
|
2268
|
-
requestEndpoint(
|
|
2388
|
+
requestEndpoint(endpoint, body, options) {
|
|
2269
2389
|
return this.transport.request(
|
|
2270
|
-
|
|
2390
|
+
resolveOperationPath(endpoint, options),
|
|
2271
2391
|
body,
|
|
2272
2392
|
{
|
|
2273
|
-
method:
|
|
2393
|
+
method: resolveOperationMethod(endpoint),
|
|
2274
2394
|
headers: options?.headers,
|
|
2275
|
-
errorFamily: resolveOperationErrorFamily(
|
|
2395
|
+
errorFamily: resolveOperationErrorFamily(endpoint),
|
|
2396
|
+
typedCommerceErrorReasons: resolveOperationTypedCommerceErrorReasons(endpoint)
|
|
2276
2397
|
}
|
|
2277
2398
|
);
|
|
2278
2399
|
}
|
|
@@ -2289,8 +2410,8 @@ var RawBaseApi = class {
|
|
|
2289
2410
|
this.apiUrl = options.apiUrl;
|
|
2290
2411
|
this.onRequestId = options.onRequestId;
|
|
2291
2412
|
}
|
|
2292
|
-
request(
|
|
2293
|
-
return this.transport.request(
|
|
2413
|
+
request(endpoint, body, options) {
|
|
2414
|
+
return this.transport.request(endpoint, body, options);
|
|
2294
2415
|
}
|
|
2295
2416
|
};
|
|
2296
2417
|
|
|
@@ -2351,6 +2472,18 @@ var PAYMENT_FAILURE_REASONS = [
|
|
|
2351
2472
|
"provider_terminal_failure",
|
|
2352
2473
|
"unknown_provider_terminal_failure"
|
|
2353
2474
|
];
|
|
2475
|
+
var PAYMENT_RECONCILIATION_REASONS = [
|
|
2476
|
+
"provider_outcome_unknown",
|
|
2477
|
+
"local_commit_ambiguous",
|
|
2478
|
+
"amount_mismatch",
|
|
2479
|
+
"currency_mismatch",
|
|
2480
|
+
"excess_capture_pending_order",
|
|
2481
|
+
"inventory_unavailable",
|
|
2482
|
+
"admission_unavailable",
|
|
2483
|
+
"excess_capture",
|
|
2484
|
+
"late_capture",
|
|
2485
|
+
"cross_checkout_duplicate"
|
|
2486
|
+
];
|
|
2354
2487
|
var CART_WARNING_CODES = [
|
|
2355
2488
|
"DISCOUNT_CODE_NOT_HONOURED",
|
|
2356
2489
|
"DISCOUNT_CURRENTLY_INACTIVE",
|
|
@@ -2412,6 +2545,9 @@ function nullableString(value, resource, path) {
|
|
|
2412
2545
|
fail(resource, path, "string or null");
|
|
2413
2546
|
}
|
|
2414
2547
|
}
|
|
2548
|
+
function nullableNonEmptyString(value, resource, path) {
|
|
2549
|
+
if (value !== null) string(value, resource, path);
|
|
2550
|
+
}
|
|
2415
2551
|
function nonBlankString(value, resource, path) {
|
|
2416
2552
|
const parsed = string(value, resource, path);
|
|
2417
2553
|
if (parsed.trim().length === 0) {
|
|
@@ -2932,8 +3068,8 @@ function validateCheckoutItem(value, resource, path) {
|
|
|
2932
3068
|
validateReference(item.product, resource, `${path}.product`);
|
|
2933
3069
|
validateReference(item.variant, resource, `${path}.variant`);
|
|
2934
3070
|
string(item.productTitle, resource, `${path}.productTitle`);
|
|
2935
|
-
|
|
2936
|
-
|
|
3071
|
+
nullableNonEmptyString(item.variantTitle, resource, `${path}.variantTitle`);
|
|
3072
|
+
nullableNonEmptyString(item.sku, resource, `${path}.sku`);
|
|
2937
3073
|
validateAdmissions(item.admissions, resource, `${path}.admissions`);
|
|
2938
3074
|
cartLineQuantity(item.quantity, resource, `${path}.quantity`);
|
|
2939
3075
|
const unitPrice = safeMinor(
|
|
@@ -3301,6 +3437,141 @@ function validateRetrievedCustomPaymentSession(value) {
|
|
|
3301
3437
|
nullableResourceId(session.orderId, resource, "$.orderId");
|
|
3302
3438
|
return value;
|
|
3303
3439
|
}
|
|
3440
|
+
function validatePortOnePaymentCurrentState(value, resource, path) {
|
|
3441
|
+
const current = record(value, resource, path);
|
|
3442
|
+
exact(
|
|
3443
|
+
current,
|
|
3444
|
+
["paymentSession", "checkout", "order", "money"],
|
|
3445
|
+
[],
|
|
3446
|
+
resource,
|
|
3447
|
+
path
|
|
3448
|
+
);
|
|
3449
|
+
const session = record(
|
|
3450
|
+
current.paymentSession,
|
|
3451
|
+
resource,
|
|
3452
|
+
`${path}.paymentSession`
|
|
3453
|
+
);
|
|
3454
|
+
exact(
|
|
3455
|
+
session,
|
|
3456
|
+
[
|
|
3457
|
+
"id",
|
|
3458
|
+
"provider",
|
|
3459
|
+
"providerStatus",
|
|
3460
|
+
"finalizationStatus",
|
|
3461
|
+
"sessionRole",
|
|
3462
|
+
"reconciliation"
|
|
3463
|
+
],
|
|
3464
|
+
[],
|
|
3465
|
+
resource,
|
|
3466
|
+
`${path}.paymentSession`
|
|
3467
|
+
);
|
|
3468
|
+
boundedString(
|
|
3469
|
+
session.id,
|
|
3470
|
+
MAX_COMMERCE_RESOURCE_ID_LENGTH,
|
|
3471
|
+
resource,
|
|
3472
|
+
`${path}.paymentSession.id`
|
|
3473
|
+
);
|
|
3474
|
+
if (session.provider !== "portone") {
|
|
3475
|
+
fail(resource, `${path}.paymentSession.provider`, "portone");
|
|
3476
|
+
}
|
|
3477
|
+
enumValue(
|
|
3478
|
+
session.providerStatus,
|
|
3479
|
+
PAYMENT_PROVIDER_STATUSES,
|
|
3480
|
+
resource,
|
|
3481
|
+
`${path}.paymentSession.providerStatus`
|
|
3482
|
+
);
|
|
3483
|
+
enumValue(
|
|
3484
|
+
session.finalizationStatus,
|
|
3485
|
+
["not_ready", "pending", "committed"],
|
|
3486
|
+
resource,
|
|
3487
|
+
`${path}.paymentSession.finalizationStatus`
|
|
3488
|
+
);
|
|
3489
|
+
enumValue(
|
|
3490
|
+
session.sessionRole,
|
|
3491
|
+
["active", "canonical_candidate", "canonical", "residual", "historical"],
|
|
3492
|
+
resource,
|
|
3493
|
+
`${path}.paymentSession.sessionRole`
|
|
3494
|
+
);
|
|
3495
|
+
const reconciliation = record(
|
|
3496
|
+
session.reconciliation,
|
|
3497
|
+
resource,
|
|
3498
|
+
`${path}.paymentSession.reconciliation`
|
|
3499
|
+
);
|
|
3500
|
+
if (reconciliation.status === "none") {
|
|
3501
|
+
validateNoReconciliation(
|
|
3502
|
+
reconciliation,
|
|
3503
|
+
resource,
|
|
3504
|
+
`${path}.paymentSession.reconciliation`
|
|
3505
|
+
);
|
|
3506
|
+
} else {
|
|
3507
|
+
validateRequiredReconciliation(
|
|
3508
|
+
reconciliation,
|
|
3509
|
+
PAYMENT_RECONCILIATION_REASONS,
|
|
3510
|
+
resource,
|
|
3511
|
+
`${path}.paymentSession.reconciliation`
|
|
3512
|
+
);
|
|
3513
|
+
}
|
|
3514
|
+
const checkout = record(current.checkout, resource, `${path}.checkout`);
|
|
3515
|
+
exact(checkout, ["id"], [], resource, `${path}.checkout`);
|
|
3516
|
+
boundedString(
|
|
3517
|
+
checkout.id,
|
|
3518
|
+
MAX_COMMERCE_RESOURCE_ID_LENGTH,
|
|
3519
|
+
resource,
|
|
3520
|
+
`${path}.checkout.id`
|
|
3521
|
+
);
|
|
3522
|
+
if (current.order !== null) {
|
|
3523
|
+
const order = record(current.order, resource, `${path}.order`);
|
|
3524
|
+
exact(order, ["id", "orderNumber"], [], resource, `${path}.order`);
|
|
3525
|
+
boundedString(
|
|
3526
|
+
order.id,
|
|
3527
|
+
MAX_COMMERCE_RESOURCE_ID_LENGTH,
|
|
3528
|
+
resource,
|
|
3529
|
+
`${path}.order.id`
|
|
3530
|
+
);
|
|
3531
|
+
nonBlankString(order.orderNumber, resource, `${path}.order.orderNumber`);
|
|
3532
|
+
}
|
|
3533
|
+
validateMoney(current.money, resource, `${path}.money`);
|
|
3534
|
+
}
|
|
3535
|
+
function validatePortOnePaymentFacadeResult(value, mutating) {
|
|
3536
|
+
const resource = mutating ? "PortOne payment reconciliation result" : "PortOne payment find result";
|
|
3537
|
+
const result = record(value, resource, "$");
|
|
3538
|
+
boolean(result.found, resource, "$.found");
|
|
3539
|
+
if (result.found === false) {
|
|
3540
|
+
exact(
|
|
3541
|
+
result,
|
|
3542
|
+
mutating ? ["found", "disposition"] : ["found"],
|
|
3543
|
+
[],
|
|
3544
|
+
resource,
|
|
3545
|
+
"$"
|
|
3546
|
+
);
|
|
3547
|
+
if (mutating && result.disposition !== "requires_attention") {
|
|
3548
|
+
fail(resource, "$.disposition", "requires_attention");
|
|
3549
|
+
}
|
|
3550
|
+
return value;
|
|
3551
|
+
}
|
|
3552
|
+
exact(
|
|
3553
|
+
result,
|
|
3554
|
+
mutating ? ["found", "disposition", "current"] : ["found", "current"],
|
|
3555
|
+
[],
|
|
3556
|
+
resource,
|
|
3557
|
+
"$"
|
|
3558
|
+
);
|
|
3559
|
+
if (mutating) {
|
|
3560
|
+
enumValue(
|
|
3561
|
+
result.disposition,
|
|
3562
|
+
[
|
|
3563
|
+
"applied",
|
|
3564
|
+
"observed",
|
|
3565
|
+
"recovered_after_ambiguous_result",
|
|
3566
|
+
"requires_attention"
|
|
3567
|
+
],
|
|
3568
|
+
resource,
|
|
3569
|
+
"$.disposition"
|
|
3570
|
+
);
|
|
3571
|
+
}
|
|
3572
|
+
validatePortOnePaymentCurrentState(result.current, resource, "$.current");
|
|
3573
|
+
return value;
|
|
3574
|
+
}
|
|
3304
3575
|
function validateConfirmCustomPaymentSessionResponse(value) {
|
|
3305
3576
|
const resource = "custom PaymentSession confirmation";
|
|
3306
3577
|
const result = record(value, resource, "$");
|
|
@@ -3354,9 +3625,96 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
|
|
|
3354
3625
|
function validateNextAction(value, provider, resource, path) {
|
|
3355
3626
|
const action = record(value, resource, path);
|
|
3356
3627
|
if (provider === "portone") {
|
|
3628
|
+
if (action.type === "portone_sdk") {
|
|
3629
|
+
const hasCancelable = "cancelable" in action;
|
|
3630
|
+
const hasRetryPolicy = "retryPolicy" in action;
|
|
3631
|
+
if (hasCancelable !== hasRetryPolicy) {
|
|
3632
|
+
fail(
|
|
3633
|
+
resource,
|
|
3634
|
+
path,
|
|
3635
|
+
"exact released action or exact negotiated capability action"
|
|
3636
|
+
);
|
|
3637
|
+
}
|
|
3638
|
+
exact(
|
|
3639
|
+
action,
|
|
3640
|
+
[
|
|
3641
|
+
"type",
|
|
3642
|
+
"version",
|
|
3643
|
+
...hasCancelable ? ["cancelable", "retryPolicy"] : [],
|
|
3644
|
+
"storeId",
|
|
3645
|
+
"channelKey",
|
|
3646
|
+
"paymentId",
|
|
3647
|
+
"orderName",
|
|
3648
|
+
"totalAmount",
|
|
3649
|
+
"currency",
|
|
3650
|
+
"payMethod",
|
|
3651
|
+
"redirectUrl"
|
|
3652
|
+
],
|
|
3653
|
+
[],
|
|
3654
|
+
resource,
|
|
3655
|
+
path
|
|
3656
|
+
);
|
|
3657
|
+
if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
|
|
3658
|
+
if (hasCancelable && action.cancelable !== false)
|
|
3659
|
+
fail(resource, `${path}.cancelable`, "false");
|
|
3660
|
+
if (hasRetryPolicy && action.retryPolicy !== "same_action_only") {
|
|
3661
|
+
fail(resource, `${path}.retryPolicy`, "same_action_only");
|
|
3662
|
+
}
|
|
3663
|
+
for (const key of ["storeId", "channelKey"]) {
|
|
3664
|
+
boundedString(action[key], 255, resource, `${path}.${key}`);
|
|
3665
|
+
}
|
|
3666
|
+
const paymentId = boundedString(
|
|
3667
|
+
action.paymentId,
|
|
3668
|
+
40,
|
|
3669
|
+
resource,
|
|
3670
|
+
`${path}.paymentId`
|
|
3671
|
+
);
|
|
3672
|
+
if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
|
|
3673
|
+
fail(
|
|
3674
|
+
resource,
|
|
3675
|
+
`${path}.paymentId`,
|
|
3676
|
+
"6-40 ASCII alphanumeric characters"
|
|
3677
|
+
);
|
|
3678
|
+
}
|
|
3679
|
+
boundedString(
|
|
3680
|
+
action.orderName,
|
|
3681
|
+
MAX_COMMERCE_SHORT_TEXT_LENGTH,
|
|
3682
|
+
resource,
|
|
3683
|
+
`${path}.orderName`
|
|
3684
|
+
);
|
|
3685
|
+
positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
|
|
3686
|
+
if (action.currency !== "CURRENCY_KRW") {
|
|
3687
|
+
fail(resource, `${path}.currency`, "CURRENCY_KRW");
|
|
3688
|
+
}
|
|
3689
|
+
if (action.payMethod !== "CARD")
|
|
3690
|
+
fail(resource, `${path}.payMethod`, "CARD");
|
|
3691
|
+
const redirectUrl = boundedString(
|
|
3692
|
+
action.redirectUrl,
|
|
3693
|
+
2048,
|
|
3694
|
+
resource,
|
|
3695
|
+
`${path}.redirectUrl`
|
|
3696
|
+
);
|
|
3697
|
+
try {
|
|
3698
|
+
const parsed = new URL(redirectUrl);
|
|
3699
|
+
const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
|
|
3700
|
+
if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
|
|
3701
|
+
throw new Error("unsafe redirect URL");
|
|
3702
|
+
} catch {
|
|
3703
|
+
fail(
|
|
3704
|
+
resource,
|
|
3705
|
+
`${path}.redirectUrl`,
|
|
3706
|
+
"HTTPS or loopback URL without embedded credentials"
|
|
3707
|
+
);
|
|
3708
|
+
}
|
|
3709
|
+
if (!hasCancelable) {
|
|
3710
|
+
action.cancelable = false;
|
|
3711
|
+
action.retryPolicy = "same_action_only";
|
|
3712
|
+
}
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3357
3715
|
exact(action, ["type", "checkoutUrl"], [], resource, path);
|
|
3358
3716
|
if (action.type !== "portone_checkout") {
|
|
3359
|
-
fail(resource, `${path}.type`, "portone_checkout");
|
|
3717
|
+
fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
|
|
3360
3718
|
}
|
|
3361
3719
|
const checkoutUrl = boundedString(
|
|
3362
3720
|
action.checkoutUrl,
|
|
@@ -3669,8 +4027,8 @@ var CartApi = class extends CustomerScopedApi {
|
|
|
3669
4027
|
endpoint(key) {
|
|
3670
4028
|
return this.serverTransport ? COMMERCE_ENDPOINTS.carts.server[key] : COMMERCE_ENDPOINTS.carts[key];
|
|
3671
4029
|
}
|
|
3672
|
-
execute(
|
|
3673
|
-
return this.requestEndpoint(
|
|
4030
|
+
execute(endpoint, body, idempotencyKey) {
|
|
4031
|
+
return this.requestEndpoint(endpoint, body, {
|
|
3674
4032
|
...idempotencyKey && {
|
|
3675
4033
|
headers: { "X-Idempotency-Key": idempotencyKey }
|
|
3676
4034
|
}
|
|
@@ -3687,26 +4045,26 @@ var CartApi = class extends CustomerScopedApi {
|
|
|
3687
4045
|
);
|
|
3688
4046
|
}
|
|
3689
4047
|
mine(params = {}) {
|
|
3690
|
-
const
|
|
3691
|
-
return this.execute(
|
|
4048
|
+
const endpoint = this.endpoint("mine");
|
|
4049
|
+
return this.execute(endpoint, params).then(
|
|
3692
4050
|
(value) => validateCartMineResult(value)
|
|
3693
4051
|
);
|
|
3694
4052
|
}
|
|
3695
4053
|
merge(params) {
|
|
3696
4054
|
const { idempotencyKey, ...body } = params;
|
|
3697
4055
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
3698
|
-
const
|
|
3699
|
-
return this.execute(
|
|
4056
|
+
const endpoint = this.endpoint("merge");
|
|
4057
|
+
return this.execute(endpoint, body, idempotencyKey).then(
|
|
3700
4058
|
(value) => validateCartMergeResult(value)
|
|
3701
4059
|
);
|
|
3702
4060
|
}
|
|
3703
4061
|
addItem(params) {
|
|
3704
4062
|
return this.mutate(this.endpoint("addItem"), params);
|
|
3705
4063
|
}
|
|
3706
|
-
mutate(
|
|
4064
|
+
mutate(endpoint, params) {
|
|
3707
4065
|
const { idempotencyKey, ...body } = params;
|
|
3708
4066
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
3709
|
-
return this.execute(
|
|
4067
|
+
return this.execute(endpoint, body, idempotencyKey).then(
|
|
3710
4068
|
(value) => validateCartMutationResult(value)
|
|
3711
4069
|
);
|
|
3712
4070
|
}
|
|
@@ -4753,21 +5111,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
|
|
|
4753
5111
|
"not_published",
|
|
4754
5112
|
"feature_disabled"
|
|
4755
5113
|
]);
|
|
4756
|
-
function isRecord(value) {
|
|
4757
|
-
return typeof value === "object" && value !== null;
|
|
4758
|
-
}
|
|
4759
|
-
function readProductDetailUnavailableReason(value) {
|
|
4760
|
-
if (!isRecord(value)) return void 0;
|
|
4761
|
-
const directReason = value.reason ?? value.code;
|
|
4762
|
-
if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
|
|
4763
|
-
return directReason;
|
|
4764
|
-
}
|
|
4765
|
-
return readProductDetailUnavailableReason(value.body);
|
|
4766
|
-
}
|
|
4767
5114
|
function productDetailResultFromError(error) {
|
|
4768
5115
|
if (!(error instanceof SDKError) || error.status !== 404) return void 0;
|
|
4769
|
-
const reason =
|
|
4770
|
-
if (!reason
|
|
5116
|
+
const reason = getSDKErrorReason(error);
|
|
5117
|
+
if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
|
|
5118
|
+
return void 0;
|
|
4771
5119
|
return { found: false, reason };
|
|
4772
5120
|
}
|
|
4773
5121
|
var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
|
|
@@ -5125,8 +5473,8 @@ var CheckoutApi = class extends CustomerScopedApi {
|
|
|
5125
5473
|
constructor(options) {
|
|
5126
5474
|
super("CheckoutApi", { ...options, requiresCredential: false });
|
|
5127
5475
|
}
|
|
5128
|
-
post(
|
|
5129
|
-
return this.requestEndpoint(
|
|
5476
|
+
post(endpoint, body, idempotencyKey) {
|
|
5477
|
+
return this.requestEndpoint(endpoint, body, {
|
|
5130
5478
|
...idempotencyKey && {
|
|
5131
5479
|
headers: { "X-Idempotency-Key": idempotencyKey }
|
|
5132
5480
|
}
|
|
@@ -5193,11 +5541,15 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
5193
5541
|
super("PaymentSessionApi", { ...options, requiresCredential: false });
|
|
5194
5542
|
this.serverTransport = Boolean(options.secretKey);
|
|
5195
5543
|
}
|
|
5196
|
-
post(
|
|
5197
|
-
|
|
5198
|
-
...idempotencyKey && {
|
|
5199
|
-
|
|
5544
|
+
post(endpoint, body, idempotencyKey, negotiateStandardActionCapabilities = false) {
|
|
5545
|
+
const headers = {
|
|
5546
|
+
...idempotencyKey && { "X-Idempotency-Key": idempotencyKey },
|
|
5547
|
+
...negotiateStandardActionCapabilities && {
|
|
5548
|
+
Accept: PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE
|
|
5200
5549
|
}
|
|
5550
|
+
};
|
|
5551
|
+
return this.requestEndpoint(endpoint, body, {
|
|
5552
|
+
...Object.keys(headers).length > 0 && { headers }
|
|
5201
5553
|
});
|
|
5202
5554
|
}
|
|
5203
5555
|
async paymentSession(result, expectedProvider) {
|
|
@@ -5222,40 +5574,41 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
5222
5574
|
this.post(
|
|
5223
5575
|
this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
|
|
5224
5576
|
body,
|
|
5225
|
-
idempotencyKey
|
|
5577
|
+
idempotencyKey,
|
|
5578
|
+
body.providerOptions.profile === "standard_v2"
|
|
5226
5579
|
),
|
|
5227
5580
|
"portone"
|
|
5228
5581
|
);
|
|
5229
5582
|
}
|
|
5230
5583
|
retrieve(params) {
|
|
5231
|
-
const
|
|
5584
|
+
const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
5232
5585
|
return this.paymentSession(
|
|
5233
|
-
this.post(
|
|
5586
|
+
this.post(endpoint, params),
|
|
5234
5587
|
"toss"
|
|
5235
5588
|
);
|
|
5236
5589
|
}
|
|
5237
5590
|
retrievePortOne(params) {
|
|
5238
|
-
const
|
|
5591
|
+
const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
|
|
5239
5592
|
return this.paymentSession(
|
|
5240
|
-
this.post(
|
|
5593
|
+
this.post(endpoint, params, void 0, true),
|
|
5241
5594
|
"portone"
|
|
5242
5595
|
);
|
|
5243
5596
|
}
|
|
5244
5597
|
cancel(params) {
|
|
5245
5598
|
const { idempotencyKey, ...body } = params;
|
|
5246
5599
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
5247
|
-
const
|
|
5600
|
+
const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
5248
5601
|
return this.paymentSession(
|
|
5249
|
-
this.post(
|
|
5602
|
+
this.post(endpoint, body, idempotencyKey),
|
|
5250
5603
|
"toss"
|
|
5251
5604
|
);
|
|
5252
5605
|
}
|
|
5253
5606
|
cancelPortOne(params) {
|
|
5254
5607
|
const { idempotencyKey, ...body } = params;
|
|
5255
5608
|
assertCommerceIdempotencyKey(idempotencyKey);
|
|
5256
|
-
const
|
|
5609
|
+
const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
|
|
5257
5610
|
return this.paymentSession(
|
|
5258
|
-
this.post(
|
|
5611
|
+
this.post(endpoint, body, idempotencyKey),
|
|
5259
5612
|
"portone"
|
|
5260
5613
|
);
|
|
5261
5614
|
}
|
|
@@ -5272,6 +5625,34 @@ var PaymentSessionApi = class extends CustomerScopedApi {
|
|
|
5272
5625
|
);
|
|
5273
5626
|
}
|
|
5274
5627
|
};
|
|
5628
|
+
var PortOnePaymentReconciliationApi = class extends BaseApi {
|
|
5629
|
+
constructor(options) {
|
|
5630
|
+
super("PortOnePaymentReconciliationApi", options);
|
|
5631
|
+
}
|
|
5632
|
+
async find(params) {
|
|
5633
|
+
const result = await this.requestEndpoint(
|
|
5634
|
+
COMMERCE_ENDPOINTS.paymentSessions.server.findPortOne,
|
|
5635
|
+
params
|
|
5636
|
+
);
|
|
5637
|
+
return validatePortOnePaymentFacadeResult(
|
|
5638
|
+
result,
|
|
5639
|
+
false
|
|
5640
|
+
);
|
|
5641
|
+
}
|
|
5642
|
+
async reconcile(params) {
|
|
5643
|
+
const { idempotencyKey, ...body } = params;
|
|
5644
|
+
assertCommerceIdempotencyKey(idempotencyKey);
|
|
5645
|
+
const result = await this.requestEndpoint(
|
|
5646
|
+
COMMERCE_ENDPOINTS.paymentSessions.server.reconcilePortOne,
|
|
5647
|
+
body,
|
|
5648
|
+
{ headers: { "X-Idempotency-Key": idempotencyKey } }
|
|
5649
|
+
);
|
|
5650
|
+
return validatePortOnePaymentFacadeResult(
|
|
5651
|
+
result,
|
|
5652
|
+
true
|
|
5653
|
+
);
|
|
5654
|
+
}
|
|
5655
|
+
};
|
|
5275
5656
|
var CustomPaymentSessionApi = class extends BaseApi {
|
|
5276
5657
|
constructor(options) {
|
|
5277
5658
|
super("CustomPaymentSessionApi", options);
|
|
@@ -5401,6 +5782,9 @@ var ServerCommerceClient = class {
|
|
|
5401
5782
|
const orderApi = new OrderApi(serverOptions);
|
|
5402
5783
|
const checkoutApi = new CheckoutApi(serverOptions);
|
|
5403
5784
|
const paymentSessionApi = new PaymentSessionApi(serverOptions);
|
|
5785
|
+
const portOneReconciliationApi = new PortOnePaymentReconciliationApi(
|
|
5786
|
+
serverOptions
|
|
5787
|
+
);
|
|
5404
5788
|
const customPaymentSessionApi = new CustomPaymentSessionApi(serverOptions);
|
|
5405
5789
|
this.product = {
|
|
5406
5790
|
stockCheck: productApi.stockCheck.bind(productApi),
|
|
@@ -5451,6 +5835,10 @@ var ServerCommerceClient = class {
|
|
|
5451
5835
|
cancel: (params) => paymentSessionApi.cancel(params),
|
|
5452
5836
|
cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params),
|
|
5453
5837
|
confirm: paymentSessionApi.confirm.bind(paymentSessionApi),
|
|
5838
|
+
findPortOne: portOneReconciliationApi.find.bind(portOneReconciliationApi),
|
|
5839
|
+
reconcilePortOne: portOneReconciliationApi.reconcile.bind(
|
|
5840
|
+
portOneReconciliationApi
|
|
5841
|
+
),
|
|
5454
5842
|
custom: {
|
|
5455
5843
|
create: customPaymentSessionApi.create.bind(customPaymentSessionApi),
|
|
5456
5844
|
retrieve: customPaymentSessionApi.retrieve.bind(
|
|
@@ -5532,11 +5920,11 @@ var EventsClient = class {
|
|
|
5532
5920
|
{ useCustomerAuth: false }
|
|
5533
5921
|
);
|
|
5534
5922
|
}
|
|
5535
|
-
async execute(
|
|
5923
|
+
async execute(endpoint, method, body, options = {}) {
|
|
5536
5924
|
const useCustomerAuth = options.useCustomerAuth === true;
|
|
5537
5925
|
const token = useCustomerAuth ? typeof this.customerToken === "function" ? this.customerToken() : this.customerToken : void 0;
|
|
5538
5926
|
try {
|
|
5539
|
-
const response = await httpFetch(
|
|
5927
|
+
const response = await httpFetch(endpoint, {
|
|
5540
5928
|
method,
|
|
5541
5929
|
apiUrl: this.apiUrl,
|
|
5542
5930
|
publishableKey: this.publishableKey,
|
|
@@ -5545,7 +5933,7 @@ var EventsClient = class {
|
|
|
5545
5933
|
...body !== void 0 && { body: JSON.stringify(body) }
|
|
5546
5934
|
});
|
|
5547
5935
|
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
5548
|
-
return parseApiResponse(response,
|
|
5936
|
+
return parseApiResponse(response, endpoint);
|
|
5549
5937
|
} catch (err) {
|
|
5550
5938
|
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
5551
5939
|
this.onRequestId?.(id);
|
|
@@ -5647,13 +6035,14 @@ var MarketDiscovery = class {
|
|
|
5647
6035
|
};
|
|
5648
6036
|
|
|
5649
6037
|
// src/core/api/tenant-introspection-api.ts
|
|
6038
|
+
var TENANT_CONTEXT_PATH = "/api/tenants/context";
|
|
5650
6039
|
var TenantIntrospectionApi = class extends RawBaseApi {
|
|
5651
6040
|
constructor(options) {
|
|
5652
6041
|
super("TenantIntrospectionApi", options);
|
|
5653
6042
|
}
|
|
5654
6043
|
context(params = {}) {
|
|
5655
|
-
const
|
|
5656
|
-
return this.request(
|
|
6044
|
+
const endpoint = params.includeCounts ? `${TENANT_CONTEXT_PATH}?counts=true` : TENANT_CONTEXT_PATH;
|
|
6045
|
+
return this.request(endpoint, void 0, {
|
|
5657
6046
|
method: "GET"
|
|
5658
6047
|
});
|
|
5659
6048
|
}
|
|
@@ -5825,7 +6214,23 @@ export {
|
|
|
5825
6214
|
ServerCollectionClient,
|
|
5826
6215
|
ServerCommerceClient,
|
|
5827
6216
|
ServerPreviewClient,
|
|
6217
|
+
TENANT_CONTEXT_PATH,
|
|
5828
6218
|
TenantIntrospectionApi,
|
|
5829
|
-
createServerClient
|
|
6219
|
+
createServerClient,
|
|
6220
|
+
isApiError,
|
|
6221
|
+
isAuthError,
|
|
6222
|
+
isCommerceSDKError,
|
|
6223
|
+
isConfigError,
|
|
6224
|
+
isConflictError,
|
|
6225
|
+
isGoneError,
|
|
6226
|
+
isNetworkError,
|
|
6227
|
+
isNotFoundError,
|
|
6228
|
+
isPermissionError,
|
|
6229
|
+
isRateLimitError,
|
|
6230
|
+
isSDKError,
|
|
6231
|
+
isServiceUnavailableError,
|
|
6232
|
+
isTimeoutError,
|
|
6233
|
+
isUsageLimitError,
|
|
6234
|
+
isValidationError
|
|
5830
6235
|
};
|
|
5831
6236
|
//# sourceMappingURL=server.js.map
|