@01.software/sdk 0.41.1 → 0.43.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 (69) hide show
  1. package/CHANGELOG.md +246 -0
  2. package/README.md +88 -19
  3. package/dist/analytics/react.cjs +71 -3
  4. package/dist/analytics/react.cjs.map +1 -1
  5. package/dist/analytics/react.d.cts +18 -2
  6. package/dist/analytics/react.d.ts +18 -2
  7. package/dist/analytics/react.js +67 -3
  8. package/dist/analytics/react.js.map +1 -1
  9. package/dist/analytics.cjs +6 -2
  10. package/dist/analytics.cjs.map +1 -1
  11. package/dist/analytics.d.cts +17 -4
  12. package/dist/analytics.d.ts +17 -4
  13. package/dist/analytics.js +6 -2
  14. package/dist/analytics.js.map +1 -1
  15. package/dist/client.cjs +233 -47
  16. package/dist/client.cjs.map +1 -1
  17. package/dist/client.d.cts +9 -6
  18. package/dist/client.d.ts +9 -6
  19. package/dist/client.js +233 -47
  20. package/dist/client.js.map +1 -1
  21. package/dist/{collection-client-Bk--pNzW.d.cts → collection-client-U70KizLf.d.cts} +3 -3
  22. package/dist/{collection-client-BdcxkW7l.d.ts → collection-client-gWsA7BVP.d.ts} +3 -3
  23. package/dist/{const-qGGI7Uii.d.cts → const-BBynifk0.d.cts} +5 -5
  24. package/dist/{const-HwdntWtG.d.ts → const-_WWHU-gX.d.ts} +5 -5
  25. package/dist/{index-B1oW50RY.d.ts → index-DPi5NWU8.d.ts} +4 -4
  26. package/dist/{index-DiXtjVab.d.cts → index-Dg4Y6Aq7.d.cts} +4 -4
  27. package/dist/index.cjs +225 -358
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +41 -8
  30. package/dist/index.d.ts +41 -8
  31. package/dist/index.js +225 -358
  32. package/dist/index.js.map +1 -1
  33. package/dist/{payload-types-CqJOgON7.d.cts → payload-types-DLxkB7Mv.d.cts} +561 -123
  34. package/dist/{payload-types-CqJOgON7.d.ts → payload-types-DLxkB7Mv.d.ts} +561 -123
  35. package/dist/query.cjs +59 -7
  36. package/dist/query.cjs.map +1 -1
  37. package/dist/query.d.cts +5 -5
  38. package/dist/query.d.ts +5 -5
  39. package/dist/query.js +59 -7
  40. package/dist/query.js.map +1 -1
  41. package/dist/realtime.cjs +1 -1
  42. package/dist/realtime.cjs.map +1 -1
  43. package/dist/realtime.d.cts +2 -2
  44. package/dist/realtime.d.ts +2 -2
  45. package/dist/realtime.js +1 -1
  46. package/dist/realtime.js.map +1 -1
  47. package/dist/server.cjs +318 -61
  48. package/dist/server.cjs.map +1 -1
  49. package/dist/server.d.cts +12 -7
  50. package/dist/server.d.ts +12 -7
  51. package/dist/server.js +318 -61
  52. package/dist/server.js.map +1 -1
  53. package/dist/{types-ByLSG-O3.d.cts → types-B1ngKbWI.d.cts} +1 -1
  54. package/dist/{types-BKa9z9s2.d.cts → types-B9lGhZlB.d.ts} +229 -15
  55. package/dist/{types-BMI3M0nb.d.ts → types-BiKNBwRA.d.ts} +1 -1
  56. package/dist/{types-DgfXb7iV.d.ts → types-Bpx5sYKo.d.cts} +229 -15
  57. package/dist/ui/canvas.cjs.map +1 -1
  58. package/dist/ui/canvas.js.map +1 -1
  59. package/dist/ui/form.d.cts +1 -1
  60. package/dist/ui/form.d.ts +1 -1
  61. package/dist/ui/video.d.cts +1 -1
  62. package/dist/ui/video.d.ts +1 -1
  63. package/dist/webhook.cjs +3 -1
  64. package/dist/webhook.cjs.map +1 -1
  65. package/dist/webhook.d.cts +4 -4
  66. package/dist/webhook.d.ts +4 -4
  67. package/dist/webhook.js +3 -1
  68. package/dist/webhook.js.map +1 -1
  69. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -216,6 +216,14 @@ var createValidationError = (message, details, userMessage, suggestion, status)
216
216
  var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
217
217
  var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
218
218
  var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
219
+ var createGoneError = (message, details, userMessage, suggestion) => new GoneError(message, details, userMessage, suggestion);
220
+ var createServiceUnavailableError = (message, retryAfter, details, userMessage, suggestion) => new ServiceUnavailableError(
221
+ message,
222
+ retryAfter,
223
+ details,
224
+ userMessage,
225
+ suggestion
226
+ );
219
227
  var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
220
228
  var createAuthError = (message, details, userMessage, suggestion, requestId) => new AuthError(message, details, userMessage, suggestion, requestId);
221
229
  var createPermissionError = (message, details, userMessage, suggestion, requestId) => new PermissionError(message, details, userMessage, suggestion, requestId);
@@ -240,7 +248,7 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
240
248
  return publishableKey ?? "";
241
249
  }
242
250
 
243
- // src/core/client/types.ts
251
+ // src/core/internal/utils/api-url.ts
244
252
  function resolveApiUrl(apiUrl) {
245
253
  if (apiUrl) {
246
254
  return apiUrl.replace(/\/$/, "");
@@ -257,7 +265,7 @@ function resolveApiUrl(apiUrl) {
257
265
  // src/core/internal/utils/http.ts
258
266
  var DEFAULT_TIMEOUT = 3e4;
259
267
  var STOREFRONT_BROWSER_TIMEOUT = 15e3;
260
- var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
268
+ var DEFAULT_RETRYABLE_STATUSES = [408, 500, 502, 503, 504];
261
269
  var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
262
270
  var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
263
271
  var DEFAULT_MAX_RETRIES = 3;
@@ -374,7 +382,12 @@ function attachRequestId(err, id) {
374
382
  if (id) err.requestId = id;
375
383
  return err;
376
384
  }
377
- function createHttpStatusError(status, parsed, details, requestId) {
385
+ function parseRetryAfter(response) {
386
+ const raw = response.headers.get("Retry-After");
387
+ if (!raw) return void 0;
388
+ return parseInt(raw, 10) || void 0;
389
+ }
390
+ function mapResponseToError(status, parsed, details, requestId, retryAfter) {
378
391
  const errorDetails = {
379
392
  ...details,
380
393
  ...parsed.errors && { errors: parsed.errors },
@@ -437,6 +450,41 @@ function createHttpStatusError(status, parsed, details, requestId) {
437
450
  requestId
438
451
  );
439
452
  }
453
+ if (status === 410) {
454
+ return attachRequestId(
455
+ createGoneError(
456
+ parsed.errorMessage,
457
+ errorDetails,
458
+ parsed.userMessage,
459
+ suggestion
460
+ ),
461
+ requestId
462
+ );
463
+ }
464
+ if (status === 429) {
465
+ return attachRequestId(
466
+ createRateLimitError(
467
+ parsed.errorMessage,
468
+ retryAfter,
469
+ errorDetails,
470
+ parsed.userMessage,
471
+ suggestion
472
+ ),
473
+ requestId
474
+ );
475
+ }
476
+ if (status === 503) {
477
+ return attachRequestId(
478
+ createServiceUnavailableError(
479
+ parsed.errorMessage,
480
+ retryAfter,
481
+ errorDetails,
482
+ parsed.userMessage,
483
+ suggestion
484
+ ),
485
+ requestId
486
+ );
487
+ }
440
488
  return attachRequestId(
441
489
  createNetworkError(
442
490
  parsed.errorMessage,
@@ -555,26 +603,17 @@ async function httpFetch(url, options) {
555
603
  method: requestInit.method || "GET",
556
604
  attempt: attempt + 1
557
605
  };
558
- if (NON_RETRYABLE_STATUSES.includes(response.status)) {
559
- throw createHttpStatusError(
560
- response.status,
561
- parsed,
562
- details,
563
- requestId
564
- );
565
- }
566
- const error = attachRequestId(
567
- createNetworkError(
568
- parsed.errorMessage,
569
- response.status,
570
- details,
571
- parsed.userMessage,
572
- getErrorSuggestion(response.status)
573
- ),
574
- requestId
606
+ const retryAfter = parseRetryAfter(response);
607
+ const error = mapResponseToError(
608
+ response.status,
609
+ parsed,
610
+ details,
611
+ requestId,
612
+ retryAfter
575
613
  );
576
614
  const method2 = (requestInit.method || "GET").toUpperCase();
577
- if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && retryConfig.retryableStatuses.includes(response.status)) {
615
+ const isTerminal = error instanceof RateLimitError || error instanceof UsageLimitError;
616
+ if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && !isTerminal && !NON_RETRYABLE_STATUSES.includes(response.status) && retryConfig.retryableStatuses.includes(response.status)) {
578
617
  lastError = error;
579
618
  const retryDelay = retryConfig.retryDelay(attempt);
580
619
  debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
@@ -646,6 +685,64 @@ async function httpFetch(url, options) {
646
685
  throw lastError ?? new NetworkError("Request failed after retries");
647
686
  }
648
687
 
688
+ // src/core/api/endpoints.ts
689
+ var COMMERCE_ENDPOINTS = {
690
+ orders: {
691
+ create: "/api/orders/create",
692
+ update: "/api/orders/update",
693
+ confirmPayment: "/api/orders/confirm-payment",
694
+ byPayment: "/api/orders/by-payment",
695
+ cancel: "/api/orders/cancel",
696
+ resolveCancelRefund: "/api/orders/resolve-cancel-refund",
697
+ checkout: "/api/orders/checkout",
698
+ createFulfillment: "/api/orders/create-fulfillment",
699
+ updateFulfillment: "/api/orders/update-fulfillment"
700
+ },
701
+ transactions: {
702
+ update: "/api/transactions/update"
703
+ },
704
+ returns: {
705
+ create: "/api/returns/create",
706
+ update: "/api/returns/update",
707
+ returnRefund: "/api/returns/return-refund"
708
+ },
709
+ fulfillmentOrders: {
710
+ prepare: "/api/fulfillment-orders/prepare-fulfillment-order"
711
+ },
712
+ fulfillments: {
713
+ bulkImport: "/api/fulfillments/bulk-import"
714
+ },
715
+ carts: {
716
+ mine: "/api/carts/mine",
717
+ merge: "/api/carts/merge",
718
+ addItem: "/api/carts/add-item",
719
+ updateItem: "/api/carts/update-item",
720
+ removeItem: "/api/carts/remove-item",
721
+ applyDiscount: "/api/carts/apply-discount",
722
+ removeDiscount: "/api/carts/remove-discount",
723
+ clear: "/api/carts/clear"
724
+ },
725
+ products: {
726
+ stockCheck: "/api/products/stock-check",
727
+ stockSnapshot: "/api/products/stock",
728
+ listingGroups: "/api/products/listing-groups",
729
+ listingGroupsCatalog: "/api/products/listing-groups/catalog",
730
+ listingGroupsQuery: "/api/products/listing-groups/query",
731
+ listingGroupsQueryCatalog: "/api/products/listing-groups/query/catalog",
732
+ detail: "/api/products/detail",
733
+ detailCatalog: "/api/products/detail/catalog",
734
+ upsert: "/api/products/upsert"
735
+ }
736
+ };
737
+ var COMMERCE_ENDPOINT_PATHS = Object.values(
738
+ COMMERCE_ENDPOINTS
739
+ ).flatMap((group) => Object.values(group));
740
+ var MEMBERSHIP_ENDPOINTS = {
741
+ subscribe: "/api/memberships/subscribe",
742
+ cancel: (id) => `/api/memberships/${id}/cancel`,
743
+ me: "/api/memberships/me"
744
+ };
745
+
649
746
  // src/core/internal/utils/query-string.ts
650
747
  function productDetailQuery(params) {
651
748
  const search = new URLSearchParams();
@@ -654,7 +751,7 @@ function productDetailQuery(params) {
654
751
  } else {
655
752
  search.set("id", params.id);
656
753
  }
657
- return `/api/products/detail?${search}`;
754
+ return `${COMMERCE_ENDPOINTS.products.detail}?${search}`;
658
755
  }
659
756
  function productDetailCatalogQuery(params) {
660
757
  const search = new URLSearchParams();
@@ -663,23 +760,17 @@ function productDetailCatalogQuery(params) {
663
760
  } else {
664
761
  search.set("id", params.id);
665
762
  }
666
- return `/api/products/detail/catalog?${search}`;
667
- }
668
- function listingGroupsQuery(params) {
669
- return `/api/products/listing-groups?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
763
+ return `${COMMERCE_ENDPOINTS.products.detailCatalog}?${search}`;
670
764
  }
671
765
  function listingGroupsCatalogQuery(params) {
672
- return `/api/products/listing-groups/catalog?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
766
+ return `${COMMERCE_ENDPOINTS.products.listingGroupsCatalog}?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
673
767
  }
674
768
  function appendListingGroupsQuerySearchParams(search, options) {
675
769
  if (options?.page != null) search.set("page", String(options.page));
676
770
  if (options?.limit != null) search.set("limit", String(options.limit));
677
771
  if (options?.sort != null) {
678
772
  const sort = options.sort;
679
- search.set(
680
- "sort",
681
- Array.isArray(sort) ? sort.join(",") : sort
682
- );
773
+ search.set("sort", Array.isArray(sort) ? sort.join(",") : sort);
683
774
  }
684
775
  if (options?.where != null) {
685
776
  search.set("whereJson", JSON.stringify(options.where));
@@ -689,16 +780,16 @@ function listingGroupsQueryUrl(options) {
689
780
  const search = new URLSearchParams();
690
781
  appendListingGroupsQuerySearchParams(search, options);
691
782
  const query = search.toString();
692
- return `/api/products/listing-groups/query${query ? `?${query}` : ""}`;
783
+ return `${COMMERCE_ENDPOINTS.products.listingGroupsQuery}${query ? `?${query}` : ""}`;
693
784
  }
694
785
  function listingGroupsQueryCatalogUrl(options) {
695
786
  const search = new URLSearchParams();
696
787
  appendListingGroupsQuerySearchParams(search, options);
697
788
  const query = search.toString();
698
- return `/api/products/listing-groups/query/catalog${query ? `?${query}` : ""}`;
789
+ return `${COMMERCE_ENDPOINTS.products.listingGroupsQueryCatalog}${query ? `?${query}` : ""}`;
699
790
  }
700
791
  function stockSnapshotQuery(params) {
701
- return `/api/products/stock?variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
792
+ return `${COMMERCE_ENDPOINTS.products.stockSnapshot}?variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
702
793
  }
703
794
 
704
795
  // src/core/collection/http-client.ts
@@ -1597,78 +1688,81 @@ var CustomerNamespace = class {
1597
1688
  // src/core/api/cart-api.ts
1598
1689
  var CartApi = class extends CustomerScopedApi {
1599
1690
  constructor(options) {
1600
- super("CartApi", options);
1691
+ super("CartApi", { ...options, requiresCredential: false });
1601
1692
  }
1602
1693
  async execute(endpoint, method, body) {
1603
1694
  return this.request(endpoint, { method, body });
1604
1695
  }
1605
- getCart(cartId) {
1696
+ /**
1697
+ * Create a cart and receive its `cartToken`. Store the token and pass it to
1698
+ * every subsequent cart operation.
1699
+ */
1700
+ createCart(params = {}) {
1701
+ return this.execute("/api/carts/create", "POST", params);
1702
+ }
1703
+ getCart(cartToken) {
1704
+ return this.execute("/api/carts/get", "POST", { cartToken });
1705
+ }
1706
+ merge(params) {
1606
1707
  return this.execute(
1607
- `/api/carts/${cartId}?depth=0&joins=false`,
1608
- "GET"
1708
+ COMMERCE_ENDPOINTS.carts.merge,
1709
+ "POST",
1710
+ params
1711
+ );
1712
+ }
1713
+ /**
1714
+ * Resolve the authenticated customer's active cart by JWT (no `cartToken`
1715
+ * required). Returns the cart and its capability handle, or both `null` when
1716
+ * the customer has no active cart. Requires a customer token.
1717
+ */
1718
+ mine() {
1719
+ return this.execute(
1720
+ COMMERCE_ENDPOINTS.carts.mine,
1721
+ "POST",
1722
+ {}
1609
1723
  );
1610
1724
  }
1611
1725
  addItem(params) {
1612
- return this.execute("/api/carts/add-item", "POST", params);
1726
+ return this.execute(
1727
+ COMMERCE_ENDPOINTS.carts.addItem,
1728
+ "POST",
1729
+ params
1730
+ );
1613
1731
  }
1614
1732
  updateItem(params) {
1615
- return this.execute("/api/carts/update-item", "POST", params);
1733
+ return this.execute(
1734
+ COMMERCE_ENDPOINTS.carts.updateItem,
1735
+ "POST",
1736
+ params
1737
+ );
1616
1738
  }
1617
1739
  removeItem(params) {
1618
1740
  return this.execute(
1619
- "/api/carts/remove-item",
1741
+ COMMERCE_ENDPOINTS.carts.removeItem,
1620
1742
  "POST",
1621
1743
  params
1622
1744
  );
1623
1745
  }
1624
1746
  applyDiscount(params) {
1625
- return this.execute("/api/carts/apply-discount", "POST", params);
1747
+ return this.execute(
1748
+ COMMERCE_ENDPOINTS.carts.applyDiscount,
1749
+ "POST",
1750
+ params
1751
+ );
1626
1752
  }
1627
1753
  removeDiscount(params) {
1628
- return this.execute("/api/carts/remove-discount", "POST", params);
1629
- }
1630
- clearCart(params) {
1631
1754
  return this.execute(
1632
- "/api/carts/clear",
1755
+ COMMERCE_ENDPOINTS.carts.removeDiscount,
1633
1756
  "POST",
1634
1757
  params
1635
1758
  );
1636
1759
  }
1637
- };
1638
-
1639
- // src/core/api/base-api.ts
1640
- var BaseApi = class {
1641
- constructor(apiName, options) {
1642
- if (!options.secretKey) {
1643
- throw createConfigError(`secretKey is required for ${apiName}.`);
1644
- }
1645
- this.publishableKey = requirePublishableKeyForSecret(
1646
- apiName,
1647
- options.publishableKey,
1648
- options.secretKey
1760
+ clearCart(params) {
1761
+ return this.execute(
1762
+ COMMERCE_ENDPOINTS.carts.clear,
1763
+ "POST",
1764
+ params
1649
1765
  );
1650
- this.secretKey = options.secretKey;
1651
- this.apiUrl = options.apiUrl;
1652
- this.onRequestId = options.onRequestId;
1653
- }
1654
- async request(endpoint, body, options) {
1655
- const method = options?.method ?? "POST";
1656
- try {
1657
- const response = await httpFetch(endpoint, {
1658
- method,
1659
- apiUrl: this.apiUrl,
1660
- publishableKey: this.publishableKey,
1661
- secretKey: this.secretKey,
1662
- ...body !== void 0 && { body: JSON.stringify(body) },
1663
- ...options?.headers && { headers: options.headers }
1664
- });
1665
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1666
- return parseApiResponse(response, endpoint);
1667
- } catch (err) {
1668
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1669
- this.onRequestId?.(id);
1670
- throw err;
1671
- }
1672
1766
  }
1673
1767
  };
1674
1768
 
@@ -3117,6 +3211,7 @@ function compareVariantOrder(a, b) {
3117
3211
  function getVariantAvailableForSale(variant) {
3118
3212
  if (variant.isActive === false) return false;
3119
3213
  if (variant.isUnlimited) return true;
3214
+ if (variant.inventoryPolicy === "continue") return true;
3120
3215
  return (variant.stock ?? 0) - (variant.reservedStock ?? 0) > 0;
3121
3216
  }
3122
3217
  function getVariantAvailableStock(variant) {
@@ -3477,37 +3572,6 @@ function withProductListingCards(response, options) {
3477
3572
  cards: response.docs.map((item) => buildProductListingCard(item, options))
3478
3573
  };
3479
3574
  }
3480
- function rejectLegacyOptionValueSwatchColor(value) {
3481
- if (Object.prototype.hasOwnProperty.call(
3482
- value,
3483
- "swatchColor"
3484
- )) {
3485
- throw new TypeError(
3486
- 'Product upsert option values no longer accept removed flat "swatchColor"; use nested "swatch" instead.'
3487
- );
3488
- }
3489
- }
3490
- function normalizeProductUpsertOptionValue(value) {
3491
- rejectLegacyOptionValueSwatchColor(value);
3492
- return value;
3493
- }
3494
- function normalizeProductUpsertParams(params) {
3495
- const options = params.options ?? [];
3496
- const variants = params.variants ?? [];
3497
- if (!options.length) {
3498
- return { ...params, options, variants };
3499
- }
3500
- return {
3501
- ...params,
3502
- options: options.map((option) => ({
3503
- ...option,
3504
- values: option.values.map(
3505
- (value) => normalizeProductUpsertOptionValue(value)
3506
- )
3507
- })),
3508
- variants
3509
- };
3510
- }
3511
3575
  var PRODUCT_UPSERT_UNKNOWN_FIELD_REASON = "unknown_field";
3512
3576
  var PRODUCT_UPSERT_READONLY_FIELD_REASON = "product_field_readonly";
3513
3577
  function isProductUpsertFieldValidationErrorBody(value) {
@@ -3516,98 +3580,6 @@ function isProductUpsertFieldValidationErrorBody(value) {
3516
3580
  const reason = body.reason;
3517
3581
  return typeof body.error === "string" && typeof body.field === "string" && (reason === PRODUCT_UPSERT_UNKNOWN_FIELD_REASON || reason === PRODUCT_UPSERT_READONLY_FIELD_REASON);
3518
3582
  }
3519
- var ProductApi = class extends BaseApi {
3520
- constructor(options) {
3521
- super("ProductApi", options);
3522
- }
3523
- /**
3524
- * Check point-in-time stock availability for one or more product variants.
3525
- * Results reflect available stock at the moment of the call and are not guaranteed
3526
- * to remain available by the time an order is placed.
3527
- */
3528
- stockCheck(params) {
3529
- return this.request("/api/products/stock-check", params);
3530
- }
3531
- stockSnapshot(params) {
3532
- return this.request(
3533
- stockSnapshotQuery(params),
3534
- void 0,
3535
- { method: "GET" }
3536
- );
3537
- }
3538
- listingGroups(params) {
3539
- return this.request(
3540
- listingGroupsQuery(params),
3541
- void 0,
3542
- { method: "GET" }
3543
- );
3544
- }
3545
- listingGroupsCatalog(params) {
3546
- return this.request(
3547
- listingGroupsCatalogQuery(params),
3548
- void 0,
3549
- { method: "GET" }
3550
- );
3551
- }
3552
- async listingPage(params = {}) {
3553
- if (params.mode === "full") {
3554
- const response2 = await this.request(buildProductListingPageUrl(params), void 0, { method: "GET" });
3555
- return withProductListingCards(response2, params);
3556
- }
3557
- const response = await this.request(buildProductListingPageUrl(params), void 0, { method: "GET" });
3558
- return withProductListingCards(response, params);
3559
- }
3560
- /**
3561
- * Fetch full product detail by slug or id.
3562
- * Returns a discriminated result so storefronts can distinguish missing,
3563
- * unpublished, and feature-disabled products.
3564
- *
3565
- * Only product-detail 404 responses carrying one of those allowlisted reasons
3566
- * are mapped to `{ found: false, reason }`. Unknown or uncoded 404s, plus
3567
- * permission/auth errors such as tenant mismatch, continue to throw typed SDK
3568
- * errors instead of being collapsed into a storefront absence result.
3569
- */
3570
- async detail(params) {
3571
- try {
3572
- const product = await this.request(
3573
- productDetailQuery(params),
3574
- void 0,
3575
- { method: "GET" }
3576
- );
3577
- return { found: true, product };
3578
- } catch (err) {
3579
- const notFoundResult = productDetailResultFromError(err);
3580
- if (notFoundResult) return notFoundResult;
3581
- throw err;
3582
- }
3583
- }
3584
- async detailCatalog(params) {
3585
- try {
3586
- const product = await this.request(
3587
- productDetailCatalogQuery(params),
3588
- void 0,
3589
- { method: "GET" }
3590
- );
3591
- return { found: true, product };
3592
- } catch (err) {
3593
- const notFoundResult = productDetailResultFromError(err);
3594
- if (notFoundResult?.found === false) return notFoundResult;
3595
- throw err;
3596
- }
3597
- }
3598
- /**
3599
- * Atomically create or update a product together with its options,
3600
- * option-values, and variants in a single transaction. Mirrors Shopify's
3601
- * `productSet` shape and is the canonical write path for the MCP
3602
- * `product-upsert` tool.
3603
- */
3604
- upsert(params) {
3605
- return this.request(
3606
- "/api/products/upsert",
3607
- normalizeProductUpsertParams(params)
3608
- );
3609
- }
3610
- };
3611
3583
 
3612
3584
  // src/core/api/order-api.ts
3613
3585
  function idempotencyRequestOptions(idempotencyKey) {
@@ -3617,126 +3589,6 @@ function splitIdempotencyKey(params) {
3617
3589
  const { idempotencyKey, ...body } = params;
3618
3590
  return { body, idempotencyKey };
3619
3591
  }
3620
- function normalizeCreateOrderBody(params) {
3621
- if (params.items !== void 0) {
3622
- const { idempotencyKey: _idempotencyKey2, items, ...rest } = params;
3623
- return { ...rest, orderItems: items };
3624
- }
3625
- const { idempotencyKey: _idempotencyKey, ...body } = params;
3626
- return body;
3627
- }
3628
- var OrderApi = class extends BaseApi {
3629
- constructor(options) {
3630
- super("OrderApi", options);
3631
- }
3632
- createOrder(params) {
3633
- const { idempotencyKey } = params;
3634
- const normalizedBody = normalizeCreateOrderBody(params);
3635
- return this.request(
3636
- "/api/orders/create",
3637
- normalizedBody,
3638
- idempotencyRequestOptions(idempotencyKey)
3639
- );
3640
- }
3641
- updateOrder(params) {
3642
- return this.request("/api/orders/update", params);
3643
- }
3644
- updateTransaction(params) {
3645
- return this.request("/api/transactions/update", params);
3646
- }
3647
- confirmPayment(params) {
3648
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3649
- const headerKey = idempotencyKey ?? params.providerEventId;
3650
- return this.request(
3651
- "/api/orders/confirm-payment",
3652
- body,
3653
- idempotencyRequestOptions(headerKey)
3654
- );
3655
- }
3656
- cancelOrder(params) {
3657
- const { idempotencyKey } = params;
3658
- const body = {
3659
- orderNumber: params.orderNumber,
3660
- reasonCode: params.reasonCode,
3661
- reasonDetail: params.reasonDetail
3662
- };
3663
- return this.request(
3664
- "/api/orders/cancel",
3665
- body,
3666
- idempotencyKey ? { headers: { "X-Idempotency-Key": idempotencyKey } } : void 0
3667
- );
3668
- }
3669
- resolveCancelRefund(params) {
3670
- return this.request(
3671
- "/api/orders/resolve-cancel-refund",
3672
- {
3673
- orderNumber: params.orderNumber,
3674
- idempotencyKey: params.idempotencyKey,
3675
- outcome: params.outcome,
3676
- refundedAmount: params.refundedAmount,
3677
- pgProvider: params.pgProvider,
3678
- ...params.pgRefundId ? { pgRefundId: params.pgRefundId } : {}
3679
- },
3680
- idempotencyRequestOptions(params.idempotencyKey)
3681
- );
3682
- }
3683
- /**
3684
- * Returns a `PublicOrder`-compatible shape even when the server backs the
3685
- * response with a Checkout (checkout/order separation, #1285). `orderNumber`
3686
- * stays the stable cross-window key. A breaking `PublicCheckout` split is a
3687
- * deferred follow-up (design D10 / Q3-b); do not change this return type here.
3688
- */
3689
- checkout(params) {
3690
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3691
- return this.request(
3692
- "/api/orders/checkout",
3693
- body,
3694
- idempotencyRequestOptions(idempotencyKey)
3695
- );
3696
- }
3697
- createFulfillment(params) {
3698
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3699
- return this.request(
3700
- "/api/orders/create-fulfillment",
3701
- body,
3702
- idempotencyRequestOptions(idempotencyKey)
3703
- );
3704
- }
3705
- prepareFulfillmentOrder(params) {
3706
- return this.request(
3707
- "/api/fulfillment-orders/prepare-fulfillment-order",
3708
- params
3709
- );
3710
- }
3711
- updateFulfillment(params) {
3712
- return this.request("/api/orders/update-fulfillment", params);
3713
- }
3714
- bulkImportFulfillments(params) {
3715
- return this.request(
3716
- "/api/fulfillments/bulk-import",
3717
- params
3718
- );
3719
- }
3720
- returnWithRefund(params) {
3721
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3722
- return this.request(
3723
- "/api/returns/return-refund",
3724
- body,
3725
- idempotencyRequestOptions(idempotencyKey)
3726
- );
3727
- }
3728
- createReturn(params) {
3729
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3730
- return this.request(
3731
- "/api/returns/create",
3732
- body,
3733
- idempotencyRequestOptions(idempotencyKey)
3734
- );
3735
- }
3736
- updateReturn(params) {
3737
- return this.request("/api/returns/update", params);
3738
- }
3739
- };
3740
3592
 
3741
3593
  // src/core/commerce/commerce-client.ts
3742
3594
  var BrowserCommerceApi = class extends CustomerScopedApi {
@@ -3768,7 +3620,10 @@ var CommerceClient = class {
3768
3620
  onRequestId: options.onRequestId
3769
3621
  });
3770
3622
  this.product = {
3771
- stockCheck: (params) => api.post("/api/products/stock-check", params),
3623
+ stockCheck: (params) => api.post(
3624
+ COMMERCE_ENDPOINTS.products.stockCheck,
3625
+ params
3626
+ ),
3772
3627
  stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
3773
3628
  listingGroups: (params) => api.get(
3774
3629
  listingGroupsCatalogQuery(params)
@@ -3786,7 +3641,9 @@ var CommerceClient = class {
3786
3641
  },
3787
3642
  detail: async (params) => {
3788
3643
  try {
3789
- const product = await api.get(productDetailQuery(params));
3644
+ const product = await api.get(
3645
+ productDetailQuery(params)
3646
+ );
3790
3647
  return { found: true, product };
3791
3648
  } catch (err) {
3792
3649
  const notFoundResult = productDetailResultFromError(err);
@@ -3808,13 +3665,16 @@ var CommerceClient = class {
3808
3665
  }
3809
3666
  };
3810
3667
  this.cart = {
3668
+ create: cartApi.createCart.bind(cartApi),
3811
3669
  get: cartApi.getCart.bind(cartApi),
3812
3670
  addItem: cartApi.addItem.bind(cartApi),
3813
3671
  updateItem: cartApi.updateItem.bind(cartApi),
3814
3672
  removeItem: cartApi.removeItem.bind(cartApi),
3815
3673
  applyDiscount: cartApi.applyDiscount.bind(cartApi),
3816
3674
  removeDiscount: cartApi.removeDiscount.bind(cartApi),
3817
- clear: cartApi.clearCart.bind(cartApi)
3675
+ clear: cartApi.clearCart.bind(cartApi),
3676
+ merge: cartApi.merge.bind(cartApi),
3677
+ mine: cartApi.mine.bind(cartApi)
3818
3678
  };
3819
3679
  this.orders = {
3820
3680
  checkout: (params) => {
@@ -3831,7 +3691,10 @@ var CommerceClient = class {
3831
3691
  validate: (params) => api.post("/api/discounts/validate", params)
3832
3692
  };
3833
3693
  this.shipping = {
3834
- calculate: (params) => api.post("/api/shipping-policies/calculate", params)
3694
+ calculate: (params) => api.post(
3695
+ "/api/shipping-policies/calculate",
3696
+ params
3697
+ )
3835
3698
  };
3836
3699
  }
3837
3700
  };
@@ -3920,8 +3783,12 @@ function buildGuestCancelRequestBody(token, params) {
3920
3783
  }
3921
3784
  function buildRangeEndpoint(params) {
3922
3785
  const urlParams = new URLSearchParams();
3923
- urlParams.set("start", formatDateParam(params.start));
3924
- urlParams.set("end", formatDateParam(params.end));
3786
+ if (params.start !== void 0) {
3787
+ urlParams.set("start", formatDateParam(params.start));
3788
+ }
3789
+ if (params.end !== void 0) {
3790
+ urlParams.set("end", formatDateParam(params.end));
3791
+ }
3925
3792
  if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
3926
3793
  if (params.page !== void 0) urlParams.set("page", String(params.page));
3927
3794
  appendValues(urlParams, "calendar", params.calendar);
@@ -3944,6 +3811,13 @@ function appendValues(params, key, value) {
3944
3811
  }
3945
3812
 
3946
3813
  // src/core/client/client.ts
3814
+ var BrowserMembershipApi = class extends CustomerScopedApi {
3815
+ me() {
3816
+ return this.request(MEMBERSHIP_ENDPOINTS.me, {
3817
+ method: "GET"
3818
+ });
3819
+ }
3820
+ };
3947
3821
  var Client = class {
3948
3822
  constructor(options) {
3949
3823
  this.lastRequestId = null;
@@ -4008,6 +3882,16 @@ var Client = class {
4008
3882
  onRequestId,
4009
3883
  this.config.apiUrl
4010
3884
  );
3885
+ const membershipApi = new BrowserMembershipApi("MembershipApi", {
3886
+ publishableKey: this.config.publishableKey,
3887
+ apiUrl: this.config.apiUrl,
3888
+ customerToken: () => this.customer.auth.getToken(),
3889
+ onUnauthorized,
3890
+ onRequestId
3891
+ });
3892
+ this.memberships = {
3893
+ me: membershipApi.me.bind(membershipApi)
3894
+ };
4011
3895
  }
4012
3896
  getState() {
4013
3897
  return { ...this.state };
@@ -4020,26 +3904,6 @@ function createClient(options) {
4020
3904
  return new Client(options);
4021
3905
  }
4022
3906
 
4023
- // src/core/api/discount-api.ts
4024
- var DiscountApi = class extends BaseApi {
4025
- constructor(options) {
4026
- super("DiscountApi", options);
4027
- }
4028
- validate(params) {
4029
- return this.request("/api/discounts/validate", params);
4030
- }
4031
- };
4032
-
4033
- // src/core/api/shipping-api.ts
4034
- var ShippingApi = class extends BaseApi {
4035
- constructor(options) {
4036
- super("ShippingApi", options);
4037
- }
4038
- calculate(params) {
4039
- return this.request("/api/shipping-policies/calculate", params);
4040
- }
4041
- };
4042
-
4043
3907
  // src/core/commerce/merge-catalog-stock.ts
4044
3908
  function mergeProductDetailWithStock(catalog, snapshot) {
4045
3909
  const snapshotByVariantId = new Map(
@@ -4095,6 +3959,8 @@ var COMMERCE_NOTIFICATION_EVENTS = [
4095
3959
  "fulfillmentShipped",
4096
3960
  "orderDelivered",
4097
3961
  "returnRequested",
3962
+ "returnApproved",
3963
+ "returnRejected",
4098
3964
  "returnCompleted"
4099
3965
  ];
4100
3966
  function isStringOrNumber(value) {
@@ -4183,7 +4049,7 @@ function isCommerceNotificationWebhookEvent(event) {
4183
4049
  if (notification.event === "fulfillmentShipped") {
4184
4050
  return sourceCollection === "fulfillments" && matchesOptionalId(data.fulfillmentId, sourceId) && typeof notification.fulfillmentId === "string" && notification.fulfillmentId.length > 0 && matchesOptionalId(notification.fulfillmentId, sourceId) && matchesOptionalId(data.fulfillmentId, notification.fulfillmentId) && matchesOptionalId(changeSourceId, notification.fulfillmentId);
4185
4051
  }
4186
- if (notification.event === "returnRequested" || notification.event === "returnCompleted") {
4052
+ if (notification.event === "returnRequested" || notification.event === "returnApproved" || notification.event === "returnRejected" || notification.event === "returnCompleted") {
4187
4053
  return sourceCollection === "returns" && matchesOptionalId(data.returnId, sourceId) && typeof notification.returnId === "string" && notification.returnId.length > 0 && matchesOptionalId(notification.returnId, sourceId) && matchesOptionalId(data.returnId, notification.returnId) && matchesOptionalId(changeSourceId, notification.returnId);
4188
4054
  }
4189
4055
  return false;
@@ -4366,7 +4232,9 @@ var INTERNAL_COLLECTIONS = [
4366
4232
  "audit-logs",
4367
4233
  "plans",
4368
4234
  "webhooks",
4369
- "event-registrations"
4235
+ "event-registrations",
4236
+ "customer-payment-methods",
4237
+ "tenant-payment-credentials"
4370
4238
  ];
4371
4239
  var COLLECTIONS = [
4372
4240
  "tenants",
@@ -4378,6 +4246,7 @@ var COLLECTIONS = [
4378
4246
  "product-categories",
4379
4247
  "product-tags",
4380
4248
  "product-collections",
4249
+ "markets",
4381
4250
  "brands",
4382
4251
  "customer-profiles",
4383
4252
  "customer-profile-stats",
@@ -4422,7 +4291,9 @@ var COLLECTIONS = [
4422
4291
  "events",
4423
4292
  "event-categories",
4424
4293
  "event-occurrences",
4425
- "event-tags"
4294
+ "event-tags",
4295
+ "membership-plans",
4296
+ "customer-memberships"
4426
4297
  ];
4427
4298
  var SERVER_ONLY_COLLECTIONS = [
4428
4299
  "tenant-logos",
@@ -4455,7 +4326,8 @@ var SERVER_ONLY_COLLECTIONS = [
4455
4326
  "customer-groups",
4456
4327
  "reports",
4457
4328
  "community-bans",
4458
- "order-export-profiles"
4329
+ "order-export-profiles",
4330
+ "membership-charges"
4459
4331
  ];
4460
4332
  var SERVER_COLLECTIONS = [
4461
4333
  ...COLLECTIONS,
@@ -5085,7 +4957,6 @@ function createClient2(options) {
5085
4957
  export {
5086
4958
  ApiError,
5087
4959
  AuthError,
5088
- BaseApi,
5089
4960
  COLLECTIONS,
5090
4961
  COMMERCE_NOTIFICATION_EVENTS,
5091
4962
  COMMERCE_NOTIFICATION_EVENT_TYPE,
@@ -5099,7 +4970,6 @@ export {
5099
4970
  ContentClient,
5100
4971
  CustomerAuth,
5101
4972
  CustomerNamespace,
5102
- DiscountApi,
5103
4973
  EventsClient,
5104
4974
  GoneError,
5105
4975
  IMAGE_SIZES,
@@ -5107,12 +4977,10 @@ export {
5107
4977
  NetworkError,
5108
4978
  NotFoundError,
5109
4979
  ORDER_CHANGED_EVENT_TYPE,
5110
- OrderApi,
5111
4980
  PRODUCT_PLP_FIND_OPTIONS,
5112
4981
  PRODUCT_UPSERT_READONLY_FIELD_REASON,
5113
4982
  PRODUCT_UPSERT_UNKNOWN_FIELD_REASON,
5114
4983
  PermissionError,
5115
- ProductApi,
5116
4984
  ProductSelectionCodecError,
5117
4985
  RateLimitError,
5118
4986
  RealtimeConnection,
@@ -5120,7 +4988,6 @@ export {
5120
4988
  SERVER_COLLECTIONS,
5121
4989
  SERVER_ONLY_COLLECTIONS,
5122
4990
  ServiceUnavailableError,
5123
- ShippingApi,
5124
4991
  TimeoutError,
5125
4992
  UsageLimitError,
5126
4993
  ValidationError,