@01.software/sdk 0.41.1 → 0.42.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 (61) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/README.md +81 -18
  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 +176 -32
  16. package/dist/client.cjs.map +1 -1
  17. package/dist/client.d.cts +6 -6
  18. package/dist/client.d.ts +6 -6
  19. package/dist/client.js +176 -32
  20. package/dist/client.js.map +1 -1
  21. package/dist/{collection-client-Bk--pNzW.d.cts → collection-client-B-qVIBnJ.d.cts} +3 -3
  22. package/dist/{collection-client-BdcxkW7l.d.ts → collection-client-BhCMwIus.d.ts} +3 -3
  23. package/dist/{const-qGGI7Uii.d.cts → const-BiDujixF.d.cts} +1 -1
  24. package/dist/{const-HwdntWtG.d.ts → const-pmHlwm3E.d.ts} +1 -1
  25. package/dist/{index-B1oW50RY.d.ts → index-B1UBDaKz.d.ts} +3 -3
  26. package/dist/{index-DiXtjVab.d.cts → index-D78ki6Ij.d.cts} +3 -3
  27. package/dist/index.cjs +156 -339
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +7 -7
  30. package/dist/index.d.ts +7 -7
  31. package/dist/index.js +156 -339
  32. package/dist/index.js.map +1 -1
  33. package/dist/{payload-types-CqJOgON7.d.cts → payload-types-C7Ul4ElL.d.cts} +181 -115
  34. package/dist/{payload-types-CqJOgON7.d.ts → payload-types-C7Ul4ElL.d.ts} +181 -115
  35. package/dist/query.d.cts +5 -5
  36. package/dist/query.d.ts +5 -5
  37. package/dist/realtime.cjs +1 -1
  38. package/dist/realtime.cjs.map +1 -1
  39. package/dist/realtime.d.cts +2 -2
  40. package/dist/realtime.d.ts +2 -2
  41. package/dist/realtime.js +1 -1
  42. package/dist/realtime.js.map +1 -1
  43. package/dist/server.cjs +230 -46
  44. package/dist/server.cjs.map +1 -1
  45. package/dist/server.d.cts +7 -7
  46. package/dist/server.d.ts +7 -7
  47. package/dist/server.js +230 -46
  48. package/dist/server.js.map +1 -1
  49. package/dist/{types-DgfXb7iV.d.ts → types-BL7M-EUV.d.cts} +138 -13
  50. package/dist/{types-BMI3M0nb.d.ts → types-Bf2iCjy8.d.ts} +1 -1
  51. package/dist/{types-ByLSG-O3.d.cts → types-ChV1t4ei.d.cts} +1 -1
  52. package/dist/{types-BKa9z9s2.d.cts → types-D5dSNIGs.d.ts} +138 -13
  53. package/dist/ui/canvas.cjs.map +1 -1
  54. package/dist/ui/canvas.js.map +1 -1
  55. package/dist/ui/form.d.cts +1 -1
  56. package/dist/ui/form.d.ts +1 -1
  57. package/dist/ui/video.d.cts +1 -1
  58. package/dist/ui/video.d.ts +1 -1
  59. package/dist/webhook.d.cts +4 -4
  60. package/dist/webhook.d.ts +4 -4
  61. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -22,7 +22,6 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  ApiError: () => ApiError,
24
24
  AuthError: () => AuthError,
25
- BaseApi: () => BaseApi,
26
25
  COLLECTIONS: () => COLLECTIONS,
27
26
  COMMERCE_NOTIFICATION_EVENTS: () => COMMERCE_NOTIFICATION_EVENTS,
28
27
  COMMERCE_NOTIFICATION_EVENT_TYPE: () => COMMERCE_NOTIFICATION_EVENT_TYPE,
@@ -36,7 +35,6 @@ __export(src_exports, {
36
35
  ContentClient: () => ContentClient,
37
36
  CustomerAuth: () => CustomerAuth,
38
37
  CustomerNamespace: () => CustomerNamespace,
39
- DiscountApi: () => DiscountApi,
40
38
  EventsClient: () => EventsClient,
41
39
  GoneError: () => GoneError,
42
40
  IMAGE_SIZES: () => IMAGE_SIZES,
@@ -44,12 +42,10 @@ __export(src_exports, {
44
42
  NetworkError: () => NetworkError,
45
43
  NotFoundError: () => NotFoundError,
46
44
  ORDER_CHANGED_EVENT_TYPE: () => ORDER_CHANGED_EVENT_TYPE,
47
- OrderApi: () => OrderApi,
48
45
  PRODUCT_PLP_FIND_OPTIONS: () => PRODUCT_PLP_FIND_OPTIONS,
49
46
  PRODUCT_UPSERT_READONLY_FIELD_REASON: () => PRODUCT_UPSERT_READONLY_FIELD_REASON,
50
47
  PRODUCT_UPSERT_UNKNOWN_FIELD_REASON: () => PRODUCT_UPSERT_UNKNOWN_FIELD_REASON,
51
48
  PermissionError: () => PermissionError,
52
- ProductApi: () => ProductApi,
53
49
  ProductSelectionCodecError: () => ProductSelectionCodecError,
54
50
  RateLimitError: () => RateLimitError,
55
51
  RealtimeConnection: () => RealtimeConnection,
@@ -57,7 +53,6 @@ __export(src_exports, {
57
53
  SERVER_COLLECTIONS: () => SERVER_COLLECTIONS,
58
54
  SERVER_ONLY_COLLECTIONS: () => SERVER_ONLY_COLLECTIONS,
59
55
  ServiceUnavailableError: () => ServiceUnavailableError,
60
- ShippingApi: () => ShippingApi,
61
56
  TimeoutError: () => TimeoutError,
62
57
  UsageLimitError: () => UsageLimitError,
63
58
  ValidationError: () => ValidationError,
@@ -360,6 +355,14 @@ var createValidationError = (message, details, userMessage, suggestion, status)
360
355
  var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
361
356
  var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
362
357
  var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
358
+ var createGoneError = (message, details, userMessage, suggestion) => new GoneError(message, details, userMessage, suggestion);
359
+ var createServiceUnavailableError = (message, retryAfter, details, userMessage, suggestion) => new ServiceUnavailableError(
360
+ message,
361
+ retryAfter,
362
+ details,
363
+ userMessage,
364
+ suggestion
365
+ );
363
366
  var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
364
367
  var createAuthError = (message, details, userMessage, suggestion, requestId) => new AuthError(message, details, userMessage, suggestion, requestId);
365
368
  var createPermissionError = (message, details, userMessage, suggestion, requestId) => new PermissionError(message, details, userMessage, suggestion, requestId);
@@ -384,7 +387,7 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
384
387
  return publishableKey ?? "";
385
388
  }
386
389
 
387
- // src/core/client/types.ts
390
+ // src/core/internal/utils/api-url.ts
388
391
  function resolveApiUrl(apiUrl) {
389
392
  if (apiUrl) {
390
393
  return apiUrl.replace(/\/$/, "");
@@ -401,7 +404,7 @@ function resolveApiUrl(apiUrl) {
401
404
  // src/core/internal/utils/http.ts
402
405
  var DEFAULT_TIMEOUT = 3e4;
403
406
  var STOREFRONT_BROWSER_TIMEOUT = 15e3;
404
- var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
407
+ var DEFAULT_RETRYABLE_STATUSES = [408, 500, 502, 503, 504];
405
408
  var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
406
409
  var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
407
410
  var DEFAULT_MAX_RETRIES = 3;
@@ -518,7 +521,12 @@ function attachRequestId(err, id) {
518
521
  if (id) err.requestId = id;
519
522
  return err;
520
523
  }
521
- function createHttpStatusError(status, parsed, details, requestId) {
524
+ function parseRetryAfter(response) {
525
+ const raw = response.headers.get("Retry-After");
526
+ if (!raw) return void 0;
527
+ return parseInt(raw, 10) || void 0;
528
+ }
529
+ function mapResponseToError(status, parsed, details, requestId, retryAfter) {
522
530
  const errorDetails = {
523
531
  ...details,
524
532
  ...parsed.errors && { errors: parsed.errors },
@@ -581,6 +589,41 @@ function createHttpStatusError(status, parsed, details, requestId) {
581
589
  requestId
582
590
  );
583
591
  }
592
+ if (status === 410) {
593
+ return attachRequestId(
594
+ createGoneError(
595
+ parsed.errorMessage,
596
+ errorDetails,
597
+ parsed.userMessage,
598
+ suggestion
599
+ ),
600
+ requestId
601
+ );
602
+ }
603
+ if (status === 429) {
604
+ return attachRequestId(
605
+ createRateLimitError(
606
+ parsed.errorMessage,
607
+ retryAfter,
608
+ errorDetails,
609
+ parsed.userMessage,
610
+ suggestion
611
+ ),
612
+ requestId
613
+ );
614
+ }
615
+ if (status === 503) {
616
+ return attachRequestId(
617
+ createServiceUnavailableError(
618
+ parsed.errorMessage,
619
+ retryAfter,
620
+ errorDetails,
621
+ parsed.userMessage,
622
+ suggestion
623
+ ),
624
+ requestId
625
+ );
626
+ }
584
627
  return attachRequestId(
585
628
  createNetworkError(
586
629
  parsed.errorMessage,
@@ -699,26 +742,17 @@ async function httpFetch(url, options) {
699
742
  method: requestInit.method || "GET",
700
743
  attempt: attempt + 1
701
744
  };
702
- if (NON_RETRYABLE_STATUSES.includes(response.status)) {
703
- throw createHttpStatusError(
704
- response.status,
705
- parsed,
706
- details,
707
- requestId
708
- );
709
- }
710
- const error = attachRequestId(
711
- createNetworkError(
712
- parsed.errorMessage,
713
- response.status,
714
- details,
715
- parsed.userMessage,
716
- getErrorSuggestion(response.status)
717
- ),
718
- requestId
745
+ const retryAfter = parseRetryAfter(response);
746
+ const error = mapResponseToError(
747
+ response.status,
748
+ parsed,
749
+ details,
750
+ requestId,
751
+ retryAfter
719
752
  );
720
753
  const method2 = (requestInit.method || "GET").toUpperCase();
721
- if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && retryConfig.retryableStatuses.includes(response.status)) {
754
+ const isTerminal = error instanceof RateLimitError || error instanceof UsageLimitError;
755
+ if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && !isTerminal && !NON_RETRYABLE_STATUSES.includes(response.status) && retryConfig.retryableStatuses.includes(response.status)) {
722
756
  lastError = error;
723
757
  const retryDelay = retryConfig.retryDelay(attempt);
724
758
  debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
@@ -809,9 +843,6 @@ function productDetailCatalogQuery(params) {
809
843
  }
810
844
  return `/api/products/detail/catalog?${search}`;
811
845
  }
812
- function listingGroupsQuery(params) {
813
- return `/api/products/listing-groups?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
814
- }
815
846
  function listingGroupsCatalogQuery(params) {
816
847
  return `/api/products/listing-groups/catalog?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
817
848
  }
@@ -1738,81 +1769,126 @@ var CustomerNamespace = class {
1738
1769
  }
1739
1770
  };
1740
1771
 
1772
+ // src/core/api/endpoints.ts
1773
+ var COMMERCE_ENDPOINTS = {
1774
+ orders: {
1775
+ create: "/api/orders/create",
1776
+ update: "/api/orders/update",
1777
+ confirmPayment: "/api/orders/confirm-payment",
1778
+ byPayment: "/api/orders/by-payment",
1779
+ cancel: "/api/orders/cancel",
1780
+ resolveCancelRefund: "/api/orders/resolve-cancel-refund",
1781
+ checkout: "/api/orders/checkout",
1782
+ createFulfillment: "/api/orders/create-fulfillment",
1783
+ updateFulfillment: "/api/orders/update-fulfillment"
1784
+ },
1785
+ transactions: {
1786
+ update: "/api/transactions/update"
1787
+ },
1788
+ returns: {
1789
+ create: "/api/returns/create",
1790
+ update: "/api/returns/update",
1791
+ returnRefund: "/api/returns/return-refund"
1792
+ },
1793
+ fulfillmentOrders: {
1794
+ prepare: "/api/fulfillment-orders/prepare-fulfillment-order"
1795
+ },
1796
+ fulfillments: {
1797
+ bulkImport: "/api/fulfillments/bulk-import"
1798
+ },
1799
+ carts: {
1800
+ mine: "/api/carts/mine",
1801
+ merge: "/api/carts/merge",
1802
+ addItem: "/api/carts/add-item",
1803
+ updateItem: "/api/carts/update-item",
1804
+ removeItem: "/api/carts/remove-item",
1805
+ applyDiscount: "/api/carts/apply-discount",
1806
+ removeDiscount: "/api/carts/remove-discount",
1807
+ clear: "/api/carts/clear"
1808
+ }
1809
+ };
1810
+ var COMMERCE_ENDPOINT_PATHS = Object.values(
1811
+ COMMERCE_ENDPOINTS
1812
+ ).flatMap((group) => Object.values(group));
1813
+
1741
1814
  // src/core/api/cart-api.ts
1742
1815
  var CartApi = class extends CustomerScopedApi {
1743
1816
  constructor(options) {
1744
- super("CartApi", options);
1817
+ super("CartApi", { ...options, requiresCredential: false });
1745
1818
  }
1746
1819
  async execute(endpoint, method, body) {
1747
1820
  return this.request(endpoint, { method, body });
1748
1821
  }
1749
- getCart(cartId) {
1822
+ /**
1823
+ * Create a cart and receive its `cartToken`. Store the token and pass it to
1824
+ * every subsequent cart operation.
1825
+ */
1826
+ createCart(params = {}) {
1827
+ return this.execute("/api/carts/create", "POST", params);
1828
+ }
1829
+ getCart(cartToken) {
1830
+ return this.execute("/api/carts/get", "POST", { cartToken });
1831
+ }
1832
+ merge(params) {
1750
1833
  return this.execute(
1751
- `/api/carts/${cartId}?depth=0&joins=false`,
1752
- "GET"
1834
+ COMMERCE_ENDPOINTS.carts.merge,
1835
+ "POST",
1836
+ params
1837
+ );
1838
+ }
1839
+ /**
1840
+ * Resolve the authenticated customer's active cart by JWT (no `cartToken`
1841
+ * required). Returns the cart and its capability handle, or both `null` when
1842
+ * the customer has no active cart. Requires a customer token.
1843
+ */
1844
+ mine() {
1845
+ return this.execute(
1846
+ COMMERCE_ENDPOINTS.carts.mine,
1847
+ "POST",
1848
+ {}
1753
1849
  );
1754
1850
  }
1755
1851
  addItem(params) {
1756
- return this.execute("/api/carts/add-item", "POST", params);
1852
+ return this.execute(
1853
+ COMMERCE_ENDPOINTS.carts.addItem,
1854
+ "POST",
1855
+ params
1856
+ );
1757
1857
  }
1758
1858
  updateItem(params) {
1759
- return this.execute("/api/carts/update-item", "POST", params);
1859
+ return this.execute(
1860
+ COMMERCE_ENDPOINTS.carts.updateItem,
1861
+ "POST",
1862
+ params
1863
+ );
1760
1864
  }
1761
1865
  removeItem(params) {
1762
1866
  return this.execute(
1763
- "/api/carts/remove-item",
1867
+ COMMERCE_ENDPOINTS.carts.removeItem,
1764
1868
  "POST",
1765
1869
  params
1766
1870
  );
1767
1871
  }
1768
1872
  applyDiscount(params) {
1769
- return this.execute("/api/carts/apply-discount", "POST", params);
1873
+ return this.execute(
1874
+ COMMERCE_ENDPOINTS.carts.applyDiscount,
1875
+ "POST",
1876
+ params
1877
+ );
1770
1878
  }
1771
1879
  removeDiscount(params) {
1772
- return this.execute("/api/carts/remove-discount", "POST", params);
1773
- }
1774
- clearCart(params) {
1775
1880
  return this.execute(
1776
- "/api/carts/clear",
1881
+ COMMERCE_ENDPOINTS.carts.removeDiscount,
1777
1882
  "POST",
1778
1883
  params
1779
1884
  );
1780
1885
  }
1781
- };
1782
-
1783
- // src/core/api/base-api.ts
1784
- var BaseApi = class {
1785
- constructor(apiName, options) {
1786
- if (!options.secretKey) {
1787
- throw createConfigError(`secretKey is required for ${apiName}.`);
1788
- }
1789
- this.publishableKey = requirePublishableKeyForSecret(
1790
- apiName,
1791
- options.publishableKey,
1792
- options.secretKey
1886
+ clearCart(params) {
1887
+ return this.execute(
1888
+ COMMERCE_ENDPOINTS.carts.clear,
1889
+ "POST",
1890
+ params
1793
1891
  );
1794
- this.secretKey = options.secretKey;
1795
- this.apiUrl = options.apiUrl;
1796
- this.onRequestId = options.onRequestId;
1797
- }
1798
- async request(endpoint, body, options) {
1799
- const method = options?.method ?? "POST";
1800
- try {
1801
- const response = await httpFetch(endpoint, {
1802
- method,
1803
- apiUrl: this.apiUrl,
1804
- publishableKey: this.publishableKey,
1805
- secretKey: this.secretKey,
1806
- ...body !== void 0 && { body: JSON.stringify(body) },
1807
- ...options?.headers && { headers: options.headers }
1808
- });
1809
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1810
- return parseApiResponse(response, endpoint);
1811
- } catch (err) {
1812
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1813
- this.onRequestId?.(id);
1814
- throw err;
1815
- }
1816
1892
  }
1817
1893
  };
1818
1894
 
@@ -3261,6 +3337,7 @@ function compareVariantOrder(a, b) {
3261
3337
  function getVariantAvailableForSale(variant) {
3262
3338
  if (variant.isActive === false) return false;
3263
3339
  if (variant.isUnlimited) return true;
3340
+ if (variant.inventoryPolicy === "continue") return true;
3264
3341
  return (variant.stock ?? 0) - (variant.reservedStock ?? 0) > 0;
3265
3342
  }
3266
3343
  function getVariantAvailableStock(variant) {
@@ -3621,37 +3698,6 @@ function withProductListingCards(response, options) {
3621
3698
  cards: response.docs.map((item) => buildProductListingCard(item, options))
3622
3699
  };
3623
3700
  }
3624
- function rejectLegacyOptionValueSwatchColor(value) {
3625
- if (Object.prototype.hasOwnProperty.call(
3626
- value,
3627
- "swatchColor"
3628
- )) {
3629
- throw new TypeError(
3630
- 'Product upsert option values no longer accept removed flat "swatchColor"; use nested "swatch" instead.'
3631
- );
3632
- }
3633
- }
3634
- function normalizeProductUpsertOptionValue(value) {
3635
- rejectLegacyOptionValueSwatchColor(value);
3636
- return value;
3637
- }
3638
- function normalizeProductUpsertParams(params) {
3639
- const options = params.options ?? [];
3640
- const variants = params.variants ?? [];
3641
- if (!options.length) {
3642
- return { ...params, options, variants };
3643
- }
3644
- return {
3645
- ...params,
3646
- options: options.map((option) => ({
3647
- ...option,
3648
- values: option.values.map(
3649
- (value) => normalizeProductUpsertOptionValue(value)
3650
- )
3651
- })),
3652
- variants
3653
- };
3654
- }
3655
3701
  var PRODUCT_UPSERT_UNKNOWN_FIELD_REASON = "unknown_field";
3656
3702
  var PRODUCT_UPSERT_READONLY_FIELD_REASON = "product_field_readonly";
3657
3703
  function isProductUpsertFieldValidationErrorBody(value) {
@@ -3660,98 +3706,6 @@ function isProductUpsertFieldValidationErrorBody(value) {
3660
3706
  const reason = body.reason;
3661
3707
  return typeof body.error === "string" && typeof body.field === "string" && (reason === PRODUCT_UPSERT_UNKNOWN_FIELD_REASON || reason === PRODUCT_UPSERT_READONLY_FIELD_REASON);
3662
3708
  }
3663
- var ProductApi = class extends BaseApi {
3664
- constructor(options) {
3665
- super("ProductApi", options);
3666
- }
3667
- /**
3668
- * Check point-in-time stock availability for one or more product variants.
3669
- * Results reflect available stock at the moment of the call and are not guaranteed
3670
- * to remain available by the time an order is placed.
3671
- */
3672
- stockCheck(params) {
3673
- return this.request("/api/products/stock-check", params);
3674
- }
3675
- stockSnapshot(params) {
3676
- return this.request(
3677
- stockSnapshotQuery(params),
3678
- void 0,
3679
- { method: "GET" }
3680
- );
3681
- }
3682
- listingGroups(params) {
3683
- return this.request(
3684
- listingGroupsQuery(params),
3685
- void 0,
3686
- { method: "GET" }
3687
- );
3688
- }
3689
- listingGroupsCatalog(params) {
3690
- return this.request(
3691
- listingGroupsCatalogQuery(params),
3692
- void 0,
3693
- { method: "GET" }
3694
- );
3695
- }
3696
- async listingPage(params = {}) {
3697
- if (params.mode === "full") {
3698
- const response2 = await this.request(buildProductListingPageUrl(params), void 0, { method: "GET" });
3699
- return withProductListingCards(response2, params);
3700
- }
3701
- const response = await this.request(buildProductListingPageUrl(params), void 0, { method: "GET" });
3702
- return withProductListingCards(response, params);
3703
- }
3704
- /**
3705
- * Fetch full product detail by slug or id.
3706
- * Returns a discriminated result so storefronts can distinguish missing,
3707
- * unpublished, and feature-disabled products.
3708
- *
3709
- * Only product-detail 404 responses carrying one of those allowlisted reasons
3710
- * are mapped to `{ found: false, reason }`. Unknown or uncoded 404s, plus
3711
- * permission/auth errors such as tenant mismatch, continue to throw typed SDK
3712
- * errors instead of being collapsed into a storefront absence result.
3713
- */
3714
- async detail(params) {
3715
- try {
3716
- const product = await this.request(
3717
- productDetailQuery(params),
3718
- void 0,
3719
- { method: "GET" }
3720
- );
3721
- return { found: true, product };
3722
- } catch (err) {
3723
- const notFoundResult = productDetailResultFromError(err);
3724
- if (notFoundResult) return notFoundResult;
3725
- throw err;
3726
- }
3727
- }
3728
- async detailCatalog(params) {
3729
- try {
3730
- const product = await this.request(
3731
- productDetailCatalogQuery(params),
3732
- void 0,
3733
- { method: "GET" }
3734
- );
3735
- return { found: true, product };
3736
- } catch (err) {
3737
- const notFoundResult = productDetailResultFromError(err);
3738
- if (notFoundResult?.found === false) return notFoundResult;
3739
- throw err;
3740
- }
3741
- }
3742
- /**
3743
- * Atomically create or update a product together with its options,
3744
- * option-values, and variants in a single transaction. Mirrors Shopify's
3745
- * `productSet` shape and is the canonical write path for the MCP
3746
- * `product-upsert` tool.
3747
- */
3748
- upsert(params) {
3749
- return this.request(
3750
- "/api/products/upsert",
3751
- normalizeProductUpsertParams(params)
3752
- );
3753
- }
3754
- };
3755
3709
 
3756
3710
  // src/core/api/order-api.ts
3757
3711
  function idempotencyRequestOptions(idempotencyKey) {
@@ -3761,126 +3715,6 @@ function splitIdempotencyKey(params) {
3761
3715
  const { idempotencyKey, ...body } = params;
3762
3716
  return { body, idempotencyKey };
3763
3717
  }
3764
- function normalizeCreateOrderBody(params) {
3765
- if (params.items !== void 0) {
3766
- const { idempotencyKey: _idempotencyKey2, items, ...rest } = params;
3767
- return { ...rest, orderItems: items };
3768
- }
3769
- const { idempotencyKey: _idempotencyKey, ...body } = params;
3770
- return body;
3771
- }
3772
- var OrderApi = class extends BaseApi {
3773
- constructor(options) {
3774
- super("OrderApi", options);
3775
- }
3776
- createOrder(params) {
3777
- const { idempotencyKey } = params;
3778
- const normalizedBody = normalizeCreateOrderBody(params);
3779
- return this.request(
3780
- "/api/orders/create",
3781
- normalizedBody,
3782
- idempotencyRequestOptions(idempotencyKey)
3783
- );
3784
- }
3785
- updateOrder(params) {
3786
- return this.request("/api/orders/update", params);
3787
- }
3788
- updateTransaction(params) {
3789
- return this.request("/api/transactions/update", params);
3790
- }
3791
- confirmPayment(params) {
3792
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3793
- const headerKey = idempotencyKey ?? params.providerEventId;
3794
- return this.request(
3795
- "/api/orders/confirm-payment",
3796
- body,
3797
- idempotencyRequestOptions(headerKey)
3798
- );
3799
- }
3800
- cancelOrder(params) {
3801
- const { idempotencyKey } = params;
3802
- const body = {
3803
- orderNumber: params.orderNumber,
3804
- reasonCode: params.reasonCode,
3805
- reasonDetail: params.reasonDetail
3806
- };
3807
- return this.request(
3808
- "/api/orders/cancel",
3809
- body,
3810
- idempotencyKey ? { headers: { "X-Idempotency-Key": idempotencyKey } } : void 0
3811
- );
3812
- }
3813
- resolveCancelRefund(params) {
3814
- return this.request(
3815
- "/api/orders/resolve-cancel-refund",
3816
- {
3817
- orderNumber: params.orderNumber,
3818
- idempotencyKey: params.idempotencyKey,
3819
- outcome: params.outcome,
3820
- refundedAmount: params.refundedAmount,
3821
- pgProvider: params.pgProvider,
3822
- ...params.pgRefundId ? { pgRefundId: params.pgRefundId } : {}
3823
- },
3824
- idempotencyRequestOptions(params.idempotencyKey)
3825
- );
3826
- }
3827
- /**
3828
- * Returns a `PublicOrder`-compatible shape even when the server backs the
3829
- * response with a Checkout (checkout/order separation, #1285). `orderNumber`
3830
- * stays the stable cross-window key. A breaking `PublicCheckout` split is a
3831
- * deferred follow-up (design D10 / Q3-b); do not change this return type here.
3832
- */
3833
- checkout(params) {
3834
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3835
- return this.request(
3836
- "/api/orders/checkout",
3837
- body,
3838
- idempotencyRequestOptions(idempotencyKey)
3839
- );
3840
- }
3841
- createFulfillment(params) {
3842
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3843
- return this.request(
3844
- "/api/orders/create-fulfillment",
3845
- body,
3846
- idempotencyRequestOptions(idempotencyKey)
3847
- );
3848
- }
3849
- prepareFulfillmentOrder(params) {
3850
- return this.request(
3851
- "/api/fulfillment-orders/prepare-fulfillment-order",
3852
- params
3853
- );
3854
- }
3855
- updateFulfillment(params) {
3856
- return this.request("/api/orders/update-fulfillment", params);
3857
- }
3858
- bulkImportFulfillments(params) {
3859
- return this.request(
3860
- "/api/fulfillments/bulk-import",
3861
- params
3862
- );
3863
- }
3864
- returnWithRefund(params) {
3865
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3866
- return this.request(
3867
- "/api/returns/return-refund",
3868
- body,
3869
- idempotencyRequestOptions(idempotencyKey)
3870
- );
3871
- }
3872
- createReturn(params) {
3873
- const { body, idempotencyKey } = splitIdempotencyKey(params);
3874
- return this.request(
3875
- "/api/returns/create",
3876
- body,
3877
- idempotencyRequestOptions(idempotencyKey)
3878
- );
3879
- }
3880
- updateReturn(params) {
3881
- return this.request("/api/returns/update", params);
3882
- }
3883
- };
3884
3718
 
3885
3719
  // src/core/commerce/commerce-client.ts
3886
3720
  var BrowserCommerceApi = class extends CustomerScopedApi {
@@ -3952,13 +3786,16 @@ var CommerceClient = class {
3952
3786
  }
3953
3787
  };
3954
3788
  this.cart = {
3789
+ create: cartApi.createCart.bind(cartApi),
3955
3790
  get: cartApi.getCart.bind(cartApi),
3956
3791
  addItem: cartApi.addItem.bind(cartApi),
3957
3792
  updateItem: cartApi.updateItem.bind(cartApi),
3958
3793
  removeItem: cartApi.removeItem.bind(cartApi),
3959
3794
  applyDiscount: cartApi.applyDiscount.bind(cartApi),
3960
3795
  removeDiscount: cartApi.removeDiscount.bind(cartApi),
3961
- clear: cartApi.clearCart.bind(cartApi)
3796
+ clear: cartApi.clearCart.bind(cartApi),
3797
+ merge: cartApi.merge.bind(cartApi),
3798
+ mine: cartApi.mine.bind(cartApi)
3962
3799
  };
3963
3800
  this.orders = {
3964
3801
  checkout: (params) => {
@@ -4164,26 +4001,6 @@ function createClient(options) {
4164
4001
  return new Client(options);
4165
4002
  }
4166
4003
 
4167
- // src/core/api/discount-api.ts
4168
- var DiscountApi = class extends BaseApi {
4169
- constructor(options) {
4170
- super("DiscountApi", options);
4171
- }
4172
- validate(params) {
4173
- return this.request("/api/discounts/validate", params);
4174
- }
4175
- };
4176
-
4177
- // src/core/api/shipping-api.ts
4178
- var ShippingApi = class extends BaseApi {
4179
- constructor(options) {
4180
- super("ShippingApi", options);
4181
- }
4182
- calculate(params) {
4183
- return this.request("/api/shipping-policies/calculate", params);
4184
- }
4185
- };
4186
-
4187
4004
  // src/core/commerce/merge-catalog-stock.ts
4188
4005
  function mergeProductDetailWithStock(catalog, snapshot) {
4189
4006
  const snapshotByVariantId = new Map(