@viu/emporix-sdk-react 2.13.1 → 2.14.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 +16 -0
- package/dist/{chunk-SXZCM2LE.js → chunk-7F5EB5XY.js} +510 -196
- package/dist/chunk-7F5EB5XY.js.map +1 -0
- package/dist/{chunk-4YDWCA7A.js → chunk-CZDVH3WH.js} +165 -107
- package/dist/chunk-CZDVH3WH.js.map +1 -0
- package/dist/{chunk-VMDBYVWG.js → chunk-ZNLAYNF5.js} +11 -4
- package/dist/chunk-ZNLAYNF5.js.map +1 -0
- package/dist/hooks.cjs +599 -315
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js +185 -4
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +779 -436
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +240 -8
- package/dist/index.js.map +1 -1
- package/dist/provider.cjs +187 -123
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +12 -3
- package/dist/provider.js.map +1 -1
- package/dist/ssr.cjs +36 -5
- package/dist/ssr.cjs.map +1 -1
- package/dist/ssr.d.cts +22 -6
- package/dist/ssr.d.ts +22 -6
- package/dist/ssr.js +54 -1
- package/dist/ssr.js.map +1 -1
- package/dist/storage.cjs +39 -9
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +5 -1
- package/dist/storage.d.ts +5 -1
- package/dist/storage.js +15 -2
- package/dist/storage.js.map +1 -1
- package/package.json +5 -4
- package/dist/chunk-4YDWCA7A.js.map +0 -1
- package/dist/chunk-SXZCM2LE.js.map +0 -1
- package/dist/chunk-TIS4BKHK.js +0 -25
- package/dist/chunk-TIS4BKHK.js.map +0 -1
- package/dist/chunk-VMDBYVWG.js.map +0 -1
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
EmporixSiteContext,
|
|
4
|
+
useActiveCompany,
|
|
5
|
+
useEmporix
|
|
6
|
+
} from "./chunk-CZDVH3WH.js";
|
|
7
|
+
|
|
8
|
+
// src/hooks/use-customer-session.ts
|
|
9
|
+
import { useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
10
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
11
|
+
import { auth } from "@viu/emporix-sdk";
|
|
5
12
|
|
|
6
13
|
// src/hooks/internal/bootstrap-cart.ts
|
|
7
14
|
async function bootstrapCart(opts) {
|
|
@@ -55,6 +62,9 @@ function getCustomerSessionStore(storage) {
|
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
64
|
};
|
|
65
|
+
storage.subscribe?.((t) => {
|
|
66
|
+
store.setState((s) => s.token === t ? s : { ...s, token: t });
|
|
67
|
+
});
|
|
58
68
|
stores.set(storage, store);
|
|
59
69
|
return store;
|
|
60
70
|
}
|
|
@@ -72,9 +82,6 @@ function useCustomerSession() {
|
|
|
72
82
|
const store = useMemo(() => getCustomerSessionStore(storage), [storage]);
|
|
73
83
|
const session = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
74
84
|
const setSession = store.setState;
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
return storage.subscribe?.((t) => setSession((s) => ({ ...s, token: t })));
|
|
77
|
-
}, [storage, setSession]);
|
|
78
85
|
const meQuery = useQuery({
|
|
79
86
|
queryKey: ["emporix", "customer", "me", { tenant: client.tenant, hasToken: session.token !== null }],
|
|
80
87
|
enabled: session.token !== null,
|
|
@@ -168,8 +175,7 @@ function useCustomerSession() {
|
|
|
168
175
|
storage.setActiveLegalEntityId(null);
|
|
169
176
|
storage.setCartId(null);
|
|
170
177
|
setSession(EMPTY_SESSION);
|
|
171
|
-
qc.removeQueries({ queryKey: ["emporix"
|
|
172
|
-
qc.removeQueries({ queryKey: ["emporix", "cart"] });
|
|
178
|
+
qc.removeQueries({ queryKey: ["emporix"] });
|
|
173
179
|
}, [client, session.token, storage, qc, setSession]);
|
|
174
180
|
const refresh = useCallback(async () => {
|
|
175
181
|
await meQuery.refetch();
|
|
@@ -252,22 +258,55 @@ async function onboardCustomerCart(opts) {
|
|
|
252
258
|
} catch {
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
|
-
|
|
261
|
+
|
|
262
|
+
// src/hooks/use-products.ts
|
|
263
|
+
import {
|
|
264
|
+
useQuery as useQuery2
|
|
265
|
+
} from "@tanstack/react-query";
|
|
266
|
+
import "@viu/emporix-sdk";
|
|
267
|
+
|
|
268
|
+
// src/hooks/internal/use-read-auth.ts
|
|
269
|
+
import { auth as auth2 } from "@viu/emporix-sdk";
|
|
270
|
+
|
|
271
|
+
// src/hooks/internal/use-storage-snapshot.ts
|
|
272
|
+
import { useCallback as useCallback2, useMemo as useMemo2, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
273
|
+
function useCustomerToken() {
|
|
274
|
+
const { storage } = useEmporix();
|
|
275
|
+
const store = useMemo2(() => getCustomerSessionStore(storage), [storage]);
|
|
276
|
+
const getToken = useCallback2(() => store.getSnapshot().token, [store]);
|
|
277
|
+
return useSyncExternalStore2(store.subscribe, getToken, getToken);
|
|
278
|
+
}
|
|
279
|
+
function useCartId() {
|
|
256
280
|
const { storage } = useEmporix();
|
|
281
|
+
const subscribe = useCallback2(
|
|
282
|
+
(onChange) => storage.subscribeAll?.((key) => {
|
|
283
|
+
if (key === "cartId") onChange();
|
|
284
|
+
}) ?? (() => {
|
|
285
|
+
}),
|
|
286
|
+
[storage]
|
|
287
|
+
);
|
|
288
|
+
const getCartId = useCallback2(() => storage.getCartId(), [storage]);
|
|
289
|
+
return useSyncExternalStore2(subscribe, getCartId, getCartId);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/hooks/internal/use-read-auth.ts
|
|
293
|
+
function useReadAuth(override) {
|
|
294
|
+
const token = useCustomerToken();
|
|
257
295
|
if (override) return { ctx: override };
|
|
258
|
-
|
|
259
|
-
return token ? { ctx: auth.customer(token) } : { ctx: auth.anonymous() };
|
|
296
|
+
return token ? { ctx: auth2.customer(token) } : { ctx: auth2.anonymous() };
|
|
260
297
|
}
|
|
261
298
|
function useCustomerOnlyCtx() {
|
|
262
|
-
const
|
|
263
|
-
const token = storage.getCustomerToken();
|
|
299
|
+
const token = useCustomerToken();
|
|
264
300
|
if (!token) {
|
|
265
301
|
throw new Error("Requires a logged-in customer (no token in storage)");
|
|
266
302
|
}
|
|
267
|
-
return
|
|
303
|
+
return auth2.customer(token);
|
|
268
304
|
}
|
|
305
|
+
|
|
306
|
+
// src/hooks/internal/use-read-site.ts
|
|
307
|
+
import { useContext as useContext2 } from "react";
|
|
269
308
|
function useReadSite() {
|
|
270
|
-
const ctx =
|
|
309
|
+
const ctx = useContext2(EmporixSiteContext);
|
|
271
310
|
return { siteCode: ctx?.siteCode ?? null, language: ctx?.language ?? null };
|
|
272
311
|
}
|
|
273
312
|
|
|
@@ -285,6 +324,11 @@ function emporixKey(resource, args, context) {
|
|
|
285
324
|
}
|
|
286
325
|
return ["emporix", resource, ...args, meta];
|
|
287
326
|
}
|
|
327
|
+
|
|
328
|
+
// src/hooks/internal/use-emporix-infinite.ts
|
|
329
|
+
import {
|
|
330
|
+
useInfiniteQuery
|
|
331
|
+
} from "@tanstack/react-query";
|
|
288
332
|
function useEmporixInfinite(opts) {
|
|
289
333
|
return useInfiniteQuery({
|
|
290
334
|
queryKey: opts.queryKey,
|
|
@@ -302,7 +346,7 @@ function useProduct(productId, options = {}) {
|
|
|
302
346
|
const { client } = useEmporix();
|
|
303
347
|
const { ctx } = useReadAuth(options.auth);
|
|
304
348
|
const { siteCode, language } = useReadSite();
|
|
305
|
-
return
|
|
349
|
+
return useQuery2({
|
|
306
350
|
queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
307
351
|
queryFn: () => client.products.get(productId, void 0, ctx),
|
|
308
352
|
staleTime: PRODUCTS_STALE_TIME
|
|
@@ -312,7 +356,7 @@ function useProducts(params = {}, options = {}) {
|
|
|
312
356
|
const { client } = useEmporix();
|
|
313
357
|
const { ctx } = useReadAuth(options.auth);
|
|
314
358
|
const { siteCode, language } = useReadSite();
|
|
315
|
-
return
|
|
359
|
+
return useQuery2({
|
|
316
360
|
queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
317
361
|
queryFn: () => client.products.list(params, ctx),
|
|
318
362
|
staleTime: PRODUCTS_STALE_TIME
|
|
@@ -335,7 +379,7 @@ function useProductByCode(code, options = {}) {
|
|
|
335
379
|
const { client } = useEmporix();
|
|
336
380
|
const { ctx } = useReadAuth(options.auth);
|
|
337
381
|
const { siteCode, language } = useReadSite();
|
|
338
|
-
return
|
|
382
|
+
return useQuery2({
|
|
339
383
|
queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
340
384
|
enabled: typeof code === "string" && code !== "",
|
|
341
385
|
queryFn: () => client.products.getByCode(code, ctx),
|
|
@@ -346,7 +390,7 @@ function useProductSearch(query, params = {}, options = {}) {
|
|
|
346
390
|
const { client } = useEmporix();
|
|
347
391
|
const { ctx } = useReadAuth(options.auth);
|
|
348
392
|
const { siteCode, language } = useReadSite();
|
|
349
|
-
return
|
|
393
|
+
return useQuery2({
|
|
350
394
|
queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
351
395
|
enabled: typeof query === "string" && query.trim() !== "",
|
|
352
396
|
queryFn: () => client.products.search(query, params, ctx),
|
|
@@ -357,7 +401,7 @@ function useProductNameSearch(term, params = {}, options = {}) {
|
|
|
357
401
|
const { client } = useEmporix();
|
|
358
402
|
const { ctx } = useReadAuth(options.auth);
|
|
359
403
|
const { siteCode, language } = useReadSite();
|
|
360
|
-
return
|
|
404
|
+
return useQuery2({
|
|
361
405
|
queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
362
406
|
enabled: typeof term === "string" && term.trim() !== "",
|
|
363
407
|
queryFn: () => client.products.searchByName(term, params, ctx),
|
|
@@ -368,7 +412,7 @@ function useProductsByCodes(codes, options = {}) {
|
|
|
368
412
|
const { client } = useEmporix();
|
|
369
413
|
const { ctx } = useReadAuth(options.auth);
|
|
370
414
|
const { siteCode, language } = useReadSite();
|
|
371
|
-
return
|
|
415
|
+
return useQuery2({
|
|
372
416
|
queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
|
|
373
417
|
tenant: client.tenant,
|
|
374
418
|
authKind: ctx.kind,
|
|
@@ -384,13 +428,21 @@ function useProductsByCodes(codes, options = {}) {
|
|
|
384
428
|
staleTime: 3e4
|
|
385
429
|
});
|
|
386
430
|
}
|
|
431
|
+
|
|
432
|
+
// src/hooks/use-shopping-lists.ts
|
|
433
|
+
import {
|
|
434
|
+
useQuery as useQuery3,
|
|
435
|
+
useMutation,
|
|
436
|
+
useQueryClient as useQueryClient2
|
|
437
|
+
} from "@tanstack/react-query";
|
|
438
|
+
import "@viu/emporix-sdk";
|
|
387
439
|
var SHOPPING_LIST_STALE_TIME = 3e4;
|
|
388
440
|
var INVALIDATE_KEY = ["emporix", "shopping-lists"];
|
|
389
441
|
function useShoppingLists(opts = {}) {
|
|
390
442
|
const { client } = useEmporix();
|
|
391
443
|
const ctx = useCustomerOnlyCtx();
|
|
392
444
|
const { siteCode, language } = useReadSite();
|
|
393
|
-
return
|
|
445
|
+
return useQuery3({
|
|
394
446
|
queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
395
447
|
queryFn: () => client.shoppingLists.list(ctx, opts),
|
|
396
448
|
staleTime: SHOPPING_LIST_STALE_TIME
|
|
@@ -399,7 +451,7 @@ function useShoppingLists(opts = {}) {
|
|
|
399
451
|
function useCreateShoppingList() {
|
|
400
452
|
const { client } = useEmporix();
|
|
401
453
|
const ctx = useCustomerOnlyCtx();
|
|
402
|
-
const qc =
|
|
454
|
+
const qc = useQueryClient2();
|
|
403
455
|
return useMutation({
|
|
404
456
|
mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
|
|
405
457
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
@@ -408,7 +460,7 @@ function useCreateShoppingList() {
|
|
|
408
460
|
function useDeleteShoppingList() {
|
|
409
461
|
const { client } = useEmporix();
|
|
410
462
|
const ctx = useCustomerOnlyCtx();
|
|
411
|
-
const qc =
|
|
463
|
+
const qc = useQueryClient2();
|
|
412
464
|
return useMutation({
|
|
413
465
|
mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
|
|
414
466
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
@@ -417,7 +469,7 @@ function useDeleteShoppingList() {
|
|
|
417
469
|
function useAddToShoppingList() {
|
|
418
470
|
const { client } = useEmporix();
|
|
419
471
|
const ctx = useCustomerOnlyCtx();
|
|
420
|
-
const qc =
|
|
472
|
+
const qc = useQueryClient2();
|
|
421
473
|
return useMutation({
|
|
422
474
|
mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
|
|
423
475
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
@@ -426,7 +478,7 @@ function useAddToShoppingList() {
|
|
|
426
478
|
function useRemoveFromShoppingList() {
|
|
427
479
|
const { client } = useEmporix();
|
|
428
480
|
const ctx = useCustomerOnlyCtx();
|
|
429
|
-
const qc =
|
|
481
|
+
const qc = useQueryClient2();
|
|
430
482
|
return useMutation({
|
|
431
483
|
mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
|
|
432
484
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
@@ -435,18 +487,22 @@ function useRemoveFromShoppingList() {
|
|
|
435
487
|
function useSetShoppingListItemQuantity() {
|
|
436
488
|
const { client } = useEmporix();
|
|
437
489
|
const ctx = useCustomerOnlyCtx();
|
|
438
|
-
const qc =
|
|
490
|
+
const qc = useQueryClient2();
|
|
439
491
|
return useMutation({
|
|
440
492
|
mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
|
|
441
493
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
442
494
|
});
|
|
443
495
|
}
|
|
496
|
+
|
|
497
|
+
// src/hooks/use-variant-children.ts
|
|
498
|
+
import { useQuery as useQuery4 } from "@tanstack/react-query";
|
|
499
|
+
import "@viu/emporix-sdk";
|
|
444
500
|
var VARIANT_CHILDREN_STALE_TIME = 6e4;
|
|
445
501
|
function useVariantChildren(parentVariantId, options = {}) {
|
|
446
502
|
const { client } = useEmporix();
|
|
447
503
|
const { ctx } = useReadAuth(options.auth);
|
|
448
504
|
const { siteCode, language } = useReadSite();
|
|
449
|
-
return
|
|
505
|
+
return useQuery4({
|
|
450
506
|
queryKey: emporixKey(
|
|
451
507
|
"variant-children",
|
|
452
508
|
[parentVariantId, { pageSize: options.pageSize }],
|
|
@@ -461,12 +517,18 @@ function useVariantChildren(parentVariantId, options = {}) {
|
|
|
461
517
|
staleTime: VARIANT_CHILDREN_STALE_TIME
|
|
462
518
|
});
|
|
463
519
|
}
|
|
520
|
+
|
|
521
|
+
// src/hooks/use-categories.ts
|
|
522
|
+
import {
|
|
523
|
+
useQuery as useQuery5
|
|
524
|
+
} from "@tanstack/react-query";
|
|
525
|
+
import "@viu/emporix-sdk";
|
|
464
526
|
var CATEGORIES_STALE_TIME = 5 * 6e4;
|
|
465
527
|
function useCategory(categoryId, options = {}) {
|
|
466
528
|
const { client } = useEmporix();
|
|
467
529
|
const { ctx } = useReadAuth(options.auth);
|
|
468
530
|
const { siteCode, language } = useReadSite();
|
|
469
|
-
return
|
|
531
|
+
return useQuery5({
|
|
470
532
|
queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
471
533
|
queryFn: () => client.categories.get(categoryId, ctx),
|
|
472
534
|
staleTime: CATEGORIES_STALE_TIME
|
|
@@ -476,7 +538,7 @@ function useSubcategories(categoryId, params = {}, options = {}) {
|
|
|
476
538
|
const { client } = useEmporix();
|
|
477
539
|
const { ctx } = useReadAuth(options.auth);
|
|
478
540
|
const { siteCode, language } = useReadSite();
|
|
479
|
-
return
|
|
541
|
+
return useQuery5({
|
|
480
542
|
queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
481
543
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
482
544
|
queryFn: () => client.categories.subcategories(categoryId, params, ctx),
|
|
@@ -487,7 +549,7 @@ function useCategories(params = {}, options = {}) {
|
|
|
487
549
|
const { client } = useEmporix();
|
|
488
550
|
const { ctx } = useReadAuth(options.auth);
|
|
489
551
|
const { siteCode, language } = useReadSite();
|
|
490
|
-
return
|
|
552
|
+
return useQuery5({
|
|
491
553
|
queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
492
554
|
queryFn: () => client.categories.list(params, ctx),
|
|
493
555
|
staleTime: CATEGORIES_STALE_TIME
|
|
@@ -510,7 +572,7 @@ function useCategoryTree(options = {}) {
|
|
|
510
572
|
const { client } = useEmporix();
|
|
511
573
|
const { ctx } = useReadAuth(options.auth);
|
|
512
574
|
const { siteCode, language } = useReadSite();
|
|
513
|
-
return
|
|
575
|
+
return useQuery5({
|
|
514
576
|
queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
515
577
|
queryFn: () => client.categories.tree(ctx),
|
|
516
578
|
staleTime: CATEGORIES_STALE_TIME
|
|
@@ -520,7 +582,7 @@ function useProductsInCategory(categoryId, params = {}, options = {}) {
|
|
|
520
582
|
const { client } = useEmporix();
|
|
521
583
|
const { ctx } = useReadAuth(options.auth);
|
|
522
584
|
const { siteCode, language } = useReadSite();
|
|
523
|
-
return
|
|
585
|
+
return useQuery5({
|
|
524
586
|
queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
525
587
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
526
588
|
queryFn: () => client.categories.productsIn(categoryId, params, ctx),
|
|
@@ -542,13 +604,25 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
|
|
|
542
604
|
staleTime: CATEGORIES_STALE_TIME
|
|
543
605
|
});
|
|
544
606
|
}
|
|
607
|
+
|
|
608
|
+
// src/hooks/use-cart.ts
|
|
609
|
+
import { useEffect } from "react";
|
|
610
|
+
import {
|
|
611
|
+
useMutation as useMutation2,
|
|
612
|
+
useQuery as useQuery6,
|
|
613
|
+
useQueryClient as useQueryClient3
|
|
614
|
+
} from "@tanstack/react-query";
|
|
615
|
+
import {
|
|
616
|
+
EmporixError
|
|
617
|
+
} from "@viu/emporix-sdk";
|
|
545
618
|
function useCart(cartId, options = {}) {
|
|
546
|
-
const { client
|
|
619
|
+
const { client } = useEmporix();
|
|
547
620
|
const { ctx } = useReadAuth(options.auth);
|
|
548
621
|
const { siteCode, language } = useReadSite();
|
|
549
622
|
const { activeCompany } = useActiveCompany();
|
|
550
|
-
const
|
|
551
|
-
|
|
623
|
+
const storedCartId = useCartId();
|
|
624
|
+
const resolvedId = cartId ?? storedCartId ?? void 0;
|
|
625
|
+
return useQuery6({
|
|
552
626
|
queryKey: emporixKey(
|
|
553
627
|
"cart",
|
|
554
628
|
[resolvedId ?? null, activeCompany?.id ?? null],
|
|
@@ -560,7 +634,7 @@ function useCart(cartId, options = {}) {
|
|
|
560
634
|
}
|
|
561
635
|
function useCartMutations(cartId) {
|
|
562
636
|
const { client, storage } = useEmporix();
|
|
563
|
-
const qc =
|
|
637
|
+
const qc = useQueryClient3();
|
|
564
638
|
const { ctx } = useReadAuth();
|
|
565
639
|
const { siteCode, language } = useReadSite();
|
|
566
640
|
const { activeCompany } = useActiveCompany();
|
|
@@ -579,7 +653,7 @@ function useCartMutations(cartId) {
|
|
|
579
653
|
{ tenant: client.tenant, authKind: ctx.kind, siteCode, language }
|
|
580
654
|
);
|
|
581
655
|
function make(run, optimistic) {
|
|
582
|
-
return
|
|
656
|
+
return useMutation2({
|
|
583
657
|
mutationFn: async (vars) => run(resolveId(), vars),
|
|
584
658
|
onMutate: async (vars) => {
|
|
585
659
|
const id = resolveId();
|
|
@@ -636,9 +710,9 @@ function useCartMutations(cartId) {
|
|
|
636
710
|
}
|
|
637
711
|
function useCreateCart() {
|
|
638
712
|
const { client, storage } = useEmporix();
|
|
639
|
-
const qc =
|
|
713
|
+
const qc = useQueryClient3();
|
|
640
714
|
const { ctx } = useReadAuth();
|
|
641
|
-
return
|
|
715
|
+
return useMutation2({
|
|
642
716
|
mutationFn: (input) => client.carts.create(input, ctx),
|
|
643
717
|
onSuccess: async (cart) => {
|
|
644
718
|
if (cart.cartId) storage.setCartId(cart.cartId);
|
|
@@ -648,20 +722,12 @@ function useCreateCart() {
|
|
|
648
722
|
}
|
|
649
723
|
function useActiveCart(opts) {
|
|
650
724
|
const { client, storage } = useEmporix();
|
|
651
|
-
const qc =
|
|
725
|
+
const qc = useQueryClient3();
|
|
652
726
|
const { ctx } = useReadAuth(opts?.auth);
|
|
653
727
|
const { siteCode: activeSite } = useReadSite();
|
|
654
728
|
const { activeCompany } = useActiveCompany();
|
|
655
|
-
const
|
|
729
|
+
const cartId = useCartId();
|
|
656
730
|
const effectiveLegalEntityId = opts?.legalEntityId ?? activeCompany?.id;
|
|
657
|
-
useEffect(() => {
|
|
658
|
-
if (!storage.subscribeAll) return;
|
|
659
|
-
return storage.subscribeAll((key) => {
|
|
660
|
-
if (key !== "cartId") return;
|
|
661
|
-
const next = storage.getCartId();
|
|
662
|
-
setCartId((prev) => prev === next ? prev : next);
|
|
663
|
-
});
|
|
664
|
-
}, [storage]);
|
|
665
731
|
useEffect(() => {
|
|
666
732
|
if (cartId !== null) return;
|
|
667
733
|
if (!opts?.create) return;
|
|
@@ -679,7 +745,6 @@ function useActiveCart(opts) {
|
|
|
679
745
|
if (cancelled) return;
|
|
680
746
|
if (cart?.id) {
|
|
681
747
|
storage.setCartId(cart.id);
|
|
682
|
-
setCartId(cart.id);
|
|
683
748
|
}
|
|
684
749
|
}).catch(() => {
|
|
685
750
|
});
|
|
@@ -691,10 +756,19 @@ function useActiveCart(opts) {
|
|
|
691
756
|
const data = cartId === null ? null : inner.data;
|
|
692
757
|
return { ...inner, data };
|
|
693
758
|
}
|
|
759
|
+
|
|
760
|
+
// src/hooks/use-checkout.ts
|
|
761
|
+
import {
|
|
762
|
+
useMutation as useMutation3,
|
|
763
|
+
useQuery as useQuery7
|
|
764
|
+
} from "@tanstack/react-query";
|
|
765
|
+
import {
|
|
766
|
+
auth as auth3
|
|
767
|
+
} from "@viu/emporix-sdk";
|
|
694
768
|
var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
|
|
695
769
|
function customerOnlyCtx(token) {
|
|
696
770
|
if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
|
|
697
|
-
return
|
|
771
|
+
return auth3.customer(token);
|
|
698
772
|
}
|
|
699
773
|
function useCheckout() {
|
|
700
774
|
const { client } = useEmporix();
|
|
@@ -705,13 +779,13 @@ function useCheckout() {
|
|
|
705
779
|
if ("legalEntityId" in input) return input;
|
|
706
780
|
return { ...input, legalEntityId: activeCompany.id };
|
|
707
781
|
};
|
|
708
|
-
const placeOrder =
|
|
782
|
+
const placeOrder = useMutation3({
|
|
709
783
|
mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
|
|
710
784
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
711
785
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
712
786
|
})
|
|
713
787
|
});
|
|
714
|
-
const placeOrderFromQuote =
|
|
788
|
+
const placeOrderFromQuote = useMutation3({
|
|
715
789
|
mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
|
|
716
790
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
717
791
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
@@ -720,11 +794,11 @@ function useCheckout() {
|
|
|
720
794
|
return { placeOrder, placeOrderFromQuote };
|
|
721
795
|
}
|
|
722
796
|
function usePaymentModes(options = {}) {
|
|
723
|
-
const { client
|
|
724
|
-
const token =
|
|
797
|
+
const { client } = useEmporix();
|
|
798
|
+
const token = useCustomerToken();
|
|
725
799
|
const { siteCode } = useReadSite();
|
|
726
800
|
const { activeCompany } = useActiveCompany();
|
|
727
|
-
return
|
|
801
|
+
return useQuery7({
|
|
728
802
|
queryKey: emporixKey(
|
|
729
803
|
"payment-modes",
|
|
730
804
|
[activeCompany?.id ?? null],
|
|
@@ -735,12 +809,18 @@ function usePaymentModes(options = {}) {
|
|
|
735
809
|
staleTime: PAYMENT_MODES_STALE_TIME
|
|
736
810
|
});
|
|
737
811
|
}
|
|
812
|
+
|
|
813
|
+
// src/hooks/use-match-prices.ts
|
|
814
|
+
import { useQuery as useQuery8 } from "@tanstack/react-query";
|
|
815
|
+
import {
|
|
816
|
+
auth as auth4
|
|
817
|
+
} from "@viu/emporix-sdk";
|
|
738
818
|
var PRICES_STALE_TIME = 6e4;
|
|
739
819
|
function useMatchPrices(input, options = {}) {
|
|
740
820
|
const { client } = useEmporix();
|
|
741
821
|
const { siteCode } = useReadSite();
|
|
742
|
-
const ctx = options.customerToken ?
|
|
743
|
-
return
|
|
822
|
+
const ctx = options.customerToken ? auth4.customer(options.customerToken) : auth4.anonymous();
|
|
823
|
+
return useQuery8({
|
|
744
824
|
queryKey: [
|
|
745
825
|
"emporix",
|
|
746
826
|
"match-prices",
|
|
@@ -751,12 +831,18 @@ function useMatchPrices(input, options = {}) {
|
|
|
751
831
|
staleTime: PRICES_STALE_TIME
|
|
752
832
|
});
|
|
753
833
|
}
|
|
834
|
+
|
|
835
|
+
// src/hooks/use-match-prices-chunked.ts
|
|
836
|
+
import { useQuery as useQuery9 } from "@tanstack/react-query";
|
|
837
|
+
import {
|
|
838
|
+
auth as auth5
|
|
839
|
+
} from "@viu/emporix-sdk";
|
|
754
840
|
var PRICES_STALE_TIME2 = 6e4;
|
|
755
841
|
function useMatchPricesChunked(input, options = {}) {
|
|
756
842
|
const { client } = useEmporix();
|
|
757
843
|
const { siteCode } = useReadSite();
|
|
758
|
-
const ctx = options.customerToken ?
|
|
759
|
-
return
|
|
844
|
+
const ctx = options.customerToken ? auth5.customer(options.customerToken) : auth5.anonymous();
|
|
845
|
+
return useQuery9({
|
|
760
846
|
queryKey: [
|
|
761
847
|
"emporix",
|
|
762
848
|
"match-prices-chunked",
|
|
@@ -788,16 +874,24 @@ function useProductMedia(productId) {
|
|
|
788
874
|
const data = q.data?.productMedia;
|
|
789
875
|
return { data, isLoading: q.isLoading, error: q.error };
|
|
790
876
|
}
|
|
877
|
+
|
|
878
|
+
// src/hooks/use-my-segments.ts
|
|
879
|
+
import {
|
|
880
|
+
useQuery as useQuery10
|
|
881
|
+
} from "@tanstack/react-query";
|
|
882
|
+
import {
|
|
883
|
+
auth as auth6
|
|
884
|
+
} from "@viu/emporix-sdk";
|
|
791
885
|
var SEGMENTS_STALE_TIME = 5 * 6e4;
|
|
792
886
|
function customerCtx(token) {
|
|
793
887
|
if (!token) throw new Error("requires a customer token in storage");
|
|
794
|
-
return
|
|
888
|
+
return auth6.customer(token);
|
|
795
889
|
}
|
|
796
890
|
function useMySegments(query = {}) {
|
|
797
|
-
const { client
|
|
798
|
-
const token =
|
|
891
|
+
const { client } = useEmporix();
|
|
892
|
+
const token = useCustomerToken();
|
|
799
893
|
const { siteCode, language } = useReadSite();
|
|
800
|
-
return
|
|
894
|
+
return useQuery10({
|
|
801
895
|
queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
|
|
802
896
|
enabled: token !== null,
|
|
803
897
|
queryFn: () => client.segments.list(query, customerCtx(token)),
|
|
@@ -805,10 +899,10 @@ function useMySegments(query = {}) {
|
|
|
805
899
|
});
|
|
806
900
|
}
|
|
807
901
|
function useMySegmentItems(query = {}) {
|
|
808
|
-
const { client
|
|
809
|
-
const token =
|
|
902
|
+
const { client } = useEmporix();
|
|
903
|
+
const token = useCustomerToken();
|
|
810
904
|
const { siteCode, language } = useReadSite();
|
|
811
|
-
return
|
|
905
|
+
return useQuery10({
|
|
812
906
|
queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
|
|
813
907
|
enabled: token !== null,
|
|
814
908
|
queryFn: () => client.segments.listItems(query, customerCtx(token)),
|
|
@@ -816,10 +910,10 @@ function useMySegmentItems(query = {}) {
|
|
|
816
910
|
});
|
|
817
911
|
}
|
|
818
912
|
function useMySegmentCategoryTree(query = {}) {
|
|
819
|
-
const { client
|
|
820
|
-
const token =
|
|
913
|
+
const { client } = useEmporix();
|
|
914
|
+
const token = useCustomerToken();
|
|
821
915
|
const { siteCode, language } = useReadSite();
|
|
822
|
-
return
|
|
916
|
+
return useQuery10({
|
|
823
917
|
queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
|
|
824
918
|
enabled: token !== null,
|
|
825
919
|
queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
|
|
@@ -827,10 +921,10 @@ function useMySegmentCategoryTree(query = {}) {
|
|
|
827
921
|
});
|
|
828
922
|
}
|
|
829
923
|
function useMySegmentProducts(query = {}) {
|
|
830
|
-
const { client
|
|
831
|
-
const token =
|
|
924
|
+
const { client } = useEmporix();
|
|
925
|
+
const token = useCustomerToken();
|
|
832
926
|
const { siteCode, language } = useReadSite();
|
|
833
|
-
return
|
|
927
|
+
return useQuery10({
|
|
834
928
|
queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
|
|
835
929
|
enabled: token !== null,
|
|
836
930
|
queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
|
|
@@ -838,8 +932,8 @@ function useMySegmentProducts(query = {}) {
|
|
|
838
932
|
});
|
|
839
933
|
}
|
|
840
934
|
function useMySegmentProductsInfinite(query = {}) {
|
|
841
|
-
const { client
|
|
842
|
-
const token =
|
|
935
|
+
const { client } = useEmporix();
|
|
936
|
+
const token = useCustomerToken();
|
|
843
937
|
const { siteCode, language } = useReadSite();
|
|
844
938
|
return useEmporixInfinite({
|
|
845
939
|
queryKey: [
|
|
@@ -857,10 +951,10 @@ function useMySegmentProductsInfinite(query = {}) {
|
|
|
857
951
|
});
|
|
858
952
|
}
|
|
859
953
|
function useMySegmentCategories(query = {}) {
|
|
860
|
-
const { client
|
|
861
|
-
const token =
|
|
954
|
+
const { client } = useEmporix();
|
|
955
|
+
const token = useCustomerToken();
|
|
862
956
|
const { siteCode, language } = useReadSite();
|
|
863
|
-
return
|
|
957
|
+
return useQuery10({
|
|
864
958
|
queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
|
|
865
959
|
enabled: token !== null,
|
|
866
960
|
queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
|
|
@@ -868,8 +962,8 @@ function useMySegmentCategories(query = {}) {
|
|
|
868
962
|
});
|
|
869
963
|
}
|
|
870
964
|
function useMySegmentCategoriesInfinite(query = {}) {
|
|
871
|
-
const { client
|
|
872
|
-
const token =
|
|
965
|
+
const { client } = useEmporix();
|
|
966
|
+
const token = useCustomerToken();
|
|
873
967
|
const { siteCode, language } = useReadSite();
|
|
874
968
|
return useEmporixInfinite({
|
|
875
969
|
queryKey: [
|
|
@@ -886,11 +980,15 @@ function useMySegmentCategoriesInfinite(query = {}) {
|
|
|
886
980
|
staleTime: SEGMENTS_STALE_TIME
|
|
887
981
|
});
|
|
888
982
|
}
|
|
983
|
+
|
|
984
|
+
// src/hooks/use-customer-profile.ts
|
|
985
|
+
import { useMutation as useMutation4, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
|
|
986
|
+
import "@viu/emporix-sdk";
|
|
889
987
|
function useUpdateCustomer() {
|
|
890
988
|
const { client } = useEmporix();
|
|
891
989
|
const ctx = useCustomerOnlyCtx();
|
|
892
|
-
const qc =
|
|
893
|
-
return
|
|
990
|
+
const qc = useQueryClient4();
|
|
991
|
+
return useMutation4({
|
|
894
992
|
mutationFn: (patch) => client.customers.update(patch, ctx),
|
|
895
993
|
onSuccess: () => {
|
|
896
994
|
void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
|
|
@@ -900,17 +998,27 @@ function useUpdateCustomer() {
|
|
|
900
998
|
function useChangePassword() {
|
|
901
999
|
const { client } = useEmporix();
|
|
902
1000
|
const ctx = useCustomerOnlyCtx();
|
|
903
|
-
return
|
|
1001
|
+
return useMutation4({
|
|
904
1002
|
mutationFn: (input) => client.customers.changePassword(input, ctx)
|
|
905
1003
|
});
|
|
906
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
// src/hooks/use-customer-addresses.ts
|
|
1007
|
+
import {
|
|
1008
|
+
useMutation as useMutation5,
|
|
1009
|
+
useQuery as useQuery11,
|
|
1010
|
+
useQueryClient as useQueryClient5
|
|
1011
|
+
} from "@tanstack/react-query";
|
|
1012
|
+
import {
|
|
1013
|
+
auth as auth7
|
|
1014
|
+
} from "@viu/emporix-sdk";
|
|
907
1015
|
var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
|
|
908
1016
|
function useCustomerAddresses(options = {}) {
|
|
909
|
-
const { client
|
|
910
|
-
const token =
|
|
1017
|
+
const { client } = useEmporix();
|
|
1018
|
+
const token = useCustomerToken();
|
|
911
1019
|
const { activeCompany } = useActiveCompany();
|
|
912
|
-
const ctx = options.auth ?? (token ?
|
|
913
|
-
return
|
|
1020
|
+
const ctx = options.auth ?? (token ? auth7.customer(token) : null);
|
|
1021
|
+
return useQuery11({
|
|
914
1022
|
queryKey: [
|
|
915
1023
|
...ADDRESSES_KEY,
|
|
916
1024
|
{ tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
|
|
@@ -922,39 +1030,51 @@ function useCustomerAddresses(options = {}) {
|
|
|
922
1030
|
function useAddressMutations() {
|
|
923
1031
|
const { client } = useEmporix();
|
|
924
1032
|
const ctx = useCustomerOnlyCtx();
|
|
925
|
-
const qc =
|
|
1033
|
+
const qc = useQueryClient5();
|
|
926
1034
|
const invalidate = () => {
|
|
927
1035
|
void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
|
|
928
1036
|
};
|
|
929
1037
|
return {
|
|
930
|
-
add:
|
|
1038
|
+
add: useMutation5({
|
|
931
1039
|
mutationFn: (input) => client.customers.addresses.add(input, ctx),
|
|
932
1040
|
onSuccess: invalidate
|
|
933
1041
|
}),
|
|
934
|
-
update:
|
|
1042
|
+
update: useMutation5({
|
|
935
1043
|
mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
|
|
936
1044
|
onSuccess: invalidate
|
|
937
1045
|
}),
|
|
938
|
-
remove:
|
|
1046
|
+
remove: useMutation5({
|
|
939
1047
|
mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
|
|
940
1048
|
onSuccess: invalidate
|
|
941
1049
|
})
|
|
942
1050
|
};
|
|
943
1051
|
}
|
|
1052
|
+
|
|
1053
|
+
// src/hooks/use-password-reset.ts
|
|
1054
|
+
import { useMutation as useMutation6 } from "@tanstack/react-query";
|
|
1055
|
+
import {
|
|
1056
|
+
auth as auth8
|
|
1057
|
+
} from "@viu/emporix-sdk";
|
|
944
1058
|
function usePasswordReset() {
|
|
945
1059
|
const { client } = useEmporix();
|
|
946
|
-
const anonCtx =
|
|
1060
|
+
const anonCtx = auth8.anonymous();
|
|
947
1061
|
return {
|
|
948
|
-
request:
|
|
1062
|
+
request: useMutation6({
|
|
949
1063
|
mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
|
|
950
1064
|
}),
|
|
951
|
-
confirm:
|
|
1065
|
+
confirm: useMutation6({
|
|
952
1066
|
mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
|
|
953
1067
|
})
|
|
954
1068
|
};
|
|
955
1069
|
}
|
|
1070
|
+
|
|
1071
|
+
// src/hooks/use-sites.ts
|
|
1072
|
+
import { useQuery as useQuery12 } from "@tanstack/react-query";
|
|
1073
|
+
|
|
1074
|
+
// src/hooks/use-site-context.ts
|
|
1075
|
+
import { useContext as useContext3 } from "react";
|
|
956
1076
|
function useSiteContext() {
|
|
957
|
-
const ctx =
|
|
1077
|
+
const ctx = useContext3(EmporixSiteContext);
|
|
958
1078
|
if (!ctx) {
|
|
959
1079
|
throw new Error("useSiteContext must be used within an EmporixProvider");
|
|
960
1080
|
}
|
|
@@ -966,7 +1086,7 @@ var SITES_STALE_TIME = 10 * 6e4;
|
|
|
966
1086
|
function useSites(options = {}) {
|
|
967
1087
|
const { client } = useEmporix();
|
|
968
1088
|
const { ctx } = useReadAuth(options.auth);
|
|
969
|
-
return
|
|
1089
|
+
return useQuery12({
|
|
970
1090
|
queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
971
1091
|
queryFn: () => client.sites.list(ctx),
|
|
972
1092
|
staleTime: SITES_STALE_TIME
|
|
@@ -975,7 +1095,7 @@ function useSites(options = {}) {
|
|
|
975
1095
|
function useDefaultSite(options = {}) {
|
|
976
1096
|
const { client } = useEmporix();
|
|
977
1097
|
const { ctx } = useReadAuth(options.auth);
|
|
978
|
-
return
|
|
1098
|
+
return useQuery12({
|
|
979
1099
|
queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
980
1100
|
queryFn: () => client.sites.current(ctx),
|
|
981
1101
|
staleTime: SITES_STALE_TIME
|
|
@@ -986,79 +1106,108 @@ function useActiveSite(options = {}) {
|
|
|
986
1106
|
const { data: sites } = useSites(options);
|
|
987
1107
|
return siteCode ? sites?.find((s) => s.code === siteCode) : void 0;
|
|
988
1108
|
}
|
|
1109
|
+
|
|
1110
|
+
// src/hooks/use-my-companies.ts
|
|
1111
|
+
import { useQuery as useQuery13 } from "@tanstack/react-query";
|
|
1112
|
+
import { auth as auth9 } from "@viu/emporix-sdk";
|
|
989
1113
|
function useMyCompanies() {
|
|
990
|
-
const { client
|
|
991
|
-
const token =
|
|
992
|
-
return
|
|
1114
|
+
const { client } = useEmporix();
|
|
1115
|
+
const token = useCustomerToken();
|
|
1116
|
+
return useQuery13({
|
|
993
1117
|
queryKey: emporixKey("companies", ["mine"], {
|
|
994
1118
|
tenant: client.tenant,
|
|
995
1119
|
authKind: token ? "customer" : "anonymous"
|
|
996
1120
|
}),
|
|
997
1121
|
enabled: token !== null,
|
|
998
|
-
queryFn: () => client.companies.listMine(
|
|
1122
|
+
queryFn: () => client.companies.listMine(auth9.customer(token))
|
|
999
1123
|
});
|
|
1000
1124
|
}
|
|
1125
|
+
|
|
1126
|
+
// src/hooks/use-company.ts
|
|
1127
|
+
import { useQuery as useQuery14 } from "@tanstack/react-query";
|
|
1128
|
+
import { auth as auth10 } from "@viu/emporix-sdk";
|
|
1001
1129
|
function useCompany(legalEntityId) {
|
|
1002
|
-
const { client
|
|
1003
|
-
const token =
|
|
1004
|
-
return
|
|
1130
|
+
const { client } = useEmporix();
|
|
1131
|
+
const token = useCustomerToken();
|
|
1132
|
+
return useQuery14({
|
|
1005
1133
|
queryKey: emporixKey("companies", [legalEntityId ?? null], {
|
|
1006
1134
|
tenant: client.tenant,
|
|
1007
1135
|
authKind: token ? "customer" : "anonymous"
|
|
1008
1136
|
}),
|
|
1009
1137
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1010
|
-
queryFn: () => client.companies.get(legalEntityId,
|
|
1138
|
+
queryFn: () => client.companies.get(legalEntityId, auth10.customer(token))
|
|
1011
1139
|
});
|
|
1012
1140
|
}
|
|
1141
|
+
|
|
1142
|
+
// src/hooks/use-company-contacts.ts
|
|
1143
|
+
import { useQuery as useQuery15 } from "@tanstack/react-query";
|
|
1144
|
+
import { auth as auth11 } from "@viu/emporix-sdk";
|
|
1013
1145
|
function useCompanyContacts(legalEntityId) {
|
|
1014
1146
|
const { client, storage } = useEmporix();
|
|
1015
1147
|
const token = storage.getCustomerToken();
|
|
1016
|
-
return
|
|
1148
|
+
return useQuery15({
|
|
1017
1149
|
queryKey: emporixKey("companies", ["contacts", legalEntityId ?? null], {
|
|
1018
1150
|
tenant: client.tenant,
|
|
1019
1151
|
authKind: token ? "customer" : "anonymous"
|
|
1020
1152
|
}),
|
|
1021
1153
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1022
|
-
queryFn: () => client.contacts.listForCompany(legalEntityId,
|
|
1154
|
+
queryFn: () => client.contacts.listForCompany(legalEntityId, auth11.customer(token))
|
|
1023
1155
|
});
|
|
1024
1156
|
}
|
|
1157
|
+
|
|
1158
|
+
// src/hooks/use-company-locations.ts
|
|
1159
|
+
import { useQuery as useQuery16 } from "@tanstack/react-query";
|
|
1160
|
+
import { auth as auth12 } from "@viu/emporix-sdk";
|
|
1025
1161
|
function useCompanyLocations(legalEntityId) {
|
|
1026
|
-
const { client
|
|
1027
|
-
const token =
|
|
1028
|
-
return
|
|
1162
|
+
const { client } = useEmporix();
|
|
1163
|
+
const token = useCustomerToken();
|
|
1164
|
+
return useQuery16({
|
|
1029
1165
|
queryKey: emporixKey("companies", ["locations", legalEntityId ?? null], {
|
|
1030
1166
|
tenant: client.tenant,
|
|
1031
1167
|
authKind: token ? "customer" : "anonymous"
|
|
1032
1168
|
}),
|
|
1033
1169
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1034
|
-
queryFn: () => client.locations.listForCompany(legalEntityId,
|
|
1170
|
+
queryFn: () => client.locations.listForCompany(legalEntityId, auth12.customer(token))
|
|
1035
1171
|
});
|
|
1036
1172
|
}
|
|
1173
|
+
|
|
1174
|
+
// src/hooks/use-company-groups.ts
|
|
1175
|
+
import { useQuery as useQuery17 } from "@tanstack/react-query";
|
|
1176
|
+
import { auth as auth13 } from "@viu/emporix-sdk";
|
|
1037
1177
|
function useCompanyGroups(legalEntityId) {
|
|
1038
|
-
const { client
|
|
1039
|
-
const token =
|
|
1040
|
-
return
|
|
1178
|
+
const { client } = useEmporix();
|
|
1179
|
+
const token = useCustomerToken();
|
|
1180
|
+
return useQuery17({
|
|
1041
1181
|
queryKey: emporixKey("companies", ["groups", legalEntityId ?? null], {
|
|
1042
1182
|
tenant: client.tenant,
|
|
1043
1183
|
authKind: token ? "customer" : "anonymous"
|
|
1044
1184
|
}),
|
|
1045
1185
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1046
|
-
queryFn: () => client.customerGroups.listForCompany(legalEntityId,
|
|
1186
|
+
queryFn: () => client.customerGroups.listForCompany(legalEntityId, auth13.customer(token))
|
|
1047
1187
|
});
|
|
1048
1188
|
}
|
|
1189
|
+
|
|
1190
|
+
// src/hooks/use-company-mutations.ts
|
|
1191
|
+
import {
|
|
1192
|
+
useMutation as useMutation7,
|
|
1193
|
+
useQueryClient as useQueryClient6
|
|
1194
|
+
} from "@tanstack/react-query";
|
|
1195
|
+
import {
|
|
1196
|
+
auth as auth14
|
|
1197
|
+
} from "@viu/emporix-sdk";
|
|
1049
1198
|
function useCustomerAuthResolver() {
|
|
1050
1199
|
const { storage } = useEmporix();
|
|
1051
1200
|
return () => {
|
|
1052
1201
|
const token = storage.getCustomerToken();
|
|
1053
1202
|
if (!token) throw new Error("Mutation requires a logged-in customer token");
|
|
1054
|
-
return
|
|
1203
|
+
return auth14.customer(token);
|
|
1055
1204
|
};
|
|
1056
1205
|
}
|
|
1057
1206
|
function useCreateCompany() {
|
|
1058
1207
|
const { client } = useEmporix();
|
|
1059
1208
|
const resolveAuth = useCustomerAuthResolver();
|
|
1060
|
-
const qc =
|
|
1061
|
-
return
|
|
1209
|
+
const qc = useQueryClient6();
|
|
1210
|
+
return useMutation7({
|
|
1062
1211
|
mutationFn: (input) => client.companies.create(input, resolveAuth()),
|
|
1063
1212
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
|
|
1064
1213
|
});
|
|
@@ -1066,8 +1215,8 @@ function useCreateCompany() {
|
|
|
1066
1215
|
function useUpdateCompany() {
|
|
1067
1216
|
const { client } = useEmporix();
|
|
1068
1217
|
const resolveAuth = useCustomerAuthResolver();
|
|
1069
|
-
const qc =
|
|
1070
|
-
return
|
|
1218
|
+
const qc = useQueryClient6();
|
|
1219
|
+
return useMutation7({
|
|
1071
1220
|
mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
|
|
1072
1221
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1073
1222
|
});
|
|
@@ -1075,8 +1224,8 @@ function useUpdateCompany() {
|
|
|
1075
1224
|
function useDeleteCompany() {
|
|
1076
1225
|
const { client } = useEmporix();
|
|
1077
1226
|
const resolveAuth = useCustomerAuthResolver();
|
|
1078
|
-
const qc =
|
|
1079
|
-
return
|
|
1227
|
+
const qc = useQueryClient6();
|
|
1228
|
+
return useMutation7({
|
|
1080
1229
|
mutationFn: (id) => client.companies.delete(id, resolveAuth()),
|
|
1081
1230
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1082
1231
|
});
|
|
@@ -1084,8 +1233,8 @@ function useDeleteCompany() {
|
|
|
1084
1233
|
function useAssignContact() {
|
|
1085
1234
|
const { client } = useEmporix();
|
|
1086
1235
|
const resolveAuth = useCustomerAuthResolver();
|
|
1087
|
-
const qc =
|
|
1088
|
-
return
|
|
1236
|
+
const qc = useQueryClient6();
|
|
1237
|
+
return useMutation7({
|
|
1089
1238
|
mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
|
|
1090
1239
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1091
1240
|
});
|
|
@@ -1093,8 +1242,8 @@ function useAssignContact() {
|
|
|
1093
1242
|
function useUpdateContactAssignment() {
|
|
1094
1243
|
const { client } = useEmporix();
|
|
1095
1244
|
const resolveAuth = useCustomerAuthResolver();
|
|
1096
|
-
const qc =
|
|
1097
|
-
return
|
|
1245
|
+
const qc = useQueryClient6();
|
|
1246
|
+
return useMutation7({
|
|
1098
1247
|
mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
|
|
1099
1248
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1100
1249
|
});
|
|
@@ -1102,8 +1251,8 @@ function useUpdateContactAssignment() {
|
|
|
1102
1251
|
function useUnassignContact() {
|
|
1103
1252
|
const { client } = useEmporix();
|
|
1104
1253
|
const resolveAuth = useCustomerAuthResolver();
|
|
1105
|
-
const qc =
|
|
1106
|
-
return
|
|
1254
|
+
const qc = useQueryClient6();
|
|
1255
|
+
return useMutation7({
|
|
1107
1256
|
mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
|
|
1108
1257
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1109
1258
|
});
|
|
@@ -1111,8 +1260,8 @@ function useUnassignContact() {
|
|
|
1111
1260
|
function useCreateLocation() {
|
|
1112
1261
|
const { client } = useEmporix();
|
|
1113
1262
|
const resolveAuth = useCustomerAuthResolver();
|
|
1114
|
-
const qc =
|
|
1115
|
-
return
|
|
1263
|
+
const qc = useQueryClient6();
|
|
1264
|
+
return useMutation7({
|
|
1116
1265
|
mutationFn: (input) => client.locations.create(input, resolveAuth()),
|
|
1117
1266
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1118
1267
|
});
|
|
@@ -1120,8 +1269,8 @@ function useCreateLocation() {
|
|
|
1120
1269
|
function useUpdateLocation() {
|
|
1121
1270
|
const { client } = useEmporix();
|
|
1122
1271
|
const resolveAuth = useCustomerAuthResolver();
|
|
1123
|
-
const qc =
|
|
1124
|
-
return
|
|
1272
|
+
const qc = useQueryClient6();
|
|
1273
|
+
return useMutation7({
|
|
1125
1274
|
mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
|
|
1126
1275
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1127
1276
|
});
|
|
@@ -1129,8 +1278,8 @@ function useUpdateLocation() {
|
|
|
1129
1278
|
function useDeleteLocation() {
|
|
1130
1279
|
const { client } = useEmporix();
|
|
1131
1280
|
const resolveAuth = useCustomerAuthResolver();
|
|
1132
|
-
const qc =
|
|
1133
|
-
return
|
|
1281
|
+
const qc = useQueryClient6();
|
|
1282
|
+
return useMutation7({
|
|
1134
1283
|
mutationFn: (id) => client.locations.delete(id, resolveAuth()),
|
|
1135
1284
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1136
1285
|
});
|
|
@@ -1138,8 +1287,8 @@ function useDeleteLocation() {
|
|
|
1138
1287
|
function useAddGroupMember() {
|
|
1139
1288
|
const { client } = useEmporix();
|
|
1140
1289
|
const resolveAuth = useCustomerAuthResolver();
|
|
1141
|
-
const qc =
|
|
1142
|
-
return
|
|
1290
|
+
const qc = useQueryClient6();
|
|
1291
|
+
return useMutation7({
|
|
1143
1292
|
mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
|
|
1144
1293
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1145
1294
|
});
|
|
@@ -1147,19 +1296,22 @@ function useAddGroupMember() {
|
|
|
1147
1296
|
function useRemoveGroupMember() {
|
|
1148
1297
|
const { client } = useEmporix();
|
|
1149
1298
|
const resolveAuth = useCustomerAuthResolver();
|
|
1150
|
-
const qc =
|
|
1151
|
-
return
|
|
1299
|
+
const qc = useQueryClient6();
|
|
1300
|
+
return useMutation7({
|
|
1152
1301
|
mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
|
|
1153
1302
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1154
1303
|
});
|
|
1155
1304
|
}
|
|
1305
|
+
|
|
1306
|
+
// src/hooks/use-company-switcher.ts
|
|
1307
|
+
import { useCallback as useCallback3 } from "react";
|
|
1156
1308
|
function useCompanySwitcher() {
|
|
1157
1309
|
const ctx = useActiveCompany();
|
|
1158
|
-
const switchFn =
|
|
1310
|
+
const switchFn = useCallback3(
|
|
1159
1311
|
(legalEntityId) => ctx.setActiveCompany(legalEntityId),
|
|
1160
1312
|
[ctx]
|
|
1161
1313
|
);
|
|
1162
|
-
const clearFn =
|
|
1314
|
+
const clearFn = useCallback3(() => ctx.setActiveCompany(null), [ctx]);
|
|
1163
1315
|
return {
|
|
1164
1316
|
companies: ctx.myCompanies,
|
|
1165
1317
|
active: ctx.activeCompany,
|
|
@@ -1168,23 +1320,32 @@ function useCompanySwitcher() {
|
|
|
1168
1320
|
clear: clearFn
|
|
1169
1321
|
};
|
|
1170
1322
|
}
|
|
1323
|
+
|
|
1324
|
+
// src/hooks/use-cloud-functions.ts
|
|
1325
|
+
import {
|
|
1326
|
+
useMutation as useMutation8,
|
|
1327
|
+
useQuery as useQuery18
|
|
1328
|
+
} from "@tanstack/react-query";
|
|
1329
|
+
import {
|
|
1330
|
+
auth as auth15
|
|
1331
|
+
} from "@viu/emporix-sdk";
|
|
1171
1332
|
function useInvokeCloudFunction() {
|
|
1172
1333
|
const { client, storage } = useEmporix();
|
|
1173
|
-
return
|
|
1334
|
+
return useMutation8({
|
|
1174
1335
|
mutationFn: (vars) => {
|
|
1175
1336
|
const { functionId, auth: authOverride, ...options } = vars;
|
|
1176
1337
|
const token = storage.getCustomerToken();
|
|
1177
|
-
const authCtx = authOverride ?? (token ?
|
|
1338
|
+
const authCtx = authOverride ?? (token ? auth15.customer(token) : auth15.anonymous());
|
|
1178
1339
|
return client.cloudFunctions.invoke(functionId, options, authCtx);
|
|
1179
1340
|
}
|
|
1180
1341
|
});
|
|
1181
1342
|
}
|
|
1182
1343
|
function useCloudFunction(functionId, options, queryOptions) {
|
|
1183
|
-
const { client
|
|
1184
|
-
const token =
|
|
1344
|
+
const { client } = useEmporix();
|
|
1345
|
+
const token = useCustomerToken();
|
|
1185
1346
|
const { auth: authOverride, ...invokeOptions } = options ?? {};
|
|
1186
|
-
const authCtx = authOverride ?? (token ?
|
|
1187
|
-
return
|
|
1347
|
+
const authCtx = authOverride ?? (token ? auth15.customer(token) : auth15.anonymous());
|
|
1348
|
+
return useQuery18({
|
|
1188
1349
|
queryKey: emporixKey(
|
|
1189
1350
|
"cloud-function",
|
|
1190
1351
|
[functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
|
|
@@ -1199,20 +1360,24 @@ function useCloudFunction(functionId, options, queryOptions) {
|
|
|
1199
1360
|
)
|
|
1200
1361
|
});
|
|
1201
1362
|
}
|
|
1363
|
+
|
|
1364
|
+
// src/hooks/use-my-orders.ts
|
|
1365
|
+
import { useQuery as useQuery19 } from "@tanstack/react-query";
|
|
1366
|
+
import { auth as auth16 } from "@viu/emporix-sdk";
|
|
1202
1367
|
function useMyOrders(options = {}) {
|
|
1203
|
-
const { client
|
|
1368
|
+
const { client } = useEmporix();
|
|
1204
1369
|
const { activeCompany } = useActiveCompany();
|
|
1205
1370
|
const { siteCode, language } = useReadSite();
|
|
1206
|
-
const token =
|
|
1371
|
+
const token = useCustomerToken();
|
|
1207
1372
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1208
|
-
return
|
|
1373
|
+
return useQuery19({
|
|
1209
1374
|
queryKey: emporixKey(
|
|
1210
1375
|
"orders",
|
|
1211
1376
|
["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
|
|
1212
1377
|
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1213
1378
|
),
|
|
1214
1379
|
enabled: token !== null,
|
|
1215
|
-
queryFn: () => client.orders.listMine(
|
|
1380
|
+
queryFn: () => client.orders.listMine(auth16.customer(token), {
|
|
1216
1381
|
...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
|
|
1217
1382
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1218
1383
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1222,11 +1387,14 @@ function useMyOrders(options = {}) {
|
|
|
1222
1387
|
})
|
|
1223
1388
|
});
|
|
1224
1389
|
}
|
|
1390
|
+
|
|
1391
|
+
// src/hooks/use-my-orders-infinite.ts
|
|
1392
|
+
import { auth as auth17 } from "@viu/emporix-sdk";
|
|
1225
1393
|
function useMyOrdersInfinite(options = {}) {
|
|
1226
|
-
const { client
|
|
1394
|
+
const { client } = useEmporix();
|
|
1227
1395
|
const { activeCompany } = useActiveCompany();
|
|
1228
1396
|
const { siteCode, language } = useReadSite();
|
|
1229
|
-
const token =
|
|
1397
|
+
const token = useCustomerToken();
|
|
1230
1398
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1231
1399
|
return useEmporixInfinite({
|
|
1232
1400
|
queryKey: emporixKey(
|
|
@@ -1235,7 +1403,7 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1235
1403
|
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1236
1404
|
),
|
|
1237
1405
|
enabled: token !== null,
|
|
1238
|
-
fetchPage: (pageNumber) => client.orders.listMine(
|
|
1406
|
+
fetchPage: (pageNumber) => client.orders.listMine(auth17.customer(token), {
|
|
1239
1407
|
pageNumber,
|
|
1240
1408
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1241
1409
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1245,11 +1413,15 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1245
1413
|
})
|
|
1246
1414
|
});
|
|
1247
1415
|
}
|
|
1416
|
+
|
|
1417
|
+
// src/hooks/use-order.ts
|
|
1418
|
+
import { useQuery as useQuery20 } from "@tanstack/react-query";
|
|
1419
|
+
import { auth as auth18 } from "@viu/emporix-sdk";
|
|
1248
1420
|
function useOrder(orderId, options = {}) {
|
|
1249
|
-
const { client
|
|
1250
|
-
const token =
|
|
1421
|
+
const { client } = useEmporix();
|
|
1422
|
+
const token = useCustomerToken();
|
|
1251
1423
|
const { language } = useReadSite();
|
|
1252
|
-
return
|
|
1424
|
+
return useQuery20({
|
|
1253
1425
|
queryKey: emporixKey("orders", [orderId ?? null], {
|
|
1254
1426
|
tenant: client.tenant,
|
|
1255
1427
|
authKind: token ? "customer" : "anonymous",
|
|
@@ -1258,15 +1430,19 @@ function useOrder(orderId, options = {}) {
|
|
|
1258
1430
|
enabled: token !== null && orderId !== void 0,
|
|
1259
1431
|
queryFn: () => client.orders.get(
|
|
1260
1432
|
orderId,
|
|
1261
|
-
|
|
1433
|
+
auth18.customer(token),
|
|
1262
1434
|
options.saasToken ? { saasToken: options.saasToken } : {}
|
|
1263
1435
|
)
|
|
1264
1436
|
});
|
|
1265
1437
|
}
|
|
1438
|
+
|
|
1439
|
+
// 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";
|
|
1266
1442
|
function useCancelOrder() {
|
|
1267
1443
|
const { client, storage } = useEmporix();
|
|
1268
|
-
const qc =
|
|
1269
|
-
return
|
|
1444
|
+
const qc = useQueryClient7();
|
|
1445
|
+
return useMutation9({
|
|
1270
1446
|
mutationKey: ["emporix", "orders", "cancel"],
|
|
1271
1447
|
mutationFn: async (input) => {
|
|
1272
1448
|
const token = storage.getCustomerToken();
|
|
@@ -1274,7 +1450,7 @@ function useCancelOrder() {
|
|
|
1274
1450
|
const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
|
|
1275
1451
|
await client.orders.cancel(
|
|
1276
1452
|
orderId,
|
|
1277
|
-
|
|
1453
|
+
auth19.customer(token),
|
|
1278
1454
|
saasToken ? { saasToken } : {}
|
|
1279
1455
|
);
|
|
1280
1456
|
},
|
|
@@ -1283,10 +1459,14 @@ function useCancelOrder() {
|
|
|
1283
1459
|
})
|
|
1284
1460
|
});
|
|
1285
1461
|
}
|
|
1462
|
+
|
|
1463
|
+
// 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";
|
|
1286
1466
|
function useOrderTransition() {
|
|
1287
1467
|
const { client, storage } = useEmporix();
|
|
1288
|
-
const qc =
|
|
1289
|
-
return
|
|
1468
|
+
const qc = useQueryClient8();
|
|
1469
|
+
return useMutation10({
|
|
1290
1470
|
mutationKey: ["emporix", "orders", "transition"],
|
|
1291
1471
|
mutationFn: async ({ orderId, status, comment, saasToken }) => {
|
|
1292
1472
|
const token = storage.getCustomerToken();
|
|
@@ -1294,7 +1474,7 @@ function useOrderTransition() {
|
|
|
1294
1474
|
await client.orders.transition(
|
|
1295
1475
|
orderId,
|
|
1296
1476
|
status,
|
|
1297
|
-
|
|
1477
|
+
auth20.customer(token),
|
|
1298
1478
|
{
|
|
1299
1479
|
...comment !== void 0 ? { comment } : {},
|
|
1300
1480
|
...saasToken !== void 0 ? { saasToken } : {}
|
|
@@ -1306,15 +1486,19 @@ function useOrderTransition() {
|
|
|
1306
1486
|
})
|
|
1307
1487
|
});
|
|
1308
1488
|
}
|
|
1489
|
+
|
|
1490
|
+
// 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";
|
|
1309
1493
|
function useReorder() {
|
|
1310
1494
|
const { client, storage } = useEmporix();
|
|
1311
|
-
const qc =
|
|
1312
|
-
return
|
|
1495
|
+
const qc = useQueryClient9();
|
|
1496
|
+
return useMutation11({
|
|
1313
1497
|
mutationKey: ["emporix", "orders", "reorder"],
|
|
1314
1498
|
mutationFn: async ({ orderId, saasToken }) => {
|
|
1315
1499
|
const token = storage.getCustomerToken();
|
|
1316
1500
|
if (!token) throw new Error("useReorder: requires a logged-in customer");
|
|
1317
|
-
const ctx =
|
|
1501
|
+
const ctx = auth21.customer(token);
|
|
1318
1502
|
const order = await qc.fetchQuery({
|
|
1319
1503
|
queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1320
1504
|
queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
|
|
@@ -1359,10 +1543,14 @@ function useReorder() {
|
|
|
1359
1543
|
}
|
|
1360
1544
|
});
|
|
1361
1545
|
}
|
|
1546
|
+
|
|
1547
|
+
// src/hooks/use-sales-order.ts
|
|
1548
|
+
import { useQuery as useQuery21 } from "@tanstack/react-query";
|
|
1549
|
+
import "@viu/emporix-sdk";
|
|
1362
1550
|
function useSalesOrder(orderId, authCtx) {
|
|
1363
1551
|
const { client } = useEmporix();
|
|
1364
1552
|
const { language } = useReadSite();
|
|
1365
|
-
return
|
|
1553
|
+
return useQuery21({
|
|
1366
1554
|
queryKey: emporixKey("salesorders", [orderId ?? null], {
|
|
1367
1555
|
tenant: client.tenant,
|
|
1368
1556
|
authKind: authCtx?.kind ?? "anonymous",
|
|
@@ -1372,10 +1560,14 @@ function useSalesOrder(orderId, authCtx) {
|
|
|
1372
1560
|
queryFn: () => client.salesOrders.get(orderId, authCtx)
|
|
1373
1561
|
});
|
|
1374
1562
|
}
|
|
1563
|
+
|
|
1564
|
+
// src/hooks/use-update-sales-order.ts
|
|
1565
|
+
import { useMutation as useMutation12, useQueryClient as useQueryClient10 } from "@tanstack/react-query";
|
|
1566
|
+
import "@viu/emporix-sdk";
|
|
1375
1567
|
function useUpdateSalesOrder() {
|
|
1376
1568
|
const { client } = useEmporix();
|
|
1377
|
-
const qc =
|
|
1378
|
-
return
|
|
1569
|
+
const qc = useQueryClient10();
|
|
1570
|
+
return useMutation12({
|
|
1379
1571
|
mutationKey: ["emporix", "salesorders", "update"],
|
|
1380
1572
|
mutationFn: async ({ orderId, patch, auth: auth24, recalculate }) => {
|
|
1381
1573
|
if (!auth24) throw new Error("useUpdateSalesOrder: requires an auth context");
|
|
@@ -1393,11 +1585,15 @@ function useUpdateSalesOrder() {
|
|
|
1393
1585
|
}
|
|
1394
1586
|
});
|
|
1395
1587
|
}
|
|
1588
|
+
|
|
1589
|
+
// src/hooks/use-availability.ts
|
|
1590
|
+
import { useQuery as useQuery22 } from "@tanstack/react-query";
|
|
1591
|
+
import { auth as auth22 } from "@viu/emporix-sdk";
|
|
1396
1592
|
var AVAILABILITY_STALE_TIME = 3e4;
|
|
1397
1593
|
function useAvailability(productId, siteCode, options = {}) {
|
|
1398
1594
|
const { client } = useEmporix();
|
|
1399
|
-
const ctx = options.customerToken ?
|
|
1400
|
-
return
|
|
1595
|
+
const ctx = options.customerToken ? auth22.customer(options.customerToken) : auth22.anonymous();
|
|
1596
|
+
return useQuery22({
|
|
1401
1597
|
queryKey: [
|
|
1402
1598
|
"emporix",
|
|
1403
1599
|
"availability",
|
|
@@ -1416,11 +1612,15 @@ function useAvailability(productId, siteCode, options = {}) {
|
|
|
1416
1612
|
staleTime: AVAILABILITY_STALE_TIME
|
|
1417
1613
|
});
|
|
1418
1614
|
}
|
|
1615
|
+
|
|
1616
|
+
// src/hooks/use-availabilities.ts
|
|
1617
|
+
import { useQuery as useQuery23 } from "@tanstack/react-query";
|
|
1618
|
+
import { auth as auth23 } from "@viu/emporix-sdk";
|
|
1419
1619
|
var AVAILABILITY_STALE_TIME2 = 3e4;
|
|
1420
1620
|
function useAvailabilities(productIds, siteCode, options = {}) {
|
|
1421
1621
|
const { client } = useEmporix();
|
|
1422
|
-
const ctx = options.customerToken ?
|
|
1423
|
-
return
|
|
1622
|
+
const ctx = options.customerToken ? auth23.customer(options.customerToken) : auth23.anonymous();
|
|
1623
|
+
return useQuery23({
|
|
1424
1624
|
queryKey: [
|
|
1425
1625
|
"emporix",
|
|
1426
1626
|
"availabilities",
|
|
@@ -1439,29 +1639,39 @@ function useAvailabilities(productIds, siteCode, options = {}) {
|
|
|
1439
1639
|
staleTime: AVAILABILITY_STALE_TIME2
|
|
1440
1640
|
});
|
|
1441
1641
|
}
|
|
1642
|
+
|
|
1643
|
+
// src/hooks/use-coupons.ts
|
|
1644
|
+
import { useMutation as useMutation13, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
|
|
1442
1645
|
var INVALIDATE_KEY2 = ["emporix", "coupons"];
|
|
1443
1646
|
function useValidateCoupon() {
|
|
1444
1647
|
const { client } = useEmporix();
|
|
1445
1648
|
const { ctx } = useReadAuth();
|
|
1446
|
-
return
|
|
1649
|
+
return useMutation13({
|
|
1447
1650
|
mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
|
|
1448
1651
|
});
|
|
1449
1652
|
}
|
|
1450
1653
|
function useRedeemCoupon() {
|
|
1451
1654
|
const { client } = useEmporix();
|
|
1452
1655
|
const { ctx } = useReadAuth();
|
|
1453
|
-
const qc =
|
|
1454
|
-
return
|
|
1656
|
+
const qc = useQueryClient11();
|
|
1657
|
+
return useMutation13({
|
|
1455
1658
|
mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
|
|
1456
1659
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
|
|
1457
1660
|
});
|
|
1458
1661
|
}
|
|
1662
|
+
|
|
1663
|
+
// src/hooks/use-reward-points.ts
|
|
1664
|
+
import {
|
|
1665
|
+
useQuery as useQuery24,
|
|
1666
|
+
useMutation as useMutation14,
|
|
1667
|
+
useQueryClient as useQueryClient12
|
|
1668
|
+
} from "@tanstack/react-query";
|
|
1459
1669
|
var STALE = 3e4;
|
|
1460
1670
|
var INVALIDATE_KEY3 = ["emporix", "reward-points"];
|
|
1461
1671
|
function useMyRewardPoints() {
|
|
1462
1672
|
const { client } = useEmporix();
|
|
1463
1673
|
const ctx = useCustomerOnlyCtx();
|
|
1464
|
-
return
|
|
1674
|
+
return useQuery24({
|
|
1465
1675
|
queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1466
1676
|
queryFn: () => client.rewardPoints.getMyPoints(ctx),
|
|
1467
1677
|
staleTime: STALE
|
|
@@ -1470,7 +1680,7 @@ function useMyRewardPoints() {
|
|
|
1470
1680
|
function useMyRewardPointsSummary() {
|
|
1471
1681
|
const { client } = useEmporix();
|
|
1472
1682
|
const ctx = useCustomerOnlyCtx();
|
|
1473
|
-
return
|
|
1683
|
+
return useQuery24({
|
|
1474
1684
|
queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1475
1685
|
queryFn: () => client.rewardPoints.getMySummary(ctx),
|
|
1476
1686
|
staleTime: STALE
|
|
@@ -1479,7 +1689,7 @@ function useMyRewardPointsSummary() {
|
|
|
1479
1689
|
function useRedeemOptions() {
|
|
1480
1690
|
const { client } = useEmporix();
|
|
1481
1691
|
const { ctx } = useReadAuth();
|
|
1482
|
-
return
|
|
1692
|
+
return useQuery24({
|
|
1483
1693
|
queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1484
1694
|
queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
|
|
1485
1695
|
staleTime: STALE
|
|
@@ -1488,18 +1698,25 @@ function useRedeemOptions() {
|
|
|
1488
1698
|
function useRedeemRewardPoints() {
|
|
1489
1699
|
const { client } = useEmporix();
|
|
1490
1700
|
const ctx = useCustomerOnlyCtx();
|
|
1491
|
-
const qc =
|
|
1492
|
-
return
|
|
1701
|
+
const qc = useQueryClient12();
|
|
1702
|
+
return useMutation14({
|
|
1493
1703
|
mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
|
|
1494
1704
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
|
|
1495
1705
|
});
|
|
1496
1706
|
}
|
|
1707
|
+
|
|
1708
|
+
// src/hooks/use-returns.ts
|
|
1709
|
+
import {
|
|
1710
|
+
useQuery as useQuery25,
|
|
1711
|
+
useMutation as useMutation15,
|
|
1712
|
+
useQueryClient as useQueryClient13
|
|
1713
|
+
} from "@tanstack/react-query";
|
|
1497
1714
|
var STALE2 = 3e4;
|
|
1498
1715
|
var INVALIDATE_KEY4 = ["emporix", "returns"];
|
|
1499
1716
|
function useMyReturns(opts = {}) {
|
|
1500
1717
|
const { client } = useEmporix();
|
|
1501
1718
|
const ctx = useCustomerOnlyCtx();
|
|
1502
|
-
return
|
|
1719
|
+
return useQuery25({
|
|
1503
1720
|
queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1504
1721
|
queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
|
|
1505
1722
|
staleTime: STALE2
|
|
@@ -1508,7 +1725,7 @@ function useMyReturns(opts = {}) {
|
|
|
1508
1725
|
function useReturn(returnId) {
|
|
1509
1726
|
const { client } = useEmporix();
|
|
1510
1727
|
const ctx = useCustomerOnlyCtx();
|
|
1511
|
-
return
|
|
1728
|
+
return useQuery25({
|
|
1512
1729
|
queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1513
1730
|
queryFn: () => client.returns.getReturn(returnId, ctx),
|
|
1514
1731
|
enabled: Boolean(returnId),
|
|
@@ -1518,18 +1735,25 @@ function useReturn(returnId) {
|
|
|
1518
1735
|
function useCreateReturn() {
|
|
1519
1736
|
const { client } = useEmporix();
|
|
1520
1737
|
const ctx = useCustomerOnlyCtx();
|
|
1521
|
-
const qc =
|
|
1522
|
-
return
|
|
1738
|
+
const qc = useQueryClient13();
|
|
1739
|
+
return useMutation15({
|
|
1523
1740
|
mutationFn: (input) => client.returns.createReturn(input, ctx),
|
|
1524
1741
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
|
|
1525
1742
|
});
|
|
1526
1743
|
}
|
|
1744
|
+
|
|
1745
|
+
// src/hooks/use-approvals.ts
|
|
1746
|
+
import {
|
|
1747
|
+
useQuery as useQuery26,
|
|
1748
|
+
useMutation as useMutation16,
|
|
1749
|
+
useQueryClient as useQueryClient14
|
|
1750
|
+
} from "@tanstack/react-query";
|
|
1527
1751
|
var STALE3 = 3e4;
|
|
1528
1752
|
var INVALIDATE_KEY5 = ["emporix", "approvals"];
|
|
1529
1753
|
function useApprovals(opts = {}) {
|
|
1530
1754
|
const { client } = useEmporix();
|
|
1531
1755
|
const ctx = useCustomerOnlyCtx();
|
|
1532
|
-
return
|
|
1756
|
+
return useQuery26({
|
|
1533
1757
|
queryKey: emporixKey("approvals", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1534
1758
|
queryFn: () => client.approvals.listApprovals(opts.query ?? {}, ctx),
|
|
1535
1759
|
staleTime: STALE3
|
|
@@ -1538,7 +1762,7 @@ function useApprovals(opts = {}) {
|
|
|
1538
1762
|
function useApproval(approvalId) {
|
|
1539
1763
|
const { client } = useEmporix();
|
|
1540
1764
|
const ctx = useCustomerOnlyCtx();
|
|
1541
|
-
return
|
|
1765
|
+
return useQuery26({
|
|
1542
1766
|
queryKey: emporixKey("approvals", [approvalId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1543
1767
|
queryFn: () => client.approvals.getApproval(approvalId, ctx),
|
|
1544
1768
|
enabled: Boolean(approvalId),
|
|
@@ -1548,8 +1772,8 @@ function useApproval(approvalId) {
|
|
|
1548
1772
|
function useCreateApproval() {
|
|
1549
1773
|
const { client } = useEmporix();
|
|
1550
1774
|
const ctx = useCustomerOnlyCtx();
|
|
1551
|
-
const qc =
|
|
1552
|
-
return
|
|
1775
|
+
const qc = useQueryClient14();
|
|
1776
|
+
return useMutation16({
|
|
1553
1777
|
mutationFn: (input) => client.approvals.createApproval(input, ctx),
|
|
1554
1778
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
|
|
1555
1779
|
});
|
|
@@ -1557,13 +1781,103 @@ function useCreateApproval() {
|
|
|
1557
1781
|
function useUpdateApproval() {
|
|
1558
1782
|
const { client } = useEmporix();
|
|
1559
1783
|
const ctx = useCustomerOnlyCtx();
|
|
1560
|
-
const qc =
|
|
1561
|
-
return
|
|
1784
|
+
const qc = useQueryClient14();
|
|
1785
|
+
return useMutation16({
|
|
1562
1786
|
mutationFn: ({ approvalId, ops }) => client.approvals.updateApproval(approvalId, ops, ctx),
|
|
1563
1787
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
|
|
1564
1788
|
});
|
|
1565
1789
|
}
|
|
1566
1790
|
|
|
1567
|
-
export {
|
|
1568
|
-
|
|
1569
|
-
|
|
1791
|
+
export {
|
|
1792
|
+
useCustomerSession,
|
|
1793
|
+
emporixKey,
|
|
1794
|
+
useProduct,
|
|
1795
|
+
useProducts,
|
|
1796
|
+
useProductsInfinite,
|
|
1797
|
+
useProductByCode,
|
|
1798
|
+
useProductSearch,
|
|
1799
|
+
useProductNameSearch,
|
|
1800
|
+
useProductsByCodes,
|
|
1801
|
+
useShoppingLists,
|
|
1802
|
+
useCreateShoppingList,
|
|
1803
|
+
useDeleteShoppingList,
|
|
1804
|
+
useAddToShoppingList,
|
|
1805
|
+
useRemoveFromShoppingList,
|
|
1806
|
+
useSetShoppingListItemQuantity,
|
|
1807
|
+
useVariantChildren,
|
|
1808
|
+
useCategory,
|
|
1809
|
+
useSubcategories,
|
|
1810
|
+
useCategories,
|
|
1811
|
+
useCategoriesInfinite,
|
|
1812
|
+
useCategoryTree,
|
|
1813
|
+
useProductsInCategory,
|
|
1814
|
+
useProductsInCategoryInfinite,
|
|
1815
|
+
useCart,
|
|
1816
|
+
useCartMutations,
|
|
1817
|
+
useCreateCart,
|
|
1818
|
+
useActiveCart,
|
|
1819
|
+
useCheckout,
|
|
1820
|
+
usePaymentModes,
|
|
1821
|
+
useMatchPrices,
|
|
1822
|
+
useMatchPricesChunked,
|
|
1823
|
+
useProductMedia,
|
|
1824
|
+
useMySegments,
|
|
1825
|
+
useMySegmentItems,
|
|
1826
|
+
useMySegmentCategoryTree,
|
|
1827
|
+
useMySegmentProducts,
|
|
1828
|
+
useMySegmentProductsInfinite,
|
|
1829
|
+
useMySegmentCategories,
|
|
1830
|
+
useMySegmentCategoriesInfinite,
|
|
1831
|
+
useUpdateCustomer,
|
|
1832
|
+
useChangePassword,
|
|
1833
|
+
useCustomerAddresses,
|
|
1834
|
+
useAddressMutations,
|
|
1835
|
+
usePasswordReset,
|
|
1836
|
+
useSiteContext,
|
|
1837
|
+
useSites,
|
|
1838
|
+
useDefaultSite,
|
|
1839
|
+
useActiveSite,
|
|
1840
|
+
useMyCompanies,
|
|
1841
|
+
useCompany,
|
|
1842
|
+
useCompanyContacts,
|
|
1843
|
+
useCompanyLocations,
|
|
1844
|
+
useCompanyGroups,
|
|
1845
|
+
useCreateCompany,
|
|
1846
|
+
useUpdateCompany,
|
|
1847
|
+
useDeleteCompany,
|
|
1848
|
+
useAssignContact,
|
|
1849
|
+
useUpdateContactAssignment,
|
|
1850
|
+
useUnassignContact,
|
|
1851
|
+
useCreateLocation,
|
|
1852
|
+
useUpdateLocation,
|
|
1853
|
+
useDeleteLocation,
|
|
1854
|
+
useAddGroupMember,
|
|
1855
|
+
useRemoveGroupMember,
|
|
1856
|
+
useCompanySwitcher,
|
|
1857
|
+
useInvokeCloudFunction,
|
|
1858
|
+
useCloudFunction,
|
|
1859
|
+
useMyOrders,
|
|
1860
|
+
useMyOrdersInfinite,
|
|
1861
|
+
useOrder,
|
|
1862
|
+
useCancelOrder,
|
|
1863
|
+
useOrderTransition,
|
|
1864
|
+
useReorder,
|
|
1865
|
+
useSalesOrder,
|
|
1866
|
+
useUpdateSalesOrder,
|
|
1867
|
+
useAvailability,
|
|
1868
|
+
useAvailabilities,
|
|
1869
|
+
useValidateCoupon,
|
|
1870
|
+
useRedeemCoupon,
|
|
1871
|
+
useMyRewardPoints,
|
|
1872
|
+
useMyRewardPointsSummary,
|
|
1873
|
+
useRedeemOptions,
|
|
1874
|
+
useRedeemRewardPoints,
|
|
1875
|
+
useMyReturns,
|
|
1876
|
+
useReturn,
|
|
1877
|
+
useCreateReturn,
|
|
1878
|
+
useApprovals,
|
|
1879
|
+
useApproval,
|
|
1880
|
+
useCreateApproval,
|
|
1881
|
+
useUpdateApproval
|
|
1882
|
+
};
|
|
1883
|
+
//# sourceMappingURL=chunk-7F5EB5XY.js.map
|