@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.
Files changed (74) hide show
  1. package/CHANGELOG.md +157 -1
  2. package/MIGRATION.md +56 -0
  3. package/README.md +276 -49
  4. package/dist/client.cjs +375 -161
  5. package/dist/client.cjs.map +1 -1
  6. package/dist/client.d.cts +7 -6
  7. package/dist/client.d.ts +7 -6
  8. package/dist/client.js +375 -161
  9. package/dist/client.js.map +1 -1
  10. package/dist/{collection-client-CBup9yOx.d.cts → collection-client-CWAeuzV4.d.cts} +6 -4
  11. package/dist/{collection-client-D3ExJU-7.d.ts → collection-client-hYvVfHIm.d.ts} +6 -4
  12. package/dist/{const-k9gHylYa.d.ts → const-D8LixhAJ.d.cts} +5 -5
  13. package/dist/{const-BXEi1Kix.d.cts → const-JD8obaKg.d.ts} +5 -5
  14. package/dist/embedded-admin/server.cjs +306 -0
  15. package/dist/embedded-admin/server.cjs.map +1 -0
  16. package/dist/embedded-admin/server.d.cts +33 -0
  17. package/dist/embedded-admin/server.d.ts +33 -0
  18. package/dist/embedded-admin/server.js +288 -0
  19. package/dist/embedded-admin/server.js.map +1 -0
  20. package/dist/embedded-admin.cjs +400 -0
  21. package/dist/embedded-admin.cjs.map +1 -0
  22. package/dist/embedded-admin.d.cts +61 -0
  23. package/dist/embedded-admin.d.ts +61 -0
  24. package/dist/embedded-admin.js +377 -0
  25. package/dist/embedded-admin.js.map +1 -0
  26. package/dist/errors.cjs +64 -15
  27. package/dist/errors.cjs.map +1 -1
  28. package/dist/errors.d.cts +13 -4
  29. package/dist/errors.d.ts +13 -4
  30. package/dist/errors.js +64 -15
  31. package/dist/errors.js.map +1 -1
  32. package/dist/{index-BCM9CTL7.d.cts → index-B0Hjh3Ey.d.ts} +72 -10
  33. package/dist/{index-CHGGkcLj.d.ts → index-Bu0kCc6o.d.cts} +72 -10
  34. package/dist/index.cjs +470 -429
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +9 -67
  37. package/dist/index.d.ts +9 -67
  38. package/dist/index.js +470 -429
  39. package/dist/index.js.map +1 -1
  40. package/dist/{payload-types-B6AZQcB7.d.cts → payload-types-BOsckg8B.d.cts} +396 -57
  41. package/dist/{payload-types-B6AZQcB7.d.ts → payload-types-BOsckg8B.d.ts} +396 -57
  42. package/dist/query.cjs +115 -70
  43. package/dist/query.cjs.map +1 -1
  44. package/dist/query.d.cts +5 -5
  45. package/dist/query.d.ts +5 -5
  46. package/dist/query.js +115 -70
  47. package/dist/query.js.map +1 -1
  48. package/dist/realtime.d.cts +2 -2
  49. package/dist/realtime.d.ts +2 -2
  50. package/dist/server.cjs +591 -186
  51. package/dist/server.cjs.map +1 -1
  52. package/dist/server.d.cts +8 -7
  53. package/dist/server.d.ts +8 -7
  54. package/dist/server.js +591 -186
  55. package/dist/server.js.map +1 -1
  56. package/dist/storefront-cache.cjs +22 -0
  57. package/dist/storefront-cache.cjs.map +1 -1
  58. package/dist/storefront-cache.js +22 -0
  59. package/dist/storefront-cache.js.map +1 -1
  60. package/dist/{types-ByD2zii1.d.ts → types-5ZlcAFuU.d.ts} +2 -2
  61. package/dist/{types-8us-_C-Q.d.cts → types-B14sEt1z.d.cts} +2 -2
  62. package/dist/{types-CM2je9Kw.d.cts → types-Bj8j7VHU.d.ts} +107 -26
  63. package/dist/{types-DbA5V3mt.d.ts → types-CM5qiR2k.d.cts} +107 -26
  64. package/dist/ui/form.d.cts +1 -1
  65. package/dist/ui/form.d.ts +1 -1
  66. package/dist/ui/video.d.cts +1 -1
  67. package/dist/ui/video.d.ts +1 -1
  68. package/dist/webhook.cjs +124 -80
  69. package/dist/webhook.cjs.map +1 -1
  70. package/dist/webhook.d.cts +21 -5
  71. package/dist/webhook.d.ts +21 -5
  72. package/dist/webhook.js +124 -80
  73. package/dist/webhook.js.map +1 -1
  74. package/package.json +27 -5
package/dist/client.cjs CHANGED
@@ -22,7 +22,22 @@ var client_exports = {};
22
22
  __export(client_exports, {
23
23
  Client: () => Client,
24
24
  ContentClient: () => ContentClient,
25
- createClient: () => createClient
25
+ createClient: () => createClient,
26
+ isApiError: () => isApiError,
27
+ isAuthError: () => isAuthError,
28
+ isCommerceSDKError: () => isCommerceSDKError,
29
+ isConfigError: () => isConfigError,
30
+ isConflictError: () => isConflictError,
31
+ isGoneError: () => isGoneError,
32
+ isNetworkError: () => isNetworkError,
33
+ isNotFoundError: () => isNotFoundError,
34
+ isPermissionError: () => isPermissionError,
35
+ isRateLimitError: () => isRateLimitError,
36
+ isSDKError: () => isSDKError,
37
+ isServiceUnavailableError: () => isServiceUnavailableError,
38
+ isTimeoutError: () => isTimeoutError,
39
+ isUsageLimitError: () => isUsageLimitError,
40
+ isValidationError: () => isValidationError
26
41
  });
27
42
  module.exports = __toCommonJS(client_exports);
28
43
 
@@ -30,6 +45,24 @@ module.exports = __toCommonJS(client_exports);
30
45
  var import_qs_esm = require("qs-esm");
31
46
 
32
47
  // src/core/errors.ts
48
+ var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
49
+ var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
50
+ function defineSDKErrorBrand(error) {
51
+ Object.defineProperty(error, SDK_ERROR_BRAND, {
52
+ value: true,
53
+ enumerable: false,
54
+ configurable: false,
55
+ writable: false
56
+ });
57
+ }
58
+ function defineSDKErrorType(error, type) {
59
+ Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
60
+ value: type,
61
+ enumerable: false,
62
+ configurable: false,
63
+ writable: false
64
+ });
65
+ }
33
66
  var SDKError = class extends Error {
34
67
  constructor(code, message, status, details, userMessage, suggestion, requestId) {
35
68
  super(message);
@@ -40,6 +73,7 @@ var SDKError = class extends Error {
40
73
  this.userMessage = userMessage;
41
74
  this.suggestion = suggestion;
42
75
  this.requestId = requestId;
76
+ defineSDKErrorBrand(this);
43
77
  if (Error.captureStackTrace) {
44
78
  Error.captureStackTrace(this, new.target);
45
79
  }
@@ -60,6 +94,7 @@ var SDKError = class extends Error {
60
94
  ...this.kind !== void 0 && { kind: this.kind },
61
95
  ...this.reason !== void 0 && { reason: this.reason },
62
96
  ...this.rawReason !== void 0 && { rawReason: this.rawReason },
97
+ ...this.apiReason !== void 0 && { apiReason: this.apiReason },
63
98
  ...this.retryable !== void 0 && { retryable: this.retryable },
64
99
  ...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
65
100
  };
@@ -105,6 +140,7 @@ var COMMERCE_ERROR_CODES = [
105
140
  "payment_session_not_cancelable",
106
141
  "payment_session_conflict",
107
142
  "provider_identity_mismatch",
143
+ "managed_refund_attestation_forbidden",
108
144
  "payment_method_unavailable",
109
145
  "provider_unavailable",
110
146
  "lock_timeout",
@@ -233,8 +269,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
233
269
  });
234
270
  return error;
235
271
  }
272
+ function enhanceNonCommerceError(error, reason) {
273
+ if (typeof reason === "string") Object.assign(error, { apiReason: reason });
274
+ return error;
275
+ }
276
+ function getSDKErrorReason(error) {
277
+ if (error.kind !== "commerce") return error.apiReason;
278
+ return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
279
+ }
236
280
  function isCommerceSDKError(error) {
237
- if (!(error instanceof SDKError) || error.kind !== "commerce") return false;
281
+ if (!isSDKError(error) || error.kind !== "commerce") return false;
238
282
  if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
239
283
  return false;
240
284
  }
@@ -244,12 +288,14 @@ var NetworkError = class extends SDKError {
244
288
  constructor(message, status, details, userMessage, suggestion) {
245
289
  super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
246
290
  this.name = "NetworkError";
291
+ defineSDKErrorType(this, "NetworkError");
247
292
  }
248
293
  };
249
294
  var ValidationError = class extends SDKError {
250
295
  constructor(message, details, userMessage, suggestion, status = 400) {
251
296
  super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
252
297
  this.name = "ValidationError";
298
+ defineSDKErrorType(this, "ValidationError");
253
299
  }
254
300
  };
255
301
  var ApiError = class extends SDKError {
@@ -264,24 +310,28 @@ var ApiError = class extends SDKError {
264
310
  requestId
265
311
  );
266
312
  this.name = "ApiError";
313
+ defineSDKErrorType(this, "ApiError");
267
314
  }
268
315
  };
269
316
  var ConfigError = class extends SDKError {
270
317
  constructor(message, details, userMessage, suggestion) {
271
318
  super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
272
319
  this.name = "ConfigError";
320
+ defineSDKErrorType(this, "ConfigError");
273
321
  }
274
322
  };
275
323
  var TimeoutError = class extends SDKError {
276
324
  constructor(message = "Request timed out.", details, userMessage, suggestion) {
277
325
  super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
278
326
  this.name = "TimeoutError";
327
+ defineSDKErrorType(this, "TimeoutError");
279
328
  }
280
329
  };
281
330
  var GoneError = class extends SDKError {
282
331
  constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
283
332
  super("GONE_ERROR", message, 410, details, userMessage, suggestion);
284
333
  this.name = "GoneError";
334
+ defineSDKErrorType(this, "GoneError");
285
335
  }
286
336
  };
287
337
  var ServiceUnavailableError = class extends SDKError {
@@ -296,6 +346,7 @@ var ServiceUnavailableError = class extends SDKError {
296
346
  );
297
347
  this.name = "ServiceUnavailableError";
298
348
  this.retryAfter = retryAfter;
349
+ defineSDKErrorType(this, "ServiceUnavailableError");
299
350
  }
300
351
  };
301
352
  var UsageLimitError = class extends SDKError {
@@ -303,6 +354,7 @@ var UsageLimitError = class extends SDKError {
303
354
  super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
304
355
  this.name = "UsageLimitError";
305
356
  this.usage = usage;
357
+ defineSDKErrorType(this, "UsageLimitError");
306
358
  }
307
359
  toJSON() {
308
360
  return {
@@ -323,6 +375,7 @@ var AuthError = class extends SDKError {
323
375
  requestId
324
376
  );
325
377
  this.name = "AuthError";
378
+ defineSDKErrorType(this, "AuthError");
326
379
  }
327
380
  };
328
381
  var PermissionError = class extends SDKError {
@@ -337,6 +390,7 @@ var PermissionError = class extends SDKError {
337
390
  requestId
338
391
  );
339
392
  this.name = "PermissionError";
393
+ defineSDKErrorType(this, "PermissionError");
340
394
  }
341
395
  };
342
396
  var NotFoundError = class extends SDKError {
@@ -351,12 +405,14 @@ var NotFoundError = class extends SDKError {
351
405
  requestId
352
406
  );
353
407
  this.name = "NotFoundError";
408
+ defineSDKErrorType(this, "NotFoundError");
354
409
  }
355
410
  };
356
411
  var ConflictError = class extends SDKError {
357
412
  constructor(message, details, userMessage, suggestion, requestId) {
358
413
  super("conflict", message, 409, details, userMessage, suggestion, requestId);
359
414
  this.name = "ConflictError";
415
+ defineSDKErrorType(this, "ConflictError");
360
416
  }
361
417
  };
362
418
  var RateLimitError = class extends SDKError {
@@ -372,8 +428,64 @@ var RateLimitError = class extends SDKError {
372
428
  );
373
429
  this.name = "RateLimitError";
374
430
  this.retryAfter = retryAfter;
431
+ defineSDKErrorType(this, "RateLimitError");
375
432
  }
376
433
  };
434
+ function hasBrandedSDKErrorShape(error) {
435
+ if (error === null || typeof error !== "object") return false;
436
+ const candidate = error;
437
+ 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";
438
+ }
439
+ function hasSDKErrorType(error, type) {
440
+ return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
441
+ }
442
+ function isSDKError(error) {
443
+ return error instanceof SDKError || hasBrandedSDKErrorShape(error);
444
+ }
445
+ function isNetworkError(error) {
446
+ return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
447
+ }
448
+ function isValidationError(error) {
449
+ if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
450
+ return true;
451
+ }
452
+ if (error == null || typeof error !== "object") return false;
453
+ const candidate = error;
454
+ return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
455
+ }
456
+ function isApiError(error) {
457
+ return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
458
+ }
459
+ function isConfigError(error) {
460
+ return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
461
+ }
462
+ function isTimeoutError(error) {
463
+ return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
464
+ }
465
+ function isGoneError(error) {
466
+ return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
467
+ }
468
+ function isServiceUnavailableError(error) {
469
+ return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
470
+ }
471
+ function isUsageLimitError(error) {
472
+ return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
473
+ }
474
+ function isAuthError(error) {
475
+ return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
476
+ }
477
+ function isPermissionError(error) {
478
+ return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
479
+ }
480
+ function isNotFoundError(error) {
481
+ return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
482
+ }
483
+ function isConflictError(error) {
484
+ return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
485
+ }
486
+ function isRateLimitError(error) {
487
+ return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
488
+ }
377
489
  var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
378
490
  var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
379
491
  var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
@@ -571,11 +683,11 @@ function parseRetryAfter(response) {
571
683
  permitsAutomaticRetry: seconds <= MAX_AUTOMATIC_RETRY_AFTER_SECONDS
572
684
  };
573
685
  }
574
- function mapResponseToError(status, parsed, details, requestId, retryAfter, errorFamily) {
686
+ function mapResponseToError(status, parsed, details, requestId, retryAfter, canonicalCommerceError) {
575
687
  const errorDetails = {
576
688
  ...details,
577
689
  ...parsed.errors && { errors: parsed.errors },
578
- ...errorFamily !== "commerce" && parsed.body && { body: parsed.body }
690
+ ...!canonicalCommerceError && parsed.body && { body: parsed.body }
579
691
  };
580
692
  const suggestion = getParsedErrorSuggestion(status, parsed);
581
693
  const finalize = (error) => {
@@ -583,7 +695,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
583
695
  if (retryAfter !== void 0) {
584
696
  Object.assign(withRequestId, { retryAfter });
585
697
  }
586
- return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
698
+ return canonicalCommerceError ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
587
699
  };
588
700
  if (status === 400 || status === 422) {
589
701
  return finalize(
@@ -689,6 +801,7 @@ async function httpFetch(url, options) {
689
801
  retry,
690
802
  onUnauthorized,
691
803
  errorFamily,
804
+ typedCommerceErrorReasons,
692
805
  ...requestInit
693
806
  } = options || {};
694
807
  const baseUrl = resolveApiUrl(apiUrl);
@@ -742,7 +855,8 @@ async function httpFetch(url, options) {
742
855
  });
743
856
  if (!response.ok) {
744
857
  const parsed = await parseErrorBody(response);
745
- const commerceEnvelope = errorFamily === "commerce" ? parseCommerceErrorEnvelope(parsed.body, requestId) : void 0;
858
+ const canonicalCommerceError = errorFamily === "commerce" || typeof parsed.reason === "string" && typedCommerceErrorReasons?.includes(parsed.reason) === true;
859
+ const commerceEnvelope = canonicalCommerceError ? parseCommerceErrorEnvelope(parsed.body, requestId) : void 0;
746
860
  if (isUsageLimitExceededResponse(response)) {
747
861
  const limit = parseInt(
748
862
  response.headers.get("X-Usage-Limit") || "0",
@@ -770,7 +884,7 @@ async function httpFetch(url, options) {
770
884
  ),
771
885
  requestId
772
886
  );
773
- throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
887
+ throw canonicalCommerceError ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
774
888
  }
775
889
  if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
776
890
  hasRetried401 = true;
@@ -795,7 +909,7 @@ async function httpFetch(url, options) {
795
909
  details,
796
910
  requestId,
797
911
  retryAfter.seconds,
798
- errorFamily
912
+ canonicalCommerceError
799
913
  );
800
914
  const method2 = (requestInit.method || "GET").toUpperCase();
801
915
  const isTerminal = error instanceof RateLimitError || error instanceof UsageLimitError;
@@ -973,15 +1087,15 @@ var HttpClient = class {
973
1087
  throw err;
974
1088
  }
975
1089
  }
976
- buildUrl(endpoint2, options) {
977
- if (!options) return endpoint2;
1090
+ buildUrl(endpoint, options) {
1091
+ if (!options) return endpoint;
978
1092
  const { fallbackLocale, ...rest } = options;
979
1093
  const queryOptions = fallbackLocale === void 0 ? rest : {
980
1094
  ...rest,
981
1095
  "fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
982
1096
  };
983
1097
  const queryString = (0, import_qs_esm.stringify)(queryOptions, { addQueryPrefix: true });
984
- return queryString ? `${endpoint2}${queryString}` : endpoint2;
1098
+ return queryString ? `${endpoint}${queryString}` : endpoint;
985
1099
  }
986
1100
  assertJsonResponse(response) {
987
1101
  const contentType = response.headers.get("content-type");
@@ -1123,39 +1237,39 @@ var ReadOnlyCollectionClient = class extends HttpClient {
1123
1237
  from(collection) {
1124
1238
  return new ReadOnlyCollectionQueryBuilder(this, collection);
1125
1239
  }
1126
- async requestFind(endpoint2, options) {
1127
- const url = this.buildUrl(endpoint2, options);
1240
+ async requestFind(endpoint, options) {
1241
+ const url = this.buildUrl(endpoint, options);
1128
1242
  const response = await this.fetchWithTracking(url, {
1129
1243
  ...this.defaultOptions,
1130
1244
  method: "GET"
1131
1245
  });
1132
1246
  return this.parseFindResponse(response);
1133
1247
  }
1134
- async requestFindEndpoint(endpoint2, data) {
1135
- const response = await this.fetchWithTracking(endpoint2, {
1248
+ async requestFindEndpoint(endpoint, data) {
1249
+ const response = await this.fetchWithTracking(endpoint, {
1136
1250
  ...this.defaultOptions,
1137
1251
  method: "POST",
1138
1252
  body: data ? JSON.stringify(data) : void 0
1139
1253
  });
1140
1254
  return this.parseFindResponse(response);
1141
1255
  }
1142
- async requestFindEndpointGet(endpoint2) {
1143
- const response = await this.fetchWithTracking(endpoint2, {
1256
+ async requestFindEndpointGet(endpoint) {
1257
+ const response = await this.fetchWithTracking(endpoint, {
1144
1258
  ...this.defaultOptions,
1145
1259
  method: "GET"
1146
1260
  });
1147
1261
  return this.parseFindResponse(response);
1148
1262
  }
1149
- async requestFindById(endpoint2, options) {
1150
- const url = this.buildUrl(endpoint2, options);
1263
+ async requestFindById(endpoint, options) {
1264
+ const url = this.buildUrl(endpoint, options);
1151
1265
  const response = await this.fetchWithTracking(url, {
1152
1266
  ...this.defaultOptions,
1153
1267
  method: "GET"
1154
1268
  });
1155
1269
  return this.parseDocumentResponse(response);
1156
1270
  }
1157
- async requestCount(endpoint2, options) {
1158
- const url = this.buildUrl(endpoint2, options);
1271
+ async requestCount(endpoint, options) {
1272
+ const url = this.buildUrl(endpoint, options);
1159
1273
  const response = await this.fetchWithTracking(url, {
1160
1274
  ...this.defaultOptions,
1161
1275
  method: "GET"
@@ -1165,7 +1279,7 @@ var ReadOnlyCollectionClient = class extends HttpClient {
1165
1279
  };
1166
1280
 
1167
1281
  // src/core/api/parse-response.ts
1168
- async function parseApiResponse(response, endpoint2, options = {}) {
1282
+ async function parseApiResponse(response, endpoint, options = {}) {
1169
1283
  if (response.status === 204 || response.headers.get("content-length") === "0") {
1170
1284
  return void 0;
1171
1285
  }
@@ -1174,7 +1288,7 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1174
1288
  parsed = await response.json();
1175
1289
  } catch {
1176
1290
  throw createApiError(
1177
- `Invalid JSON response from ${endpoint2}`,
1291
+ `Invalid JSON response from ${endpoint}`,
1178
1292
  response.status,
1179
1293
  void 0,
1180
1294
  "Server returned an invalid response.",
@@ -1217,13 +1331,14 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1217
1331
  }
1218
1332
  const withRequestId = attachRequestId(error, requestId);
1219
1333
  if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
1220
- throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
1334
+ throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
1221
1335
  }
1222
1336
  return data;
1223
1337
  }
1224
1338
 
1225
1339
  // ../../internal/http-contracts/src/index.ts
1226
1340
  var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
1341
+ var PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE = "application/vnd.01software.portone-action-capabilities.v1+json";
1227
1342
  var operation = (collection, method, path, errorFamily) => Object.freeze({
1228
1343
  [operationBrand]: true,
1229
1344
  collection,
@@ -1232,6 +1347,10 @@ var operation = (collection, method, path, errorFamily) => Object.freeze({
1232
1347
  ...errorFamily && { errorFamily }
1233
1348
  });
1234
1349
  var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
1350
+ var selectiveCommerceOperation = (collection, method, path, typedCommerceErrorReasons) => Object.freeze({
1351
+ ...operation(collection, method, path),
1352
+ typedCommerceErrorReasons: Object.freeze([...typedCommerceErrorReasons])
1353
+ });
1235
1354
  var COMMERCE_ENDPOINT_OPERATIONS = {
1236
1355
  products: {
1237
1356
  detail: operation("products", "get", "/detail"),
@@ -1263,7 +1382,12 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1263
1382
  confirmPayment: operation("orders", "post", "/confirm-payment"),
1264
1383
  byPayment: operation("orders", "get", "/by-payment"),
1265
1384
  cancel: operation("orders", "post", "/cancel"),
1266
- resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
1385
+ resolveCancelRefund: selectiveCommerceOperation(
1386
+ "orders",
1387
+ "post",
1388
+ "/resolve-cancel-refund",
1389
+ ["managed_refund_attestation_forbidden"]
1390
+ ),
1267
1391
  checkout: strictCommerceOperation("orders", "post", "/checkout"),
1268
1392
  createFulfillment: operation("orders", "post", "/create-fulfillment"),
1269
1393
  updateFulfillment: operation("orders", "post", "/update-fulfillment")
@@ -1334,6 +1458,16 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1334
1458
  "payment-sessions",
1335
1459
  "post",
1336
1460
  "/server/confirm"
1461
+ ),
1462
+ findPortOne: strictCommerceOperation(
1463
+ "payment-sessions",
1464
+ "post",
1465
+ "/server/portone/find"
1466
+ ),
1467
+ reconcilePortOne: strictCommerceOperation(
1468
+ "payment-sessions",
1469
+ "post",
1470
+ "/server/portone/reconcile"
1337
1471
  )
1338
1472
  },
1339
1473
  custom: {
@@ -1353,12 +1487,26 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1353
1487
  validate: operation("discounts", "post", "/validate")
1354
1488
  }
1355
1489
  };
1490
+ var portOneStandardActionCapabilityOperations = /* @__PURE__ */ new Set([
1491
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create,
1492
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve,
1493
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create,
1494
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
1495
+ ]);
1356
1496
  var MEMBERSHIP_ENDPOINT_OPERATIONS = {
1357
1497
  subscribe: operation(null, "post", "/memberships/subscribe"),
1358
1498
  cancel: operation(null, "post", "/memberships/:id/cancel"),
1359
1499
  me: operation(null, "get", "/memberships/me")
1360
1500
  };
1501
+ var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
1502
+ show: operation("tenants", "get", "/embedded-admin-app"),
1503
+ configure: operation("tenants", "patch", "/embedded-admin-app"),
1504
+ disable: operation("tenants", "delete", "/embedded-admin-app")
1505
+ };
1361
1506
  var EVENTS_ENDPOINT_OPERATIONS = {
1507
+ events: {
1508
+ convertSchedule: operation("events", "post", "/:id/schedule")
1509
+ },
1362
1510
  occurrences: {
1363
1511
  range: operation("event-occurrences", "get", "/range"),
1364
1512
  admissionAvailability: operation(
@@ -1399,46 +1547,51 @@ function resolveOperationMethod(descriptor) {
1399
1547
  }
1400
1548
 
1401
1549
  // src/core/api/endpoints.ts
1402
- var endpoint = (method, path) => ({ method, path });
1403
1550
  var sharedEndpoint = (descriptor) => descriptor;
1404
- function resolveOperationMethod2(descriptor) {
1405
- return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
1406
- }
1407
1551
  function resolveOperationErrorFamily(descriptor) {
1408
- return "collection" in descriptor ? descriptor.errorFamily : void 0;
1409
- }
1410
- function resolveOperationPath2(descriptor, options) {
1411
- if ("collection" in descriptor) {
1412
- return resolveOperationPath(descriptor, options);
1413
- }
1414
- const query = options?.query?.toString().replace(/^\?/, "");
1415
- return query ? `${descriptor.path}?${query}` : descriptor.path;
1552
+ return descriptor.errorFamily;
1416
1553
  }
1417
1554
  var COMMERCE_ENDPOINTS = {
1418
1555
  products: {
1419
- detail: endpoint("GET", "/api/products/detail"),
1420
- detailCatalog: endpoint("GET", "/api/products/detail/catalog"),
1421
- listingGroups: endpoint("GET", "/api/products/listing-groups"),
1422
- listingGroupsCatalog: endpoint(
1423
- "GET",
1424
- "/api/products/listing-groups/catalog"
1556
+ detail: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.detail),
1557
+ detailCatalog: sharedEndpoint(
1558
+ COMMERCE_ENDPOINT_OPERATIONS.products.detailCatalog
1559
+ ),
1560
+ listingGroups: sharedEndpoint(
1561
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroups
1562
+ ),
1563
+ listingGroupsCatalog: sharedEndpoint(
1564
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsCatalog
1425
1565
  ),
1426
- listingGroupsQuery: endpoint("GET", "/api/products/listing-groups/query"),
1427
- listingGroupsQueryCatalog: endpoint(
1428
- "GET",
1429
- "/api/products/listing-groups/query/catalog"
1566
+ // The manifest keeps the GET read and the POST body-query apart; this
1567
+ // semantic name has always resolved to the GET one.
1568
+ listingGroupsQuery: sharedEndpoint(
1569
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryGet
1430
1570
  ),
1431
- stockCheck: endpoint("POST", "/api/products/stock-check"),
1432
- stockSnapshot: endpoint("GET", "/api/products/stock"),
1433
- upsert: endpoint("POST", "/api/products/upsert")
1571
+ listingGroupsQueryCatalog: sharedEndpoint(
1572
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryCatalog
1573
+ ),
1574
+ stockCheck: sharedEndpoint(
1575
+ COMMERCE_ENDPOINT_OPERATIONS.products.stockCheck
1576
+ ),
1577
+ stockSnapshot: sharedEndpoint(
1578
+ COMMERCE_ENDPOINT_OPERATIONS.products.stockSnapshot
1579
+ ),
1580
+ upsert: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.upsert)
1434
1581
  },
1435
1582
  orders: {
1436
- update: endpoint("POST", "/api/orders/update"),
1437
- byPayment: endpoint("GET", "/api/orders/by-payment"),
1438
- cancel: endpoint("POST", "/api/orders/cancel"),
1439
- resolveCancelRefund: endpoint("POST", "/api/orders/resolve-cancel-refund"),
1440
- createFulfillment: endpoint("POST", "/api/orders/create-fulfillment"),
1441
- updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
1583
+ update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.update),
1584
+ byPayment: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.byPayment),
1585
+ cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.cancel),
1586
+ resolveCancelRefund: sharedEndpoint(
1587
+ COMMERCE_ENDPOINT_OPERATIONS.orders.resolveCancelRefund
1588
+ ),
1589
+ createFulfillment: sharedEndpoint(
1590
+ COMMERCE_ENDPOINT_OPERATIONS.orders.createFulfillment
1591
+ ),
1592
+ updateFulfillment: sharedEndpoint(
1593
+ COMMERCE_ENDPOINT_OPERATIONS.orders.updateFulfillment
1594
+ )
1442
1595
  },
1443
1596
  checkouts: {
1444
1597
  create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
@@ -1450,18 +1603,21 @@ var COMMERCE_ENDPOINTS = {
1450
1603
  }
1451
1604
  },
1452
1605
  returns: {
1453
- create: endpoint("POST", "/api/returns/create"),
1454
- update: endpoint("POST", "/api/returns/update"),
1455
- returnRefund: endpoint("POST", "/api/returns/return-refund")
1606
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.create),
1607
+ update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.update),
1608
+ returnRefund: sharedEndpoint(
1609
+ COMMERCE_ENDPOINT_OPERATIONS.returns.returnRefund
1610
+ )
1456
1611
  },
1457
1612
  fulfillmentOrders: {
1458
- prepare: endpoint(
1459
- "POST",
1460
- "/api/fulfillment-orders/prepare-fulfillment-order"
1613
+ prepare: sharedEndpoint(
1614
+ COMMERCE_ENDPOINT_OPERATIONS.fulfillmentOrders.prepare
1461
1615
  )
1462
1616
  },
1463
1617
  fulfillments: {
1464
- bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
1618
+ bulkImport: sharedEndpoint(
1619
+ COMMERCE_ENDPOINT_OPERATIONS.fulfillments.bulkImport
1620
+ )
1465
1621
  },
1466
1622
  carts: {
1467
1623
  create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
@@ -1526,42 +1682,21 @@ var COMMERCE_ENDPOINTS = {
1526
1682
  ),
1527
1683
  confirm: sharedEndpoint(
1528
1684
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
1685
+ ),
1686
+ findPortOne: sharedEndpoint(
1687
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.findPortOne
1688
+ ),
1689
+ reconcilePortOne: sharedEndpoint(
1690
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.reconcilePortOne
1529
1691
  )
1530
1692
  }
1531
1693
  },
1532
1694
  shippingPolicies: {
1533
- calculate: endpoint("POST", "/api/shipping-policies/calculate")
1695
+ calculate: sharedEndpoint(
1696
+ COMMERCE_ENDPOINT_OPERATIONS.shippingPolicies.calculate
1697
+ )
1534
1698
  }
1535
1699
  };
1536
- function isCommerceEndpointDescriptor(value) {
1537
- if (!value || typeof value !== "object") return false;
1538
- const candidate = value;
1539
- return typeof candidate.method === "string" && typeof candidate.path === "string";
1540
- }
1541
- function flattenEndpointPaths(value) {
1542
- if (isCommerceEndpointDescriptor(value)) return [resolveOperationPath2(value)];
1543
- if (!value || typeof value !== "object") return [];
1544
- return Object.values(value).flatMap((entry) => flattenEndpointPaths(entry));
1545
- }
1546
- function flattenEndpointDescriptors(value) {
1547
- if (isCommerceEndpointDescriptor(value)) return [value];
1548
- if (!value || typeof value !== "object") return [];
1549
- return Object.values(value).flatMap(
1550
- (entry) => flattenEndpointDescriptors(entry)
1551
- );
1552
- }
1553
- var COMMERCE_ENDPOINT_PATHS = flattenEndpointPaths(COMMERCE_ENDPOINTS);
1554
- var COMMERCE_ENDPOINT_DESCRIPTORS = flattenEndpointDescriptors(COMMERCE_ENDPOINTS);
1555
- var MEMBERSHIP_ENDPOINTS = {
1556
- subscribe: "/api/memberships/subscribe",
1557
- cancel: (id) => `/api/memberships/${id}/cancel`,
1558
- me: "/api/memberships/me"
1559
- };
1560
- var MEMBERSHIP_ENDPOINT_PATHS = [
1561
- MEMBERSHIP_ENDPOINTS.subscribe,
1562
- MEMBERSHIP_ENDPOINTS.cancel(":id"),
1563
- MEMBERSHIP_ENDPOINTS.me
1564
- ];
1565
1700
 
1566
1701
  // src/core/api/customer-scoped-api.ts
1567
1702
  var CustomerScopedTransport = class {
@@ -1582,10 +1717,10 @@ var CustomerScopedTransport = class {
1582
1717
  this.onUnauthorized = options.onUnauthorized;
1583
1718
  this.onRequestId = options.onRequestId;
1584
1719
  }
1585
- async request(endpoint2, options) {
1720
+ async request(endpoint, options) {
1586
1721
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1587
1722
  try {
1588
- const response = await httpFetch(endpoint2, {
1723
+ const response = await httpFetch(endpoint, {
1589
1724
  method: options.method,
1590
1725
  apiUrl: this.apiUrl,
1591
1726
  publishableKey: this.publishableKey,
@@ -1599,7 +1734,7 @@ var CustomerScopedTransport = class {
1599
1734
  ...options.errorFamily && { errorFamily: options.errorFamily }
1600
1735
  });
1601
1736
  this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1602
- return parseApiResponse(response, endpoint2, {
1737
+ return parseApiResponse(response, endpoint, {
1603
1738
  errorFamily: options.errorFamily
1604
1739
  });
1605
1740
  } catch (err) {
@@ -1613,12 +1748,12 @@ var CustomerScopedApi = class {
1613
1748
  constructor(apiName, options) {
1614
1749
  this.transport = new CustomerScopedTransport(apiName, options);
1615
1750
  }
1616
- requestEndpoint(endpoint2, body, options) {
1617
- return this.transport.request(resolveOperationPath2(endpoint2, options), {
1618
- method: resolveOperationMethod2(endpoint2),
1751
+ requestEndpoint(endpoint, body, options) {
1752
+ return this.transport.request(resolveOperationPath(endpoint, options), {
1753
+ method: resolveOperationMethod(endpoint),
1619
1754
  body,
1620
1755
  headers: options?.headers,
1621
- errorFamily: resolveOperationErrorFamily(endpoint2)
1756
+ errorFamily: resolveOperationErrorFamily(endpoint)
1622
1757
  });
1623
1758
  }
1624
1759
  };
@@ -1626,8 +1761,8 @@ var RawCustomerScopedApi = class {
1626
1761
  constructor(apiName, options) {
1627
1762
  this.transport = new CustomerScopedTransport(apiName, options);
1628
1763
  }
1629
- request(endpoint2, options) {
1630
- return this.transport.request(endpoint2, options);
1764
+ request(endpoint, options) {
1765
+ return this.transport.request(endpoint, options);
1631
1766
  }
1632
1767
  };
1633
1768
 
@@ -1641,13 +1776,7 @@ function unwrapPayloadDoc(value) {
1641
1776
  return value;
1642
1777
  }
1643
1778
  function hasCanonicalNotFoundReason(error) {
1644
- const details = error.details;
1645
- if (typeof details !== "object" || details === null) return false;
1646
- if ("reason" in details && details.reason === "not_found") return true;
1647
- if (!("body" in details) || typeof details.body !== "object" || details.body === null) {
1648
- return false;
1649
- }
1650
- return "reason" in details.body && details.body.reason === "not_found";
1779
+ return getSDKErrorReason(error) === "not_found";
1651
1780
  }
1652
1781
  var CommunityClient = class extends RawCustomerScopedApi {
1653
1782
  constructor(options) {
@@ -1708,11 +1837,11 @@ var CommunityClient = class extends RawCustomerScopedApi {
1708
1837
  if (params.page !== void 0) urlParams.set("page", String(params.page));
1709
1838
  return `/api/comments/public?${urlParams.toString()}`;
1710
1839
  }
1711
- async execute(endpoint2, method, body) {
1712
- return this.request(endpoint2, { method, body });
1840
+ async execute(endpoint, method, body) {
1841
+ return this.request(endpoint, { method, body });
1713
1842
  }
1714
- async executeDoc(endpoint2, method, body) {
1715
- const response = await this.execute(endpoint2, method, body);
1843
+ async executeDoc(endpoint, method, body) {
1844
+ const response = await this.execute(endpoint, method, body);
1716
1845
  return unwrapPayloadDoc(response);
1717
1846
  }
1718
1847
  createPost(params) {
@@ -1978,8 +2107,8 @@ var CommunityClient = class extends RawCustomerScopedApi {
1978
2107
 
1979
2108
  // src/core/content/content-client.ts
1980
2109
  var PublicContentApi = class extends RawCustomerScopedApi {
1981
- get(endpoint2) {
1982
- return this.request(endpoint2, { method: "GET" });
2110
+ get(endpoint) {
2111
+ return this.request(endpoint, { method: "GET" });
1983
2112
  }
1984
2113
  };
1985
2114
  function appendCommonParams(search, options, defaultSort) {
@@ -2160,6 +2289,9 @@ function nullableString(value, resource, path) {
2160
2289
  fail(resource, path, "string or null");
2161
2290
  }
2162
2291
  }
2292
+ function nullableNonEmptyString(value, resource, path) {
2293
+ if (value !== null) string(value, resource, path);
2294
+ }
2163
2295
  function cartLineQuantity(value, resource, path) {
2164
2296
  const quantity = positiveInteger(value, resource, path);
2165
2297
  if (quantity > MAX_CART_LINE_QUANTITY) {
@@ -2669,8 +2801,8 @@ function validatePublicOrderItem(value, resource, path) {
2669
2801
  validateReference(item.variant, resource, `${path}.variant`);
2670
2802
  }
2671
2803
  string(item.productTitle, resource, `${path}.productTitle`);
2672
- nullableString(item.variantTitle, resource, `${path}.variantTitle`);
2673
- nullableString(item.sku, resource, `${path}.sku`);
2804
+ nullableNonEmptyString(item.variantTitle, resource, `${path}.variantTitle`);
2805
+ nullableNonEmptyString(item.sku, resource, `${path}.sku`);
2674
2806
  validateAdmissions(item.admissions, resource, `${path}.admissions`);
2675
2807
  const quantity = positiveInteger(item.quantity, resource, `${path}.quantity`);
2676
2808
  const unitPrice = safeMinor(
@@ -2921,8 +3053,8 @@ function validateCheckoutItem(value, resource, path) {
2921
3053
  validateReference(item.product, resource, `${path}.product`);
2922
3054
  validateReference(item.variant, resource, `${path}.variant`);
2923
3055
  string(item.productTitle, resource, `${path}.productTitle`);
2924
- nullableString(item.variantTitle, resource, `${path}.variantTitle`);
2925
- nullableString(item.sku, resource, `${path}.sku`);
3056
+ nullableNonEmptyString(item.variantTitle, resource, `${path}.variantTitle`);
3057
+ nullableNonEmptyString(item.sku, resource, `${path}.sku`);
2926
3058
  validateAdmissions(item.admissions, resource, `${path}.admissions`);
2927
3059
  cartLineQuantity(item.quantity, resource, `${path}.quantity`);
2928
3060
  const unitPrice = safeMinor(
@@ -3253,9 +3385,96 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
3253
3385
  function validateNextAction(value, provider, resource, path) {
3254
3386
  const action = record(value, resource, path);
3255
3387
  if (provider === "portone") {
3388
+ if (action.type === "portone_sdk") {
3389
+ const hasCancelable = "cancelable" in action;
3390
+ const hasRetryPolicy = "retryPolicy" in action;
3391
+ if (hasCancelable !== hasRetryPolicy) {
3392
+ fail(
3393
+ resource,
3394
+ path,
3395
+ "exact released action or exact negotiated capability action"
3396
+ );
3397
+ }
3398
+ exact(
3399
+ action,
3400
+ [
3401
+ "type",
3402
+ "version",
3403
+ ...hasCancelable ? ["cancelable", "retryPolicy"] : [],
3404
+ "storeId",
3405
+ "channelKey",
3406
+ "paymentId",
3407
+ "orderName",
3408
+ "totalAmount",
3409
+ "currency",
3410
+ "payMethod",
3411
+ "redirectUrl"
3412
+ ],
3413
+ [],
3414
+ resource,
3415
+ path
3416
+ );
3417
+ if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
3418
+ if (hasCancelable && action.cancelable !== false)
3419
+ fail(resource, `${path}.cancelable`, "false");
3420
+ if (hasRetryPolicy && action.retryPolicy !== "same_action_only") {
3421
+ fail(resource, `${path}.retryPolicy`, "same_action_only");
3422
+ }
3423
+ for (const key of ["storeId", "channelKey"]) {
3424
+ boundedString(action[key], 255, resource, `${path}.${key}`);
3425
+ }
3426
+ const paymentId = boundedString(
3427
+ action.paymentId,
3428
+ 40,
3429
+ resource,
3430
+ `${path}.paymentId`
3431
+ );
3432
+ if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
3433
+ fail(
3434
+ resource,
3435
+ `${path}.paymentId`,
3436
+ "6-40 ASCII alphanumeric characters"
3437
+ );
3438
+ }
3439
+ boundedString(
3440
+ action.orderName,
3441
+ MAX_COMMERCE_SHORT_TEXT_LENGTH,
3442
+ resource,
3443
+ `${path}.orderName`
3444
+ );
3445
+ positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
3446
+ if (action.currency !== "CURRENCY_KRW") {
3447
+ fail(resource, `${path}.currency`, "CURRENCY_KRW");
3448
+ }
3449
+ if (action.payMethod !== "CARD")
3450
+ fail(resource, `${path}.payMethod`, "CARD");
3451
+ const redirectUrl = boundedString(
3452
+ action.redirectUrl,
3453
+ 2048,
3454
+ resource,
3455
+ `${path}.redirectUrl`
3456
+ );
3457
+ try {
3458
+ const parsed = new URL(redirectUrl);
3459
+ const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
3460
+ if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
3461
+ throw new Error("unsafe redirect URL");
3462
+ } catch {
3463
+ fail(
3464
+ resource,
3465
+ `${path}.redirectUrl`,
3466
+ "HTTPS or loopback URL without embedded credentials"
3467
+ );
3468
+ }
3469
+ if (!hasCancelable) {
3470
+ action.cancelable = false;
3471
+ action.retryPolicy = "same_action_only";
3472
+ }
3473
+ return;
3474
+ }
3256
3475
  exact(action, ["type", "checkoutUrl"], [], resource, path);
3257
3476
  if (action.type !== "portone_checkout") {
3258
- fail(resource, `${path}.type`, "portone_checkout");
3477
+ fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
3259
3478
  }
3260
3479
  const checkoutUrl = boundedString(
3261
3480
  action.checkoutUrl,
@@ -3981,8 +4200,8 @@ var CartApi = class extends CustomerScopedApi {
3981
4200
  endpoint(key) {
3982
4201
  return this.serverTransport ? COMMERCE_ENDPOINTS.carts.server[key] : COMMERCE_ENDPOINTS.carts[key];
3983
4202
  }
3984
- execute(endpoint2, body, idempotencyKey) {
3985
- return this.requestEndpoint(endpoint2, body, {
4203
+ execute(endpoint, body, idempotencyKey) {
4204
+ return this.requestEndpoint(endpoint, body, {
3986
4205
  ...idempotencyKey && {
3987
4206
  headers: { "X-Idempotency-Key": idempotencyKey }
3988
4207
  }
@@ -3999,26 +4218,26 @@ var CartApi = class extends CustomerScopedApi {
3999
4218
  );
4000
4219
  }
4001
4220
  mine(params = {}) {
4002
- const endpoint2 = this.endpoint("mine");
4003
- return this.execute(endpoint2, params).then(
4221
+ const endpoint = this.endpoint("mine");
4222
+ return this.execute(endpoint, params).then(
4004
4223
  (value) => validateCartMineResult(value)
4005
4224
  );
4006
4225
  }
4007
4226
  merge(params) {
4008
4227
  const { idempotencyKey, ...body } = params;
4009
4228
  assertCommerceIdempotencyKey(idempotencyKey);
4010
- const endpoint2 = this.endpoint("merge");
4011
- return this.execute(endpoint2, body, idempotencyKey).then(
4229
+ const endpoint = this.endpoint("merge");
4230
+ return this.execute(endpoint, body, idempotencyKey).then(
4012
4231
  (value) => validateCartMergeResult(value)
4013
4232
  );
4014
4233
  }
4015
4234
  addItem(params) {
4016
4235
  return this.mutate(this.endpoint("addItem"), params);
4017
4236
  }
4018
- mutate(endpoint2, params) {
4237
+ mutate(endpoint, params) {
4019
4238
  const { idempotencyKey, ...body } = params;
4020
4239
  assertCommerceIdempotencyKey(idempotencyKey);
4021
- return this.execute(endpoint2, body, idempotencyKey).then(
4240
+ return this.execute(endpoint, body, idempotencyKey).then(
4022
4241
  (value) => validateCartMutationResult(value)
4023
4242
  );
4024
4243
  }
@@ -4044,8 +4263,8 @@ var CheckoutApi = class extends CustomerScopedApi {
4044
4263
  constructor(options) {
4045
4264
  super("CheckoutApi", { ...options, requiresCredential: false });
4046
4265
  }
4047
- post(endpoint2, body, idempotencyKey) {
4048
- return this.requestEndpoint(endpoint2, body, {
4266
+ post(endpoint, body, idempotencyKey) {
4267
+ return this.requestEndpoint(endpoint, body, {
4049
4268
  ...idempotencyKey && {
4050
4269
  headers: { "X-Idempotency-Key": idempotencyKey }
4051
4270
  }
@@ -4112,11 +4331,15 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4112
4331
  super("PaymentSessionApi", { ...options, requiresCredential: false });
4113
4332
  this.serverTransport = Boolean(options.secretKey);
4114
4333
  }
4115
- post(endpoint2, body, idempotencyKey) {
4116
- return this.requestEndpoint(endpoint2, body, {
4117
- ...idempotencyKey && {
4118
- headers: { "X-Idempotency-Key": idempotencyKey }
4334
+ post(endpoint, body, idempotencyKey, negotiateStandardActionCapabilities = false) {
4335
+ const headers = {
4336
+ ...idempotencyKey && { "X-Idempotency-Key": idempotencyKey },
4337
+ ...negotiateStandardActionCapabilities && {
4338
+ Accept: PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE
4119
4339
  }
4340
+ };
4341
+ return this.requestEndpoint(endpoint, body, {
4342
+ ...Object.keys(headers).length > 0 && { headers }
4120
4343
  });
4121
4344
  }
4122
4345
  async paymentSession(result, expectedProvider) {
@@ -4141,40 +4364,41 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4141
4364
  this.post(
4142
4365
  this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
4143
4366
  body,
4144
- idempotencyKey
4367
+ idempotencyKey,
4368
+ body.providerOptions.profile === "standard_v2"
4145
4369
  ),
4146
4370
  "portone"
4147
4371
  );
4148
4372
  }
4149
4373
  retrieve(params) {
4150
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4374
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4151
4375
  return this.paymentSession(
4152
- this.post(endpoint2, params),
4376
+ this.post(endpoint, params),
4153
4377
  "toss"
4154
4378
  );
4155
4379
  }
4156
4380
  retrievePortOne(params) {
4157
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4381
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4158
4382
  return this.paymentSession(
4159
- this.post(endpoint2, params),
4383
+ this.post(endpoint, params, void 0, true),
4160
4384
  "portone"
4161
4385
  );
4162
4386
  }
4163
4387
  cancel(params) {
4164
4388
  const { idempotencyKey, ...body } = params;
4165
4389
  assertCommerceIdempotencyKey(idempotencyKey);
4166
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4390
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4167
4391
  return this.paymentSession(
4168
- this.post(endpoint2, body, idempotencyKey),
4392
+ this.post(endpoint, body, idempotencyKey),
4169
4393
  "toss"
4170
4394
  );
4171
4395
  }
4172
4396
  cancelPortOne(params) {
4173
4397
  const { idempotencyKey, ...body } = params;
4174
4398
  assertCommerceIdempotencyKey(idempotencyKey);
4175
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4399
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4176
4400
  return this.paymentSession(
4177
- this.post(endpoint2, body, idempotencyKey),
4401
+ this.post(endpoint, body, idempotencyKey),
4178
4402
  "portone"
4179
4403
  );
4180
4404
  }
@@ -5218,21 +5442,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
5218
5442
  "not_published",
5219
5443
  "feature_disabled"
5220
5444
  ]);
5221
- function isRecord(value) {
5222
- return typeof value === "object" && value !== null;
5223
- }
5224
- function readProductDetailUnavailableReason(value) {
5225
- if (!isRecord(value)) return void 0;
5226
- const directReason = value.reason ?? value.code;
5227
- if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
5228
- return directReason;
5229
- }
5230
- return readProductDetailUnavailableReason(value.body);
5231
- }
5232
5445
  function productDetailResultFromError(error) {
5233
5446
  if (!(error instanceof SDKError) || error.status !== 404) return void 0;
5234
- const reason = readProductDetailUnavailableReason(error.details);
5235
- if (!reason) return void 0;
5447
+ const reason = getSDKErrorReason(error);
5448
+ if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
5449
+ return void 0;
5236
5450
  return { found: false, reason };
5237
5451
  }
5238
5452
  var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
@@ -5325,8 +5539,8 @@ function withProductListingCards(response, options) {
5325
5539
 
5326
5540
  // src/core/commerce/commerce-client.ts
5327
5541
  var BrowserCommerceApi = class extends CustomerScopedApi {
5328
- requestEndpoint(endpoint2, body, options) {
5329
- return super.requestEndpoint(endpoint2, body, options);
5542
+ requestEndpoint(endpoint, body, options) {
5543
+ return super.requestEndpoint(endpoint, body, options);
5330
5544
  }
5331
5545
  };
5332
5546
  var CommerceClient = class {
@@ -5526,11 +5740,11 @@ var EventsClient = class {
5526
5740
  { useCustomerAuth: false }
5527
5741
  );
5528
5742
  }
5529
- async execute(endpoint2, method, body, options = {}) {
5743
+ async execute(endpoint, method, body, options = {}) {
5530
5744
  const useCustomerAuth = options.useCustomerAuth === true;
5531
5745
  const token = useCustomerAuth ? typeof this.customerToken === "function" ? this.customerToken() : this.customerToken : void 0;
5532
5746
  try {
5533
- const response = await httpFetch(endpoint2, {
5747
+ const response = await httpFetch(endpoint, {
5534
5748
  method,
5535
5749
  apiUrl: this.apiUrl,
5536
5750
  publishableKey: this.publishableKey,
@@ -5539,7 +5753,7 @@ var EventsClient = class {
5539
5753
  ...body !== void 0 && { body: JSON.stringify(body) }
5540
5754
  });
5541
5755
  this.onRequestId?.(response.headers.get("x-request-id") ?? null);
5542
- return parseApiResponse(response, endpoint2);
5756
+ return parseApiResponse(response, endpoint);
5543
5757
  } catch (err) {
5544
5758
  const id = err instanceof SDKError ? err.requestId ?? null : null;
5545
5759
  this.onRequestId?.(id);