@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.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 instanceof SDKError) || error.kind !== "commerce") return false;
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, errorFamily) {
643
+ function mapResponseToError(status, parsed, details, requestId, retryAfter, canonicalCommerceError) {
547
644
  const errorDetails = {
548
645
  ...details,
549
646
  ...parsed.errors && { errors: parsed.errors },
550
- ...errorFamily !== "commerce" && parsed.body && { body: parsed.body }
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 errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
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 commerceEnvelope = errorFamily === "commerce" ? parseCommerceErrorEnvelope(parsed.body, requestId) : void 0;
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 errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
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
- errorFamily
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(endpoint2, options) {
949
- if (!options) return endpoint2;
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 ? `${endpoint2}${queryString}` : endpoint2;
1055
+ return queryString ? `${endpoint}${queryString}` : endpoint;
957
1056
  }
958
1057
  assertJsonResponse(response) {
959
1058
  const contentType = response.headers.get("content-type");
@@ -1095,39 +1194,39 @@ var ReadOnlyCollectionClient = class extends HttpClient {
1095
1194
  from(collection) {
1096
1195
  return new ReadOnlyCollectionQueryBuilder(this, collection);
1097
1196
  }
1098
- async requestFind(endpoint2, options) {
1099
- const url = this.buildUrl(endpoint2, options);
1197
+ async requestFind(endpoint, options) {
1198
+ const url = this.buildUrl(endpoint, options);
1100
1199
  const response = await this.fetchWithTracking(url, {
1101
1200
  ...this.defaultOptions,
1102
1201
  method: "GET"
1103
1202
  });
1104
1203
  return this.parseFindResponse(response);
1105
1204
  }
1106
- async requestFindEndpoint(endpoint2, data) {
1107
- const response = await this.fetchWithTracking(endpoint2, {
1205
+ async requestFindEndpoint(endpoint, data) {
1206
+ const response = await this.fetchWithTracking(endpoint, {
1108
1207
  ...this.defaultOptions,
1109
1208
  method: "POST",
1110
1209
  body: data ? JSON.stringify(data) : void 0
1111
1210
  });
1112
1211
  return this.parseFindResponse(response);
1113
1212
  }
1114
- async requestFindEndpointGet(endpoint2) {
1115
- const response = await this.fetchWithTracking(endpoint2, {
1213
+ async requestFindEndpointGet(endpoint) {
1214
+ const response = await this.fetchWithTracking(endpoint, {
1116
1215
  ...this.defaultOptions,
1117
1216
  method: "GET"
1118
1217
  });
1119
1218
  return this.parseFindResponse(response);
1120
1219
  }
1121
- async requestFindById(endpoint2, options) {
1122
- const url = this.buildUrl(endpoint2, options);
1220
+ async requestFindById(endpoint, options) {
1221
+ const url = this.buildUrl(endpoint, options);
1123
1222
  const response = await this.fetchWithTracking(url, {
1124
1223
  ...this.defaultOptions,
1125
1224
  method: "GET"
1126
1225
  });
1127
1226
  return this.parseDocumentResponse(response);
1128
1227
  }
1129
- async requestCount(endpoint2, options) {
1130
- const url = this.buildUrl(endpoint2, options);
1228
+ async requestCount(endpoint, options) {
1229
+ const url = this.buildUrl(endpoint, options);
1131
1230
  const response = await this.fetchWithTracking(url, {
1132
1231
  ...this.defaultOptions,
1133
1232
  method: "GET"
@@ -1137,7 +1236,7 @@ var ReadOnlyCollectionClient = class extends HttpClient {
1137
1236
  };
1138
1237
 
1139
1238
  // src/core/api/parse-response.ts
1140
- async function parseApiResponse(response, endpoint2, options = {}) {
1239
+ async function parseApiResponse(response, endpoint, options = {}) {
1141
1240
  if (response.status === 204 || response.headers.get("content-length") === "0") {
1142
1241
  return void 0;
1143
1242
  }
@@ -1146,7 +1245,7 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1146
1245
  parsed = await response.json();
1147
1246
  } catch {
1148
1247
  throw createApiError(
1149
- `Invalid JSON response from ${endpoint2}`,
1248
+ `Invalid JSON response from ${endpoint}`,
1150
1249
  response.status,
1151
1250
  void 0,
1152
1251
  "Server returned an invalid response.",
@@ -1189,13 +1288,14 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1189
1288
  }
1190
1289
  const withRequestId = attachRequestId(error, requestId);
1191
1290
  if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
1192
- throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
1291
+ throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
1193
1292
  }
1194
1293
  return data;
1195
1294
  }
1196
1295
 
1197
1296
  // ../../internal/http-contracts/src/index.ts
1198
1297
  var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
1298
+ var PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE = "application/vnd.01software.portone-action-capabilities.v1+json";
1199
1299
  var operation = (collection, method, path, errorFamily) => Object.freeze({
1200
1300
  [operationBrand]: true,
1201
1301
  collection,
@@ -1204,6 +1304,10 @@ var operation = (collection, method, path, errorFamily) => Object.freeze({
1204
1304
  ...errorFamily && { errorFamily }
1205
1305
  });
1206
1306
  var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
1307
+ var selectiveCommerceOperation = (collection, method, path, typedCommerceErrorReasons) => Object.freeze({
1308
+ ...operation(collection, method, path),
1309
+ typedCommerceErrorReasons: Object.freeze([...typedCommerceErrorReasons])
1310
+ });
1207
1311
  var COMMERCE_ENDPOINT_OPERATIONS = {
1208
1312
  products: {
1209
1313
  detail: operation("products", "get", "/detail"),
@@ -1235,7 +1339,12 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1235
1339
  confirmPayment: operation("orders", "post", "/confirm-payment"),
1236
1340
  byPayment: operation("orders", "get", "/by-payment"),
1237
1341
  cancel: operation("orders", "post", "/cancel"),
1238
- resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
1342
+ resolveCancelRefund: selectiveCommerceOperation(
1343
+ "orders",
1344
+ "post",
1345
+ "/resolve-cancel-refund",
1346
+ ["managed_refund_attestation_forbidden"]
1347
+ ),
1239
1348
  checkout: strictCommerceOperation("orders", "post", "/checkout"),
1240
1349
  createFulfillment: operation("orders", "post", "/create-fulfillment"),
1241
1350
  updateFulfillment: operation("orders", "post", "/update-fulfillment")
@@ -1306,6 +1415,16 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1306
1415
  "payment-sessions",
1307
1416
  "post",
1308
1417
  "/server/confirm"
1418
+ ),
1419
+ findPortOne: strictCommerceOperation(
1420
+ "payment-sessions",
1421
+ "post",
1422
+ "/server/portone/find"
1423
+ ),
1424
+ reconcilePortOne: strictCommerceOperation(
1425
+ "payment-sessions",
1426
+ "post",
1427
+ "/server/portone/reconcile"
1309
1428
  )
1310
1429
  },
1311
1430
  custom: {
@@ -1325,12 +1444,26 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1325
1444
  validate: operation("discounts", "post", "/validate")
1326
1445
  }
1327
1446
  };
1447
+ var portOneStandardActionCapabilityOperations = /* @__PURE__ */ new Set([
1448
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create,
1449
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve,
1450
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create,
1451
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
1452
+ ]);
1328
1453
  var MEMBERSHIP_ENDPOINT_OPERATIONS = {
1329
1454
  subscribe: operation(null, "post", "/memberships/subscribe"),
1330
1455
  cancel: operation(null, "post", "/memberships/:id/cancel"),
1331
1456
  me: operation(null, "get", "/memberships/me")
1332
1457
  };
1458
+ var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
1459
+ show: operation("tenants", "get", "/embedded-admin-app"),
1460
+ configure: operation("tenants", "patch", "/embedded-admin-app"),
1461
+ disable: operation("tenants", "delete", "/embedded-admin-app")
1462
+ };
1333
1463
  var EVENTS_ENDPOINT_OPERATIONS = {
1464
+ events: {
1465
+ convertSchedule: operation("events", "post", "/:id/schedule")
1466
+ },
1334
1467
  occurrences: {
1335
1468
  range: operation("event-occurrences", "get", "/range"),
1336
1469
  admissionAvailability: operation(
@@ -1371,46 +1504,51 @@ function resolveOperationMethod(descriptor) {
1371
1504
  }
1372
1505
 
1373
1506
  // src/core/api/endpoints.ts
1374
- var endpoint = (method, path) => ({ method, path });
1375
1507
  var sharedEndpoint = (descriptor) => descriptor;
1376
- function resolveOperationMethod2(descriptor) {
1377
- return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
1378
- }
1379
1508
  function resolveOperationErrorFamily(descriptor) {
1380
- return "collection" in descriptor ? descriptor.errorFamily : void 0;
1381
- }
1382
- function resolveOperationPath2(descriptor, options) {
1383
- if ("collection" in descriptor) {
1384
- return resolveOperationPath(descriptor, options);
1385
- }
1386
- const query = options?.query?.toString().replace(/^\?/, "");
1387
- return query ? `${descriptor.path}?${query}` : descriptor.path;
1509
+ return descriptor.errorFamily;
1388
1510
  }
1389
1511
  var COMMERCE_ENDPOINTS = {
1390
1512
  products: {
1391
- detail: endpoint("GET", "/api/products/detail"),
1392
- detailCatalog: endpoint("GET", "/api/products/detail/catalog"),
1393
- listingGroups: endpoint("GET", "/api/products/listing-groups"),
1394
- listingGroupsCatalog: endpoint(
1395
- "GET",
1396
- "/api/products/listing-groups/catalog"
1513
+ detail: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.detail),
1514
+ detailCatalog: sharedEndpoint(
1515
+ COMMERCE_ENDPOINT_OPERATIONS.products.detailCatalog
1516
+ ),
1517
+ listingGroups: sharedEndpoint(
1518
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroups
1519
+ ),
1520
+ listingGroupsCatalog: sharedEndpoint(
1521
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsCatalog
1397
1522
  ),
1398
- listingGroupsQuery: endpoint("GET", "/api/products/listing-groups/query"),
1399
- listingGroupsQueryCatalog: endpoint(
1400
- "GET",
1401
- "/api/products/listing-groups/query/catalog"
1523
+ // The manifest keeps the GET read and the POST body-query apart; this
1524
+ // semantic name has always resolved to the GET one.
1525
+ listingGroupsQuery: sharedEndpoint(
1526
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryGet
1402
1527
  ),
1403
- stockCheck: endpoint("POST", "/api/products/stock-check"),
1404
- stockSnapshot: endpoint("GET", "/api/products/stock"),
1405
- upsert: endpoint("POST", "/api/products/upsert")
1528
+ listingGroupsQueryCatalog: sharedEndpoint(
1529
+ COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryCatalog
1530
+ ),
1531
+ stockCheck: sharedEndpoint(
1532
+ COMMERCE_ENDPOINT_OPERATIONS.products.stockCheck
1533
+ ),
1534
+ stockSnapshot: sharedEndpoint(
1535
+ COMMERCE_ENDPOINT_OPERATIONS.products.stockSnapshot
1536
+ ),
1537
+ upsert: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.upsert)
1406
1538
  },
1407
1539
  orders: {
1408
- update: endpoint("POST", "/api/orders/update"),
1409
- byPayment: endpoint("GET", "/api/orders/by-payment"),
1410
- cancel: endpoint("POST", "/api/orders/cancel"),
1411
- resolveCancelRefund: endpoint("POST", "/api/orders/resolve-cancel-refund"),
1412
- createFulfillment: endpoint("POST", "/api/orders/create-fulfillment"),
1413
- updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
1540
+ update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.update),
1541
+ byPayment: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.byPayment),
1542
+ cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.cancel),
1543
+ resolveCancelRefund: sharedEndpoint(
1544
+ COMMERCE_ENDPOINT_OPERATIONS.orders.resolveCancelRefund
1545
+ ),
1546
+ createFulfillment: sharedEndpoint(
1547
+ COMMERCE_ENDPOINT_OPERATIONS.orders.createFulfillment
1548
+ ),
1549
+ updateFulfillment: sharedEndpoint(
1550
+ COMMERCE_ENDPOINT_OPERATIONS.orders.updateFulfillment
1551
+ )
1414
1552
  },
1415
1553
  checkouts: {
1416
1554
  create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
@@ -1422,18 +1560,21 @@ var COMMERCE_ENDPOINTS = {
1422
1560
  }
1423
1561
  },
1424
1562
  returns: {
1425
- create: endpoint("POST", "/api/returns/create"),
1426
- update: endpoint("POST", "/api/returns/update"),
1427
- returnRefund: endpoint("POST", "/api/returns/return-refund")
1563
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.create),
1564
+ update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.update),
1565
+ returnRefund: sharedEndpoint(
1566
+ COMMERCE_ENDPOINT_OPERATIONS.returns.returnRefund
1567
+ )
1428
1568
  },
1429
1569
  fulfillmentOrders: {
1430
- prepare: endpoint(
1431
- "POST",
1432
- "/api/fulfillment-orders/prepare-fulfillment-order"
1570
+ prepare: sharedEndpoint(
1571
+ COMMERCE_ENDPOINT_OPERATIONS.fulfillmentOrders.prepare
1433
1572
  )
1434
1573
  },
1435
1574
  fulfillments: {
1436
- bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
1575
+ bulkImport: sharedEndpoint(
1576
+ COMMERCE_ENDPOINT_OPERATIONS.fulfillments.bulkImport
1577
+ )
1437
1578
  },
1438
1579
  carts: {
1439
1580
  create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
@@ -1498,42 +1639,21 @@ var COMMERCE_ENDPOINTS = {
1498
1639
  ),
1499
1640
  confirm: sharedEndpoint(
1500
1641
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
1642
+ ),
1643
+ findPortOne: sharedEndpoint(
1644
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.findPortOne
1645
+ ),
1646
+ reconcilePortOne: sharedEndpoint(
1647
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.reconcilePortOne
1501
1648
  )
1502
1649
  }
1503
1650
  },
1504
1651
  shippingPolicies: {
1505
- calculate: endpoint("POST", "/api/shipping-policies/calculate")
1652
+ calculate: sharedEndpoint(
1653
+ COMMERCE_ENDPOINT_OPERATIONS.shippingPolicies.calculate
1654
+ )
1506
1655
  }
1507
1656
  };
1508
- function isCommerceEndpointDescriptor(value) {
1509
- if (!value || typeof value !== "object") return false;
1510
- const candidate = value;
1511
- return typeof candidate.method === "string" && typeof candidate.path === "string";
1512
- }
1513
- function flattenEndpointPaths(value) {
1514
- if (isCommerceEndpointDescriptor(value)) return [resolveOperationPath2(value)];
1515
- if (!value || typeof value !== "object") return [];
1516
- return Object.values(value).flatMap((entry) => flattenEndpointPaths(entry));
1517
- }
1518
- function flattenEndpointDescriptors(value) {
1519
- if (isCommerceEndpointDescriptor(value)) return [value];
1520
- if (!value || typeof value !== "object") return [];
1521
- return Object.values(value).flatMap(
1522
- (entry) => flattenEndpointDescriptors(entry)
1523
- );
1524
- }
1525
- var COMMERCE_ENDPOINT_PATHS = flattenEndpointPaths(COMMERCE_ENDPOINTS);
1526
- var COMMERCE_ENDPOINT_DESCRIPTORS = flattenEndpointDescriptors(COMMERCE_ENDPOINTS);
1527
- var MEMBERSHIP_ENDPOINTS = {
1528
- subscribe: "/api/memberships/subscribe",
1529
- cancel: (id) => `/api/memberships/${id}/cancel`,
1530
- me: "/api/memberships/me"
1531
- };
1532
- var MEMBERSHIP_ENDPOINT_PATHS = [
1533
- MEMBERSHIP_ENDPOINTS.subscribe,
1534
- MEMBERSHIP_ENDPOINTS.cancel(":id"),
1535
- MEMBERSHIP_ENDPOINTS.me
1536
- ];
1537
1657
 
1538
1658
  // src/core/api/customer-scoped-api.ts
1539
1659
  var CustomerScopedTransport = class {
@@ -1554,10 +1674,10 @@ var CustomerScopedTransport = class {
1554
1674
  this.onUnauthorized = options.onUnauthorized;
1555
1675
  this.onRequestId = options.onRequestId;
1556
1676
  }
1557
- async request(endpoint2, options) {
1677
+ async request(endpoint, options) {
1558
1678
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1559
1679
  try {
1560
- const response = await httpFetch(endpoint2, {
1680
+ const response = await httpFetch(endpoint, {
1561
1681
  method: options.method,
1562
1682
  apiUrl: this.apiUrl,
1563
1683
  publishableKey: this.publishableKey,
@@ -1571,7 +1691,7 @@ var CustomerScopedTransport = class {
1571
1691
  ...options.errorFamily && { errorFamily: options.errorFamily }
1572
1692
  });
1573
1693
  this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1574
- return parseApiResponse(response, endpoint2, {
1694
+ return parseApiResponse(response, endpoint, {
1575
1695
  errorFamily: options.errorFamily
1576
1696
  });
1577
1697
  } catch (err) {
@@ -1585,12 +1705,12 @@ var CustomerScopedApi = class {
1585
1705
  constructor(apiName, options) {
1586
1706
  this.transport = new CustomerScopedTransport(apiName, options);
1587
1707
  }
1588
- requestEndpoint(endpoint2, body, options) {
1589
- return this.transport.request(resolveOperationPath2(endpoint2, options), {
1590
- method: resolveOperationMethod2(endpoint2),
1708
+ requestEndpoint(endpoint, body, options) {
1709
+ return this.transport.request(resolveOperationPath(endpoint, options), {
1710
+ method: resolveOperationMethod(endpoint),
1591
1711
  body,
1592
1712
  headers: options?.headers,
1593
- errorFamily: resolveOperationErrorFamily(endpoint2)
1713
+ errorFamily: resolveOperationErrorFamily(endpoint)
1594
1714
  });
1595
1715
  }
1596
1716
  };
@@ -1598,8 +1718,8 @@ var RawCustomerScopedApi = class {
1598
1718
  constructor(apiName, options) {
1599
1719
  this.transport = new CustomerScopedTransport(apiName, options);
1600
1720
  }
1601
- request(endpoint2, options) {
1602
- return this.transport.request(endpoint2, options);
1721
+ request(endpoint, options) {
1722
+ return this.transport.request(endpoint, options);
1603
1723
  }
1604
1724
  };
1605
1725
 
@@ -1613,13 +1733,7 @@ function unwrapPayloadDoc(value) {
1613
1733
  return value;
1614
1734
  }
1615
1735
  function hasCanonicalNotFoundReason(error) {
1616
- const details = error.details;
1617
- if (typeof details !== "object" || details === null) return false;
1618
- if ("reason" in details && details.reason === "not_found") return true;
1619
- if (!("body" in details) || typeof details.body !== "object" || details.body === null) {
1620
- return false;
1621
- }
1622
- return "reason" in details.body && details.body.reason === "not_found";
1736
+ return getSDKErrorReason(error) === "not_found";
1623
1737
  }
1624
1738
  var CommunityClient = class extends RawCustomerScopedApi {
1625
1739
  constructor(options) {
@@ -1680,11 +1794,11 @@ var CommunityClient = class extends RawCustomerScopedApi {
1680
1794
  if (params.page !== void 0) urlParams.set("page", String(params.page));
1681
1795
  return `/api/comments/public?${urlParams.toString()}`;
1682
1796
  }
1683
- async execute(endpoint2, method, body) {
1684
- return this.request(endpoint2, { method, body });
1797
+ async execute(endpoint, method, body) {
1798
+ return this.request(endpoint, { method, body });
1685
1799
  }
1686
- async executeDoc(endpoint2, method, body) {
1687
- const response = await this.execute(endpoint2, method, body);
1800
+ async executeDoc(endpoint, method, body) {
1801
+ const response = await this.execute(endpoint, method, body);
1688
1802
  return unwrapPayloadDoc(response);
1689
1803
  }
1690
1804
  createPost(params) {
@@ -1950,8 +2064,8 @@ var CommunityClient = class extends RawCustomerScopedApi {
1950
2064
 
1951
2065
  // src/core/content/content-client.ts
1952
2066
  var PublicContentApi = class extends RawCustomerScopedApi {
1953
- get(endpoint2) {
1954
- return this.request(endpoint2, { method: "GET" });
2067
+ get(endpoint) {
2068
+ return this.request(endpoint, { method: "GET" });
1955
2069
  }
1956
2070
  };
1957
2071
  function appendCommonParams(search, options, defaultSort) {
@@ -2132,6 +2246,9 @@ function nullableString(value, resource, path) {
2132
2246
  fail(resource, path, "string or null");
2133
2247
  }
2134
2248
  }
2249
+ function nullableNonEmptyString(value, resource, path) {
2250
+ if (value !== null) string(value, resource, path);
2251
+ }
2135
2252
  function cartLineQuantity(value, resource, path) {
2136
2253
  const quantity = positiveInteger(value, resource, path);
2137
2254
  if (quantity > MAX_CART_LINE_QUANTITY) {
@@ -2641,8 +2758,8 @@ function validatePublicOrderItem(value, resource, path) {
2641
2758
  validateReference(item.variant, resource, `${path}.variant`);
2642
2759
  }
2643
2760
  string(item.productTitle, resource, `${path}.productTitle`);
2644
- nullableString(item.variantTitle, resource, `${path}.variantTitle`);
2645
- nullableString(item.sku, resource, `${path}.sku`);
2761
+ nullableNonEmptyString(item.variantTitle, resource, `${path}.variantTitle`);
2762
+ nullableNonEmptyString(item.sku, resource, `${path}.sku`);
2646
2763
  validateAdmissions(item.admissions, resource, `${path}.admissions`);
2647
2764
  const quantity = positiveInteger(item.quantity, resource, `${path}.quantity`);
2648
2765
  const unitPrice = safeMinor(
@@ -2893,8 +3010,8 @@ function validateCheckoutItem(value, resource, path) {
2893
3010
  validateReference(item.product, resource, `${path}.product`);
2894
3011
  validateReference(item.variant, resource, `${path}.variant`);
2895
3012
  string(item.productTitle, resource, `${path}.productTitle`);
2896
- nullableString(item.variantTitle, resource, `${path}.variantTitle`);
2897
- nullableString(item.sku, resource, `${path}.sku`);
3013
+ nullableNonEmptyString(item.variantTitle, resource, `${path}.variantTitle`);
3014
+ nullableNonEmptyString(item.sku, resource, `${path}.sku`);
2898
3015
  validateAdmissions(item.admissions, resource, `${path}.admissions`);
2899
3016
  cartLineQuantity(item.quantity, resource, `${path}.quantity`);
2900
3017
  const unitPrice = safeMinor(
@@ -3225,9 +3342,96 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
3225
3342
  function validateNextAction(value, provider, resource, path) {
3226
3343
  const action = record(value, resource, path);
3227
3344
  if (provider === "portone") {
3345
+ if (action.type === "portone_sdk") {
3346
+ const hasCancelable = "cancelable" in action;
3347
+ const hasRetryPolicy = "retryPolicy" in action;
3348
+ if (hasCancelable !== hasRetryPolicy) {
3349
+ fail(
3350
+ resource,
3351
+ path,
3352
+ "exact released action or exact negotiated capability action"
3353
+ );
3354
+ }
3355
+ exact(
3356
+ action,
3357
+ [
3358
+ "type",
3359
+ "version",
3360
+ ...hasCancelable ? ["cancelable", "retryPolicy"] : [],
3361
+ "storeId",
3362
+ "channelKey",
3363
+ "paymentId",
3364
+ "orderName",
3365
+ "totalAmount",
3366
+ "currency",
3367
+ "payMethod",
3368
+ "redirectUrl"
3369
+ ],
3370
+ [],
3371
+ resource,
3372
+ path
3373
+ );
3374
+ if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
3375
+ if (hasCancelable && action.cancelable !== false)
3376
+ fail(resource, `${path}.cancelable`, "false");
3377
+ if (hasRetryPolicy && action.retryPolicy !== "same_action_only") {
3378
+ fail(resource, `${path}.retryPolicy`, "same_action_only");
3379
+ }
3380
+ for (const key of ["storeId", "channelKey"]) {
3381
+ boundedString(action[key], 255, resource, `${path}.${key}`);
3382
+ }
3383
+ const paymentId = boundedString(
3384
+ action.paymentId,
3385
+ 40,
3386
+ resource,
3387
+ `${path}.paymentId`
3388
+ );
3389
+ if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
3390
+ fail(
3391
+ resource,
3392
+ `${path}.paymentId`,
3393
+ "6-40 ASCII alphanumeric characters"
3394
+ );
3395
+ }
3396
+ boundedString(
3397
+ action.orderName,
3398
+ MAX_COMMERCE_SHORT_TEXT_LENGTH,
3399
+ resource,
3400
+ `${path}.orderName`
3401
+ );
3402
+ positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
3403
+ if (action.currency !== "CURRENCY_KRW") {
3404
+ fail(resource, `${path}.currency`, "CURRENCY_KRW");
3405
+ }
3406
+ if (action.payMethod !== "CARD")
3407
+ fail(resource, `${path}.payMethod`, "CARD");
3408
+ const redirectUrl = boundedString(
3409
+ action.redirectUrl,
3410
+ 2048,
3411
+ resource,
3412
+ `${path}.redirectUrl`
3413
+ );
3414
+ try {
3415
+ const parsed = new URL(redirectUrl);
3416
+ const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
3417
+ if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
3418
+ throw new Error("unsafe redirect URL");
3419
+ } catch {
3420
+ fail(
3421
+ resource,
3422
+ `${path}.redirectUrl`,
3423
+ "HTTPS or loopback URL without embedded credentials"
3424
+ );
3425
+ }
3426
+ if (!hasCancelable) {
3427
+ action.cancelable = false;
3428
+ action.retryPolicy = "same_action_only";
3429
+ }
3430
+ return;
3431
+ }
3228
3432
  exact(action, ["type", "checkoutUrl"], [], resource, path);
3229
3433
  if (action.type !== "portone_checkout") {
3230
- fail(resource, `${path}.type`, "portone_checkout");
3434
+ fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
3231
3435
  }
3232
3436
  const checkoutUrl = boundedString(
3233
3437
  action.checkoutUrl,
@@ -3953,8 +4157,8 @@ var CartApi = class extends CustomerScopedApi {
3953
4157
  endpoint(key) {
3954
4158
  return this.serverTransport ? COMMERCE_ENDPOINTS.carts.server[key] : COMMERCE_ENDPOINTS.carts[key];
3955
4159
  }
3956
- execute(endpoint2, body, idempotencyKey) {
3957
- return this.requestEndpoint(endpoint2, body, {
4160
+ execute(endpoint, body, idempotencyKey) {
4161
+ return this.requestEndpoint(endpoint, body, {
3958
4162
  ...idempotencyKey && {
3959
4163
  headers: { "X-Idempotency-Key": idempotencyKey }
3960
4164
  }
@@ -3971,26 +4175,26 @@ var CartApi = class extends CustomerScopedApi {
3971
4175
  );
3972
4176
  }
3973
4177
  mine(params = {}) {
3974
- const endpoint2 = this.endpoint("mine");
3975
- return this.execute(endpoint2, params).then(
4178
+ const endpoint = this.endpoint("mine");
4179
+ return this.execute(endpoint, params).then(
3976
4180
  (value) => validateCartMineResult(value)
3977
4181
  );
3978
4182
  }
3979
4183
  merge(params) {
3980
4184
  const { idempotencyKey, ...body } = params;
3981
4185
  assertCommerceIdempotencyKey(idempotencyKey);
3982
- const endpoint2 = this.endpoint("merge");
3983
- return this.execute(endpoint2, body, idempotencyKey).then(
4186
+ const endpoint = this.endpoint("merge");
4187
+ return this.execute(endpoint, body, idempotencyKey).then(
3984
4188
  (value) => validateCartMergeResult(value)
3985
4189
  );
3986
4190
  }
3987
4191
  addItem(params) {
3988
4192
  return this.mutate(this.endpoint("addItem"), params);
3989
4193
  }
3990
- mutate(endpoint2, params) {
4194
+ mutate(endpoint, params) {
3991
4195
  const { idempotencyKey, ...body } = params;
3992
4196
  assertCommerceIdempotencyKey(idempotencyKey);
3993
- return this.execute(endpoint2, body, idempotencyKey).then(
4197
+ return this.execute(endpoint, body, idempotencyKey).then(
3994
4198
  (value) => validateCartMutationResult(value)
3995
4199
  );
3996
4200
  }
@@ -4016,8 +4220,8 @@ var CheckoutApi = class extends CustomerScopedApi {
4016
4220
  constructor(options) {
4017
4221
  super("CheckoutApi", { ...options, requiresCredential: false });
4018
4222
  }
4019
- post(endpoint2, body, idempotencyKey) {
4020
- return this.requestEndpoint(endpoint2, body, {
4223
+ post(endpoint, body, idempotencyKey) {
4224
+ return this.requestEndpoint(endpoint, body, {
4021
4225
  ...idempotencyKey && {
4022
4226
  headers: { "X-Idempotency-Key": idempotencyKey }
4023
4227
  }
@@ -4084,11 +4288,15 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4084
4288
  super("PaymentSessionApi", { ...options, requiresCredential: false });
4085
4289
  this.serverTransport = Boolean(options.secretKey);
4086
4290
  }
4087
- post(endpoint2, body, idempotencyKey) {
4088
- return this.requestEndpoint(endpoint2, body, {
4089
- ...idempotencyKey && {
4090
- headers: { "X-Idempotency-Key": idempotencyKey }
4291
+ post(endpoint, body, idempotencyKey, negotiateStandardActionCapabilities = false) {
4292
+ const headers = {
4293
+ ...idempotencyKey && { "X-Idempotency-Key": idempotencyKey },
4294
+ ...negotiateStandardActionCapabilities && {
4295
+ Accept: PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE
4091
4296
  }
4297
+ };
4298
+ return this.requestEndpoint(endpoint, body, {
4299
+ ...Object.keys(headers).length > 0 && { headers }
4092
4300
  });
4093
4301
  }
4094
4302
  async paymentSession(result, expectedProvider) {
@@ -4113,40 +4321,41 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4113
4321
  this.post(
4114
4322
  this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
4115
4323
  body,
4116
- idempotencyKey
4324
+ idempotencyKey,
4325
+ body.providerOptions.profile === "standard_v2"
4117
4326
  ),
4118
4327
  "portone"
4119
4328
  );
4120
4329
  }
4121
4330
  retrieve(params) {
4122
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4331
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4123
4332
  return this.paymentSession(
4124
- this.post(endpoint2, params),
4333
+ this.post(endpoint, params),
4125
4334
  "toss"
4126
4335
  );
4127
4336
  }
4128
4337
  retrievePortOne(params) {
4129
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4338
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4130
4339
  return this.paymentSession(
4131
- this.post(endpoint2, params),
4340
+ this.post(endpoint, params, void 0, true),
4132
4341
  "portone"
4133
4342
  );
4134
4343
  }
4135
4344
  cancel(params) {
4136
4345
  const { idempotencyKey, ...body } = params;
4137
4346
  assertCommerceIdempotencyKey(idempotencyKey);
4138
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4347
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4139
4348
  return this.paymentSession(
4140
- this.post(endpoint2, body, idempotencyKey),
4349
+ this.post(endpoint, body, idempotencyKey),
4141
4350
  "toss"
4142
4351
  );
4143
4352
  }
4144
4353
  cancelPortOne(params) {
4145
4354
  const { idempotencyKey, ...body } = params;
4146
4355
  assertCommerceIdempotencyKey(idempotencyKey);
4147
- const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4356
+ const endpoint = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4148
4357
  return this.paymentSession(
4149
- this.post(endpoint2, body, idempotencyKey),
4358
+ this.post(endpoint, body, idempotencyKey),
4150
4359
  "portone"
4151
4360
  );
4152
4361
  }
@@ -5190,21 +5399,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
5190
5399
  "not_published",
5191
5400
  "feature_disabled"
5192
5401
  ]);
5193
- function isRecord(value) {
5194
- return typeof value === "object" && value !== null;
5195
- }
5196
- function readProductDetailUnavailableReason(value) {
5197
- if (!isRecord(value)) return void 0;
5198
- const directReason = value.reason ?? value.code;
5199
- if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
5200
- return directReason;
5201
- }
5202
- return readProductDetailUnavailableReason(value.body);
5203
- }
5204
5402
  function productDetailResultFromError(error) {
5205
5403
  if (!(error instanceof SDKError) || error.status !== 404) return void 0;
5206
- const reason = readProductDetailUnavailableReason(error.details);
5207
- if (!reason) return void 0;
5404
+ const reason = getSDKErrorReason(error);
5405
+ if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
5406
+ return void 0;
5208
5407
  return { found: false, reason };
5209
5408
  }
5210
5409
  var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
@@ -5297,8 +5496,8 @@ function withProductListingCards(response, options) {
5297
5496
 
5298
5497
  // src/core/commerce/commerce-client.ts
5299
5498
  var BrowserCommerceApi = class extends CustomerScopedApi {
5300
- requestEndpoint(endpoint2, body, options) {
5301
- return super.requestEndpoint(endpoint2, body, options);
5499
+ requestEndpoint(endpoint, body, options) {
5500
+ return super.requestEndpoint(endpoint, body, options);
5302
5501
  }
5303
5502
  };
5304
5503
  var CommerceClient = class {
@@ -5498,11 +5697,11 @@ var EventsClient = class {
5498
5697
  { useCustomerAuth: false }
5499
5698
  );
5500
5699
  }
5501
- async execute(endpoint2, method, body, options = {}) {
5700
+ async execute(endpoint, method, body, options = {}) {
5502
5701
  const useCustomerAuth = options.useCustomerAuth === true;
5503
5702
  const token = useCustomerAuth ? typeof this.customerToken === "function" ? this.customerToken() : this.customerToken : void 0;
5504
5703
  try {
5505
- const response = await httpFetch(endpoint2, {
5704
+ const response = await httpFetch(endpoint, {
5506
5705
  method,
5507
5706
  apiUrl: this.apiUrl,
5508
5707
  publishableKey: this.publishableKey,
@@ -5511,7 +5710,7 @@ var EventsClient = class {
5511
5710
  ...body !== void 0 && { body: JSON.stringify(body) }
5512
5711
  });
5513
5712
  this.onRequestId?.(response.headers.get("x-request-id") ?? null);
5514
- return parseApiResponse(response, endpoint2);
5713
+ return parseApiResponse(response, endpoint);
5515
5714
  } catch (err) {
5516
5715
  const id = err instanceof SDKError ? err.requestId ?? null : null;
5517
5716
  this.onRequestId?.(id);
@@ -5731,6 +5930,21 @@ function createClient(options) {
5731
5930
  export {
5732
5931
  Client,
5733
5932
  ContentClient,
5734
- createClient
5933
+ createClient,
5934
+ isApiError,
5935
+ isAuthError,
5936
+ isCommerceSDKError,
5937
+ isConfigError,
5938
+ isConflictError,
5939
+ isGoneError,
5940
+ isNetworkError,
5941
+ isNotFoundError,
5942
+ isPermissionError,
5943
+ isRateLimitError,
5944
+ isSDKError,
5945
+ isServiceUnavailableError,
5946
+ isTimeoutError,
5947
+ isUsageLimitError,
5948
+ isValidationError
5735
5949
  };
5736
5950
  //# sourceMappingURL=client.js.map