@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.
- package/CHANGELOG.md +10 -0
- package/dist/{chunk-ZNLAYNF5.js → chunk-62GKMVS3.js} +20 -1
- package/dist/chunk-62GKMVS3.js.map +1 -0
- package/dist/{chunk-7F5EB5XY.js → chunk-IREROKYI.js} +302 -269
- package/dist/chunk-IREROKYI.js.map +1 -0
- package/dist/{chunk-CZDVH3WH.js → chunk-ZNE3J25W.js} +2 -2
- package/dist/{chunk-CZDVH3WH.js.map → chunk-ZNE3J25W.js.map} +1 -1
- package/dist/hooks.cjs +354 -317
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +3 -3
- package/dist/index.cjs +371 -315
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/{provider-Bcb-tOpS.d.ts → provider-Cgm9QVoo.d.ts} +1 -1
- package/dist/{provider-Ddo7aSOI.d.cts → provider-DGjmBPMr.d.cts} +1 -1
- package/dist/provider.cjs +6 -0
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +2 -2
- package/dist/storage.cjs +19 -0
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +3 -1
- package/dist/storage.d.ts +3 -1
- package/dist/storage.js +1 -1
- package/dist/{use-returns-uZJiO46w.d.ts → use-returns-DrqdwizU.d.ts} +1 -1
- package/dist/{use-returns-DT98Ptod.d.cts → use-returns-fKPIgjmU.d.cts} +1 -1
- package/package.json +3 -3
- package/dist/chunk-7F5EB5XY.js.map +0 -1
- package/dist/chunk-ZNLAYNF5.js.map +0 -1
package/dist/hooks.cjs
CHANGED
|
@@ -188,8 +188,8 @@ function getCustomerSessionStore(storage) {
|
|
|
188
188
|
if (existing) return existing;
|
|
189
189
|
let state = {
|
|
190
190
|
token: storage.getCustomerToken(),
|
|
191
|
-
refreshToken:
|
|
192
|
-
saasToken: null
|
|
191
|
+
refreshToken: storage.getRefreshToken(),
|
|
192
|
+
saasToken: storage.getSaasToken?.() ?? null
|
|
193
193
|
};
|
|
194
194
|
const listeners = /* @__PURE__ */ new Set();
|
|
195
195
|
const store = {
|
|
@@ -240,6 +240,7 @@ function useCustomerSession() {
|
|
|
240
240
|
const result = await client.customers.login(input);
|
|
241
241
|
storage.setCustomerToken(result.customerToken);
|
|
242
242
|
storage.setRefreshToken(result.refreshToken || null);
|
|
243
|
+
storage.setSaasToken?.(result.saasToken || null);
|
|
243
244
|
storage.setAnonymousSession(null);
|
|
244
245
|
setSession({
|
|
245
246
|
token: result.customerToken,
|
|
@@ -273,6 +274,7 @@ function useCustomerSession() {
|
|
|
273
274
|
async (incoming) => {
|
|
274
275
|
storage.setCustomerToken(incoming.customerToken);
|
|
275
276
|
storage.setRefreshToken(incoming.refreshToken || null);
|
|
277
|
+
storage.setSaasToken?.(incoming.saasToken || null);
|
|
276
278
|
storage.setAnonymousSession(null);
|
|
277
279
|
setSession({
|
|
278
280
|
token: incoming.customerToken,
|
|
@@ -317,6 +319,7 @@ function useCustomerSession() {
|
|
|
317
319
|
}
|
|
318
320
|
storage.setCustomerToken(null);
|
|
319
321
|
storage.setRefreshToken(null);
|
|
322
|
+
storage.setSaasToken?.(null);
|
|
320
323
|
storage.setActiveLegalEntityId(null);
|
|
321
324
|
storage.setCartId(null);
|
|
322
325
|
setSession(EMPTY_SESSION);
|
|
@@ -333,6 +336,7 @@ function useCustomerSession() {
|
|
|
333
336
|
});
|
|
334
337
|
storage.setCustomerToken(refreshed.customerToken);
|
|
335
338
|
if (refreshed.refreshToken) storage.setRefreshToken(refreshed.refreshToken);
|
|
339
|
+
if (refreshed.saasToken) storage.setSaasToken?.(refreshed.saasToken);
|
|
336
340
|
setSession((s) => ({
|
|
337
341
|
token: refreshed.customerToken,
|
|
338
342
|
refreshToken: refreshed.refreshToken || s.refreshToken,
|
|
@@ -405,8 +409,8 @@ async function onboardCustomerCart(opts) {
|
|
|
405
409
|
}
|
|
406
410
|
|
|
407
411
|
// src/hooks/use-products.ts
|
|
408
|
-
var
|
|
409
|
-
var
|
|
412
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
413
|
+
var import_emporix_sdk6 = require("@viu/emporix-sdk");
|
|
410
414
|
|
|
411
415
|
// src/hooks/internal/use-read-auth.ts
|
|
412
416
|
var import_emporix_sdk4 = require("@viu/emporix-sdk");
|
|
@@ -481,25 +485,54 @@ function useEmporixInfinite(opts) {
|
|
|
481
485
|
});
|
|
482
486
|
}
|
|
483
487
|
|
|
488
|
+
// src/hooks/internal/use-emporix-query.ts
|
|
489
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
490
|
+
var import_emporix_sdk5 = require("@viu/emporix-sdk");
|
|
491
|
+
function useEmporixQuery(cfg) {
|
|
492
|
+
const { client } = useEmporix();
|
|
493
|
+
const token = useCustomerToken();
|
|
494
|
+
const { siteCode, language } = useReadSite();
|
|
495
|
+
const authOverride = cfg.mode === "read-auth" ? cfg.authOverride : void 0;
|
|
496
|
+
const readCtx = authOverride ?? (token ? import_emporix_sdk5.auth.customer(token) : import_emporix_sdk5.auth.anonymous());
|
|
497
|
+
const authKind = cfg.mode === "customer" ? token ? "customer" : "anonymous" : readCtx.kind;
|
|
498
|
+
const resolvedCtx = cfg.mode === "customer" ? import_emporix_sdk5.auth.customer(token) : readCtx;
|
|
499
|
+
const siteMeta = cfg.site === "full" ? { siteCode, language } : cfg.site === "language" ? { language } : {};
|
|
500
|
+
const enabled = (cfg.enabled ?? true) && (cfg.mode === "customer" ? token !== null : true);
|
|
501
|
+
return (0, import_react_query5.useQuery)({
|
|
502
|
+
queryKey: emporixKey(cfg.resource, cfg.args, {
|
|
503
|
+
tenant: client.tenant,
|
|
504
|
+
authKind,
|
|
505
|
+
...siteMeta
|
|
506
|
+
}),
|
|
507
|
+
queryFn: () => cfg.queryFn(resolvedCtx),
|
|
508
|
+
enabled,
|
|
509
|
+
...cfg.staleTime !== void 0 ? { staleTime: cfg.staleTime } : {}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
484
513
|
// src/hooks/use-products.ts
|
|
485
514
|
var PRODUCTS_STALE_TIME = 6e4;
|
|
486
515
|
function useProduct(productId, options = {}) {
|
|
487
516
|
const { client } = useEmporix();
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
517
|
+
return useEmporixQuery({
|
|
518
|
+
mode: "read-auth",
|
|
519
|
+
site: "full",
|
|
520
|
+
resource: "product",
|
|
521
|
+
args: [productId],
|
|
522
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
523
|
+
queryFn: (ctx) => client.products.get(productId, void 0, ctx),
|
|
493
524
|
staleTime: PRODUCTS_STALE_TIME
|
|
494
525
|
});
|
|
495
526
|
}
|
|
496
527
|
function useProducts(params = {}, options = {}) {
|
|
497
528
|
const { client } = useEmporix();
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
529
|
+
return useEmporixQuery({
|
|
530
|
+
mode: "read-auth",
|
|
531
|
+
site: "full",
|
|
532
|
+
resource: "products",
|
|
533
|
+
args: [params],
|
|
534
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
535
|
+
queryFn: (ctx) => client.products.list(params, ctx),
|
|
503
536
|
staleTime: PRODUCTS_STALE_TIME
|
|
504
537
|
});
|
|
505
538
|
}
|
|
@@ -518,50 +551,53 @@ function useProductsInfinite(params = {}, options = {}) {
|
|
|
518
551
|
}
|
|
519
552
|
function useProductByCode(code, options = {}) {
|
|
520
553
|
const { client } = useEmporix();
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
554
|
+
return useEmporixQuery({
|
|
555
|
+
mode: "read-auth",
|
|
556
|
+
site: "full",
|
|
557
|
+
resource: "product-by-code",
|
|
558
|
+
args: [code],
|
|
559
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
525
560
|
enabled: typeof code === "string" && code !== "",
|
|
526
|
-
queryFn: () => client.products.getByCode(code, ctx),
|
|
561
|
+
queryFn: (ctx) => client.products.getByCode(code, ctx),
|
|
527
562
|
staleTime: PRODUCTS_STALE_TIME
|
|
528
563
|
});
|
|
529
564
|
}
|
|
530
565
|
function useProductSearch(query, params = {}, options = {}) {
|
|
531
566
|
const { client } = useEmporix();
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
567
|
+
return useEmporixQuery({
|
|
568
|
+
mode: "read-auth",
|
|
569
|
+
site: "full",
|
|
570
|
+
resource: "product-search",
|
|
571
|
+
args: [query, params],
|
|
572
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
536
573
|
enabled: typeof query === "string" && query.trim() !== "",
|
|
537
|
-
queryFn: () => client.products.search(query, params, ctx),
|
|
574
|
+
queryFn: (ctx) => client.products.search(query, params, ctx),
|
|
538
575
|
staleTime: PRODUCTS_STALE_TIME
|
|
539
576
|
});
|
|
540
577
|
}
|
|
541
578
|
function useProductNameSearch(term, params = {}, options = {}) {
|
|
542
579
|
const { client } = useEmporix();
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
580
|
+
return useEmporixQuery({
|
|
581
|
+
mode: "read-auth",
|
|
582
|
+
site: "full",
|
|
583
|
+
resource: "product-name-search",
|
|
584
|
+
args: [term, params],
|
|
585
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
547
586
|
enabled: typeof term === "string" && term.trim() !== "",
|
|
548
|
-
queryFn: () => client.products.searchByName(term, params, ctx),
|
|
587
|
+
queryFn: (ctx) => client.products.searchByName(term, params, ctx),
|
|
549
588
|
staleTime: PRODUCTS_STALE_TIME
|
|
550
589
|
});
|
|
551
590
|
}
|
|
552
591
|
function useProductsByCodes(codes, options = {}) {
|
|
553
592
|
const { client } = useEmporix();
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
siteCode,
|
|
561
|
-
language
|
|
562
|
-
}),
|
|
593
|
+
return useEmporixQuery({
|
|
594
|
+
mode: "read-auth",
|
|
595
|
+
site: "full",
|
|
596
|
+
resource: "products-by-codes",
|
|
597
|
+
args: [codes, options.chunkSize],
|
|
598
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
563
599
|
enabled: codes.length > 0,
|
|
564
|
-
queryFn: () => client.products.searchByCodes(
|
|
600
|
+
queryFn: (ctx) => client.products.searchByCodes(
|
|
565
601
|
codes,
|
|
566
602
|
options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
|
|
567
603
|
ctx
|
|
@@ -571,15 +607,15 @@ function useProductsByCodes(codes, options = {}) {
|
|
|
571
607
|
}
|
|
572
608
|
|
|
573
609
|
// src/hooks/use-shopping-lists.ts
|
|
574
|
-
var
|
|
575
|
-
var
|
|
610
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
611
|
+
var import_emporix_sdk7 = require("@viu/emporix-sdk");
|
|
576
612
|
var SHOPPING_LIST_STALE_TIME = 3e4;
|
|
577
613
|
var INVALIDATE_KEY = ["emporix", "shopping-lists"];
|
|
578
614
|
function useShoppingLists(opts = {}) {
|
|
579
615
|
const { client } = useEmporix();
|
|
580
616
|
const ctx = useCustomerOnlyCtx();
|
|
581
617
|
const { siteCode, language } = useReadSite();
|
|
582
|
-
return (0,
|
|
618
|
+
return (0, import_react_query7.useQuery)({
|
|
583
619
|
queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
584
620
|
queryFn: () => client.shoppingLists.list(ctx, opts),
|
|
585
621
|
staleTime: SHOPPING_LIST_STALE_TIME
|
|
@@ -588,8 +624,8 @@ function useShoppingLists(opts = {}) {
|
|
|
588
624
|
function useCreateShoppingList() {
|
|
589
625
|
const { client } = useEmporix();
|
|
590
626
|
const ctx = useCustomerOnlyCtx();
|
|
591
|
-
const qc = (0,
|
|
592
|
-
return (0,
|
|
627
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
628
|
+
return (0, import_react_query7.useMutation)({
|
|
593
629
|
mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
|
|
594
630
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
595
631
|
});
|
|
@@ -597,8 +633,8 @@ function useCreateShoppingList() {
|
|
|
597
633
|
function useDeleteShoppingList() {
|
|
598
634
|
const { client } = useEmporix();
|
|
599
635
|
const ctx = useCustomerOnlyCtx();
|
|
600
|
-
const qc = (0,
|
|
601
|
-
return (0,
|
|
636
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
637
|
+
return (0, import_react_query7.useMutation)({
|
|
602
638
|
mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
|
|
603
639
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
604
640
|
});
|
|
@@ -606,8 +642,8 @@ function useDeleteShoppingList() {
|
|
|
606
642
|
function useAddToShoppingList() {
|
|
607
643
|
const { client } = useEmporix();
|
|
608
644
|
const ctx = useCustomerOnlyCtx();
|
|
609
|
-
const qc = (0,
|
|
610
|
-
return (0,
|
|
645
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
646
|
+
return (0, import_react_query7.useMutation)({
|
|
611
647
|
mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
|
|
612
648
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
613
649
|
});
|
|
@@ -615,8 +651,8 @@ function useAddToShoppingList() {
|
|
|
615
651
|
function useRemoveFromShoppingList() {
|
|
616
652
|
const { client } = useEmporix();
|
|
617
653
|
const ctx = useCustomerOnlyCtx();
|
|
618
|
-
const qc = (0,
|
|
619
|
-
return (0,
|
|
654
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
655
|
+
return (0, import_react_query7.useMutation)({
|
|
620
656
|
mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
|
|
621
657
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
622
658
|
});
|
|
@@ -624,29 +660,27 @@ function useRemoveFromShoppingList() {
|
|
|
624
660
|
function useSetShoppingListItemQuantity() {
|
|
625
661
|
const { client } = useEmporix();
|
|
626
662
|
const ctx = useCustomerOnlyCtx();
|
|
627
|
-
const qc = (0,
|
|
628
|
-
return (0,
|
|
663
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
664
|
+
return (0, import_react_query7.useMutation)({
|
|
629
665
|
mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
|
|
630
666
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
631
667
|
});
|
|
632
668
|
}
|
|
633
669
|
|
|
634
670
|
// src/hooks/use-variant-children.ts
|
|
635
|
-
var
|
|
636
|
-
var
|
|
671
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
672
|
+
var import_emporix_sdk8 = require("@viu/emporix-sdk");
|
|
637
673
|
var VARIANT_CHILDREN_STALE_TIME = 6e4;
|
|
638
674
|
function useVariantChildren(parentVariantId, options = {}) {
|
|
639
675
|
const { client } = useEmporix();
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
{ tenant: client.tenant, authKind: ctx.kind, siteCode, language }
|
|
647
|
-
),
|
|
676
|
+
return useEmporixQuery({
|
|
677
|
+
mode: "read-auth",
|
|
678
|
+
site: "full",
|
|
679
|
+
resource: "variant-children",
|
|
680
|
+
args: [parentVariantId, { pageSize: options.pageSize }],
|
|
681
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
648
682
|
enabled: typeof parentVariantId === "string" && parentVariantId !== "",
|
|
649
|
-
queryFn: () => client.products.listVariantChildren(
|
|
683
|
+
queryFn: (ctx) => client.products.listVariantChildren(
|
|
650
684
|
parentVariantId,
|
|
651
685
|
options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
652
686
|
ctx
|
|
@@ -656,37 +690,43 @@ function useVariantChildren(parentVariantId, options = {}) {
|
|
|
656
690
|
}
|
|
657
691
|
|
|
658
692
|
// src/hooks/use-categories.ts
|
|
659
|
-
var
|
|
660
|
-
var
|
|
693
|
+
var import_react_query9 = require("@tanstack/react-query");
|
|
694
|
+
var import_emporix_sdk9 = require("@viu/emporix-sdk");
|
|
661
695
|
var CATEGORIES_STALE_TIME = 5 * 6e4;
|
|
662
696
|
function useCategory(categoryId, options = {}) {
|
|
663
697
|
const { client } = useEmporix();
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
698
|
+
return useEmporixQuery({
|
|
699
|
+
mode: "read-auth",
|
|
700
|
+
site: "full",
|
|
701
|
+
resource: "category",
|
|
702
|
+
args: [categoryId],
|
|
703
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
704
|
+
queryFn: (ctx) => client.categories.get(categoryId, ctx),
|
|
669
705
|
staleTime: CATEGORIES_STALE_TIME
|
|
670
706
|
});
|
|
671
707
|
}
|
|
672
708
|
function useSubcategories(categoryId, params = {}, options = {}) {
|
|
673
709
|
const { client } = useEmporix();
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
710
|
+
return useEmporixQuery({
|
|
711
|
+
mode: "read-auth",
|
|
712
|
+
site: "full",
|
|
713
|
+
resource: "subcategories",
|
|
714
|
+
args: [categoryId ?? null, params],
|
|
715
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
678
716
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
679
|
-
queryFn: () => client.categories.subcategories(categoryId, params, ctx),
|
|
717
|
+
queryFn: (ctx) => client.categories.subcategories(categoryId, params, ctx),
|
|
680
718
|
staleTime: CATEGORIES_STALE_TIME
|
|
681
719
|
});
|
|
682
720
|
}
|
|
683
721
|
function useCategories(params = {}, options = {}) {
|
|
684
722
|
const { client } = useEmporix();
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
723
|
+
return useEmporixQuery({
|
|
724
|
+
mode: "read-auth",
|
|
725
|
+
site: "full",
|
|
726
|
+
resource: "categories",
|
|
727
|
+
args: [params],
|
|
728
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
729
|
+
queryFn: (ctx) => client.categories.list(params, ctx),
|
|
690
730
|
staleTime: CATEGORIES_STALE_TIME
|
|
691
731
|
});
|
|
692
732
|
}
|
|
@@ -705,22 +745,26 @@ function useCategoriesInfinite(params = {}, options = {}) {
|
|
|
705
745
|
}
|
|
706
746
|
function useCategoryTree(options = {}) {
|
|
707
747
|
const { client } = useEmporix();
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
748
|
+
return useEmporixQuery({
|
|
749
|
+
mode: "read-auth",
|
|
750
|
+
site: "full",
|
|
751
|
+
resource: "category-tree",
|
|
752
|
+
args: [],
|
|
753
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
754
|
+
queryFn: (ctx) => client.categories.tree(ctx),
|
|
713
755
|
staleTime: CATEGORIES_STALE_TIME
|
|
714
756
|
});
|
|
715
757
|
}
|
|
716
758
|
function useProductsInCategory(categoryId, params = {}, options = {}) {
|
|
717
759
|
const { client } = useEmporix();
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
760
|
+
return useEmporixQuery({
|
|
761
|
+
mode: "read-auth",
|
|
762
|
+
site: "full",
|
|
763
|
+
resource: "products-in-category",
|
|
764
|
+
args: [categoryId, params],
|
|
765
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
722
766
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
723
|
-
queryFn: () => client.categories.productsIn(categoryId, params, ctx),
|
|
767
|
+
queryFn: (ctx) => client.categories.productsIn(categoryId, params, ctx),
|
|
724
768
|
staleTime: CATEGORIES_STALE_TIME
|
|
725
769
|
});
|
|
726
770
|
}
|
|
@@ -742,35 +786,33 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
|
|
|
742
786
|
|
|
743
787
|
// src/hooks/use-cart.ts
|
|
744
788
|
var import_react6 = require("react");
|
|
745
|
-
var
|
|
746
|
-
var
|
|
789
|
+
var import_react_query10 = require("@tanstack/react-query");
|
|
790
|
+
var import_emporix_sdk10 = require("@viu/emporix-sdk");
|
|
747
791
|
function useCart(cartId, options = {}) {
|
|
748
792
|
const { client } = useEmporix();
|
|
749
|
-
const { ctx } = useReadAuth(options.auth);
|
|
750
|
-
const { siteCode, language } = useReadSite();
|
|
751
793
|
const { activeCompany } = useActiveCompany();
|
|
752
794
|
const storedCartId = useCartId();
|
|
753
795
|
const resolvedId = cartId ?? storedCartId ?? void 0;
|
|
754
|
-
return (
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
796
|
+
return useEmporixQuery({
|
|
797
|
+
mode: "read-auth",
|
|
798
|
+
site: "full",
|
|
799
|
+
resource: "cart",
|
|
800
|
+
args: [resolvedId ?? null, activeCompany?.id ?? null],
|
|
801
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
760
802
|
enabled: resolvedId !== void 0,
|
|
761
|
-
queryFn: () => client.carts.get(resolvedId, ctx)
|
|
803
|
+
queryFn: (ctx) => client.carts.get(resolvedId, ctx)
|
|
762
804
|
});
|
|
763
805
|
}
|
|
764
806
|
function useCartMutations(cartId) {
|
|
765
807
|
const { client, storage } = useEmporix();
|
|
766
|
-
const qc = (0,
|
|
808
|
+
const qc = (0, import_react_query10.useQueryClient)();
|
|
767
809
|
const { ctx } = useReadAuth();
|
|
768
810
|
const { siteCode, language } = useReadSite();
|
|
769
811
|
const { activeCompany } = useActiveCompany();
|
|
770
812
|
const resolveId = () => {
|
|
771
813
|
const id = cartId ?? storage.getCartId();
|
|
772
814
|
if (!id) {
|
|
773
|
-
throw new
|
|
815
|
+
throw new import_emporix_sdk10.EmporixError(
|
|
774
816
|
"useCartMutations: no cartId available \u2014 pass one explicitly or call useActiveCart({ create: true }) first"
|
|
775
817
|
);
|
|
776
818
|
}
|
|
@@ -782,7 +824,7 @@ function useCartMutations(cartId) {
|
|
|
782
824
|
{ tenant: client.tenant, authKind: ctx.kind, siteCode, language }
|
|
783
825
|
);
|
|
784
826
|
function make(run, optimistic) {
|
|
785
|
-
return (0,
|
|
827
|
+
return (0, import_react_query10.useMutation)({
|
|
786
828
|
mutationFn: async (vars) => run(resolveId(), vars),
|
|
787
829
|
onMutate: async (vars) => {
|
|
788
830
|
const id = resolveId();
|
|
@@ -839,9 +881,9 @@ function useCartMutations(cartId) {
|
|
|
839
881
|
}
|
|
840
882
|
function useCreateCart() {
|
|
841
883
|
const { client, storage } = useEmporix();
|
|
842
|
-
const qc = (0,
|
|
884
|
+
const qc = (0, import_react_query10.useQueryClient)();
|
|
843
885
|
const { ctx } = useReadAuth();
|
|
844
|
-
return (0,
|
|
886
|
+
return (0, import_react_query10.useMutation)({
|
|
845
887
|
mutationFn: (input) => client.carts.create(input, ctx),
|
|
846
888
|
onSuccess: async (cart) => {
|
|
847
889
|
if (cart.cartId) storage.setCartId(cart.cartId);
|
|
@@ -851,7 +893,7 @@ function useCreateCart() {
|
|
|
851
893
|
}
|
|
852
894
|
function useActiveCart(opts) {
|
|
853
895
|
const { client, storage } = useEmporix();
|
|
854
|
-
const qc = (0,
|
|
896
|
+
const qc = (0, import_react_query10.useQueryClient)();
|
|
855
897
|
const { ctx } = useReadAuth(opts?.auth);
|
|
856
898
|
const { siteCode: activeSite } = useReadSite();
|
|
857
899
|
const { activeCompany } = useActiveCompany();
|
|
@@ -887,15 +929,16 @@ function useActiveCart(opts) {
|
|
|
887
929
|
}
|
|
888
930
|
|
|
889
931
|
// src/hooks/use-checkout.ts
|
|
890
|
-
var
|
|
891
|
-
var
|
|
932
|
+
var import_react_query11 = require("@tanstack/react-query");
|
|
933
|
+
var import_emporix_sdk11 = require("@viu/emporix-sdk");
|
|
892
934
|
var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
|
|
893
935
|
function customerOnlyCtx(token) {
|
|
894
936
|
if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
|
|
895
|
-
return
|
|
937
|
+
return import_emporix_sdk11.auth.customer(token);
|
|
896
938
|
}
|
|
897
939
|
function useCheckout() {
|
|
898
|
-
const { client } = useEmporix();
|
|
940
|
+
const { client, storage } = useEmporix();
|
|
941
|
+
const qc = (0, import_react_query11.useQueryClient)();
|
|
899
942
|
const { ctx } = useReadAuth();
|
|
900
943
|
const { activeCompany } = useActiveCompany();
|
|
901
944
|
const withLE = (input) => {
|
|
@@ -903,17 +946,23 @@ function useCheckout() {
|
|
|
903
946
|
if ("legalEntityId" in input) return input;
|
|
904
947
|
return { ...input, legalEntityId: activeCompany.id };
|
|
905
948
|
};
|
|
906
|
-
const
|
|
949
|
+
const onOrderPlaced = () => {
|
|
950
|
+
storage.setCartId(null);
|
|
951
|
+
qc.removeQueries({ queryKey: ["emporix", "cart-bootstrap"] });
|
|
952
|
+
};
|
|
953
|
+
const placeOrder = (0, import_react_query11.useMutation)({
|
|
907
954
|
mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
|
|
908
955
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
909
956
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
910
|
-
})
|
|
957
|
+
}),
|
|
958
|
+
onSuccess: onOrderPlaced
|
|
911
959
|
});
|
|
912
|
-
const placeOrderFromQuote = (0,
|
|
960
|
+
const placeOrderFromQuote = (0, import_react_query11.useMutation)({
|
|
913
961
|
mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
|
|
914
962
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
915
963
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
916
|
-
})
|
|
964
|
+
}),
|
|
965
|
+
onSuccess: onOrderPlaced
|
|
917
966
|
});
|
|
918
967
|
return { placeOrder, placeOrderFromQuote };
|
|
919
968
|
}
|
|
@@ -922,7 +971,7 @@ function usePaymentModes(options = {}) {
|
|
|
922
971
|
const token = useCustomerToken();
|
|
923
972
|
const { siteCode } = useReadSite();
|
|
924
973
|
const { activeCompany } = useActiveCompany();
|
|
925
|
-
return (0,
|
|
974
|
+
return (0, import_react_query11.useQuery)({
|
|
926
975
|
queryKey: emporixKey(
|
|
927
976
|
"payment-modes",
|
|
928
977
|
[activeCompany?.id ?? null],
|
|
@@ -935,14 +984,14 @@ function usePaymentModes(options = {}) {
|
|
|
935
984
|
}
|
|
936
985
|
|
|
937
986
|
// src/hooks/use-match-prices.ts
|
|
938
|
-
var
|
|
939
|
-
var
|
|
987
|
+
var import_react_query12 = require("@tanstack/react-query");
|
|
988
|
+
var import_emporix_sdk12 = require("@viu/emporix-sdk");
|
|
940
989
|
var PRICES_STALE_TIME = 6e4;
|
|
941
990
|
function useMatchPrices(input, options = {}) {
|
|
942
991
|
const { client } = useEmporix();
|
|
943
992
|
const { siteCode } = useReadSite();
|
|
944
|
-
const ctx = options.customerToken ?
|
|
945
|
-
return (0,
|
|
993
|
+
const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
|
|
994
|
+
return (0, import_react_query12.useQuery)({
|
|
946
995
|
queryKey: [
|
|
947
996
|
"emporix",
|
|
948
997
|
"match-prices",
|
|
@@ -955,14 +1004,14 @@ function useMatchPrices(input, options = {}) {
|
|
|
955
1004
|
}
|
|
956
1005
|
|
|
957
1006
|
// src/hooks/use-match-prices-chunked.ts
|
|
958
|
-
var
|
|
959
|
-
var
|
|
1007
|
+
var import_react_query13 = require("@tanstack/react-query");
|
|
1008
|
+
var import_emporix_sdk13 = require("@viu/emporix-sdk");
|
|
960
1009
|
var PRICES_STALE_TIME2 = 6e4;
|
|
961
1010
|
function useMatchPricesChunked(input, options = {}) {
|
|
962
1011
|
const { client } = useEmporix();
|
|
963
1012
|
const { siteCode } = useReadSite();
|
|
964
|
-
const ctx = options.customerToken ?
|
|
965
|
-
return (0,
|
|
1013
|
+
const ctx = options.customerToken ? import_emporix_sdk13.auth.customer(options.customerToken) : import_emporix_sdk13.auth.anonymous();
|
|
1014
|
+
return (0, import_react_query13.useQuery)({
|
|
966
1015
|
queryKey: [
|
|
967
1016
|
"emporix",
|
|
968
1017
|
"match-prices-chunked",
|
|
@@ -996,18 +1045,18 @@ function useProductMedia(productId) {
|
|
|
996
1045
|
}
|
|
997
1046
|
|
|
998
1047
|
// src/hooks/use-my-segments.ts
|
|
999
|
-
var
|
|
1000
|
-
var
|
|
1048
|
+
var import_react_query14 = require("@tanstack/react-query");
|
|
1049
|
+
var import_emporix_sdk14 = require("@viu/emporix-sdk");
|
|
1001
1050
|
var SEGMENTS_STALE_TIME = 5 * 6e4;
|
|
1002
1051
|
function customerCtx(token) {
|
|
1003
1052
|
if (!token) throw new Error("requires a customer token in storage");
|
|
1004
|
-
return
|
|
1053
|
+
return import_emporix_sdk14.auth.customer(token);
|
|
1005
1054
|
}
|
|
1006
1055
|
function useMySegments(query = {}) {
|
|
1007
1056
|
const { client } = useEmporix();
|
|
1008
1057
|
const token = useCustomerToken();
|
|
1009
1058
|
const { siteCode, language } = useReadSite();
|
|
1010
|
-
return (0,
|
|
1059
|
+
return (0, import_react_query14.useQuery)({
|
|
1011
1060
|
queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
|
|
1012
1061
|
enabled: token !== null,
|
|
1013
1062
|
queryFn: () => client.segments.list(query, customerCtx(token)),
|
|
@@ -1018,7 +1067,7 @@ function useMySegmentItems(query = {}) {
|
|
|
1018
1067
|
const { client } = useEmporix();
|
|
1019
1068
|
const token = useCustomerToken();
|
|
1020
1069
|
const { siteCode, language } = useReadSite();
|
|
1021
|
-
return (0,
|
|
1070
|
+
return (0, import_react_query14.useQuery)({
|
|
1022
1071
|
queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
|
|
1023
1072
|
enabled: token !== null,
|
|
1024
1073
|
queryFn: () => client.segments.listItems(query, customerCtx(token)),
|
|
@@ -1029,7 +1078,7 @@ function useMySegmentCategoryTree(query = {}) {
|
|
|
1029
1078
|
const { client } = useEmporix();
|
|
1030
1079
|
const token = useCustomerToken();
|
|
1031
1080
|
const { siteCode, language } = useReadSite();
|
|
1032
|
-
return (0,
|
|
1081
|
+
return (0, import_react_query14.useQuery)({
|
|
1033
1082
|
queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
|
|
1034
1083
|
enabled: token !== null,
|
|
1035
1084
|
queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
|
|
@@ -1040,7 +1089,7 @@ function useMySegmentProducts(query = {}) {
|
|
|
1040
1089
|
const { client } = useEmporix();
|
|
1041
1090
|
const token = useCustomerToken();
|
|
1042
1091
|
const { siteCode, language } = useReadSite();
|
|
1043
|
-
return (0,
|
|
1092
|
+
return (0, import_react_query14.useQuery)({
|
|
1044
1093
|
queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
|
|
1045
1094
|
enabled: token !== null,
|
|
1046
1095
|
queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
|
|
@@ -1070,7 +1119,7 @@ function useMySegmentCategories(query = {}) {
|
|
|
1070
1119
|
const { client } = useEmporix();
|
|
1071
1120
|
const token = useCustomerToken();
|
|
1072
1121
|
const { siteCode, language } = useReadSite();
|
|
1073
|
-
return (0,
|
|
1122
|
+
return (0, import_react_query14.useQuery)({
|
|
1074
1123
|
queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
|
|
1075
1124
|
enabled: token !== null,
|
|
1076
1125
|
queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
|
|
@@ -1098,13 +1147,13 @@ function useMySegmentCategoriesInfinite(query = {}) {
|
|
|
1098
1147
|
}
|
|
1099
1148
|
|
|
1100
1149
|
// src/hooks/use-customer-profile.ts
|
|
1101
|
-
var
|
|
1102
|
-
var
|
|
1150
|
+
var import_react_query15 = require("@tanstack/react-query");
|
|
1151
|
+
var import_emporix_sdk15 = require("@viu/emporix-sdk");
|
|
1103
1152
|
function useUpdateCustomer() {
|
|
1104
1153
|
const { client } = useEmporix();
|
|
1105
1154
|
const ctx = useCustomerOnlyCtx();
|
|
1106
|
-
const qc = (0,
|
|
1107
|
-
return (0,
|
|
1155
|
+
const qc = (0, import_react_query15.useQueryClient)();
|
|
1156
|
+
return (0, import_react_query15.useMutation)({
|
|
1108
1157
|
mutationFn: (patch) => client.customers.update(patch, ctx),
|
|
1109
1158
|
onSuccess: () => {
|
|
1110
1159
|
void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
|
|
@@ -1114,21 +1163,21 @@ function useUpdateCustomer() {
|
|
|
1114
1163
|
function useChangePassword() {
|
|
1115
1164
|
const { client } = useEmporix();
|
|
1116
1165
|
const ctx = useCustomerOnlyCtx();
|
|
1117
|
-
return (0,
|
|
1166
|
+
return (0, import_react_query15.useMutation)({
|
|
1118
1167
|
mutationFn: (input) => client.customers.changePassword(input, ctx)
|
|
1119
1168
|
});
|
|
1120
1169
|
}
|
|
1121
1170
|
|
|
1122
1171
|
// src/hooks/use-customer-addresses.ts
|
|
1123
|
-
var
|
|
1124
|
-
var
|
|
1172
|
+
var import_react_query16 = require("@tanstack/react-query");
|
|
1173
|
+
var import_emporix_sdk16 = require("@viu/emporix-sdk");
|
|
1125
1174
|
var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
|
|
1126
1175
|
function useCustomerAddresses(options = {}) {
|
|
1127
1176
|
const { client } = useEmporix();
|
|
1128
1177
|
const token = useCustomerToken();
|
|
1129
1178
|
const { activeCompany } = useActiveCompany();
|
|
1130
|
-
const ctx = options.auth ?? (token ?
|
|
1131
|
-
return (0,
|
|
1179
|
+
const ctx = options.auth ?? (token ? import_emporix_sdk16.auth.customer(token) : null);
|
|
1180
|
+
return (0, import_react_query16.useQuery)({
|
|
1132
1181
|
queryKey: [
|
|
1133
1182
|
...ADDRESSES_KEY,
|
|
1134
1183
|
{ tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
|
|
@@ -1140,20 +1189,20 @@ function useCustomerAddresses(options = {}) {
|
|
|
1140
1189
|
function useAddressMutations() {
|
|
1141
1190
|
const { client } = useEmporix();
|
|
1142
1191
|
const ctx = useCustomerOnlyCtx();
|
|
1143
|
-
const qc = (0,
|
|
1192
|
+
const qc = (0, import_react_query16.useQueryClient)();
|
|
1144
1193
|
const invalidate = () => {
|
|
1145
1194
|
void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
|
|
1146
1195
|
};
|
|
1147
1196
|
return {
|
|
1148
|
-
add: (0,
|
|
1197
|
+
add: (0, import_react_query16.useMutation)({
|
|
1149
1198
|
mutationFn: (input) => client.customers.addresses.add(input, ctx),
|
|
1150
1199
|
onSuccess: invalidate
|
|
1151
1200
|
}),
|
|
1152
|
-
update: (0,
|
|
1201
|
+
update: (0, import_react_query16.useMutation)({
|
|
1153
1202
|
mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
|
|
1154
1203
|
onSuccess: invalidate
|
|
1155
1204
|
}),
|
|
1156
|
-
remove: (0,
|
|
1205
|
+
remove: (0, import_react_query16.useMutation)({
|
|
1157
1206
|
mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
|
|
1158
1207
|
onSuccess: invalidate
|
|
1159
1208
|
})
|
|
@@ -1161,23 +1210,23 @@ function useAddressMutations() {
|
|
|
1161
1210
|
}
|
|
1162
1211
|
|
|
1163
1212
|
// src/hooks/use-password-reset.ts
|
|
1164
|
-
var
|
|
1165
|
-
var
|
|
1213
|
+
var import_react_query17 = require("@tanstack/react-query");
|
|
1214
|
+
var import_emporix_sdk17 = require("@viu/emporix-sdk");
|
|
1166
1215
|
function usePasswordReset() {
|
|
1167
1216
|
const { client } = useEmporix();
|
|
1168
|
-
const anonCtx =
|
|
1217
|
+
const anonCtx = import_emporix_sdk17.auth.anonymous();
|
|
1169
1218
|
return {
|
|
1170
|
-
request: (0,
|
|
1219
|
+
request: (0, import_react_query17.useMutation)({
|
|
1171
1220
|
mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
|
|
1172
1221
|
}),
|
|
1173
|
-
confirm: (0,
|
|
1222
|
+
confirm: (0, import_react_query17.useMutation)({
|
|
1174
1223
|
mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
|
|
1175
1224
|
})
|
|
1176
1225
|
};
|
|
1177
1226
|
}
|
|
1178
1227
|
|
|
1179
1228
|
// src/hooks/use-sites.ts
|
|
1180
|
-
var
|
|
1229
|
+
var import_react_query18 = require("@tanstack/react-query");
|
|
1181
1230
|
|
|
1182
1231
|
// src/hooks/use-site-context.ts
|
|
1183
1232
|
var import_react7 = require("react");
|
|
@@ -1194,7 +1243,7 @@ var SITES_STALE_TIME = 10 * 6e4;
|
|
|
1194
1243
|
function useSites(options = {}) {
|
|
1195
1244
|
const { client } = useEmporix();
|
|
1196
1245
|
const { ctx } = useReadAuth(options.auth);
|
|
1197
|
-
return (0,
|
|
1246
|
+
return (0, import_react_query18.useQuery)({
|
|
1198
1247
|
queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1199
1248
|
queryFn: () => client.sites.list(ctx),
|
|
1200
1249
|
staleTime: SITES_STALE_TIME
|
|
@@ -1203,7 +1252,7 @@ function useSites(options = {}) {
|
|
|
1203
1252
|
function useDefaultSite(options = {}) {
|
|
1204
1253
|
const { client } = useEmporix();
|
|
1205
1254
|
const { ctx } = useReadAuth(options.auth);
|
|
1206
|
-
return (0,
|
|
1255
|
+
return (0, import_react_query18.useQuery)({
|
|
1207
1256
|
queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1208
1257
|
queryFn: () => client.sites.current(ctx),
|
|
1209
1258
|
staleTime: SITES_STALE_TIME
|
|
@@ -1216,101 +1265,95 @@ function useActiveSite(options = {}) {
|
|
|
1216
1265
|
}
|
|
1217
1266
|
|
|
1218
1267
|
// src/hooks/use-my-companies.ts
|
|
1219
|
-
var
|
|
1220
|
-
var
|
|
1268
|
+
var import_react_query19 = require("@tanstack/react-query");
|
|
1269
|
+
var import_emporix_sdk18 = require("@viu/emporix-sdk");
|
|
1221
1270
|
function useMyCompanies() {
|
|
1222
1271
|
const { client } = useEmporix();
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
enabled: token !== null,
|
|
1230
|
-
queryFn: () => client.companies.listMine(import_emporix_sdk17.auth.customer(token))
|
|
1272
|
+
return useEmporixQuery({
|
|
1273
|
+
mode: "customer",
|
|
1274
|
+
site: "none",
|
|
1275
|
+
resource: "companies",
|
|
1276
|
+
args: ["mine"],
|
|
1277
|
+
queryFn: (ctx) => client.companies.listMine(ctx)
|
|
1231
1278
|
});
|
|
1232
1279
|
}
|
|
1233
1280
|
|
|
1234
1281
|
// src/hooks/use-company.ts
|
|
1235
|
-
var
|
|
1236
|
-
var
|
|
1282
|
+
var import_react_query20 = require("@tanstack/react-query");
|
|
1283
|
+
var import_emporix_sdk19 = require("@viu/emporix-sdk");
|
|
1237
1284
|
function useCompany(legalEntityId) {
|
|
1238
1285
|
const { client } = useEmporix();
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
queryFn: () => client.companies.get(legalEntityId, import_emporix_sdk18.auth.customer(token))
|
|
1286
|
+
return useEmporixQuery({
|
|
1287
|
+
mode: "customer",
|
|
1288
|
+
site: "none",
|
|
1289
|
+
resource: "companies",
|
|
1290
|
+
args: [legalEntityId ?? null],
|
|
1291
|
+
enabled: legalEntityId !== void 0,
|
|
1292
|
+
queryFn: (ctx) => client.companies.get(legalEntityId, ctx)
|
|
1247
1293
|
});
|
|
1248
1294
|
}
|
|
1249
1295
|
|
|
1250
1296
|
// src/hooks/use-company-contacts.ts
|
|
1251
|
-
var
|
|
1252
|
-
var
|
|
1297
|
+
var import_react_query21 = require("@tanstack/react-query");
|
|
1298
|
+
var import_emporix_sdk20 = require("@viu/emporix-sdk");
|
|
1253
1299
|
function useCompanyContacts(legalEntityId) {
|
|
1254
|
-
const { client
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
queryFn: () => client.contacts.listForCompany(legalEntityId, import_emporix_sdk19.auth.customer(token))
|
|
1300
|
+
const { client } = useEmporix();
|
|
1301
|
+
return useEmporixQuery({
|
|
1302
|
+
mode: "customer",
|
|
1303
|
+
site: "none",
|
|
1304
|
+
resource: "companies",
|
|
1305
|
+
args: ["contacts", legalEntityId ?? null],
|
|
1306
|
+
enabled: legalEntityId !== void 0,
|
|
1307
|
+
queryFn: (ctx) => client.contacts.listForCompany(legalEntityId, ctx)
|
|
1263
1308
|
});
|
|
1264
1309
|
}
|
|
1265
1310
|
|
|
1266
1311
|
// src/hooks/use-company-locations.ts
|
|
1267
|
-
var
|
|
1268
|
-
var
|
|
1312
|
+
var import_react_query22 = require("@tanstack/react-query");
|
|
1313
|
+
var import_emporix_sdk21 = require("@viu/emporix-sdk");
|
|
1269
1314
|
function useCompanyLocations(legalEntityId) {
|
|
1270
1315
|
const { client } = useEmporix();
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
queryFn: () => client.locations.listForCompany(legalEntityId, import_emporix_sdk20.auth.customer(token))
|
|
1316
|
+
return useEmporixQuery({
|
|
1317
|
+
mode: "customer",
|
|
1318
|
+
site: "none",
|
|
1319
|
+
resource: "companies",
|
|
1320
|
+
args: ["locations", legalEntityId ?? null],
|
|
1321
|
+
enabled: legalEntityId !== void 0,
|
|
1322
|
+
queryFn: (ctx) => client.locations.listForCompany(legalEntityId, ctx)
|
|
1279
1323
|
});
|
|
1280
1324
|
}
|
|
1281
1325
|
|
|
1282
1326
|
// src/hooks/use-company-groups.ts
|
|
1283
|
-
var
|
|
1284
|
-
var
|
|
1327
|
+
var import_react_query23 = require("@tanstack/react-query");
|
|
1328
|
+
var import_emporix_sdk22 = require("@viu/emporix-sdk");
|
|
1285
1329
|
function useCompanyGroups(legalEntityId) {
|
|
1286
1330
|
const { client } = useEmporix();
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
queryFn: () => client.customerGroups.listForCompany(legalEntityId, import_emporix_sdk21.auth.customer(token))
|
|
1331
|
+
return useEmporixQuery({
|
|
1332
|
+
mode: "customer",
|
|
1333
|
+
site: "none",
|
|
1334
|
+
resource: "companies",
|
|
1335
|
+
args: ["groups", legalEntityId ?? null],
|
|
1336
|
+
enabled: legalEntityId !== void 0,
|
|
1337
|
+
queryFn: (ctx) => client.customerGroups.listForCompany(legalEntityId, ctx)
|
|
1295
1338
|
});
|
|
1296
1339
|
}
|
|
1297
1340
|
|
|
1298
1341
|
// src/hooks/use-company-mutations.ts
|
|
1299
|
-
var
|
|
1300
|
-
var
|
|
1342
|
+
var import_react_query24 = require("@tanstack/react-query");
|
|
1343
|
+
var import_emporix_sdk23 = require("@viu/emporix-sdk");
|
|
1301
1344
|
function useCustomerAuthResolver() {
|
|
1302
1345
|
const { storage } = useEmporix();
|
|
1303
1346
|
return () => {
|
|
1304
1347
|
const token = storage.getCustomerToken();
|
|
1305
1348
|
if (!token) throw new Error("Mutation requires a logged-in customer token");
|
|
1306
|
-
return
|
|
1349
|
+
return import_emporix_sdk23.auth.customer(token);
|
|
1307
1350
|
};
|
|
1308
1351
|
}
|
|
1309
1352
|
function useCreateCompany() {
|
|
1310
1353
|
const { client } = useEmporix();
|
|
1311
1354
|
const resolveAuth = useCustomerAuthResolver();
|
|
1312
|
-
const qc = (0,
|
|
1313
|
-
return (0,
|
|
1355
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1356
|
+
return (0, import_react_query24.useMutation)({
|
|
1314
1357
|
mutationFn: (input) => client.companies.create(input, resolveAuth()),
|
|
1315
1358
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
|
|
1316
1359
|
});
|
|
@@ -1318,8 +1361,8 @@ function useCreateCompany() {
|
|
|
1318
1361
|
function useUpdateCompany() {
|
|
1319
1362
|
const { client } = useEmporix();
|
|
1320
1363
|
const resolveAuth = useCustomerAuthResolver();
|
|
1321
|
-
const qc = (0,
|
|
1322
|
-
return (0,
|
|
1364
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1365
|
+
return (0, import_react_query24.useMutation)({
|
|
1323
1366
|
mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
|
|
1324
1367
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1325
1368
|
});
|
|
@@ -1327,8 +1370,8 @@ function useUpdateCompany() {
|
|
|
1327
1370
|
function useDeleteCompany() {
|
|
1328
1371
|
const { client } = useEmporix();
|
|
1329
1372
|
const resolveAuth = useCustomerAuthResolver();
|
|
1330
|
-
const qc = (0,
|
|
1331
|
-
return (0,
|
|
1373
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1374
|
+
return (0, import_react_query24.useMutation)({
|
|
1332
1375
|
mutationFn: (id) => client.companies.delete(id, resolveAuth()),
|
|
1333
1376
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1334
1377
|
});
|
|
@@ -1336,8 +1379,8 @@ function useDeleteCompany() {
|
|
|
1336
1379
|
function useAssignContact() {
|
|
1337
1380
|
const { client } = useEmporix();
|
|
1338
1381
|
const resolveAuth = useCustomerAuthResolver();
|
|
1339
|
-
const qc = (0,
|
|
1340
|
-
return (0,
|
|
1382
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1383
|
+
return (0, import_react_query24.useMutation)({
|
|
1341
1384
|
mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
|
|
1342
1385
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1343
1386
|
});
|
|
@@ -1345,8 +1388,8 @@ function useAssignContact() {
|
|
|
1345
1388
|
function useUpdateContactAssignment() {
|
|
1346
1389
|
const { client } = useEmporix();
|
|
1347
1390
|
const resolveAuth = useCustomerAuthResolver();
|
|
1348
|
-
const qc = (0,
|
|
1349
|
-
return (0,
|
|
1391
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1392
|
+
return (0, import_react_query24.useMutation)({
|
|
1350
1393
|
mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
|
|
1351
1394
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1352
1395
|
});
|
|
@@ -1354,8 +1397,8 @@ function useUpdateContactAssignment() {
|
|
|
1354
1397
|
function useUnassignContact() {
|
|
1355
1398
|
const { client } = useEmporix();
|
|
1356
1399
|
const resolveAuth = useCustomerAuthResolver();
|
|
1357
|
-
const qc = (0,
|
|
1358
|
-
return (0,
|
|
1400
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1401
|
+
return (0, import_react_query24.useMutation)({
|
|
1359
1402
|
mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
|
|
1360
1403
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1361
1404
|
});
|
|
@@ -1363,8 +1406,8 @@ function useUnassignContact() {
|
|
|
1363
1406
|
function useCreateLocation() {
|
|
1364
1407
|
const { client } = useEmporix();
|
|
1365
1408
|
const resolveAuth = useCustomerAuthResolver();
|
|
1366
|
-
const qc = (0,
|
|
1367
|
-
return (0,
|
|
1409
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1410
|
+
return (0, import_react_query24.useMutation)({
|
|
1368
1411
|
mutationFn: (input) => client.locations.create(input, resolveAuth()),
|
|
1369
1412
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1370
1413
|
});
|
|
@@ -1372,8 +1415,8 @@ function useCreateLocation() {
|
|
|
1372
1415
|
function useUpdateLocation() {
|
|
1373
1416
|
const { client } = useEmporix();
|
|
1374
1417
|
const resolveAuth = useCustomerAuthResolver();
|
|
1375
|
-
const qc = (0,
|
|
1376
|
-
return (0,
|
|
1418
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1419
|
+
return (0, import_react_query24.useMutation)({
|
|
1377
1420
|
mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
|
|
1378
1421
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1379
1422
|
});
|
|
@@ -1381,8 +1424,8 @@ function useUpdateLocation() {
|
|
|
1381
1424
|
function useDeleteLocation() {
|
|
1382
1425
|
const { client } = useEmporix();
|
|
1383
1426
|
const resolveAuth = useCustomerAuthResolver();
|
|
1384
|
-
const qc = (0,
|
|
1385
|
-
return (0,
|
|
1427
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1428
|
+
return (0, import_react_query24.useMutation)({
|
|
1386
1429
|
mutationFn: (id) => client.locations.delete(id, resolveAuth()),
|
|
1387
1430
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1388
1431
|
});
|
|
@@ -1390,8 +1433,8 @@ function useDeleteLocation() {
|
|
|
1390
1433
|
function useAddGroupMember() {
|
|
1391
1434
|
const { client } = useEmporix();
|
|
1392
1435
|
const resolveAuth = useCustomerAuthResolver();
|
|
1393
|
-
const qc = (0,
|
|
1394
|
-
return (0,
|
|
1436
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1437
|
+
return (0, import_react_query24.useMutation)({
|
|
1395
1438
|
mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
|
|
1396
1439
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1397
1440
|
});
|
|
@@ -1399,8 +1442,8 @@ function useAddGroupMember() {
|
|
|
1399
1442
|
function useRemoveGroupMember() {
|
|
1400
1443
|
const { client } = useEmporix();
|
|
1401
1444
|
const resolveAuth = useCustomerAuthResolver();
|
|
1402
|
-
const qc = (0,
|
|
1403
|
-
return (0,
|
|
1445
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1446
|
+
return (0, import_react_query24.useMutation)({
|
|
1404
1447
|
mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
|
|
1405
1448
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1406
1449
|
});
|
|
@@ -1425,15 +1468,15 @@ function useCompanySwitcher() {
|
|
|
1425
1468
|
}
|
|
1426
1469
|
|
|
1427
1470
|
// src/hooks/use-cloud-functions.ts
|
|
1428
|
-
var
|
|
1429
|
-
var
|
|
1471
|
+
var import_react_query25 = require("@tanstack/react-query");
|
|
1472
|
+
var import_emporix_sdk24 = require("@viu/emporix-sdk");
|
|
1430
1473
|
function useInvokeCloudFunction() {
|
|
1431
1474
|
const { client, storage } = useEmporix();
|
|
1432
|
-
return (0,
|
|
1475
|
+
return (0, import_react_query25.useMutation)({
|
|
1433
1476
|
mutationFn: (vars) => {
|
|
1434
1477
|
const { functionId, auth: authOverride, ...options } = vars;
|
|
1435
1478
|
const token = storage.getCustomerToken();
|
|
1436
|
-
const authCtx = authOverride ?? (token ?
|
|
1479
|
+
const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
|
|
1437
1480
|
return client.cloudFunctions.invoke(functionId, options, authCtx);
|
|
1438
1481
|
}
|
|
1439
1482
|
});
|
|
@@ -1442,8 +1485,8 @@ function useCloudFunction(functionId, options, queryOptions) {
|
|
|
1442
1485
|
const { client } = useEmporix();
|
|
1443
1486
|
const token = useCustomerToken();
|
|
1444
1487
|
const { auth: authOverride, ...invokeOptions } = options ?? {};
|
|
1445
|
-
const authCtx = authOverride ?? (token ?
|
|
1446
|
-
return (0,
|
|
1488
|
+
const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
|
|
1489
|
+
return (0, import_react_query25.useQuery)({
|
|
1447
1490
|
queryKey: emporixKey(
|
|
1448
1491
|
"cloud-function",
|
|
1449
1492
|
[functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
|
|
@@ -1460,22 +1503,19 @@ function useCloudFunction(functionId, options, queryOptions) {
|
|
|
1460
1503
|
}
|
|
1461
1504
|
|
|
1462
1505
|
// src/hooks/use-my-orders.ts
|
|
1463
|
-
var
|
|
1464
|
-
var
|
|
1506
|
+
var import_react_query26 = require("@tanstack/react-query");
|
|
1507
|
+
var import_emporix_sdk25 = require("@viu/emporix-sdk");
|
|
1465
1508
|
function useMyOrders(options = {}) {
|
|
1466
1509
|
const { client } = useEmporix();
|
|
1467
1510
|
const { activeCompany } = useActiveCompany();
|
|
1468
|
-
const { siteCode
|
|
1469
|
-
const token = useCustomerToken();
|
|
1511
|
+
const { siteCode } = useReadSite();
|
|
1470
1512
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1471
|
-
return (
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
),
|
|
1477
|
-
enabled: token !== null,
|
|
1478
|
-
queryFn: () => client.orders.listMine(import_emporix_sdk24.auth.customer(token), {
|
|
1513
|
+
return useEmporixQuery({
|
|
1514
|
+
mode: "customer",
|
|
1515
|
+
site: "full",
|
|
1516
|
+
resource: "orders",
|
|
1517
|
+
args: ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
|
|
1518
|
+
queryFn: (ctx) => client.orders.listMine(ctx, {
|
|
1479
1519
|
...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
|
|
1480
1520
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1481
1521
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1487,7 +1527,7 @@ function useMyOrders(options = {}) {
|
|
|
1487
1527
|
}
|
|
1488
1528
|
|
|
1489
1529
|
// src/hooks/use-my-orders-infinite.ts
|
|
1490
|
-
var
|
|
1530
|
+
var import_emporix_sdk26 = require("@viu/emporix-sdk");
|
|
1491
1531
|
function useMyOrdersInfinite(options = {}) {
|
|
1492
1532
|
const { client } = useEmporix();
|
|
1493
1533
|
const { activeCompany } = useActiveCompany();
|
|
@@ -1501,7 +1541,7 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1501
1541
|
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1502
1542
|
),
|
|
1503
1543
|
enabled: token !== null,
|
|
1504
|
-
fetchPage: (pageNumber) => client.orders.listMine(
|
|
1544
|
+
fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk26.auth.customer(token), {
|
|
1505
1545
|
pageNumber,
|
|
1506
1546
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1507
1547
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1513,34 +1553,31 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1513
1553
|
}
|
|
1514
1554
|
|
|
1515
1555
|
// src/hooks/use-order.ts
|
|
1516
|
-
var
|
|
1517
|
-
var
|
|
1556
|
+
var import_react_query27 = require("@tanstack/react-query");
|
|
1557
|
+
var import_emporix_sdk27 = require("@viu/emporix-sdk");
|
|
1518
1558
|
function useOrder(orderId, options = {}) {
|
|
1519
1559
|
const { client } = useEmporix();
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
}),
|
|
1528
|
-
enabled: token !== null && orderId !== void 0,
|
|
1529
|
-
queryFn: () => client.orders.get(
|
|
1560
|
+
return useEmporixQuery({
|
|
1561
|
+
mode: "customer",
|
|
1562
|
+
site: "language",
|
|
1563
|
+
resource: "orders",
|
|
1564
|
+
args: [orderId ?? null],
|
|
1565
|
+
enabled: orderId !== void 0,
|
|
1566
|
+
queryFn: (ctx) => client.orders.get(
|
|
1530
1567
|
orderId,
|
|
1531
|
-
|
|
1568
|
+
ctx,
|
|
1532
1569
|
options.saasToken ? { saasToken: options.saasToken } : {}
|
|
1533
1570
|
)
|
|
1534
1571
|
});
|
|
1535
1572
|
}
|
|
1536
1573
|
|
|
1537
1574
|
// src/hooks/use-cancel-order.ts
|
|
1538
|
-
var
|
|
1539
|
-
var
|
|
1575
|
+
var import_react_query28 = require("@tanstack/react-query");
|
|
1576
|
+
var import_emporix_sdk28 = require("@viu/emporix-sdk");
|
|
1540
1577
|
function useCancelOrder() {
|
|
1541
1578
|
const { client, storage } = useEmporix();
|
|
1542
|
-
const qc = (0,
|
|
1543
|
-
return (0,
|
|
1579
|
+
const qc = (0, import_react_query28.useQueryClient)();
|
|
1580
|
+
return (0, import_react_query28.useMutation)({
|
|
1544
1581
|
mutationKey: ["emporix", "orders", "cancel"],
|
|
1545
1582
|
mutationFn: async (input) => {
|
|
1546
1583
|
const token = storage.getCustomerToken();
|
|
@@ -1548,7 +1585,7 @@ function useCancelOrder() {
|
|
|
1548
1585
|
const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
|
|
1549
1586
|
await client.orders.cancel(
|
|
1550
1587
|
orderId,
|
|
1551
|
-
|
|
1588
|
+
import_emporix_sdk28.auth.customer(token),
|
|
1552
1589
|
saasToken ? { saasToken } : {}
|
|
1553
1590
|
);
|
|
1554
1591
|
},
|
|
@@ -1559,12 +1596,12 @@ function useCancelOrder() {
|
|
|
1559
1596
|
}
|
|
1560
1597
|
|
|
1561
1598
|
// src/hooks/use-order-transition.ts
|
|
1562
|
-
var
|
|
1563
|
-
var
|
|
1599
|
+
var import_react_query29 = require("@tanstack/react-query");
|
|
1600
|
+
var import_emporix_sdk29 = require("@viu/emporix-sdk");
|
|
1564
1601
|
function useOrderTransition() {
|
|
1565
1602
|
const { client, storage } = useEmporix();
|
|
1566
|
-
const qc = (0,
|
|
1567
|
-
return (0,
|
|
1603
|
+
const qc = (0, import_react_query29.useQueryClient)();
|
|
1604
|
+
return (0, import_react_query29.useMutation)({
|
|
1568
1605
|
mutationKey: ["emporix", "orders", "transition"],
|
|
1569
1606
|
mutationFn: async ({ orderId, status, comment, saasToken }) => {
|
|
1570
1607
|
const token = storage.getCustomerToken();
|
|
@@ -1572,7 +1609,7 @@ function useOrderTransition() {
|
|
|
1572
1609
|
await client.orders.transition(
|
|
1573
1610
|
orderId,
|
|
1574
1611
|
status,
|
|
1575
|
-
|
|
1612
|
+
import_emporix_sdk29.auth.customer(token),
|
|
1576
1613
|
{
|
|
1577
1614
|
...comment !== void 0 ? { comment } : {},
|
|
1578
1615
|
...saasToken !== void 0 ? { saasToken } : {}
|
|
@@ -1586,17 +1623,17 @@ function useOrderTransition() {
|
|
|
1586
1623
|
}
|
|
1587
1624
|
|
|
1588
1625
|
// src/hooks/use-reorder.ts
|
|
1589
|
-
var
|
|
1590
|
-
var
|
|
1626
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
1627
|
+
var import_emporix_sdk30 = require("@viu/emporix-sdk");
|
|
1591
1628
|
function useReorder() {
|
|
1592
1629
|
const { client, storage } = useEmporix();
|
|
1593
|
-
const qc = (0,
|
|
1594
|
-
return (0,
|
|
1630
|
+
const qc = (0, import_react_query30.useQueryClient)();
|
|
1631
|
+
return (0, import_react_query30.useMutation)({
|
|
1595
1632
|
mutationKey: ["emporix", "orders", "reorder"],
|
|
1596
1633
|
mutationFn: async ({ orderId, saasToken }) => {
|
|
1597
1634
|
const token = storage.getCustomerToken();
|
|
1598
1635
|
if (!token) throw new Error("useReorder: requires a logged-in customer");
|
|
1599
|
-
const ctx =
|
|
1636
|
+
const ctx = import_emporix_sdk30.auth.customer(token);
|
|
1600
1637
|
const order = await qc.fetchQuery({
|
|
1601
1638
|
queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1602
1639
|
queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
|
|
@@ -1643,12 +1680,12 @@ function useReorder() {
|
|
|
1643
1680
|
}
|
|
1644
1681
|
|
|
1645
1682
|
// src/hooks/use-sales-order.ts
|
|
1646
|
-
var
|
|
1647
|
-
var
|
|
1683
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
1684
|
+
var import_emporix_sdk31 = require("@viu/emporix-sdk");
|
|
1648
1685
|
function useSalesOrder(orderId, authCtx) {
|
|
1649
1686
|
const { client } = useEmporix();
|
|
1650
1687
|
const { language } = useReadSite();
|
|
1651
|
-
return (0,
|
|
1688
|
+
return (0, import_react_query31.useQuery)({
|
|
1652
1689
|
queryKey: emporixKey("salesorders", [orderId ?? null], {
|
|
1653
1690
|
tenant: client.tenant,
|
|
1654
1691
|
authKind: authCtx?.kind ?? "anonymous",
|
|
@@ -1660,19 +1697,19 @@ function useSalesOrder(orderId, authCtx) {
|
|
|
1660
1697
|
}
|
|
1661
1698
|
|
|
1662
1699
|
// src/hooks/use-update-sales-order.ts
|
|
1663
|
-
var
|
|
1664
|
-
var
|
|
1700
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
1701
|
+
var import_emporix_sdk32 = require("@viu/emporix-sdk");
|
|
1665
1702
|
function useUpdateSalesOrder() {
|
|
1666
1703
|
const { client } = useEmporix();
|
|
1667
|
-
const qc = (0,
|
|
1668
|
-
return (0,
|
|
1704
|
+
const qc = (0, import_react_query32.useQueryClient)();
|
|
1705
|
+
return (0, import_react_query32.useMutation)({
|
|
1669
1706
|
mutationKey: ["emporix", "salesorders", "update"],
|
|
1670
|
-
mutationFn: async ({ orderId, patch, auth:
|
|
1671
|
-
if (!
|
|
1707
|
+
mutationFn: async ({ orderId, patch, auth: auth20, recalculate }) => {
|
|
1708
|
+
if (!auth20) throw new Error("useUpdateSalesOrder: requires an auth context");
|
|
1672
1709
|
return client.salesOrders.update(
|
|
1673
1710
|
orderId,
|
|
1674
1711
|
patch,
|
|
1675
|
-
|
|
1712
|
+
auth20,
|
|
1676
1713
|
recalculate !== void 0 ? { recalculate } : {}
|
|
1677
1714
|
);
|
|
1678
1715
|
},
|
|
@@ -1685,13 +1722,13 @@ function useUpdateSalesOrder() {
|
|
|
1685
1722
|
}
|
|
1686
1723
|
|
|
1687
1724
|
// src/hooks/use-availability.ts
|
|
1688
|
-
var
|
|
1689
|
-
var
|
|
1725
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
1726
|
+
var import_emporix_sdk33 = require("@viu/emporix-sdk");
|
|
1690
1727
|
var AVAILABILITY_STALE_TIME = 3e4;
|
|
1691
1728
|
function useAvailability(productId, siteCode, options = {}) {
|
|
1692
1729
|
const { client } = useEmporix();
|
|
1693
|
-
const ctx = options.customerToken ?
|
|
1694
|
-
return (0,
|
|
1730
|
+
const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
|
|
1731
|
+
return (0, import_react_query33.useQuery)({
|
|
1695
1732
|
queryKey: [
|
|
1696
1733
|
"emporix",
|
|
1697
1734
|
"availability",
|
|
@@ -1712,13 +1749,13 @@ function useAvailability(productId, siteCode, options = {}) {
|
|
|
1712
1749
|
}
|
|
1713
1750
|
|
|
1714
1751
|
// src/hooks/use-availabilities.ts
|
|
1715
|
-
var
|
|
1716
|
-
var
|
|
1752
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
1753
|
+
var import_emporix_sdk34 = require("@viu/emporix-sdk");
|
|
1717
1754
|
var AVAILABILITY_STALE_TIME2 = 3e4;
|
|
1718
1755
|
function useAvailabilities(productIds, siteCode, options = {}) {
|
|
1719
1756
|
const { client } = useEmporix();
|
|
1720
|
-
const ctx = options.customerToken ?
|
|
1721
|
-
return (0,
|
|
1757
|
+
const ctx = options.customerToken ? import_emporix_sdk34.auth.customer(options.customerToken) : import_emporix_sdk34.auth.anonymous();
|
|
1758
|
+
return (0, import_react_query34.useQuery)({
|
|
1722
1759
|
queryKey: [
|
|
1723
1760
|
"emporix",
|
|
1724
1761
|
"availabilities",
|
|
@@ -1739,33 +1776,33 @@ function useAvailabilities(productIds, siteCode, options = {}) {
|
|
|
1739
1776
|
}
|
|
1740
1777
|
|
|
1741
1778
|
// src/hooks/use-coupons.ts
|
|
1742
|
-
var
|
|
1779
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
1743
1780
|
var INVALIDATE_KEY2 = ["emporix", "coupons"];
|
|
1744
1781
|
function useValidateCoupon() {
|
|
1745
1782
|
const { client } = useEmporix();
|
|
1746
1783
|
const { ctx } = useReadAuth();
|
|
1747
|
-
return (0,
|
|
1784
|
+
return (0, import_react_query35.useMutation)({
|
|
1748
1785
|
mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
|
|
1749
1786
|
});
|
|
1750
1787
|
}
|
|
1751
1788
|
function useRedeemCoupon() {
|
|
1752
1789
|
const { client } = useEmporix();
|
|
1753
1790
|
const { ctx } = useReadAuth();
|
|
1754
|
-
const qc = (0,
|
|
1755
|
-
return (0,
|
|
1791
|
+
const qc = (0, import_react_query35.useQueryClient)();
|
|
1792
|
+
return (0, import_react_query35.useMutation)({
|
|
1756
1793
|
mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
|
|
1757
1794
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
|
|
1758
1795
|
});
|
|
1759
1796
|
}
|
|
1760
1797
|
|
|
1761
1798
|
// src/hooks/use-reward-points.ts
|
|
1762
|
-
var
|
|
1799
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
1763
1800
|
var STALE = 3e4;
|
|
1764
1801
|
var INVALIDATE_KEY3 = ["emporix", "reward-points"];
|
|
1765
1802
|
function useMyRewardPoints() {
|
|
1766
1803
|
const { client } = useEmporix();
|
|
1767
1804
|
const ctx = useCustomerOnlyCtx();
|
|
1768
|
-
return (0,
|
|
1805
|
+
return (0, import_react_query36.useQuery)({
|
|
1769
1806
|
queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1770
1807
|
queryFn: () => client.rewardPoints.getMyPoints(ctx),
|
|
1771
1808
|
staleTime: STALE
|
|
@@ -1774,7 +1811,7 @@ function useMyRewardPoints() {
|
|
|
1774
1811
|
function useMyRewardPointsSummary() {
|
|
1775
1812
|
const { client } = useEmporix();
|
|
1776
1813
|
const ctx = useCustomerOnlyCtx();
|
|
1777
|
-
return (0,
|
|
1814
|
+
return (0, import_react_query36.useQuery)({
|
|
1778
1815
|
queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1779
1816
|
queryFn: () => client.rewardPoints.getMySummary(ctx),
|
|
1780
1817
|
staleTime: STALE
|
|
@@ -1783,7 +1820,7 @@ function useMyRewardPointsSummary() {
|
|
|
1783
1820
|
function useRedeemOptions() {
|
|
1784
1821
|
const { client } = useEmporix();
|
|
1785
1822
|
const { ctx } = useReadAuth();
|
|
1786
|
-
return (0,
|
|
1823
|
+
return (0, import_react_query36.useQuery)({
|
|
1787
1824
|
queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1788
1825
|
queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
|
|
1789
1826
|
staleTime: STALE
|
|
@@ -1792,21 +1829,21 @@ function useRedeemOptions() {
|
|
|
1792
1829
|
function useRedeemRewardPoints() {
|
|
1793
1830
|
const { client } = useEmporix();
|
|
1794
1831
|
const ctx = useCustomerOnlyCtx();
|
|
1795
|
-
const qc = (0,
|
|
1796
|
-
return (0,
|
|
1832
|
+
const qc = (0, import_react_query36.useQueryClient)();
|
|
1833
|
+
return (0, import_react_query36.useMutation)({
|
|
1797
1834
|
mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
|
|
1798
1835
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
|
|
1799
1836
|
});
|
|
1800
1837
|
}
|
|
1801
1838
|
|
|
1802
1839
|
// src/hooks/use-returns.ts
|
|
1803
|
-
var
|
|
1840
|
+
var import_react_query37 = require("@tanstack/react-query");
|
|
1804
1841
|
var STALE2 = 3e4;
|
|
1805
1842
|
var INVALIDATE_KEY4 = ["emporix", "returns"];
|
|
1806
1843
|
function useMyReturns(opts = {}) {
|
|
1807
1844
|
const { client } = useEmporix();
|
|
1808
1845
|
const ctx = useCustomerOnlyCtx();
|
|
1809
|
-
return (0,
|
|
1846
|
+
return (0, import_react_query37.useQuery)({
|
|
1810
1847
|
queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1811
1848
|
queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
|
|
1812
1849
|
staleTime: STALE2
|
|
@@ -1815,7 +1852,7 @@ function useMyReturns(opts = {}) {
|
|
|
1815
1852
|
function useReturn(returnId) {
|
|
1816
1853
|
const { client } = useEmporix();
|
|
1817
1854
|
const ctx = useCustomerOnlyCtx();
|
|
1818
|
-
return (0,
|
|
1855
|
+
return (0, import_react_query37.useQuery)({
|
|
1819
1856
|
queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1820
1857
|
queryFn: () => client.returns.getReturn(returnId, ctx),
|
|
1821
1858
|
enabled: Boolean(returnId),
|
|
@@ -1825,21 +1862,21 @@ function useReturn(returnId) {
|
|
|
1825
1862
|
function useCreateReturn() {
|
|
1826
1863
|
const { client } = useEmporix();
|
|
1827
1864
|
const ctx = useCustomerOnlyCtx();
|
|
1828
|
-
const qc = (0,
|
|
1829
|
-
return (0,
|
|
1865
|
+
const qc = (0, import_react_query37.useQueryClient)();
|
|
1866
|
+
return (0, import_react_query37.useMutation)({
|
|
1830
1867
|
mutationFn: (input) => client.returns.createReturn(input, ctx),
|
|
1831
1868
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
|
|
1832
1869
|
});
|
|
1833
1870
|
}
|
|
1834
1871
|
|
|
1835
1872
|
// src/hooks/use-approvals.ts
|
|
1836
|
-
var
|
|
1873
|
+
var import_react_query38 = require("@tanstack/react-query");
|
|
1837
1874
|
var STALE3 = 3e4;
|
|
1838
1875
|
var INVALIDATE_KEY5 = ["emporix", "approvals"];
|
|
1839
1876
|
function useApprovals(opts = {}) {
|
|
1840
1877
|
const { client } = useEmporix();
|
|
1841
1878
|
const ctx = useCustomerOnlyCtx();
|
|
1842
|
-
return (0,
|
|
1879
|
+
return (0, import_react_query38.useQuery)({
|
|
1843
1880
|
queryKey: emporixKey("approvals", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1844
1881
|
queryFn: () => client.approvals.listApprovals(opts.query ?? {}, ctx),
|
|
1845
1882
|
staleTime: STALE3
|
|
@@ -1848,7 +1885,7 @@ function useApprovals(opts = {}) {
|
|
|
1848
1885
|
function useApproval(approvalId) {
|
|
1849
1886
|
const { client } = useEmporix();
|
|
1850
1887
|
const ctx = useCustomerOnlyCtx();
|
|
1851
|
-
return (0,
|
|
1888
|
+
return (0, import_react_query38.useQuery)({
|
|
1852
1889
|
queryKey: emporixKey("approvals", [approvalId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1853
1890
|
queryFn: () => client.approvals.getApproval(approvalId, ctx),
|
|
1854
1891
|
enabled: Boolean(approvalId),
|
|
@@ -1858,8 +1895,8 @@ function useApproval(approvalId) {
|
|
|
1858
1895
|
function useCreateApproval() {
|
|
1859
1896
|
const { client } = useEmporix();
|
|
1860
1897
|
const ctx = useCustomerOnlyCtx();
|
|
1861
|
-
const qc = (0,
|
|
1862
|
-
return (0,
|
|
1898
|
+
const qc = (0, import_react_query38.useQueryClient)();
|
|
1899
|
+
return (0, import_react_query38.useMutation)({
|
|
1863
1900
|
mutationFn: (input) => client.approvals.createApproval(input, ctx),
|
|
1864
1901
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
|
|
1865
1902
|
});
|
|
@@ -1867,8 +1904,8 @@ function useCreateApproval() {
|
|
|
1867
1904
|
function useUpdateApproval() {
|
|
1868
1905
|
const { client } = useEmporix();
|
|
1869
1906
|
const ctx = useCustomerOnlyCtx();
|
|
1870
|
-
const qc = (0,
|
|
1871
|
-
return (0,
|
|
1907
|
+
const qc = (0, import_react_query38.useQueryClient)();
|
|
1908
|
+
return (0, import_react_query38.useMutation)({
|
|
1872
1909
|
mutationFn: ({ approvalId, ops }) => client.approvals.updateApproval(approvalId, ops, ctx),
|
|
1873
1910
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
|
|
1874
1911
|
});
|