@viu/emporix-sdk-react 2.13.0 → 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 +22 -0
- package/dist/{chunk-KOVOQJ5F.js → chunk-7F5EB5XY.js} +512 -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 +601 -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 +781 -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-KOVOQJ5F.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
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,132 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
20
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
CompanyContextProvider: () => CompanyContextProvider,
|
|
25
|
+
EmporixCompanyContext: () => EmporixCompanyContext,
|
|
26
|
+
EmporixErrorBoundary: () => EmporixErrorBoundary,
|
|
27
|
+
EmporixProvider: () => EmporixProvider,
|
|
28
|
+
createCookieStorage: () => createCookieStorage,
|
|
29
|
+
createLocalStorageStorage: () => createLocalStorageStorage,
|
|
30
|
+
createMemoryStorage: () => createMemoryStorage,
|
|
31
|
+
prefetchCart: () => prefetchCart,
|
|
32
|
+
prefetchOrder: () => prefetchOrder,
|
|
33
|
+
prefetchProduct: () => prefetchProduct,
|
|
34
|
+
useActiveCart: () => useActiveCart,
|
|
35
|
+
useActiveCompany: () => useActiveCompany,
|
|
36
|
+
useActiveSite: () => useActiveSite,
|
|
37
|
+
useAddGroupMember: () => useAddGroupMember,
|
|
38
|
+
useAddToShoppingList: () => useAddToShoppingList,
|
|
39
|
+
useAddressMutations: () => useAddressMutations,
|
|
40
|
+
useAssignContact: () => useAssignContact,
|
|
41
|
+
useAvailabilities: () => useAvailabilities,
|
|
42
|
+
useAvailability: () => useAvailability,
|
|
43
|
+
useCancelOrder: () => useCancelOrder,
|
|
44
|
+
useCart: () => useCart,
|
|
45
|
+
useCartMutations: () => useCartMutations,
|
|
46
|
+
useCategories: () => useCategories,
|
|
47
|
+
useCategoriesInfinite: () => useCategoriesInfinite,
|
|
48
|
+
useCategory: () => useCategory,
|
|
49
|
+
useCategoryTree: () => useCategoryTree,
|
|
50
|
+
useChangePassword: () => useChangePassword,
|
|
51
|
+
useCheckout: () => useCheckout,
|
|
52
|
+
useCloudFunction: () => useCloudFunction,
|
|
53
|
+
useCompany: () => useCompany,
|
|
54
|
+
useCompanyContacts: () => useCompanyContacts,
|
|
55
|
+
useCompanyGroups: () => useCompanyGroups,
|
|
56
|
+
useCompanyLocations: () => useCompanyLocations,
|
|
57
|
+
useCompanySwitcher: () => useCompanySwitcher,
|
|
58
|
+
useCreateCart: () => useCreateCart,
|
|
59
|
+
useCreateCompany: () => useCreateCompany,
|
|
60
|
+
useCreateLocation: () => useCreateLocation,
|
|
61
|
+
useCreateReturn: () => useCreateReturn,
|
|
62
|
+
useCreateShoppingList: () => useCreateShoppingList,
|
|
63
|
+
useCustomerAddresses: () => useCustomerAddresses,
|
|
64
|
+
useCustomerSession: () => useCustomerSession,
|
|
65
|
+
useDefaultSite: () => useDefaultSite,
|
|
66
|
+
useDeleteCompany: () => useDeleteCompany,
|
|
67
|
+
useDeleteLocation: () => useDeleteLocation,
|
|
68
|
+
useDeleteShoppingList: () => useDeleteShoppingList,
|
|
69
|
+
useEmporix: () => useEmporix,
|
|
70
|
+
useEmporixErrorHandler: () => useEmporixErrorHandler,
|
|
71
|
+
useEmporixTelemetry: () => useEmporixTelemetry,
|
|
72
|
+
useInvokeCloudFunction: () => useInvokeCloudFunction,
|
|
73
|
+
useMatchPrices: () => useMatchPrices,
|
|
74
|
+
useMatchPricesChunked: () => useMatchPricesChunked,
|
|
75
|
+
useMyCompanies: () => useMyCompanies,
|
|
76
|
+
useMyOrders: () => useMyOrders,
|
|
77
|
+
useMyOrdersInfinite: () => useMyOrdersInfinite,
|
|
78
|
+
useMyReturns: () => useMyReturns,
|
|
79
|
+
useMyRewardPoints: () => useMyRewardPoints,
|
|
80
|
+
useMyRewardPointsSummary: () => useMyRewardPointsSummary,
|
|
81
|
+
useMySegmentCategories: () => useMySegmentCategories,
|
|
82
|
+
useMySegmentCategoriesInfinite: () => useMySegmentCategoriesInfinite,
|
|
83
|
+
useMySegmentCategoryTree: () => useMySegmentCategoryTree,
|
|
84
|
+
useMySegmentItems: () => useMySegmentItems,
|
|
85
|
+
useMySegmentProducts: () => useMySegmentProducts,
|
|
86
|
+
useMySegmentProductsInfinite: () => useMySegmentProductsInfinite,
|
|
87
|
+
useMySegments: () => useMySegments,
|
|
88
|
+
useOrder: () => useOrder,
|
|
89
|
+
useOrderTransition: () => useOrderTransition,
|
|
90
|
+
usePasswordReset: () => usePasswordReset,
|
|
91
|
+
usePaymentModes: () => usePaymentModes,
|
|
92
|
+
useProduct: () => useProduct,
|
|
93
|
+
useProductByCode: () => useProductByCode,
|
|
94
|
+
useProductMedia: () => useProductMedia,
|
|
95
|
+
useProductNameSearch: () => useProductNameSearch,
|
|
96
|
+
useProductSearch: () => useProductSearch,
|
|
97
|
+
useProducts: () => useProducts,
|
|
98
|
+
useProductsByCodes: () => useProductsByCodes,
|
|
99
|
+
useProductsInCategory: () => useProductsInCategory,
|
|
100
|
+
useProductsInCategoryInfinite: () => useProductsInCategoryInfinite,
|
|
101
|
+
useProductsInfinite: () => useProductsInfinite,
|
|
102
|
+
useRedeemCoupon: () => useRedeemCoupon,
|
|
103
|
+
useRedeemOptions: () => useRedeemOptions,
|
|
104
|
+
useRedeemRewardPoints: () => useRedeemRewardPoints,
|
|
105
|
+
useRemoveFromShoppingList: () => useRemoveFromShoppingList,
|
|
106
|
+
useRemoveGroupMember: () => useRemoveGroupMember,
|
|
107
|
+
useReorder: () => useReorder,
|
|
108
|
+
useReturn: () => useReturn,
|
|
109
|
+
useSalesOrder: () => useSalesOrder,
|
|
110
|
+
useSetShoppingListItemQuantity: () => useSetShoppingListItemQuantity,
|
|
111
|
+
useShoppingLists: () => useShoppingLists,
|
|
112
|
+
useSiteContext: () => useSiteContext,
|
|
113
|
+
useSites: () => useSites,
|
|
114
|
+
useSubcategories: () => useSubcategories,
|
|
115
|
+
useUnassignContact: () => useUnassignContact,
|
|
116
|
+
useUpdateCompany: () => useUpdateCompany,
|
|
117
|
+
useUpdateContactAssignment: () => useUpdateContactAssignment,
|
|
118
|
+
useUpdateCustomer: () => useUpdateCustomer,
|
|
119
|
+
useUpdateLocation: () => useUpdateLocation,
|
|
120
|
+
useUpdateSalesOrder: () => useUpdateSalesOrder,
|
|
121
|
+
useValidateCoupon: () => useValidateCoupon,
|
|
122
|
+
useVariantChildren: () => useVariantChildren
|
|
123
|
+
});
|
|
124
|
+
module.exports = __toCommonJS(src_exports);
|
|
7
125
|
|
|
8
126
|
// src/provider.tsx
|
|
127
|
+
var import_react3 = require("react");
|
|
128
|
+
var import_react_query2 = require("@tanstack/react-query");
|
|
129
|
+
var import_emporix_sdk2 = require("@viu/emporix-sdk");
|
|
9
130
|
|
|
10
131
|
// src/storage/local-storage.ts
|
|
11
132
|
var DEFAULT_TOKEN_KEY = "emporix.customerToken";
|
|
@@ -88,7 +209,7 @@ var REFRESH_NAME = "emporix.refreshToken";
|
|
|
88
209
|
function createCookieStorage(opts = {}) {
|
|
89
210
|
const tokenName = opts.name ?? DEFAULT_TOKEN_NAME;
|
|
90
211
|
const sameSite = opts.sameSite ?? "lax";
|
|
91
|
-
const secure = opts.secure ??
|
|
212
|
+
const secure = opts.secure ?? (typeof location !== "undefined" && location.protocol === "https:");
|
|
92
213
|
if (typeof document === "undefined") {
|
|
93
214
|
console.warn("[emporix] document unavailable; cookie storage falling back to in-memory");
|
|
94
215
|
return createMemoryStorage();
|
|
@@ -234,14 +355,23 @@ function createMemoryStorage(opts = {}) {
|
|
|
234
355
|
subscribeAll: (l) => all.add(l)
|
|
235
356
|
};
|
|
236
357
|
}
|
|
237
|
-
|
|
358
|
+
|
|
359
|
+
// src/telemetry.ts
|
|
360
|
+
var import_react = require("react");
|
|
361
|
+
var EmporixTelemetryContext = (0, import_react.createContext)(null);
|
|
238
362
|
function useEmporixTelemetry() {
|
|
239
|
-
const ctx =
|
|
363
|
+
const ctx = (0, import_react.useContext)(EmporixTelemetryContext);
|
|
240
364
|
if (!ctx) {
|
|
241
365
|
throw new Error("useEmporixTelemetry must be used within an EmporixProvider");
|
|
242
366
|
}
|
|
243
367
|
return ctx;
|
|
244
368
|
}
|
|
369
|
+
|
|
370
|
+
// src/company-context.tsx
|
|
371
|
+
var import_react2 = require("react");
|
|
372
|
+
var import_react_query = require("@tanstack/react-query");
|
|
373
|
+
var import_emporix_sdk = require("@viu/emporix-sdk");
|
|
374
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
245
375
|
var NULL_CTX = {
|
|
246
376
|
activeCompany: null,
|
|
247
377
|
myCompanies: [],
|
|
@@ -254,9 +384,9 @@ var NULL_CTX = {
|
|
|
254
384
|
refetchMyCompanies: async () => {
|
|
255
385
|
}
|
|
256
386
|
};
|
|
257
|
-
var EmporixCompanyContext =
|
|
387
|
+
var EmporixCompanyContext = (0, import_react2.createContext)(NULL_CTX);
|
|
258
388
|
function useActiveCompany() {
|
|
259
|
-
return
|
|
389
|
+
return (0, import_react2.useContext)(EmporixCompanyContext);
|
|
260
390
|
}
|
|
261
391
|
function CompanyContextProvider({
|
|
262
392
|
client,
|
|
@@ -264,83 +394,103 @@ function CompanyContextProvider({
|
|
|
264
394
|
initialActiveLegalEntityId,
|
|
265
395
|
children
|
|
266
396
|
}) {
|
|
267
|
-
const qc =
|
|
397
|
+
const qc = (0, import_react_query.useQueryClient)();
|
|
268
398
|
const { emit } = useEmporixTelemetry();
|
|
269
|
-
const [myCompanies, setMyCompanies] =
|
|
270
|
-
const [activeCompany, setActive] =
|
|
271
|
-
const [status, setStatus] =
|
|
272
|
-
const [error, setError] =
|
|
273
|
-
const activeRef =
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
storage.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
)
|
|
399
|
+
const [myCompanies, setMyCompanies] = (0, import_react2.useState)([]);
|
|
400
|
+
const [activeCompany, setActive] = (0, import_react2.useState)(null);
|
|
401
|
+
const [status, setStatus] = (0, import_react2.useState)("idle");
|
|
402
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
403
|
+
const activeRef = (0, import_react2.useRef)(null);
|
|
404
|
+
(0, import_react2.useEffect)(() => {
|
|
405
|
+
activeRef.current = activeCompany;
|
|
406
|
+
}, [activeCompany]);
|
|
407
|
+
const switchChain = (0, import_react2.useRef)(Promise.resolve());
|
|
408
|
+
const switchTo = (0, import_react2.useCallback)(
|
|
409
|
+
(target) => {
|
|
410
|
+
const run = async () => {
|
|
411
|
+
const start = Date.now();
|
|
412
|
+
const from = activeRef.current?.id ?? null;
|
|
413
|
+
const refreshToken = storage.getRefreshToken();
|
|
414
|
+
const token = storage.getCustomerToken();
|
|
415
|
+
if (!refreshToken || !token) {
|
|
416
|
+
setActive(target);
|
|
417
|
+
storage.setActiveLegalEntityId(target?.id ?? null);
|
|
418
|
+
} else {
|
|
419
|
+
const next = await client.customers.refresh({
|
|
420
|
+
refreshToken,
|
|
421
|
+
...target ? { legalEntityId: target.id } : {}
|
|
422
|
+
});
|
|
423
|
+
storage.setCustomerToken(next.customerToken);
|
|
424
|
+
if (next.refreshToken) storage.setRefreshToken(next.refreshToken);
|
|
425
|
+
storage.setCartId(null);
|
|
426
|
+
storage.setActiveLegalEntityId(target?.id ?? null);
|
|
427
|
+
setActive(target);
|
|
428
|
+
qc.invalidateQueries({
|
|
429
|
+
predicate: (q) => Array.isArray(q.queryKey) && q.queryKey.some(
|
|
430
|
+
(k) => k === "cart" || k === "companies" || k === "customer" || k === from || target !== null && k === target.id
|
|
431
|
+
)
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
emit({
|
|
435
|
+
type: "company:switched",
|
|
436
|
+
from,
|
|
437
|
+
to: target?.id ?? null,
|
|
438
|
+
durationMs: Date.now() - start
|
|
298
439
|
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
from,
|
|
303
|
-
to: target?.id ?? null,
|
|
304
|
-
durationMs: Date.now() - start
|
|
440
|
+
};
|
|
441
|
+
const task = switchChain.current.then(run, run);
|
|
442
|
+
switchChain.current = task.catch(() => {
|
|
305
443
|
});
|
|
444
|
+
return task;
|
|
306
445
|
},
|
|
307
446
|
[client, storage, qc, emit]
|
|
308
447
|
);
|
|
309
|
-
const load =
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
setStatus("loading");
|
|
318
|
-
try {
|
|
319
|
-
const companies = await client.companies.listMine(emporixSdk.auth.customer(token));
|
|
320
|
-
setMyCompanies(companies);
|
|
321
|
-
const persisted = initialActiveLegalEntityId ?? storage.getActiveLegalEntityId();
|
|
322
|
-
const matched = persisted ? companies.find((c) => c.id === persisted) ?? null : null;
|
|
323
|
-
if (matched) {
|
|
324
|
-
setActive(matched);
|
|
325
|
-
if (storage.getActiveLegalEntityId() !== matched.id) {
|
|
326
|
-
storage.setActiveLegalEntityId(matched.id ?? null);
|
|
327
|
-
}
|
|
328
|
-
} else if (companies.length === 1) {
|
|
329
|
-
await switchTo(companies[0] ?? null);
|
|
330
|
-
} else {
|
|
448
|
+
const load = (0, import_react2.useCallback)(
|
|
449
|
+
async (signal) => {
|
|
450
|
+
const token = storage.getCustomerToken();
|
|
451
|
+
if (!token) {
|
|
452
|
+
if (signal?.cancelled) return;
|
|
453
|
+
setMyCompanies([]);
|
|
331
454
|
setActive(null);
|
|
332
|
-
|
|
455
|
+
setStatus("idle");
|
|
456
|
+
return;
|
|
333
457
|
}
|
|
334
|
-
setStatus("
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
458
|
+
setStatus("loading");
|
|
459
|
+
try {
|
|
460
|
+
const companies = await client.companies.listMine(import_emporix_sdk.auth.customer(token));
|
|
461
|
+
if (signal?.cancelled) return;
|
|
462
|
+
setMyCompanies(companies);
|
|
463
|
+
const persisted = initialActiveLegalEntityId ?? storage.getActiveLegalEntityId();
|
|
464
|
+
const matched = persisted ? companies.find((c) => c.id === persisted) ?? null : null;
|
|
465
|
+
if (matched) {
|
|
466
|
+
setActive(matched);
|
|
467
|
+
if (storage.getActiveLegalEntityId() !== matched.id) {
|
|
468
|
+
storage.setActiveLegalEntityId(matched.id ?? null);
|
|
469
|
+
}
|
|
470
|
+
} else if (companies.length === 1) {
|
|
471
|
+
await switchTo(companies[0] ?? null);
|
|
472
|
+
} else {
|
|
473
|
+
setActive(null);
|
|
474
|
+
if (persisted && !matched) storage.setActiveLegalEntityId(null);
|
|
475
|
+
}
|
|
476
|
+
if (signal?.cancelled) return;
|
|
477
|
+
setStatus("idle");
|
|
478
|
+
} catch (e) {
|
|
479
|
+
if (signal?.cancelled) return;
|
|
480
|
+
setError(e);
|
|
481
|
+
setStatus("error");
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
[client, storage, initialActiveLegalEntityId, switchTo]
|
|
485
|
+
);
|
|
486
|
+
(0, import_react2.useEffect)(() => {
|
|
487
|
+
const signal = { cancelled: false };
|
|
488
|
+
void load(signal);
|
|
489
|
+
return () => {
|
|
490
|
+
signal.cancelled = true;
|
|
491
|
+
};
|
|
342
492
|
}, [load]);
|
|
343
|
-
|
|
493
|
+
(0, import_react2.useEffect)(() => {
|
|
344
494
|
let prev = storage.getCustomerToken();
|
|
345
495
|
return storage.subscribe?.((next) => {
|
|
346
496
|
const becameAuth = !prev && next;
|
|
@@ -349,7 +499,7 @@ function CompanyContextProvider({
|
|
|
349
499
|
if (becameAuth || becameUnauth) void load();
|
|
350
500
|
});
|
|
351
501
|
}, [storage, load]);
|
|
352
|
-
const setActiveCompany =
|
|
502
|
+
const setActiveCompany = (0, import_react2.useCallback)(
|
|
353
503
|
async (legalEntityId) => {
|
|
354
504
|
setStatus("switching");
|
|
355
505
|
try {
|
|
@@ -369,7 +519,7 @@ function CompanyContextProvider({
|
|
|
369
519
|
},
|
|
370
520
|
[myCompanies, switchTo]
|
|
371
521
|
);
|
|
372
|
-
const value =
|
|
522
|
+
const value = (0, import_react2.useMemo)(() => {
|
|
373
523
|
const mode = activeCompany ? "b2b" : myCompanies.length > 1 ? "unresolved" : "b2c";
|
|
374
524
|
return {
|
|
375
525
|
activeCompany,
|
|
@@ -381,10 +531,13 @@ function CompanyContextProvider({
|
|
|
381
531
|
refetchMyCompanies: load
|
|
382
532
|
};
|
|
383
533
|
}, [activeCompany, myCompanies, status, error, setActiveCompany, load]);
|
|
384
|
-
return /* @__PURE__ */
|
|
534
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmporixCompanyContext.Provider, { value, children });
|
|
385
535
|
}
|
|
386
|
-
|
|
387
|
-
|
|
536
|
+
|
|
537
|
+
// src/provider.tsx
|
|
538
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
539
|
+
var EmporixContext = (0, import_react3.createContext)(null);
|
|
540
|
+
var EmporixSiteContext = (0, import_react3.createContext)(null);
|
|
388
541
|
var DEFAULT_QUERY_OPTIONS = {
|
|
389
542
|
staleTime: 3e4,
|
|
390
543
|
refetchOnWindowFocus: false,
|
|
@@ -403,27 +556,35 @@ function EmporixProvider({
|
|
|
403
556
|
onCustomerSessionExpired,
|
|
404
557
|
children
|
|
405
558
|
}) {
|
|
406
|
-
const value =
|
|
559
|
+
const value = (0, import_react3.useMemo)(() => {
|
|
407
560
|
const s = storage ?? createMemoryStorage(
|
|
408
561
|
initialCustomerToken !== void 0 ? { initial: initialCustomerToken } : {}
|
|
409
562
|
);
|
|
410
|
-
if (initialCustomerToken && storage && storage.getCustomerToken() === null) {
|
|
411
|
-
storage.setCustomerToken(initialCustomerToken);
|
|
412
|
-
}
|
|
413
563
|
return { client, storage: s };
|
|
414
564
|
}, [client, storage, initialCustomerToken]);
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
)
|
|
419
|
-
|
|
565
|
+
const [fallbackQc] = (0, import_react3.useState)(() => new import_react_query2.QueryClient());
|
|
566
|
+
const qc = queryClient ?? fallbackQc;
|
|
567
|
+
const defaultsRef = (0, import_react3.useRef)(null);
|
|
568
|
+
if (defaultsRef.current !== qc) {
|
|
569
|
+
qc.setQueryDefaults(["emporix"], {
|
|
570
|
+
...DEFAULT_QUERY_OPTIONS,
|
|
571
|
+
...qc.getDefaultOptions().queries,
|
|
572
|
+
...qc.getQueryDefaults(["emporix"])
|
|
573
|
+
});
|
|
574
|
+
defaultsRef.current = qc;
|
|
575
|
+
}
|
|
576
|
+
const wiredRef = (0, import_react3.useRef)(null);
|
|
577
|
+
if (wiredRef.current?.client !== client || wiredRef.current?.storage !== value.storage) {
|
|
420
578
|
client.tokenProvider.attachAnonymousStore?.({
|
|
421
579
|
read: () => value.storage.getAnonymousSession(),
|
|
422
580
|
write: (s) => value.storage.setAnonymousSession(s)
|
|
423
581
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
582
|
+
if (initialCustomerToken && storage && storage.getCustomerToken() === null) {
|
|
583
|
+
storage.setCustomerToken(initialCustomerToken);
|
|
584
|
+
}
|
|
585
|
+
wiredRef.current = { client, storage: value.storage };
|
|
586
|
+
}
|
|
587
|
+
const safeEmit = (0, import_react3.useCallback)(
|
|
427
588
|
(event) => {
|
|
428
589
|
if (!onTelemetry) return;
|
|
429
590
|
try {
|
|
@@ -434,8 +595,8 @@ function EmporixProvider({
|
|
|
434
595
|
},
|
|
435
596
|
[onTelemetry]
|
|
436
597
|
);
|
|
437
|
-
const telemetryValue =
|
|
438
|
-
|
|
598
|
+
const telemetryValue = (0, import_react3.useMemo)(() => ({ emit: safeEmit }), [safeEmit]);
|
|
599
|
+
(0, import_react3.useEffect)(() => {
|
|
439
600
|
if (!onTelemetry) return;
|
|
440
601
|
const startedAt = /* @__PURE__ */ new Map();
|
|
441
602
|
const unsubQuery = qc.getQueryCache().subscribe((event) => {
|
|
@@ -514,7 +675,7 @@ function EmporixProvider({
|
|
|
514
675
|
unsubStorage?.();
|
|
515
676
|
};
|
|
516
677
|
}, [qc, onTelemetry, client, value.storage, safeEmit]);
|
|
517
|
-
|
|
678
|
+
(0, import_react3.useEffect)(() => {
|
|
518
679
|
if (!autoRefreshCustomerToken) return;
|
|
519
680
|
const storage2 = value.storage;
|
|
520
681
|
client.setCustomerTokenRefresher({
|
|
@@ -544,14 +705,14 @@ function EmporixProvider({
|
|
|
544
705
|
});
|
|
545
706
|
return () => client.setCustomerTokenRefresher(null);
|
|
546
707
|
}, [autoRefreshCustomerToken, client, value.storage, safeEmit, onCustomerSessionExpired]);
|
|
547
|
-
return /* @__PURE__ */
|
|
708
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmporixContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmporixTelemetryContext.Provider, { value: telemetryValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_query2.QueryClientProvider, { client: qc, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
548
709
|
SiteContextProvider,
|
|
549
710
|
{
|
|
550
711
|
client,
|
|
551
712
|
storage: value.storage,
|
|
552
713
|
...initialSiteCode !== void 0 ? { initialSiteCode } : {},
|
|
553
714
|
...initialLanguage !== void 0 ? { initialLanguage } : {},
|
|
554
|
-
children: /* @__PURE__ */
|
|
715
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
555
716
|
CompanyContextProvider,
|
|
556
717
|
{
|
|
557
718
|
client,
|
|
@@ -570,30 +731,30 @@ function SiteContextProvider({
|
|
|
570
731
|
initialLanguage,
|
|
571
732
|
children
|
|
572
733
|
}) {
|
|
573
|
-
const qc =
|
|
574
|
-
const [siteCode, setSiteCodeState] =
|
|
734
|
+
const qc = (0, import_react_query2.useQueryClient)();
|
|
735
|
+
const [siteCode, setSiteCodeState] = (0, import_react3.useState)(() => {
|
|
575
736
|
if (initialSiteCode !== void 0) return initialSiteCode;
|
|
576
737
|
const fromStorage = storage.getSiteCode();
|
|
577
738
|
if (fromStorage !== null) return fromStorage;
|
|
578
739
|
return client.config?.credentials?.storefront?.context?.siteCode ?? null;
|
|
579
740
|
});
|
|
580
|
-
const [currency, setCurrencyState] =
|
|
741
|
+
const [currency, setCurrencyState] = (0, import_react3.useState)(
|
|
581
742
|
() => client.config?.credentials?.storefront?.context?.currency ?? null
|
|
582
743
|
);
|
|
583
|
-
const [language, setLanguageState] =
|
|
744
|
+
const [language, setLanguageState] = (0, import_react3.useState)(() => {
|
|
584
745
|
if (initialLanguage !== void 0) return initialLanguage;
|
|
585
746
|
const fromStorage = storage.getLanguage();
|
|
586
747
|
if (fromStorage !== null) return fromStorage;
|
|
587
748
|
return client.config?.credentials?.storefront?.context?.language ?? null;
|
|
588
749
|
});
|
|
589
|
-
const [targetLocation, setTargetLocation] =
|
|
590
|
-
const [isSwitching, setIsSwitching] =
|
|
591
|
-
const [switchError, setSwitchError] =
|
|
592
|
-
|
|
750
|
+
const [targetLocation, setTargetLocation] = (0, import_react3.useState)(null);
|
|
751
|
+
const [isSwitching, setIsSwitching] = (0, import_react3.useState)(false);
|
|
752
|
+
const [switchError, setSwitchError] = (0, import_react3.useState)(null);
|
|
753
|
+
(0, import_react3.useEffect)(() => {
|
|
593
754
|
if (!siteCode || currency !== null && targetLocation !== null && language !== null) return;
|
|
594
755
|
let cancelled = false;
|
|
595
756
|
const token = storage.getCustomerToken();
|
|
596
|
-
const authCtx = token ?
|
|
757
|
+
const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
|
|
597
758
|
qc.fetchQuery({
|
|
598
759
|
queryKey: [
|
|
599
760
|
"emporix",
|
|
@@ -617,10 +778,10 @@ function SiteContextProvider({
|
|
|
617
778
|
cancelled = true;
|
|
618
779
|
};
|
|
619
780
|
}, [siteCode]);
|
|
620
|
-
|
|
781
|
+
(0, import_react3.useEffect)(() => {
|
|
621
782
|
if (language) client.setStorefrontContext({ language });
|
|
622
783
|
}, []);
|
|
623
|
-
const setSite =
|
|
784
|
+
const setSite = (0, import_react3.useCallback)(
|
|
624
785
|
async (code) => {
|
|
625
786
|
storage.setSiteCode(code);
|
|
626
787
|
storage.setCartId(null);
|
|
@@ -635,7 +796,7 @@ function SiteContextProvider({
|
|
|
635
796
|
setIsSwitching(true);
|
|
636
797
|
try {
|
|
637
798
|
const token = storage.getCustomerToken();
|
|
638
|
-
const authCtx = token ?
|
|
799
|
+
const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
|
|
639
800
|
const site = await qc.fetchQuery({
|
|
640
801
|
queryKey: [
|
|
641
802
|
"emporix",
|
|
@@ -670,7 +831,7 @@ function SiteContextProvider({
|
|
|
670
831
|
},
|
|
671
832
|
[client, storage, qc, language]
|
|
672
833
|
);
|
|
673
|
-
const setCurrency =
|
|
834
|
+
const setCurrency = (0, import_react3.useCallback)(
|
|
674
835
|
async (next) => {
|
|
675
836
|
storage.setCartId(null);
|
|
676
837
|
setCurrencyState(next);
|
|
@@ -680,7 +841,7 @@ function SiteContextProvider({
|
|
|
680
841
|
setIsSwitching(true);
|
|
681
842
|
try {
|
|
682
843
|
const token = storage.getCustomerToken();
|
|
683
|
-
const authCtx = token ?
|
|
844
|
+
const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
|
|
684
845
|
await client.sessionContext.patch(
|
|
685
846
|
{ currency: next, ...siteCode ? { siteCode } : {} },
|
|
686
847
|
authCtx
|
|
@@ -693,7 +854,7 @@ function SiteContextProvider({
|
|
|
693
854
|
},
|
|
694
855
|
[client, storage, qc, siteCode]
|
|
695
856
|
);
|
|
696
|
-
const setLanguage =
|
|
857
|
+
const setLanguage = (0, import_react3.useCallback)(
|
|
697
858
|
async (next) => {
|
|
698
859
|
storage.setLanguage(next);
|
|
699
860
|
setLanguageState(next);
|
|
@@ -703,7 +864,7 @@ function SiteContextProvider({
|
|
|
703
864
|
setIsSwitching(true);
|
|
704
865
|
try {
|
|
705
866
|
const token = storage.getCustomerToken();
|
|
706
|
-
const authCtx = token ?
|
|
867
|
+
const authCtx = token ? import_emporix_sdk2.auth.customer(token) : import_emporix_sdk2.auth.anonymous();
|
|
707
868
|
await client.sessionContext.patch(
|
|
708
869
|
{ language: next, ...siteCode ? { siteCode } : {} },
|
|
709
870
|
authCtx
|
|
@@ -716,7 +877,7 @@ function SiteContextProvider({
|
|
|
716
877
|
},
|
|
717
878
|
[client, storage, qc, siteCode]
|
|
718
879
|
);
|
|
719
|
-
const value =
|
|
880
|
+
const value = (0, import_react3.useMemo)(
|
|
720
881
|
() => ({
|
|
721
882
|
siteCode,
|
|
722
883
|
currency,
|
|
@@ -730,14 +891,19 @@ function SiteContextProvider({
|
|
|
730
891
|
}),
|
|
731
892
|
[siteCode, currency, targetLocation, language, setSite, setCurrency, setLanguage, isSwitching, switchError]
|
|
732
893
|
);
|
|
733
|
-
return /* @__PURE__ */
|
|
894
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EmporixSiteContext.Provider, { value, children });
|
|
734
895
|
}
|
|
735
896
|
function useEmporix() {
|
|
736
|
-
const ctx =
|
|
897
|
+
const ctx = (0, import_react3.useContext)(EmporixContext);
|
|
737
898
|
if (!ctx) throw new Error("useEmporix must be used within an EmporixProvider");
|
|
738
899
|
return ctx;
|
|
739
900
|
}
|
|
740
901
|
|
|
902
|
+
// src/hooks/use-customer-session.ts
|
|
903
|
+
var import_react4 = require("react");
|
|
904
|
+
var import_react_query3 = require("@tanstack/react-query");
|
|
905
|
+
var import_emporix_sdk3 = require("@viu/emporix-sdk");
|
|
906
|
+
|
|
741
907
|
// src/hooks/internal/bootstrap-cart.ts
|
|
742
908
|
async function bootstrapCart(opts) {
|
|
743
909
|
return opts.qc.fetchQuery({
|
|
@@ -790,6 +956,9 @@ function getCustomerSessionStore(storage) {
|
|
|
790
956
|
};
|
|
791
957
|
}
|
|
792
958
|
};
|
|
959
|
+
storage.subscribe?.((t) => {
|
|
960
|
+
store.setState((s) => s.token === t ? s : { ...s, token: t });
|
|
961
|
+
});
|
|
793
962
|
stores.set(storage, store);
|
|
794
963
|
return store;
|
|
795
964
|
}
|
|
@@ -802,27 +971,25 @@ var EMPTY_SESSION = {
|
|
|
802
971
|
};
|
|
803
972
|
function useCustomerSession() {
|
|
804
973
|
const { client, storage } = useEmporix();
|
|
805
|
-
const qc =
|
|
806
|
-
const siteCtx =
|
|
807
|
-
const store =
|
|
808
|
-
const session =
|
|
974
|
+
const qc = (0, import_react_query3.useQueryClient)();
|
|
975
|
+
const siteCtx = (0, import_react4.useContext)(EmporixSiteContext);
|
|
976
|
+
const store = (0, import_react4.useMemo)(() => getCustomerSessionStore(storage), [storage]);
|
|
977
|
+
const session = (0, import_react4.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
809
978
|
const setSession = store.setState;
|
|
810
|
-
|
|
811
|
-
return storage.subscribe?.((t) => setSession((s) => ({ ...s, token: t })));
|
|
812
|
-
}, [storage, setSession]);
|
|
813
|
-
const meQuery = reactQuery.useQuery({
|
|
979
|
+
const meQuery = (0, import_react_query3.useQuery)({
|
|
814
980
|
queryKey: ["emporix", "customer", "me", { tenant: client.tenant, hasToken: session.token !== null }],
|
|
815
981
|
enabled: session.token !== null,
|
|
816
|
-
queryFn: () => client.customers.me(
|
|
982
|
+
queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(session.token)),
|
|
817
983
|
// 30s — matches Balanced default. Lets honourPreferredSite's fetchQuery
|
|
818
984
|
// (with staleTime: Infinity) reuse the cache instead of refetching.
|
|
819
985
|
staleTime: 3e4
|
|
820
986
|
});
|
|
821
|
-
const login =
|
|
987
|
+
const login = (0, import_react4.useCallback)(
|
|
822
988
|
async (input) => {
|
|
823
989
|
const result = await client.customers.login(input);
|
|
824
990
|
storage.setCustomerToken(result.customerToken);
|
|
825
991
|
storage.setRefreshToken(result.refreshToken || null);
|
|
992
|
+
storage.setAnonymousSession(null);
|
|
826
993
|
setSession({
|
|
827
994
|
token: result.customerToken,
|
|
828
995
|
refreshToken: result.refreshToken || null,
|
|
@@ -845,16 +1012,17 @@ function useCustomerSession() {
|
|
|
845
1012
|
},
|
|
846
1013
|
[client, storage, qc, siteCtx, setSession]
|
|
847
1014
|
);
|
|
848
|
-
const signup =
|
|
1015
|
+
const signup = (0, import_react4.useCallback)(
|
|
849
1016
|
async (input) => {
|
|
850
1017
|
await client.customers.signup(input);
|
|
851
1018
|
},
|
|
852
1019
|
[client]
|
|
853
1020
|
);
|
|
854
|
-
const applySession =
|
|
1021
|
+
const applySession = (0, import_react4.useCallback)(
|
|
855
1022
|
async (incoming) => {
|
|
856
1023
|
storage.setCustomerToken(incoming.customerToken);
|
|
857
1024
|
storage.setRefreshToken(incoming.refreshToken || null);
|
|
1025
|
+
storage.setAnonymousSession(null);
|
|
858
1026
|
setSession({
|
|
859
1027
|
token: incoming.customerToken,
|
|
860
1028
|
refreshToken: incoming.refreshToken || null,
|
|
@@ -877,22 +1045,22 @@ function useCustomerSession() {
|
|
|
877
1045
|
},
|
|
878
1046
|
[client, storage, qc, siteCtx, setSession]
|
|
879
1047
|
);
|
|
880
|
-
const socialLogin =
|
|
1048
|
+
const socialLogin = (0, import_react4.useCallback)(
|
|
881
1049
|
async (input) => {
|
|
882
1050
|
await applySession(await client.customers.socialLogin(input));
|
|
883
1051
|
},
|
|
884
1052
|
[client, applySession]
|
|
885
1053
|
);
|
|
886
|
-
const exchangeToken =
|
|
1054
|
+
const exchangeToken = (0, import_react4.useCallback)(
|
|
887
1055
|
async (input) => {
|
|
888
1056
|
await applySession(await client.customers.exchangeToken(input));
|
|
889
1057
|
},
|
|
890
1058
|
[client, applySession]
|
|
891
1059
|
);
|
|
892
|
-
const logout =
|
|
1060
|
+
const logout = (0, import_react4.useCallback)(async () => {
|
|
893
1061
|
if (session.token) {
|
|
894
1062
|
try {
|
|
895
|
-
await client.customers.logout(
|
|
1063
|
+
await client.customers.logout(import_emporix_sdk3.auth.customer(session.token));
|
|
896
1064
|
} catch {
|
|
897
1065
|
}
|
|
898
1066
|
}
|
|
@@ -901,13 +1069,12 @@ function useCustomerSession() {
|
|
|
901
1069
|
storage.setActiveLegalEntityId(null);
|
|
902
1070
|
storage.setCartId(null);
|
|
903
1071
|
setSession(EMPTY_SESSION);
|
|
904
|
-
qc.removeQueries({ queryKey: ["emporix"
|
|
905
|
-
qc.removeQueries({ queryKey: ["emporix", "cart"] });
|
|
1072
|
+
qc.removeQueries({ queryKey: ["emporix"] });
|
|
906
1073
|
}, [client, session.token, storage, qc, setSession]);
|
|
907
|
-
const refresh =
|
|
1074
|
+
const refresh = (0, import_react4.useCallback)(async () => {
|
|
908
1075
|
await meQuery.refetch();
|
|
909
1076
|
}, [meQuery]);
|
|
910
|
-
const refreshSession =
|
|
1077
|
+
const refreshSession = (0, import_react4.useCallback)(async () => {
|
|
911
1078
|
if (!session.refreshToken) return;
|
|
912
1079
|
const refreshed = await client.customers.refresh({
|
|
913
1080
|
refreshToken: session.refreshToken,
|
|
@@ -950,7 +1117,7 @@ async function honourPreferredSite(opts) {
|
|
|
950
1117
|
"me",
|
|
951
1118
|
{ tenant: client.tenant, hasToken: true }
|
|
952
1119
|
],
|
|
953
|
-
queryFn: () => client.customers.me(
|
|
1120
|
+
queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(customerToken)),
|
|
954
1121
|
// Reuse whatever meQuery already wrote (login flow runs meQuery in
|
|
955
1122
|
// parallel). Without this, fetchQuery refetches if meQuery's data is
|
|
956
1123
|
// already stale (default staleTime: 0 on meQuery).
|
|
@@ -967,7 +1134,7 @@ async function onboardCustomerCart(opts) {
|
|
|
967
1134
|
const { qc, client, storage, customerToken } = opts;
|
|
968
1135
|
const siteCode = client.config?.credentials?.storefront?.context?.siteCode;
|
|
969
1136
|
if (!siteCode) return;
|
|
970
|
-
const ctx =
|
|
1137
|
+
const ctx = import_emporix_sdk3.auth.customer(customerToken);
|
|
971
1138
|
try {
|
|
972
1139
|
const customerCart = await bootstrapCart({
|
|
973
1140
|
qc,
|
|
@@ -985,22 +1152,53 @@ async function onboardCustomerCart(opts) {
|
|
|
985
1152
|
} catch {
|
|
986
1153
|
}
|
|
987
1154
|
}
|
|
988
|
-
|
|
1155
|
+
|
|
1156
|
+
// src/hooks/use-products.ts
|
|
1157
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
1158
|
+
var import_emporix_sdk5 = require("@viu/emporix-sdk");
|
|
1159
|
+
|
|
1160
|
+
// src/hooks/internal/use-read-auth.ts
|
|
1161
|
+
var import_emporix_sdk4 = require("@viu/emporix-sdk");
|
|
1162
|
+
|
|
1163
|
+
// src/hooks/internal/use-storage-snapshot.ts
|
|
1164
|
+
var import_react5 = require("react");
|
|
1165
|
+
function useCustomerToken() {
|
|
989
1166
|
const { storage } = useEmporix();
|
|
1167
|
+
const store = (0, import_react5.useMemo)(() => getCustomerSessionStore(storage), [storage]);
|
|
1168
|
+
const getToken = (0, import_react5.useCallback)(() => store.getSnapshot().token, [store]);
|
|
1169
|
+
return (0, import_react5.useSyncExternalStore)(store.subscribe, getToken, getToken);
|
|
1170
|
+
}
|
|
1171
|
+
function useCartId() {
|
|
1172
|
+
const { storage } = useEmporix();
|
|
1173
|
+
const subscribe = (0, import_react5.useCallback)(
|
|
1174
|
+
(onChange) => storage.subscribeAll?.((key) => {
|
|
1175
|
+
if (key === "cartId") onChange();
|
|
1176
|
+
}) ?? (() => {
|
|
1177
|
+
}),
|
|
1178
|
+
[storage]
|
|
1179
|
+
);
|
|
1180
|
+
const getCartId = (0, import_react5.useCallback)(() => storage.getCartId(), [storage]);
|
|
1181
|
+
return (0, import_react5.useSyncExternalStore)(subscribe, getCartId, getCartId);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// src/hooks/internal/use-read-auth.ts
|
|
1185
|
+
function useReadAuth(override) {
|
|
1186
|
+
const token = useCustomerToken();
|
|
990
1187
|
if (override) return { ctx: override };
|
|
991
|
-
|
|
992
|
-
return token ? { ctx: emporixSdk.auth.customer(token) } : { ctx: emporixSdk.auth.anonymous() };
|
|
1188
|
+
return token ? { ctx: import_emporix_sdk4.auth.customer(token) } : { ctx: import_emporix_sdk4.auth.anonymous() };
|
|
993
1189
|
}
|
|
994
1190
|
function useCustomerOnlyCtx() {
|
|
995
|
-
const
|
|
996
|
-
const token = storage.getCustomerToken();
|
|
1191
|
+
const token = useCustomerToken();
|
|
997
1192
|
if (!token) {
|
|
998
1193
|
throw new Error("Requires a logged-in customer (no token in storage)");
|
|
999
1194
|
}
|
|
1000
|
-
return
|
|
1195
|
+
return import_emporix_sdk4.auth.customer(token);
|
|
1001
1196
|
}
|
|
1197
|
+
|
|
1198
|
+
// src/hooks/internal/use-read-site.ts
|
|
1199
|
+
var import_react6 = require("react");
|
|
1002
1200
|
function useReadSite() {
|
|
1003
|
-
const ctx =
|
|
1201
|
+
const ctx = (0, import_react6.useContext)(EmporixSiteContext);
|
|
1004
1202
|
return { siteCode: ctx?.siteCode ?? null, language: ctx?.language ?? null };
|
|
1005
1203
|
}
|
|
1006
1204
|
|
|
@@ -1018,8 +1216,11 @@ function emporixKey(resource, args, context) {
|
|
|
1018
1216
|
}
|
|
1019
1217
|
return ["emporix", resource, ...args, meta];
|
|
1020
1218
|
}
|
|
1219
|
+
|
|
1220
|
+
// src/hooks/internal/use-emporix-infinite.ts
|
|
1221
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
1021
1222
|
function useEmporixInfinite(opts) {
|
|
1022
|
-
return
|
|
1223
|
+
return (0, import_react_query4.useInfiniteQuery)({
|
|
1023
1224
|
queryKey: opts.queryKey,
|
|
1024
1225
|
initialPageParam: 1,
|
|
1025
1226
|
queryFn: ({ pageParam }) => opts.fetchPage(pageParam),
|
|
@@ -1035,7 +1236,7 @@ function useProduct(productId, options = {}) {
|
|
|
1035
1236
|
const { client } = useEmporix();
|
|
1036
1237
|
const { ctx } = useReadAuth(options.auth);
|
|
1037
1238
|
const { siteCode, language } = useReadSite();
|
|
1038
|
-
return
|
|
1239
|
+
return (0, import_react_query5.useQuery)({
|
|
1039
1240
|
queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1040
1241
|
queryFn: () => client.products.get(productId, void 0, ctx),
|
|
1041
1242
|
staleTime: PRODUCTS_STALE_TIME
|
|
@@ -1045,7 +1246,7 @@ function useProducts(params = {}, options = {}) {
|
|
|
1045
1246
|
const { client } = useEmporix();
|
|
1046
1247
|
const { ctx } = useReadAuth(options.auth);
|
|
1047
1248
|
const { siteCode, language } = useReadSite();
|
|
1048
|
-
return
|
|
1249
|
+
return (0, import_react_query5.useQuery)({
|
|
1049
1250
|
queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1050
1251
|
queryFn: () => client.products.list(params, ctx),
|
|
1051
1252
|
staleTime: PRODUCTS_STALE_TIME
|
|
@@ -1068,7 +1269,7 @@ function useProductByCode(code, options = {}) {
|
|
|
1068
1269
|
const { client } = useEmporix();
|
|
1069
1270
|
const { ctx } = useReadAuth(options.auth);
|
|
1070
1271
|
const { siteCode, language } = useReadSite();
|
|
1071
|
-
return
|
|
1272
|
+
return (0, import_react_query5.useQuery)({
|
|
1072
1273
|
queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1073
1274
|
enabled: typeof code === "string" && code !== "",
|
|
1074
1275
|
queryFn: () => client.products.getByCode(code, ctx),
|
|
@@ -1079,7 +1280,7 @@ function useProductSearch(query, params = {}, options = {}) {
|
|
|
1079
1280
|
const { client } = useEmporix();
|
|
1080
1281
|
const { ctx } = useReadAuth(options.auth);
|
|
1081
1282
|
const { siteCode, language } = useReadSite();
|
|
1082
|
-
return
|
|
1283
|
+
return (0, import_react_query5.useQuery)({
|
|
1083
1284
|
queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1084
1285
|
enabled: typeof query === "string" && query.trim() !== "",
|
|
1085
1286
|
queryFn: () => client.products.search(query, params, ctx),
|
|
@@ -1090,7 +1291,7 @@ function useProductNameSearch(term, params = {}, options = {}) {
|
|
|
1090
1291
|
const { client } = useEmporix();
|
|
1091
1292
|
const { ctx } = useReadAuth(options.auth);
|
|
1092
1293
|
const { siteCode, language } = useReadSite();
|
|
1093
|
-
return
|
|
1294
|
+
return (0, import_react_query5.useQuery)({
|
|
1094
1295
|
queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1095
1296
|
enabled: typeof term === "string" && term.trim() !== "",
|
|
1096
1297
|
queryFn: () => client.products.searchByName(term, params, ctx),
|
|
@@ -1101,7 +1302,7 @@ function useProductsByCodes(codes, options = {}) {
|
|
|
1101
1302
|
const { client } = useEmporix();
|
|
1102
1303
|
const { ctx } = useReadAuth(options.auth);
|
|
1103
1304
|
const { siteCode, language } = useReadSite();
|
|
1104
|
-
return
|
|
1305
|
+
return (0, import_react_query5.useQuery)({
|
|
1105
1306
|
queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
|
|
1106
1307
|
tenant: client.tenant,
|
|
1107
1308
|
authKind: ctx.kind,
|
|
@@ -1117,13 +1318,17 @@ function useProductsByCodes(codes, options = {}) {
|
|
|
1117
1318
|
staleTime: 3e4
|
|
1118
1319
|
});
|
|
1119
1320
|
}
|
|
1321
|
+
|
|
1322
|
+
// src/hooks/use-shopping-lists.ts
|
|
1323
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
1324
|
+
var import_emporix_sdk6 = require("@viu/emporix-sdk");
|
|
1120
1325
|
var SHOPPING_LIST_STALE_TIME = 3e4;
|
|
1121
1326
|
var INVALIDATE_KEY = ["emporix", "shopping-lists"];
|
|
1122
1327
|
function useShoppingLists(opts = {}) {
|
|
1123
1328
|
const { client } = useEmporix();
|
|
1124
1329
|
const ctx = useCustomerOnlyCtx();
|
|
1125
1330
|
const { siteCode, language } = useReadSite();
|
|
1126
|
-
return
|
|
1331
|
+
return (0, import_react_query6.useQuery)({
|
|
1127
1332
|
queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1128
1333
|
queryFn: () => client.shoppingLists.list(ctx, opts),
|
|
1129
1334
|
staleTime: SHOPPING_LIST_STALE_TIME
|
|
@@ -1132,8 +1337,8 @@ function useShoppingLists(opts = {}) {
|
|
|
1132
1337
|
function useCreateShoppingList() {
|
|
1133
1338
|
const { client } = useEmporix();
|
|
1134
1339
|
const ctx = useCustomerOnlyCtx();
|
|
1135
|
-
const qc =
|
|
1136
|
-
return
|
|
1340
|
+
const qc = (0, import_react_query6.useQueryClient)();
|
|
1341
|
+
return (0, import_react_query6.useMutation)({
|
|
1137
1342
|
mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
|
|
1138
1343
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
1139
1344
|
});
|
|
@@ -1141,8 +1346,8 @@ function useCreateShoppingList() {
|
|
|
1141
1346
|
function useDeleteShoppingList() {
|
|
1142
1347
|
const { client } = useEmporix();
|
|
1143
1348
|
const ctx = useCustomerOnlyCtx();
|
|
1144
|
-
const qc =
|
|
1145
|
-
return
|
|
1349
|
+
const qc = (0, import_react_query6.useQueryClient)();
|
|
1350
|
+
return (0, import_react_query6.useMutation)({
|
|
1146
1351
|
mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
|
|
1147
1352
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
1148
1353
|
});
|
|
@@ -1150,8 +1355,8 @@ function useDeleteShoppingList() {
|
|
|
1150
1355
|
function useAddToShoppingList() {
|
|
1151
1356
|
const { client } = useEmporix();
|
|
1152
1357
|
const ctx = useCustomerOnlyCtx();
|
|
1153
|
-
const qc =
|
|
1154
|
-
return
|
|
1358
|
+
const qc = (0, import_react_query6.useQueryClient)();
|
|
1359
|
+
return (0, import_react_query6.useMutation)({
|
|
1155
1360
|
mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
|
|
1156
1361
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
1157
1362
|
});
|
|
@@ -1159,8 +1364,8 @@ function useAddToShoppingList() {
|
|
|
1159
1364
|
function useRemoveFromShoppingList() {
|
|
1160
1365
|
const { client } = useEmporix();
|
|
1161
1366
|
const ctx = useCustomerOnlyCtx();
|
|
1162
|
-
const qc =
|
|
1163
|
-
return
|
|
1367
|
+
const qc = (0, import_react_query6.useQueryClient)();
|
|
1368
|
+
return (0, import_react_query6.useMutation)({
|
|
1164
1369
|
mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
|
|
1165
1370
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
1166
1371
|
});
|
|
@@ -1168,18 +1373,22 @@ function useRemoveFromShoppingList() {
|
|
|
1168
1373
|
function useSetShoppingListItemQuantity() {
|
|
1169
1374
|
const { client } = useEmporix();
|
|
1170
1375
|
const ctx = useCustomerOnlyCtx();
|
|
1171
|
-
const qc =
|
|
1172
|
-
return
|
|
1376
|
+
const qc = (0, import_react_query6.useQueryClient)();
|
|
1377
|
+
return (0, import_react_query6.useMutation)({
|
|
1173
1378
|
mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
|
|
1174
1379
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
1175
1380
|
});
|
|
1176
1381
|
}
|
|
1382
|
+
|
|
1383
|
+
// src/hooks/use-variant-children.ts
|
|
1384
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
1385
|
+
var import_emporix_sdk7 = require("@viu/emporix-sdk");
|
|
1177
1386
|
var VARIANT_CHILDREN_STALE_TIME = 6e4;
|
|
1178
1387
|
function useVariantChildren(parentVariantId, options = {}) {
|
|
1179
1388
|
const { client } = useEmporix();
|
|
1180
1389
|
const { ctx } = useReadAuth(options.auth);
|
|
1181
1390
|
const { siteCode, language } = useReadSite();
|
|
1182
|
-
return
|
|
1391
|
+
return (0, import_react_query7.useQuery)({
|
|
1183
1392
|
queryKey: emporixKey(
|
|
1184
1393
|
"variant-children",
|
|
1185
1394
|
[parentVariantId, { pageSize: options.pageSize }],
|
|
@@ -1194,12 +1403,16 @@ function useVariantChildren(parentVariantId, options = {}) {
|
|
|
1194
1403
|
staleTime: VARIANT_CHILDREN_STALE_TIME
|
|
1195
1404
|
});
|
|
1196
1405
|
}
|
|
1406
|
+
|
|
1407
|
+
// src/hooks/use-categories.ts
|
|
1408
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
1409
|
+
var import_emporix_sdk8 = require("@viu/emporix-sdk");
|
|
1197
1410
|
var CATEGORIES_STALE_TIME = 5 * 6e4;
|
|
1198
1411
|
function useCategory(categoryId, options = {}) {
|
|
1199
1412
|
const { client } = useEmporix();
|
|
1200
1413
|
const { ctx } = useReadAuth(options.auth);
|
|
1201
1414
|
const { siteCode, language } = useReadSite();
|
|
1202
|
-
return
|
|
1415
|
+
return (0, import_react_query8.useQuery)({
|
|
1203
1416
|
queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1204
1417
|
queryFn: () => client.categories.get(categoryId, ctx),
|
|
1205
1418
|
staleTime: CATEGORIES_STALE_TIME
|
|
@@ -1209,7 +1422,7 @@ function useSubcategories(categoryId, params = {}, options = {}) {
|
|
|
1209
1422
|
const { client } = useEmporix();
|
|
1210
1423
|
const { ctx } = useReadAuth(options.auth);
|
|
1211
1424
|
const { siteCode, language } = useReadSite();
|
|
1212
|
-
return
|
|
1425
|
+
return (0, import_react_query8.useQuery)({
|
|
1213
1426
|
queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1214
1427
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
1215
1428
|
queryFn: () => client.categories.subcategories(categoryId, params, ctx),
|
|
@@ -1220,7 +1433,7 @@ function useCategories(params = {}, options = {}) {
|
|
|
1220
1433
|
const { client } = useEmporix();
|
|
1221
1434
|
const { ctx } = useReadAuth(options.auth);
|
|
1222
1435
|
const { siteCode, language } = useReadSite();
|
|
1223
|
-
return
|
|
1436
|
+
return (0, import_react_query8.useQuery)({
|
|
1224
1437
|
queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1225
1438
|
queryFn: () => client.categories.list(params, ctx),
|
|
1226
1439
|
staleTime: CATEGORIES_STALE_TIME
|
|
@@ -1243,7 +1456,7 @@ function useCategoryTree(options = {}) {
|
|
|
1243
1456
|
const { client } = useEmporix();
|
|
1244
1457
|
const { ctx } = useReadAuth(options.auth);
|
|
1245
1458
|
const { siteCode, language } = useReadSite();
|
|
1246
|
-
return
|
|
1459
|
+
return (0, import_react_query8.useQuery)({
|
|
1247
1460
|
queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1248
1461
|
queryFn: () => client.categories.tree(ctx),
|
|
1249
1462
|
staleTime: CATEGORIES_STALE_TIME
|
|
@@ -1253,7 +1466,7 @@ function useProductsInCategory(categoryId, params = {}, options = {}) {
|
|
|
1253
1466
|
const { client } = useEmporix();
|
|
1254
1467
|
const { ctx } = useReadAuth(options.auth);
|
|
1255
1468
|
const { siteCode, language } = useReadSite();
|
|
1256
|
-
return
|
|
1469
|
+
return (0, import_react_query8.useQuery)({
|
|
1257
1470
|
queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
1258
1471
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
1259
1472
|
queryFn: () => client.categories.productsIn(categoryId, params, ctx),
|
|
@@ -1275,13 +1488,19 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
|
|
|
1275
1488
|
staleTime: CATEGORIES_STALE_TIME
|
|
1276
1489
|
});
|
|
1277
1490
|
}
|
|
1491
|
+
|
|
1492
|
+
// src/hooks/use-cart.ts
|
|
1493
|
+
var import_react7 = require("react");
|
|
1494
|
+
var import_react_query9 = require("@tanstack/react-query");
|
|
1495
|
+
var import_emporix_sdk9 = require("@viu/emporix-sdk");
|
|
1278
1496
|
function useCart(cartId, options = {}) {
|
|
1279
|
-
const { client
|
|
1497
|
+
const { client } = useEmporix();
|
|
1280
1498
|
const { ctx } = useReadAuth(options.auth);
|
|
1281
1499
|
const { siteCode, language } = useReadSite();
|
|
1282
1500
|
const { activeCompany } = useActiveCompany();
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1501
|
+
const storedCartId = useCartId();
|
|
1502
|
+
const resolvedId = cartId ?? storedCartId ?? void 0;
|
|
1503
|
+
return (0, import_react_query9.useQuery)({
|
|
1285
1504
|
queryKey: emporixKey(
|
|
1286
1505
|
"cart",
|
|
1287
1506
|
[resolvedId ?? null, activeCompany?.id ?? null],
|
|
@@ -1293,14 +1512,14 @@ function useCart(cartId, options = {}) {
|
|
|
1293
1512
|
}
|
|
1294
1513
|
function useCartMutations(cartId) {
|
|
1295
1514
|
const { client, storage } = useEmporix();
|
|
1296
|
-
const qc =
|
|
1515
|
+
const qc = (0, import_react_query9.useQueryClient)();
|
|
1297
1516
|
const { ctx } = useReadAuth();
|
|
1298
1517
|
const { siteCode, language } = useReadSite();
|
|
1299
1518
|
const { activeCompany } = useActiveCompany();
|
|
1300
1519
|
const resolveId = () => {
|
|
1301
1520
|
const id = cartId ?? storage.getCartId();
|
|
1302
1521
|
if (!id) {
|
|
1303
|
-
throw new
|
|
1522
|
+
throw new import_emporix_sdk9.EmporixError(
|
|
1304
1523
|
"useCartMutations: no cartId available \u2014 pass one explicitly or call useActiveCart({ create: true }) first"
|
|
1305
1524
|
);
|
|
1306
1525
|
}
|
|
@@ -1312,7 +1531,7 @@ function useCartMutations(cartId) {
|
|
|
1312
1531
|
{ tenant: client.tenant, authKind: ctx.kind, siteCode, language }
|
|
1313
1532
|
);
|
|
1314
1533
|
function make(run, optimistic) {
|
|
1315
|
-
return
|
|
1534
|
+
return (0, import_react_query9.useMutation)({
|
|
1316
1535
|
mutationFn: async (vars) => run(resolveId(), vars),
|
|
1317
1536
|
onMutate: async (vars) => {
|
|
1318
1537
|
const id = resolveId();
|
|
@@ -1369,9 +1588,9 @@ function useCartMutations(cartId) {
|
|
|
1369
1588
|
}
|
|
1370
1589
|
function useCreateCart() {
|
|
1371
1590
|
const { client, storage } = useEmporix();
|
|
1372
|
-
const qc =
|
|
1591
|
+
const qc = (0, import_react_query9.useQueryClient)();
|
|
1373
1592
|
const { ctx } = useReadAuth();
|
|
1374
|
-
return
|
|
1593
|
+
return (0, import_react_query9.useMutation)({
|
|
1375
1594
|
mutationFn: (input) => client.carts.create(input, ctx),
|
|
1376
1595
|
onSuccess: async (cart) => {
|
|
1377
1596
|
if (cart.cartId) storage.setCartId(cart.cartId);
|
|
@@ -1381,21 +1600,13 @@ function useCreateCart() {
|
|
|
1381
1600
|
}
|
|
1382
1601
|
function useActiveCart(opts) {
|
|
1383
1602
|
const { client, storage } = useEmporix();
|
|
1384
|
-
const qc =
|
|
1603
|
+
const qc = (0, import_react_query9.useQueryClient)();
|
|
1385
1604
|
const { ctx } = useReadAuth(opts?.auth);
|
|
1386
1605
|
const { siteCode: activeSite } = useReadSite();
|
|
1387
1606
|
const { activeCompany } = useActiveCompany();
|
|
1388
|
-
const
|
|
1607
|
+
const cartId = useCartId();
|
|
1389
1608
|
const effectiveLegalEntityId = opts?.legalEntityId ?? activeCompany?.id;
|
|
1390
|
-
|
|
1391
|
-
if (!storage.subscribeAll) return;
|
|
1392
|
-
return storage.subscribeAll((key) => {
|
|
1393
|
-
if (key !== "cartId") return;
|
|
1394
|
-
const next = storage.getCartId();
|
|
1395
|
-
setCartId((prev) => prev === next ? prev : next);
|
|
1396
|
-
});
|
|
1397
|
-
}, [storage]);
|
|
1398
|
-
react.useEffect(() => {
|
|
1609
|
+
(0, import_react7.useEffect)(() => {
|
|
1399
1610
|
if (cartId !== null) return;
|
|
1400
1611
|
if (!opts?.create) return;
|
|
1401
1612
|
const siteCode = activeSite ?? client.config?.credentials?.storefront?.context?.siteCode;
|
|
@@ -1412,7 +1623,6 @@ function useActiveCart(opts) {
|
|
|
1412
1623
|
if (cancelled) return;
|
|
1413
1624
|
if (cart?.id) {
|
|
1414
1625
|
storage.setCartId(cart.id);
|
|
1415
|
-
setCartId(cart.id);
|
|
1416
1626
|
}
|
|
1417
1627
|
}).catch(() => {
|
|
1418
1628
|
});
|
|
@@ -1424,10 +1634,14 @@ function useActiveCart(opts) {
|
|
|
1424
1634
|
const data = cartId === null ? null : inner.data;
|
|
1425
1635
|
return { ...inner, data };
|
|
1426
1636
|
}
|
|
1637
|
+
|
|
1638
|
+
// src/hooks/use-checkout.ts
|
|
1639
|
+
var import_react_query10 = require("@tanstack/react-query");
|
|
1640
|
+
var import_emporix_sdk10 = require("@viu/emporix-sdk");
|
|
1427
1641
|
var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
|
|
1428
1642
|
function customerOnlyCtx(token) {
|
|
1429
1643
|
if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
|
|
1430
|
-
return
|
|
1644
|
+
return import_emporix_sdk10.auth.customer(token);
|
|
1431
1645
|
}
|
|
1432
1646
|
function useCheckout() {
|
|
1433
1647
|
const { client } = useEmporix();
|
|
@@ -1438,13 +1652,13 @@ function useCheckout() {
|
|
|
1438
1652
|
if ("legalEntityId" in input) return input;
|
|
1439
1653
|
return { ...input, legalEntityId: activeCompany.id };
|
|
1440
1654
|
};
|
|
1441
|
-
const placeOrder =
|
|
1655
|
+
const placeOrder = (0, import_react_query10.useMutation)({
|
|
1442
1656
|
mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
|
|
1443
1657
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
1444
1658
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
1445
1659
|
})
|
|
1446
1660
|
});
|
|
1447
|
-
const placeOrderFromQuote =
|
|
1661
|
+
const placeOrderFromQuote = (0, import_react_query10.useMutation)({
|
|
1448
1662
|
mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
|
|
1449
1663
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
1450
1664
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
@@ -1453,11 +1667,11 @@ function useCheckout() {
|
|
|
1453
1667
|
return { placeOrder, placeOrderFromQuote };
|
|
1454
1668
|
}
|
|
1455
1669
|
function usePaymentModes(options = {}) {
|
|
1456
|
-
const { client
|
|
1457
|
-
const token =
|
|
1670
|
+
const { client } = useEmporix();
|
|
1671
|
+
const token = useCustomerToken();
|
|
1458
1672
|
const { siteCode } = useReadSite();
|
|
1459
1673
|
const { activeCompany } = useActiveCompany();
|
|
1460
|
-
return
|
|
1674
|
+
return (0, import_react_query10.useQuery)({
|
|
1461
1675
|
queryKey: emporixKey(
|
|
1462
1676
|
"payment-modes",
|
|
1463
1677
|
[activeCompany?.id ?? null],
|
|
@@ -1468,12 +1682,16 @@ function usePaymentModes(options = {}) {
|
|
|
1468
1682
|
staleTime: PAYMENT_MODES_STALE_TIME
|
|
1469
1683
|
});
|
|
1470
1684
|
}
|
|
1685
|
+
|
|
1686
|
+
// src/hooks/use-match-prices.ts
|
|
1687
|
+
var import_react_query11 = require("@tanstack/react-query");
|
|
1688
|
+
var import_emporix_sdk11 = require("@viu/emporix-sdk");
|
|
1471
1689
|
var PRICES_STALE_TIME = 6e4;
|
|
1472
1690
|
function useMatchPrices(input, options = {}) {
|
|
1473
1691
|
const { client } = useEmporix();
|
|
1474
1692
|
const { siteCode } = useReadSite();
|
|
1475
|
-
const ctx = options.customerToken ?
|
|
1476
|
-
return
|
|
1693
|
+
const ctx = options.customerToken ? import_emporix_sdk11.auth.customer(options.customerToken) : import_emporix_sdk11.auth.anonymous();
|
|
1694
|
+
return (0, import_react_query11.useQuery)({
|
|
1477
1695
|
queryKey: [
|
|
1478
1696
|
"emporix",
|
|
1479
1697
|
"match-prices",
|
|
@@ -1484,12 +1702,16 @@ function useMatchPrices(input, options = {}) {
|
|
|
1484
1702
|
staleTime: PRICES_STALE_TIME
|
|
1485
1703
|
});
|
|
1486
1704
|
}
|
|
1705
|
+
|
|
1706
|
+
// src/hooks/use-match-prices-chunked.ts
|
|
1707
|
+
var import_react_query12 = require("@tanstack/react-query");
|
|
1708
|
+
var import_emporix_sdk12 = require("@viu/emporix-sdk");
|
|
1487
1709
|
var PRICES_STALE_TIME2 = 6e4;
|
|
1488
1710
|
function useMatchPricesChunked(input, options = {}) {
|
|
1489
1711
|
const { client } = useEmporix();
|
|
1490
1712
|
const { siteCode } = useReadSite();
|
|
1491
|
-
const ctx = options.customerToken ?
|
|
1492
|
-
return
|
|
1713
|
+
const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
|
|
1714
|
+
return (0, import_react_query12.useQuery)({
|
|
1493
1715
|
queryKey: [
|
|
1494
1716
|
"emporix",
|
|
1495
1717
|
"match-prices-chunked",
|
|
@@ -1521,16 +1743,20 @@ function useProductMedia(productId) {
|
|
|
1521
1743
|
const data = q.data?.productMedia;
|
|
1522
1744
|
return { data, isLoading: q.isLoading, error: q.error };
|
|
1523
1745
|
}
|
|
1746
|
+
|
|
1747
|
+
// src/hooks/use-my-segments.ts
|
|
1748
|
+
var import_react_query13 = require("@tanstack/react-query");
|
|
1749
|
+
var import_emporix_sdk13 = require("@viu/emporix-sdk");
|
|
1524
1750
|
var SEGMENTS_STALE_TIME = 5 * 6e4;
|
|
1525
1751
|
function customerCtx(token) {
|
|
1526
1752
|
if (!token) throw new Error("requires a customer token in storage");
|
|
1527
|
-
return
|
|
1753
|
+
return import_emporix_sdk13.auth.customer(token);
|
|
1528
1754
|
}
|
|
1529
1755
|
function useMySegments(query = {}) {
|
|
1530
|
-
const { client
|
|
1531
|
-
const token =
|
|
1756
|
+
const { client } = useEmporix();
|
|
1757
|
+
const token = useCustomerToken();
|
|
1532
1758
|
const { siteCode, language } = useReadSite();
|
|
1533
|
-
return
|
|
1759
|
+
return (0, import_react_query13.useQuery)({
|
|
1534
1760
|
queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
|
|
1535
1761
|
enabled: token !== null,
|
|
1536
1762
|
queryFn: () => client.segments.list(query, customerCtx(token)),
|
|
@@ -1538,10 +1764,10 @@ function useMySegments(query = {}) {
|
|
|
1538
1764
|
});
|
|
1539
1765
|
}
|
|
1540
1766
|
function useMySegmentItems(query = {}) {
|
|
1541
|
-
const { client
|
|
1542
|
-
const token =
|
|
1767
|
+
const { client } = useEmporix();
|
|
1768
|
+
const token = useCustomerToken();
|
|
1543
1769
|
const { siteCode, language } = useReadSite();
|
|
1544
|
-
return
|
|
1770
|
+
return (0, import_react_query13.useQuery)({
|
|
1545
1771
|
queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
|
|
1546
1772
|
enabled: token !== null,
|
|
1547
1773
|
queryFn: () => client.segments.listItems(query, customerCtx(token)),
|
|
@@ -1549,10 +1775,10 @@ function useMySegmentItems(query = {}) {
|
|
|
1549
1775
|
});
|
|
1550
1776
|
}
|
|
1551
1777
|
function useMySegmentCategoryTree(query = {}) {
|
|
1552
|
-
const { client
|
|
1553
|
-
const token =
|
|
1778
|
+
const { client } = useEmporix();
|
|
1779
|
+
const token = useCustomerToken();
|
|
1554
1780
|
const { siteCode, language } = useReadSite();
|
|
1555
|
-
return
|
|
1781
|
+
return (0, import_react_query13.useQuery)({
|
|
1556
1782
|
queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
|
|
1557
1783
|
enabled: token !== null,
|
|
1558
1784
|
queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
|
|
@@ -1560,10 +1786,10 @@ function useMySegmentCategoryTree(query = {}) {
|
|
|
1560
1786
|
});
|
|
1561
1787
|
}
|
|
1562
1788
|
function useMySegmentProducts(query = {}) {
|
|
1563
|
-
const { client
|
|
1564
|
-
const token =
|
|
1789
|
+
const { client } = useEmporix();
|
|
1790
|
+
const token = useCustomerToken();
|
|
1565
1791
|
const { siteCode, language } = useReadSite();
|
|
1566
|
-
return
|
|
1792
|
+
return (0, import_react_query13.useQuery)({
|
|
1567
1793
|
queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
|
|
1568
1794
|
enabled: token !== null,
|
|
1569
1795
|
queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
|
|
@@ -1571,8 +1797,8 @@ function useMySegmentProducts(query = {}) {
|
|
|
1571
1797
|
});
|
|
1572
1798
|
}
|
|
1573
1799
|
function useMySegmentProductsInfinite(query = {}) {
|
|
1574
|
-
const { client
|
|
1575
|
-
const token =
|
|
1800
|
+
const { client } = useEmporix();
|
|
1801
|
+
const token = useCustomerToken();
|
|
1576
1802
|
const { siteCode, language } = useReadSite();
|
|
1577
1803
|
return useEmporixInfinite({
|
|
1578
1804
|
queryKey: [
|
|
@@ -1590,10 +1816,10 @@ function useMySegmentProductsInfinite(query = {}) {
|
|
|
1590
1816
|
});
|
|
1591
1817
|
}
|
|
1592
1818
|
function useMySegmentCategories(query = {}) {
|
|
1593
|
-
const { client
|
|
1594
|
-
const token =
|
|
1819
|
+
const { client } = useEmporix();
|
|
1820
|
+
const token = useCustomerToken();
|
|
1595
1821
|
const { siteCode, language } = useReadSite();
|
|
1596
|
-
return
|
|
1822
|
+
return (0, import_react_query13.useQuery)({
|
|
1597
1823
|
queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
|
|
1598
1824
|
enabled: token !== null,
|
|
1599
1825
|
queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
|
|
@@ -1601,8 +1827,8 @@ function useMySegmentCategories(query = {}) {
|
|
|
1601
1827
|
});
|
|
1602
1828
|
}
|
|
1603
1829
|
function useMySegmentCategoriesInfinite(query = {}) {
|
|
1604
|
-
const { client
|
|
1605
|
-
const token =
|
|
1830
|
+
const { client } = useEmporix();
|
|
1831
|
+
const token = useCustomerToken();
|
|
1606
1832
|
const { siteCode, language } = useReadSite();
|
|
1607
1833
|
return useEmporixInfinite({
|
|
1608
1834
|
queryKey: [
|
|
@@ -1619,11 +1845,15 @@ function useMySegmentCategoriesInfinite(query = {}) {
|
|
|
1619
1845
|
staleTime: SEGMENTS_STALE_TIME
|
|
1620
1846
|
});
|
|
1621
1847
|
}
|
|
1848
|
+
|
|
1849
|
+
// src/hooks/use-customer-profile.ts
|
|
1850
|
+
var import_react_query14 = require("@tanstack/react-query");
|
|
1851
|
+
var import_emporix_sdk14 = require("@viu/emporix-sdk");
|
|
1622
1852
|
function useUpdateCustomer() {
|
|
1623
1853
|
const { client } = useEmporix();
|
|
1624
1854
|
const ctx = useCustomerOnlyCtx();
|
|
1625
|
-
const qc =
|
|
1626
|
-
return
|
|
1855
|
+
const qc = (0, import_react_query14.useQueryClient)();
|
|
1856
|
+
return (0, import_react_query14.useMutation)({
|
|
1627
1857
|
mutationFn: (patch) => client.customers.update(patch, ctx),
|
|
1628
1858
|
onSuccess: () => {
|
|
1629
1859
|
void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
|
|
@@ -1633,17 +1863,21 @@ function useUpdateCustomer() {
|
|
|
1633
1863
|
function useChangePassword() {
|
|
1634
1864
|
const { client } = useEmporix();
|
|
1635
1865
|
const ctx = useCustomerOnlyCtx();
|
|
1636
|
-
return
|
|
1866
|
+
return (0, import_react_query14.useMutation)({
|
|
1637
1867
|
mutationFn: (input) => client.customers.changePassword(input, ctx)
|
|
1638
1868
|
});
|
|
1639
1869
|
}
|
|
1870
|
+
|
|
1871
|
+
// src/hooks/use-customer-addresses.ts
|
|
1872
|
+
var import_react_query15 = require("@tanstack/react-query");
|
|
1873
|
+
var import_emporix_sdk15 = require("@viu/emporix-sdk");
|
|
1640
1874
|
var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
|
|
1641
1875
|
function useCustomerAddresses(options = {}) {
|
|
1642
|
-
const { client
|
|
1643
|
-
const token =
|
|
1876
|
+
const { client } = useEmporix();
|
|
1877
|
+
const token = useCustomerToken();
|
|
1644
1878
|
const { activeCompany } = useActiveCompany();
|
|
1645
|
-
const ctx = options.auth ?? (token ?
|
|
1646
|
-
return
|
|
1879
|
+
const ctx = options.auth ?? (token ? import_emporix_sdk15.auth.customer(token) : null);
|
|
1880
|
+
return (0, import_react_query15.useQuery)({
|
|
1647
1881
|
queryKey: [
|
|
1648
1882
|
...ADDRESSES_KEY,
|
|
1649
1883
|
{ tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
|
|
@@ -1655,39 +1889,49 @@ function useCustomerAddresses(options = {}) {
|
|
|
1655
1889
|
function useAddressMutations() {
|
|
1656
1890
|
const { client } = useEmporix();
|
|
1657
1891
|
const ctx = useCustomerOnlyCtx();
|
|
1658
|
-
const qc =
|
|
1892
|
+
const qc = (0, import_react_query15.useQueryClient)();
|
|
1659
1893
|
const invalidate = () => {
|
|
1660
1894
|
void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
|
|
1661
1895
|
};
|
|
1662
1896
|
return {
|
|
1663
|
-
add:
|
|
1897
|
+
add: (0, import_react_query15.useMutation)({
|
|
1664
1898
|
mutationFn: (input) => client.customers.addresses.add(input, ctx),
|
|
1665
1899
|
onSuccess: invalidate
|
|
1666
1900
|
}),
|
|
1667
|
-
update:
|
|
1901
|
+
update: (0, import_react_query15.useMutation)({
|
|
1668
1902
|
mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
|
|
1669
1903
|
onSuccess: invalidate
|
|
1670
1904
|
}),
|
|
1671
|
-
remove:
|
|
1905
|
+
remove: (0, import_react_query15.useMutation)({
|
|
1672
1906
|
mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
|
|
1673
1907
|
onSuccess: invalidate
|
|
1674
1908
|
})
|
|
1675
1909
|
};
|
|
1676
1910
|
}
|
|
1911
|
+
|
|
1912
|
+
// src/hooks/use-password-reset.ts
|
|
1913
|
+
var import_react_query16 = require("@tanstack/react-query");
|
|
1914
|
+
var import_emporix_sdk16 = require("@viu/emporix-sdk");
|
|
1677
1915
|
function usePasswordReset() {
|
|
1678
1916
|
const { client } = useEmporix();
|
|
1679
|
-
const anonCtx =
|
|
1917
|
+
const anonCtx = import_emporix_sdk16.auth.anonymous();
|
|
1680
1918
|
return {
|
|
1681
|
-
request:
|
|
1919
|
+
request: (0, import_react_query16.useMutation)({
|
|
1682
1920
|
mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
|
|
1683
1921
|
}),
|
|
1684
|
-
confirm:
|
|
1922
|
+
confirm: (0, import_react_query16.useMutation)({
|
|
1685
1923
|
mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
|
|
1686
1924
|
})
|
|
1687
1925
|
};
|
|
1688
1926
|
}
|
|
1927
|
+
|
|
1928
|
+
// src/hooks/use-sites.ts
|
|
1929
|
+
var import_react_query17 = require("@tanstack/react-query");
|
|
1930
|
+
|
|
1931
|
+
// src/hooks/use-site-context.ts
|
|
1932
|
+
var import_react8 = require("react");
|
|
1689
1933
|
function useSiteContext() {
|
|
1690
|
-
const ctx =
|
|
1934
|
+
const ctx = (0, import_react8.useContext)(EmporixSiteContext);
|
|
1691
1935
|
if (!ctx) {
|
|
1692
1936
|
throw new Error("useSiteContext must be used within an EmporixProvider");
|
|
1693
1937
|
}
|
|
@@ -1699,7 +1943,7 @@ var SITES_STALE_TIME = 10 * 6e4;
|
|
|
1699
1943
|
function useSites(options = {}) {
|
|
1700
1944
|
const { client } = useEmporix();
|
|
1701
1945
|
const { ctx } = useReadAuth(options.auth);
|
|
1702
|
-
return
|
|
1946
|
+
return (0, import_react_query17.useQuery)({
|
|
1703
1947
|
queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1704
1948
|
queryFn: () => client.sites.list(ctx),
|
|
1705
1949
|
staleTime: SITES_STALE_TIME
|
|
@@ -1708,7 +1952,7 @@ function useSites(options = {}) {
|
|
|
1708
1952
|
function useDefaultSite(options = {}) {
|
|
1709
1953
|
const { client } = useEmporix();
|
|
1710
1954
|
const { ctx } = useReadAuth(options.auth);
|
|
1711
|
-
return
|
|
1955
|
+
return (0, import_react_query17.useQuery)({
|
|
1712
1956
|
queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1713
1957
|
queryFn: () => client.sites.current(ctx),
|
|
1714
1958
|
staleTime: SITES_STALE_TIME
|
|
@@ -1719,79 +1963,103 @@ function useActiveSite(options = {}) {
|
|
|
1719
1963
|
const { data: sites } = useSites(options);
|
|
1720
1964
|
return siteCode ? sites?.find((s) => s.code === siteCode) : void 0;
|
|
1721
1965
|
}
|
|
1966
|
+
|
|
1967
|
+
// src/hooks/use-my-companies.ts
|
|
1968
|
+
var import_react_query18 = require("@tanstack/react-query");
|
|
1969
|
+
var import_emporix_sdk17 = require("@viu/emporix-sdk");
|
|
1722
1970
|
function useMyCompanies() {
|
|
1723
|
-
const { client
|
|
1724
|
-
const token =
|
|
1725
|
-
return
|
|
1971
|
+
const { client } = useEmporix();
|
|
1972
|
+
const token = useCustomerToken();
|
|
1973
|
+
return (0, import_react_query18.useQuery)({
|
|
1726
1974
|
queryKey: emporixKey("companies", ["mine"], {
|
|
1727
1975
|
tenant: client.tenant,
|
|
1728
1976
|
authKind: token ? "customer" : "anonymous"
|
|
1729
1977
|
}),
|
|
1730
1978
|
enabled: token !== null,
|
|
1731
|
-
queryFn: () => client.companies.listMine(
|
|
1979
|
+
queryFn: () => client.companies.listMine(import_emporix_sdk17.auth.customer(token))
|
|
1732
1980
|
});
|
|
1733
1981
|
}
|
|
1982
|
+
|
|
1983
|
+
// src/hooks/use-company.ts
|
|
1984
|
+
var import_react_query19 = require("@tanstack/react-query");
|
|
1985
|
+
var import_emporix_sdk18 = require("@viu/emporix-sdk");
|
|
1734
1986
|
function useCompany(legalEntityId) {
|
|
1735
|
-
const { client
|
|
1736
|
-
const token =
|
|
1737
|
-
return
|
|
1987
|
+
const { client } = useEmporix();
|
|
1988
|
+
const token = useCustomerToken();
|
|
1989
|
+
return (0, import_react_query19.useQuery)({
|
|
1738
1990
|
queryKey: emporixKey("companies", [legalEntityId ?? null], {
|
|
1739
1991
|
tenant: client.tenant,
|
|
1740
1992
|
authKind: token ? "customer" : "anonymous"
|
|
1741
1993
|
}),
|
|
1742
1994
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1743
|
-
queryFn: () => client.companies.get(legalEntityId,
|
|
1995
|
+
queryFn: () => client.companies.get(legalEntityId, import_emporix_sdk18.auth.customer(token))
|
|
1744
1996
|
});
|
|
1745
1997
|
}
|
|
1998
|
+
|
|
1999
|
+
// src/hooks/use-company-contacts.ts
|
|
2000
|
+
var import_react_query20 = require("@tanstack/react-query");
|
|
2001
|
+
var import_emporix_sdk19 = require("@viu/emporix-sdk");
|
|
1746
2002
|
function useCompanyContacts(legalEntityId) {
|
|
1747
2003
|
const { client, storage } = useEmporix();
|
|
1748
2004
|
const token = storage.getCustomerToken();
|
|
1749
|
-
return
|
|
2005
|
+
return (0, import_react_query20.useQuery)({
|
|
1750
2006
|
queryKey: emporixKey("companies", ["contacts", legalEntityId ?? null], {
|
|
1751
2007
|
tenant: client.tenant,
|
|
1752
2008
|
authKind: token ? "customer" : "anonymous"
|
|
1753
2009
|
}),
|
|
1754
2010
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1755
|
-
queryFn: () => client.contacts.listForCompany(legalEntityId,
|
|
2011
|
+
queryFn: () => client.contacts.listForCompany(legalEntityId, import_emporix_sdk19.auth.customer(token))
|
|
1756
2012
|
});
|
|
1757
2013
|
}
|
|
2014
|
+
|
|
2015
|
+
// src/hooks/use-company-locations.ts
|
|
2016
|
+
var import_react_query21 = require("@tanstack/react-query");
|
|
2017
|
+
var import_emporix_sdk20 = require("@viu/emporix-sdk");
|
|
1758
2018
|
function useCompanyLocations(legalEntityId) {
|
|
1759
|
-
const { client
|
|
1760
|
-
const token =
|
|
1761
|
-
return
|
|
2019
|
+
const { client } = useEmporix();
|
|
2020
|
+
const token = useCustomerToken();
|
|
2021
|
+
return (0, import_react_query21.useQuery)({
|
|
1762
2022
|
queryKey: emporixKey("companies", ["locations", legalEntityId ?? null], {
|
|
1763
2023
|
tenant: client.tenant,
|
|
1764
2024
|
authKind: token ? "customer" : "anonymous"
|
|
1765
2025
|
}),
|
|
1766
2026
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1767
|
-
queryFn: () => client.locations.listForCompany(legalEntityId,
|
|
2027
|
+
queryFn: () => client.locations.listForCompany(legalEntityId, import_emporix_sdk20.auth.customer(token))
|
|
1768
2028
|
});
|
|
1769
2029
|
}
|
|
2030
|
+
|
|
2031
|
+
// src/hooks/use-company-groups.ts
|
|
2032
|
+
var import_react_query22 = require("@tanstack/react-query");
|
|
2033
|
+
var import_emporix_sdk21 = require("@viu/emporix-sdk");
|
|
1770
2034
|
function useCompanyGroups(legalEntityId) {
|
|
1771
|
-
const { client
|
|
1772
|
-
const token =
|
|
1773
|
-
return
|
|
2035
|
+
const { client } = useEmporix();
|
|
2036
|
+
const token = useCustomerToken();
|
|
2037
|
+
return (0, import_react_query22.useQuery)({
|
|
1774
2038
|
queryKey: emporixKey("companies", ["groups", legalEntityId ?? null], {
|
|
1775
2039
|
tenant: client.tenant,
|
|
1776
2040
|
authKind: token ? "customer" : "anonymous"
|
|
1777
2041
|
}),
|
|
1778
2042
|
enabled: token !== null && legalEntityId !== void 0,
|
|
1779
|
-
queryFn: () => client.customerGroups.listForCompany(legalEntityId,
|
|
2043
|
+
queryFn: () => client.customerGroups.listForCompany(legalEntityId, import_emporix_sdk21.auth.customer(token))
|
|
1780
2044
|
});
|
|
1781
2045
|
}
|
|
2046
|
+
|
|
2047
|
+
// src/hooks/use-company-mutations.ts
|
|
2048
|
+
var import_react_query23 = require("@tanstack/react-query");
|
|
2049
|
+
var import_emporix_sdk22 = require("@viu/emporix-sdk");
|
|
1782
2050
|
function useCustomerAuthResolver() {
|
|
1783
2051
|
const { storage } = useEmporix();
|
|
1784
2052
|
return () => {
|
|
1785
2053
|
const token = storage.getCustomerToken();
|
|
1786
2054
|
if (!token) throw new Error("Mutation requires a logged-in customer token");
|
|
1787
|
-
return
|
|
2055
|
+
return import_emporix_sdk22.auth.customer(token);
|
|
1788
2056
|
};
|
|
1789
2057
|
}
|
|
1790
2058
|
function useCreateCompany() {
|
|
1791
2059
|
const { client } = useEmporix();
|
|
1792
2060
|
const resolveAuth = useCustomerAuthResolver();
|
|
1793
|
-
const qc =
|
|
1794
|
-
return
|
|
2061
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2062
|
+
return (0, import_react_query23.useMutation)({
|
|
1795
2063
|
mutationFn: (input) => client.companies.create(input, resolveAuth()),
|
|
1796
2064
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
|
|
1797
2065
|
});
|
|
@@ -1799,8 +2067,8 @@ function useCreateCompany() {
|
|
|
1799
2067
|
function useUpdateCompany() {
|
|
1800
2068
|
const { client } = useEmporix();
|
|
1801
2069
|
const resolveAuth = useCustomerAuthResolver();
|
|
1802
|
-
const qc =
|
|
1803
|
-
return
|
|
2070
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2071
|
+
return (0, import_react_query23.useMutation)({
|
|
1804
2072
|
mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
|
|
1805
2073
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1806
2074
|
});
|
|
@@ -1808,8 +2076,8 @@ function useUpdateCompany() {
|
|
|
1808
2076
|
function useDeleteCompany() {
|
|
1809
2077
|
const { client } = useEmporix();
|
|
1810
2078
|
const resolveAuth = useCustomerAuthResolver();
|
|
1811
|
-
const qc =
|
|
1812
|
-
return
|
|
2079
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2080
|
+
return (0, import_react_query23.useMutation)({
|
|
1813
2081
|
mutationFn: (id) => client.companies.delete(id, resolveAuth()),
|
|
1814
2082
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1815
2083
|
});
|
|
@@ -1817,8 +2085,8 @@ function useDeleteCompany() {
|
|
|
1817
2085
|
function useAssignContact() {
|
|
1818
2086
|
const { client } = useEmporix();
|
|
1819
2087
|
const resolveAuth = useCustomerAuthResolver();
|
|
1820
|
-
const qc =
|
|
1821
|
-
return
|
|
2088
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2089
|
+
return (0, import_react_query23.useMutation)({
|
|
1822
2090
|
mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
|
|
1823
2091
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1824
2092
|
});
|
|
@@ -1826,8 +2094,8 @@ function useAssignContact() {
|
|
|
1826
2094
|
function useUpdateContactAssignment() {
|
|
1827
2095
|
const { client } = useEmporix();
|
|
1828
2096
|
const resolveAuth = useCustomerAuthResolver();
|
|
1829
|
-
const qc =
|
|
1830
|
-
return
|
|
2097
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2098
|
+
return (0, import_react_query23.useMutation)({
|
|
1831
2099
|
mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
|
|
1832
2100
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1833
2101
|
});
|
|
@@ -1835,8 +2103,8 @@ function useUpdateContactAssignment() {
|
|
|
1835
2103
|
function useUnassignContact() {
|
|
1836
2104
|
const { client } = useEmporix();
|
|
1837
2105
|
const resolveAuth = useCustomerAuthResolver();
|
|
1838
|
-
const qc =
|
|
1839
|
-
return
|
|
2106
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2107
|
+
return (0, import_react_query23.useMutation)({
|
|
1840
2108
|
mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
|
|
1841
2109
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1842
2110
|
});
|
|
@@ -1844,8 +2112,8 @@ function useUnassignContact() {
|
|
|
1844
2112
|
function useCreateLocation() {
|
|
1845
2113
|
const { client } = useEmporix();
|
|
1846
2114
|
const resolveAuth = useCustomerAuthResolver();
|
|
1847
|
-
const qc =
|
|
1848
|
-
return
|
|
2115
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2116
|
+
return (0, import_react_query23.useMutation)({
|
|
1849
2117
|
mutationFn: (input) => client.locations.create(input, resolveAuth()),
|
|
1850
2118
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1851
2119
|
});
|
|
@@ -1853,8 +2121,8 @@ function useCreateLocation() {
|
|
|
1853
2121
|
function useUpdateLocation() {
|
|
1854
2122
|
const { client } = useEmporix();
|
|
1855
2123
|
const resolveAuth = useCustomerAuthResolver();
|
|
1856
|
-
const qc =
|
|
1857
|
-
return
|
|
2124
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2125
|
+
return (0, import_react_query23.useMutation)({
|
|
1858
2126
|
mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
|
|
1859
2127
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1860
2128
|
});
|
|
@@ -1862,8 +2130,8 @@ function useUpdateLocation() {
|
|
|
1862
2130
|
function useDeleteLocation() {
|
|
1863
2131
|
const { client } = useEmporix();
|
|
1864
2132
|
const resolveAuth = useCustomerAuthResolver();
|
|
1865
|
-
const qc =
|
|
1866
|
-
return
|
|
2133
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2134
|
+
return (0, import_react_query23.useMutation)({
|
|
1867
2135
|
mutationFn: (id) => client.locations.delete(id, resolveAuth()),
|
|
1868
2136
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1869
2137
|
});
|
|
@@ -1871,8 +2139,8 @@ function useDeleteLocation() {
|
|
|
1871
2139
|
function useAddGroupMember() {
|
|
1872
2140
|
const { client } = useEmporix();
|
|
1873
2141
|
const resolveAuth = useCustomerAuthResolver();
|
|
1874
|
-
const qc =
|
|
1875
|
-
return
|
|
2142
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2143
|
+
return (0, import_react_query23.useMutation)({
|
|
1876
2144
|
mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
|
|
1877
2145
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1878
2146
|
});
|
|
@@ -1880,19 +2148,22 @@ function useAddGroupMember() {
|
|
|
1880
2148
|
function useRemoveGroupMember() {
|
|
1881
2149
|
const { client } = useEmporix();
|
|
1882
2150
|
const resolveAuth = useCustomerAuthResolver();
|
|
1883
|
-
const qc =
|
|
1884
|
-
return
|
|
2151
|
+
const qc = (0, import_react_query23.useQueryClient)();
|
|
2152
|
+
return (0, import_react_query23.useMutation)({
|
|
1885
2153
|
mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
|
|
1886
2154
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1887
2155
|
});
|
|
1888
2156
|
}
|
|
2157
|
+
|
|
2158
|
+
// src/hooks/use-company-switcher.ts
|
|
2159
|
+
var import_react9 = require("react");
|
|
1889
2160
|
function useCompanySwitcher() {
|
|
1890
2161
|
const ctx = useActiveCompany();
|
|
1891
|
-
const switchFn =
|
|
2162
|
+
const switchFn = (0, import_react9.useCallback)(
|
|
1892
2163
|
(legalEntityId) => ctx.setActiveCompany(legalEntityId),
|
|
1893
2164
|
[ctx]
|
|
1894
2165
|
);
|
|
1895
|
-
const clearFn =
|
|
2166
|
+
const clearFn = (0, import_react9.useCallback)(() => ctx.setActiveCompany(null), [ctx]);
|
|
1896
2167
|
return {
|
|
1897
2168
|
companies: ctx.myCompanies,
|
|
1898
2169
|
active: ctx.activeCompany,
|
|
@@ -1901,23 +2172,27 @@ function useCompanySwitcher() {
|
|
|
1901
2172
|
clear: clearFn
|
|
1902
2173
|
};
|
|
1903
2174
|
}
|
|
2175
|
+
|
|
2176
|
+
// src/hooks/use-cloud-functions.ts
|
|
2177
|
+
var import_react_query24 = require("@tanstack/react-query");
|
|
2178
|
+
var import_emporix_sdk23 = require("@viu/emporix-sdk");
|
|
1904
2179
|
function useInvokeCloudFunction() {
|
|
1905
2180
|
const { client, storage } = useEmporix();
|
|
1906
|
-
return
|
|
2181
|
+
return (0, import_react_query24.useMutation)({
|
|
1907
2182
|
mutationFn: (vars) => {
|
|
1908
2183
|
const { functionId, auth: authOverride, ...options } = vars;
|
|
1909
2184
|
const token = storage.getCustomerToken();
|
|
1910
|
-
const authCtx = authOverride ?? (token ?
|
|
2185
|
+
const authCtx = authOverride ?? (token ? import_emporix_sdk23.auth.customer(token) : import_emporix_sdk23.auth.anonymous());
|
|
1911
2186
|
return client.cloudFunctions.invoke(functionId, options, authCtx);
|
|
1912
2187
|
}
|
|
1913
2188
|
});
|
|
1914
2189
|
}
|
|
1915
2190
|
function useCloudFunction(functionId, options, queryOptions) {
|
|
1916
|
-
const { client
|
|
1917
|
-
const token =
|
|
2191
|
+
const { client } = useEmporix();
|
|
2192
|
+
const token = useCustomerToken();
|
|
1918
2193
|
const { auth: authOverride, ...invokeOptions } = options ?? {};
|
|
1919
|
-
const authCtx = authOverride ?? (token ?
|
|
1920
|
-
return
|
|
2194
|
+
const authCtx = authOverride ?? (token ? import_emporix_sdk23.auth.customer(token) : import_emporix_sdk23.auth.anonymous());
|
|
2195
|
+
return (0, import_react_query24.useQuery)({
|
|
1921
2196
|
queryKey: emporixKey(
|
|
1922
2197
|
"cloud-function",
|
|
1923
2198
|
[functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
|
|
@@ -1932,20 +2207,24 @@ function useCloudFunction(functionId, options, queryOptions) {
|
|
|
1932
2207
|
)
|
|
1933
2208
|
});
|
|
1934
2209
|
}
|
|
2210
|
+
|
|
2211
|
+
// src/hooks/use-my-orders.ts
|
|
2212
|
+
var import_react_query25 = require("@tanstack/react-query");
|
|
2213
|
+
var import_emporix_sdk24 = require("@viu/emporix-sdk");
|
|
1935
2214
|
function useMyOrders(options = {}) {
|
|
1936
|
-
const { client
|
|
2215
|
+
const { client } = useEmporix();
|
|
1937
2216
|
const { activeCompany } = useActiveCompany();
|
|
1938
2217
|
const { siteCode, language } = useReadSite();
|
|
1939
|
-
const token =
|
|
2218
|
+
const token = useCustomerToken();
|
|
1940
2219
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1941
|
-
return
|
|
2220
|
+
return (0, import_react_query25.useQuery)({
|
|
1942
2221
|
queryKey: emporixKey(
|
|
1943
2222
|
"orders",
|
|
1944
2223
|
["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
|
|
1945
2224
|
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1946
2225
|
),
|
|
1947
2226
|
enabled: token !== null,
|
|
1948
|
-
queryFn: () => client.orders.listMine(
|
|
2227
|
+
queryFn: () => client.orders.listMine(import_emporix_sdk24.auth.customer(token), {
|
|
1949
2228
|
...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
|
|
1950
2229
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1951
2230
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1955,11 +2234,14 @@ function useMyOrders(options = {}) {
|
|
|
1955
2234
|
})
|
|
1956
2235
|
});
|
|
1957
2236
|
}
|
|
2237
|
+
|
|
2238
|
+
// src/hooks/use-my-orders-infinite.ts
|
|
2239
|
+
var import_emporix_sdk25 = require("@viu/emporix-sdk");
|
|
1958
2240
|
function useMyOrdersInfinite(options = {}) {
|
|
1959
|
-
const { client
|
|
2241
|
+
const { client } = useEmporix();
|
|
1960
2242
|
const { activeCompany } = useActiveCompany();
|
|
1961
2243
|
const { siteCode, language } = useReadSite();
|
|
1962
|
-
const token =
|
|
2244
|
+
const token = useCustomerToken();
|
|
1963
2245
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1964
2246
|
return useEmporixInfinite({
|
|
1965
2247
|
queryKey: emporixKey(
|
|
@@ -1968,7 +2250,7 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1968
2250
|
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1969
2251
|
),
|
|
1970
2252
|
enabled: token !== null,
|
|
1971
|
-
fetchPage: (pageNumber) => client.orders.listMine(
|
|
2253
|
+
fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk25.auth.customer(token), {
|
|
1972
2254
|
pageNumber,
|
|
1973
2255
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1974
2256
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1978,11 +2260,15 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1978
2260
|
})
|
|
1979
2261
|
});
|
|
1980
2262
|
}
|
|
2263
|
+
|
|
2264
|
+
// src/hooks/use-order.ts
|
|
2265
|
+
var import_react_query26 = require("@tanstack/react-query");
|
|
2266
|
+
var import_emporix_sdk26 = require("@viu/emporix-sdk");
|
|
1981
2267
|
function useOrder(orderId, options = {}) {
|
|
1982
|
-
const { client
|
|
1983
|
-
const token =
|
|
2268
|
+
const { client } = useEmporix();
|
|
2269
|
+
const token = useCustomerToken();
|
|
1984
2270
|
const { language } = useReadSite();
|
|
1985
|
-
return
|
|
2271
|
+
return (0, import_react_query26.useQuery)({
|
|
1986
2272
|
queryKey: emporixKey("orders", [orderId ?? null], {
|
|
1987
2273
|
tenant: client.tenant,
|
|
1988
2274
|
authKind: token ? "customer" : "anonymous",
|
|
@@ -1991,15 +2277,19 @@ function useOrder(orderId, options = {}) {
|
|
|
1991
2277
|
enabled: token !== null && orderId !== void 0,
|
|
1992
2278
|
queryFn: () => client.orders.get(
|
|
1993
2279
|
orderId,
|
|
1994
|
-
|
|
2280
|
+
import_emporix_sdk26.auth.customer(token),
|
|
1995
2281
|
options.saasToken ? { saasToken: options.saasToken } : {}
|
|
1996
2282
|
)
|
|
1997
2283
|
});
|
|
1998
2284
|
}
|
|
2285
|
+
|
|
2286
|
+
// src/hooks/use-cancel-order.ts
|
|
2287
|
+
var import_react_query27 = require("@tanstack/react-query");
|
|
2288
|
+
var import_emporix_sdk27 = require("@viu/emporix-sdk");
|
|
1999
2289
|
function useCancelOrder() {
|
|
2000
2290
|
const { client, storage } = useEmporix();
|
|
2001
|
-
const qc =
|
|
2002
|
-
return
|
|
2291
|
+
const qc = (0, import_react_query27.useQueryClient)();
|
|
2292
|
+
return (0, import_react_query27.useMutation)({
|
|
2003
2293
|
mutationKey: ["emporix", "orders", "cancel"],
|
|
2004
2294
|
mutationFn: async (input) => {
|
|
2005
2295
|
const token = storage.getCustomerToken();
|
|
@@ -2007,7 +2297,7 @@ function useCancelOrder() {
|
|
|
2007
2297
|
const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
|
|
2008
2298
|
await client.orders.cancel(
|
|
2009
2299
|
orderId,
|
|
2010
|
-
|
|
2300
|
+
import_emporix_sdk27.auth.customer(token),
|
|
2011
2301
|
saasToken ? { saasToken } : {}
|
|
2012
2302
|
);
|
|
2013
2303
|
},
|
|
@@ -2016,10 +2306,14 @@ function useCancelOrder() {
|
|
|
2016
2306
|
})
|
|
2017
2307
|
});
|
|
2018
2308
|
}
|
|
2309
|
+
|
|
2310
|
+
// src/hooks/use-order-transition.ts
|
|
2311
|
+
var import_react_query28 = require("@tanstack/react-query");
|
|
2312
|
+
var import_emporix_sdk28 = require("@viu/emporix-sdk");
|
|
2019
2313
|
function useOrderTransition() {
|
|
2020
2314
|
const { client, storage } = useEmporix();
|
|
2021
|
-
const qc =
|
|
2022
|
-
return
|
|
2315
|
+
const qc = (0, import_react_query28.useQueryClient)();
|
|
2316
|
+
return (0, import_react_query28.useMutation)({
|
|
2023
2317
|
mutationKey: ["emporix", "orders", "transition"],
|
|
2024
2318
|
mutationFn: async ({ orderId, status, comment, saasToken }) => {
|
|
2025
2319
|
const token = storage.getCustomerToken();
|
|
@@ -2027,7 +2321,7 @@ function useOrderTransition() {
|
|
|
2027
2321
|
await client.orders.transition(
|
|
2028
2322
|
orderId,
|
|
2029
2323
|
status,
|
|
2030
|
-
|
|
2324
|
+
import_emporix_sdk28.auth.customer(token),
|
|
2031
2325
|
{
|
|
2032
2326
|
...comment !== void 0 ? { comment } : {},
|
|
2033
2327
|
...saasToken !== void 0 ? { saasToken } : {}
|
|
@@ -2039,15 +2333,19 @@ function useOrderTransition() {
|
|
|
2039
2333
|
})
|
|
2040
2334
|
});
|
|
2041
2335
|
}
|
|
2336
|
+
|
|
2337
|
+
// src/hooks/use-reorder.ts
|
|
2338
|
+
var import_react_query29 = require("@tanstack/react-query");
|
|
2339
|
+
var import_emporix_sdk29 = require("@viu/emporix-sdk");
|
|
2042
2340
|
function useReorder() {
|
|
2043
2341
|
const { client, storage } = useEmporix();
|
|
2044
|
-
const qc =
|
|
2045
|
-
return
|
|
2342
|
+
const qc = (0, import_react_query29.useQueryClient)();
|
|
2343
|
+
return (0, import_react_query29.useMutation)({
|
|
2046
2344
|
mutationKey: ["emporix", "orders", "reorder"],
|
|
2047
2345
|
mutationFn: async ({ orderId, saasToken }) => {
|
|
2048
2346
|
const token = storage.getCustomerToken();
|
|
2049
2347
|
if (!token) throw new Error("useReorder: requires a logged-in customer");
|
|
2050
|
-
const ctx =
|
|
2348
|
+
const ctx = import_emporix_sdk29.auth.customer(token);
|
|
2051
2349
|
const order = await qc.fetchQuery({
|
|
2052
2350
|
queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
|
|
2053
2351
|
queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
|
|
@@ -2092,10 +2390,14 @@ function useReorder() {
|
|
|
2092
2390
|
}
|
|
2093
2391
|
});
|
|
2094
2392
|
}
|
|
2393
|
+
|
|
2394
|
+
// src/hooks/use-sales-order.ts
|
|
2395
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
2396
|
+
var import_emporix_sdk30 = require("@viu/emporix-sdk");
|
|
2095
2397
|
function useSalesOrder(orderId, authCtx) {
|
|
2096
2398
|
const { client } = useEmporix();
|
|
2097
2399
|
const { language } = useReadSite();
|
|
2098
|
-
return
|
|
2400
|
+
return (0, import_react_query30.useQuery)({
|
|
2099
2401
|
queryKey: emporixKey("salesorders", [orderId ?? null], {
|
|
2100
2402
|
tenant: client.tenant,
|
|
2101
2403
|
authKind: authCtx?.kind ?? "anonymous",
|
|
@@ -2105,10 +2407,14 @@ function useSalesOrder(orderId, authCtx) {
|
|
|
2105
2407
|
queryFn: () => client.salesOrders.get(orderId, authCtx)
|
|
2106
2408
|
});
|
|
2107
2409
|
}
|
|
2410
|
+
|
|
2411
|
+
// src/hooks/use-update-sales-order.ts
|
|
2412
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
2413
|
+
var import_emporix_sdk31 = require("@viu/emporix-sdk");
|
|
2108
2414
|
function useUpdateSalesOrder() {
|
|
2109
2415
|
const { client } = useEmporix();
|
|
2110
|
-
const qc =
|
|
2111
|
-
return
|
|
2416
|
+
const qc = (0, import_react_query31.useQueryClient)();
|
|
2417
|
+
return (0, import_react_query31.useMutation)({
|
|
2112
2418
|
mutationKey: ["emporix", "salesorders", "update"],
|
|
2113
2419
|
mutationFn: async ({ orderId, patch, auth: auth27, recalculate }) => {
|
|
2114
2420
|
if (!auth27) throw new Error("useUpdateSalesOrder: requires an auth context");
|
|
@@ -2126,11 +2432,15 @@ function useUpdateSalesOrder() {
|
|
|
2126
2432
|
}
|
|
2127
2433
|
});
|
|
2128
2434
|
}
|
|
2435
|
+
|
|
2436
|
+
// src/hooks/use-availability.ts
|
|
2437
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
2438
|
+
var import_emporix_sdk32 = require("@viu/emporix-sdk");
|
|
2129
2439
|
var AVAILABILITY_STALE_TIME = 3e4;
|
|
2130
2440
|
function useAvailability(productId, siteCode, options = {}) {
|
|
2131
2441
|
const { client } = useEmporix();
|
|
2132
|
-
const ctx = options.customerToken ?
|
|
2133
|
-
return
|
|
2442
|
+
const ctx = options.customerToken ? import_emporix_sdk32.auth.customer(options.customerToken) : import_emporix_sdk32.auth.anonymous();
|
|
2443
|
+
return (0, import_react_query32.useQuery)({
|
|
2134
2444
|
queryKey: [
|
|
2135
2445
|
"emporix",
|
|
2136
2446
|
"availability",
|
|
@@ -2149,11 +2459,15 @@ function useAvailability(productId, siteCode, options = {}) {
|
|
|
2149
2459
|
staleTime: AVAILABILITY_STALE_TIME
|
|
2150
2460
|
});
|
|
2151
2461
|
}
|
|
2462
|
+
|
|
2463
|
+
// src/hooks/use-availabilities.ts
|
|
2464
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
2465
|
+
var import_emporix_sdk33 = require("@viu/emporix-sdk");
|
|
2152
2466
|
var AVAILABILITY_STALE_TIME2 = 3e4;
|
|
2153
2467
|
function useAvailabilities(productIds, siteCode, options = {}) {
|
|
2154
2468
|
const { client } = useEmporix();
|
|
2155
|
-
const ctx = options.customerToken ?
|
|
2156
|
-
return
|
|
2469
|
+
const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
|
|
2470
|
+
return (0, import_react_query33.useQuery)({
|
|
2157
2471
|
queryKey: [
|
|
2158
2472
|
"emporix",
|
|
2159
2473
|
"availabilities",
|
|
@@ -2172,29 +2486,35 @@ function useAvailabilities(productIds, siteCode, options = {}) {
|
|
|
2172
2486
|
staleTime: AVAILABILITY_STALE_TIME2
|
|
2173
2487
|
});
|
|
2174
2488
|
}
|
|
2489
|
+
|
|
2490
|
+
// src/hooks/use-coupons.ts
|
|
2491
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
2175
2492
|
var INVALIDATE_KEY2 = ["emporix", "coupons"];
|
|
2176
2493
|
function useValidateCoupon() {
|
|
2177
2494
|
const { client } = useEmporix();
|
|
2178
2495
|
const { ctx } = useReadAuth();
|
|
2179
|
-
return
|
|
2496
|
+
return (0, import_react_query34.useMutation)({
|
|
2180
2497
|
mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
|
|
2181
2498
|
});
|
|
2182
2499
|
}
|
|
2183
2500
|
function useRedeemCoupon() {
|
|
2184
2501
|
const { client } = useEmporix();
|
|
2185
2502
|
const { ctx } = useReadAuth();
|
|
2186
|
-
const qc =
|
|
2187
|
-
return
|
|
2503
|
+
const qc = (0, import_react_query34.useQueryClient)();
|
|
2504
|
+
return (0, import_react_query34.useMutation)({
|
|
2188
2505
|
mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
|
|
2189
2506
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
|
|
2190
2507
|
});
|
|
2191
2508
|
}
|
|
2509
|
+
|
|
2510
|
+
// src/hooks/use-reward-points.ts
|
|
2511
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
2192
2512
|
var STALE = 3e4;
|
|
2193
2513
|
var INVALIDATE_KEY3 = ["emporix", "reward-points"];
|
|
2194
2514
|
function useMyRewardPoints() {
|
|
2195
2515
|
const { client } = useEmporix();
|
|
2196
2516
|
const ctx = useCustomerOnlyCtx();
|
|
2197
|
-
return
|
|
2517
|
+
return (0, import_react_query35.useQuery)({
|
|
2198
2518
|
queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
2199
2519
|
queryFn: () => client.rewardPoints.getMyPoints(ctx),
|
|
2200
2520
|
staleTime: STALE
|
|
@@ -2203,7 +2523,7 @@ function useMyRewardPoints() {
|
|
|
2203
2523
|
function useMyRewardPointsSummary() {
|
|
2204
2524
|
const { client } = useEmporix();
|
|
2205
2525
|
const ctx = useCustomerOnlyCtx();
|
|
2206
|
-
return
|
|
2526
|
+
return (0, import_react_query35.useQuery)({
|
|
2207
2527
|
queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
2208
2528
|
queryFn: () => client.rewardPoints.getMySummary(ctx),
|
|
2209
2529
|
staleTime: STALE
|
|
@@ -2212,7 +2532,7 @@ function useMyRewardPointsSummary() {
|
|
|
2212
2532
|
function useRedeemOptions() {
|
|
2213
2533
|
const { client } = useEmporix();
|
|
2214
2534
|
const { ctx } = useReadAuth();
|
|
2215
|
-
return
|
|
2535
|
+
return (0, import_react_query35.useQuery)({
|
|
2216
2536
|
queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
2217
2537
|
queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
|
|
2218
2538
|
staleTime: STALE
|
|
@@ -2221,18 +2541,21 @@ function useRedeemOptions() {
|
|
|
2221
2541
|
function useRedeemRewardPoints() {
|
|
2222
2542
|
const { client } = useEmporix();
|
|
2223
2543
|
const ctx = useCustomerOnlyCtx();
|
|
2224
|
-
const qc =
|
|
2225
|
-
return
|
|
2544
|
+
const qc = (0, import_react_query35.useQueryClient)();
|
|
2545
|
+
return (0, import_react_query35.useMutation)({
|
|
2226
2546
|
mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
|
|
2227
2547
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
|
|
2228
2548
|
});
|
|
2229
2549
|
}
|
|
2550
|
+
|
|
2551
|
+
// src/hooks/use-returns.ts
|
|
2552
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
2230
2553
|
var STALE2 = 3e4;
|
|
2231
2554
|
var INVALIDATE_KEY4 = ["emporix", "returns"];
|
|
2232
2555
|
function useMyReturns(opts = {}) {
|
|
2233
2556
|
const { client } = useEmporix();
|
|
2234
2557
|
const ctx = useCustomerOnlyCtx();
|
|
2235
|
-
return
|
|
2558
|
+
return (0, import_react_query36.useQuery)({
|
|
2236
2559
|
queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
2237
2560
|
queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
|
|
2238
2561
|
staleTime: STALE2
|
|
@@ -2241,7 +2564,7 @@ function useMyReturns(opts = {}) {
|
|
|
2241
2564
|
function useReturn(returnId) {
|
|
2242
2565
|
const { client } = useEmporix();
|
|
2243
2566
|
const ctx = useCustomerOnlyCtx();
|
|
2244
|
-
return
|
|
2567
|
+
return (0, import_react_query36.useQuery)({
|
|
2245
2568
|
queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
2246
2569
|
queryFn: () => client.returns.getReturn(returnId, ctx),
|
|
2247
2570
|
enabled: Boolean(returnId),
|
|
@@ -2251,13 +2574,17 @@ function useReturn(returnId) {
|
|
|
2251
2574
|
function useCreateReturn() {
|
|
2252
2575
|
const { client } = useEmporix();
|
|
2253
2576
|
const ctx = useCustomerOnlyCtx();
|
|
2254
|
-
const qc =
|
|
2255
|
-
return
|
|
2577
|
+
const qc = (0, import_react_query36.useQueryClient)();
|
|
2578
|
+
return (0, import_react_query36.useMutation)({
|
|
2256
2579
|
mutationFn: (input) => client.returns.createReturn(input, ctx),
|
|
2257
2580
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
|
|
2258
2581
|
});
|
|
2259
2582
|
}
|
|
2260
|
-
|
|
2583
|
+
|
|
2584
|
+
// src/errors.tsx
|
|
2585
|
+
var import_react10 = require("react");
|
|
2586
|
+
var import_emporix_sdk34 = require("@viu/emporix-sdk");
|
|
2587
|
+
var EmporixErrorBoundary = class extends import_react10.Component {
|
|
2261
2588
|
state = { error: null };
|
|
2262
2589
|
static getDerivedStateFromError(error) {
|
|
2263
2590
|
return { error };
|
|
@@ -2272,127 +2599,145 @@ var EmporixErrorBoundary = class extends react.Component {
|
|
|
2272
2599
|
};
|
|
2273
2600
|
function useEmporixErrorHandler(handlers) {
|
|
2274
2601
|
return (error) => {
|
|
2275
|
-
if (error instanceof
|
|
2276
|
-
else if (error instanceof
|
|
2602
|
+
if (error instanceof import_emporix_sdk34.EmporixAuthError) handlers.onAuthError?.(error);
|
|
2603
|
+
else if (error instanceof import_emporix_sdk34.EmporixError) handlers.onError?.(error);
|
|
2277
2604
|
};
|
|
2278
2605
|
}
|
|
2279
|
-
|
|
2606
|
+
|
|
2607
|
+
// src/ssr.ts
|
|
2608
|
+
var import_emporix_sdk35 = require("@viu/emporix-sdk");
|
|
2609
|
+
async function prefetchProduct(qc, client, productId, authCtx = import_emporix_sdk35.auth.anonymous(), opts = {}) {
|
|
2280
2610
|
await qc.prefetchQuery({
|
|
2281
|
-
queryKey:
|
|
2611
|
+
queryKey: emporixKey("product", [productId], {
|
|
2612
|
+
tenant: client.tenant,
|
|
2613
|
+
authKind: authCtx.kind,
|
|
2614
|
+
siteCode: opts.siteCode ?? null,
|
|
2615
|
+
language: opts.language ?? null
|
|
2616
|
+
}),
|
|
2282
2617
|
queryFn: () => client.products.get(productId, void 0, authCtx)
|
|
2283
2618
|
});
|
|
2284
2619
|
}
|
|
2285
|
-
async function prefetchCart(qc, client, cartId, authCtx) {
|
|
2620
|
+
async function prefetchCart(qc, client, cartId, authCtx, opts = {}) {
|
|
2286
2621
|
await qc.prefetchQuery({
|
|
2287
|
-
queryKey:
|
|
2622
|
+
queryKey: emporixKey("cart", [cartId, opts.activeCompanyId ?? null], {
|
|
2623
|
+
tenant: client.tenant,
|
|
2624
|
+
authKind: authCtx.kind,
|
|
2625
|
+
siteCode: opts.siteCode ?? null,
|
|
2626
|
+
language: opts.language ?? null
|
|
2627
|
+
}),
|
|
2288
2628
|
queryFn: () => client.carts.get(cartId, authCtx)
|
|
2289
2629
|
});
|
|
2290
2630
|
}
|
|
2291
2631
|
async function prefetchOrder(qc, client, orderId, authCtx, opts = {}) {
|
|
2292
2632
|
await qc.prefetchQuery({
|
|
2293
|
-
queryKey:
|
|
2633
|
+
queryKey: emporixKey("orders", [orderId], {
|
|
2634
|
+
tenant: client.tenant,
|
|
2635
|
+
authKind: authCtx.kind,
|
|
2636
|
+
language: opts.language ?? null
|
|
2637
|
+
}),
|
|
2294
2638
|
queryFn: () => client.orders.get(orderId, authCtx, opts.saasToken ? { saasToken: opts.saasToken } : {})
|
|
2295
2639
|
});
|
|
2296
2640
|
}
|
|
2297
|
-
|
|
2298
|
-
exports
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2641
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2642
|
+
0 && (module.exports = {
|
|
2643
|
+
CompanyContextProvider,
|
|
2644
|
+
EmporixCompanyContext,
|
|
2645
|
+
EmporixErrorBoundary,
|
|
2646
|
+
EmporixProvider,
|
|
2647
|
+
createCookieStorage,
|
|
2648
|
+
createLocalStorageStorage,
|
|
2649
|
+
createMemoryStorage,
|
|
2650
|
+
prefetchCart,
|
|
2651
|
+
prefetchOrder,
|
|
2652
|
+
prefetchProduct,
|
|
2653
|
+
useActiveCart,
|
|
2654
|
+
useActiveCompany,
|
|
2655
|
+
useActiveSite,
|
|
2656
|
+
useAddGroupMember,
|
|
2657
|
+
useAddToShoppingList,
|
|
2658
|
+
useAddressMutations,
|
|
2659
|
+
useAssignContact,
|
|
2660
|
+
useAvailabilities,
|
|
2661
|
+
useAvailability,
|
|
2662
|
+
useCancelOrder,
|
|
2663
|
+
useCart,
|
|
2664
|
+
useCartMutations,
|
|
2665
|
+
useCategories,
|
|
2666
|
+
useCategoriesInfinite,
|
|
2667
|
+
useCategory,
|
|
2668
|
+
useCategoryTree,
|
|
2669
|
+
useChangePassword,
|
|
2670
|
+
useCheckout,
|
|
2671
|
+
useCloudFunction,
|
|
2672
|
+
useCompany,
|
|
2673
|
+
useCompanyContacts,
|
|
2674
|
+
useCompanyGroups,
|
|
2675
|
+
useCompanyLocations,
|
|
2676
|
+
useCompanySwitcher,
|
|
2677
|
+
useCreateCart,
|
|
2678
|
+
useCreateCompany,
|
|
2679
|
+
useCreateLocation,
|
|
2680
|
+
useCreateReturn,
|
|
2681
|
+
useCreateShoppingList,
|
|
2682
|
+
useCustomerAddresses,
|
|
2683
|
+
useCustomerSession,
|
|
2684
|
+
useDefaultSite,
|
|
2685
|
+
useDeleteCompany,
|
|
2686
|
+
useDeleteLocation,
|
|
2687
|
+
useDeleteShoppingList,
|
|
2688
|
+
useEmporix,
|
|
2689
|
+
useEmporixErrorHandler,
|
|
2690
|
+
useEmporixTelemetry,
|
|
2691
|
+
useInvokeCloudFunction,
|
|
2692
|
+
useMatchPrices,
|
|
2693
|
+
useMatchPricesChunked,
|
|
2694
|
+
useMyCompanies,
|
|
2695
|
+
useMyOrders,
|
|
2696
|
+
useMyOrdersInfinite,
|
|
2697
|
+
useMyReturns,
|
|
2698
|
+
useMyRewardPoints,
|
|
2699
|
+
useMyRewardPointsSummary,
|
|
2700
|
+
useMySegmentCategories,
|
|
2701
|
+
useMySegmentCategoriesInfinite,
|
|
2702
|
+
useMySegmentCategoryTree,
|
|
2703
|
+
useMySegmentItems,
|
|
2704
|
+
useMySegmentProducts,
|
|
2705
|
+
useMySegmentProductsInfinite,
|
|
2706
|
+
useMySegments,
|
|
2707
|
+
useOrder,
|
|
2708
|
+
useOrderTransition,
|
|
2709
|
+
usePasswordReset,
|
|
2710
|
+
usePaymentModes,
|
|
2711
|
+
useProduct,
|
|
2712
|
+
useProductByCode,
|
|
2713
|
+
useProductMedia,
|
|
2714
|
+
useProductNameSearch,
|
|
2715
|
+
useProductSearch,
|
|
2716
|
+
useProducts,
|
|
2717
|
+
useProductsByCodes,
|
|
2718
|
+
useProductsInCategory,
|
|
2719
|
+
useProductsInCategoryInfinite,
|
|
2720
|
+
useProductsInfinite,
|
|
2721
|
+
useRedeemCoupon,
|
|
2722
|
+
useRedeemOptions,
|
|
2723
|
+
useRedeemRewardPoints,
|
|
2724
|
+
useRemoveFromShoppingList,
|
|
2725
|
+
useRemoveGroupMember,
|
|
2726
|
+
useReorder,
|
|
2727
|
+
useReturn,
|
|
2728
|
+
useSalesOrder,
|
|
2729
|
+
useSetShoppingListItemQuantity,
|
|
2730
|
+
useShoppingLists,
|
|
2731
|
+
useSiteContext,
|
|
2732
|
+
useSites,
|
|
2733
|
+
useSubcategories,
|
|
2734
|
+
useUnassignContact,
|
|
2735
|
+
useUpdateCompany,
|
|
2736
|
+
useUpdateContactAssignment,
|
|
2737
|
+
useUpdateCustomer,
|
|
2738
|
+
useUpdateLocation,
|
|
2739
|
+
useUpdateSalesOrder,
|
|
2740
|
+
useValidateCoupon,
|
|
2741
|
+
useVariantChildren
|
|
2742
|
+
});
|
|
2398
2743
|
//# sourceMappingURL=index.cjs.map
|