@viu/emporix-sdk-react 2.14.0 → 2.15.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.
@@ -3,7 +3,7 @@ import {
3
3
  EmporixSiteContext,
4
4
  useActiveCompany,
5
5
  useEmporix
6
- } from "./chunk-CZDVH3WH.js";
6
+ } from "./chunk-ZNE3J25W.js";
7
7
 
8
8
  // src/hooks/use-customer-session.ts
9
9
  import { useCallback, useContext, useMemo, useSyncExternalStore } from "react";
@@ -43,8 +43,8 @@ function getCustomerSessionStore(storage) {
43
43
  if (existing) return existing;
44
44
  let state = {
45
45
  token: storage.getCustomerToken(),
46
- refreshToken: null,
47
- saasToken: null
46
+ refreshToken: storage.getRefreshToken(),
47
+ saasToken: storage.getSaasToken?.() ?? null
48
48
  };
49
49
  const listeners = /* @__PURE__ */ new Set();
50
50
  const store = {
@@ -95,6 +95,7 @@ function useCustomerSession() {
95
95
  const result = await client.customers.login(input);
96
96
  storage.setCustomerToken(result.customerToken);
97
97
  storage.setRefreshToken(result.refreshToken || null);
98
+ storage.setSaasToken?.(result.saasToken || null);
98
99
  storage.setAnonymousSession(null);
99
100
  setSession({
100
101
  token: result.customerToken,
@@ -128,6 +129,7 @@ function useCustomerSession() {
128
129
  async (incoming) => {
129
130
  storage.setCustomerToken(incoming.customerToken);
130
131
  storage.setRefreshToken(incoming.refreshToken || null);
132
+ storage.setSaasToken?.(incoming.saasToken || null);
131
133
  storage.setAnonymousSession(null);
132
134
  setSession({
133
135
  token: incoming.customerToken,
@@ -172,6 +174,7 @@ function useCustomerSession() {
172
174
  }
173
175
  storage.setCustomerToken(null);
174
176
  storage.setRefreshToken(null);
177
+ storage.setSaasToken?.(null);
175
178
  storage.setActiveLegalEntityId(null);
176
179
  storage.setCartId(null);
177
180
  setSession(EMPTY_SESSION);
@@ -188,6 +191,7 @@ function useCustomerSession() {
188
191
  });
189
192
  storage.setCustomerToken(refreshed.customerToken);
190
193
  if (refreshed.refreshToken) storage.setRefreshToken(refreshed.refreshToken);
194
+ if (refreshed.saasToken) storage.setSaasToken?.(refreshed.saasToken);
191
195
  setSession((s) => ({
192
196
  token: refreshed.customerToken,
193
197
  refreshToken: refreshed.refreshToken || s.refreshToken,
@@ -260,9 +264,7 @@ async function onboardCustomerCart(opts) {
260
264
  }
261
265
 
262
266
  // src/hooks/use-products.ts
263
- import {
264
- useQuery as useQuery2
265
- } from "@tanstack/react-query";
267
+ import "@tanstack/react-query";
266
268
  import "@viu/emporix-sdk";
267
269
 
268
270
  // src/hooks/internal/use-read-auth.ts
@@ -340,25 +342,54 @@ function useEmporixInfinite(opts) {
340
342
  });
341
343
  }
342
344
 
345
+ // src/hooks/internal/use-emporix-query.ts
346
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
347
+ import { auth as auth3 } from "@viu/emporix-sdk";
348
+ function useEmporixQuery(cfg) {
349
+ const { client } = useEmporix();
350
+ const token = useCustomerToken();
351
+ const { siteCode, language } = useReadSite();
352
+ const authOverride = cfg.mode === "read-auth" ? cfg.authOverride : void 0;
353
+ const readCtx = authOverride ?? (token ? auth3.customer(token) : auth3.anonymous());
354
+ const authKind = cfg.mode === "customer" ? token ? "customer" : "anonymous" : readCtx.kind;
355
+ const resolvedCtx = cfg.mode === "customer" ? auth3.customer(token) : readCtx;
356
+ const siteMeta = cfg.site === "full" ? { siteCode, language } : cfg.site === "language" ? { language } : {};
357
+ const enabled = (cfg.enabled ?? true) && (cfg.mode === "customer" ? token !== null : true);
358
+ return useQuery2({
359
+ queryKey: emporixKey(cfg.resource, cfg.args, {
360
+ tenant: client.tenant,
361
+ authKind,
362
+ ...siteMeta
363
+ }),
364
+ queryFn: () => cfg.queryFn(resolvedCtx),
365
+ enabled,
366
+ ...cfg.staleTime !== void 0 ? { staleTime: cfg.staleTime } : {}
367
+ });
368
+ }
369
+
343
370
  // src/hooks/use-products.ts
344
371
  var PRODUCTS_STALE_TIME = 6e4;
345
372
  function useProduct(productId, options = {}) {
346
373
  const { client } = useEmporix();
347
- const { ctx } = useReadAuth(options.auth);
348
- const { siteCode, language } = useReadSite();
349
- return useQuery2({
350
- queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
351
- queryFn: () => client.products.get(productId, void 0, ctx),
374
+ return useEmporixQuery({
375
+ mode: "read-auth",
376
+ site: "full",
377
+ resource: "product",
378
+ args: [productId],
379
+ ...options.auth ? { authOverride: options.auth } : {},
380
+ queryFn: (ctx) => client.products.get(productId, void 0, ctx),
352
381
  staleTime: PRODUCTS_STALE_TIME
353
382
  });
354
383
  }
355
384
  function useProducts(params = {}, options = {}) {
356
385
  const { client } = useEmporix();
357
- const { ctx } = useReadAuth(options.auth);
358
- const { siteCode, language } = useReadSite();
359
- return useQuery2({
360
- queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
361
- queryFn: () => client.products.list(params, ctx),
386
+ return useEmporixQuery({
387
+ mode: "read-auth",
388
+ site: "full",
389
+ resource: "products",
390
+ args: [params],
391
+ ...options.auth ? { authOverride: options.auth } : {},
392
+ queryFn: (ctx) => client.products.list(params, ctx),
362
393
  staleTime: PRODUCTS_STALE_TIME
363
394
  });
364
395
  }
@@ -377,50 +408,53 @@ function useProductsInfinite(params = {}, options = {}) {
377
408
  }
378
409
  function useProductByCode(code, options = {}) {
379
410
  const { client } = useEmporix();
380
- const { ctx } = useReadAuth(options.auth);
381
- const { siteCode, language } = useReadSite();
382
- return useQuery2({
383
- queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
411
+ return useEmporixQuery({
412
+ mode: "read-auth",
413
+ site: "full",
414
+ resource: "product-by-code",
415
+ args: [code],
416
+ ...options.auth ? { authOverride: options.auth } : {},
384
417
  enabled: typeof code === "string" && code !== "",
385
- queryFn: () => client.products.getByCode(code, ctx),
418
+ queryFn: (ctx) => client.products.getByCode(code, ctx),
386
419
  staleTime: PRODUCTS_STALE_TIME
387
420
  });
388
421
  }
389
422
  function useProductSearch(query, params = {}, options = {}) {
390
423
  const { client } = useEmporix();
391
- const { ctx } = useReadAuth(options.auth);
392
- const { siteCode, language } = useReadSite();
393
- return useQuery2({
394
- queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
424
+ return useEmporixQuery({
425
+ mode: "read-auth",
426
+ site: "full",
427
+ resource: "product-search",
428
+ args: [query, params],
429
+ ...options.auth ? { authOverride: options.auth } : {},
395
430
  enabled: typeof query === "string" && query.trim() !== "",
396
- queryFn: () => client.products.search(query, params, ctx),
431
+ queryFn: (ctx) => client.products.search(query, params, ctx),
397
432
  staleTime: PRODUCTS_STALE_TIME
398
433
  });
399
434
  }
400
435
  function useProductNameSearch(term, params = {}, options = {}) {
401
436
  const { client } = useEmporix();
402
- const { ctx } = useReadAuth(options.auth);
403
- const { siteCode, language } = useReadSite();
404
- return useQuery2({
405
- queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
437
+ return useEmporixQuery({
438
+ mode: "read-auth",
439
+ site: "full",
440
+ resource: "product-name-search",
441
+ args: [term, params],
442
+ ...options.auth ? { authOverride: options.auth } : {},
406
443
  enabled: typeof term === "string" && term.trim() !== "",
407
- queryFn: () => client.products.searchByName(term, params, ctx),
444
+ queryFn: (ctx) => client.products.searchByName(term, params, ctx),
408
445
  staleTime: PRODUCTS_STALE_TIME
409
446
  });
410
447
  }
411
448
  function useProductsByCodes(codes, options = {}) {
412
449
  const { client } = useEmporix();
413
- const { ctx } = useReadAuth(options.auth);
414
- const { siteCode, language } = useReadSite();
415
- return useQuery2({
416
- queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
417
- tenant: client.tenant,
418
- authKind: ctx.kind,
419
- siteCode,
420
- language
421
- }),
450
+ return useEmporixQuery({
451
+ mode: "read-auth",
452
+ site: "full",
453
+ resource: "products-by-codes",
454
+ args: [codes, options.chunkSize],
455
+ ...options.auth ? { authOverride: options.auth } : {},
422
456
  enabled: codes.length > 0,
423
- queryFn: () => client.products.searchByCodes(
457
+ queryFn: (ctx) => client.products.searchByCodes(
424
458
  codes,
425
459
  options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
426
460
  ctx
@@ -495,21 +529,19 @@ function useSetShoppingListItemQuantity() {
495
529
  }
496
530
 
497
531
  // src/hooks/use-variant-children.ts
498
- import { useQuery as useQuery4 } from "@tanstack/react-query";
532
+ import "@tanstack/react-query";
499
533
  import "@viu/emporix-sdk";
500
534
  var VARIANT_CHILDREN_STALE_TIME = 6e4;
501
535
  function useVariantChildren(parentVariantId, options = {}) {
502
536
  const { client } = useEmporix();
503
- const { ctx } = useReadAuth(options.auth);
504
- const { siteCode, language } = useReadSite();
505
- return useQuery4({
506
- queryKey: emporixKey(
507
- "variant-children",
508
- [parentVariantId, { pageSize: options.pageSize }],
509
- { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
510
- ),
537
+ return useEmporixQuery({
538
+ mode: "read-auth",
539
+ site: "full",
540
+ resource: "variant-children",
541
+ args: [parentVariantId, { pageSize: options.pageSize }],
542
+ ...options.auth ? { authOverride: options.auth } : {},
511
543
  enabled: typeof parentVariantId === "string" && parentVariantId !== "",
512
- queryFn: () => client.products.listVariantChildren(
544
+ queryFn: (ctx) => client.products.listVariantChildren(
513
545
  parentVariantId,
514
546
  options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
515
547
  ctx
@@ -519,39 +551,43 @@ function useVariantChildren(parentVariantId, options = {}) {
519
551
  }
520
552
 
521
553
  // src/hooks/use-categories.ts
522
- import {
523
- useQuery as useQuery5
524
- } from "@tanstack/react-query";
554
+ import "@tanstack/react-query";
525
555
  import "@viu/emporix-sdk";
526
556
  var CATEGORIES_STALE_TIME = 5 * 6e4;
527
557
  function useCategory(categoryId, options = {}) {
528
558
  const { client } = useEmporix();
529
- const { ctx } = useReadAuth(options.auth);
530
- const { siteCode, language } = useReadSite();
531
- return useQuery5({
532
- queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
533
- queryFn: () => client.categories.get(categoryId, ctx),
559
+ return useEmporixQuery({
560
+ mode: "read-auth",
561
+ site: "full",
562
+ resource: "category",
563
+ args: [categoryId],
564
+ ...options.auth ? { authOverride: options.auth } : {},
565
+ queryFn: (ctx) => client.categories.get(categoryId, ctx),
534
566
  staleTime: CATEGORIES_STALE_TIME
535
567
  });
536
568
  }
537
569
  function useSubcategories(categoryId, params = {}, options = {}) {
538
570
  const { client } = useEmporix();
539
- const { ctx } = useReadAuth(options.auth);
540
- const { siteCode, language } = useReadSite();
541
- return useQuery5({
542
- queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
571
+ return useEmporixQuery({
572
+ mode: "read-auth",
573
+ site: "full",
574
+ resource: "subcategories",
575
+ args: [categoryId ?? null, params],
576
+ ...options.auth ? { authOverride: options.auth } : {},
543
577
  enabled: typeof categoryId === "string" && categoryId !== "",
544
- queryFn: () => client.categories.subcategories(categoryId, params, ctx),
578
+ queryFn: (ctx) => client.categories.subcategories(categoryId, params, ctx),
545
579
  staleTime: CATEGORIES_STALE_TIME
546
580
  });
547
581
  }
548
582
  function useCategories(params = {}, options = {}) {
549
583
  const { client } = useEmporix();
550
- const { ctx } = useReadAuth(options.auth);
551
- const { siteCode, language } = useReadSite();
552
- return useQuery5({
553
- queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
554
- queryFn: () => client.categories.list(params, ctx),
584
+ return useEmporixQuery({
585
+ mode: "read-auth",
586
+ site: "full",
587
+ resource: "categories",
588
+ args: [params],
589
+ ...options.auth ? { authOverride: options.auth } : {},
590
+ queryFn: (ctx) => client.categories.list(params, ctx),
555
591
  staleTime: CATEGORIES_STALE_TIME
556
592
  });
557
593
  }
@@ -570,22 +606,26 @@ function useCategoriesInfinite(params = {}, options = {}) {
570
606
  }
571
607
  function useCategoryTree(options = {}) {
572
608
  const { client } = useEmporix();
573
- const { ctx } = useReadAuth(options.auth);
574
- const { siteCode, language } = useReadSite();
575
- return useQuery5({
576
- queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
577
- queryFn: () => client.categories.tree(ctx),
609
+ return useEmporixQuery({
610
+ mode: "read-auth",
611
+ site: "full",
612
+ resource: "category-tree",
613
+ args: [],
614
+ ...options.auth ? { authOverride: options.auth } : {},
615
+ queryFn: (ctx) => client.categories.tree(ctx),
578
616
  staleTime: CATEGORIES_STALE_TIME
579
617
  });
580
618
  }
581
619
  function useProductsInCategory(categoryId, params = {}, options = {}) {
582
620
  const { client } = useEmporix();
583
- const { ctx } = useReadAuth(options.auth);
584
- const { siteCode, language } = useReadSite();
585
- return useQuery5({
586
- queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
621
+ return useEmporixQuery({
622
+ mode: "read-auth",
623
+ site: "full",
624
+ resource: "products-in-category",
625
+ args: [categoryId, params],
626
+ ...options.auth ? { authOverride: options.auth } : {},
587
627
  enabled: typeof categoryId === "string" && categoryId !== "",
588
- queryFn: () => client.categories.productsIn(categoryId, params, ctx),
628
+ queryFn: (ctx) => client.categories.productsIn(categoryId, params, ctx),
589
629
  staleTime: CATEGORIES_STALE_TIME
590
630
  });
591
631
  }
@@ -609,7 +649,6 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
609
649
  import { useEffect } from "react";
610
650
  import {
611
651
  useMutation as useMutation2,
612
- useQuery as useQuery6,
613
652
  useQueryClient as useQueryClient3
614
653
  } from "@tanstack/react-query";
615
654
  import {
@@ -617,19 +656,17 @@ import {
617
656
  } from "@viu/emporix-sdk";
618
657
  function useCart(cartId, options = {}) {
619
658
  const { client } = useEmporix();
620
- const { ctx } = useReadAuth(options.auth);
621
- const { siteCode, language } = useReadSite();
622
659
  const { activeCompany } = useActiveCompany();
623
660
  const storedCartId = useCartId();
624
661
  const resolvedId = cartId ?? storedCartId ?? void 0;
625
- return useQuery6({
626
- queryKey: emporixKey(
627
- "cart",
628
- [resolvedId ?? null, activeCompany?.id ?? null],
629
- { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
630
- ),
662
+ return useEmporixQuery({
663
+ mode: "read-auth",
664
+ site: "full",
665
+ resource: "cart",
666
+ args: [resolvedId ?? null, activeCompany?.id ?? null],
667
+ ...options.auth ? { authOverride: options.auth } : {},
631
668
  enabled: resolvedId !== void 0,
632
- queryFn: () => client.carts.get(resolvedId, ctx)
669
+ queryFn: (ctx) => client.carts.get(resolvedId, ctx)
633
670
  });
634
671
  }
635
672
  function useCartMutations(cartId) {
@@ -760,18 +797,20 @@ function useActiveCart(opts) {
760
797
  // src/hooks/use-checkout.ts
761
798
  import {
762
799
  useMutation as useMutation3,
763
- useQuery as useQuery7
800
+ useQuery as useQuery5,
801
+ useQueryClient as useQueryClient4
764
802
  } from "@tanstack/react-query";
765
803
  import {
766
- auth as auth3
804
+ auth as auth4
767
805
  } from "@viu/emporix-sdk";
768
806
  var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
769
807
  function customerOnlyCtx(token) {
770
808
  if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
771
- return auth3.customer(token);
809
+ return auth4.customer(token);
772
810
  }
773
811
  function useCheckout() {
774
- const { client } = useEmporix();
812
+ const { client, storage } = useEmporix();
813
+ const qc = useQueryClient4();
775
814
  const { ctx } = useReadAuth();
776
815
  const { activeCompany } = useActiveCompany();
777
816
  const withLE = (input) => {
@@ -779,17 +818,23 @@ function useCheckout() {
779
818
  if ("legalEntityId" in input) return input;
780
819
  return { ...input, legalEntityId: activeCompany.id };
781
820
  };
821
+ const onOrderPlaced = () => {
822
+ storage.setCartId(null);
823
+ qc.removeQueries({ queryKey: ["emporix", "cart-bootstrap"] });
824
+ };
782
825
  const placeOrder = useMutation3({
783
826
  mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
784
827
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
785
828
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
786
- })
829
+ }),
830
+ onSuccess: onOrderPlaced
787
831
  });
788
832
  const placeOrderFromQuote = useMutation3({
789
833
  mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
790
834
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
791
835
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
792
- })
836
+ }),
837
+ onSuccess: onOrderPlaced
793
838
  });
794
839
  return { placeOrder, placeOrderFromQuote };
795
840
  }
@@ -798,7 +843,7 @@ function usePaymentModes(options = {}) {
798
843
  const token = useCustomerToken();
799
844
  const { siteCode } = useReadSite();
800
845
  const { activeCompany } = useActiveCompany();
801
- return useQuery7({
846
+ return useQuery5({
802
847
  queryKey: emporixKey(
803
848
  "payment-modes",
804
849
  [activeCompany?.id ?? null],
@@ -811,16 +856,16 @@ function usePaymentModes(options = {}) {
811
856
  }
812
857
 
813
858
  // src/hooks/use-match-prices.ts
814
- import { useQuery as useQuery8 } from "@tanstack/react-query";
859
+ import { useQuery as useQuery6 } from "@tanstack/react-query";
815
860
  import {
816
- auth as auth4
861
+ auth as auth5
817
862
  } from "@viu/emporix-sdk";
818
863
  var PRICES_STALE_TIME = 6e4;
819
864
  function useMatchPrices(input, options = {}) {
820
865
  const { client } = useEmporix();
821
866
  const { siteCode } = useReadSite();
822
- const ctx = options.customerToken ? auth4.customer(options.customerToken) : auth4.anonymous();
823
- return useQuery8({
867
+ const ctx = options.customerToken ? auth5.customer(options.customerToken) : auth5.anonymous();
868
+ return useQuery6({
824
869
  queryKey: [
825
870
  "emporix",
826
871
  "match-prices",
@@ -833,16 +878,16 @@ function useMatchPrices(input, options = {}) {
833
878
  }
834
879
 
835
880
  // src/hooks/use-match-prices-chunked.ts
836
- import { useQuery as useQuery9 } from "@tanstack/react-query";
881
+ import { useQuery as useQuery7 } from "@tanstack/react-query";
837
882
  import {
838
- auth as auth5
883
+ auth as auth6
839
884
  } from "@viu/emporix-sdk";
840
885
  var PRICES_STALE_TIME2 = 6e4;
841
886
  function useMatchPricesChunked(input, options = {}) {
842
887
  const { client } = useEmporix();
843
888
  const { siteCode } = useReadSite();
844
- const ctx = options.customerToken ? auth5.customer(options.customerToken) : auth5.anonymous();
845
- return useQuery9({
889
+ const ctx = options.customerToken ? auth6.customer(options.customerToken) : auth6.anonymous();
890
+ return useQuery7({
846
891
  queryKey: [
847
892
  "emporix",
848
893
  "match-prices-chunked",
@@ -877,21 +922,21 @@ function useProductMedia(productId) {
877
922
 
878
923
  // src/hooks/use-my-segments.ts
879
924
  import {
880
- useQuery as useQuery10
925
+ useQuery as useQuery8
881
926
  } from "@tanstack/react-query";
882
927
  import {
883
- auth as auth6
928
+ auth as auth7
884
929
  } from "@viu/emporix-sdk";
885
930
  var SEGMENTS_STALE_TIME = 5 * 6e4;
886
931
  function customerCtx(token) {
887
932
  if (!token) throw new Error("requires a customer token in storage");
888
- return auth6.customer(token);
933
+ return auth7.customer(token);
889
934
  }
890
935
  function useMySegments(query = {}) {
891
936
  const { client } = useEmporix();
892
937
  const token = useCustomerToken();
893
938
  const { siteCode, language } = useReadSite();
894
- return useQuery10({
939
+ return useQuery8({
895
940
  queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
896
941
  enabled: token !== null,
897
942
  queryFn: () => client.segments.list(query, customerCtx(token)),
@@ -902,7 +947,7 @@ function useMySegmentItems(query = {}) {
902
947
  const { client } = useEmporix();
903
948
  const token = useCustomerToken();
904
949
  const { siteCode, language } = useReadSite();
905
- return useQuery10({
950
+ return useQuery8({
906
951
  queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
907
952
  enabled: token !== null,
908
953
  queryFn: () => client.segments.listItems(query, customerCtx(token)),
@@ -913,7 +958,7 @@ function useMySegmentCategoryTree(query = {}) {
913
958
  const { client } = useEmporix();
914
959
  const token = useCustomerToken();
915
960
  const { siteCode, language } = useReadSite();
916
- return useQuery10({
961
+ return useQuery8({
917
962
  queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
918
963
  enabled: token !== null,
919
964
  queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
@@ -924,7 +969,7 @@ function useMySegmentProducts(query = {}) {
924
969
  const { client } = useEmporix();
925
970
  const token = useCustomerToken();
926
971
  const { siteCode, language } = useReadSite();
927
- return useQuery10({
972
+ return useQuery8({
928
973
  queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
929
974
  enabled: token !== null,
930
975
  queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
@@ -954,7 +999,7 @@ function useMySegmentCategories(query = {}) {
954
999
  const { client } = useEmporix();
955
1000
  const token = useCustomerToken();
956
1001
  const { siteCode, language } = useReadSite();
957
- return useQuery10({
1002
+ return useQuery8({
958
1003
  queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
959
1004
  enabled: token !== null,
960
1005
  queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
@@ -982,12 +1027,12 @@ function useMySegmentCategoriesInfinite(query = {}) {
982
1027
  }
983
1028
 
984
1029
  // src/hooks/use-customer-profile.ts
985
- import { useMutation as useMutation4, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
1030
+ import { useMutation as useMutation4, useQueryClient as useQueryClient5 } from "@tanstack/react-query";
986
1031
  import "@viu/emporix-sdk";
987
1032
  function useUpdateCustomer() {
988
1033
  const { client } = useEmporix();
989
1034
  const ctx = useCustomerOnlyCtx();
990
- const qc = useQueryClient4();
1035
+ const qc = useQueryClient5();
991
1036
  return useMutation4({
992
1037
  mutationFn: (patch) => client.customers.update(patch, ctx),
993
1038
  onSuccess: () => {
@@ -1006,19 +1051,19 @@ function useChangePassword() {
1006
1051
  // src/hooks/use-customer-addresses.ts
1007
1052
  import {
1008
1053
  useMutation as useMutation5,
1009
- useQuery as useQuery11,
1010
- useQueryClient as useQueryClient5
1054
+ useQuery as useQuery9,
1055
+ useQueryClient as useQueryClient6
1011
1056
  } from "@tanstack/react-query";
1012
1057
  import {
1013
- auth as auth7
1058
+ auth as auth8
1014
1059
  } from "@viu/emporix-sdk";
1015
1060
  var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
1016
1061
  function useCustomerAddresses(options = {}) {
1017
1062
  const { client } = useEmporix();
1018
1063
  const token = useCustomerToken();
1019
1064
  const { activeCompany } = useActiveCompany();
1020
- const ctx = options.auth ?? (token ? auth7.customer(token) : null);
1021
- return useQuery11({
1065
+ const ctx = options.auth ?? (token ? auth8.customer(token) : null);
1066
+ return useQuery9({
1022
1067
  queryKey: [
1023
1068
  ...ADDRESSES_KEY,
1024
1069
  { tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
@@ -1030,7 +1075,7 @@ function useCustomerAddresses(options = {}) {
1030
1075
  function useAddressMutations() {
1031
1076
  const { client } = useEmporix();
1032
1077
  const ctx = useCustomerOnlyCtx();
1033
- const qc = useQueryClient5();
1078
+ const qc = useQueryClient6();
1034
1079
  const invalidate = () => {
1035
1080
  void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
1036
1081
  };
@@ -1053,11 +1098,11 @@ function useAddressMutations() {
1053
1098
  // src/hooks/use-password-reset.ts
1054
1099
  import { useMutation as useMutation6 } from "@tanstack/react-query";
1055
1100
  import {
1056
- auth as auth8
1101
+ auth as auth9
1057
1102
  } from "@viu/emporix-sdk";
1058
1103
  function usePasswordReset() {
1059
1104
  const { client } = useEmporix();
1060
- const anonCtx = auth8.anonymous();
1105
+ const anonCtx = auth9.anonymous();
1061
1106
  return {
1062
1107
  request: useMutation6({
1063
1108
  mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
@@ -1069,7 +1114,7 @@ function usePasswordReset() {
1069
1114
  }
1070
1115
 
1071
1116
  // src/hooks/use-sites.ts
1072
- import { useQuery as useQuery12 } from "@tanstack/react-query";
1117
+ import { useQuery as useQuery10 } from "@tanstack/react-query";
1073
1118
 
1074
1119
  // src/hooks/use-site-context.ts
1075
1120
  import { useContext as useContext3 } from "react";
@@ -1086,7 +1131,7 @@ var SITES_STALE_TIME = 10 * 6e4;
1086
1131
  function useSites(options = {}) {
1087
1132
  const { client } = useEmporix();
1088
1133
  const { ctx } = useReadAuth(options.auth);
1089
- return useQuery12({
1134
+ return useQuery10({
1090
1135
  queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
1091
1136
  queryFn: () => client.sites.list(ctx),
1092
1137
  staleTime: SITES_STALE_TIME
@@ -1095,7 +1140,7 @@ function useSites(options = {}) {
1095
1140
  function useDefaultSite(options = {}) {
1096
1141
  const { client } = useEmporix();
1097
1142
  const { ctx } = useReadAuth(options.auth);
1098
- return useQuery12({
1143
+ return useQuery10({
1099
1144
  queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
1100
1145
  queryFn: () => client.sites.current(ctx),
1101
1146
  staleTime: SITES_STALE_TIME
@@ -1108,105 +1153,99 @@ function useActiveSite(options = {}) {
1108
1153
  }
1109
1154
 
1110
1155
  // src/hooks/use-my-companies.ts
1111
- import { useQuery as useQuery13 } from "@tanstack/react-query";
1112
- import { auth as auth9 } from "@viu/emporix-sdk";
1156
+ import "@tanstack/react-query";
1157
+ import "@viu/emporix-sdk";
1113
1158
  function useMyCompanies() {
1114
1159
  const { client } = useEmporix();
1115
- const token = useCustomerToken();
1116
- return useQuery13({
1117
- queryKey: emporixKey("companies", ["mine"], {
1118
- tenant: client.tenant,
1119
- authKind: token ? "customer" : "anonymous"
1120
- }),
1121
- enabled: token !== null,
1122
- queryFn: () => client.companies.listMine(auth9.customer(token))
1160
+ return useEmporixQuery({
1161
+ mode: "customer",
1162
+ site: "none",
1163
+ resource: "companies",
1164
+ args: ["mine"],
1165
+ queryFn: (ctx) => client.companies.listMine(ctx)
1123
1166
  });
1124
1167
  }
1125
1168
 
1126
1169
  // src/hooks/use-company.ts
1127
- import { useQuery as useQuery14 } from "@tanstack/react-query";
1128
- import { auth as auth10 } from "@viu/emporix-sdk";
1170
+ import "@tanstack/react-query";
1171
+ import "@viu/emporix-sdk";
1129
1172
  function useCompany(legalEntityId) {
1130
1173
  const { client } = useEmporix();
1131
- const token = useCustomerToken();
1132
- return useQuery14({
1133
- queryKey: emporixKey("companies", [legalEntityId ?? null], {
1134
- tenant: client.tenant,
1135
- authKind: token ? "customer" : "anonymous"
1136
- }),
1137
- enabled: token !== null && legalEntityId !== void 0,
1138
- queryFn: () => client.companies.get(legalEntityId, auth10.customer(token))
1174
+ return useEmporixQuery({
1175
+ mode: "customer",
1176
+ site: "none",
1177
+ resource: "companies",
1178
+ args: [legalEntityId ?? null],
1179
+ enabled: legalEntityId !== void 0,
1180
+ queryFn: (ctx) => client.companies.get(legalEntityId, ctx)
1139
1181
  });
1140
1182
  }
1141
1183
 
1142
1184
  // src/hooks/use-company-contacts.ts
1143
- import { useQuery as useQuery15 } from "@tanstack/react-query";
1144
- import { auth as auth11 } from "@viu/emporix-sdk";
1185
+ import "@tanstack/react-query";
1186
+ import "@viu/emporix-sdk";
1145
1187
  function useCompanyContacts(legalEntityId) {
1146
- const { client, storage } = useEmporix();
1147
- const token = storage.getCustomerToken();
1148
- return useQuery15({
1149
- queryKey: emporixKey("companies", ["contacts", legalEntityId ?? null], {
1150
- tenant: client.tenant,
1151
- authKind: token ? "customer" : "anonymous"
1152
- }),
1153
- enabled: token !== null && legalEntityId !== void 0,
1154
- queryFn: () => client.contacts.listForCompany(legalEntityId, auth11.customer(token))
1188
+ const { client } = useEmporix();
1189
+ return useEmporixQuery({
1190
+ mode: "customer",
1191
+ site: "none",
1192
+ resource: "companies",
1193
+ args: ["contacts", legalEntityId ?? null],
1194
+ enabled: legalEntityId !== void 0,
1195
+ queryFn: (ctx) => client.contacts.listForCompany(legalEntityId, ctx)
1155
1196
  });
1156
1197
  }
1157
1198
 
1158
1199
  // src/hooks/use-company-locations.ts
1159
- import { useQuery as useQuery16 } from "@tanstack/react-query";
1160
- import { auth as auth12 } from "@viu/emporix-sdk";
1200
+ import "@tanstack/react-query";
1201
+ import "@viu/emporix-sdk";
1161
1202
  function useCompanyLocations(legalEntityId) {
1162
1203
  const { client } = useEmporix();
1163
- const token = useCustomerToken();
1164
- return useQuery16({
1165
- queryKey: emporixKey("companies", ["locations", legalEntityId ?? null], {
1166
- tenant: client.tenant,
1167
- authKind: token ? "customer" : "anonymous"
1168
- }),
1169
- enabled: token !== null && legalEntityId !== void 0,
1170
- queryFn: () => client.locations.listForCompany(legalEntityId, auth12.customer(token))
1204
+ return useEmporixQuery({
1205
+ mode: "customer",
1206
+ site: "none",
1207
+ resource: "companies",
1208
+ args: ["locations", legalEntityId ?? null],
1209
+ enabled: legalEntityId !== void 0,
1210
+ queryFn: (ctx) => client.locations.listForCompany(legalEntityId, ctx)
1171
1211
  });
1172
1212
  }
1173
1213
 
1174
1214
  // src/hooks/use-company-groups.ts
1175
- import { useQuery as useQuery17 } from "@tanstack/react-query";
1176
- import { auth as auth13 } from "@viu/emporix-sdk";
1215
+ import "@tanstack/react-query";
1216
+ import "@viu/emporix-sdk";
1177
1217
  function useCompanyGroups(legalEntityId) {
1178
1218
  const { client } = useEmporix();
1179
- const token = useCustomerToken();
1180
- return useQuery17({
1181
- queryKey: emporixKey("companies", ["groups", legalEntityId ?? null], {
1182
- tenant: client.tenant,
1183
- authKind: token ? "customer" : "anonymous"
1184
- }),
1185
- enabled: token !== null && legalEntityId !== void 0,
1186
- queryFn: () => client.customerGroups.listForCompany(legalEntityId, auth13.customer(token))
1219
+ return useEmporixQuery({
1220
+ mode: "customer",
1221
+ site: "none",
1222
+ resource: "companies",
1223
+ args: ["groups", legalEntityId ?? null],
1224
+ enabled: legalEntityId !== void 0,
1225
+ queryFn: (ctx) => client.customerGroups.listForCompany(legalEntityId, ctx)
1187
1226
  });
1188
1227
  }
1189
1228
 
1190
1229
  // src/hooks/use-company-mutations.ts
1191
1230
  import {
1192
1231
  useMutation as useMutation7,
1193
- useQueryClient as useQueryClient6
1232
+ useQueryClient as useQueryClient7
1194
1233
  } from "@tanstack/react-query";
1195
1234
  import {
1196
- auth as auth14
1235
+ auth as auth10
1197
1236
  } from "@viu/emporix-sdk";
1198
1237
  function useCustomerAuthResolver() {
1199
1238
  const { storage } = useEmporix();
1200
1239
  return () => {
1201
1240
  const token = storage.getCustomerToken();
1202
1241
  if (!token) throw new Error("Mutation requires a logged-in customer token");
1203
- return auth14.customer(token);
1242
+ return auth10.customer(token);
1204
1243
  };
1205
1244
  }
1206
1245
  function useCreateCompany() {
1207
1246
  const { client } = useEmporix();
1208
1247
  const resolveAuth = useCustomerAuthResolver();
1209
- const qc = useQueryClient6();
1248
+ const qc = useQueryClient7();
1210
1249
  return useMutation7({
1211
1250
  mutationFn: (input) => client.companies.create(input, resolveAuth()),
1212
1251
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
@@ -1215,7 +1254,7 @@ function useCreateCompany() {
1215
1254
  function useUpdateCompany() {
1216
1255
  const { client } = useEmporix();
1217
1256
  const resolveAuth = useCustomerAuthResolver();
1218
- const qc = useQueryClient6();
1257
+ const qc = useQueryClient7();
1219
1258
  return useMutation7({
1220
1259
  mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
1221
1260
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
@@ -1224,7 +1263,7 @@ function useUpdateCompany() {
1224
1263
  function useDeleteCompany() {
1225
1264
  const { client } = useEmporix();
1226
1265
  const resolveAuth = useCustomerAuthResolver();
1227
- const qc = useQueryClient6();
1266
+ const qc = useQueryClient7();
1228
1267
  return useMutation7({
1229
1268
  mutationFn: (id) => client.companies.delete(id, resolveAuth()),
1230
1269
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
@@ -1233,7 +1272,7 @@ function useDeleteCompany() {
1233
1272
  function useAssignContact() {
1234
1273
  const { client } = useEmporix();
1235
1274
  const resolveAuth = useCustomerAuthResolver();
1236
- const qc = useQueryClient6();
1275
+ const qc = useQueryClient7();
1237
1276
  return useMutation7({
1238
1277
  mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
1239
1278
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
@@ -1242,7 +1281,7 @@ function useAssignContact() {
1242
1281
  function useUpdateContactAssignment() {
1243
1282
  const { client } = useEmporix();
1244
1283
  const resolveAuth = useCustomerAuthResolver();
1245
- const qc = useQueryClient6();
1284
+ const qc = useQueryClient7();
1246
1285
  return useMutation7({
1247
1286
  mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
1248
1287
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
@@ -1251,7 +1290,7 @@ function useUpdateContactAssignment() {
1251
1290
  function useUnassignContact() {
1252
1291
  const { client } = useEmporix();
1253
1292
  const resolveAuth = useCustomerAuthResolver();
1254
- const qc = useQueryClient6();
1293
+ const qc = useQueryClient7();
1255
1294
  return useMutation7({
1256
1295
  mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
1257
1296
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
@@ -1260,7 +1299,7 @@ function useUnassignContact() {
1260
1299
  function useCreateLocation() {
1261
1300
  const { client } = useEmporix();
1262
1301
  const resolveAuth = useCustomerAuthResolver();
1263
- const qc = useQueryClient6();
1302
+ const qc = useQueryClient7();
1264
1303
  return useMutation7({
1265
1304
  mutationFn: (input) => client.locations.create(input, resolveAuth()),
1266
1305
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
@@ -1269,7 +1308,7 @@ function useCreateLocation() {
1269
1308
  function useUpdateLocation() {
1270
1309
  const { client } = useEmporix();
1271
1310
  const resolveAuth = useCustomerAuthResolver();
1272
- const qc = useQueryClient6();
1311
+ const qc = useQueryClient7();
1273
1312
  return useMutation7({
1274
1313
  mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
1275
1314
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
@@ -1278,7 +1317,7 @@ function useUpdateLocation() {
1278
1317
  function useDeleteLocation() {
1279
1318
  const { client } = useEmporix();
1280
1319
  const resolveAuth = useCustomerAuthResolver();
1281
- const qc = useQueryClient6();
1320
+ const qc = useQueryClient7();
1282
1321
  return useMutation7({
1283
1322
  mutationFn: (id) => client.locations.delete(id, resolveAuth()),
1284
1323
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
@@ -1287,7 +1326,7 @@ function useDeleteLocation() {
1287
1326
  function useAddGroupMember() {
1288
1327
  const { client } = useEmporix();
1289
1328
  const resolveAuth = useCustomerAuthResolver();
1290
- const qc = useQueryClient6();
1329
+ const qc = useQueryClient7();
1291
1330
  return useMutation7({
1292
1331
  mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
1293
1332
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
@@ -1296,7 +1335,7 @@ function useAddGroupMember() {
1296
1335
  function useRemoveGroupMember() {
1297
1336
  const { client } = useEmporix();
1298
1337
  const resolveAuth = useCustomerAuthResolver();
1299
- const qc = useQueryClient6();
1338
+ const qc = useQueryClient7();
1300
1339
  return useMutation7({
1301
1340
  mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
1302
1341
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
@@ -1324,10 +1363,10 @@ function useCompanySwitcher() {
1324
1363
  // src/hooks/use-cloud-functions.ts
1325
1364
  import {
1326
1365
  useMutation as useMutation8,
1327
- useQuery as useQuery18
1366
+ useQuery as useQuery11
1328
1367
  } from "@tanstack/react-query";
1329
1368
  import {
1330
- auth as auth15
1369
+ auth as auth11
1331
1370
  } from "@viu/emporix-sdk";
1332
1371
  function useInvokeCloudFunction() {
1333
1372
  const { client, storage } = useEmporix();
@@ -1335,7 +1374,7 @@ function useInvokeCloudFunction() {
1335
1374
  mutationFn: (vars) => {
1336
1375
  const { functionId, auth: authOverride, ...options } = vars;
1337
1376
  const token = storage.getCustomerToken();
1338
- const authCtx = authOverride ?? (token ? auth15.customer(token) : auth15.anonymous());
1377
+ const authCtx = authOverride ?? (token ? auth11.customer(token) : auth11.anonymous());
1339
1378
  return client.cloudFunctions.invoke(functionId, options, authCtx);
1340
1379
  }
1341
1380
  });
@@ -1344,8 +1383,8 @@ function useCloudFunction(functionId, options, queryOptions) {
1344
1383
  const { client } = useEmporix();
1345
1384
  const token = useCustomerToken();
1346
1385
  const { auth: authOverride, ...invokeOptions } = options ?? {};
1347
- const authCtx = authOverride ?? (token ? auth15.customer(token) : auth15.anonymous());
1348
- return useQuery18({
1386
+ const authCtx = authOverride ?? (token ? auth11.customer(token) : auth11.anonymous());
1387
+ return useQuery11({
1349
1388
  queryKey: emporixKey(
1350
1389
  "cloud-function",
1351
1390
  [functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
@@ -1362,22 +1401,19 @@ function useCloudFunction(functionId, options, queryOptions) {
1362
1401
  }
1363
1402
 
1364
1403
  // src/hooks/use-my-orders.ts
1365
- import { useQuery as useQuery19 } from "@tanstack/react-query";
1366
- import { auth as auth16 } from "@viu/emporix-sdk";
1404
+ import "@tanstack/react-query";
1405
+ import "@viu/emporix-sdk";
1367
1406
  function useMyOrders(options = {}) {
1368
1407
  const { client } = useEmporix();
1369
1408
  const { activeCompany } = useActiveCompany();
1370
- const { siteCode, language } = useReadSite();
1371
- const token = useCustomerToken();
1409
+ const { siteCode } = useReadSite();
1372
1410
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1373
- return useQuery19({
1374
- queryKey: emporixKey(
1375
- "orders",
1376
- ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
1377
- { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1378
- ),
1379
- enabled: token !== null,
1380
- queryFn: () => client.orders.listMine(auth16.customer(token), {
1411
+ return useEmporixQuery({
1412
+ mode: "customer",
1413
+ site: "full",
1414
+ resource: "orders",
1415
+ args: ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
1416
+ queryFn: (ctx) => client.orders.listMine(ctx, {
1381
1417
  ...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
1382
1418
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1383
1419
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -1389,7 +1425,7 @@ function useMyOrders(options = {}) {
1389
1425
  }
1390
1426
 
1391
1427
  // src/hooks/use-my-orders-infinite.ts
1392
- import { auth as auth17 } from "@viu/emporix-sdk";
1428
+ import { auth as auth12 } from "@viu/emporix-sdk";
1393
1429
  function useMyOrdersInfinite(options = {}) {
1394
1430
  const { client } = useEmporix();
1395
1431
  const { activeCompany } = useActiveCompany();
@@ -1403,7 +1439,7 @@ function useMyOrdersInfinite(options = {}) {
1403
1439
  { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1404
1440
  ),
1405
1441
  enabled: token !== null,
1406
- fetchPage: (pageNumber) => client.orders.listMine(auth17.customer(token), {
1442
+ fetchPage: (pageNumber) => client.orders.listMine(auth12.customer(token), {
1407
1443
  pageNumber,
1408
1444
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1409
1445
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -1415,33 +1451,30 @@ function useMyOrdersInfinite(options = {}) {
1415
1451
  }
1416
1452
 
1417
1453
  // src/hooks/use-order.ts
1418
- import { useQuery as useQuery20 } from "@tanstack/react-query";
1419
- import { auth as auth18 } from "@viu/emporix-sdk";
1454
+ import "@tanstack/react-query";
1455
+ import "@viu/emporix-sdk";
1420
1456
  function useOrder(orderId, options = {}) {
1421
1457
  const { client } = useEmporix();
1422
- const token = useCustomerToken();
1423
- const { language } = useReadSite();
1424
- return useQuery20({
1425
- queryKey: emporixKey("orders", [orderId ?? null], {
1426
- tenant: client.tenant,
1427
- authKind: token ? "customer" : "anonymous",
1428
- language
1429
- }),
1430
- enabled: token !== null && orderId !== void 0,
1431
- queryFn: () => client.orders.get(
1458
+ return useEmporixQuery({
1459
+ mode: "customer",
1460
+ site: "language",
1461
+ resource: "orders",
1462
+ args: [orderId ?? null],
1463
+ enabled: orderId !== void 0,
1464
+ queryFn: (ctx) => client.orders.get(
1432
1465
  orderId,
1433
- auth18.customer(token),
1466
+ ctx,
1434
1467
  options.saasToken ? { saasToken: options.saasToken } : {}
1435
1468
  )
1436
1469
  });
1437
1470
  }
1438
1471
 
1439
1472
  // src/hooks/use-cancel-order.ts
1440
- import { useMutation as useMutation9, useQueryClient as useQueryClient7 } from "@tanstack/react-query";
1441
- import { auth as auth19 } from "@viu/emporix-sdk";
1473
+ import { useMutation as useMutation9, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1474
+ import { auth as auth13 } from "@viu/emporix-sdk";
1442
1475
  function useCancelOrder() {
1443
1476
  const { client, storage } = useEmporix();
1444
- const qc = useQueryClient7();
1477
+ const qc = useQueryClient8();
1445
1478
  return useMutation9({
1446
1479
  mutationKey: ["emporix", "orders", "cancel"],
1447
1480
  mutationFn: async (input) => {
@@ -1450,7 +1483,7 @@ function useCancelOrder() {
1450
1483
  const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
1451
1484
  await client.orders.cancel(
1452
1485
  orderId,
1453
- auth19.customer(token),
1486
+ auth13.customer(token),
1454
1487
  saasToken ? { saasToken } : {}
1455
1488
  );
1456
1489
  },
@@ -1461,11 +1494,11 @@ function useCancelOrder() {
1461
1494
  }
1462
1495
 
1463
1496
  // src/hooks/use-order-transition.ts
1464
- import { useMutation as useMutation10, useQueryClient as useQueryClient8 } from "@tanstack/react-query";
1465
- import { auth as auth20 } from "@viu/emporix-sdk";
1497
+ import { useMutation as useMutation10, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
1498
+ import { auth as auth14 } from "@viu/emporix-sdk";
1466
1499
  function useOrderTransition() {
1467
1500
  const { client, storage } = useEmporix();
1468
- const qc = useQueryClient8();
1501
+ const qc = useQueryClient9();
1469
1502
  return useMutation10({
1470
1503
  mutationKey: ["emporix", "orders", "transition"],
1471
1504
  mutationFn: async ({ orderId, status, comment, saasToken }) => {
@@ -1474,7 +1507,7 @@ function useOrderTransition() {
1474
1507
  await client.orders.transition(
1475
1508
  orderId,
1476
1509
  status,
1477
- auth20.customer(token),
1510
+ auth14.customer(token),
1478
1511
  {
1479
1512
  ...comment !== void 0 ? { comment } : {},
1480
1513
  ...saasToken !== void 0 ? { saasToken } : {}
@@ -1488,17 +1521,17 @@ function useOrderTransition() {
1488
1521
  }
1489
1522
 
1490
1523
  // src/hooks/use-reorder.ts
1491
- import { useMutation as useMutation11, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
1492
- import { auth as auth21 } from "@viu/emporix-sdk";
1524
+ import { useMutation as useMutation11, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
1525
+ import { auth as auth15 } from "@viu/emporix-sdk";
1493
1526
  function useReorder() {
1494
1527
  const { client, storage } = useEmporix();
1495
- const qc = useQueryClient9();
1528
+ const qc = useQueryClient10();
1496
1529
  return useMutation11({
1497
1530
  mutationKey: ["emporix", "orders", "reorder"],
1498
1531
  mutationFn: async ({ orderId, saasToken }) => {
1499
1532
  const token = storage.getCustomerToken();
1500
1533
  if (!token) throw new Error("useReorder: requires a logged-in customer");
1501
- const ctx = auth21.customer(token);
1534
+ const ctx = auth15.customer(token);
1502
1535
  const order = await qc.fetchQuery({
1503
1536
  queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
1504
1537
  queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
@@ -1545,12 +1578,12 @@ function useReorder() {
1545
1578
  }
1546
1579
 
1547
1580
  // src/hooks/use-sales-order.ts
1548
- import { useQuery as useQuery21 } from "@tanstack/react-query";
1581
+ import { useQuery as useQuery12 } from "@tanstack/react-query";
1549
1582
  import "@viu/emporix-sdk";
1550
1583
  function useSalesOrder(orderId, authCtx) {
1551
1584
  const { client } = useEmporix();
1552
1585
  const { language } = useReadSite();
1553
- return useQuery21({
1586
+ return useQuery12({
1554
1587
  queryKey: emporixKey("salesorders", [orderId ?? null], {
1555
1588
  tenant: client.tenant,
1556
1589
  authKind: authCtx?.kind ?? "anonymous",
@@ -1562,19 +1595,19 @@ function useSalesOrder(orderId, authCtx) {
1562
1595
  }
1563
1596
 
1564
1597
  // src/hooks/use-update-sales-order.ts
1565
- import { useMutation as useMutation12, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
1598
+ import { useMutation as useMutation12, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
1566
1599
  import "@viu/emporix-sdk";
1567
1600
  function useUpdateSalesOrder() {
1568
1601
  const { client } = useEmporix();
1569
- const qc = useQueryClient10();
1602
+ const qc = useQueryClient11();
1570
1603
  return useMutation12({
1571
1604
  mutationKey: ["emporix", "salesorders", "update"],
1572
- mutationFn: async ({ orderId, patch, auth: auth24, recalculate }) => {
1573
- if (!auth24) throw new Error("useUpdateSalesOrder: requires an auth context");
1605
+ mutationFn: async ({ orderId, patch, auth: auth18, recalculate }) => {
1606
+ if (!auth18) throw new Error("useUpdateSalesOrder: requires an auth context");
1574
1607
  return client.salesOrders.update(
1575
1608
  orderId,
1576
1609
  patch,
1577
- auth24,
1610
+ auth18,
1578
1611
  recalculate !== void 0 ? { recalculate } : {}
1579
1612
  );
1580
1613
  },
@@ -1587,13 +1620,13 @@ function useUpdateSalesOrder() {
1587
1620
  }
1588
1621
 
1589
1622
  // src/hooks/use-availability.ts
1590
- import { useQuery as useQuery22 } from "@tanstack/react-query";
1591
- import { auth as auth22 } from "@viu/emporix-sdk";
1623
+ import { useQuery as useQuery13 } from "@tanstack/react-query";
1624
+ import { auth as auth16 } from "@viu/emporix-sdk";
1592
1625
  var AVAILABILITY_STALE_TIME = 3e4;
1593
1626
  function useAvailability(productId, siteCode, options = {}) {
1594
1627
  const { client } = useEmporix();
1595
- const ctx = options.customerToken ? auth22.customer(options.customerToken) : auth22.anonymous();
1596
- return useQuery22({
1628
+ const ctx = options.customerToken ? auth16.customer(options.customerToken) : auth16.anonymous();
1629
+ return useQuery13({
1597
1630
  queryKey: [
1598
1631
  "emporix",
1599
1632
  "availability",
@@ -1614,13 +1647,13 @@ function useAvailability(productId, siteCode, options = {}) {
1614
1647
  }
1615
1648
 
1616
1649
  // src/hooks/use-availabilities.ts
1617
- import { useQuery as useQuery23 } from "@tanstack/react-query";
1618
- import { auth as auth23 } from "@viu/emporix-sdk";
1650
+ import { useQuery as useQuery14 } from "@tanstack/react-query";
1651
+ import { auth as auth17 } from "@viu/emporix-sdk";
1619
1652
  var AVAILABILITY_STALE_TIME2 = 3e4;
1620
1653
  function useAvailabilities(productIds, siteCode, options = {}) {
1621
1654
  const { client } = useEmporix();
1622
- const ctx = options.customerToken ? auth23.customer(options.customerToken) : auth23.anonymous();
1623
- return useQuery23({
1655
+ const ctx = options.customerToken ? auth17.customer(options.customerToken) : auth17.anonymous();
1656
+ return useQuery14({
1624
1657
  queryKey: [
1625
1658
  "emporix",
1626
1659
  "availabilities",
@@ -1641,7 +1674,7 @@ function useAvailabilities(productIds, siteCode, options = {}) {
1641
1674
  }
1642
1675
 
1643
1676
  // src/hooks/use-coupons.ts
1644
- import { useMutation as useMutation13, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
1677
+ import { useMutation as useMutation13, useQueryClient as useQueryClient12 } from "@tanstack/react-query";
1645
1678
  var INVALIDATE_KEY2 = ["emporix", "coupons"];
1646
1679
  function useValidateCoupon() {
1647
1680
  const { client } = useEmporix();
@@ -1653,7 +1686,7 @@ function useValidateCoupon() {
1653
1686
  function useRedeemCoupon() {
1654
1687
  const { client } = useEmporix();
1655
1688
  const { ctx } = useReadAuth();
1656
- const qc = useQueryClient11();
1689
+ const qc = useQueryClient12();
1657
1690
  return useMutation13({
1658
1691
  mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
1659
1692
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
@@ -1662,16 +1695,16 @@ function useRedeemCoupon() {
1662
1695
 
1663
1696
  // src/hooks/use-reward-points.ts
1664
1697
  import {
1665
- useQuery as useQuery24,
1698
+ useQuery as useQuery15,
1666
1699
  useMutation as useMutation14,
1667
- useQueryClient as useQueryClient12
1700
+ useQueryClient as useQueryClient13
1668
1701
  } from "@tanstack/react-query";
1669
1702
  var STALE = 3e4;
1670
1703
  var INVALIDATE_KEY3 = ["emporix", "reward-points"];
1671
1704
  function useMyRewardPoints() {
1672
1705
  const { client } = useEmporix();
1673
1706
  const ctx = useCustomerOnlyCtx();
1674
- return useQuery24({
1707
+ return useQuery15({
1675
1708
  queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
1676
1709
  queryFn: () => client.rewardPoints.getMyPoints(ctx),
1677
1710
  staleTime: STALE
@@ -1680,7 +1713,7 @@ function useMyRewardPoints() {
1680
1713
  function useMyRewardPointsSummary() {
1681
1714
  const { client } = useEmporix();
1682
1715
  const ctx = useCustomerOnlyCtx();
1683
- return useQuery24({
1716
+ return useQuery15({
1684
1717
  queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
1685
1718
  queryFn: () => client.rewardPoints.getMySummary(ctx),
1686
1719
  staleTime: STALE
@@ -1689,7 +1722,7 @@ function useMyRewardPointsSummary() {
1689
1722
  function useRedeemOptions() {
1690
1723
  const { client } = useEmporix();
1691
1724
  const { ctx } = useReadAuth();
1692
- return useQuery24({
1725
+ return useQuery15({
1693
1726
  queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
1694
1727
  queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
1695
1728
  staleTime: STALE
@@ -1698,7 +1731,7 @@ function useRedeemOptions() {
1698
1731
  function useRedeemRewardPoints() {
1699
1732
  const { client } = useEmporix();
1700
1733
  const ctx = useCustomerOnlyCtx();
1701
- const qc = useQueryClient12();
1734
+ const qc = useQueryClient13();
1702
1735
  return useMutation14({
1703
1736
  mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
1704
1737
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
@@ -1707,16 +1740,16 @@ function useRedeemRewardPoints() {
1707
1740
 
1708
1741
  // src/hooks/use-returns.ts
1709
1742
  import {
1710
- useQuery as useQuery25,
1743
+ useQuery as useQuery16,
1711
1744
  useMutation as useMutation15,
1712
- useQueryClient as useQueryClient13
1745
+ useQueryClient as useQueryClient14
1713
1746
  } from "@tanstack/react-query";
1714
1747
  var STALE2 = 3e4;
1715
1748
  var INVALIDATE_KEY4 = ["emporix", "returns"];
1716
1749
  function useMyReturns(opts = {}) {
1717
1750
  const { client } = useEmporix();
1718
1751
  const ctx = useCustomerOnlyCtx();
1719
- return useQuery25({
1752
+ return useQuery16({
1720
1753
  queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1721
1754
  queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
1722
1755
  staleTime: STALE2
@@ -1725,7 +1758,7 @@ function useMyReturns(opts = {}) {
1725
1758
  function useReturn(returnId) {
1726
1759
  const { client } = useEmporix();
1727
1760
  const ctx = useCustomerOnlyCtx();
1728
- return useQuery25({
1761
+ return useQuery16({
1729
1762
  queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1730
1763
  queryFn: () => client.returns.getReturn(returnId, ctx),
1731
1764
  enabled: Boolean(returnId),
@@ -1735,7 +1768,7 @@ function useReturn(returnId) {
1735
1768
  function useCreateReturn() {
1736
1769
  const { client } = useEmporix();
1737
1770
  const ctx = useCustomerOnlyCtx();
1738
- const qc = useQueryClient13();
1771
+ const qc = useQueryClient14();
1739
1772
  return useMutation15({
1740
1773
  mutationFn: (input) => client.returns.createReturn(input, ctx),
1741
1774
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
@@ -1744,16 +1777,16 @@ function useCreateReturn() {
1744
1777
 
1745
1778
  // src/hooks/use-approvals.ts
1746
1779
  import {
1747
- useQuery as useQuery26,
1780
+ useQuery as useQuery17,
1748
1781
  useMutation as useMutation16,
1749
- useQueryClient as useQueryClient14
1782
+ useQueryClient as useQueryClient15
1750
1783
  } from "@tanstack/react-query";
1751
1784
  var STALE3 = 3e4;
1752
1785
  var INVALIDATE_KEY5 = ["emporix", "approvals"];
1753
1786
  function useApprovals(opts = {}) {
1754
1787
  const { client } = useEmporix();
1755
1788
  const ctx = useCustomerOnlyCtx();
1756
- return useQuery26({
1789
+ return useQuery17({
1757
1790
  queryKey: emporixKey("approvals", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1758
1791
  queryFn: () => client.approvals.listApprovals(opts.query ?? {}, ctx),
1759
1792
  staleTime: STALE3
@@ -1762,7 +1795,7 @@ function useApprovals(opts = {}) {
1762
1795
  function useApproval(approvalId) {
1763
1796
  const { client } = useEmporix();
1764
1797
  const ctx = useCustomerOnlyCtx();
1765
- return useQuery26({
1798
+ return useQuery17({
1766
1799
  queryKey: emporixKey("approvals", [approvalId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
1767
1800
  queryFn: () => client.approvals.getApproval(approvalId, ctx),
1768
1801
  enabled: Boolean(approvalId),
@@ -1772,7 +1805,7 @@ function useApproval(approvalId) {
1772
1805
  function useCreateApproval() {
1773
1806
  const { client } = useEmporix();
1774
1807
  const ctx = useCustomerOnlyCtx();
1775
- const qc = useQueryClient14();
1808
+ const qc = useQueryClient15();
1776
1809
  return useMutation16({
1777
1810
  mutationFn: (input) => client.approvals.createApproval(input, ctx),
1778
1811
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
@@ -1781,7 +1814,7 @@ function useCreateApproval() {
1781
1814
  function useUpdateApproval() {
1782
1815
  const { client } = useEmporix();
1783
1816
  const ctx = useCustomerOnlyCtx();
1784
- const qc = useQueryClient14();
1817
+ const qc = useQueryClient15();
1785
1818
  return useMutation16({
1786
1819
  mutationFn: ({ approvalId, ops }) => client.approvals.updateApproval(approvalId, ops, ctx),
1787
1820
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
@@ -1880,4 +1913,4 @@ export {
1880
1913
  useCreateApproval,
1881
1914
  useUpdateApproval
1882
1915
  };
1883
- //# sourceMappingURL=chunk-7F5EB5XY.js.map
1916
+ //# sourceMappingURL=chunk-IREROKYI.js.map