@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.cjs CHANGED
@@ -29,7 +29,22 @@ __export(server_exports, {
29
29
  ServerCommerceClient: () => ServerCommerceClient,
30
30
  ServerPreviewClient: () => ServerPreviewClient,
31
31
  TenantIntrospectionApi: () => TenantIntrospectionApi,
32
- createServerClient: () => createServerClient
32
+ createServerClient: () => createServerClient,
33
+ isApiError: () => isApiError,
34
+ isAuthError: () => isAuthError,
35
+ isCommerceSDKError: () => isCommerceSDKError,
36
+ isConfigError: () => isConfigError,
37
+ isConflictError: () => isConflictError,
38
+ isGoneError: () => isGoneError,
39
+ isNetworkError: () => isNetworkError,
40
+ isNotFoundError: () => isNotFoundError,
41
+ isPermissionError: () => isPermissionError,
42
+ isRateLimitError: () => isRateLimitError,
43
+ isSDKError: () => isSDKError,
44
+ isServiceUnavailableError: () => isServiceUnavailableError,
45
+ isTimeoutError: () => isTimeoutError,
46
+ isUsageLimitError: () => isUsageLimitError,
47
+ isValidationError: () => isValidationError
33
48
  });
34
49
  module.exports = __toCommonJS(server_exports);
35
50
 
@@ -37,6 +52,24 @@ module.exports = __toCommonJS(server_exports);
37
52
  var import_qs_esm = require("qs-esm");
38
53
 
39
54
  // src/core/errors.ts
55
+ var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
56
+ var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
57
+ function defineSDKErrorBrand(error) {
58
+ Object.defineProperty(error, SDK_ERROR_BRAND, {
59
+ value: true,
60
+ enumerable: false,
61
+ configurable: false,
62
+ writable: false
63
+ });
64
+ }
65
+ function defineSDKErrorType(error, type) {
66
+ Object.defineProperty(error, SDK_ERROR_TYPE_BRAND, {
67
+ value: type,
68
+ enumerable: false,
69
+ configurable: false,
70
+ writable: false
71
+ });
72
+ }
40
73
  var SDKError = class extends Error {
41
74
  constructor(code, message, status, details, userMessage, suggestion, requestId) {
42
75
  super(message);
@@ -47,6 +80,7 @@ var SDKError = class extends Error {
47
80
  this.userMessage = userMessage;
48
81
  this.suggestion = suggestion;
49
82
  this.requestId = requestId;
83
+ defineSDKErrorBrand(this);
50
84
  if (Error.captureStackTrace) {
51
85
  Error.captureStackTrace(this, new.target);
52
86
  }
@@ -67,6 +101,7 @@ var SDKError = class extends Error {
67
101
  ...this.kind !== void 0 && { kind: this.kind },
68
102
  ...this.reason !== void 0 && { reason: this.reason },
69
103
  ...this.rawReason !== void 0 && { rawReason: this.rawReason },
104
+ ...this.apiReason !== void 0 && { apiReason: this.apiReason },
70
105
  ...this.retryable !== void 0 && { retryable: this.retryable },
71
106
  ...this.retryAfter !== void 0 && { retryAfter: this.retryAfter }
72
107
  };
@@ -74,34 +109,78 @@ var SDKError = class extends Error {
74
109
  };
75
110
  var COMMERCE_ERROR_CODES = [
76
111
  "validation_failed",
112
+ "bad_request",
77
113
  "unauthorized",
78
114
  "forbidden",
115
+ "account_suspended",
116
+ "key_invalid",
117
+ "pat_tenant_header_forbidden",
118
+ "tenant_mismatch",
119
+ "test_tenant_expired",
120
+ "token_invalid",
79
121
  "token_expired",
80
122
  "origin_not_allowed",
81
123
  "server_credentials_required",
124
+ "role_denied",
125
+ "scope_denied",
126
+ "feature_disabled",
82
127
  "not_found",
83
128
  "conflict",
129
+ "locked",
84
130
  "cart_revision_conflict",
85
131
  "rate_limit_exceeded",
86
132
  "usage_limit_exceeded",
87
133
  "service_unavailable",
88
134
  "idempotency_conflict",
89
135
  "idempotency_in_progress",
136
+ "idempotency_key_required",
137
+ "invalid_idempotency_key",
90
138
  "cart_not_active",
91
139
  "cart_locked",
92
140
  "cart_empty",
93
141
  "cart_market_unavailable",
94
142
  "cart_market_mismatch",
95
143
  "checkout_not_open",
144
+ "checkout_already_open",
96
145
  "payment_slot_held",
97
146
  "reservation_expired",
98
147
  "payment_session_not_cancelable",
148
+ "payment_session_conflict",
99
149
  "provider_identity_mismatch",
150
+ "payment_method_unavailable",
100
151
  "provider_unavailable",
101
152
  "lock_timeout",
102
153
  "price_changed",
103
154
  "pricing_fact_in_use",
104
155
  "insufficient_stock",
156
+ "reservation_conflict",
157
+ "stock_lock_unavailable",
158
+ "variant_not_found",
159
+ "variant_stock_write_failed",
160
+ "stock_invariant_violation",
161
+ "payment_confirmation_in_flight",
162
+ "checkout_reservation_release_requires_transaction",
163
+ "admission_metadata_invalid",
164
+ "admission_metadata_required",
165
+ "capacity_exceeded",
166
+ "occurrence_lock_unavailable",
167
+ "occurrence_not_open",
168
+ "admission_type_capacity_exceeded",
169
+ "admission_type_occurrence_mismatch",
170
+ "admission_hold_expired",
171
+ "admission_hold_checkout_item_conflict",
172
+ "admission_hold_checkout_conflict",
173
+ "admission_hold_quantity_mismatch",
174
+ "admission_hold_unbound",
175
+ "admission_hold_missing",
176
+ "admission_hold_checkout_item_missing",
177
+ "admission_hold_expiry_failed",
178
+ "admission_hold_expiry_requires_transaction",
179
+ "admission_hold_line_item_mismatch",
180
+ "admission_materialization_failed",
181
+ "variant_inactive",
182
+ "variant_product_mismatch",
183
+ "product_not_public",
105
184
  "market_not_found",
106
185
  "market_shipping_currency_unsupported",
107
186
  "missing_market_rate",
@@ -126,7 +205,11 @@ var COMMERCE_ERROR_CODES = [
126
205
  "discount_min_order_amount",
127
206
  "discount_currency_scope_required",
128
207
  "discount_allocation_method_unsupported",
129
- "currency_mismatch"
208
+ "currency_mismatch",
209
+ "customer_token_required",
210
+ "market_required",
211
+ "server_derived",
212
+ "internal_error"
130
213
  ];
131
214
  var COMMERCE_ERROR_CODE_SET = new Set(
132
215
  COMMERCE_ERROR_CODES
@@ -152,6 +235,12 @@ function commerceProtocolError(issue, trustedRequestId) {
152
235
  );
153
236
  }
154
237
  function parseCommerceErrorEnvelope(body, headerRequestId) {
238
+ if (headerRequestId === void 0) {
239
+ throw commerceProtocolError("missing_request_id_header");
240
+ }
241
+ if (headerRequestId.length === 0) {
242
+ throw commerceProtocolError("empty_request_id_header");
243
+ }
155
244
  if (!isPlainRecord(body)) {
156
245
  throw commerceProtocolError("expected_object", headerRequestId);
157
246
  }
@@ -161,7 +250,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
161
250
  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)) {
162
251
  throw commerceProtocolError("invalid_field", headerRequestId);
163
252
  }
164
- if (headerRequestId && headerRequestId !== body.requestId) {
253
+ if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
165
254
  throw commerceProtocolError("request_id_mismatch", headerRequestId);
166
255
  }
167
256
  return {
@@ -186,8 +275,16 @@ function enhanceCommerceError(error, body, headerRequestId) {
186
275
  });
187
276
  return error;
188
277
  }
278
+ function enhanceNonCommerceError(error, reason) {
279
+ if (typeof reason === "string") Object.assign(error, { apiReason: reason });
280
+ return error;
281
+ }
282
+ function getSDKErrorReason(error) {
283
+ if (error.kind !== "commerce") return error.apiReason;
284
+ return error.reason === "unknown_commerce_error" ? error.rawReason : error.reason;
285
+ }
189
286
  function isCommerceSDKError(error) {
190
- if (!(error instanceof SDKError) || error.kind !== "commerce") return false;
287
+ if (!isSDKError(error) || error.kind !== "commerce") return false;
191
288
  if (typeof error.requestId !== "string" || typeof error.retryable !== "boolean" || error.retryAfter !== void 0 && (!Number.isSafeInteger(error.retryAfter) || error.retryAfter < 0) || typeof error.reason !== "string") {
192
289
  return false;
193
290
  }
@@ -197,12 +294,14 @@ var NetworkError = class extends SDKError {
197
294
  constructor(message, status, details, userMessage, suggestion) {
198
295
  super("NETWORK_ERROR", message, status, details, userMessage, suggestion);
199
296
  this.name = "NetworkError";
297
+ defineSDKErrorType(this, "NetworkError");
200
298
  }
201
299
  };
202
300
  var ValidationError = class extends SDKError {
203
301
  constructor(message, details, userMessage, suggestion, status = 400) {
204
302
  super("VALIDATION_ERROR", message, status, details, userMessage, suggestion);
205
303
  this.name = "ValidationError";
304
+ defineSDKErrorType(this, "ValidationError");
206
305
  }
207
306
  };
208
307
  var ApiError = class extends SDKError {
@@ -217,24 +316,28 @@ var ApiError = class extends SDKError {
217
316
  requestId
218
317
  );
219
318
  this.name = "ApiError";
319
+ defineSDKErrorType(this, "ApiError");
220
320
  }
221
321
  };
222
322
  var ConfigError = class extends SDKError {
223
323
  constructor(message, details, userMessage, suggestion) {
224
324
  super("CONFIG_ERROR", message, void 0, details, userMessage, suggestion);
225
325
  this.name = "ConfigError";
326
+ defineSDKErrorType(this, "ConfigError");
226
327
  }
227
328
  };
228
329
  var TimeoutError = class extends SDKError {
229
330
  constructor(message = "Request timed out.", details, userMessage, suggestion) {
230
331
  super("TIMEOUT_ERROR", message, 408, details, userMessage, suggestion);
231
332
  this.name = "TimeoutError";
333
+ defineSDKErrorType(this, "TimeoutError");
232
334
  }
233
335
  };
234
336
  var GoneError = class extends SDKError {
235
337
  constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
236
338
  super("GONE_ERROR", message, 410, details, userMessage, suggestion);
237
339
  this.name = "GoneError";
340
+ defineSDKErrorType(this, "GoneError");
238
341
  }
239
342
  };
240
343
  var ServiceUnavailableError = class extends SDKError {
@@ -249,6 +352,7 @@ var ServiceUnavailableError = class extends SDKError {
249
352
  );
250
353
  this.name = "ServiceUnavailableError";
251
354
  this.retryAfter = retryAfter;
355
+ defineSDKErrorType(this, "ServiceUnavailableError");
252
356
  }
253
357
  };
254
358
  var UsageLimitError = class extends SDKError {
@@ -256,6 +360,7 @@ var UsageLimitError = class extends SDKError {
256
360
  super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
257
361
  this.name = "UsageLimitError";
258
362
  this.usage = usage;
363
+ defineSDKErrorType(this, "UsageLimitError");
259
364
  }
260
365
  toJSON() {
261
366
  return {
@@ -276,6 +381,7 @@ var AuthError = class extends SDKError {
276
381
  requestId
277
382
  );
278
383
  this.name = "AuthError";
384
+ defineSDKErrorType(this, "AuthError");
279
385
  }
280
386
  };
281
387
  var PermissionError = class extends SDKError {
@@ -290,6 +396,7 @@ var PermissionError = class extends SDKError {
290
396
  requestId
291
397
  );
292
398
  this.name = "PermissionError";
399
+ defineSDKErrorType(this, "PermissionError");
293
400
  }
294
401
  };
295
402
  var NotFoundError = class extends SDKError {
@@ -304,12 +411,14 @@ var NotFoundError = class extends SDKError {
304
411
  requestId
305
412
  );
306
413
  this.name = "NotFoundError";
414
+ defineSDKErrorType(this, "NotFoundError");
307
415
  }
308
416
  };
309
417
  var ConflictError = class extends SDKError {
310
418
  constructor(message, details, userMessage, suggestion, requestId) {
311
419
  super("conflict", message, 409, details, userMessage, suggestion, requestId);
312
420
  this.name = "ConflictError";
421
+ defineSDKErrorType(this, "ConflictError");
313
422
  }
314
423
  };
315
424
  var RateLimitError = class extends SDKError {
@@ -325,8 +434,64 @@ var RateLimitError = class extends SDKError {
325
434
  );
326
435
  this.name = "RateLimitError";
327
436
  this.retryAfter = retryAfter;
437
+ defineSDKErrorType(this, "RateLimitError");
328
438
  }
329
439
  };
440
+ function hasBrandedSDKErrorShape(error) {
441
+ if (error === null || typeof error !== "object") return false;
442
+ const candidate = error;
443
+ 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";
444
+ }
445
+ function hasSDKErrorType(error, type) {
446
+ return hasBrandedSDKErrorShape(error) && error[SDK_ERROR_TYPE_BRAND] === type;
447
+ }
448
+ function isSDKError(error) {
449
+ return error instanceof SDKError || hasBrandedSDKErrorShape(error);
450
+ }
451
+ function isNetworkError(error) {
452
+ return error instanceof NetworkError || hasSDKErrorType(error, "NetworkError");
453
+ }
454
+ function isValidationError(error) {
455
+ if (error instanceof ValidationError || hasSDKErrorType(error, "ValidationError")) {
456
+ return true;
457
+ }
458
+ if (error == null || typeof error !== "object") return false;
459
+ const candidate = error;
460
+ return candidate.name === "ValidationError" && candidate.code === "VALIDATION_ERROR" && typeof candidate.message === "string" && typeof candidate.getUserMessage === "function" && typeof candidate.toJSON === "function";
461
+ }
462
+ function isApiError(error) {
463
+ return error instanceof ApiError || hasSDKErrorType(error, "ApiError");
464
+ }
465
+ function isConfigError(error) {
466
+ return error instanceof ConfigError || hasSDKErrorType(error, "ConfigError");
467
+ }
468
+ function isTimeoutError(error) {
469
+ return error instanceof TimeoutError || hasSDKErrorType(error, "TimeoutError");
470
+ }
471
+ function isGoneError(error) {
472
+ return error instanceof GoneError || hasSDKErrorType(error, "GoneError");
473
+ }
474
+ function isServiceUnavailableError(error) {
475
+ return error instanceof ServiceUnavailableError || hasSDKErrorType(error, "ServiceUnavailableError");
476
+ }
477
+ function isUsageLimitError(error) {
478
+ return error instanceof UsageLimitError || hasSDKErrorType(error, "UsageLimitError");
479
+ }
480
+ function isAuthError(error) {
481
+ return error instanceof AuthError || hasSDKErrorType(error, "AuthError");
482
+ }
483
+ function isPermissionError(error) {
484
+ return error instanceof PermissionError || hasSDKErrorType(error, "PermissionError");
485
+ }
486
+ function isNotFoundError(error) {
487
+ return error instanceof NotFoundError || hasSDKErrorType(error, "NotFoundError");
488
+ }
489
+ function isConflictError(error) {
490
+ return error instanceof ConflictError || hasSDKErrorType(error, "ConflictError");
491
+ }
492
+ function isRateLimitError(error) {
493
+ return error instanceof RateLimitError || hasSDKErrorType(error, "RateLimitError");
494
+ }
330
495
  var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
331
496
  var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
332
497
  var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
@@ -536,7 +701,7 @@ function mapResponseToError(status, parsed, details, requestId, retryAfter, erro
536
701
  if (retryAfter !== void 0) {
537
702
  Object.assign(withRequestId, { retryAfter });
538
703
  }
539
- return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : withRequestId;
704
+ return errorFamily === "commerce" ? enhanceCommerceError(withRequestId, parsed.body, requestId) : enhanceNonCommerceError(withRequestId, parsed.reason);
540
705
  };
541
706
  if (status === 400 || status === 422) {
542
707
  return finalize(
@@ -723,7 +888,7 @@ async function httpFetch(url, options) {
723
888
  ),
724
889
  requestId
725
890
  );
726
- throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : usageError;
891
+ throw errorFamily === "commerce" ? enhanceCommerceError(usageError, parsed.body, requestId) : enhanceNonCommerceError(usageError, parsed.reason);
727
892
  }
728
893
  if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401 && (commerceEnvelope?.reason ?? parsed.reason) === "token_expired") {
729
894
  hasRetried401 = true;
@@ -1413,7 +1578,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1413
1578
  return parsed;
1414
1579
  }
1415
1580
  const data = parsed;
1416
- if (data.error) {
1581
+ const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
1582
+ (key) => Object.prototype.hasOwnProperty.call(data, key)
1583
+ );
1584
+ if (data.error || hasCommerceEnvelopeSignal) {
1417
1585
  const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
1418
1586
  const reason = typeof data.reason === "string" ? data.reason : void 0;
1419
1587
  const requestId = response.headers.get("x-request-id") ?? void 0;
@@ -1442,19 +1610,21 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1442
1610
  }
1443
1611
  const withRequestId = attachRequestId(error, requestId);
1444
1612
  if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
1445
- throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : withRequestId;
1613
+ throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
1446
1614
  }
1447
1615
  return data;
1448
1616
  }
1449
1617
 
1450
1618
  // ../../internal/http-contracts/src/index.ts
1451
1619
  var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
1452
- var operation = (collection, method, path) => Object.freeze({
1620
+ var operation = (collection, method, path, errorFamily) => Object.freeze({
1453
1621
  [operationBrand]: true,
1454
1622
  collection,
1455
1623
  method,
1456
- path
1624
+ path,
1625
+ ...errorFamily && { errorFamily }
1457
1626
  });
1627
+ var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
1458
1628
  var COMMERCE_ENDPOINT_OPERATIONS = {
1459
1629
  products: {
1460
1630
  detail: operation("products", "get", "/detail"),
@@ -1487,13 +1657,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1487
1657
  byPayment: operation("orders", "get", "/by-payment"),
1488
1658
  cancel: operation("orders", "post", "/cancel"),
1489
1659
  resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
1490
- checkout: operation("orders", "post", "/checkout"),
1660
+ checkout: strictCommerceOperation("orders", "post", "/checkout"),
1491
1661
  createFulfillment: operation("orders", "post", "/create-fulfillment"),
1492
1662
  updateFulfillment: operation("orders", "post", "/update-fulfillment")
1493
1663
  },
1494
1664
  checkouts: {
1495
- detail: operation("checkouts", "post", "/detail"),
1496
- query: operation("checkouts", "post", "/query")
1665
+ detail: strictCommerceOperation("checkouts", "post", "/detail"),
1666
+ query: strictCommerceOperation("checkouts", "post", "/query")
1497
1667
  },
1498
1668
  transactions: {
1499
1669
  update: operation("transactions", "post", "/update")
@@ -1514,29 +1684,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1514
1684
  bulkImport: operation("fulfillments", "post", "/bulk-import")
1515
1685
  },
1516
1686
  carts: {
1517
- create: operation("carts", "post", "/create"),
1518
- retrieve: operation("carts", "post", "/retrieve"),
1519
- mine: operation("carts", "post", "/mine"),
1520
- merge: operation("carts", "post", "/merge"),
1521
- addItem: operation("carts", "post", "/add-item"),
1522
- updateItem: operation("carts", "post", "/update-item"),
1523
- removeItem: operation("carts", "post", "/remove-item"),
1524
- updateDiscountCodes: operation("carts", "post", "/update-discount-codes"),
1525
- updateAttributes: operation("carts", "post", "/update-attributes"),
1526
- clear: operation("carts", "post", "/clear")
1687
+ create: strictCommerceOperation("carts", "post", "/create"),
1688
+ retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
1689
+ mine: strictCommerceOperation("carts", "post", "/mine"),
1690
+ merge: strictCommerceOperation("carts", "post", "/merge"),
1691
+ addItem: strictCommerceOperation("carts", "post", "/add-item"),
1692
+ updateItem: strictCommerceOperation("carts", "post", "/update-item"),
1693
+ removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
1694
+ updateDiscountCodes: strictCommerceOperation(
1695
+ "carts",
1696
+ "post",
1697
+ "/update-discount-codes"
1698
+ ),
1699
+ updateAttributes: strictCommerceOperation(
1700
+ "carts",
1701
+ "post",
1702
+ "/update-attributes"
1703
+ ),
1704
+ clear: strictCommerceOperation("carts", "post", "/clear")
1527
1705
  },
1528
1706
  paymentSessions: {
1529
- create: operation("payment-sessions", "post", "/create"),
1530
- retrieve: operation("payment-sessions", "post", "/retrieve"),
1531
- cancel: operation("payment-sessions", "post", "/cancel"),
1707
+ create: strictCommerceOperation("payment-sessions", "post", "/create"),
1708
+ retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
1709
+ cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
1532
1710
  server: {
1533
- create: operation("payment-sessions", "post", "/server/create"),
1534
- retrieve: operation("payment-sessions", "post", "/server/retrieve"),
1535
- cancel: operation("payment-sessions", "post", "/server/cancel"),
1536
- confirm: operation("payment-sessions", "post", "/server/confirm")
1711
+ create: strictCommerceOperation(
1712
+ "payment-sessions",
1713
+ "post",
1714
+ "/server/create"
1715
+ ),
1716
+ retrieve: strictCommerceOperation(
1717
+ "payment-sessions",
1718
+ "post",
1719
+ "/server/retrieve"
1720
+ ),
1721
+ cancel: strictCommerceOperation(
1722
+ "payment-sessions",
1723
+ "post",
1724
+ "/server/cancel"
1725
+ ),
1726
+ confirm: strictCommerceOperation(
1727
+ "payment-sessions",
1728
+ "post",
1729
+ "/server/confirm"
1730
+ )
1537
1731
  },
1538
1732
  custom: {
1539
1733
  create: operation("orders", "post", "/custom-payment-sessions"),
1734
+ retrieve: operation(
1735
+ "orders",
1736
+ "post",
1737
+ "/custom-payment-sessions/retrieve"
1738
+ ),
1540
1739
  confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
1541
1740
  }
1542
1741
  },
@@ -1562,6 +1761,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
1562
1761
  )
1563
1762
  }
1564
1763
  };
1764
+ var COMMUNITY_ENDPOINT_OPERATIONS = {
1765
+ posts: {
1766
+ detail: operation("posts", "get", "/detail")
1767
+ }
1768
+ };
1565
1769
  function resolveOperationTemplate(descriptor) {
1566
1770
  return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
1567
1771
  }
@@ -1593,6 +1797,9 @@ var sharedEndpoint = (descriptor) => descriptor;
1593
1797
  function resolveOperationMethod2(descriptor) {
1594
1798
  return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
1595
1799
  }
1800
+ function resolveOperationErrorFamily(descriptor) {
1801
+ return "collection" in descriptor ? descriptor.errorFamily : void 0;
1802
+ }
1596
1803
  function resolveOperationPath2(descriptor, options) {
1597
1804
  if ("collection" in descriptor) {
1598
1805
  return resolveOperationPath(descriptor, options);
@@ -1627,12 +1834,12 @@ var COMMERCE_ENDPOINTS = {
1627
1834
  updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
1628
1835
  },
1629
1836
  checkouts: {
1630
- create: endpoint("POST", "/api/orders/checkout"),
1631
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1837
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1838
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1632
1839
  server: {
1633
- create: endpoint("POST", "/api/orders/checkout"),
1634
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1635
- query: endpoint("POST", "/api/checkouts/query")
1840
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1841
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1842
+ query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
1636
1843
  }
1637
1844
  },
1638
1845
  returns: {
@@ -1650,10 +1857,10 @@ var COMMERCE_ENDPOINTS = {
1650
1857
  bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
1651
1858
  },
1652
1859
  carts: {
1653
- create: endpoint("POST", "/api/carts/create"),
1860
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
1654
1861
  retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
1655
- mine: endpoint("POST", "/api/carts/mine"),
1656
- merge: endpoint("POST", "/api/carts/merge"),
1862
+ mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
1863
+ merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
1657
1864
  server: {
1658
1865
  // Server credentials are an authorization lane, not a second Cart
1659
1866
  // transport. These must stay bound to the registered shared operations.
@@ -1673,29 +1880,46 @@ var COMMERCE_ENDPOINTS = {
1673
1880
  clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1674
1881
  },
1675
1882
  addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
1676
- updateItem: endpoint("POST", "/api/carts/update-item"),
1677
- removeItem: endpoint("POST", "/api/carts/remove-item"),
1678
- updateDiscountCodes: endpoint("POST", "/api/carts/update-discount-codes"),
1679
- updateAttributes: endpoint("POST", "/api/carts/update-attributes"),
1680
- clear: endpoint("POST", "/api/carts/clear")
1883
+ updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
1884
+ removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
1885
+ updateDiscountCodes: sharedEndpoint(
1886
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
1887
+ ),
1888
+ updateAttributes: sharedEndpoint(
1889
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
1890
+ ),
1891
+ clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1681
1892
  },
1682
1893
  paymentSessions: {
1683
- create: endpoint("POST", "/api/payment-sessions/create"),
1684
- retrieve: endpoint("POST", "/api/payment-sessions/retrieve"),
1685
- cancel: endpoint("POST", "/api/payment-sessions/cancel"),
1894
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
1895
+ retrieve: sharedEndpoint(
1896
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
1897
+ ),
1898
+ cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
1686
1899
  custom: {
1687
1900
  create: sharedEndpoint(
1688
1901
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
1689
1902
  ),
1903
+ retrieve: sharedEndpoint(
1904
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
1905
+ ),
1690
1906
  confirm: sharedEndpoint(
1691
1907
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
1692
1908
  )
1693
1909
  },
1694
1910
  server: {
1695
- create: endpoint("POST", "/api/payment-sessions/server/create"),
1696
- retrieve: endpoint("POST", "/api/payment-sessions/server/retrieve"),
1697
- cancel: endpoint("POST", "/api/payment-sessions/server/cancel"),
1698
- confirm: endpoint("POST", "/api/payment-sessions/server/confirm")
1911
+ create: sharedEndpoint(
1912
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
1913
+ ),
1914
+ retrieve: sharedEndpoint(
1915
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
1916
+ ),
1917
+ cancel: sharedEndpoint(
1918
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
1919
+ ),
1920
+ confirm: sharedEndpoint(
1921
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
1922
+ )
1699
1923
  }
1700
1924
  },
1701
1925
  shippingPolicies: {
@@ -1786,7 +2010,8 @@ var CustomerScopedApi = class {
1786
2010
  return this.transport.request(resolveOperationPath2(endpoint2, options), {
1787
2011
  method: resolveOperationMethod2(endpoint2),
1788
2012
  body,
1789
- headers: options?.headers
2013
+ headers: options?.headers,
2014
+ errorFamily: resolveOperationErrorFamily(endpoint2)
1790
2015
  });
1791
2016
  }
1792
2017
  };
@@ -1808,15 +2033,33 @@ function unwrapPayloadDoc(value) {
1808
2033
  }
1809
2034
  return value;
1810
2035
  }
2036
+ function hasCanonicalNotFoundReason(error) {
2037
+ return getSDKErrorReason(error) === "not_found";
2038
+ }
1811
2039
  var CommunityClient = class extends RawCustomerScopedApi {
1812
2040
  constructor(options) {
1813
2041
  super("CommunityClient", { ...options, requiresCredential: false });
2042
+ this.requiresSafePublicRawReads = !options.secretKey;
1814
2043
  }
1815
2044
  buildQuery(params) {
1816
2045
  if (!params) return "";
1817
2046
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
1818
2047
  return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
1819
2048
  }
2049
+ withSafePublicRawReadQuery(query) {
2050
+ if (!this.requiresSafePublicRawReads) return query;
2051
+ if (!query) return "?depth=0&joins=false";
2052
+ return `?depth=0&joins=false&${query.slice(1)}`;
2053
+ }
2054
+ buildSafePublicRawListQuery(params) {
2055
+ if (!this.requiresSafePublicRawReads) {
2056
+ return this.buildQuery(params);
2057
+ }
2058
+ const queryParams = {};
2059
+ if (params?.page !== void 0) queryParams.page = params.page;
2060
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
2061
+ return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
2062
+ }
1820
2063
  buildPostsListQuery(params) {
1821
2064
  const urlParams = new URLSearchParams();
1822
2065
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
@@ -1876,15 +2119,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
1876
2119
  "GET"
1877
2120
  );
1878
2121
  }
2122
+ /**
2123
+ * Public post detail projected by the same allowlist as the public feed.
2124
+ * Missing, hidden, and cross-tenant posts all resolve to `null`.
2125
+ */
2126
+ async getPost(params) {
2127
+ const query = new URLSearchParams({ postId: params.postId });
2128
+ try {
2129
+ return await this.execute(
2130
+ resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
2131
+ query
2132
+ }),
2133
+ resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
2134
+ );
2135
+ } catch (error) {
2136
+ if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
2137
+ return null;
2138
+ }
2139
+ throw error;
2140
+ }
2141
+ }
1879
2142
  listPostCategories(params) {
1880
2143
  return this.execute(
1881
- `/api/post-categories${this.buildQuery(params)}`,
2144
+ `/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
1882
2145
  "GET"
1883
2146
  );
1884
2147
  }
1885
2148
  listPostTags(params) {
1886
2149
  return this.execute(
1887
- `/api/post-tags${this.buildQuery(params)}`,
2150
+ `/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
1888
2151
  "GET"
1889
2152
  );
1890
2153
  }
@@ -2050,7 +2313,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
2050
2313
  }
2051
2314
  getReactionTypes() {
2052
2315
  return this.execute(
2053
- "/api/reaction-types?limit=100",
2316
+ `/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
2054
2317
  "GET"
2055
2318
  );
2056
2319
  }
@@ -2078,11 +2341,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
2078
2341
  }
2079
2342
  // Profiles
2080
2343
  listProfileLists(params) {
2081
- return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
2344
+ return this.execute(
2345
+ `/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
2346
+ "GET"
2347
+ );
2082
2348
  }
2083
2349
  async getProfileList(params) {
2084
2350
  const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
2085
- const res = await this.execute(`/api/customer-profile-lists${query}`, "GET");
2351
+ const res = await this.execute(
2352
+ `/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
2353
+ "GET"
2354
+ );
2086
2355
  return res.docs[0] ?? null;
2087
2356
  }
2088
2357
  updatePublicProfile(body) {
@@ -2142,7 +2411,8 @@ var BaseApi = class {
2142
2411
  body,
2143
2412
  {
2144
2413
  method: resolveOperationMethod2(endpoint2),
2145
- headers: options?.headers
2414
+ headers: options?.headers,
2415
+ errorFamily: resolveOperationErrorFamily(endpoint2)
2146
2416
  }
2147
2417
  );
2148
2418
  }
@@ -2199,7 +2469,7 @@ var MAX_COMMERCE_CAPABILITY_LENGTH = 512;
2199
2469
  var MAX_CART_DISCOUNT_CODE_LENGTH = 128;
2200
2470
  var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
2201
2471
  var ABANDONED_REASONS = ["expired", "customer", "operator"];
2202
- var PAYMENT_PROVIDERS = ["toss"];
2472
+ var PAYMENT_PROVIDERS = ["toss", "portone"];
2203
2473
  var PAYMENT_PROVIDER_STATUSES = [
2204
2474
  "requires_payment_method",
2205
2475
  "requires_action",
@@ -2282,6 +2552,21 @@ function nullableString(value, resource, path) {
2282
2552
  fail(resource, path, "string or null");
2283
2553
  }
2284
2554
  }
2555
+ function nonBlankString(value, resource, path) {
2556
+ const parsed = string(value, resource, path);
2557
+ if (parsed.trim().length === 0) {
2558
+ fail(resource, path, "non-blank string");
2559
+ }
2560
+ return parsed;
2561
+ }
2562
+ function nullableNonBlankString(value, resource, path) {
2563
+ if (value !== null) nonBlankString(value, resource, path);
2564
+ }
2565
+ function nullableResourceId(value, resource, path) {
2566
+ if (value !== null) {
2567
+ boundedString(value, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, path);
2568
+ }
2569
+ }
2285
2570
  function cartLineQuantity(value, resource, path) {
2286
2571
  const quantity = positiveInteger(value, resource, path);
2287
2572
  if (quantity > MAX_CART_LINE_QUANTITY) {
@@ -3103,6 +3388,59 @@ function validateCustomPaymentSession(value) {
3103
3388
  validateMoney(session.money, resource, "$.money");
3104
3389
  return value;
3105
3390
  }
3391
+ function validateRetrievedCustomPaymentSession(value) {
3392
+ const resource = "retrieved custom PaymentSession";
3393
+ const session = record(value, resource, "$");
3394
+ exact(
3395
+ session,
3396
+ [
3397
+ "id",
3398
+ "provider",
3399
+ "providerSessionId",
3400
+ "providerPaymentId",
3401
+ "status",
3402
+ "providerStatus",
3403
+ "finalizationStatus",
3404
+ "money",
3405
+ "orderId"
3406
+ ],
3407
+ [],
3408
+ resource,
3409
+ "$"
3410
+ );
3411
+ boundedString(session.id, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, "$.id");
3412
+ const provider = string(session.provider, resource, "$.provider");
3413
+ if (!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(provider)) {
3414
+ fail(resource, "$.provider", "provider slug");
3415
+ }
3416
+ nonBlankString(session.providerSessionId, resource, "$.providerSessionId");
3417
+ nullableNonBlankString(
3418
+ session.providerPaymentId,
3419
+ resource,
3420
+ "$.providerPaymentId"
3421
+ );
3422
+ enumValue(
3423
+ session.status,
3424
+ ["pending", "captured", "failed", "canceled"],
3425
+ resource,
3426
+ "$.status"
3427
+ );
3428
+ enumValue(
3429
+ session.providerStatus,
3430
+ PAYMENT_PROVIDER_STATUSES,
3431
+ resource,
3432
+ "$.providerStatus"
3433
+ );
3434
+ enumValue(
3435
+ session.finalizationStatus,
3436
+ ["not_ready", "pending", "committed"],
3437
+ resource,
3438
+ "$.finalizationStatus"
3439
+ );
3440
+ validateMoney(session.money, resource, "$.money");
3441
+ nullableResourceId(session.orderId, resource, "$.orderId");
3442
+ return value;
3443
+ }
3106
3444
  function validateConfirmCustomPaymentSessionResponse(value) {
3107
3445
  const resource = "custom PaymentSession confirmation";
3108
3446
  const result = record(value, resource, "$");
@@ -3153,8 +3491,101 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
3153
3491
  previous = current;
3154
3492
  });
3155
3493
  }
3156
- function validateNextAction(value, resource, path) {
3494
+ function validateNextAction(value, provider, resource, path) {
3157
3495
  const action = record(value, resource, path);
3496
+ if (provider === "portone") {
3497
+ if (action.type === "portone_sdk") {
3498
+ exact(
3499
+ action,
3500
+ [
3501
+ "type",
3502
+ "version",
3503
+ "storeId",
3504
+ "channelKey",
3505
+ "paymentId",
3506
+ "orderName",
3507
+ "totalAmount",
3508
+ "currency",
3509
+ "payMethod",
3510
+ "redirectUrl"
3511
+ ],
3512
+ [],
3513
+ resource,
3514
+ path
3515
+ );
3516
+ if (action.version !== "v2") fail(resource, `${path}.version`, "v2");
3517
+ for (const key of ["storeId", "channelKey"]) {
3518
+ boundedString(action[key], 255, resource, `${path}.${key}`);
3519
+ }
3520
+ const paymentId = boundedString(
3521
+ action.paymentId,
3522
+ 40,
3523
+ resource,
3524
+ `${path}.paymentId`
3525
+ );
3526
+ if (!/^[A-Za-z0-9]{6,40}$/.test(paymentId)) {
3527
+ fail(
3528
+ resource,
3529
+ `${path}.paymentId`,
3530
+ "6-40 ASCII alphanumeric characters"
3531
+ );
3532
+ }
3533
+ boundedString(
3534
+ action.orderName,
3535
+ MAX_COMMERCE_SHORT_TEXT_LENGTH,
3536
+ resource,
3537
+ `${path}.orderName`
3538
+ );
3539
+ positiveInteger(action.totalAmount, resource, `${path}.totalAmount`);
3540
+ if (action.currency !== "CURRENCY_KRW") {
3541
+ fail(resource, `${path}.currency`, "CURRENCY_KRW");
3542
+ }
3543
+ if (action.payMethod !== "CARD")
3544
+ fail(resource, `${path}.payMethod`, "CARD");
3545
+ const redirectUrl = boundedString(
3546
+ action.redirectUrl,
3547
+ 2048,
3548
+ resource,
3549
+ `${path}.redirectUrl`
3550
+ );
3551
+ try {
3552
+ const parsed = new URL(redirectUrl);
3553
+ const loopback = parsed.protocol === "http:" && (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1");
3554
+ if (!loopback && parsed.protocol !== "https:" || parsed.username || parsed.password)
3555
+ throw new Error("unsafe redirect URL");
3556
+ } catch {
3557
+ fail(
3558
+ resource,
3559
+ `${path}.redirectUrl`,
3560
+ "HTTPS or loopback URL without embedded credentials"
3561
+ );
3562
+ }
3563
+ return;
3564
+ }
3565
+ exact(action, ["type", "checkoutUrl"], [], resource, path);
3566
+ if (action.type !== "portone_checkout") {
3567
+ fail(resource, `${path}.type`, "portone_checkout | portone_sdk");
3568
+ }
3569
+ const checkoutUrl = boundedString(
3570
+ action.checkoutUrl,
3571
+ 2048,
3572
+ resource,
3573
+ `${path}.checkoutUrl`
3574
+ );
3575
+ try {
3576
+ const parsed = new URL(checkoutUrl);
3577
+ if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
3578
+ throw new Error("unsafe checkout URL");
3579
+ }
3580
+ } catch {
3581
+ fail(
3582
+ resource,
3583
+ `${path}.checkoutUrl`,
3584
+ "absolute HTTPS URL without embedded credentials"
3585
+ );
3586
+ }
3587
+ return;
3588
+ }
3158
3589
  exact(
3159
3590
  action,
3160
3591
  [
@@ -3205,10 +3636,18 @@ function validateNextAction(value, resource, path) {
3205
3636
  if (action.customerEmail !== void 0)
3206
3637
  validateCustomer({ email: action.customerEmail }, resource, path);
3207
3638
  }
3208
- function validatePublicPaymentSession(value) {
3639
+ function validatePublicPaymentSession(value, expectedProvider) {
3209
3640
  const resource = "PaymentSession";
3210
3641
  const session = record(value, resource, "$");
3211
- enumValue(session.provider, PAYMENT_PROVIDERS, resource, "$.provider");
3642
+ const provider = enumValue(
3643
+ session.provider,
3644
+ PAYMENT_PROVIDERS,
3645
+ resource,
3646
+ "$.provider"
3647
+ );
3648
+ if (expectedProvider !== void 0 && provider !== expectedProvider) {
3649
+ fail(resource, "$.provider", expectedProvider);
3650
+ }
3212
3651
  const status = enumValue(
3213
3652
  session.providerStatus,
3214
3653
  PAYMENT_PROVIDER_STATUSES,
@@ -3245,7 +3684,12 @@ function validatePublicPaymentSession(value) {
3245
3684
  }
3246
3685
  if (!("nextAction" in session))
3247
3686
  fail(resource, "$.nextAction", "required field");
3248
- validateNextAction(session.nextAction, resource, "$.nextAction");
3687
+ validateNextAction(
3688
+ session.nextAction,
3689
+ provider,
3690
+ resource,
3691
+ "$.nextAction"
3692
+ );
3249
3693
  } else if (session.sessionRole === "residual") {
3250
3694
  if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
3251
3695
  fail(resource, "$", "suppressed residual not-ready state");
@@ -4517,21 +4961,11 @@ var PRODUCT_DETAIL_UNAVAILABLE_REASONS = /* @__PURE__ */ new Set([
4517
4961
  "not_published",
4518
4962
  "feature_disabled"
4519
4963
  ]);
4520
- function isRecord(value) {
4521
- return typeof value === "object" && value !== null;
4522
- }
4523
- function readProductDetailUnavailableReason(value) {
4524
- if (!isRecord(value)) return void 0;
4525
- const directReason = value.reason ?? value.code;
4526
- if (typeof directReason === "string" && PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(directReason)) {
4527
- return directReason;
4528
- }
4529
- return readProductDetailUnavailableReason(value.body);
4530
- }
4531
4964
  function productDetailResultFromError(error) {
4532
4965
  if (!(error instanceof SDKError) || error.status !== 404) return void 0;
4533
- const reason = readProductDetailUnavailableReason(error.details);
4534
- if (!reason) return void 0;
4966
+ const reason = getSDKErrorReason(error);
4967
+ if (!reason || !PRODUCT_DETAIL_UNAVAILABLE_REASONS.has(reason))
4968
+ return void 0;
4535
4969
  return { found: false, reason };
4536
4970
  }
4537
4971
  var MARKET_PRICE_QUERY_UNSUPPORTED_MESSAGE = "Market listing pages do not support base price filters or price sorts.";
@@ -4964,8 +5398,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4964
5398
  }
4965
5399
  });
4966
5400
  }
4967
- async paymentSession(result) {
4968
- return validatePublicPaymentSession(await result);
5401
+ async paymentSession(result, expectedProvider) {
5402
+ return validatePublicPaymentSession(await result, expectedProvider);
4969
5403
  }
4970
5404
  create(params) {
4971
5405
  const { idempotencyKey, ...body } = params;
@@ -4975,18 +5409,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4975
5409
  this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
4976
5410
  body,
4977
5411
  idempotencyKey
4978
- )
5412
+ ),
5413
+ "toss"
5414
+ );
5415
+ }
5416
+ createPortOne(params) {
5417
+ const { idempotencyKey, ...body } = params;
5418
+ assertCommerceIdempotencyKey(idempotencyKey);
5419
+ return this.paymentSession(
5420
+ this.post(
5421
+ this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
5422
+ body,
5423
+ idempotencyKey
5424
+ ),
5425
+ "portone"
4979
5426
  );
4980
5427
  }
4981
5428
  retrieve(params) {
4982
5429
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4983
- return this.paymentSession(this.post(endpoint2, params));
5430
+ return this.paymentSession(
5431
+ this.post(endpoint2, params),
5432
+ "toss"
5433
+ );
5434
+ }
5435
+ retrievePortOne(params) {
5436
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
5437
+ return this.paymentSession(
5438
+ this.post(endpoint2, params),
5439
+ "portone"
5440
+ );
4984
5441
  }
4985
5442
  cancel(params) {
4986
5443
  const { idempotencyKey, ...body } = params;
4987
5444
  assertCommerceIdempotencyKey(idempotencyKey);
4988
5445
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4989
- return this.paymentSession(this.post(endpoint2, body, idempotencyKey));
5446
+ return this.paymentSession(
5447
+ this.post(endpoint2, body, idempotencyKey),
5448
+ "toss"
5449
+ );
5450
+ }
5451
+ cancelPortOne(params) {
5452
+ const { idempotencyKey, ...body } = params;
5453
+ assertCommerceIdempotencyKey(idempotencyKey);
5454
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
5455
+ return this.paymentSession(
5456
+ this.post(endpoint2, body, idempotencyKey),
5457
+ "portone"
5458
+ );
4990
5459
  }
4991
5460
  confirm(params) {
4992
5461
  const { idempotencyKey, ...body } = params;
@@ -4996,7 +5465,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4996
5465
  COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
4997
5466
  body,
4998
5467
  idempotencyKey
4999
- )
5468
+ ),
5469
+ "toss"
5000
5470
  );
5001
5471
  }
5002
5472
  };
@@ -5017,6 +5487,15 @@ var CustomPaymentSessionApi = class extends BaseApi {
5017
5487
  );
5018
5488
  return validateCustomPaymentSession(result);
5019
5489
  }
5490
+ async retrieve(params) {
5491
+ const result = await this.requestEndpoint(
5492
+ COMMERCE_ENDPOINTS.paymentSessions.custom.retrieve,
5493
+ params
5494
+ );
5495
+ return validateRetrievedCustomPaymentSession(
5496
+ result
5497
+ );
5498
+ }
5020
5499
  async confirm(params, options = {}) {
5021
5500
  const body = {
5022
5501
  provider: params.provider,
@@ -5164,11 +5643,17 @@ var ServerCommerceClient = class {
5164
5643
  };
5165
5644
  this.paymentSessions = {
5166
5645
  create: paymentSessionApi.create.bind(paymentSessionApi),
5646
+ createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
5167
5647
  retrieve: (params) => paymentSessionApi.retrieve(params),
5648
+ retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
5168
5649
  cancel: (params) => paymentSessionApi.cancel(params),
5650
+ cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params),
5169
5651
  confirm: paymentSessionApi.confirm.bind(paymentSessionApi),
5170
5652
  custom: {
5171
5653
  create: customPaymentSessionApi.create.bind(customPaymentSessionApi),
5654
+ retrieve: customPaymentSessionApi.retrieve.bind(
5655
+ customPaymentSessionApi
5656
+ ),
5172
5657
  confirm: customPaymentSessionApi.confirm.bind(customPaymentSessionApi)
5173
5658
  }
5174
5659
  };