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