@viu/emporix-sdk-react 2.0.0 → 2.2.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,45 @@ function useProductSearch(query, params = {}, options = {}) {
345
345
  staleTime: PRODUCTS_STALE_TIME
346
346
  });
347
347
  }
348
+ function useProductsByCodes(codes, options = {}) {
349
+ const { client } = useEmporix();
350
+ const { ctx } = useReadAuth(options.auth);
351
+ const { siteCode } = useReadSite();
352
+ return reactQuery.useQuery({
353
+ queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
354
+ tenant: client.tenant,
355
+ authKind: ctx.kind,
356
+ siteCode
357
+ }),
358
+ enabled: codes.length > 0,
359
+ queryFn: () => client.products.searchByCodes(
360
+ codes,
361
+ options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
362
+ ctx
363
+ ),
364
+ staleTime: 3e4
365
+ });
366
+ }
367
+ var VARIANT_CHILDREN_STALE_TIME = 6e4;
368
+ function useVariantChildren(parentVariantId, options = {}) {
369
+ const { client } = useEmporix();
370
+ const { ctx } = useReadAuth(options.auth);
371
+ const { siteCode } = useReadSite();
372
+ return reactQuery.useQuery({
373
+ queryKey: emporixKey(
374
+ "variant-children",
375
+ [parentVariantId, { pageSize: options.pageSize }],
376
+ { tenant: client.tenant, authKind: ctx.kind, siteCode }
377
+ ),
378
+ enabled: typeof parentVariantId === "string" && parentVariantId !== "",
379
+ queryFn: () => client.products.listVariantChildren(
380
+ parentVariantId,
381
+ options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
382
+ ctx
383
+ ),
384
+ staleTime: VARIANT_CHILDREN_STALE_TIME
385
+ });
386
+ }
348
387
  var CATEGORIES_STALE_TIME = 5 * 6e4;
349
388
  function useCategory(categoryId, options = {}) {
350
389
  const { client } = useEmporix();
@@ -609,6 +648,36 @@ function useMatchPrices(input, options = {}) {
609
648
  staleTime: PRICES_STALE_TIME
610
649
  });
611
650
  }
651
+ var PRICES_STALE_TIME2 = 6e4;
652
+ function useMatchPricesChunked(input, options = {}) {
653
+ const { client } = useEmporix();
654
+ const { siteCode } = useReadSite();
655
+ const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
656
+ return reactQuery.useQuery({
657
+ queryKey: [
658
+ "emporix",
659
+ "match-prices-chunked",
660
+ {
661
+ tenant: client.tenant,
662
+ input,
663
+ anon: !options.customerToken,
664
+ siteCode,
665
+ chunkSize: options.chunkSize,
666
+ concurrency: options.concurrency
667
+ }
668
+ ],
669
+ enabled: (options.enabled ?? true) && (input.items?.length ?? 0) > 0,
670
+ queryFn: () => client.prices.matchByContextChunked(
671
+ input,
672
+ {
673
+ ...options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
674
+ ...options.concurrency !== void 0 ? { concurrency: options.concurrency } : {}
675
+ },
676
+ ctx
677
+ ),
678
+ staleTime: PRICES_STALE_TIME2
679
+ });
680
+ }
612
681
 
613
682
  // src/hooks/use-product-media.ts
614
683
  function useProductMedia(productId) {
@@ -1133,12 +1202,12 @@ function useUpdateSalesOrder() {
1133
1202
  const qc = reactQuery.useQueryClient();
1134
1203
  return reactQuery.useMutation({
1135
1204
  mutationKey: ["emporix", "salesorders", "update"],
1136
- mutationFn: async ({ orderId, patch, auth: auth22, recalculate }) => {
1137
- if (!auth22) throw new Error("useUpdateSalesOrder: requires an auth context");
1205
+ mutationFn: async ({ orderId, patch, auth: auth25, recalculate }) => {
1206
+ if (!auth25) throw new Error("useUpdateSalesOrder: requires an auth context");
1138
1207
  return client.salesOrders.update(
1139
1208
  orderId,
1140
1209
  patch,
1141
- auth22,
1210
+ auth25,
1142
1211
  recalculate !== void 0 ? { recalculate } : {}
1143
1212
  );
1144
1213
  },
@@ -1149,10 +1218,58 @@ function useUpdateSalesOrder() {
1149
1218
  }
1150
1219
  });
1151
1220
  }
1221
+ var AVAILABILITY_STALE_TIME = 3e4;
1222
+ function useAvailability(productId, siteCode, options = {}) {
1223
+ const { client } = useEmporix();
1224
+ const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1225
+ return reactQuery.useQuery({
1226
+ queryKey: [
1227
+ "emporix",
1228
+ "availability",
1229
+ {
1230
+ tenant: client.tenant,
1231
+ productId,
1232
+ siteCode,
1233
+ anon: !options.customerToken,
1234
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1235
+ }
1236
+ ],
1237
+ enabled: (options.enabled ?? true) && Boolean(productId) && Boolean(siteCode),
1238
+ queryFn: () => client.availability.get(productId, siteCode, ctx, {
1239
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1240
+ }),
1241
+ staleTime: AVAILABILITY_STALE_TIME
1242
+ });
1243
+ }
1244
+ var AVAILABILITY_STALE_TIME2 = 3e4;
1245
+ function useAvailabilities(productIds, siteCode, options = {}) {
1246
+ const { client } = useEmporix();
1247
+ const ctx = options.customerToken ? emporixSdk.auth.customer(options.customerToken) : emporixSdk.auth.anonymous();
1248
+ return reactQuery.useQuery({
1249
+ queryKey: [
1250
+ "emporix",
1251
+ "availabilities",
1252
+ {
1253
+ tenant: client.tenant,
1254
+ productIds,
1255
+ siteCode,
1256
+ anon: !options.customerToken,
1257
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1258
+ }
1259
+ ],
1260
+ enabled: (options.enabled ?? true) && productIds.length > 0 && Boolean(siteCode),
1261
+ queryFn: () => client.availability.getMany(productIds, siteCode, ctx, {
1262
+ defaultAvailableOnNotFound: options.defaultAvailableOnNotFound ?? false
1263
+ }),
1264
+ staleTime: AVAILABILITY_STALE_TIME2
1265
+ });
1266
+ }
1152
1267
 
1153
1268
  exports.useActiveCart = useActiveCart;
1154
1269
  exports.useAddressMutations = useAddressMutations;
1155
1270
  exports.useAssignContact = useAssignContact;
1271
+ exports.useAvailabilities = useAvailabilities;
1272
+ exports.useAvailability = useAvailability;
1156
1273
  exports.useCancelOrder = useCancelOrder;
1157
1274
  exports.useCart = useCart;
1158
1275
  exports.useCartMutations = useCartMutations;
@@ -1176,6 +1293,7 @@ exports.useDefaultSite = useDefaultSite;
1176
1293
  exports.useDeleteCompany = useDeleteCompany;
1177
1294
  exports.useDeleteLocation = useDeleteLocation;
1178
1295
  exports.useMatchPrices = useMatchPrices;
1296
+ exports.useMatchPricesChunked = useMatchPricesChunked;
1179
1297
  exports.useMyCompanies = useMyCompanies;
1180
1298
  exports.useMyOrders = useMyOrders;
1181
1299
  exports.useMyOrdersInfinite = useMyOrdersInfinite;
@@ -1195,6 +1313,7 @@ exports.useProductByCode = useProductByCode;
1195
1313
  exports.useProductMedia = useProductMedia;
1196
1314
  exports.useProductSearch = useProductSearch;
1197
1315
  exports.useProducts = useProducts;
1316
+ exports.useProductsByCodes = useProductsByCodes;
1198
1317
  exports.useProductsInCategory = useProductsInCategory;
1199
1318
  exports.useProductsInCategoryInfinite = useProductsInCategoryInfinite;
1200
1319
  exports.useProductsInfinite = useProductsInfinite;
@@ -1208,5 +1327,6 @@ exports.useUpdateContactAssignment = useUpdateContactAssignment;
1208
1327
  exports.useUpdateCustomer = useUpdateCustomer;
1209
1328
  exports.useUpdateLocation = useUpdateLocation;
1210
1329
  exports.useUpdateSalesOrder = useUpdateSalesOrder;
1330
+ exports.useVariantChildren = useVariantChildren;
1211
1331
  //# sourceMappingURL=hooks.cjs.map
1212
1332
  //# sourceMappingURL=hooks.cjs.map