@01.software/sdk 0.33.0 → 0.35.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 (76) hide show
  1. package/README.md +214 -22
  2. package/dist/analytics/react.cjs.map +1 -1
  3. package/dist/analytics/react.js.map +1 -1
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js.map +1 -1
  6. package/dist/client.cjs +342 -27
  7. package/dist/client.cjs.map +1 -1
  8. package/dist/client.d.cts +7 -6
  9. package/dist/client.d.ts +7 -6
  10. package/dist/client.js +342 -27
  11. package/dist/client.js.map +1 -1
  12. package/dist/{collection-client-De6eKW1J.d.cts → collection-client-CR2B8c1v.d.cts} +7 -3
  13. package/dist/{collection-client-B6SlhzIP.d.ts → collection-client-DkREjhQ9.d.ts} +7 -3
  14. package/dist/{const-sPR2IkCe.d.cts → const-BTvdrXtY.d.cts} +4 -4
  15. package/dist/{const-DwmSDeWq.d.ts → const-CdqCauHQ.d.ts} +4 -4
  16. package/dist/errors.cjs +300 -0
  17. package/dist/errors.cjs.map +1 -0
  18. package/dist/{index-BGEhoDUs.d.cts → errors.d.cts} +13 -1
  19. package/dist/{index-BGEhoDUs.d.ts → errors.d.ts} +13 -1
  20. package/dist/errors.js +277 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/index-CjA3U6X3.d.cts +186 -0
  23. package/dist/index-DK8_NXkh.d.ts +186 -0
  24. package/dist/index.cjs +1402 -177
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +75 -10
  27. package/dist/index.d.ts +75 -10
  28. package/dist/index.js +1402 -177
  29. package/dist/index.js.map +1 -1
  30. package/dist/{payload-types-dkeQyrDC.d.cts → payload-types-C7tb7Xbs.d.cts} +208 -52
  31. package/dist/{payload-types-dkeQyrDC.d.ts → payload-types-C7tb7Xbs.d.ts} +208 -52
  32. package/dist/query.cjs +195 -36
  33. package/dist/query.cjs.map +1 -1
  34. package/dist/query.d.cts +45 -18
  35. package/dist/query.d.ts +45 -18
  36. package/dist/query.js +195 -36
  37. package/dist/query.js.map +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.map +1 -1
  42. package/dist/{server-CrsPyqEc.d.cts → server-nXOezi4b.d.cts} +22 -6
  43. package/dist/{server-CrsPyqEc.d.ts → server-nXOezi4b.d.ts} +22 -6
  44. package/dist/server.cjs +440 -33
  45. package/dist/server.cjs.map +1 -1
  46. package/dist/server.d.cts +11 -179
  47. package/dist/server.d.ts +11 -179
  48. package/dist/server.js +440 -33
  49. package/dist/server.js.map +1 -1
  50. package/dist/{types-Cel_4L9t.d.ts → types-1ylMrCuW.d.ts} +1 -1
  51. package/dist/{types-B3YT092I.d.cts → types-Bx558PU6.d.cts} +1 -1
  52. package/dist/{types-BHh0YLmq.d.ts → types-Byo_Rty4.d.ts} +705 -69
  53. package/dist/{types-BZKxss8Y.d.cts → types-DDhtZI6E.d.cts} +705 -69
  54. package/dist/ui/canvas/server.cjs +231 -38
  55. package/dist/ui/canvas/server.cjs.map +1 -1
  56. package/dist/ui/canvas/server.d.cts +1 -1
  57. package/dist/ui/canvas/server.d.ts +1 -1
  58. package/dist/ui/canvas/server.js +221 -38
  59. package/dist/ui/canvas/server.js.map +1 -1
  60. package/dist/ui/canvas.cjs +320 -257
  61. package/dist/ui/canvas.cjs.map +1 -1
  62. package/dist/ui/canvas.d.cts +5 -19
  63. package/dist/ui/canvas.d.ts +5 -19
  64. package/dist/ui/canvas.js +323 -260
  65. package/dist/ui/canvas.js.map +1 -1
  66. package/dist/ui/form.d.cts +1 -1
  67. package/dist/ui/form.d.ts +1 -1
  68. package/dist/ui/video.d.cts +1 -1
  69. package/dist/ui/video.d.ts +1 -1
  70. package/dist/webhook.cjs +2 -1
  71. package/dist/webhook.cjs.map +1 -1
  72. package/dist/webhook.d.cts +20 -179
  73. package/dist/webhook.d.ts +20 -179
  74. package/dist/webhook.js +2 -1
  75. package/dist/webhook.js.map +1 -1
  76. package/package.json +12 -3
package/dist/query.cjs CHANGED
@@ -29,6 +29,7 @@ __export(query_exports, {
29
29
  createServerQueryHooks: () => createServerQueryHooks,
30
30
  customerKeys: () => customerKeys,
31
31
  getQueryClient: () => getQueryClient,
32
+ getStorefrontQueryClient: () => getStorefrontQueryClient,
32
33
  productKeys: () => productKeys
33
34
  });
34
35
  module.exports = __toCommonJS(query_exports);
@@ -53,6 +54,7 @@ function makeQueryClient() {
53
54
  });
54
55
  }
55
56
  var browserQueryClient;
57
+ var browserStorefrontQueryClient;
56
58
  function getQueryClient() {
57
59
  if (import_react_query.isServer) {
58
60
  return makeQueryClient();
@@ -62,6 +64,30 @@ function getQueryClient() {
62
64
  }
63
65
  return browserQueryClient;
64
66
  }
67
+ var STOREFRONT_STALE_TIME_MS = 6e4;
68
+ function makeStorefrontQueryClient() {
69
+ return new import_react_query.QueryClient({
70
+ defaultOptions: {
71
+ queries: {
72
+ staleTime: STOREFRONT_STALE_TIME_MS,
73
+ refetchOnWindowFocus: false
74
+ },
75
+ dehydrate: {
76
+ shouldDehydrateQuery: (query) => (0, import_react_query.defaultShouldDehydrateQuery)(query) || query.state.status === "pending",
77
+ shouldRedactErrors: () => false
78
+ }
79
+ }
80
+ });
81
+ }
82
+ function getStorefrontQueryClient() {
83
+ if (import_react_query.isServer) {
84
+ return makeStorefrontQueryClient();
85
+ }
86
+ if (!browserStorefrontQueryClient) {
87
+ browserStorefrontQueryClient = makeStorefrontQueryClient();
88
+ }
89
+ return browserStorefrontQueryClient;
90
+ }
65
91
 
66
92
  // src/core/query/query-keys.ts
67
93
  function collectionKeys(collection) {
@@ -81,7 +107,9 @@ var customerKeys = {
81
107
  };
82
108
  var productKeys = {
83
109
  listingGroups: (options) => ["products", "listing-groups", "list", options],
110
+ listingGroupsCatalog: (options) => ["products", "listing-groups", "catalog", options],
84
111
  listingGroupsInfinite: (options) => ["products", "listing-groups", "infinite", options],
112
+ listingGroupsCatalogInfinite: (options) => ["products", "listing-groups", "catalog", "infinite", options],
85
113
  detail: (params) => ["products", "detail", params],
86
114
  detailAll: () => ["products", "detail"]
87
115
  };
@@ -341,7 +369,7 @@ var CollectionHooks = class {
341
369
  // src/core/query/customer-hooks.ts
342
370
  var import_react_query3 = require("@tanstack/react-query");
343
371
 
344
- // src/core/internal/errors/index.ts
372
+ // src/core/errors.ts
345
373
  var SDKError = class extends Error {
346
374
  constructor(code, message, status, details, userMessage, suggestion, requestId) {
347
375
  super(message);
@@ -597,6 +625,42 @@ var CustomerHooks = class {
597
625
 
598
626
  // src/core/query/query-hooks.ts
599
627
  var import_react_query4 = require("@tanstack/react-query");
628
+
629
+ // src/core/internal/utils/query-string.ts
630
+ function appendListingGroupsQuerySearchParams(search, options) {
631
+ if (options?.page != null) search.set("page", String(options.page));
632
+ if (options?.limit != null) search.set("limit", String(options.limit));
633
+ if (options?.sort != null) {
634
+ const sort = options.sort;
635
+ search.set(
636
+ "sort",
637
+ Array.isArray(sort) ? sort.join(",") : sort
638
+ );
639
+ }
640
+ if (options?.where != null) {
641
+ search.set("whereJson", JSON.stringify(options.where));
642
+ }
643
+ }
644
+ function listingGroupsQueryCatalogUrl(options) {
645
+ const search = new URLSearchParams();
646
+ appendListingGroupsQuerySearchParams(search, options);
647
+ const query = search.toString();
648
+ return `/api/products/listing-groups/query/catalog${query ? `?${query}` : ""}`;
649
+ }
650
+
651
+ // src/core/query/query-hooks.ts
652
+ var LISTING_GROUPS_QUERY_PATH = "/api/products/listing-groups/query";
653
+ function fetchProductListingGroupsQuery(collectionClient, queryOptions) {
654
+ return collectionClient.requestFindEndpoint(
655
+ LISTING_GROUPS_QUERY_PATH,
656
+ { options: queryOptions }
657
+ );
658
+ }
659
+ function fetchProductListingGroupsCatalogQuery(collectionClient, queryOptions) {
660
+ return collectionClient.requestFindEndpointGet(
661
+ listingGroupsQueryCatalogUrl(queryOptions)
662
+ );
663
+ }
600
664
  var QueryHooks = class extends CollectionHooks {
601
665
  constructor(queryClient, collectionClient, customerAuth, commerceClient) {
602
666
  super(queryClient, collectionClient);
@@ -622,9 +686,21 @@ var QueryHooks = class extends CollectionHooks {
622
686
  const { placeholderData, ...restOptions } = options ?? {};
623
687
  return (0, import_react_query4.useQuery)({
624
688
  queryKey: productKeys.listingGroups(queryOptions),
625
- queryFn: async () => this.collectionClient.requestFindEndpoint(
626
- "/api/products/listing-groups/query",
627
- { options: queryOptions }
689
+ queryFn: async () => fetchProductListingGroupsQuery(this.collectionClient, queryOptions),
690
+ ...restOptions,
691
+ ...placeholderData !== void 0 && {
692
+ placeholderData
693
+ }
694
+ });
695
+ }
696
+ useProductListingGroupsCatalogQuery(params, options) {
697
+ const queryOptions = params.options;
698
+ const { placeholderData, ...restOptions } = options ?? {};
699
+ return (0, import_react_query4.useQuery)({
700
+ queryKey: productKeys.listingGroupsCatalog(queryOptions),
701
+ queryFn: async () => fetchProductListingGroupsCatalogQuery(
702
+ this.collectionClient,
703
+ queryOptions
628
704
  ),
629
705
  ...restOptions,
630
706
  ...placeholderData !== void 0 && {
@@ -636,9 +712,17 @@ var QueryHooks = class extends CollectionHooks {
636
712
  const queryOptions = params.options;
637
713
  return (0, import_react_query4.useSuspenseQuery)({
638
714
  queryKey: productKeys.listingGroups(queryOptions),
639
- queryFn: async () => this.collectionClient.requestFindEndpoint(
640
- "/api/products/listing-groups/query",
641
- { options: queryOptions }
715
+ queryFn: async () => fetchProductListingGroupsQuery(this.collectionClient, queryOptions),
716
+ ...options
717
+ });
718
+ }
719
+ useSuspenseProductListingGroupsCatalogQuery(params, options) {
720
+ const queryOptions = params.options;
721
+ return (0, import_react_query4.useSuspenseQuery)({
722
+ queryKey: productKeys.listingGroupsCatalog(queryOptions),
723
+ queryFn: async () => fetchProductListingGroupsCatalogQuery(
724
+ this.collectionClient,
725
+ queryOptions
642
726
  ),
643
727
  ...options
644
728
  });
@@ -650,12 +734,28 @@ var QueryHooks = class extends CollectionHooks {
650
734
  } = params;
651
735
  return (0, import_react_query4.useInfiniteQuery)({
652
736
  queryKey: productKeys.listingGroupsInfinite(queryOptions),
653
- queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
654
- "/api/products/listing-groups/query",
655
- {
656
- options: { ...queryOptions, page: pageParam, limit: pageSize }
657
- }
658
- ),
737
+ queryFn: async ({ pageParam }) => fetchProductListingGroupsQuery(this.collectionClient, {
738
+ ...queryOptions,
739
+ page: pageParam,
740
+ limit: pageSize
741
+ }),
742
+ initialPageParam: 1,
743
+ getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
744
+ ...options
745
+ });
746
+ }
747
+ useInfiniteProductListingGroupsCatalogQuery(params, options) {
748
+ const {
749
+ options: queryOptions,
750
+ pageSize = 20
751
+ } = params;
752
+ return (0, import_react_query4.useInfiniteQuery)({
753
+ queryKey: productKeys.listingGroupsCatalogInfinite(queryOptions),
754
+ queryFn: async ({ pageParam }) => fetchProductListingGroupsCatalogQuery(this.collectionClient, {
755
+ ...queryOptions,
756
+ page: pageParam,
757
+ limit: pageSize
758
+ }),
659
759
  initialPageParam: 1,
660
760
  getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
661
761
  ...options
@@ -668,12 +768,28 @@ var QueryHooks = class extends CollectionHooks {
668
768
  } = params;
669
769
  return (0, import_react_query4.useSuspenseInfiniteQuery)({
670
770
  queryKey: productKeys.listingGroupsInfinite(queryOptions),
671
- queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
672
- "/api/products/listing-groups/query",
673
- {
674
- options: { ...queryOptions, page: pageParam, limit: pageSize }
675
- }
676
- ),
771
+ queryFn: async ({ pageParam }) => fetchProductListingGroupsQuery(this.collectionClient, {
772
+ ...queryOptions,
773
+ page: pageParam,
774
+ limit: pageSize
775
+ }),
776
+ initialPageParam: 1,
777
+ getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
778
+ ...options
779
+ });
780
+ }
781
+ useSuspenseInfiniteProductListingGroupsCatalogQuery(params, options) {
782
+ const {
783
+ options: queryOptions,
784
+ pageSize = 20
785
+ } = params;
786
+ return (0, import_react_query4.useSuspenseInfiniteQuery)({
787
+ queryKey: productKeys.listingGroupsCatalogInfinite(queryOptions),
788
+ queryFn: async ({ pageParam }) => fetchProductListingGroupsCatalogQuery(this.collectionClient, {
789
+ ...queryOptions,
790
+ page: pageParam,
791
+ limit: pageSize
792
+ }),
677
793
  initialPageParam: 1,
678
794
  getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
679
795
  ...options
@@ -683,9 +799,17 @@ var QueryHooks = class extends CollectionHooks {
683
799
  const queryOptions = params.options;
684
800
  return this.queryClient.prefetchQuery({
685
801
  queryKey: productKeys.listingGroups(queryOptions),
686
- queryFn: async () => this.collectionClient.requestFindEndpoint(
687
- "/api/products/listing-groups/query",
688
- { options: queryOptions }
802
+ queryFn: async () => fetchProductListingGroupsQuery(this.collectionClient, queryOptions),
803
+ ...options
804
+ });
805
+ }
806
+ async prefetchProductListingGroupsCatalogQuery(params, options) {
807
+ const queryOptions = params.options;
808
+ return this.queryClient.prefetchQuery({
809
+ queryKey: productKeys.listingGroupsCatalog(queryOptions),
810
+ queryFn: async () => fetchProductListingGroupsCatalogQuery(
811
+ this.collectionClient,
812
+ queryOptions
689
813
  ),
690
814
  ...options
691
815
  });
@@ -697,12 +821,29 @@ var QueryHooks = class extends CollectionHooks {
697
821
  } = params;
698
822
  return this.queryClient.prefetchInfiniteQuery({
699
823
  queryKey: productKeys.listingGroupsInfinite(queryOptions),
700
- queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
701
- "/api/products/listing-groups/query",
702
- {
703
- options: { ...queryOptions, page: pageParam, limit: pageSize }
704
- }
705
- ),
824
+ queryFn: async ({ pageParam }) => fetchProductListingGroupsQuery(this.collectionClient, {
825
+ ...queryOptions,
826
+ page: pageParam,
827
+ limit: pageSize
828
+ }),
829
+ initialPageParam: 1,
830
+ getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
831
+ pages: options?.pages ?? 1,
832
+ staleTime: options?.staleTime
833
+ });
834
+ }
835
+ async prefetchInfiniteProductListingGroupsCatalogQuery(params, options) {
836
+ const {
837
+ options: queryOptions,
838
+ pageSize = 20
839
+ } = params;
840
+ return this.queryClient.prefetchInfiniteQuery({
841
+ queryKey: productKeys.listingGroupsCatalogInfinite(queryOptions),
842
+ queryFn: async ({ pageParam }) => fetchProductListingGroupsCatalogQuery(this.collectionClient, {
843
+ ...queryOptions,
844
+ page: pageParam,
845
+ limit: pageSize
846
+ }),
706
847
  initialPageParam: 1,
707
848
  getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
708
849
  pages: options?.pages ?? 1,
@@ -711,11 +852,13 @@ var QueryHooks = class extends CollectionHooks {
711
852
  }
712
853
  useProductDetail(params, options) {
713
854
  const discriminator = "slug" in params ? params.slug : params.id;
714
- const enabled = options?.enabled !== false && Boolean(discriminator);
855
+ const { enabled, ...restOptions } = options ?? {};
856
+ const queryEnabled = enabled !== false && Boolean(discriminator);
715
857
  return (0, import_react_query4.useQuery)({
716
858
  queryKey: productKeys.detail(params),
717
859
  queryFn: () => this._commerce.product.detail(params),
718
- enabled
860
+ enabled: queryEnabled,
861
+ ...restOptions
719
862
  });
720
863
  }
721
864
  useProductDetailBySlug(slug, options) {
@@ -1097,9 +1240,12 @@ function resolveApiUrl(apiUrl) {
1097
1240
 
1098
1241
  // src/core/internal/utils/http.ts
1099
1242
  var DEFAULT_TIMEOUT = 3e4;
1243
+ var STOREFRONT_BROWSER_TIMEOUT = 15e3;
1100
1244
  var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
1101
1245
  var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
1102
1246
  var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
1247
+ var DEFAULT_MAX_RETRIES = 3;
1248
+ var STOREFRONT_BROWSER_MAX_RETRIES = 1;
1103
1249
  function debugLog(debug, type, message, data) {
1104
1250
  if (!debug) return;
1105
1251
  const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
@@ -1292,15 +1438,18 @@ async function httpFetch(url, options) {
1292
1438
  publishableKey,
1293
1439
  secretKey,
1294
1440
  customerToken,
1295
- timeout = DEFAULT_TIMEOUT,
1441
+ timeout: timeoutOption = DEFAULT_TIMEOUT,
1296
1442
  debug,
1297
1443
  retry,
1298
1444
  onUnauthorized,
1299
1445
  ...requestInit
1300
1446
  } = options || {};
1301
1447
  const baseUrl = resolveApiUrl(apiUrl);
1448
+ const method = (requestInit.method || "GET").toUpperCase();
1449
+ const isPublishableKeyBrowserGet = typeof window !== "undefined" && !secretKey && !customerToken && Boolean(publishableKey) && SAFE_METHODS.includes(method);
1450
+ const timeout = timeoutOption === DEFAULT_TIMEOUT && isPublishableKeyBrowserGet ? STOREFRONT_BROWSER_TIMEOUT : timeoutOption;
1302
1451
  const retryConfig = {
1303
- maxRetries: retry?.maxRetries ?? 3,
1452
+ maxRetries: retry?.maxRetries ?? (isPublishableKeyBrowserGet ? STOREFRONT_BROWSER_MAX_RETRIES : DEFAULT_MAX_RETRIES),
1304
1453
  retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
1305
1454
  retryDelay: retry?.retryDelay ?? ((attempt) => Math.min(1e3 * 2 ** attempt, 1e4))
1306
1455
  };
@@ -1408,8 +1557,8 @@ async function httpFetch(url, options) {
1408
1557
  ),
1409
1558
  requestId
1410
1559
  );
1411
- const method = (requestInit.method || "GET").toUpperCase();
1412
- if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method) && retryConfig.retryableStatuses.includes(response.status)) {
1560
+ const method2 = (requestInit.method || "GET").toUpperCase();
1561
+ if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && retryConfig.retryableStatuses.includes(response.status)) {
1413
1562
  lastError = error;
1414
1563
  const retryDelay = retryConfig.retryDelay(attempt);
1415
1564
  debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
@@ -1421,8 +1570,8 @@ async function httpFetch(url, options) {
1421
1570
  return response;
1422
1571
  } catch (error) {
1423
1572
  debugLog(debug, "error", url, error);
1424
- const method = (requestInit.method || "GET").toUpperCase();
1425
- const isSafe = SAFE_METHODS.includes(method);
1573
+ const method2 = (requestInit.method || "GET").toUpperCase();
1574
+ const isSafe = SAFE_METHODS.includes(method2);
1426
1575
  if (error instanceof Error && error.name === "AbortError") {
1427
1576
  const timeoutError = createTimeoutError(
1428
1577
  `Request timed out after ${timeout}ms.`,
@@ -1655,6 +1804,16 @@ var CollectionClient = class extends HttpClient {
1655
1804
  });
1656
1805
  return this.parseFindResponse(response);
1657
1806
  }
1807
+ /**
1808
+ * Find-like response from a cacheable GET custom endpoint.
1809
+ */
1810
+ async requestFindEndpointGet(endpoint) {
1811
+ const response = await this.fetchWithTracking(endpoint, {
1812
+ ...this.defaultOptions,
1813
+ method: "GET"
1814
+ });
1815
+ return this.parseFindResponse(response);
1816
+ }
1658
1817
  /**
1659
1818
  * Find document by ID
1660
1819
  * GET /api/{collection}/{id}