@01.software/sdk 0.38.0 → 0.39.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 (56) hide show
  1. package/README.md +117 -34
  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 +1219 -5
  7. package/dist/client.cjs.map +1 -1
  8. package/dist/client.d.cts +5 -4
  9. package/dist/client.d.ts +5 -4
  10. package/dist/client.js +1219 -5
  11. package/dist/client.js.map +1 -1
  12. package/dist/{collection-client-BroIWHY1.d.ts → collection-client-CaMgs5KE.d.ts} +14 -8
  13. package/dist/{collection-client-B0J9wMNE.d.cts → collection-client-DVfB0Em1.d.cts} +14 -8
  14. package/dist/errors.cjs +4 -1
  15. package/dist/errors.cjs.map +1 -1
  16. package/dist/errors.js +4 -1
  17. package/dist/errors.js.map +1 -1
  18. package/dist/index.cjs +2787 -2612
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +2787 -2612
  23. package/dist/index.js.map +1 -1
  24. package/dist/query.cjs +241 -58
  25. package/dist/query.cjs.map +1 -1
  26. package/dist/query.d.cts +148 -23
  27. package/dist/query.d.ts +148 -23
  28. package/dist/query.js +241 -58
  29. package/dist/query.js.map +1 -1
  30. package/dist/realtime.cjs +5 -1
  31. package/dist/realtime.cjs.map +1 -1
  32. package/dist/realtime.js +5 -1
  33. package/dist/realtime.js.map +1 -1
  34. package/dist/server.cjs +1149 -1
  35. package/dist/server.cjs.map +1 -1
  36. package/dist/server.d.cts +4 -4
  37. package/dist/server.d.ts +4 -4
  38. package/dist/server.js +1149 -1
  39. package/dist/server.js.map +1 -1
  40. package/dist/storefront-cache.cjs +144 -0
  41. package/dist/storefront-cache.cjs.map +1 -0
  42. package/dist/storefront-cache.d.cts +24 -0
  43. package/dist/storefront-cache.d.ts +24 -0
  44. package/dist/storefront-cache.js +121 -0
  45. package/dist/storefront-cache.js.map +1 -0
  46. package/dist/{types-CIGscmus.d.cts → types-BQo7UdI9.d.cts} +181 -35
  47. package/dist/{types-D2xYdz4P.d.ts → types-CVf8sCZ-.d.ts} +181 -35
  48. package/dist/ui/canvas/server.cjs +5 -1
  49. package/dist/ui/canvas/server.cjs.map +1 -1
  50. package/dist/ui/canvas/server.js +5 -1
  51. package/dist/ui/canvas/server.js.map +1 -1
  52. package/dist/ui/canvas.cjs +5 -1
  53. package/dist/ui/canvas.cjs.map +1 -1
  54. package/dist/ui/canvas.js +5 -1
  55. package/dist/ui/canvas.js.map +1 -1
  56. package/package.json +13 -3
package/dist/query.js CHANGED
@@ -58,6 +58,49 @@ function getStorefrontQueryClient() {
58
58
  }
59
59
 
60
60
  // src/core/query/query-keys.ts
61
+ function nonEmpty(values) {
62
+ return values?.length ? values : void 0;
63
+ }
64
+ function canonicalProductListingPageParams(params = {}, limit) {
65
+ const filters = params.filters;
66
+ const canonicalFilters = {};
67
+ const ids = nonEmpty(filters?.ids);
68
+ if (ids) canonicalFilters.ids = ids;
69
+ const slugs = nonEmpty(filters?.slugs);
70
+ if (slugs) canonicalFilters.slugs = slugs;
71
+ const handles = nonEmpty(filters?.handles);
72
+ if (handles) canonicalFilters.handles = handles;
73
+ const categoryIds = nonEmpty(filters?.categoryIds);
74
+ if (categoryIds) canonicalFilters.categoryIds = categoryIds;
75
+ const tagIds = nonEmpty(filters?.tagIds);
76
+ if (tagIds) canonicalFilters.tagIds = tagIds;
77
+ if (filters?.price?.min != null || filters?.price?.max != null) {
78
+ canonicalFilters.price = {
79
+ ...filters.price.min != null && { min: filters.price.min },
80
+ ...filters.price.max != null && { max: filters.price.max }
81
+ };
82
+ }
83
+ if (filters?.availableForSale != null) {
84
+ canonicalFilters.availableForSale = filters.availableForSale;
85
+ }
86
+ const search = params.search?.trim();
87
+ return {
88
+ mode: params.mode ?? "catalog",
89
+ ...params.page != null && { page: params.page },
90
+ ...limit != null ? { limit } : params.limit != null ? { limit: params.limit } : {},
91
+ ...search && { search },
92
+ ...params.sort != null && { sort: params.sort },
93
+ ...Object.keys(canonicalFilters).length > 0 && {
94
+ filters: canonicalFilters
95
+ },
96
+ ...params.basePath != null && { basePath: params.basePath },
97
+ ...params.trailingSlash != null && { trailingSlash: params.trailingSlash },
98
+ ...params.emit != null && { emit: params.emit },
99
+ ...params.preferCompleteVariantFromHint != null && {
100
+ preferCompleteVariantFromHint: params.preferCompleteVariantFromHint
101
+ }
102
+ };
103
+ }
61
104
  function collectionKeys(collection) {
62
105
  return {
63
106
  all: [collection],
@@ -66,7 +109,11 @@ function collectionKeys(collection) {
66
109
  details: () => [collection, "detail"],
67
110
  detail: (id, options) => [collection, "detail", id, options],
68
111
  infinites: () => [collection, "infinite"],
69
- infinite: (options) => [collection, "infinite", options]
112
+ infinite: (options, pageSize) => [
113
+ collection,
114
+ "infinite",
115
+ pageSize === void 0 ? options : { ...options, limit: pageSize }
116
+ ]
70
117
  };
71
118
  }
72
119
  var customerKeys = {
@@ -76,8 +123,29 @@ var customerKeys = {
76
123
  var productKeys = {
77
124
  listingGroups: (options) => ["products", "listing-groups", "list", options],
78
125
  listingGroupsCatalog: (options) => ["products", "listing-groups", "catalog", options],
79
- listingGroupsInfinite: (options) => ["products", "listing-groups", "infinite", options],
80
- listingGroupsCatalogInfinite: (options) => ["products", "listing-groups", "catalog", "infinite", options],
126
+ listingGroupsInfinite: (options, pageSize) => [
127
+ "products",
128
+ "listing-groups",
129
+ "infinite",
130
+ pageSize === void 0 ? options : { ...options, limit: pageSize }
131
+ ],
132
+ listingGroupsCatalogInfinite: (options, pageSize) => [
133
+ "products",
134
+ "listing-groups",
135
+ "catalog",
136
+ "infinite",
137
+ pageSize === void 0 ? options : { ...options, limit: pageSize }
138
+ ],
139
+ listingPage: (params) => ["products", "listing-page", canonicalProductListingPageParams(params)],
140
+ listingPageInfinite: (params, pageSize) => [
141
+ "products",
142
+ "listing-page",
143
+ "infinite",
144
+ canonicalProductListingPageParams(
145
+ params,
146
+ pageSize
147
+ )
148
+ ],
81
149
  detail: (params) => ["products", "detail", params],
82
150
  detailAll: () => ["products", "detail"]
83
151
  };
@@ -164,13 +232,14 @@ var CollectionHooks = class {
164
232
  }
165
233
  // ===== useInfiniteQuery =====
166
234
  useInfiniteQuery(params, options) {
167
- const {
168
- collection,
169
- options: queryOptions,
170
- pageSize = DEFAULT_PAGE_SIZE
171
- } = params;
235
+ const { collection, options: queryOptions } = params;
236
+ const explicitPageSize = params.pageSize;
237
+ const pageSize = explicitPageSize ?? DEFAULT_PAGE_SIZE;
172
238
  return useInfiniteQueryOriginal({
173
- queryKey: collectionKeys(collection).infinite(queryOptions),
239
+ queryKey: collectionKeys(collection).infinite(
240
+ queryOptions,
241
+ explicitPageSize
242
+ ),
174
243
  queryFn: async ({ pageParam }) => {
175
244
  const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
176
245
  return response;
@@ -184,13 +253,14 @@ var CollectionHooks = class {
184
253
  }
185
254
  // ===== useSuspenseInfiniteQuery =====
186
255
  useSuspenseInfiniteQuery(params, options) {
187
- const {
188
- collection,
189
- options: queryOptions,
190
- pageSize = DEFAULT_PAGE_SIZE
191
- } = params;
256
+ const { collection, options: queryOptions } = params;
257
+ const explicitPageSize = params.pageSize;
258
+ const pageSize = explicitPageSize ?? DEFAULT_PAGE_SIZE;
192
259
  return useSuspenseInfiniteQueryOriginal({
193
- queryKey: collectionKeys(collection).infinite(queryOptions),
260
+ queryKey: collectionKeys(collection).infinite(
261
+ queryOptions,
262
+ explicitPageSize
263
+ ),
194
264
  queryFn: async ({ pageParam }) => {
195
265
  const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
196
266
  return response;
@@ -226,13 +296,14 @@ var CollectionHooks = class {
226
296
  }
227
297
  // ===== prefetchInfiniteQuery =====
228
298
  async prefetchInfiniteQuery(params, options) {
229
- const {
230
- collection,
231
- options: queryOptions,
232
- pageSize = DEFAULT_PAGE_SIZE
233
- } = params;
299
+ const { collection, options: queryOptions } = params;
300
+ const explicitPageSize = params.pageSize;
301
+ const pageSize = explicitPageSize ?? DEFAULT_PAGE_SIZE;
234
302
  return this.queryClient.prefetchInfiniteQuery({
235
- queryKey: collectionKeys(collection).infinite(queryOptions),
303
+ queryKey: collectionKeys(collection).infinite(
304
+ queryOptions,
305
+ explicitPageSize
306
+ ),
236
307
  queryFn: async ({ pageParam }) => {
237
308
  const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
238
309
  return response;
@@ -541,6 +612,50 @@ function fetchProductListingGroupsCatalogQuery(collectionClient, queryOptions) {
541
612
  listingGroupsQueryCatalogUrl(queryOptions)
542
613
  );
543
614
  }
615
+ function productListingPageQueryOptions(commerceClient, params = {}) {
616
+ return {
617
+ queryKey: productKeys.listingPage(params),
618
+ queryFn: () => commerceClient.product.listingPage(params)
619
+ };
620
+ }
621
+ function productListingPageInfiniteQueryOptions(commerceClient, params = {}) {
622
+ const {
623
+ pageSize: explicitPageSize,
624
+ page: _page,
625
+ limit: _limit,
626
+ ...pageParams
627
+ } = params;
628
+ const pageSize = explicitPageSize ?? 20;
629
+ return {
630
+ queryKey: productKeys.listingPageInfinite(pageParams, explicitPageSize),
631
+ queryFn: ({ pageParam }) => commerceClient.product.listingPage({
632
+ ...pageParams,
633
+ page: pageParam,
634
+ limit: pageSize
635
+ }),
636
+ initialPageParam: 1,
637
+ getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0
638
+ };
639
+ }
640
+ function prefetchProductListingPage(queryClient, commerceClient, params = {}, options) {
641
+ return queryClient.prefetchQuery({
642
+ ...productListingPageQueryOptions(
643
+ commerceClient,
644
+ params
645
+ ),
646
+ ...options
647
+ });
648
+ }
649
+ function prefetchInfiniteProductListingPage(queryClient, commerceClient, params = {}, options) {
650
+ return queryClient.prefetchInfiniteQuery({
651
+ ...productListingPageInfiniteQueryOptions(
652
+ commerceClient,
653
+ params
654
+ ),
655
+ pages: options?.pages ?? 1,
656
+ staleTime: options?.staleTime
657
+ });
658
+ }
544
659
  var QueryHooks = class extends CollectionHooks {
545
660
  constructor(queryClient, collectionClient, customerAuth, commerceClient) {
546
661
  super(queryClient, collectionClient);
@@ -561,6 +676,14 @@ var QueryHooks = class extends CollectionHooks {
561
676
  this._customer = new CustomerHooks(queryClient, customerAuth);
562
677
  this._commerce = commerceClient;
563
678
  }
679
+ ensureCommerce() {
680
+ if (!this._commerce) {
681
+ throw createConfigError(
682
+ "Product listing page hooks require Client or ServerClient. Use createQueryHooks(client) or createServerQueryHooks(server) instead of constructing QueryHooks directly."
683
+ );
684
+ }
685
+ return this._commerce;
686
+ }
564
687
  useProductListingGroupsQuery(params, options) {
565
688
  const queryOptions = params.options;
566
689
  const { placeholderData, ...restOptions } = options ?? {};
@@ -608,12 +731,14 @@ var QueryHooks = class extends CollectionHooks {
608
731
  });
609
732
  }
610
733
  useInfiniteProductListingGroupsQuery(params, options) {
611
- const {
612
- options: queryOptions,
613
- pageSize = 20
614
- } = params;
734
+ const { options: queryOptions } = params;
735
+ const explicitPageSize = params.pageSize;
736
+ const pageSize = explicitPageSize ?? 20;
615
737
  return useInfiniteQueryOriginal2({
616
- queryKey: productKeys.listingGroupsInfinite(queryOptions),
738
+ queryKey: productKeys.listingGroupsInfinite(
739
+ queryOptions,
740
+ explicitPageSize
741
+ ),
617
742
  queryFn: async ({ pageParam }) => fetchProductListingGroupsQuery(this.collectionClient, {
618
743
  ...queryOptions,
619
744
  page: pageParam,
@@ -625,12 +750,14 @@ var QueryHooks = class extends CollectionHooks {
625
750
  });
626
751
  }
627
752
  useInfiniteProductListingGroupsCatalogQuery(params, options) {
628
- const {
629
- options: queryOptions,
630
- pageSize = 20
631
- } = params;
753
+ const { options: queryOptions } = params;
754
+ const explicitPageSize = params.pageSize;
755
+ const pageSize = explicitPageSize ?? 20;
632
756
  return useInfiniteQueryOriginal2({
633
- queryKey: productKeys.listingGroupsCatalogInfinite(queryOptions),
757
+ queryKey: productKeys.listingGroupsCatalogInfinite(
758
+ queryOptions,
759
+ explicitPageSize
760
+ ),
634
761
  queryFn: async ({ pageParam }) => fetchProductListingGroupsCatalogQuery(this.collectionClient, {
635
762
  ...queryOptions,
636
763
  page: pageParam,
@@ -642,12 +769,14 @@ var QueryHooks = class extends CollectionHooks {
642
769
  });
643
770
  }
644
771
  useSuspenseInfiniteProductListingGroupsQuery(params, options) {
645
- const {
646
- options: queryOptions,
647
- pageSize = 20
648
- } = params;
772
+ const { options: queryOptions } = params;
773
+ const explicitPageSize = params.pageSize;
774
+ const pageSize = explicitPageSize ?? 20;
649
775
  return useSuspenseInfiniteQueryOriginal2({
650
- queryKey: productKeys.listingGroupsInfinite(queryOptions),
776
+ queryKey: productKeys.listingGroupsInfinite(
777
+ queryOptions,
778
+ explicitPageSize
779
+ ),
651
780
  queryFn: async ({ pageParam }) => fetchProductListingGroupsQuery(this.collectionClient, {
652
781
  ...queryOptions,
653
782
  page: pageParam,
@@ -659,12 +788,14 @@ var QueryHooks = class extends CollectionHooks {
659
788
  });
660
789
  }
661
790
  useSuspenseInfiniteProductListingGroupsCatalogQuery(params, options) {
662
- const {
663
- options: queryOptions,
664
- pageSize = 20
665
- } = params;
791
+ const { options: queryOptions } = params;
792
+ const explicitPageSize = params.pageSize;
793
+ const pageSize = explicitPageSize ?? 20;
666
794
  return useSuspenseInfiniteQueryOriginal2({
667
- queryKey: productKeys.listingGroupsCatalogInfinite(queryOptions),
795
+ queryKey: productKeys.listingGroupsCatalogInfinite(
796
+ queryOptions,
797
+ explicitPageSize
798
+ ),
668
799
  queryFn: async ({ pageParam }) => fetchProductListingGroupsCatalogQuery(this.collectionClient, {
669
800
  ...queryOptions,
670
801
  page: pageParam,
@@ -695,12 +826,14 @@ var QueryHooks = class extends CollectionHooks {
695
826
  });
696
827
  }
697
828
  async prefetchInfiniteProductListingGroupsQuery(params, options) {
698
- const {
699
- options: queryOptions,
700
- pageSize = 20
701
- } = params;
829
+ const { options: queryOptions } = params;
830
+ const explicitPageSize = params.pageSize;
831
+ const pageSize = explicitPageSize ?? 20;
702
832
  return this.queryClient.prefetchInfiniteQuery({
703
- queryKey: productKeys.listingGroupsInfinite(queryOptions),
833
+ queryKey: productKeys.listingGroupsInfinite(
834
+ queryOptions,
835
+ explicitPageSize
836
+ ),
704
837
  queryFn: async ({ pageParam }) => fetchProductListingGroupsQuery(this.collectionClient, {
705
838
  ...queryOptions,
706
839
  page: pageParam,
@@ -713,12 +846,14 @@ var QueryHooks = class extends CollectionHooks {
713
846
  });
714
847
  }
715
848
  async prefetchInfiniteProductListingGroupsCatalogQuery(params, options) {
716
- const {
717
- options: queryOptions,
718
- pageSize = 20
719
- } = params;
849
+ const { options: queryOptions } = params;
850
+ const explicitPageSize = params.pageSize;
851
+ const pageSize = explicitPageSize ?? 20;
720
852
  return this.queryClient.prefetchInfiniteQuery({
721
- queryKey: productKeys.listingGroupsCatalogInfinite(queryOptions),
853
+ queryKey: productKeys.listingGroupsCatalogInfinite(
854
+ queryOptions,
855
+ explicitPageSize
856
+ ),
722
857
  queryFn: async ({ pageParam }) => fetchProductListingGroupsCatalogQuery(this.collectionClient, {
723
858
  ...queryOptions,
724
859
  page: pageParam,
@@ -730,6 +865,45 @@ var QueryHooks = class extends CollectionHooks {
730
865
  staleTime: options?.staleTime
731
866
  });
732
867
  }
868
+ useProductListingPage(params = {}, options) {
869
+ const { placeholderData, ...restOptions } = options ?? {};
870
+ return useQueryOriginal3({
871
+ ...productListingPageQueryOptions(this.ensureCommerce(), params),
872
+ ...restOptions,
873
+ ...placeholderData !== void 0 && {
874
+ placeholderData
875
+ }
876
+ });
877
+ }
878
+ useSuspenseProductListingPage(params = {}, options) {
879
+ const suspenseOptions = options;
880
+ return useSuspenseQueryOriginal2({
881
+ ...productListingPageQueryOptions(this.ensureCommerce(), params),
882
+ ...suspenseOptions
883
+ });
884
+ }
885
+ useInfiniteProductListingPage(params = {}, options) {
886
+ return useInfiniteQueryOriginal2({
887
+ ...productListingPageInfiniteQueryOptions(this.ensureCommerce(), params),
888
+ ...options
889
+ });
890
+ }
891
+ async prefetchProductListingPage(params = {}, options) {
892
+ return prefetchProductListingPage(
893
+ this.queryClient,
894
+ this.ensureCommerce(),
895
+ params,
896
+ options
897
+ );
898
+ }
899
+ async prefetchInfiniteProductListingPage(params = {}, options) {
900
+ return prefetchInfiniteProductListingPage(
901
+ this.queryClient,
902
+ this.ensureCommerce(),
903
+ params,
904
+ options
905
+ );
906
+ }
733
907
  useProductDetail(params, options) {
734
908
  const discriminator = "slug" in params ? params.slug : params.id;
735
909
  const { enabled, ...restOptions } = options ?? {};
@@ -921,12 +1095,17 @@ function createReadOnlyQueryHooksFacade(hooks) {
921
1095
  invalidateCustomerQueries: hooks.invalidateCustomerQueries.bind(hooks),
922
1096
  getCustomerData: hooks.getCustomerData.bind(hooks),
923
1097
  setCustomerData: hooks.setCustomerData.bind(hooks),
924
- useProductListingGroupsQuery: hooks.useProductListingGroupsQuery.bind(hooks),
925
- useSuspenseProductListingGroupsQuery: hooks.useSuspenseProductListingGroupsQuery.bind(hooks),
926
- useInfiniteProductListingGroupsQuery: hooks.useInfiniteProductListingGroupsQuery.bind(hooks),
927
- useSuspenseInfiniteProductListingGroupsQuery: hooks.useSuspenseInfiniteProductListingGroupsQuery.bind(hooks),
928
- prefetchProductListingGroupsQuery: hooks.prefetchProductListingGroupsQuery.bind(hooks),
929
- prefetchInfiniteProductListingGroupsQuery: hooks.prefetchInfiniteProductListingGroupsQuery.bind(hooks),
1098
+ useProductListingGroupsCatalogQuery: hooks.useProductListingGroupsCatalogQuery.bind(hooks),
1099
+ useSuspenseProductListingGroupsCatalogQuery: hooks.useSuspenseProductListingGroupsCatalogQuery.bind(hooks),
1100
+ useInfiniteProductListingGroupsCatalogQuery: hooks.useInfiniteProductListingGroupsCatalogQuery.bind(hooks),
1101
+ useSuspenseInfiniteProductListingGroupsCatalogQuery: hooks.useSuspenseInfiniteProductListingGroupsCatalogQuery.bind(hooks),
1102
+ prefetchProductListingGroupsCatalogQuery: hooks.prefetchProductListingGroupsCatalogQuery.bind(hooks),
1103
+ prefetchInfiniteProductListingGroupsCatalogQuery: hooks.prefetchInfiniteProductListingGroupsCatalogQuery.bind(hooks),
1104
+ useProductListingPage: hooks.useProductListingPage.bind(hooks),
1105
+ useSuspenseProductListingPage: hooks.useSuspenseProductListingPage.bind(hooks),
1106
+ useInfiniteProductListingPage: hooks.useInfiniteProductListingPage.bind(hooks),
1107
+ prefetchProductListingPage: hooks.prefetchProductListingPage.bind(hooks),
1108
+ prefetchInfiniteProductListingPage: hooks.prefetchInfiniteProductListingPage.bind(hooks),
930
1109
  useProductDetail: hooks.useProductDetail.bind(hooks),
931
1110
  useProductDetailBySlug: hooks.useProductDetailBySlug.bind(hooks),
932
1111
  useProductDetailById: hooks.useProductDetailById.bind(hooks)
@@ -960,6 +1139,10 @@ export {
960
1139
  customerKeys,
961
1140
  getQueryClient,
962
1141
  getStorefrontQueryClient,
963
- productKeys
1142
+ prefetchInfiniteProductListingPage,
1143
+ prefetchProductListingPage,
1144
+ productKeys,
1145
+ productListingPageInfiniteQueryOptions,
1146
+ productListingPageQueryOptions
964
1147
  };
965
1148
  //# sourceMappingURL=query.js.map