@01.software/sdk 0.41.0 → 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 +222 -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-Bymfni8u.d.cts → collection-client-B-qVIBnJ.d.cts} +5 -5
  22. package/dist/{collection-client-CN4lj6gi.d.ts → collection-client-BhCMwIus.d.ts} +5 -5
  23. package/dist/{const-4BUtUdGU.d.cts → const-BiDujixF.d.cts} +1 -1
  24. package/dist/{const-ymprfiPf.d.ts → const-pmHlwm3E.d.ts} +1 -1
  25. package/dist/{index-w36lpSkU.d.ts → index-B1UBDaKz.d.ts} +3 -3
  26. package/dist/{index-Dquv4xTL.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-DC0xzR9i.d.cts → payload-types-C7Ul4ElL.d.cts} +181 -118
  34. package/dist/{payload-types-DC0xzR9i.d.ts → payload-types-C7Ul4ElL.d.ts} +181 -118
  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 +236 -50
  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 +236 -50
  48. package/dist/server.js.map +1 -1
  49. package/dist/{types-CHrzs2GB.d.ts → types-BL7M-EUV.d.cts} +140 -14
  50. package/dist/{types-Bh2p-EMc.d.ts → types-Bf2iCjy8.d.ts} +1 -1
  51. package/dist/{types-BvpjooU-.d.cts → types-ChV1t4ei.d.cts} +1 -1
  52. package/dist/{types-Bl-m9ttd.d.cts → types-D5dSNIGs.d.ts} +140 -14
  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 +3 -3
package/dist/client.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { R as ReadOnlyCollectionClient } from './collection-client-Bymfni8u.cjs';
2
- import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as ClientState, e as ClientConfig } from './types-Bl-m9ttd.cjs';
3
- export { A as AddItemParams, f as ApiQueryOptions, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, j as ClientMetadata, k as ContentClientOptions, D as DebugConfig, l as DeepPartial, m as ExtractArrayType, P as PayloadFindResponse, n as PayloadMutationResponse, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, x as RetryConfig, y as RootClient, y as RootClientType, z as RootCollectionClient, B as RootReadOnlyQueryBuilder, S as Sort, F as StorefrontContentListOptions, G as StorefrontContentReference, H as StorefrontGalleryItem, I as StorefrontGalleryItemsListOptions, J as StorefrontGalleryItemsSort, K as StorefrontLink, L as StorefrontLinksListOptions, M as StorefrontLinksSort, U as UpdateItemParams, W as Where } from './types-Bl-m9ttd.cjs';
4
- import './payload-types-DC0xzR9i.cjs';
5
- export { C as Collection, P as PublicCollection } from './const-4BUtUdGU.cjs';
1
+ import { R as ReadOnlyCollectionClient } from './collection-client-B-qVIBnJ.cjs';
2
+ import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as ClientState, e as ClientConfig } from './types-BL7M-EUV.cjs';
3
+ export { A as AddItemParams, f as ApiQueryOptions, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, j as ClientMetadata, k as ContentClientOptions, D as DebugConfig, l as DeepPartial, m as ExtractArrayType, P as PayloadFindResponse, n as PayloadMutationResponse, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, x as RetryConfig, y as RootClient, y as RootClientType, z as RootCollectionClient, B as RootReadOnlyQueryBuilder, S as Sort, F as StorefrontContentListOptions, G as StorefrontContentReference, H as StorefrontGalleryItem, I as StorefrontGalleryItemsListOptions, J as StorefrontGalleryItemsSort, K as StorefrontLink, L as StorefrontLinksListOptions, M as StorefrontLinksSort, U as UpdateItemParams, W as Where } from './types-BL7M-EUV.cjs';
4
+ import './payload-types-C7Ul4ElL.cjs';
5
+ export { C as Collection, P as PublicCollection } from './const-BiDujixF.cjs';
6
6
  import './metadata.cjs';
7
- import './types-BvpjooU-.cjs';
7
+ import './types-ChV1t4ei.cjs';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
package/dist/client.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { R as ReadOnlyCollectionClient } from './collection-client-CN4lj6gi.js';
2
- import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as ClientState, e as ClientConfig } from './types-CHrzs2GB.js';
3
- export { A as AddItemParams, f as ApiQueryOptions, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, j as ClientMetadata, k as ContentClientOptions, D as DebugConfig, l as DeepPartial, m as ExtractArrayType, P as PayloadFindResponse, n as PayloadMutationResponse, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, x as RetryConfig, y as RootClient, y as RootClientType, z as RootCollectionClient, B as RootReadOnlyQueryBuilder, S as Sort, F as StorefrontContentListOptions, G as StorefrontContentReference, H as StorefrontGalleryItem, I as StorefrontGalleryItemsListOptions, J as StorefrontGalleryItemsSort, K as StorefrontLink, L as StorefrontLinksListOptions, M as StorefrontLinksSort, U as UpdateItemParams, W as Where } from './types-CHrzs2GB.js';
4
- import './payload-types-DC0xzR9i.js';
5
- export { C as Collection, P as PublicCollection } from './const-ymprfiPf.js';
1
+ import { R as ReadOnlyCollectionClient } from './collection-client-BhCMwIus.js';
2
+ import { C as CommerceClient, a as CommunityClient, b as ContentClient, E as EventsClient, c as CustomerNamespace, d as ClientState, e as ClientConfig } from './types-D5dSNIGs.js';
3
+ export { A as AddItemParams, f as ApiQueryOptions, g as ApplyDiscountParams, h as CheckoutParams, i as ClearCartParams, j as ClientMetadata, k as ContentClientOptions, D as DebugConfig, l as DeepPartial, m as ExtractArrayType, P as PayloadFindResponse, n as PayloadMutationResponse, o as PublicCart, p as PublicCartItem, q as PublicCartReference, r as PublicMediaAsset, s as PublicMediaSize, t as PublicOrder, u as PublicOrderItem, v as PublicOrderReference, R as RemoveDiscountParams, w as RemoveItemParams, x as RetryConfig, y as RootClient, y as RootClientType, z as RootCollectionClient, B as RootReadOnlyQueryBuilder, S as Sort, F as StorefrontContentListOptions, G as StorefrontContentReference, H as StorefrontGalleryItem, I as StorefrontGalleryItemsListOptions, J as StorefrontGalleryItemsSort, K as StorefrontLink, L as StorefrontLinksListOptions, M as StorefrontLinksSort, U as UpdateItemParams, W as Where } from './types-D5dSNIGs.js';
4
+ import './payload-types-C7Ul4ElL.js';
5
+ export { C as Collection, P as PublicCollection } from './const-pmHlwm3E.js';
6
6
  import './metadata.js';
7
- import './types-Bh2p-EMc.js';
7
+ import './types-Bf2iCjy8.js';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
package/dist/client.js CHANGED
@@ -70,6 +70,26 @@ var TimeoutError = class extends SDKError {
70
70
  this.name = "TimeoutError";
71
71
  }
72
72
  };
73
+ var GoneError = class extends SDKError {
74
+ constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
75
+ super("GONE_ERROR", message, 410, details, userMessage, suggestion);
76
+ this.name = "GoneError";
77
+ }
78
+ };
79
+ var ServiceUnavailableError = class extends SDKError {
80
+ constructor(message = "Service temporarily unavailable.", retryAfter, details, userMessage, suggestion) {
81
+ super(
82
+ "SERVICE_UNAVAILABLE_ERROR",
83
+ message,
84
+ 503,
85
+ details,
86
+ userMessage,
87
+ suggestion
88
+ );
89
+ this.name = "ServiceUnavailableError";
90
+ this.retryAfter = retryAfter;
91
+ }
92
+ };
73
93
  var UsageLimitError = class extends SDKError {
74
94
  constructor(message, usage, details, userMessage, suggestion) {
75
95
  super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
@@ -151,6 +171,14 @@ var createValidationError = (message, details, userMessage, suggestion, status)
151
171
  var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
152
172
  var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
153
173
  var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
174
+ var createGoneError = (message, details, userMessage, suggestion) => new GoneError(message, details, userMessage, suggestion);
175
+ var createServiceUnavailableError = (message, retryAfter, details, userMessage, suggestion) => new ServiceUnavailableError(
176
+ message,
177
+ retryAfter,
178
+ details,
179
+ userMessage,
180
+ suggestion
181
+ );
154
182
  var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
155
183
  var createAuthError = (message, details, userMessage, suggestion, requestId) => new AuthError(message, details, userMessage, suggestion, requestId);
156
184
  var createPermissionError = (message, details, userMessage, suggestion, requestId) => new PermissionError(message, details, userMessage, suggestion, requestId);
@@ -175,7 +203,7 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
175
203
  return publishableKey ?? "";
176
204
  }
177
205
 
178
- // src/core/client/types.ts
206
+ // src/core/internal/utils/api-url.ts
179
207
  function resolveApiUrl(apiUrl) {
180
208
  if (apiUrl) {
181
209
  return apiUrl.replace(/\/$/, "");
@@ -192,7 +220,7 @@ function resolveApiUrl(apiUrl) {
192
220
  // src/core/internal/utils/http.ts
193
221
  var DEFAULT_TIMEOUT = 3e4;
194
222
  var STOREFRONT_BROWSER_TIMEOUT = 15e3;
195
- var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
223
+ var DEFAULT_RETRYABLE_STATUSES = [408, 500, 502, 503, 504];
196
224
  var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
197
225
  var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
198
226
  var DEFAULT_MAX_RETRIES = 3;
@@ -309,7 +337,12 @@ function attachRequestId(err, id) {
309
337
  if (id) err.requestId = id;
310
338
  return err;
311
339
  }
312
- function createHttpStatusError(status, parsed, details, requestId) {
340
+ function parseRetryAfter(response) {
341
+ const raw = response.headers.get("Retry-After");
342
+ if (!raw) return void 0;
343
+ return parseInt(raw, 10) || void 0;
344
+ }
345
+ function mapResponseToError(status, parsed, details, requestId, retryAfter) {
313
346
  const errorDetails = {
314
347
  ...details,
315
348
  ...parsed.errors && { errors: parsed.errors },
@@ -372,6 +405,41 @@ function createHttpStatusError(status, parsed, details, requestId) {
372
405
  requestId
373
406
  );
374
407
  }
408
+ if (status === 410) {
409
+ return attachRequestId(
410
+ createGoneError(
411
+ parsed.errorMessage,
412
+ errorDetails,
413
+ parsed.userMessage,
414
+ suggestion
415
+ ),
416
+ requestId
417
+ );
418
+ }
419
+ if (status === 429) {
420
+ return attachRequestId(
421
+ createRateLimitError(
422
+ parsed.errorMessage,
423
+ retryAfter,
424
+ errorDetails,
425
+ parsed.userMessage,
426
+ suggestion
427
+ ),
428
+ requestId
429
+ );
430
+ }
431
+ if (status === 503) {
432
+ return attachRequestId(
433
+ createServiceUnavailableError(
434
+ parsed.errorMessage,
435
+ retryAfter,
436
+ errorDetails,
437
+ parsed.userMessage,
438
+ suggestion
439
+ ),
440
+ requestId
441
+ );
442
+ }
375
443
  return attachRequestId(
376
444
  createNetworkError(
377
445
  parsed.errorMessage,
@@ -490,26 +558,17 @@ async function httpFetch(url, options) {
490
558
  method: requestInit.method || "GET",
491
559
  attempt: attempt + 1
492
560
  };
493
- if (NON_RETRYABLE_STATUSES.includes(response.status)) {
494
- throw createHttpStatusError(
495
- response.status,
496
- parsed,
497
- details,
498
- requestId
499
- );
500
- }
501
- const error = attachRequestId(
502
- createNetworkError(
503
- parsed.errorMessage,
504
- response.status,
505
- details,
506
- parsed.userMessage,
507
- getErrorSuggestion(response.status)
508
- ),
509
- requestId
561
+ const retryAfter = parseRetryAfter(response);
562
+ const error = mapResponseToError(
563
+ response.status,
564
+ parsed,
565
+ details,
566
+ requestId,
567
+ retryAfter
510
568
  );
511
569
  const method2 = (requestInit.method || "GET").toUpperCase();
512
- if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && retryConfig.retryableStatuses.includes(response.status)) {
570
+ const isTerminal = error instanceof RateLimitError || error instanceof UsageLimitError;
571
+ if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && !isTerminal && !NON_RETRYABLE_STATUSES.includes(response.status) && retryConfig.retryableStatuses.includes(response.status)) {
513
572
  lastError = error;
514
573
  const retryDelay = retryConfig.retryDelay(attempt);
515
574
  debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
@@ -1519,42 +1578,123 @@ var CustomerNamespace = class {
1519
1578
  }
1520
1579
  };
1521
1580
 
1581
+ // src/core/api/endpoints.ts
1582
+ var COMMERCE_ENDPOINTS = {
1583
+ orders: {
1584
+ create: "/api/orders/create",
1585
+ update: "/api/orders/update",
1586
+ confirmPayment: "/api/orders/confirm-payment",
1587
+ byPayment: "/api/orders/by-payment",
1588
+ cancel: "/api/orders/cancel",
1589
+ resolveCancelRefund: "/api/orders/resolve-cancel-refund",
1590
+ checkout: "/api/orders/checkout",
1591
+ createFulfillment: "/api/orders/create-fulfillment",
1592
+ updateFulfillment: "/api/orders/update-fulfillment"
1593
+ },
1594
+ transactions: {
1595
+ update: "/api/transactions/update"
1596
+ },
1597
+ returns: {
1598
+ create: "/api/returns/create",
1599
+ update: "/api/returns/update",
1600
+ returnRefund: "/api/returns/return-refund"
1601
+ },
1602
+ fulfillmentOrders: {
1603
+ prepare: "/api/fulfillment-orders/prepare-fulfillment-order"
1604
+ },
1605
+ fulfillments: {
1606
+ bulkImport: "/api/fulfillments/bulk-import"
1607
+ },
1608
+ carts: {
1609
+ mine: "/api/carts/mine",
1610
+ merge: "/api/carts/merge",
1611
+ addItem: "/api/carts/add-item",
1612
+ updateItem: "/api/carts/update-item",
1613
+ removeItem: "/api/carts/remove-item",
1614
+ applyDiscount: "/api/carts/apply-discount",
1615
+ removeDiscount: "/api/carts/remove-discount",
1616
+ clear: "/api/carts/clear"
1617
+ }
1618
+ };
1619
+ var COMMERCE_ENDPOINT_PATHS = Object.values(
1620
+ COMMERCE_ENDPOINTS
1621
+ ).flatMap((group) => Object.values(group));
1622
+
1522
1623
  // src/core/api/cart-api.ts
1523
1624
  var CartApi = class extends CustomerScopedApi {
1524
1625
  constructor(options) {
1525
- super("CartApi", options);
1626
+ super("CartApi", { ...options, requiresCredential: false });
1526
1627
  }
1527
1628
  async execute(endpoint, method, body) {
1528
1629
  return this.request(endpoint, { method, body });
1529
1630
  }
1530
- getCart(cartId) {
1631
+ /**
1632
+ * Create a cart and receive its `cartToken`. Store the token and pass it to
1633
+ * every subsequent cart operation.
1634
+ */
1635
+ createCart(params = {}) {
1636
+ return this.execute("/api/carts/create", "POST", params);
1637
+ }
1638
+ getCart(cartToken) {
1639
+ return this.execute("/api/carts/get", "POST", { cartToken });
1640
+ }
1641
+ merge(params) {
1531
1642
  return this.execute(
1532
- `/api/carts/${cartId}?depth=0&joins=false`,
1533
- "GET"
1643
+ COMMERCE_ENDPOINTS.carts.merge,
1644
+ "POST",
1645
+ params
1646
+ );
1647
+ }
1648
+ /**
1649
+ * Resolve the authenticated customer's active cart by JWT (no `cartToken`
1650
+ * required). Returns the cart and its capability handle, or both `null` when
1651
+ * the customer has no active cart. Requires a customer token.
1652
+ */
1653
+ mine() {
1654
+ return this.execute(
1655
+ COMMERCE_ENDPOINTS.carts.mine,
1656
+ "POST",
1657
+ {}
1534
1658
  );
1535
1659
  }
1536
1660
  addItem(params) {
1537
- return this.execute("/api/carts/add-item", "POST", params);
1661
+ return this.execute(
1662
+ COMMERCE_ENDPOINTS.carts.addItem,
1663
+ "POST",
1664
+ params
1665
+ );
1538
1666
  }
1539
1667
  updateItem(params) {
1540
- return this.execute("/api/carts/update-item", "POST", params);
1668
+ return this.execute(
1669
+ COMMERCE_ENDPOINTS.carts.updateItem,
1670
+ "POST",
1671
+ params
1672
+ );
1541
1673
  }
1542
1674
  removeItem(params) {
1543
1675
  return this.execute(
1544
- "/api/carts/remove-item",
1676
+ COMMERCE_ENDPOINTS.carts.removeItem,
1545
1677
  "POST",
1546
1678
  params
1547
1679
  );
1548
1680
  }
1549
1681
  applyDiscount(params) {
1550
- return this.execute("/api/carts/apply-discount", "POST", params);
1682
+ return this.execute(
1683
+ COMMERCE_ENDPOINTS.carts.applyDiscount,
1684
+ "POST",
1685
+ params
1686
+ );
1551
1687
  }
1552
1688
  removeDiscount(params) {
1553
- return this.execute("/api/carts/remove-discount", "POST", params);
1689
+ return this.execute(
1690
+ COMMERCE_ENDPOINTS.carts.removeDiscount,
1691
+ "POST",
1692
+ params
1693
+ );
1554
1694
  }
1555
1695
  clearCart(params) {
1556
1696
  return this.execute(
1557
- "/api/carts/clear",
1697
+ COMMERCE_ENDPOINTS.carts.clear,
1558
1698
  "POST",
1559
1699
  params
1560
1700
  );
@@ -2365,6 +2505,7 @@ function compareVariantOrder(a, b) {
2365
2505
  function getVariantAvailableForSale(variant) {
2366
2506
  if (variant.isActive === false) return false;
2367
2507
  if (variant.isUnlimited) return true;
2508
+ if (variant.inventoryPolicy === "continue") return true;
2368
2509
  return (variant.stock ?? 0) - (variant.reservedStock ?? 0) > 0;
2369
2510
  }
2370
2511
  function isVariantAvailableForSale(variant) {
@@ -2742,13 +2883,16 @@ var CommerceClient = class {
2742
2883
  }
2743
2884
  };
2744
2885
  this.cart = {
2886
+ create: cartApi.createCart.bind(cartApi),
2745
2887
  get: cartApi.getCart.bind(cartApi),
2746
2888
  addItem: cartApi.addItem.bind(cartApi),
2747
2889
  updateItem: cartApi.updateItem.bind(cartApi),
2748
2890
  removeItem: cartApi.removeItem.bind(cartApi),
2749
2891
  applyDiscount: cartApi.applyDiscount.bind(cartApi),
2750
2892
  removeDiscount: cartApi.removeDiscount.bind(cartApi),
2751
- clear: cartApi.clearCart.bind(cartApi)
2893
+ clear: cartApi.clearCart.bind(cartApi),
2894
+ merge: cartApi.merge.bind(cartApi),
2895
+ mine: cartApi.mine.bind(cartApi)
2752
2896
  };
2753
2897
  this.orders = {
2754
2898
  checkout: (params) => {