@viu/emporix-sdk-react 2.0.0 → 2.1.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.
package/dist/hooks.cjs CHANGED
@@ -345,6 +345,26 @@ function useProductSearch(query, params = {}, options = {}) {
345
345
  staleTime: PRODUCTS_STALE_TIME
346
346
  });
347
347
  }
348
+ var VARIANT_CHILDREN_STALE_TIME = 6e4;
349
+ function useVariantChildren(parentVariantId, options = {}) {
350
+ const { client } = useEmporix();
351
+ const { ctx } = useReadAuth(options.auth);
352
+ const { siteCode } = useReadSite();
353
+ return reactQuery.useQuery({
354
+ queryKey: emporixKey(
355
+ "variant-children",
356
+ [parentVariantId, { pageSize: options.pageSize }],
357
+ { tenant: client.tenant, authKind: ctx.kind, siteCode }
358
+ ),
359
+ enabled: typeof parentVariantId === "string" && parentVariantId !== "",
360
+ queryFn: () => client.products.listVariantChildren(
361
+ parentVariantId,
362
+ options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
363
+ ctx
364
+ ),
365
+ staleTime: VARIANT_CHILDREN_STALE_TIME
366
+ });
367
+ }
348
368
  var CATEGORIES_STALE_TIME = 5 * 6e4;
349
369
  function useCategory(categoryId, options = {}) {
350
370
  const { client } = useEmporix();
@@ -609,6 +629,36 @@ function useMatchPrices(input, options = {}) {
609
629
  staleTime: PRICES_STALE_TIME
610
630
  });
611
631
  }
632
+ var PRICES_STALE_TIME2 = 6e4;
633
+ function useMatchPricesChunked(input, options = {}) {
634
+ const { client } = useEmporix();
635
+ const { siteCode } = useReadSite();
636
+ const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
637
+ return reactQuery.useQuery({
638
+ queryKey: [
639
+ "emporix",
640
+ "match-prices-chunked",
641
+ {
642
+ tenant: client.tenant,
643
+ input,
644
+ anon: !options.customerToken,
645
+ siteCode,
646
+ chunkSize: options.chunkSize,
647
+ concurrency: options.concurrency
648
+ }
649
+ ],
650
+ enabled: (options.enabled ?? true) && (input.items?.length ?? 0) > 0,
651
+ queryFn: () => client.prices.matchByContextChunked(
652
+ input,
653
+ {
654
+ ...options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
655
+ ...options.concurrency !== void 0 ? { concurrency: options.concurrency } : {}
656
+ },
657
+ ctx
658
+ ),
659
+ staleTime: PRICES_STALE_TIME2
660
+ });
661
+ }
612
662
 
613
663
  // src/hooks/use-product-media.ts
614
664
  function useProductMedia(productId) {
@@ -1133,12 +1183,12 @@ function useUpdateSalesOrder() {
1133
1183
  const qc = reactQuery.useQueryClient();
1134
1184
  return reactQuery.useMutation({
1135
1185
  mutationKey: ["emporix", "salesorders", "update"],
1136
- mutationFn: async ({ orderId, patch, auth: auth22, recalculate }) => {
1137
- if (!auth22) throw new Error("useUpdateSalesOrder: requires an auth context");
1186
+ mutationFn: async ({ orderId, patch, auth: auth25, recalculate }) => {
1187
+ if (!auth25) throw new Error("useUpdateSalesOrder: requires an auth context");
1138
1188
  return client.salesOrders.update(
1139
1189
  orderId,
1140
1190
  patch,
1141
- auth22,
1191
+ auth25,
1142
1192
  recalculate !== void 0 ? { recalculate } : {}
1143
1193
  );
1144
1194
  },
@@ -1149,10 +1199,58 @@ function useUpdateSalesOrder() {
1149
1199
  }
1150
1200
  });
1151
1201
  }
1202
+ var AVAILABILITY_STALE_TIME = 3e4;
1203
+ function useAvailability(productId, siteCode, options = {}) {
1204
+ const { client } = useEmporix();
1205
+ const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1206
+ return reactQuery.useQuery({
1207
+ queryKey: [
1208
+ "emporix",
1209
+ "availability",
1210
+ {
1211
+ tenant: client.tenant,
1212
+ productId,
1213
+ siteCode,
1214
+ anon: !options.customerToken,
1215
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1216
+ }
1217
+ ],
1218
+ enabled: (options.enabled ?? true) && Boolean(productId) && Boolean(siteCode),
1219
+ queryFn: () => client.availability.get(productId, siteCode, ctx, {
1220
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1221
+ }),
1222
+ staleTime: AVAILABILITY_STALE_TIME
1223
+ });
1224
+ }
1225
+ var AVAILABILITY_STALE_TIME2 = 3e4;
1226
+ function useAvailabilities(productIds, siteCode, options = {}) {
1227
+ const { client } = useEmporix();
1228
+ const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1229
+ return reactQuery.useQuery({
1230
+ queryKey: [
1231
+ "emporix",
1232
+ "availabilities",
1233
+ {
1234
+ tenant: client.tenant,
1235
+ productIds,
1236
+ siteCode,
1237
+ anon: !options.customerToken,
1238
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1239
+ }
1240
+ ],
1241
+ enabled: (options.enabled ?? true) && productIds.length > 0 && Boolean(siteCode),
1242
+ queryFn: () => client.availability.getMany(productIds, siteCode, ctx, {
1243
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1244
+ }),
1245
+ staleTime: AVAILABILITY_STALE_TIME2
1246
+ });
1247
+ }
1152
1248
 
1153
1249
  exports.useActiveCart = useActiveCart;
1154
1250
  exports.useAddressMutations = useAddressMutations;
1155
1251
  exports.useAssignContact = useAssignContact;
1252
+ exports.useAvailabilities = useAvailabilities;
1253
+ exports.useAvailability = useAvailability;
1156
1254
  exports.useCancelOrder = useCancelOrder;
1157
1255
  exports.useCart = useCart;
1158
1256
  exports.useCartMutations = useCartMutations;
@@ -1176,6 +1274,7 @@ exports.useDefaultSite = useDefaultSite;
1176
1274
  exports.useDeleteCompany = useDeleteCompany;
1177
1275
  exports.useDeleteLocation = useDeleteLocation;
1178
1276
  exports.useMatchPrices = useMatchPrices;
1277
+ exports.useMatchPricesChunked = useMatchPricesChunked;
1179
1278
  exports.useMyCompanies = useMyCompanies;
1180
1279
  exports.useMyOrders = useMyOrders;
1181
1280
  exports.useMyOrdersInfinite = useMyOrdersInfinite;
@@ -1208,5 +1307,6 @@ exports.useUpdateContactAssignment = useUpdateContactAssignment;
1208
1307
  exports.useUpdateCustomer = useUpdateCustomer;
1209
1308
  exports.useUpdateLocation = useUpdateLocation;
1210
1309
  exports.useUpdateSalesOrder = useUpdateSalesOrder;
1310
+ exports.useVariantChildren = useVariantChildren;
1211
1311
  //# sourceMappingURL=hooks.cjs.map
1212
1312
  //# sourceMappingURL=hooks.cjs.map