@01.software/sdk 0.46.1 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +96 -1
  2. package/README.md +145 -14
  3. package/dist/client.cjs +485 -81
  4. package/dist/client.cjs.map +1 -1
  5. package/dist/client.d.cts +7 -6
  6. package/dist/client.d.ts +7 -6
  7. package/dist/client.js +485 -81
  8. package/dist/client.js.map +1 -1
  9. package/dist/{collection-client-BEGXnfQe.d.ts → collection-client-DnDt6EQz.d.ts} +4 -4
  10. package/dist/{collection-client-L2rEgBaR.d.cts → collection-client-XfGLPuTf.d.cts} +4 -4
  11. package/dist/{const-y0eipvnQ.d.cts → const-CBba4lDo.d.cts} +4 -4
  12. package/dist/{const-GYVwlXLr.d.ts → const-DCNV5Kq7.d.ts} +4 -4
  13. package/dist/errors.cjs +112 -16
  14. package/dist/errors.cjs.map +1 -1
  15. package/dist/errors.d.cts +13 -4
  16. package/dist/errors.d.ts +13 -4
  17. package/dist/errors.js +112 -16
  18. package/dist/errors.js.map +1 -1
  19. package/dist/{index-BfYL6Qb1.d.cts → index-CbKyoEzy.d.cts} +3 -3
  20. package/dist/{index-Bei4WlVw.d.ts → index-DUuIqUS8.d.ts} +3 -3
  21. package/dist/index.cjs +452 -104
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +8 -8
  24. package/dist/index.d.ts +8 -8
  25. package/dist/index.js +452 -104
  26. package/dist/index.js.map +1 -1
  27. package/dist/{payload-types-3WNyC0gk.d.cts → payload-types-MKbx5MuJ.d.cts} +309 -17
  28. package/dist/{payload-types-3WNyC0gk.d.ts → payload-types-MKbx5MuJ.d.ts} +309 -17
  29. package/dist/query.cjs +165 -43
  30. package/dist/query.cjs.map +1 -1
  31. package/dist/query.d.cts +5 -5
  32. package/dist/query.d.ts +5 -5
  33. package/dist/query.js +165 -43
  34. package/dist/query.js.map +1 -1
  35. package/dist/realtime.d.cts +2 -2
  36. package/dist/realtime.d.ts +2 -2
  37. package/dist/server.cjs +566 -81
  38. package/dist/server.cjs.map +1 -1
  39. package/dist/server.d.cts +8 -7
  40. package/dist/server.d.ts +8 -7
  41. package/dist/server.js +566 -81
  42. package/dist/server.js.map +1 -1
  43. package/dist/storefront-cache.cjs +70 -1
  44. package/dist/storefront-cache.cjs.map +1 -1
  45. package/dist/storefront-cache.js +70 -1
  46. package/dist/storefront-cache.js.map +1 -1
  47. package/dist/{types-mIROvhhP.d.ts → types-1UeOk1Uy.d.cts} +110 -8
  48. package/dist/{types-CAicTn-o.d.cts → types-BKr_2avj.d.cts} +2 -2
  49. package/dist/{types-CDJ2M-MJ.d.cts → types-Du4s5anw.d.ts} +110 -8
  50. package/dist/{types-DpSyNTxy.d.ts → types-L_nh-ED7.d.ts} +2 -2
  51. package/dist/ui/form.d.cts +1 -1
  52. package/dist/ui/form.d.ts +1 -1
  53. package/dist/ui/video.d.cts +1 -1
  54. package/dist/ui/video.d.ts +1 -1
  55. package/dist/webhook.d.cts +4 -4
  56. package/dist/webhook.d.ts +4 -4
  57. package/package.json +6 -5
package/dist/server.js CHANGED
@@ -2,6 +2,24 @@
2
2
  import { stringify } from "qs-esm";
3
3
 
4
4
  // src/core/errors.ts
5
+ var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
6
+ var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
7
+ function defineSDKErrorBrand(error) {
8
+ Object.defineProperty(error, SDK_ERROR_BRAND, {
9
+ value: true,
10
+ enumerable: false,
11
+ configurable: false,
12
+ writable: false
13
+ });
14
+ }
15
+ function defineSDKErrorType(error, type) {
16
+ Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
17
+ value: type,
18
+ enumerable: false,
19
+ configurable: false,
20
+ writable: false
21
+ });
22
+ }
5
23
  var SDKError = class extends Error {
6
24
  constructor(code, message, status, details, userMessage, suggestion, requestId) {
7
25
  super(message);
@@ -12,6 +30,7 @@ var SDKError = class extends Error {
12
30
  this.userMessage = userMessage;
13
31
  this.suggestion = suggestion;
14
32
  this.requestId = requestId;
33
+ defineSDKErrorBrand(this);
15
34
  if (Error.captureStackTrace) {
16
35
  Error.captureStackTrace(this, new.target);
17
36
  }
@@ -32,6 +51,7 @@ var SDKError = class extends Error {
32
51
  ...this.kind !== void 0 && { kind: this.kind },
33
52
  ...this.reason !== void 0 && { reason: this.reason },
34
53
  ...this.rawReason !== void 0 && { rawReason: this.rawReason },
54
+ ...this.apiReason !== void 0 && { apiReason: this.apiReason },
35
55
  ...this.retryable !== void 0 && { retryable: this.retryable },
36
56
  ...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
37
57
  };
@@ -39,34 +59,78 @@ var SDKError = class extends Error {
39
59
  };
40
60
  var COMMERCE_ERROR_CODES = [
41
61
  "validation_failed",
62
+ "bad_request",
42
63
  "unauthorized",
43
64
  "forbidden",
65
+ "account_suspended",
66
+ "key_invalid",
67
+ "pat_tenant_header_forbidden",
68
+ "tenant_mismatch",
69
+ "test_tenant_expired",
70
+ "token_invalid",
44
71
  "token_expired",
45
72
  "origin_not_allowed",
46
73
  "server_credentials_required",
74
+ "role_denied",
75
+ "scope_denied",
76
+ "feature_disabled",
47
77
  "not_found",
48
78
  "conflict",
79
+ "locked",
49
80
  "cart_revision_conflict",
50
81
  "rate_limit_exceeded",
51
82
  "usage_limit_exceeded",
52
83
  "service_unavailable",
53
84
  "idempotency_conflict",
54
85
  "idempotency_in_progress",
86
+ "idempotency_key_required",
87
+ "invalid_idempotency_key",
55
88
  "cart_not_active",
56
89
  "cart_locked",
57
90
  "cart_empty",
58
91
  "cart_market_unavailable",
59
92
  "cart_market_mismatch",
60
93
  "checkout_not_open",
94
+ "checkout_already_open",
61
95
  "payment_slot_held",
62
96
  "reservation_expired",
63
97
  "payment_session_not_cancelable",
98
+ "payment_session_conflict",
64
99
  "provider_identity_mismatch",
100
+ "payment_method_unavailable",
65
101
  "provider_unavailable",
66
102
  "lock_timeout",
67
103
  "price_changed",
68
104
  "pricing_fact_in_use",
69
105
  "insufficient_stock",
106
+ "reservation_conflict",
107
+ "stock_lock_unavailable",
108
+ "variant_not_found",
109
+ "variant_stock_write_failed",
110
+ "stock_invariant_violation",
111
+ "payment_confirmation_in_flight",
112
+ "checkout_reservation_release_requires_transaction",
113
+ "admission_metadata_invalid",
114
+ "admission_metadata_required",
115
+ "capacity_exceeded",
116
+ "occurrence_lock_unavailable",
117
+ "occurrence_not_open",
118
+ "admission_type_capacity_exceeded",
119
+ "admission_type_occurrence_mismatch",
120
+ "admission_hold_expired",
121
+ "admission_hold_checkout_item_conflict",
122
+ "admission_hold_checkout_conflict",
123
+ "admission_hold_quantity_mismatch",
124
+ "admission_hold_unbound",
125
+ "admission_hold_missing",
126
+ "admission_hold_checkout_item_missing",
127
+ "admission_hold_expiry_failed",
128
+ "admission_hold_expiry_requires_transaction",
129
+ "admission_hold_line_item_mismatch",
130
+ "admission_materialization_failed",
131
+ "variant_inactive",
132
+ "variant_product_mismatch",
133
+ "product_not_public",
70
134
  "market_not_found",
71
135
  "market_shipping_currency_unsupported",
72
136
  "missing_market_rate",
@@ -91,7 +155,11 @@ var COMMERCE_ERROR_CODES = [
91
155
  "discount_min_order_amount",
92
156
  "discount_currency_scope_required",
93
157
  "discount_allocation_method_unsupported",
94
- "currency_mismatch"
158
+ "currency_mismatch",
159
+ "customer_token_required",
160
+ "market_required",
161
+ "server_derived",
162
+ "internal_error"
95
163
  ];
96
164
  var COMMERCE_ERROR_CODE_SET = new Set(
97
165
  COMMERCE_ERROR_CODES
@@ -117,6 +185,12 @@ function commerceProtocolError(issue, trustedRequestId) {
117
185
  );
118
186
  }
119
187
  function parseCommerceErrorEnvelope(body, headerRequestId) {
188
+ if (headerRequestId === void 0) {
189
+ throw commerceProtocolError("missing_request_id_header");
190
+ }
191
+ if (headerRequestId.length === 0) {
192
+ throw commerceProtocolError("empty_request_id_header");
193
+ }
120
194
  if (!isPlainRecord(body)) {
121
195
  throw commerceProtocolError("expected_object", headerRequestId);
122
196
  }
@@ -126,7 +200,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
126
200
  if (typeof body.error !== "string" || body.error.length === 0 || typeof body.reason !== "string" || body.reason.length === 0 || typeof body.requestId !== "string" || body.requestId.length === 0 || body.retryable !== void 0 && typeof body.retryable !== "boolean" || body.details !== void 0 && !isPlainRecord(body.details)) {
127
201
  throw commerceProtocolError("invalid_field", headerRequestId);
128
202
  }
129
- if (headerRequestId && headerRequestId !== body.requestId) {
203
+ if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
130
204
  throw commerceProtocolError("request_id_mismatch", headerRequestId);
131
205
  }
132
206
  return {
@@ -151,8 +225,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
151
225
  });
152
226
  return error;
153
227
  }
228
+ function enhanceNonCommerceError(error, reason) {
229
+ if (typeof reason === "string") Object.assign(error, { apiReason: reason });
230
+ return error;
231
+ }
232
+ function getSDKErrorReason(error) {
233
+ if (error.kind !== "commerce") return error.apiReason;
234
+ return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
235
+ }
154
236
  function isCommerceSDKError(error) {
155
- if (!(error instanceof SDKError) || error.kind !== "commerce") return false;
237
+ if (!isSDKError(error) || error.kind !== "commerce") return false;
156
238
  if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
157
239
  return false;
158
240
  }
@@ -162,12 +244,14 @@ var NetworkError = class extends SDKError {
162
244
  constructor(message, status, details, userMessage, suggestion) {
163
245
  super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
164
246
  this.name = "NetworkError";
247
+ defineSDKErrorType(this, "NetworkError");
165
248
  }
166
249
  };
167
250
  var ValidationError = class extends SDKError {
168
251
  constructor(message, details, userMessage, suggestion, status = 400) {
169
252
  super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
170
253
  this.name = "ValidationError";
254
+ defineSDKErrorType(this, "ValidationError");
171
255
  }
172
256
  };
173
257
  var ApiError = class extends SDKError {
@@ -182,24 +266,28 @@ var ApiError = class extends SDKError {
182
266
  requestId
183
267
  );
184
268
  this.name = "ApiError";
269
+ defineSDKErrorType(this, "ApiError");
185
270
  }
186
271
  };
187
272
  var ConfigError = class extends SDKError {
188
273
  constructor(message, details, userMessage, suggestion) {
189
274
  super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
190
275
  this.name = "ConfigError";
276
+ defineSDKErrorType(this, "ConfigError");
191
277
  }
192
278
  };
193
279
  var TimeoutError = class extends SDKError {
194
280
  constructor(message = "Request timed out.", details, userMessage, suggestion) {
195
281
  super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
196
282
  this.name = "TimeoutError";
283
+ defineSDKErrorType(this, "TimeoutError");
197
284
  }
198
285
  };
199
286
  var GoneError = class extends SDKError {
200
287
  constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
201
288
  super("GONE_ERROR", message, 410, details, userMessage, suggestion);
202
289
  this.name = "GoneError";
290
+ defineSDKErrorType(this, "GoneError");
203
291
  }
204
292
  };
205
293
  var ServiceUnavailableError = class extends SDKError {
@@ -214,6 +302,7 @@ var ServiceUnavailableError = class extends SDKError {
214
302
  );
215
303
  this.name = "ServiceUnavailableError";
216
304
  this.retryAfter = retryAfter;
305
+ defineSDKErrorType(this, "ServiceUnavailableError");
217
306
  }
218
307
  };
219
308
  var UsageLimitError = class extends SDKError {
@@ -221,6 +310,7 @@ var UsageLimitError = class extends SDKError {
221
310
  super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
222
311
  this.name = "UsageLimitError";
223
312
  this.usage = usage;
313
+ defineSDKErrorType(this, "UsageLimitError");
224
314
  }
225
315
  toJSON() {
226
316
  return {
@@ -241,6 +331,7 @@ var AuthError = class extends SDKError {
241
331
  requestId
242
332
  );
243
333
  this.name = "AuthError";
334
+ defineSDKErrorType(this, "AuthError");
244
335
  }
245
336
  };
246
337
  var PermissionError = class extends SDKError {
@@ -255,6 +346,7 @@ var PermissionError = class extends SDKError {
255
346
  requestId
256
347
  );
257
348
  this.name = "PermissionError";
349
+ defineSDKErrorType(this, "PermissionError");
258
350
  }
259
351
  };
260
352
  var NotFoundError = class extends SDKError {
@@ -269,12 +361,14 @@ var NotFoundError = class extends SDKError {
269
361
  requestId
270
362
  );
271
363
  this.name = "NotFoundError";
364
+ defineSDKErrorType(this, "NotFoundError");
272
365
  }
273
366
  };
274
367
  var ConflictError = class extends SDKError {
275
368
  constructor(message, details, userMessage, suggestion, requestId) {
276
369
  super("conflict", message, 409, details, userMessage, suggestion, requestId);
277
370
  this.name = "ConflictError";
371
+ defineSDKErrorType(this, "ConflictError");
278
372
  }
279
373
  };
280
374
  var RateLimitError = class extends SDKError {
@@ -290,8 +384,64 @@ var RateLimitError = class extends SDKError {
290
384
  );
291
385
  this.name = "RateLimitError";
292
386
  this.retryAfter = retryAfter;
387
+ defineSDKErrorType(this, "RateLimitError");
293
388
  }
294
389
  };
390
+ function hasBrandedSDKErrorShape(error) {
391
+ if (error === null || typeof error !== "object") return false;
392
+ const candidate = error;
393
+ return candidate[SDK_ERROR_BRAND] === true && typeof candidate.name === "string" && typeof candidate.code === "string" && typeof candidate.message === "string" && (candidate.status === void 0 || typeof candidate.status === "number") && (candidate.userMessage === void 0 || typeof candidate.userMessage === "string") && (candidate.suggestion === void 0 || typeof candidate.suggestion === "string") && (candidate.requestId === void 0 || typeof candidate.requestId === "string") && (candidate.kind === void 0 || candidate.kind === "commerce") && (candidate.reason === void 0 || typeof candidate.reason === "string") && (candidate.rawReason === void 0 || typeof candidate.rawReason === "string") && (candidate.apiReason === void 0 || typeof candidate.apiReason === "string") && (candidate.retryable === void 0 || typeof candidate.retryable === "boolean") && (candidate.retryAfter === void 0 || typeof candidate.retryAfter === "number") && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
394
+ }
395
+ function hasSDKErrorType(error, type) {
396
+ return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
397
+ }
398
+ function isSDKError(error) {
399
+ return error instanceof SDKError || hasBrandedSDKErrorShape(error);
400
+ }
401
+ function isNetworkError(error) {
402
+ return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
403
+ }
404
+ function isValidationError(error) {
405
+ if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
406
+ return true;
407
+ }
408
+ if (error == null || typeof error !== "object") return false;
409
+ const candidate = error;
410
+ return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
411
+ }
412
+ function isApiError(error) {
413
+ return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
414
+ }
415
+ function isConfigError(error) {
416
+ return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
417
+ }
418
+ function isTimeoutError(error) {
419
+ return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
420
+ }
421
+ function isGoneError(error) {
422
+ return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
423
+ }
424
+ function isServiceUnavailableError(error) {
425
+ return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
426
+ }
427
+ function isUsageLimitError(error) {
428
+ return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
429
+ }
430
+ function isAuthError(error) {
431
+ return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
432
+ }
433
+ function isPermissionError(error) {
434
+ return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
435
+ }
436
+ function isNotFoundError(error) {
437
+ return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
438
+ }
439
+ function isConflictError(error) {
440
+ return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
441
+ }
442
+ function isRateLimitError(error) {
443
+ return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
444
+ }
295
445
  var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
296
446
  var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
297
447
  var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
@@ -501,7 +651,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
501
651
  if (retryAfter !== void 0) {
502
652
  Object.assign(withRequestId, { retryAfter });
503
653
  }
504
- return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
654
+ return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
505
655
  };
506
656
  if (status === 400 || status === 422) {
507
657
  return finalize(
@@ -688,7 +838,7 @@ async function httpFetch(url, options) {
688
838
  ),
689
839
  requestId
690
840
  );
691
- throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
841
+ throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
692
842
  }
693
843
  if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
694
844
  hasRetried401 = true;
@@ -1378,7 +1528,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1378
1528
  return parsed;
1379
1529
  }
1380
1530
  const data = parsed;
1381
- if (data.error) {
1531
+ const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
1532
+ (key) => Object.prototype.hasOwnProperty.call(data, key)
1533
+ );
1534
+ if (data.error || hasCommerceEnvelopeSignal) {
1382
1535
  const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
1383
1536
  const reason = typeof data.reason === "string" ? data.reason : void 0;
1384
1537
  const requestId = response.headers.get("x-request-id") ?? void 0;
@@ -1407,19 +1560,21 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1407
1560
  }
1408
1561
  const withRequestId = attachRequestId(error, requestId);
1409
1562
  if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
1410
- throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
1563
+ throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
1411
1564
  }
1412
1565
  return data;
1413
1566
  }
1414
1567
 
1415
1568
  // ../../internal/http-contracts/src/index.ts
1416
1569
  var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
1417
- var operation = (collection, method, path) => Object.freeze({
1570
+ var operation = (collection, method, path, errorFamily) => Object.freeze({
1418
1571
  [operationBrand]: true,
1419
1572
  collection,
1420
1573
  method,
1421
- path
1574
+ path,
1575
+ ...errorFamily && { errorFamily }
1422
1576
  });
1577
+ var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
1423
1578
  var COMMERCE_ENDPOINT_OPERATIONS = {
1424
1579
  products: {
1425
1580
  detail: operation("products", "get", "/detail"),
@@ -1452,13 +1607,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1452
1607
  byPayment: operation("orders", "get", "/by-payment"),
1453
1608
  cancel: operation("orders", "post", "/cancel"),
1454
1609
  resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
1455
- checkout: operation("orders", "post", "/checkout"),
1610
+ checkout: strictCommerceOperation("orders", "post", "/checkout"),
1456
1611
  createFulfillment: operation("orders", "post", "/create-fulfillment"),
1457
1612
  updateFulfillment: operation("orders", "post", "/update-fulfillment")
1458
1613
  },
1459
1614
  checkouts: {
1460
- detail: operation("checkouts", "post", "/detail"),
1461
- query: operation("checkouts", "post", "/query")
1615
+ detail: strictCommerceOperation("checkouts", "post", "/detail"),
1616
+ query: strictCommerceOperation("checkouts", "post", "/query")
1462
1617
  },
1463
1618
  transactions: {
1464
1619
  update: operation("transactions", "post", "/update")
@@ -1479,29 +1634,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1479
1634
  bulkImport: operation("fulfillments", "post", "/bulk-import")
1480
1635
  },
1481
1636
  carts: {
1482
- create: operation("carts", "post", "/create"),
1483
- retrieve: operation("carts", "post", "/retrieve"),
1484
- mine: operation("carts", "post", "/mine"),
1485
- merge: operation("carts", "post", "/merge"),
1486
- addItem: operation("carts", "post", "/add-item"),
1487
- updateItem: operation("carts", "post", "/update-item"),
1488
- removeItem: operation("carts", "post", "/remove-item"),
1489
- updateDiscountCodes: operation("carts", "post", "/update-discount-codes"),
1490
- updateAttributes: operation("carts", "post", "/update-attributes"),
1491
- clear: operation("carts", "post", "/clear")
1637
+ create: strictCommerceOperation("carts", "post", "/create"),
1638
+ retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
1639
+ mine: strictCommerceOperation("carts", "post", "/mine"),
1640
+ merge: strictCommerceOperation("carts", "post", "/merge"),
1641
+ addItem: strictCommerceOperation("carts", "post", "/add-item"),
1642
+ updateItem: strictCommerceOperation("carts", "post", "/update-item"),
1643
+ removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
1644
+ updateDiscountCodes: strictCommerceOperation(
1645
+ "carts",
1646
+ "post",
1647
+ "/update-discount-codes"
1648
+ ),
1649
+ updateAttributes: strictCommerceOperation(
1650
+ "carts",
1651
+ "post",
1652
+ "/update-attributes"
1653
+ ),
1654
+ clear: strictCommerceOperation("carts", "post", "/clear")
1492
1655
  },
1493
1656
  paymentSessions: {
1494
- create: operation("payment-sessions", "post", "/create"),
1495
- retrieve: operation("payment-sessions", "post", "/retrieve"),
1496
- cancel: operation("payment-sessions", "post", "/cancel"),
1657
+ create: strictCommerceOperation("payment-sessions", "post", "/create"),
1658
+ retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
1659
+ cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
1497
1660
  server: {
1498
- create: operation("payment-sessions", "post", "/server/create"),
1499
- retrieve: operation("payment-sessions", "post", "/server/retrieve"),
1500
- cancel: operation("payment-sessions", "post", "/server/cancel"),
1501
- confirm: operation("payment-sessions", "post", "/server/confirm")
1661
+ create: strictCommerceOperation(
1662
+ "payment-sessions",
1663
+ "post",
1664
+ "/server/create"
1665
+ ),
1666
+ retrieve: strictCommerceOperation(
1667
+ "payment-sessions",
1668
+ "post",
1669
+ "/server/retrieve"
1670
+ ),
1671
+ cancel: strictCommerceOperation(
1672
+ "payment-sessions",
1673
+ "post",
1674
+ "/server/cancel"
1675
+ ),
1676
+ confirm: strictCommerceOperation(
1677
+ "payment-sessions",
1678
+ "post",
1679
+ "/server/confirm"
1680
+ )
1502
1681
  },
1503
1682
  custom: {
1504
1683
  create: operation("orders", "post", "/custom-payment-sessions"),
1684
+ retrieve: operation(
1685
+ "orders",
1686
+ "post",
1687
+ "/custom-payment-sessions/retrieve"
1688
+ ),
1505
1689
  confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
1506
1690
  }
1507
1691
  },
@@ -1527,6 +1711,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
1527
1711
  )
1528
1712
  }
1529
1713
  };
1714
+ var COMMUNITY_ENDPOINT_OPERATIONS = {
1715
+ posts: {
1716
+ detail: operation("posts", "get", "/detail")
1717
+ }
1718
+ };
1530
1719
  function resolveOperationTemplate(descriptor) {
1531
1720
  return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
1532
1721
  }
@@ -1558,6 +1747,9 @@ var sharedEndpoint = (descriptor) => descriptor;
1558
1747
  function resolveOperationMethod2(descriptor) {
1559
1748
  return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
1560
1749
  }
1750
+ function resolveOperationErrorFamily(descriptor) {
1751
+ return "collection" in descriptor ? descriptor.errorFamily : void 0;
1752
+ }
1561
1753
  function resolveOperationPath2(descriptor, options) {
1562
1754
  if ("collection" in descriptor) {
1563
1755
  return resolveOperationPath(descriptor, options);
@@ -1592,12 +1784,12 @@ var COMMERCE_ENDPOINTS = {
1592
1784
  updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
1593
1785
  },
1594
1786
  checkouts: {
1595
- create: endpoint("POST", "/api/orders/checkout"),
1596
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1787
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1788
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1597
1789
  server: {
1598
- create: endpoint("POST", "/api/orders/checkout"),
1599
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1600
- query: endpoint("POST", "/api/checkouts/query")
1790
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1791
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1792
+ query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
1601
1793
  }
1602
1794
  },
1603
1795
  returns: {
@@ -1615,10 +1807,10 @@ var COMMERCE_ENDPOINTS = {
1615
1807
  bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
1616
1808
  },
1617
1809
  carts: {
1618
- create: endpoint("POST", "/api/carts/create"),
1810
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
1619
1811
  retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
1620
- mine: endpoint("POST", "/api/carts/mine"),
1621
- merge: endpoint("POST", "/api/carts/merge"),
1812
+ mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
1813
+ merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
1622
1814
  server: {
1623
1815
  // Server credentials are an authorization lane, not a second Cart
1624
1816
  // transport. These must stay bound to the registered shared operations.
@@ -1638,29 +1830,46 @@ var COMMERCE_ENDPOINTS = {
1638
1830
  clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1639
1831
  },
1640
1832
  addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
1641
- updateItem: endpoint("POST", "/api/carts/update-item"),
1642
- removeItem: endpoint("POST", "/api/carts/remove-item"),
1643
- updateDiscountCodes: endpoint("POST", "/api/carts/update-discount-codes"),
1644
- updateAttributes: endpoint("POST", "/api/carts/update-attributes"),
1645
- clear: endpoint("POST", "/api/carts/clear")
1833
+ updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
1834
+ removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
1835
+ updateDiscountCodes: sharedEndpoint(
1836
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
1837
+ ),
1838
+ updateAttributes: sharedEndpoint(
1839
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
1840
+ ),
1841
+ clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1646
1842
  },
1647
1843
  paymentSessions: {
1648
- create: endpoint("POST", "/api/payment-sessions/create"),
1649
- retrieve: endpoint("POST", "/api/payment-sessions/retrieve"),
1650
- cancel: endpoint("POST", "/api/payment-sessions/cancel"),
1844
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
1845
+ retrieve: sharedEndpoint(
1846
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
1847
+ ),
1848
+ cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
1651
1849
  custom: {
1652
1850
  create: sharedEndpoint(
1653
1851
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
1654
1852
  ),
1853
+ retrieve: sharedEndpoint(
1854
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
1855
+ ),
1655
1856
  confirm: sharedEndpoint(
1656
1857
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
1657
1858
  )
1658
1859
  },
1659
1860
  server: {
1660
- create: endpoint("POST", "/api/payment-sessions/server/create"),
1661
- retrieve: endpoint("POST", "/api/payment-sessions/server/retrieve"),
1662
- cancel: endpoint("POST", "/api/payment-sessions/server/cancel"),
1663
- confirm: endpoint("POST", "/api/payment-sessions/server/confirm")
1861
+ create: sharedEndpoint(
1862
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
1863
+ ),
1864
+ retrieve: sharedEndpoint(
1865
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
1866
+ ),
1867
+ cancel: sharedEndpoint(
1868
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
1869
+ ),
1870
+ confirm: sharedEndpoint(
1871
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
1872
+ )
1664
1873
  }
1665
1874
  },
1666
1875
  shippingPolicies: {
@@ -1751,7 +1960,8 @@ var CustomerScopedApi = class {
1751
1960
  return this.transport.request(resolveOperationPath2(endpoint2, options), {
1752
1961
  method: resolveOperationMethod2(endpoint2),
1753
1962
  body,
1754
- headers: options?.headers
1963
+ headers: options?.headers,
1964
+ errorFamily: resolveOperationErrorFamily(endpoint2)
1755
1965
  });
1756
1966
  }
1757
1967
  };
@@ -1773,15 +1983,33 @@ function unwrapPayloadDoc(value) {
1773
1983
  }
1774
1984
  return value;
1775
1985
  }
1986
+ function hasCanonicalNotFoundReason(error) {
1987
+ return getSDKErrorReason(error) === "not_found";
1988
+ }
1776
1989
  var CommunityClient = class extends RawCustomerScopedApi {
1777
1990
  constructor(options) {
1778
1991
  super("CommunityClient", { ...options, requiresCredential: false });
1992
+ this.requiresSafePublicRawReads = !options.secretKey;
1779
1993
  }
1780
1994
  buildQuery(params) {
1781
1995
  if (!params) return "";
1782
1996
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
1783
1997
  return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
1784
1998
  }
1999
+ withSafePublicRawReadQuery(query) {
2000
+ if (!this.requiresSafePublicRawReads) return query;
2001
+ if (!query) return "?depth=0&joins=false";
2002
+ return `?depth=0&joins=false&${query.slice(1)}`;
2003
+ }
2004
+ buildSafePublicRawListQuery(params) {
2005
+ if (!this.requiresSafePublicRawReads) {
2006
+ return this.buildQuery(params);
2007
+ }
2008
+ const queryParams = {};
2009
+ if (params?.page !== void 0) queryParams.page = params.page;
2010
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
2011
+ return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
2012
+ }
1785
2013
  buildPostsListQuery(params) {
1786
2014
  const urlParams = new URLSearchParams();
1787
2015
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
@@ -1841,15 +2069,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
1841
2069
  "GET"
1842
2070
  );
1843
2071
  }
2072
+ /**
2073
+ * Public post detail projected by the same allowlist as the public feed.
2074
+ * Missing, hidden, and cross-tenant posts all resolve to `null`.
2075
+ */
2076
+ async getPost(params) {
2077
+ const query = new URLSearchParams({ postId: params.postId });
2078
+ try {
2079
+ return await this.execute(
2080
+ resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
2081
+ query
2082
+ }),
2083
+ resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
2084
+ );
2085
+ } catch (error) {
2086
+ if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
2087
+ return null;
2088
+ }
2089
+ throw error;
2090
+ }
2091
+ }
1844
2092
  listPostCategories(params) {
1845
2093
  return this.execute(
1846
- `/api/post-categories${this.buildQuery(params)}`,
2094
+ `/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
1847
2095
  "GET"
1848
2096
  );
1849
2097
  }
1850
2098
  listPostTags(params) {
1851
2099
  return this.execute(
1852
- `/api/post-tags${this.buildQuery(params)}`,
2100
+ `/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
1853
2101
  "GET"
1854
2102
  );
1855
2103
  }
@@ -2015,7 +2263,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
2015
2263
  }
2016
2264
  getReactionTypes() {
2017
2265
  return this.execute(
2018
- "/api/reaction-types?limit=100",
2266
+ `/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
2019
2267
  "GET"
2020
2268
  );
2021
2269
  }
@@ -2043,11 +2291,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
2043
2291
  }
2044
2292
  // Profiles
2045
2293
  listProfileLists(params) {
2046
- return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
2294
+ return this.execute(
2295
+ `/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
2296
+ "GET"
2297
+ );
2047
2298
  }
2048
2299
  async getProfileList(params) {
2049
2300
  const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
2050
- const res = await this.execute(`/api/customer-profile-lists${query}`, "GET");
2301
+ const res = await this.execute(
2302
+ `/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
2303
+ "GET"
2304
+ );
2051
2305
  return res.docs[0] ?? null;
2052
2306
  }
2053
2307
  updatePublicProfile(body) {
@@ -2107,7 +2361,8 @@ var BaseApi = class {
2107
2361
  body,
2108
2362
  {
2109
2363
  method: resolveOperationMethod2(endpoint2),
2110
- headers: options?.headers
2364
+ headers: options?.headers,
2365
+ errorFamily: resolveOperationErrorFamily(endpoint2)
2111
2366
  }
2112
2367
  );
2113
2368
  }
@@ -2164,7 +2419,7 @@ var MAX_COMMERCE_CAPABILITY_LENGTH = 512;
2164
2419
  var MAX_CART_DISCOUNT_CODE_LENGTH = 128;
2165
2420
  var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
2166
2421
  var ABANDONED_REASONS = ["expired", "customer", "operator"];
2167
- var PAYMENT_PROVIDERS = ["toss"];
2422
+ var PAYMENT_PROVIDERS = ["toss", "portone"];
2168
2423
  var PAYMENT_PROVIDER_STATUSES = [
2169
2424
  "requires_payment_method",
2170
2425
  "requires_action",
@@ -2247,6 +2502,21 @@ function nullableString(value, resource, path) {
2247
2502
  fail(resource, path, "string or null");
2248
2503
  }
2249
2504
  }
2505
+ function nonBlankString(value, resource, path) {
2506
+ const parsed = string(value, resource, path);
2507
+ if (parsed.trim().length === 0) {
2508
+ fail(resource, path, "non-blank string");
2509
+ }
2510
+ return parsed;
2511
+ }
2512
+ function nullableNonBlankString(value, resource, path) {
2513
+ if (value !== null) nonBlankString(value, resource, path);
2514
+ }
2515
+ function nullableResourceId(value, resource, path) {
2516
+ if (value !== null) {
2517
+ boundedString(value, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, path);
2518
+ }
2519
+ }
2250
2520
  function cartLineQuantity(value, resource, path) {
2251
2521
  const quantity = positiveInteger(value, resource, path);
2252
2522
  if (quantity > MAX_CART_LINE_QUANTITY) {
@@ -3068,6 +3338,59 @@ function validateCustomPaymentSession(value) {
3068
3338
  validateMoney(session.money, resource, "$.money");
3069
3339
  return value;
3070
3340
  }
3341
+ function validateRetrievedCustomPaymentSession(value) {
3342
+ const resource = "retrieved custom PaymentSession";
3343
+ const session = record(value, resource, "$");
3344
+ exact(
3345
+ session,
3346
+ [
3347
+ "id",
3348
+ "provider",
3349
+ "providerSessionId",
3350
+ "providerPaymentId",
3351
+ "status",
3352
+ "providerStatus",
3353
+ "finalizationStatus",
3354
+ "money",
3355
+ "orderId"
3356
+ ],
3357
+ [],
3358
+ resource,
3359
+ "$"
3360
+ );
3361
+ boundedString(session.id, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, "$.id");
3362
+ const provider = string(session.provider, resource, "$.provider");
3363
+ if (!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(provider)) {
3364
+ fail(resource, "$.provider", "provider slug");
3365
+ }
3366
+ nonBlankString(session.providerSessionId, resource, "$.providerSessionId");
3367
+ nullableNonBlankString(
3368
+ session.providerPaymentId,
3369
+ resource,
3370
+ "$.providerPaymentId"
3371
+ );
3372
+ enumValue(
3373
+ session.status,
3374
+ ["pending", "captured", "failed", "canceled"],
3375
+ resource,
3376
+ "$.status"
3377
+ );
3378
+ enumValue(
3379
+ session.providerStatus,
3380
+ PAYMENT_PROVIDER_STATUSES,
3381
+ resource,
3382
+ "$.providerStatus"
3383
+ );
3384
+ enumValue(
3385
+ session.finalizationStatus,
3386
+ ["not_ready", "pending", "committed"],
3387
+ resource,
3388
+ "$.finalizationStatus"
3389
+ );
3390
+ validateMoney(session.money, resource, "$.money");
3391
+ nullableResourceId(session.orderId, resource, "$.orderId");
3392
+ return value;
3393
+ }
3071
3394
  function validateConfirmCustomPaymentSessionResponse(value) {
3072
3395
  const resource = "custom PaymentSession confirmation";
3073
3396
  const result = record(value, resource, "$");
@@ -3118,8 +3441,101 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
3118
3441
  previous = current;
3119
3442
  });
3120
3443
  }
3121
- function validateNextAction(value, resource, path) {
3444
+ function validateNextAction(value, provider, resource, path) {
3122
3445
  const action = record(value, resource, path);
3446
+ if (provider === "portone") {
3447
+ if (action.type === "portone_sdk") {
3448
+ exact(
3449
+ action,
3450
+ [
3451
+ "type",
3452
+ "version",
3453
+ "storeId",
3454
+ "channelKey",
3455
+ "paymentId",
3456
+ "orderName",
3457
+ "totalAmount",
3458
+ "currency",
3459
+ "payMethod",
3460
+ "redirectUrl"
3461
+ ],
3462
+ [],
3463
+ resource,
3464
+ path
3465
+ );
3466
+ if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
3467
+ for (const key of ["storeId", "channelKey"]) {
3468
+ boundedString(action[key], 255, resource, `${path}.${key}`);
3469
+ }
3470
+ const paymentId = boundedString(
3471
+ action.paymentId,
3472
+ 40,
3473
+ resource,
3474
+ `${path}.paymentId`
3475
+ );
3476
+ if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
3477
+ fail(
3478
+ resource,
3479
+ `${path}.paymentId`,
3480
+ "6-40 ASCII alphanumeric characters"
3481
+ );
3482
+ }
3483
+ boundedString(
3484
+ action.orderName,
3485
+ MAX_COMMERCE_SHORT_TEXT_LENGTH,
3486
+ resource,
3487
+ `${path}.orderName`
3488
+ );
3489
+ positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
3490
+ if (action.currency !== "CURRENCY_KRW") {
3491
+ fail(resource, `${path}.currency`, "CURRENCY_KRW");
3492
+ }
3493
+ if (action.payMethod !== "CARD")
3494
+ fail(resource, `${path}.payMethod`, "CARD");
3495
+ const redirectUrl = boundedString(
3496
+ action.redirectUrl,
3497
+ 2048,
3498
+ resource,
3499
+ `${path}.redirectUrl`
3500
+ );
3501
+ try {
3502
+ const parsed = new URL(redirectUrl);
3503
+ const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
3504
+ if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
3505
+ throw new Error("unsafe redirect URL");
3506
+ } catch {
3507
+ fail(
3508
+ resource,
3509
+ `${path}.redirectUrl`,
3510
+ "HTTPS or loopback URL without embedded credentials"
3511
+ );
3512
+ }
3513
+ return;
3514
+ }
3515
+ exact(action, ["type", "checkoutUrl"], [], resource, path);
3516
+ if (action.type !== "portone_checkout") {
3517
+ fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
3518
+ }
3519
+ const checkoutUrl = boundedString(
3520
+ action.checkoutUrl,
3521
+ 2048,
3522
+ resource,
3523
+ `${path}.checkoutUrl`
3524
+ );
3525
+ try {
3526
+ const parsed = new URL(checkoutUrl);
3527
+ if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
3528
+ throw new Error("unsafe checkout URL");
3529
+ }
3530
+ } catch {
3531
+ fail(
3532
+ resource,
3533
+ `${path}.checkoutUrl`,
3534
+ "absolute HTTPS URL without embedded credentials"
3535
+ );
3536
+ }
3537
+ return;
3538
+ }
3123
3539
  exact(
3124
3540
  action,
3125
3541
  [
@@ -3170,10 +3586,18 @@ function validateNextAction(value, resource, path) {
3170
3586
  if (action.customerEmail !== void 0)
3171
3587
  validateCustomer({ email: action.customerEmail }, resource, path);
3172
3588
  }
3173
- function validatePublicPaymentSession(value) {
3589
+ function validatePublicPaymentSession(value, expectedProvider) {
3174
3590
  const resource = "PaymentSession";
3175
3591
  const session = record(value, resource, "$");
3176
- enumValue(session.provider, PAYMENT_PROVIDERS, resource, "$.provider");
3592
+ const provider = enumValue(
3593
+ session.provider,
3594
+ PAYMENT_PROVIDERS,
3595
+ resource,
3596
+ "$.provider"
3597
+ );
3598
+ if (expectedProvider !== void 0 && provider !== expectedProvider) {
3599
+ fail(resource, "$.provider", expectedProvider);
3600
+ }
3177
3601
  const status = enumValue(
3178
3602
  session.providerStatus,
3179
3603
  PAYMENT_PROVIDER_STATUSES,
@@ -3210,7 +3634,12 @@ function validatePublicPaymentSession(value) {
3210
3634
  }
3211
3635
  if (!("nextAction" in session))
3212
3636
  fail(resource, "$.nextAction", "required field");
3213
- validateNextAction(session.nextAction, resource, "$.nextAction");
3637
+ validateNextAction(
3638
+ session.nextAction,
3639
+ provider,
3640
+ resource,
3641
+ "$.nextAction"
3642
+ );
3214
3643
  } else if (session.sessionRole === "residual") {
3215
3644
  if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
3216
3645
  fail(resource, "$", "suppressed residual not-ready state");
@@ -4482,21 +4911,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
4482
4911
  "not_published",
4483
4912
  "feature_disabled"
4484
4913
  ]);
4485
- function isRecord(value) {
4486
- return typeof value === "object" && value !== null;
4487
- }
4488
- function readProductDetailUnavailableReason(value) {
4489
- if (!isRecord(value)) return void 0;
4490
- const directReason = value.reason ?? value.code;
4491
- if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
4492
- return directReason;
4493
- }
4494
- return readProductDetailUnavailableReason(value.body);
4495
- }
4496
4914
  function productDetailResultFromError(error) {
4497
4915
  if (!(error instanceof SDKError) || error.status !== 404) return void 0;
4498
- const reason = readProductDetailUnavailableReason(error.details);
4499
- if (!reason) return void 0;
4916
+ const reason = getSDKErrorReason(error);
4917
+ if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
4918
+ return void 0;
4500
4919
  return { found: false, reason };
4501
4920
  }
4502
4921
  var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
@@ -4929,8 +5348,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4929
5348
  }
4930
5349
  });
4931
5350
  }
4932
- async paymentSession(result) {
4933
- return validatePublicPaymentSession(await result);
5351
+ async paymentSession(result, expectedProvider) {
5352
+ return validatePublicPaymentSession(await result, expectedProvider);
4934
5353
  }
4935
5354
  create(params) {
4936
5355
  const { idempotencyKey, ...body } = params;
@@ -4940,18 +5359,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4940
5359
  this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
4941
5360
  body,
4942
5361
  idempotencyKey
4943
- )
5362
+ ),
5363
+ "toss"
5364
+ );
5365
+ }
5366
+ createPortOne(params) {
5367
+ const { idempotencyKey, ...body } = params;
5368
+ assertCommerceIdempotencyKey(idempotencyKey);
5369
+ return this.paymentSession(
5370
+ this.post(
5371
+ this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
5372
+ body,
5373
+ idempotencyKey
5374
+ ),
5375
+ "portone"
4944
5376
  );
4945
5377
  }
4946
5378
  retrieve(params) {
4947
5379
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4948
- return this.paymentSession(this.post(endpoint2, params));
5380
+ return this.paymentSession(
5381
+ this.post(endpoint2, params),
5382
+ "toss"
5383
+ );
5384
+ }
5385
+ retrievePortOne(params) {
5386
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
5387
+ return this.paymentSession(
5388
+ this.post(endpoint2, params),
5389
+ "portone"
5390
+ );
4949
5391
  }
4950
5392
  cancel(params) {
4951
5393
  const { idempotencyKey, ...body } = params;
4952
5394
  assertCommerceIdempotencyKey(idempotencyKey);
4953
5395
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4954
- return this.paymentSession(this.post(endpoint2, body, idempotencyKey));
5396
+ return this.paymentSession(
5397
+ this.post(endpoint2, body, idempotencyKey),
5398
+ "toss"
5399
+ );
5400
+ }
5401
+ cancelPortOne(params) {
5402
+ const { idempotencyKey, ...body } = params;
5403
+ assertCommerceIdempotencyKey(idempotencyKey);
5404
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
5405
+ return this.paymentSession(
5406
+ this.post(endpoint2, body, idempotencyKey),
5407
+ "portone"
5408
+ );
4955
5409
  }
4956
5410
  confirm(params) {
4957
5411
  const { idempotencyKey, ...body } = params;
@@ -4961,7 +5415,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4961
5415
  COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
4962
5416
  body,
4963
5417
  idempotencyKey
4964
- )
5418
+ ),
5419
+ "toss"
4965
5420
  );
4966
5421
  }
4967
5422
  };
@@ -4982,6 +5437,15 @@ var CustomPaymentSessionApi = class extends BaseApi {
4982
5437
  );
4983
5438
  return validateCustomPaymentSession(result);
4984
5439
  }
5440
+ async retrieve(params) {
5441
+ const result = await this.requestEndpoint(
5442
+ COMMERCE_ENDPOINTS.paymentSessions.custom.retrieve,
5443
+ params
5444
+ );
5445
+ return validateRetrievedCustomPaymentSession(
5446
+ result
5447
+ );
5448
+ }
4985
5449
  async confirm(params, options = {}) {
4986
5450
  const body = {
4987
5451
  provider: params.provider,
@@ -5129,11 +5593,17 @@ var ServerCommerceClient = class {
5129
5593
  };
5130
5594
  this.paymentSessions = {
5131
5595
  create: paymentSessionApi.create.bind(paymentSessionApi),
5596
+ createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
5132
5597
  retrieve: (params) => paymentSessionApi.retrieve(params),
5598
+ retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
5133
5599
  cancel: (params) => paymentSessionApi.cancel(params),
5600
+ cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params),
5134
5601
  confirm: paymentSessionApi.confirm.bind(paymentSessionApi),
5135
5602
  custom: {
5136
5603
  create: customPaymentSessionApi.create.bind(customPaymentSessionApi),
5604
+ retrieve: customPaymentSessionApi.retrieve.bind(
5605
+ customPaymentSessionApi
5606
+ ),
5137
5607
  confirm: customPaymentSessionApi.confirm.bind(customPaymentSessionApi)
5138
5608
  }
5139
5609
  };
@@ -5504,6 +5974,21 @@ export {
5504
5974
  ServerCommerceClient,
5505
5975
  ServerPreviewClient,
5506
5976
  TenantIntrospectionApi,
5507
- createServerClient
5977
+ createServerClient,
5978
+ isApiError,
5979
+ isAuthError,
5980
+ isCommerceSDKError,
5981
+ isConfigError,
5982
+ isConflictError,
5983
+ isGoneError,
5984
+ isNetworkError,
5985
+ isNotFoundError,
5986
+ isPermissionError,
5987
+ isRateLimitError,
5988
+ isSDKError,
5989
+ isServiceUnavailableError,
5990
+ isTimeoutError,
5991
+ isUsageLimitError,
5992
+ isValidationError
5508
5993
  };
5509
5994
  //# sourceMappingURL=server.js.map