@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.cjs CHANGED
@@ -74,34 +74,78 @@ var SDKError = class extends Error {
74
74
  };
75
75
  var COMMERCE_ERROR_CODES = [
76
76
  "validation_failed",
77
+ "bad_request",
77
78
  "unauthorized",
78
79
  "forbidden",
80
+ "account_suspended",
81
+ "key_invalid",
82
+ "pat_tenant_header_forbidden",
83
+ "tenant_mismatch",
84
+ "test_tenant_expired",
85
+ "token_invalid",
79
86
  "token_expired",
80
87
  "origin_not_allowed",
81
88
  "server_credentials_required",
89
+ "role_denied",
90
+ "scope_denied",
91
+ "feature_disabled",
82
92
  "not_found",
83
93
  "conflict",
94
+ "locked",
84
95
  "cart_revision_conflict",
85
96
  "rate_limit_exceeded",
86
97
  "usage_limit_exceeded",
87
98
  "service_unavailable",
88
99
  "idempotency_conflict",
89
100
  "idempotency_in_progress",
101
+ "idempotency_key_required",
102
+ "invalid_idempotency_key",
90
103
  "cart_not_active",
91
104
  "cart_locked",
92
105
  "cart_empty",
93
106
  "cart_market_unavailable",
94
107
  "cart_market_mismatch",
95
108
  "checkout_not_open",
109
+ "checkout_already_open",
96
110
  "payment_slot_held",
97
111
  "reservation_expired",
98
112
  "payment_session_not_cancelable",
113
+ "payment_session_conflict",
99
114
  "provider_identity_mismatch",
115
+ "payment_method_unavailable",
100
116
  "provider_unavailable",
101
117
  "lock_timeout",
102
118
  "price_changed",
103
119
  "pricing_fact_in_use",
104
120
  "insufficient_stock",
121
+ "reservation_conflict",
122
+ "stock_lock_unavailable",
123
+ "variant_not_found",
124
+ "variant_stock_write_failed",
125
+ "stock_invariant_violation",
126
+ "payment_confirmation_in_flight",
127
+ "checkout_reservation_release_requires_transaction",
128
+ "admission_metadata_invalid",
129
+ "admission_metadata_required",
130
+ "capacity_exceeded",
131
+ "occurrence_lock_unavailable",
132
+ "occurrence_not_open",
133
+ "admission_type_capacity_exceeded",
134
+ "admission_type_occurrence_mismatch",
135
+ "admission_hold_expired",
136
+ "admission_hold_checkout_item_conflict",
137
+ "admission_hold_checkout_conflict",
138
+ "admission_hold_quantity_mismatch",
139
+ "admission_hold_unbound",
140
+ "admission_hold_missing",
141
+ "admission_hold_checkout_item_missing",
142
+ "admission_hold_expiry_failed",
143
+ "admission_hold_expiry_requires_transaction",
144
+ "admission_hold_line_item_mismatch",
145
+ "admission_materialization_failed",
146
+ "variant_inactive",
147
+ "variant_product_mismatch",
148
+ "product_not_public",
105
149
  "market_not_found",
106
150
  "market_shipping_currency_unsupported",
107
151
  "missing_market_rate",
@@ -126,7 +170,11 @@ var COMMERCE_ERROR_CODES = [
126
170
  "discount_min_order_amount",
127
171
  "discount_currency_scope_required",
128
172
  "discount_allocation_method_unsupported",
129
- "currency_mismatch"
173
+ "currency_mismatch",
174
+ "customer_token_required",
175
+ "market_required",
176
+ "server_derived",
177
+ "internal_error"
130
178
  ];
131
179
  var COMMERCE_ERROR_CODE_SET = new Set(
132
180
  COMMERCE_ERROR_CODES
@@ -152,6 +200,12 @@ function commerceProtocolError(issue, trustedRequestId) {
152
200
  );
153
201
  }
154
202
  function parseCommerceErrorEnvelope(body, headerRequestId) {
203
+ if (headerRequestId === void 0) {
204
+ throw commerceProtocolError("missing_request_id_header");
205
+ }
206
+ if (headerRequestId.length === 0) {
207
+ throw commerceProtocolError("empty_request_id_header");
208
+ }
155
209
  if (!isPlainRecord(body)) {
156
210
  throw commerceProtocolError("expected_object", headerRequestId);
157
211
  }
@@ -161,7 +215,7 @@ function parseCommerceErrorEnvelope(body, headerRequestId) {
161
215
  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
216
  throw commerceProtocolError("invalid_field", headerRequestId);
163
217
  }
164
- if (headerRequestId && headerRequestId !== body.requestId) {
218
+ if (headerRequestId !== void 0 && headerRequestId !== body.requestId) {
165
219
  throw commerceProtocolError("request_id_mismatch", headerRequestId);
166
220
  }
167
221
  return {
@@ -1413,7 +1467,10 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1413
1467
  return parsed;
1414
1468
  }
1415
1469
  const data = parsed;
1416
- if (data.error) {
1470
+ const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
1471
+ (key) => Object.prototype.hasOwnProperty.call(data, key)
1472
+ );
1473
+ if (data.error || hasCommerceEnvelopeSignal) {
1417
1474
  const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
1418
1475
  const reason = typeof data.reason === "string" ? data.reason : void 0;
1419
1476
  const requestId = response.headers.get("x-request-id") ?? void 0;
@@ -1449,12 +1506,14 @@ async function parseApiResponse(response, endpoint2, options = {}) {
1449
1506
 
1450
1507
  // ../../internal/http-contracts/src/index.ts
1451
1508
  var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
1452
- var operation = (collection, method, path) => Object.freeze({
1509
+ var operation = (collection, method, path, errorFamily) => Object.freeze({
1453
1510
  [operationBrand]: true,
1454
1511
  collection,
1455
1512
  method,
1456
- path
1513
+ path,
1514
+ ...errorFamily && { errorFamily }
1457
1515
  });
1516
+ var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
1458
1517
  var COMMERCE_ENDPOINT_OPERATIONS = {
1459
1518
  products: {
1460
1519
  detail: operation("products", "get", "/detail"),
@@ -1487,13 +1546,13 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1487
1546
  byPayment: operation("orders", "get", "/by-payment"),
1488
1547
  cancel: operation("orders", "post", "/cancel"),
1489
1548
  resolveCancelRefund: operation("orders", "post", "/resolve-cancel-refund"),
1490
- checkout: operation("orders", "post", "/checkout"),
1549
+ checkout: strictCommerceOperation("orders", "post", "/checkout"),
1491
1550
  createFulfillment: operation("orders", "post", "/create-fulfillment"),
1492
1551
  updateFulfillment: operation("orders", "post", "/update-fulfillment")
1493
1552
  },
1494
1553
  checkouts: {
1495
- detail: operation("checkouts", "post", "/detail"),
1496
- query: operation("checkouts", "post", "/query")
1554
+ detail: strictCommerceOperation("checkouts", "post", "/detail"),
1555
+ query: strictCommerceOperation("checkouts", "post", "/query")
1497
1556
  },
1498
1557
  transactions: {
1499
1558
  update: operation("transactions", "post", "/update")
@@ -1514,29 +1573,58 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
1514
1573
  bulkImport: operation("fulfillments", "post", "/bulk-import")
1515
1574
  },
1516
1575
  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")
1576
+ create: strictCommerceOperation("carts", "post", "/create"),
1577
+ retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
1578
+ mine: strictCommerceOperation("carts", "post", "/mine"),
1579
+ merge: strictCommerceOperation("carts", "post", "/merge"),
1580
+ addItem: strictCommerceOperation("carts", "post", "/add-item"),
1581
+ updateItem: strictCommerceOperation("carts", "post", "/update-item"),
1582
+ removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
1583
+ updateDiscountCodes: strictCommerceOperation(
1584
+ "carts",
1585
+ "post",
1586
+ "/update-discount-codes"
1587
+ ),
1588
+ updateAttributes: strictCommerceOperation(
1589
+ "carts",
1590
+ "post",
1591
+ "/update-attributes"
1592
+ ),
1593
+ clear: strictCommerceOperation("carts", "post", "/clear")
1527
1594
  },
1528
1595
  paymentSessions: {
1529
- create: operation("payment-sessions", "post", "/create"),
1530
- retrieve: operation("payment-sessions", "post", "/retrieve"),
1531
- cancel: operation("payment-sessions", "post", "/cancel"),
1596
+ create: strictCommerceOperation("payment-sessions", "post", "/create"),
1597
+ retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
1598
+ cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
1532
1599
  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")
1600
+ create: strictCommerceOperation(
1601
+ "payment-sessions",
1602
+ "post",
1603
+ "/server/create"
1604
+ ),
1605
+ retrieve: strictCommerceOperation(
1606
+ "payment-sessions",
1607
+ "post",
1608
+ "/server/retrieve"
1609
+ ),
1610
+ cancel: strictCommerceOperation(
1611
+ "payment-sessions",
1612
+ "post",
1613
+ "/server/cancel"
1614
+ ),
1615
+ confirm: strictCommerceOperation(
1616
+ "payment-sessions",
1617
+ "post",
1618
+ "/server/confirm"
1619
+ )
1537
1620
  },
1538
1621
  custom: {
1539
1622
  create: operation("orders", "post", "/custom-payment-sessions"),
1623
+ retrieve: operation(
1624
+ "orders",
1625
+ "post",
1626
+ "/custom-payment-sessions/retrieve"
1627
+ ),
1540
1628
  confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
1541
1629
  }
1542
1630
  },
@@ -1562,6 +1650,11 @@ var EVENTS_ENDPOINT_OPERATIONS = {
1562
1650
  )
1563
1651
  }
1564
1652
  };
1653
+ var COMMUNITY_ENDPOINT_OPERATIONS = {
1654
+ posts: {
1655
+ detail: operation("posts", "get", "/detail")
1656
+ }
1657
+ };
1565
1658
  function resolveOperationTemplate(descriptor) {
1566
1659
  return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
1567
1660
  }
@@ -1593,6 +1686,9 @@ var sharedEndpoint = (descriptor) => descriptor;
1593
1686
  function resolveOperationMethod2(descriptor) {
1594
1687
  return "collection" in descriptor ? resolveOperationMethod(descriptor) : descriptor.method;
1595
1688
  }
1689
+ function resolveOperationErrorFamily(descriptor) {
1690
+ return "collection" in descriptor ? descriptor.errorFamily : void 0;
1691
+ }
1596
1692
  function resolveOperationPath2(descriptor, options) {
1597
1693
  if ("collection" in descriptor) {
1598
1694
  return resolveOperationPath(descriptor, options);
@@ -1627,12 +1723,12 @@ var COMMERCE_ENDPOINTS = {
1627
1723
  updateFulfillment: endpoint("POST", "/api/orders/update-fulfillment")
1628
1724
  },
1629
1725
  checkouts: {
1630
- create: endpoint("POST", "/api/orders/checkout"),
1631
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1726
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1727
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1632
1728
  server: {
1633
- create: endpoint("POST", "/api/orders/checkout"),
1634
- retrieve: endpoint("POST", "/api/checkouts/detail"),
1635
- query: endpoint("POST", "/api/checkouts/query")
1729
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
1730
+ retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
1731
+ query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
1636
1732
  }
1637
1733
  },
1638
1734
  returns: {
@@ -1650,10 +1746,10 @@ var COMMERCE_ENDPOINTS = {
1650
1746
  bulkImport: endpoint("POST", "/api/fulfillments/bulk-import")
1651
1747
  },
1652
1748
  carts: {
1653
- create: endpoint("POST", "/api/carts/create"),
1749
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
1654
1750
  retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
1655
- mine: endpoint("POST", "/api/carts/mine"),
1656
- merge: endpoint("POST", "/api/carts/merge"),
1751
+ mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
1752
+ merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
1657
1753
  server: {
1658
1754
  // Server credentials are an authorization lane, not a second Cart
1659
1755
  // transport. These must stay bound to the registered shared operations.
@@ -1673,29 +1769,46 @@ var COMMERCE_ENDPOINTS = {
1673
1769
  clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1674
1770
  },
1675
1771
  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")
1772
+ updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
1773
+ removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
1774
+ updateDiscountCodes: sharedEndpoint(
1775
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
1776
+ ),
1777
+ updateAttributes: sharedEndpoint(
1778
+ COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
1779
+ ),
1780
+ clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
1681
1781
  },
1682
1782
  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"),
1783
+ create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
1784
+ retrieve: sharedEndpoint(
1785
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
1786
+ ),
1787
+ cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
1686
1788
  custom: {
1687
1789
  create: sharedEndpoint(
1688
1790
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
1689
1791
  ),
1792
+ retrieve: sharedEndpoint(
1793
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
1794
+ ),
1690
1795
  confirm: sharedEndpoint(
1691
1796
  COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
1692
1797
  )
1693
1798
  },
1694
1799
  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")
1800
+ create: sharedEndpoint(
1801
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
1802
+ ),
1803
+ retrieve: sharedEndpoint(
1804
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
1805
+ ),
1806
+ cancel: sharedEndpoint(
1807
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
1808
+ ),
1809
+ confirm: sharedEndpoint(
1810
+ COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
1811
+ )
1699
1812
  }
1700
1813
  },
1701
1814
  shippingPolicies: {
@@ -1786,7 +1899,8 @@ var CustomerScopedApi = class {
1786
1899
  return this.transport.request(resolveOperationPath2(endpoint2, options), {
1787
1900
  method: resolveOperationMethod2(endpoint2),
1788
1901
  body,
1789
- headers: options?.headers
1902
+ headers: options?.headers,
1903
+ errorFamily: resolveOperationErrorFamily(endpoint2)
1790
1904
  });
1791
1905
  }
1792
1906
  };
@@ -1808,15 +1922,39 @@ function unwrapPayloadDoc(value) {
1808
1922
  }
1809
1923
  return value;
1810
1924
  }
1925
+ function hasCanonicalNotFoundReason(error) {
1926
+ const details = error.details;
1927
+ if (typeof details !== "object" || details === null) return false;
1928
+ if ("reason" in details && details.reason === "not_found") return true;
1929
+ if (!("body" in details) || typeof details.body !== "object" || details.body === null) {
1930
+ return false;
1931
+ }
1932
+ return "reason" in details.body && details.body.reason === "not_found";
1933
+ }
1811
1934
  var CommunityClient = class extends RawCustomerScopedApi {
1812
1935
  constructor(options) {
1813
1936
  super("CommunityClient", { ...options, requiresCredential: false });
1937
+ this.requiresSafePublicRawReads = !options.secretKey;
1814
1938
  }
1815
1939
  buildQuery(params) {
1816
1940
  if (!params) return "";
1817
1941
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
1818
1942
  return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
1819
1943
  }
1944
+ withSafePublicRawReadQuery(query) {
1945
+ if (!this.requiresSafePublicRawReads) return query;
1946
+ if (!query) return "?depth=0&joins=false";
1947
+ return `?depth=0&joins=false&${query.slice(1)}`;
1948
+ }
1949
+ buildSafePublicRawListQuery(params) {
1950
+ if (!this.requiresSafePublicRawReads) {
1951
+ return this.buildQuery(params);
1952
+ }
1953
+ const queryParams = {};
1954
+ if (params?.page !== void 0) queryParams.page = params.page;
1955
+ if (params?.limit !== void 0) queryParams.limit = params.limit;
1956
+ return this.withSafePublicRawReadQuery(this.buildQuery(queryParams));
1957
+ }
1820
1958
  buildPostsListQuery(params) {
1821
1959
  const urlParams = new URLSearchParams();
1822
1960
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
@@ -1876,15 +2014,35 @@ var CommunityClient = class extends RawCustomerScopedApi {
1876
2014
  "GET"
1877
2015
  );
1878
2016
  }
2017
+ /**
2018
+ * Public post detail projected by the same allowlist as the public feed.
2019
+ * Missing, hidden, and cross-tenant posts all resolve to `null`.
2020
+ */
2021
+ async getPost(params) {
2022
+ const query = new URLSearchParams({ postId: params.postId });
2023
+ try {
2024
+ return await this.execute(
2025
+ resolveOperationPath(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail, {
2026
+ query
2027
+ }),
2028
+ resolveOperationMethod(COMMUNITY_ENDPOINT_OPERATIONS.posts.detail)
2029
+ );
2030
+ } catch (error) {
2031
+ if (error instanceof NotFoundError && hasCanonicalNotFoundReason(error)) {
2032
+ return null;
2033
+ }
2034
+ throw error;
2035
+ }
2036
+ }
1879
2037
  listPostCategories(params) {
1880
2038
  return this.execute(
1881
- `/api/post-categories${this.buildQuery(params)}`,
2039
+ `/api/post-categories${this.buildSafePublicRawListQuery(params)}`,
1882
2040
  "GET"
1883
2041
  );
1884
2042
  }
1885
2043
  listPostTags(params) {
1886
2044
  return this.execute(
1887
- `/api/post-tags${this.buildQuery(params)}`,
2045
+ `/api/post-tags${this.buildSafePublicRawListQuery(params)}`,
1888
2046
  "GET"
1889
2047
  );
1890
2048
  }
@@ -2050,7 +2208,7 @@ var CommunityClient = class extends RawCustomerScopedApi {
2050
2208
  }
2051
2209
  getReactionTypes() {
2052
2210
  return this.execute(
2053
- "/api/reaction-types?limit=100",
2211
+ `/api/reaction-types${this.buildSafePublicRawListQuery({ limit: 100 })}`,
2054
2212
  "GET"
2055
2213
  );
2056
2214
  }
@@ -2078,11 +2236,17 @@ var CommunityClient = class extends RawCustomerScopedApi {
2078
2236
  }
2079
2237
  // Profiles
2080
2238
  listProfileLists(params) {
2081
- return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
2239
+ return this.execute(
2240
+ `/api/customer-profile-lists${this.buildSafePublicRawListQuery(params)}`,
2241
+ "GET"
2242
+ );
2082
2243
  }
2083
2244
  async getProfileList(params) {
2084
2245
  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");
2246
+ const res = await this.execute(
2247
+ `/api/customer-profile-lists${this.withSafePublicRawReadQuery(query)}`,
2248
+ "GET"
2249
+ );
2086
2250
  return res.docs[0] ?? null;
2087
2251
  }
2088
2252
  updatePublicProfile(body) {
@@ -2142,7 +2306,8 @@ var BaseApi = class {
2142
2306
  body,
2143
2307
  {
2144
2308
  method: resolveOperationMethod2(endpoint2),
2145
- headers: options?.headers
2309
+ headers: options?.headers,
2310
+ errorFamily: resolveOperationErrorFamily(endpoint2)
2146
2311
  }
2147
2312
  );
2148
2313
  }
@@ -2199,7 +2364,7 @@ var MAX_COMMERCE_CAPABILITY_LENGTH = 512;
2199
2364
  var MAX_CART_DISCOUNT_CODE_LENGTH = 128;
2200
2365
  var CHECKOUT_STATUSES = ["open", "placed", "abandoned"];
2201
2366
  var ABANDONED_REASONS = ["expired", "customer", "operator"];
2202
- var PAYMENT_PROVIDERS = ["toss"];
2367
+ var PAYMENT_PROVIDERS = ["toss", "portone"];
2203
2368
  var PAYMENT_PROVIDER_STATUSES = [
2204
2369
  "requires_payment_method",
2205
2370
  "requires_action",
@@ -2282,6 +2447,21 @@ function nullableString(value, resource, path) {
2282
2447
  fail(resource, path, "string or null");
2283
2448
  }
2284
2449
  }
2450
+ function nonBlankString(value, resource, path) {
2451
+ const parsed = string(value, resource, path);
2452
+ if (parsed.trim().length === 0) {
2453
+ fail(resource, path, "non-blank string");
2454
+ }
2455
+ return parsed;
2456
+ }
2457
+ function nullableNonBlankString(value, resource, path) {
2458
+ if (value !== null) nonBlankString(value, resource, path);
2459
+ }
2460
+ function nullableResourceId(value, resource, path) {
2461
+ if (value !== null) {
2462
+ boundedString(value, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, path);
2463
+ }
2464
+ }
2285
2465
  function cartLineQuantity(value, resource, path) {
2286
2466
  const quantity = positiveInteger(value, resource, path);
2287
2467
  if (quantity > MAX_CART_LINE_QUANTITY) {
@@ -3103,6 +3283,59 @@ function validateCustomPaymentSession(value) {
3103
3283
  validateMoney(session.money, resource, "$.money");
3104
3284
  return value;
3105
3285
  }
3286
+ function validateRetrievedCustomPaymentSession(value) {
3287
+ const resource = "retrieved custom PaymentSession";
3288
+ const session = record(value, resource, "$");
3289
+ exact(
3290
+ session,
3291
+ [
3292
+ "id",
3293
+ "provider",
3294
+ "providerSessionId",
3295
+ "providerPaymentId",
3296
+ "status",
3297
+ "providerStatus",
3298
+ "finalizationStatus",
3299
+ "money",
3300
+ "orderId"
3301
+ ],
3302
+ [],
3303
+ resource,
3304
+ "$"
3305
+ );
3306
+ boundedString(session.id, MAX_COMMERCE_RESOURCE_ID_LENGTH, resource, "$.id");
3307
+ const provider = string(session.provider, resource, "$.provider");
3308
+ if (!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(provider)) {
3309
+ fail(resource, "$.provider", "provider slug");
3310
+ }
3311
+ nonBlankString(session.providerSessionId, resource, "$.providerSessionId");
3312
+ nullableNonBlankString(
3313
+ session.providerPaymentId,
3314
+ resource,
3315
+ "$.providerPaymentId"
3316
+ );
3317
+ enumValue(
3318
+ session.status,
3319
+ ["pending", "captured", "failed", "canceled"],
3320
+ resource,
3321
+ "$.status"
3322
+ );
3323
+ enumValue(
3324
+ session.providerStatus,
3325
+ PAYMENT_PROVIDER_STATUSES,
3326
+ resource,
3327
+ "$.providerStatus"
3328
+ );
3329
+ enumValue(
3330
+ session.finalizationStatus,
3331
+ ["not_ready", "pending", "committed"],
3332
+ resource,
3333
+ "$.finalizationStatus"
3334
+ );
3335
+ validateMoney(session.money, resource, "$.money");
3336
+ nullableResourceId(session.orderId, resource, "$.orderId");
3337
+ return value;
3338
+ }
3106
3339
  function validateConfirmCustomPaymentSessionResponse(value) {
3107
3340
  const resource = "custom PaymentSession confirmation";
3108
3341
  const result = record(value, resource, "$");
@@ -3153,8 +3386,33 @@ function validateRequiredReconciliation(value, allowed, resource, path) {
3153
3386
  previous = current;
3154
3387
  });
3155
3388
  }
3156
- function validateNextAction(value, resource, path) {
3389
+ function validateNextAction(value, provider, resource, path) {
3157
3390
  const action = record(value, resource, path);
3391
+ if (provider === "portone") {
3392
+ exact(action, ["type", "checkoutUrl"], [], resource, path);
3393
+ if (action.type !== "portone_checkout") {
3394
+ fail(resource, `${path}.type`, "portone_checkout");
3395
+ }
3396
+ const checkoutUrl = boundedString(
3397
+ action.checkoutUrl,
3398
+ 2048,
3399
+ resource,
3400
+ `${path}.checkoutUrl`
3401
+ );
3402
+ try {
3403
+ const parsed = new URL(checkoutUrl);
3404
+ if (parsed.protocol !== "https:" || parsed.username !== "" || parsed.password !== "") {
3405
+ throw new Error("unsafe checkout URL");
3406
+ }
3407
+ } catch {
3408
+ fail(
3409
+ resource,
3410
+ `${path}.checkoutUrl`,
3411
+ "absolute HTTPS URL without embedded credentials"
3412
+ );
3413
+ }
3414
+ return;
3415
+ }
3158
3416
  exact(
3159
3417
  action,
3160
3418
  [
@@ -3205,10 +3463,18 @@ function validateNextAction(value, resource, path) {
3205
3463
  if (action.customerEmail !== void 0)
3206
3464
  validateCustomer({ email: action.customerEmail }, resource, path);
3207
3465
  }
3208
- function validatePublicPaymentSession(value) {
3466
+ function validatePublicPaymentSession(value, expectedProvider) {
3209
3467
  const resource = "PaymentSession";
3210
3468
  const session = record(value, resource, "$");
3211
- enumValue(session.provider, PAYMENT_PROVIDERS, resource, "$.provider");
3469
+ const provider = enumValue(
3470
+ session.provider,
3471
+ PAYMENT_PROVIDERS,
3472
+ resource,
3473
+ "$.provider"
3474
+ );
3475
+ if (expectedProvider !== void 0 && provider !== expectedProvider) {
3476
+ fail(resource, "$.provider", expectedProvider);
3477
+ }
3212
3478
  const status = enumValue(
3213
3479
  session.providerStatus,
3214
3480
  PAYMENT_PROVIDER_STATUSES,
@@ -3245,7 +3511,12 @@ function validatePublicPaymentSession(value) {
3245
3511
  }
3246
3512
  if (!("nextAction" in session))
3247
3513
  fail(resource, "$.nextAction", "required field");
3248
- validateNextAction(session.nextAction, resource, "$.nextAction");
3514
+ validateNextAction(
3515
+ session.nextAction,
3516
+ provider,
3517
+ resource,
3518
+ "$.nextAction"
3519
+ );
3249
3520
  } else if (session.sessionRole === "residual") {
3250
3521
  if (session.presentationStatus !== "suppressed" || session.finalizationStatus !== "not_ready") {
3251
3522
  fail(resource, "$", "suppressed residual not-ready state");
@@ -4964,8 +5235,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4964
5235
  }
4965
5236
  });
4966
5237
  }
4967
- async paymentSession(result) {
4968
- return validatePublicPaymentSession(await result);
5238
+ async paymentSession(result, expectedProvider) {
5239
+ return validatePublicPaymentSession(await result, expectedProvider);
4969
5240
  }
4970
5241
  create(params) {
4971
5242
  const { idempotencyKey, ...body } = params;
@@ -4975,18 +5246,53 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4975
5246
  this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
4976
5247
  body,
4977
5248
  idempotencyKey
4978
- )
5249
+ ),
5250
+ "toss"
5251
+ );
5252
+ }
5253
+ createPortOne(params) {
5254
+ const { idempotencyKey, ...body } = params;
5255
+ assertCommerceIdempotencyKey(idempotencyKey);
5256
+ return this.paymentSession(
5257
+ this.post(
5258
+ this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.create : COMMERCE_ENDPOINTS.paymentSessions.create,
5259
+ body,
5260
+ idempotencyKey
5261
+ ),
5262
+ "portone"
4979
5263
  );
4980
5264
  }
4981
5265
  retrieve(params) {
4982
5266
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
4983
- return this.paymentSession(this.post(endpoint2, params));
5267
+ return this.paymentSession(
5268
+ this.post(endpoint2, params),
5269
+ "toss"
5270
+ );
5271
+ }
5272
+ retrievePortOne(params) {
5273
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.retrieve : COMMERCE_ENDPOINTS.paymentSessions.retrieve;
5274
+ return this.paymentSession(
5275
+ this.post(endpoint2, params),
5276
+ "portone"
5277
+ );
4984
5278
  }
4985
5279
  cancel(params) {
4986
5280
  const { idempotencyKey, ...body } = params;
4987
5281
  assertCommerceIdempotencyKey(idempotencyKey);
4988
5282
  const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
4989
- return this.paymentSession(this.post(endpoint2, body, idempotencyKey));
5283
+ return this.paymentSession(
5284
+ this.post(endpoint2, body, idempotencyKey),
5285
+ "toss"
5286
+ );
5287
+ }
5288
+ cancelPortOne(params) {
5289
+ const { idempotencyKey, ...body } = params;
5290
+ assertCommerceIdempotencyKey(idempotencyKey);
5291
+ const endpoint2 = this.serverTransport ? COMMERCE_ENDPOINTS.paymentSessions.server.cancel : COMMERCE_ENDPOINTS.paymentSessions.cancel;
5292
+ return this.paymentSession(
5293
+ this.post(endpoint2, body, idempotencyKey),
5294
+ "portone"
5295
+ );
4990
5296
  }
4991
5297
  confirm(params) {
4992
5298
  const { idempotencyKey, ...body } = params;
@@ -4996,7 +5302,8 @@ var PaymentSessionApi = class extends CustomerScopedApi {
4996
5302
  COMMERCE_ENDPOINTS.paymentSessions.server.confirm,
4997
5303
  body,
4998
5304
  idempotencyKey
4999
- )
5305
+ ),
5306
+ "toss"
5000
5307
  );
5001
5308
  }
5002
5309
  };
@@ -5017,6 +5324,15 @@ var CustomPaymentSessionApi = class extends BaseApi {
5017
5324
  );
5018
5325
  return validateCustomPaymentSession(result);
5019
5326
  }
5327
+ async retrieve(params) {
5328
+ const result = await this.requestEndpoint(
5329
+ COMMERCE_ENDPOINTS.paymentSessions.custom.retrieve,
5330
+ params
5331
+ );
5332
+ return validateRetrievedCustomPaymentSession(
5333
+ result
5334
+ );
5335
+ }
5020
5336
  async confirm(params, options = {}) {
5021
5337
  const body = {
5022
5338
  provider: params.provider,
@@ -5164,11 +5480,17 @@ var ServerCommerceClient = class {
5164
5480
  };
5165
5481
  this.paymentSessions = {
5166
5482
  create: paymentSessionApi.create.bind(paymentSessionApi),
5483
+ createPortOne: paymentSessionApi.createPortOne.bind(paymentSessionApi),
5167
5484
  retrieve: (params) => paymentSessionApi.retrieve(params),
5485
+ retrievePortOne: (params) => paymentSessionApi.retrievePortOne(params),
5168
5486
  cancel: (params) => paymentSessionApi.cancel(params),
5487
+ cancelPortOne: (params) => paymentSessionApi.cancelPortOne(params),
5169
5488
  confirm: paymentSessionApi.confirm.bind(paymentSessionApi),
5170
5489
  custom: {
5171
5490
  create: customPaymentSessionApi.create.bind(customPaymentSessionApi),
5491
+ retrieve: customPaymentSessionApi.retrieve.bind(
5492
+ customPaymentSessionApi
5493
+ ),
5172
5494
  confirm: customPaymentSessionApi.confirm.bind(customPaymentSessionApi)
5173
5495
  }
5174
5496
  };