@01.software/sdk 0.46.0 → 0.48.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 +75 -1
  2. package/README.md +81 -7
  3. package/dist/client.cjs +304 -63
  4. package/dist/client.cjs.map +1 -1
  5. package/dist/client.d.cts +6 -6
  6. package/dist/client.d.ts +6 -6
  7. package/dist/client.js +304 -63
  8. package/dist/client.js.map +1 -1
  9. package/dist/{collection-client-DolMjCoC.d.cts → collection-client-CBup9yOx.d.cts} +4 -4
  10. package/dist/{collection-client-D6kKrYdq.d.ts → collection-client-D3ExJU-7.d.ts} +4 -4
  11. package/dist/{const-BAG0MH0u.d.cts → const-BXEi1Kix.d.cts} +4 -4
  12. package/dist/{const-CaPq2AE4.d.ts → const-k9gHylYa.d.ts} +4 -4
  13. package/dist/errors.cjs +49 -1
  14. package/dist/errors.cjs.map +1 -1
  15. package/dist/errors.d.cts +3 -3
  16. package/dist/errors.d.ts +3 -3
  17. package/dist/errors.js +49 -1
  18. package/dist/errors.js.map +1 -1
  19. package/dist/{index-YGrZrxNn.d.cts → index-BCM9CTL7.d.cts} +3 -3
  20. package/dist/{index-BNICJxBL.d.ts → index-CHGGkcLj.d.ts} +3 -3
  21. package/dist/index.cjs +308 -64
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +7 -7
  24. package/dist/index.d.ts +7 -7
  25. package/dist/index.js +308 -64
  26. package/dist/index.js.map +1 -1
  27. package/dist/{payload-types-CJZuXcgF.d.cts → payload-types-B6AZQcB7.d.cts} +182 -15
  28. package/dist/{payload-types-CJZuXcgF.d.ts → payload-types-B6AZQcB7.d.ts} +182 -15
  29. package/dist/query.cjs +144 -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 +144 -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 +385 -63
  38. package/dist/server.cjs.map +1 -1
  39. package/dist/server.d.cts +7 -7
  40. package/dist/server.d.ts +7 -7
  41. package/dist/server.js +385 -63
  42. package/dist/server.js.map +1 -1
  43. package/dist/storefront-cache.cjs +49 -1
  44. package/dist/storefront-cache.cjs.map +1 -1
  45. package/dist/storefront-cache.js +49 -1
  46. package/dist/storefront-cache.js.map +1 -1
  47. package/dist/{types-D5p7-m1l.d.cts → types-8us-_C-Q.d.cts} +2 -2
  48. package/dist/{types-BC6rVmJa.d.ts → types-ByD2zii1.d.ts} +2 -2
  49. package/dist/{types-xlqBeW2N.d.cts → types-CM2je9Kw.d.cts} +84 -7
  50. package/dist/{types-C60vHIkY.d.ts → types-DbA5V3mt.d.ts} +84 -7
  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 -6
package/dist/server.js CHANGED
@@ -39,34 +39,78 @@ var SDKError = class extends Error {
39
39
  };
40
40
  var COMMERCE_ERROR_CODES = [
41
41
  "validation_failed",
42
+ "bad_request",
42
43
  "unauthorized",
43
44
  "forbidden",
45
+ "account_suspended",
46
+ "key_invalid",
47
+ "pat_tenant_header_forbidden",
48
+ "tenant_mismatch",
49
+ "test_tenant_expired",
50
+ "token_invalid",
44
51
  "token_expired",
45
52
  "origin_not_allowed",
46
53
  "server_credentials_required",
54
+ "role_denied",
55
+ "scope_denied",
56
+ "feature_disabled",
47
57
  "not_found",
48
58
  "conflict",
59
+ "locked",
49
60
  "cart_revision_conflict",
50
61
  "rate_limit_exceeded",
51
62
  "usage_limit_exceeded",
52
63
  "service_unavailable",
53
64
  "idempotency_conflict",
54
65
  "idempotency_in_progress",
66
+ "idempotency_key_required",
67
+ "invalid_idempotency_key",
55
68
  "cart_not_active",
56
69
  "cart_locked",
57
70
  "cart_empty",
58
71
  "cart_market_unavailable",
59
72
  "cart_market_mismatch",
60
73
  "checkout_not_open",
74
+ "checkout_already_open",
61
75
  "payment_slot_held",
62
76
  "reservation_expired",
63
77
  "payment_session_not_cancelable",
78
+ "payment_session_conflict",
64
79
  "provider_identity_mismatch",
80
+ "payment_method_unavailable",
65
81
  "provider_unavailable",
66
82
  "lock_timeout",
67
83
  "price_changed",
68
84
  "pricing_fact_in_use",
69
85
  "insufficient_stock",
86
+ "reservation_conflict",
87
+ "stock_lock_unavailable",
88
+ "variant_not_found",
89
+ "variant_stock_write_failed",
90
+ "stock_invariant_violation",
91
+ "payment_confirmation_in_flight",
92
+ "checkout_reservation_release_requires_transaction",
93
+ "admission_metadata_invalid",
94
+ "admission_metadata_required",
95
+ "capacity_exceeded",
96
+ "occurrence_lock_unavailable",
97
+ "occurrence_not_open",
98
+ "admission_type_capacity_exceeded",
99
+ "admission_type_occurrence_mismatch",
100
+ "admission_hold_expired",
101
+ "admission_hold_checkout_item_conflict",
102
+ "admission_hold_checkout_conflict",
103
+ "admission_hold_quantity_mismatch",
104
+ "admission_hold_unbound",
105
+ "admission_hold_missing",
106
+ "admission_hold_checkout_item_missing",
107
+ "admission_hold_expiry_failed",
108
+ "admission_hold_expiry_requires_transaction",
109
+ "admission_hold_line_item_mismatch",
110
+ "admission_materialization_failed",
111
+ "variant_inactive",
112
+ "variant_product_mismatch",
113
+ "product_not_public",
70
114
  "market_not_found",
71
115
  "market_shipping_currency_unsupported",
72
116
  "missing_market_rate",
@@ -91,7 +135,11 @@ var COMMERCE_ERROR_CODES = [
91
135
  "discount_min_order_amount",
92
136
  "discount_currency_scope_required",
93
137
  "discount_allocation_method_unsupported",
94
- "currency_mismatch"
138
+ "currency_mismatch",
139
+ "customer_token_required",
140
+ "market_required",
141
+ "server_derived",
142
+ "internal_error"
95
143
  ];
96
144
  var COMMERCE_ERROR_CODE_SET = new Set(
97
145
  COMMERCE_ERROR_CODES
@@ -117,6 +165,12 @@ function commerceProtocolError(issue, trustedRequestId) {
117
165
  );
118
166
  }
119
167
  function parseCommerceErrorEnvelope(body, headerRequestId) {
168
+ if (headerRequestId === void 0) {
169
+ throw commerceProtocolError("missing_request_id_header");
170
+ }
171
+ if (headerRequestId.length === 0) {
172
+ throw commerceProtocolError("empty_request_id_header");
173
+ }
120
174
  if (!isPlainRecord(body)) {
121
175
  throw commerceProtocolError("expected_object", headerRequestId);
122
176
  }
@@ -126,7 +180,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
126
180
  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
181
  throw commerceProtocolError("invalid_field", headerRequestId);
128
182
  }
129
- if (headerRequestId && headerRequestId !== body.requestId) {
183
+ if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
130
184
  throw commerceProtocolError("request_id_mismatch", headerRequestId);
131
185
  }
132
186
  return {
@@ -1378,7 +1432,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1378
1432
  return parsed;
1379
1433
  }
1380
1434
  const data = parsed;
1381
- if (data.error) {
1435
+ const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
1436
+ (key) => Object.prototype.hasOwnProperty.call(data, key)
1437
+ );
1438
+ if (data.error || hasCommerceEnvelopeSignal) {
1382
1439
  const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
1383
1440
  const reason = typeof data.reason === "string" ? data.reason : void 0;
1384
1441
  const requestId = response.headers.get("x-request-id") ?? void 0;
@@ -1414,12 +1471,14 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1414
1471
 
1415
1472
  // ../../internal/http-contracts/src/index.ts
1416
1473
  var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
1417
- var operation = (collection, method, path) => Object.freeze({
1474
+ var operation = (collection, method, path, errorFamily) => Object.freeze({
1418
1475
  [operationBrand]: true,
1419
1476
  collection,
1420
1477
  method,
1421
- path
1478
+ path,
1479
+ ...errorFamily && { errorFamily }
1422
1480
  });
1481
+ var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
1423
1482
  var COMMERCE_ENDPOINT_OPERATIONS = {
1424
1483
  products: {
1425
1484
  detail: operation("products", "get", "/detail"),
@@ -1452,13 +1511,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1452
1511
  byPayment: operation("orders", "get", "/by-payment"),
1453
1512
  cancel: operation("orders", "post", "/cancel"),
1454
1513
  resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
1455
- checkout: operation("orders", "post", "/checkout"),
1514
+ checkout: strictCommerceOperation("orders", "post", "/checkout"),
1456
1515
  createFulfillment: operation("orders", "post", "/create-fulfillment"),
1457
1516
  updateFulfillment: operation("orders", "post", "/update-fulfillment")
1458
1517
  },
1459
1518
  checkouts: {
1460
- detail: operation("checkouts", "post", "/detail"),
1461
- query: operation("checkouts", "post", "/query")
1519
+ detail: strictCommerceOperation("checkouts", "post", "/detail"),
1520
+ query: strictCommerceOperation("checkouts", "post", "/query")
1462
1521
  },
1463
1522
  transactions: {
1464
1523
  update: operation("transactions", "post", "/update")
@@ -1479,29 +1538,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1479
1538
  bulkImport: operation("fulfillments", "post", "/bulk-import")
1480
1539
  },
1481
1540
  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")
1541
+ create: strictCommerceOperation("carts", "post", "/create"),
1542
+ retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
1543
+ mine: strictCommerceOperation("carts", "post", "/mine"),
1544
+ merge: strictCommerceOperation("carts", "post", "/merge"),
1545
+ addItem: strictCommerceOperation("carts", "post", "/add-item"),
1546
+ updateItem: strictCommerceOperation("carts", "post", "/update-item"),
1547
+ removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
1548
+ updateDiscountCodes: strictCommerceOperation(
1549
+ "carts",
1550
+ "post",
1551
+ "/update-discount-codes"
1552
+ ),
1553
+ updateAttributes: strictCommerceOperation(
1554
+ "carts",
1555
+ "post",
1556
+ "/update-attributes"
1557
+ ),
1558
+ clear: strictCommerceOperation("carts", "post", "/clear")
1492
1559
  },
1493
1560
  paymentSessions: {
1494
- create: operation("payment-sessions", "post", "/create"),
1495
- retrieve: operation("payment-sessions", "post", "/retrieve"),
1496
- cancel: operation("payment-sessions", "post", "/cancel"),
1561
+ create: strictCommerceOperation("payment-sessions", "post", "/create"),
1562
+ retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
1563
+ cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
1497
1564
  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")
1565
+ create: strictCommerceOperation(
1566
+ "payment-sessions",
1567
+ "post",
1568
+ "/server/create"
1569
+ ),
1570
+ retrieve: strictCommerceOperation(
1571
+ "payment-sessions",
1572
+ "post",
1573
+ "/server/retrieve"
1574
+ ),
1575
+ cancel: strictCommerceOperation(
1576
+ "payment-sessions",
1577
+ "post",
1578
+ "/server/cancel"
1579
+ ),
1580
+ confirm: strictCommerceOperation(
1581
+ "payment-sessions",
1582
+ "post",
1583
+ "/server/confirm"
1584
+ )
1502
1585
  },
1503
1586
  custom: {
1504
1587
  create: operation("orders", "post", "/custom-payment-sessions"),
1588
+ retrieve: operation(
1589
+ "orders",
1590
+ "post",
1591
+ "/custom-payment-sessions/retrieve"
1592
+ ),
1505
1593
  confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
1506
1594
  }
1507
1595
  },
@@ -1527,6 +1615,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
1527
1615
  )
1528
1616
  }
1529
1617
  };
1618
+ var COMMUNITY_ENDPOINT_OPERATIONS = {
1619
+ posts: {
1620
+ detail: operation("posts", "get", "/detail")
1621
+ }
1622
+ };
1530
1623
  function resolveOperationTemplate(descriptor) {
1531
1624
  return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
1532
1625
  }
@@ -1558,6 +1651,9 @@ var sharedEndpoint = (descriptor) => descriptor;
1558
1651
  function resolveOperationMethod2(descriptor) {
1559
1652
  return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
1560
1653
  }
1654
+ function resolveOperationErrorFamily(descriptor) {
1655
+ return "collection" in descriptor ? descriptor.errorFamily : void 0;
1656
+ }
1561
1657
  function resolveOperationPath2(descriptor, options) {
1562
1658
  if ("collection" in descriptor) {
1563
1659
  return resolveOperationPath(descriptor, options);
@@ -1592,12 +1688,12 @@ var COMMERCE_ENDPOINTS = {
1592
1688
  updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
1593
1689
  },
1594
1690
  checkouts: {
1595
- create: endpoint("POST", "/api/orders/checkout"),
1596
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1691
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1692
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1597
1693
  server: {
1598
- create: endpoint("POST", "/api/orders/checkout"),
1599
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1600
- query: endpoint("POST", "/api/checkouts/query")
1694
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1695
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1696
+ query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
1601
1697
  }
1602
1698
  },
1603
1699
  returns: {
@@ -1615,10 +1711,10 @@ var COMMERCE_ENDPOINTS = {
1615
1711
  bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
1616
1712
  },
1617
1713
  carts: {
1618
- create: endpoint("POST", "/api/carts/create"),
1714
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
1619
1715
  retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
1620
- mine: endpoint("POST", "/api/carts/mine"),
1621
- merge: endpoint("POST", "/api/carts/merge"),
1716
+ mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
1717
+ merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
1622
1718
  server: {
1623
1719
  // Server credentials are an authorization lane, not a second Cart
1624
1720
  // transport. These must stay bound to the registered shared operations.
@@ -1638,29 +1734,46 @@ var COMMERCE_ENDPOINTS = {
1638
1734
  clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1639
1735
  },
1640
1736
  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")
1737
+ updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
1738
+ removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
1739
+ updateDiscountCodes: sharedEndpoint(
1740
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
1741
+ ),
1742
+ updateAttributes: sharedEndpoint(
1743
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
1744
+ ),
1745
+ clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1646
1746
  },
1647
1747
  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"),
1748
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
1749
+ retrieve: sharedEndpoint(
1750
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
1751
+ ),
1752
+ cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
1651
1753
  custom: {
1652
1754
  create: sharedEndpoint(
1653
1755
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
1654
1756
  ),
1757
+ retrieve: sharedEndpoint(
1758
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
1759
+ ),
1655
1760
  confirm: sharedEndpoint(
1656
1761
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
1657
1762
  )
1658
1763
  },
1659
1764
  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")
1765
+ create: sharedEndpoint(
1766
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
1767
+ ),
1768
+ retrieve: sharedEndpoint(
1769
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
1770
+ ),
1771
+ cancel: sharedEndpoint(
1772
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
1773
+ ),
1774
+ confirm: sharedEndpoint(
1775
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
1776
+ )
1664
1777
  }
1665
1778
  },
1666
1779
  shippingPolicies: {
@@ -1751,7 +1864,8 @@ var CustomerScopedApi = class {
1751
1864
  return this.transport.request(resolveOperationPath2(endpoint2, options), {
1752
1865
  method: resolveOperationMethod2(endpoint2),
1753
1866
  body,
1754
- headers: options?.headers
1867
+ headers: options?.headers,
1868
+ errorFamily: resolveOperationErrorFamily(endpoint2)
1755
1869
  });
1756
1870
  }
1757
1871
  };
@@ -1773,15 +1887,39 @@ function unwrapPayloadDoc(value) {
1773
1887
  }
1774
1888
  return value;
1775
1889
  }
1890
+ function hasCanonicalNotFoundReason(error) {
1891
+ const details = error.details;
1892
+ if (typeof details !== "object" || details === null) return false;
1893
+ if ("reason" in details && details.reason === "not_found") return true;
1894
+ if (!("body" in details) || typeof details.body !== "object" || details.body === null) {
1895
+ return false;
1896
+ }
1897
+ return "reason" in details.body && details.body.reason === "not_found";
1898
+ }
1776
1899
  var CommunityClient = class extends RawCustomerScopedApi {
1777
1900
  constructor(options) {
1778
1901
  super("CommunityClient", { ...options, requiresCredential: false });
1902
+ this.requiresSafePublicRawReads = !options.secretKey;
1779
1903
  }
1780
1904
  buildQuery(params) {
1781
1905
  if (!params) return "";
1782
1906
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
1783
1907
  return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
1784
1908
  }
1909
+ withSafePublicRawReadQuery(query) {
1910
+ if (!this.requiresSafePublicRawReads) return query;
1911
+ if (!query) return "?depth=0&joins=false";
1912
+ return `?depth=0&joins=false&${query.slice(1)}`;
1913
+ }
1914
+ buildSafePublicRawListQuery(params) {
1915
+ if (!this.requiresSafePublicRawReads) {
1916
+ return this.buildQuery(params);
1917
+ }
1918
+ const queryParams = {};
1919
+ if (params?.page !== void 0) queryParams.page = params.page;
1920
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
1921
+ return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
1922
+ }
1785
1923
  buildPostsListQuery(params) {
1786
1924
  const urlParams = new URLSearchParams();
1787
1925
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
@@ -1841,15 +1979,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
1841
1979
  "GET"
1842
1980
  );
1843
1981
  }
1982
+ /**
1983
+ * Public post detail projected by the same allowlist as the public feed.
1984
+ * Missing, hidden, and cross-tenant posts all resolve to `null`.
1985
+ */
1986
+ async getPost(params) {
1987
+ const query = new URLSearchParams({ postId: params.postId });
1988
+ try {
1989
+ return await this.execute(
1990
+ resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
1991
+ query
1992
+ }),
1993
+ resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
1994
+ );
1995
+ } catch (error) {
1996
+ if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
1997
+ return null;
1998
+ }
1999
+ throw error;
2000
+ }
2001
+ }
1844
2002
  listPostCategories(params) {
1845
2003
  return this.execute(
1846
- `/api/post-categories${this.buildQuery(params)}`,
2004
+ `/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
1847
2005
  "GET"
1848
2006
  );
1849
2007
  }
1850
2008
  listPostTags(params) {
1851
2009
  return this.execute(
1852
- `/api/post-tags${this.buildQuery(params)}`,
2010
+ `/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
1853
2011
  "GET"
1854
2012
  );
1855
2013
  }
@@ -2015,7 +2173,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
2015
2173
  }
2016
2174
  getReactionTypes() {
2017
2175
  return this.execute(
2018
- "/api/reaction-types?limit=100",
2176
+ `/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
2019
2177
  "GET"
2020
2178
  );
2021
2179
  }
@@ -2043,11 +2201,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
2043
2201
  }
2044
2202
  // Profiles
2045
2203
  listProfileLists(params) {
2046
- return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
2204
+ return this.execute(
2205
+ `/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
2206
+ "GET"
2207
+ );
2047
2208
  }
2048
2209
  async getProfileList(params) {
2049
2210
  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");
2211
+ const res = await this.execute(
2212
+ `/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
2213
+ "GET"
2214
+ );
2051
2215
  return res.docs[0] ?? null;
2052
2216
  }
2053
2217
  updatePublicProfile(body) {
@@ -2107,7 +2271,8 @@ var BaseApi = class {
2107
2271
  body,
2108
2272
  {
2109
2273
  method: resolveOperationMethod2(endpoint2),
2110
- headers: options?.headers
2274
+ headers: options?.headers,
2275
+ errorFamily: resolveOperationErrorFamily(endpoint2)
2111
2276
  }
2112
2277
  );
2113
2278
  }
@@ -2164,7 +2329,7 @@ var MAX_COMMERCE_CAPABILITY_LENGTH = 512;
2164
2329
  var MAX_CART_DISCOUNT_CODE_LENGTH = 128;
2165
2330
  var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
2166
2331
  var ABANDONED_REASONS = ["expired", "customer", "operator"];
2167
- var PAYMENT_PROVIDERS = ["toss"];
2332
+ var PAYMENT_PROVIDERS = ["toss", "portone"];
2168
2333
  var PAYMENT_PROVIDER_STATUSES = [
2169
2334
  "requires_payment_method",
2170
2335
  "requires_action",
@@ -2247,6 +2412,21 @@ function nullableString(value, resource, path) {
2247
2412
  fail(resource, path, "string or null");
2248
2413
  }
2249
2414
  }
2415
+ function nonBlankString(value, resource, path) {
2416
+ const parsed = string(value, resource, path);
2417
+ if (parsed.trim().length === 0) {
2418
+ fail(resource, path, "non-blank string");
2419
+ }
2420
+ return parsed;
2421
+ }
2422
+ function nullableNonBlankString(value, resource, path) {
2423
+ if (value !== null) nonBlankString(value, resource, path);
2424
+ }
2425
+ function nullableResourceId(value, resource, path) {
2426
+ if (value !== null) {
2427
+ boundedString(value, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, path);
2428
+ }
2429
+ }
2250
2430
  function cartLineQuantity(value, resource, path) {
2251
2431
  const quantity = positiveInteger(value, resource, path);
2252
2432
  if (quantity > MAX_CART_LINE_QUANTITY) {
@@ -3068,6 +3248,59 @@ function validateCustomPaymentSession(value) {
3068
3248
  validateMoney(session.money, resource, "$.money");
3069
3249
  return value;
3070
3250
  }
3251
+ function validateRetrievedCustomPaymentSession(value) {
3252
+ const resource = "retrieved custom PaymentSession";
3253
+ const session = record(value, resource, "$");
3254
+ exact(
3255
+ session,
3256
+ [
3257
+ "id",
3258
+ "provider",
3259
+ "providerSessionId",
3260
+ "providerPaymentId",
3261
+ "status",
3262
+ "providerStatus",
3263
+ "finalizationStatus",
3264
+ "money",
3265
+ "orderId"
3266
+ ],
3267
+ [],
3268
+ resource,
3269
+ "$"
3270
+ );
3271
+ boundedString(session.id, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, "$.id");
3272
+ const provider = string(session.provider, resource, "$.provider");
3273
+ if (!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(provider)) {
3274
+ fail(resource, "$.provider", "provider slug");
3275
+ }
3276
+ nonBlankString(session.providerSessionId, resource, "$.providerSessionId");
3277
+ nullableNonBlankString(
3278
+ session.providerPaymentId,
3279
+ resource,
3280
+ "$.providerPaymentId"
3281
+ );
3282
+ enumValue(
3283
+ session.status,
3284
+ ["pending", "captured", "failed", "canceled"],
3285
+ resource,
3286
+ "$.status"
3287
+ );
3288
+ enumValue(
3289
+ session.providerStatus,
3290
+ PAYMENT_PROVIDER_STATUSES,
3291
+ resource,
3292
+ "$.providerStatus"
3293
+ );
3294
+ enumValue(
3295
+ session.finalizationStatus,
3296
+ ["not_ready", "pending", "committed"],
3297
+ resource,
3298
+ "$.finalizationStatus"
3299
+ );
3300
+ validateMoney(session.money, resource, "$.money");
3301
+ nullableResourceId(session.orderId, resource, "$.orderId");
3302
+ return value;
3303
+ }
3071
3304
  function validateConfirmCustomPaymentSessionResponse(value) {
3072
3305
  const resource = "custom PaymentSession confirmation";
3073
3306
  const result = record(value, resource, "$");
@@ -3118,8 +3351,33 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
3118
3351
  previous = current;
3119
3352
  });
3120
3353
  }
3121
- function validateNextAction(value, resource, path) {
3354
+ function validateNextAction(value, provider, resource, path) {
3122
3355
  const action = record(value, resource, path);
3356
+ if (provider === "portone") {
3357
+ exact(action, ["type", "checkoutUrl"], [], resource, path);
3358
+ if (action.type !== "portone_checkout") {
3359
+ fail(resource, `${path}.type`, "portone_checkout");
3360
+ }
3361
+ const checkoutUrl = boundedString(
3362
+ action.checkoutUrl,
3363
+ 2048,
3364
+ resource,
3365
+ `${path}.checkoutUrl`
3366
+ );
3367
+ try {
3368
+ const parsed = new URL(checkoutUrl);
3369
+ if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
3370
+ throw new Error("unsafe checkout URL");
3371
+ }
3372
+ } catch {
3373
+ fail(
3374
+ resource,
3375
+ `${path}.checkoutUrl`,
3376
+ "absolute HTTPS URL without embedded credentials"
3377
+ );
3378
+ }
3379
+ return;
3380
+ }
3123
3381
  exact(
3124
3382
  action,
3125
3383
  [
@@ -3170,10 +3428,18 @@ function validateNextAction(value, resource, path) {
3170
3428
  if (action.customerEmail !== void 0)
3171
3429
  validateCustomer({ email: action.customerEmail }, resource, path);
3172
3430
  }
3173
- function validatePublicPaymentSession(value) {
3431
+ function validatePublicPaymentSession(value, expectedProvider) {
3174
3432
  const resource = "PaymentSession";
3175
3433
  const session = record(value, resource, "$");
3176
- enumValue(session.provider, PAYMENT_PROVIDERS, resource, "$.provider");
3434
+ const provider = enumValue(
3435
+ session.provider,
3436
+ PAYMENT_PROVIDERS,
3437
+ resource,
3438
+ "$.provider"
3439
+ );
3440
+ if (expectedProvider !== void 0 && provider !== expectedProvider) {
3441
+ fail(resource, "$.provider", expectedProvider);
3442
+ }
3177
3443
  const status = enumValue(
3178
3444
  session.providerStatus,
3179
3445
  PAYMENT_PROVIDER_STATUSES,
@@ -3210,7 +3476,12 @@ function validatePublicPaymentSession(value) {
3210
3476
  }
3211
3477
  if (!("nextAction" in session))
3212
3478
  fail(resource, "$.nextAction", "required field");
3213
- validateNextAction(session.nextAction, resource, "$.nextAction");
3479
+ validateNextAction(
3480
+ session.nextAction,
3481
+ provider,
3482
+ resource,
3483
+ "$.nextAction"
3484
+ );
3214
3485
  } else if (session.sessionRole === "residual") {
3215
3486
  if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
3216
3487
  fail(resource, "$", "suppressed residual not-ready state");
@@ -4929,8 +5200,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4929
5200
  }
4930
5201
  });
4931
5202
  }
4932
- async paymentSession(result) {
4933
- return validatePublicPaymentSession(await result);
5203
+ async paymentSession(result, expectedProvider) {
5204
+ return validatePublicPaymentSession(await result, expectedProvider);
4934
5205
  }
4935
5206
  create(params) {
4936
5207
  const { idempotencyKey, ...body } = params;
@@ -4940,18 +5211,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4940
5211
  this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
4941
5212
  body,
4942
5213
  idempotencyKey
4943
- )
5214
+ ),
5215
+ "toss"
5216
+ );
5217
+ }
5218
+ createPortOne(params) {
5219
+ const { idempotencyKey, ...body } = params;
5220
+ assertCommerceIdempotencyKey(idempotencyKey);
5221
+ return this.paymentSession(
5222
+ this.post(
5223
+ this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
5224
+ body,
5225
+ idempotencyKey
5226
+ ),
5227
+ "portone"
4944
5228
  );
4945
5229
  }
4946
5230
  retrieve(params) {
4947
5231
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4948
- return this.paymentSession(this.post(endpoint2, params));
5232
+ return this.paymentSession(
5233
+ this.post(endpoint2, params),
5234
+ "toss"
5235
+ );
5236
+ }
5237
+ retrievePortOne(params) {
5238
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
5239
+ return this.paymentSession(
5240
+ this.post(endpoint2, params),
5241
+ "portone"
5242
+ );
4949
5243
  }
4950
5244
  cancel(params) {
4951
5245
  const { idempotencyKey, ...body } = params;
4952
5246
  assertCommerceIdempotencyKey(idempotencyKey);
4953
5247
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4954
- return this.paymentSession(this.post(endpoint2, body, idempotencyKey));
5248
+ return this.paymentSession(
5249
+ this.post(endpoint2, body, idempotencyKey),
5250
+ "toss"
5251
+ );
5252
+ }
5253
+ cancelPortOne(params) {
5254
+ const { idempotencyKey, ...body } = params;
5255
+ assertCommerceIdempotencyKey(idempotencyKey);
5256
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
5257
+ return this.paymentSession(
5258
+ this.post(endpoint2, body, idempotencyKey),
5259
+ "portone"
5260
+ );
4955
5261
  }
4956
5262
  confirm(params) {
4957
5263
  const { idempotencyKey, ...body } = params;
@@ -4961,7 +5267,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4961
5267
  COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
4962
5268
  body,
4963
5269
  idempotencyKey
4964
- )
5270
+ ),
5271
+ "toss"
4965
5272
  );
4966
5273
  }
4967
5274
  };
@@ -4982,6 +5289,15 @@ var CustomPaymentSessionApi = class extends BaseApi {
4982
5289
  );
4983
5290
  return validateCustomPaymentSession(result);
4984
5291
  }
5292
+ async retrieve(params) {
5293
+ const result = await this.requestEndpoint(
5294
+ COMMERCE_ENDPOINTS.paymentSessions.custom.retrieve,
5295
+ params
5296
+ );
5297
+ return validateRetrievedCustomPaymentSession(
5298
+ result
5299
+ );
5300
+ }
4985
5301
  async confirm(params, options = {}) {
4986
5302
  const body = {
4987
5303
  provider: params.provider,
@@ -5129,11 +5445,17 @@ var ServerCommerceClient = class {
5129
5445
  };
5130
5446
  this.paymentSessions = {
5131
5447
  create: paymentSessionApi.create.bind(paymentSessionApi),
5448
+ createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
5132
5449
  retrieve: (params) => paymentSessionApi.retrieve(params),
5450
+ retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
5133
5451
  cancel: (params) => paymentSessionApi.cancel(params),
5452
+ cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params),
5134
5453
  confirm: paymentSessionApi.confirm.bind(paymentSessionApi),
5135
5454
  custom: {
5136
5455
  create: customPaymentSessionApi.create.bind(customPaymentSessionApi),
5456
+ retrieve: customPaymentSessionApi.retrieve.bind(
5457
+ customPaymentSessionApi
5458
+ ),
5137
5459
  confirm: customPaymentSessionApi.confirm.bind(customPaymentSessionApi)
5138
5460
  }
5139
5461
  };