@viu/emporix-sdk-react 2.13.1 → 2.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/{chunk-VMDBYVWG.js → chunk-62GKMVS3.js} +30 -4
- package/dist/chunk-62GKMVS3.js.map +1 -0
- package/dist/{chunk-SXZCM2LE.js → chunk-IREROKYI.js} +658 -311
- package/dist/chunk-IREROKYI.js.map +1 -0
- package/dist/{chunk-4YDWCA7A.js → chunk-ZNE3J25W.js} +165 -107
- package/dist/chunk-ZNE3J25W.js.map +1 -0
- package/dist/hooks.cjs +751 -430
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +185 -4
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +950 -551
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -6
- package/dist/index.d.ts +40 -6
- package/dist/index.js +240 -8
- package/dist/index.js.map +1 -1
- package/dist/{provider-Bcb-tOpS.d.ts → provider-Cgm9QVoo.d.ts} +1 -1
- package/dist/{provider-Ddo7aSOI.d.cts → provider-DGjmBPMr.d.cts} +1 -1
- package/dist/provider.cjs +193 -123
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +12 -3
- package/dist/provider.js.map +1 -1
- package/dist/ssr.cjs +36 -5
- package/dist/ssr.cjs.map +1 -1
- package/dist/ssr.d.cts +22 -6
- package/dist/ssr.d.ts +22 -6
- package/dist/ssr.js +54 -1
- package/dist/ssr.js.map +1 -1
- package/dist/storage.cjs +58 -9
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +8 -2
- package/dist/storage.d.ts +8 -2
- package/dist/storage.js +15 -2
- package/dist/storage.js.map +1 -1
- package/dist/{use-returns-uZJiO46w.d.ts → use-returns-DrqdwizU.d.ts} +1 -1
- package/dist/{use-returns-DT98Ptod.d.cts → use-returns-fKPIgjmU.d.cts} +1 -1
- package/package.json +5 -4
- package/dist/chunk-4YDWCA7A.js.map +0 -1
- package/dist/chunk-SXZCM2LE.js.map +0 -1
- package/dist/chunk-TIS4BKHK.js +0 -25
- package/dist/chunk-TIS4BKHK.js.map +0 -1
- package/dist/chunk-VMDBYVWG.js.map +0 -1
package/dist/hooks.cjs
CHANGED
|
@@ -1,11 +1,133 @@
|
|
|
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/hooks/index.ts
|
|
22
|
+
var hooks_exports = {};
|
|
23
|
+
__export(hooks_exports, {
|
|
24
|
+
useActiveCart: () => useActiveCart,
|
|
25
|
+
useActiveSite: () => useActiveSite,
|
|
26
|
+
useAddGroupMember: () => useAddGroupMember,
|
|
27
|
+
useAddToShoppingList: () => useAddToShoppingList,
|
|
28
|
+
useAddressMutations: () => useAddressMutations,
|
|
29
|
+
useApproval: () => useApproval,
|
|
30
|
+
useApprovals: () => useApprovals,
|
|
31
|
+
useAssignContact: () => useAssignContact,
|
|
32
|
+
useAvailabilities: () => useAvailabilities,
|
|
33
|
+
useAvailability: () => useAvailability,
|
|
34
|
+
useCancelOrder: () => useCancelOrder,
|
|
35
|
+
useCart: () => useCart,
|
|
36
|
+
useCartMutations: () => useCartMutations,
|
|
37
|
+
useCategories: () => useCategories,
|
|
38
|
+
useCategoriesInfinite: () => useCategoriesInfinite,
|
|
39
|
+
useCategory: () => useCategory,
|
|
40
|
+
useCategoryTree: () => useCategoryTree,
|
|
41
|
+
useChangePassword: () => useChangePassword,
|
|
42
|
+
useCheckout: () => useCheckout,
|
|
43
|
+
useCloudFunction: () => useCloudFunction,
|
|
44
|
+
useCompany: () => useCompany,
|
|
45
|
+
useCompanyContacts: () => useCompanyContacts,
|
|
46
|
+
useCompanyGroups: () => useCompanyGroups,
|
|
47
|
+
useCompanyLocations: () => useCompanyLocations,
|
|
48
|
+
useCompanySwitcher: () => useCompanySwitcher,
|
|
49
|
+
useCreateApproval: () => useCreateApproval,
|
|
50
|
+
useCreateCart: () => useCreateCart,
|
|
51
|
+
useCreateCompany: () => useCreateCompany,
|
|
52
|
+
useCreateLocation: () => useCreateLocation,
|
|
53
|
+
useCreateReturn: () => useCreateReturn,
|
|
54
|
+
useCreateShoppingList: () => useCreateShoppingList,
|
|
55
|
+
useCustomerAddresses: () => useCustomerAddresses,
|
|
56
|
+
useCustomerSession: () => useCustomerSession,
|
|
57
|
+
useDefaultSite: () => useDefaultSite,
|
|
58
|
+
useDeleteCompany: () => useDeleteCompany,
|
|
59
|
+
useDeleteLocation: () => useDeleteLocation,
|
|
60
|
+
useDeleteShoppingList: () => useDeleteShoppingList,
|
|
61
|
+
useInvokeCloudFunction: () => useInvokeCloudFunction,
|
|
62
|
+
useMatchPrices: () => useMatchPrices,
|
|
63
|
+
useMatchPricesChunked: () => useMatchPricesChunked,
|
|
64
|
+
useMyCompanies: () => useMyCompanies,
|
|
65
|
+
useMyOrders: () => useMyOrders,
|
|
66
|
+
useMyOrdersInfinite: () => useMyOrdersInfinite,
|
|
67
|
+
useMyReturns: () => useMyReturns,
|
|
68
|
+
useMyRewardPoints: () => useMyRewardPoints,
|
|
69
|
+
useMyRewardPointsSummary: () => useMyRewardPointsSummary,
|
|
70
|
+
useMySegmentCategories: () => useMySegmentCategories,
|
|
71
|
+
useMySegmentCategoriesInfinite: () => useMySegmentCategoriesInfinite,
|
|
72
|
+
useMySegmentCategoryTree: () => useMySegmentCategoryTree,
|
|
73
|
+
useMySegmentItems: () => useMySegmentItems,
|
|
74
|
+
useMySegmentProducts: () => useMySegmentProducts,
|
|
75
|
+
useMySegmentProductsInfinite: () => useMySegmentProductsInfinite,
|
|
76
|
+
useMySegments: () => useMySegments,
|
|
77
|
+
useOrder: () => useOrder,
|
|
78
|
+
useOrderTransition: () => useOrderTransition,
|
|
79
|
+
usePasswordReset: () => usePasswordReset,
|
|
80
|
+
usePaymentModes: () => usePaymentModes,
|
|
81
|
+
useProduct: () => useProduct,
|
|
82
|
+
useProductByCode: () => useProductByCode,
|
|
83
|
+
useProductMedia: () => useProductMedia,
|
|
84
|
+
useProductNameSearch: () => useProductNameSearch,
|
|
85
|
+
useProductSearch: () => useProductSearch,
|
|
86
|
+
useProducts: () => useProducts,
|
|
87
|
+
useProductsByCodes: () => useProductsByCodes,
|
|
88
|
+
useProductsInCategory: () => useProductsInCategory,
|
|
89
|
+
useProductsInCategoryInfinite: () => useProductsInCategoryInfinite,
|
|
90
|
+
useProductsInfinite: () => useProductsInfinite,
|
|
91
|
+
useRedeemCoupon: () => useRedeemCoupon,
|
|
92
|
+
useRedeemOptions: () => useRedeemOptions,
|
|
93
|
+
useRedeemRewardPoints: () => useRedeemRewardPoints,
|
|
94
|
+
useRemoveFromShoppingList: () => useRemoveFromShoppingList,
|
|
95
|
+
useRemoveGroupMember: () => useRemoveGroupMember,
|
|
96
|
+
useReorder: () => useReorder,
|
|
97
|
+
useReturn: () => useReturn,
|
|
98
|
+
useSalesOrder: () => useSalesOrder,
|
|
99
|
+
useSetShoppingListItemQuantity: () => useSetShoppingListItemQuantity,
|
|
100
|
+
useShoppingLists: () => useShoppingLists,
|
|
101
|
+
useSiteContext: () => useSiteContext,
|
|
102
|
+
useSites: () => useSites,
|
|
103
|
+
useSubcategories: () => useSubcategories,
|
|
104
|
+
useUnassignContact: () => useUnassignContact,
|
|
105
|
+
useUpdateApproval: () => useUpdateApproval,
|
|
106
|
+
useUpdateCompany: () => useUpdateCompany,
|
|
107
|
+
useUpdateContactAssignment: () => useUpdateContactAssignment,
|
|
108
|
+
useUpdateCustomer: () => useUpdateCustomer,
|
|
109
|
+
useUpdateLocation: () => useUpdateLocation,
|
|
110
|
+
useUpdateSalesOrder: () => useUpdateSalesOrder,
|
|
111
|
+
useValidateCoupon: () => useValidateCoupon,
|
|
112
|
+
useVariantChildren: () => useVariantChildren
|
|
113
|
+
});
|
|
114
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
7
115
|
|
|
8
116
|
// src/hooks/use-customer-session.ts
|
|
117
|
+
var import_react3 = require("react");
|
|
118
|
+
var import_react_query3 = require("@tanstack/react-query");
|
|
119
|
+
var import_emporix_sdk3 = require("@viu/emporix-sdk");
|
|
120
|
+
|
|
121
|
+
// src/provider.tsx
|
|
122
|
+
var import_react2 = require("react");
|
|
123
|
+
var import_react_query2 = require("@tanstack/react-query");
|
|
124
|
+
var import_emporix_sdk2 = require("@viu/emporix-sdk");
|
|
125
|
+
|
|
126
|
+
// src/company-context.tsx
|
|
127
|
+
var import_react = require("react");
|
|
128
|
+
var import_react_query = require("@tanstack/react-query");
|
|
129
|
+
var import_emporix_sdk = require("@viu/emporix-sdk");
|
|
130
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
9
131
|
var NULL_CTX = {
|
|
10
132
|
activeCompany: null,
|
|
11
133
|
myCompanies: [],
|
|
@@ -18,14 +140,17 @@ var NULL_CTX = {
|
|
|
18
140
|
refetchMyCompanies: async () => {
|
|
19
141
|
}
|
|
20
142
|
};
|
|
21
|
-
var EmporixCompanyContext =
|
|
143
|
+
var EmporixCompanyContext = (0, import_react.createContext)(NULL_CTX);
|
|
22
144
|
function useActiveCompany() {
|
|
23
|
-
return
|
|
145
|
+
return (0, import_react.useContext)(EmporixCompanyContext);
|
|
24
146
|
}
|
|
25
|
-
|
|
26
|
-
|
|
147
|
+
|
|
148
|
+
// src/provider.tsx
|
|
149
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
150
|
+
var EmporixContext = (0, import_react2.createContext)(null);
|
|
151
|
+
var EmporixSiteContext = (0, import_react2.createContext)(null);
|
|
27
152
|
function useEmporix() {
|
|
28
|
-
const ctx =
|
|
153
|
+
const ctx = (0, import_react2.useContext)(EmporixContext);
|
|
29
154
|
if (!ctx) throw new Error("useEmporix must be used within an EmporixProvider");
|
|
30
155
|
return ctx;
|
|
31
156
|
}
|
|
@@ -63,8 +188,8 @@ function getCustomerSessionStore(storage) {
|
|
|
63
188
|
if (existing) return existing;
|
|
64
189
|
let state = {
|
|
65
190
|
token: storage.getCustomerToken(),
|
|
66
|
-
refreshToken:
|
|
67
|
-
saasToken: null
|
|
191
|
+
refreshToken: storage.getRefreshToken(),
|
|
192
|
+
saasToken: storage.getSaasToken?.() ?? null
|
|
68
193
|
};
|
|
69
194
|
const listeners = /* @__PURE__ */ new Set();
|
|
70
195
|
const store = {
|
|
@@ -82,6 +207,9 @@ function getCustomerSessionStore(storage) {
|
|
|
82
207
|
};
|
|
83
208
|
}
|
|
84
209
|
};
|
|
210
|
+
storage.subscribe?.((t) => {
|
|
211
|
+
store.setState((s) => s.token === t ? s : { ...s, token: t });
|
|
212
|
+
});
|
|
85
213
|
stores.set(storage, store);
|
|
86
214
|
return store;
|
|
87
215
|
}
|
|
@@ -94,27 +222,25 @@ var EMPTY_SESSION = {
|
|
|
94
222
|
};
|
|
95
223
|
function useCustomerSession() {
|
|
96
224
|
const { client, storage } = useEmporix();
|
|
97
|
-
const qc =
|
|
98
|
-
const siteCtx =
|
|
99
|
-
const store =
|
|
100
|
-
const session =
|
|
225
|
+
const qc = (0, import_react_query3.useQueryClient)();
|
|
226
|
+
const siteCtx = (0, import_react3.useContext)(EmporixSiteContext);
|
|
227
|
+
const store = (0, import_react3.useMemo)(() => getCustomerSessionStore(storage), [storage]);
|
|
228
|
+
const session = (0, import_react3.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
101
229
|
const setSession = store.setState;
|
|
102
|
-
|
|
103
|
-
return storage.subscribe?.((t) => setSession((s) => ({ ...s, token: t })));
|
|
104
|
-
}, [storage, setSession]);
|
|
105
|
-
const meQuery = reactQuery.useQuery({
|
|
230
|
+
const meQuery = (0, import_react_query3.useQuery)({
|
|
106
231
|
queryKey: ["emporix", "customer", "me", { tenant: client.tenant, hasToken: session.token !== null }],
|
|
107
232
|
enabled: session.token !== null,
|
|
108
|
-
queryFn: () => client.customers.me(
|
|
233
|
+
queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(session.token)),
|
|
109
234
|
// 30s — matches Balanced default. Lets honourPreferredSite's fetchQuery
|
|
110
235
|
// (with staleTime: Infinity) reuse the cache instead of refetching.
|
|
111
236
|
staleTime: 3e4
|
|
112
237
|
});
|
|
113
|
-
const login =
|
|
238
|
+
const login = (0, import_react3.useCallback)(
|
|
114
239
|
async (input) => {
|
|
115
240
|
const result = await client.customers.login(input);
|
|
116
241
|
storage.setCustomerToken(result.customerToken);
|
|
117
242
|
storage.setRefreshToken(result.refreshToken || null);
|
|
243
|
+
storage.setSaasToken?.(result.saasToken || null);
|
|
118
244
|
storage.setAnonymousSession(null);
|
|
119
245
|
setSession({
|
|
120
246
|
token: result.customerToken,
|
|
@@ -138,16 +264,17 @@ function useCustomerSession() {
|
|
|
138
264
|
},
|
|
139
265
|
[client, storage, qc, siteCtx, setSession]
|
|
140
266
|
);
|
|
141
|
-
const signup =
|
|
267
|
+
const signup = (0, import_react3.useCallback)(
|
|
142
268
|
async (input) => {
|
|
143
269
|
await client.customers.signup(input);
|
|
144
270
|
},
|
|
145
271
|
[client]
|
|
146
272
|
);
|
|
147
|
-
const applySession =
|
|
273
|
+
const applySession = (0, import_react3.useCallback)(
|
|
148
274
|
async (incoming) => {
|
|
149
275
|
storage.setCustomerToken(incoming.customerToken);
|
|
150
276
|
storage.setRefreshToken(incoming.refreshToken || null);
|
|
277
|
+
storage.setSaasToken?.(incoming.saasToken || null);
|
|
151
278
|
storage.setAnonymousSession(null);
|
|
152
279
|
setSession({
|
|
153
280
|
token: incoming.customerToken,
|
|
@@ -171,37 +298,37 @@ function useCustomerSession() {
|
|
|
171
298
|
},
|
|
172
299
|
[client, storage, qc, siteCtx, setSession]
|
|
173
300
|
);
|
|
174
|
-
const socialLogin =
|
|
301
|
+
const socialLogin = (0, import_react3.useCallback)(
|
|
175
302
|
async (input) => {
|
|
176
303
|
await applySession(await client.customers.socialLogin(input));
|
|
177
304
|
},
|
|
178
305
|
[client, applySession]
|
|
179
306
|
);
|
|
180
|
-
const exchangeToken =
|
|
307
|
+
const exchangeToken = (0, import_react3.useCallback)(
|
|
181
308
|
async (input) => {
|
|
182
309
|
await applySession(await client.customers.exchangeToken(input));
|
|
183
310
|
},
|
|
184
311
|
[client, applySession]
|
|
185
312
|
);
|
|
186
|
-
const logout =
|
|
313
|
+
const logout = (0, import_react3.useCallback)(async () => {
|
|
187
314
|
if (session.token) {
|
|
188
315
|
try {
|
|
189
|
-
await client.customers.logout(
|
|
316
|
+
await client.customers.logout(import_emporix_sdk3.auth.customer(session.token));
|
|
190
317
|
} catch {
|
|
191
318
|
}
|
|
192
319
|
}
|
|
193
320
|
storage.setCustomerToken(null);
|
|
194
321
|
storage.setRefreshToken(null);
|
|
322
|
+
storage.setSaasToken?.(null);
|
|
195
323
|
storage.setActiveLegalEntityId(null);
|
|
196
324
|
storage.setCartId(null);
|
|
197
325
|
setSession(EMPTY_SESSION);
|
|
198
|
-
qc.removeQueries({ queryKey: ["emporix"
|
|
199
|
-
qc.removeQueries({ queryKey: ["emporix", "cart"] });
|
|
326
|
+
qc.removeQueries({ queryKey: ["emporix"] });
|
|
200
327
|
}, [client, session.token, storage, qc, setSession]);
|
|
201
|
-
const refresh =
|
|
328
|
+
const refresh = (0, import_react3.useCallback)(async () => {
|
|
202
329
|
await meQuery.refetch();
|
|
203
330
|
}, [meQuery]);
|
|
204
|
-
const refreshSession =
|
|
331
|
+
const refreshSession = (0, import_react3.useCallback)(async () => {
|
|
205
332
|
if (!session.refreshToken) return;
|
|
206
333
|
const refreshed = await client.customers.refresh({
|
|
207
334
|
refreshToken: session.refreshToken,
|
|
@@ -209,6 +336,7 @@ function useCustomerSession() {
|
|
|
209
336
|
});
|
|
210
337
|
storage.setCustomerToken(refreshed.customerToken);
|
|
211
338
|
if (refreshed.refreshToken) storage.setRefreshToken(refreshed.refreshToken);
|
|
339
|
+
if (refreshed.saasToken) storage.setSaasToken?.(refreshed.saasToken);
|
|
212
340
|
setSession((s) => ({
|
|
213
341
|
token: refreshed.customerToken,
|
|
214
342
|
refreshToken: refreshed.refreshToken || s.refreshToken,
|
|
@@ -244,7 +372,7 @@ async function honourPreferredSite(opts) {
|
|
|
244
372
|
"me",
|
|
245
373
|
{ tenant: client.tenant, hasToken: true }
|
|
246
374
|
],
|
|
247
|
-
queryFn: () => client.customers.me(
|
|
375
|
+
queryFn: () => client.customers.me(import_emporix_sdk3.auth.customer(customerToken)),
|
|
248
376
|
// Reuse whatever meQuery already wrote (login flow runs meQuery in
|
|
249
377
|
// parallel). Without this, fetchQuery refetches if meQuery's data is
|
|
250
378
|
// already stale (default staleTime: 0 on meQuery).
|
|
@@ -261,7 +389,7 @@ async function onboardCustomerCart(opts) {
|
|
|
261
389
|
const { qc, client, storage, customerToken } = opts;
|
|
262
390
|
const siteCode = client.config?.credentials?.storefront?.context?.siteCode;
|
|
263
391
|
if (!siteCode) return;
|
|
264
|
-
const ctx =
|
|
392
|
+
const ctx = import_emporix_sdk3.auth.customer(customerToken);
|
|
265
393
|
try {
|
|
266
394
|
const customerCart = await bootstrapCart({
|
|
267
395
|
qc,
|
|
@@ -279,22 +407,53 @@ async function onboardCustomerCart(opts) {
|
|
|
279
407
|
} catch {
|
|
280
408
|
}
|
|
281
409
|
}
|
|
282
|
-
|
|
410
|
+
|
|
411
|
+
// src/hooks/use-products.ts
|
|
412
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
413
|
+
var import_emporix_sdk6 = require("@viu/emporix-sdk");
|
|
414
|
+
|
|
415
|
+
// src/hooks/internal/use-read-auth.ts
|
|
416
|
+
var import_emporix_sdk4 = require("@viu/emporix-sdk");
|
|
417
|
+
|
|
418
|
+
// src/hooks/internal/use-storage-snapshot.ts
|
|
419
|
+
var import_react4 = require("react");
|
|
420
|
+
function useCustomerToken() {
|
|
421
|
+
const { storage } = useEmporix();
|
|
422
|
+
const store = (0, import_react4.useMemo)(() => getCustomerSessionStore(storage), [storage]);
|
|
423
|
+
const getToken = (0, import_react4.useCallback)(() => store.getSnapshot().token, [store]);
|
|
424
|
+
return (0, import_react4.useSyncExternalStore)(store.subscribe, getToken, getToken);
|
|
425
|
+
}
|
|
426
|
+
function useCartId() {
|
|
283
427
|
const { storage } = useEmporix();
|
|
428
|
+
const subscribe = (0, import_react4.useCallback)(
|
|
429
|
+
(onChange) => storage.subscribeAll?.((key) => {
|
|
430
|
+
if (key === "cartId") onChange();
|
|
431
|
+
}) ?? (() => {
|
|
432
|
+
}),
|
|
433
|
+
[storage]
|
|
434
|
+
);
|
|
435
|
+
const getCartId = (0, import_react4.useCallback)(() => storage.getCartId(), [storage]);
|
|
436
|
+
return (0, import_react4.useSyncExternalStore)(subscribe, getCartId, getCartId);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// src/hooks/internal/use-read-auth.ts
|
|
440
|
+
function useReadAuth(override) {
|
|
441
|
+
const token = useCustomerToken();
|
|
284
442
|
if (override) return { ctx: override };
|
|
285
|
-
|
|
286
|
-
return token ? { ctx: emporixSdk.auth.customer(token) } : { ctx: emporixSdk.auth.anonymous() };
|
|
443
|
+
return token ? { ctx: import_emporix_sdk4.auth.customer(token) } : { ctx: import_emporix_sdk4.auth.anonymous() };
|
|
287
444
|
}
|
|
288
445
|
function useCustomerOnlyCtx() {
|
|
289
|
-
const
|
|
290
|
-
const token = storage.getCustomerToken();
|
|
446
|
+
const token = useCustomerToken();
|
|
291
447
|
if (!token) {
|
|
292
448
|
throw new Error("Requires a logged-in customer (no token in storage)");
|
|
293
449
|
}
|
|
294
|
-
return
|
|
450
|
+
return import_emporix_sdk4.auth.customer(token);
|
|
295
451
|
}
|
|
452
|
+
|
|
453
|
+
// src/hooks/internal/use-read-site.ts
|
|
454
|
+
var import_react5 = require("react");
|
|
296
455
|
function useReadSite() {
|
|
297
|
-
const ctx =
|
|
456
|
+
const ctx = (0, import_react5.useContext)(EmporixSiteContext);
|
|
298
457
|
return { siteCode: ctx?.siteCode ?? null, language: ctx?.language ?? null };
|
|
299
458
|
}
|
|
300
459
|
|
|
@@ -312,8 +471,11 @@ function emporixKey(resource, args, context) {
|
|
|
312
471
|
}
|
|
313
472
|
return ["emporix", resource, ...args, meta];
|
|
314
473
|
}
|
|
474
|
+
|
|
475
|
+
// src/hooks/internal/use-emporix-infinite.ts
|
|
476
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
315
477
|
function useEmporixInfinite(opts) {
|
|
316
|
-
return
|
|
478
|
+
return (0, import_react_query4.useInfiniteQuery)({
|
|
317
479
|
queryKey: opts.queryKey,
|
|
318
480
|
initialPageParam: 1,
|
|
319
481
|
queryFn: ({ pageParam }) => opts.fetchPage(pageParam),
|
|
@@ -323,25 +485,54 @@ function useEmporixInfinite(opts) {
|
|
|
323
485
|
});
|
|
324
486
|
}
|
|
325
487
|
|
|
488
|
+
// src/hooks/internal/use-emporix-query.ts
|
|
489
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
490
|
+
var import_emporix_sdk5 = require("@viu/emporix-sdk");
|
|
491
|
+
function useEmporixQuery(cfg) {
|
|
492
|
+
const { client } = useEmporix();
|
|
493
|
+
const token = useCustomerToken();
|
|
494
|
+
const { siteCode, language } = useReadSite();
|
|
495
|
+
const authOverride = cfg.mode === "read-auth" ? cfg.authOverride : void 0;
|
|
496
|
+
const readCtx = authOverride ?? (token ? import_emporix_sdk5.auth.customer(token) : import_emporix_sdk5.auth.anonymous());
|
|
497
|
+
const authKind = cfg.mode === "customer" ? token ? "customer" : "anonymous" : readCtx.kind;
|
|
498
|
+
const resolvedCtx = cfg.mode === "customer" ? import_emporix_sdk5.auth.customer(token) : readCtx;
|
|
499
|
+
const siteMeta = cfg.site === "full" ? { siteCode, language } : cfg.site === "language" ? { language } : {};
|
|
500
|
+
const enabled = (cfg.enabled ?? true) && (cfg.mode === "customer" ? token !== null : true);
|
|
501
|
+
return (0, import_react_query5.useQuery)({
|
|
502
|
+
queryKey: emporixKey(cfg.resource, cfg.args, {
|
|
503
|
+
tenant: client.tenant,
|
|
504
|
+
authKind,
|
|
505
|
+
...siteMeta
|
|
506
|
+
}),
|
|
507
|
+
queryFn: () => cfg.queryFn(resolvedCtx),
|
|
508
|
+
enabled,
|
|
509
|
+
...cfg.staleTime !== void 0 ? { staleTime: cfg.staleTime } : {}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
326
513
|
// src/hooks/use-products.ts
|
|
327
514
|
var PRODUCTS_STALE_TIME = 6e4;
|
|
328
515
|
function useProduct(productId, options = {}) {
|
|
329
516
|
const { client } = useEmporix();
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
517
|
+
return useEmporixQuery({
|
|
518
|
+
mode: "read-auth",
|
|
519
|
+
site: "full",
|
|
520
|
+
resource: "product",
|
|
521
|
+
args: [productId],
|
|
522
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
523
|
+
queryFn: (ctx) => client.products.get(productId, void 0, ctx),
|
|
335
524
|
staleTime: PRODUCTS_STALE_TIME
|
|
336
525
|
});
|
|
337
526
|
}
|
|
338
527
|
function useProducts(params = {}, options = {}) {
|
|
339
528
|
const { client } = useEmporix();
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
529
|
+
return useEmporixQuery({
|
|
530
|
+
mode: "read-auth",
|
|
531
|
+
site: "full",
|
|
532
|
+
resource: "products",
|
|
533
|
+
args: [params],
|
|
534
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
535
|
+
queryFn: (ctx) => client.products.list(params, ctx),
|
|
345
536
|
staleTime: PRODUCTS_STALE_TIME
|
|
346
537
|
});
|
|
347
538
|
}
|
|
@@ -360,50 +551,53 @@ function useProductsInfinite(params = {}, options = {}) {
|
|
|
360
551
|
}
|
|
361
552
|
function useProductByCode(code, options = {}) {
|
|
362
553
|
const { client } = useEmporix();
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
554
|
+
return useEmporixQuery({
|
|
555
|
+
mode: "read-auth",
|
|
556
|
+
site: "full",
|
|
557
|
+
resource: "product-by-code",
|
|
558
|
+
args: [code],
|
|
559
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
367
560
|
enabled: typeof code === "string" && code !== "",
|
|
368
|
-
queryFn: () => client.products.getByCode(code, ctx),
|
|
561
|
+
queryFn: (ctx) => client.products.getByCode(code, ctx),
|
|
369
562
|
staleTime: PRODUCTS_STALE_TIME
|
|
370
563
|
});
|
|
371
564
|
}
|
|
372
565
|
function useProductSearch(query, params = {}, options = {}) {
|
|
373
566
|
const { client } = useEmporix();
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
567
|
+
return useEmporixQuery({
|
|
568
|
+
mode: "read-auth",
|
|
569
|
+
site: "full",
|
|
570
|
+
resource: "product-search",
|
|
571
|
+
args: [query, params],
|
|
572
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
378
573
|
enabled: typeof query === "string" && query.trim() !== "",
|
|
379
|
-
queryFn: () => client.products.search(query, params, ctx),
|
|
574
|
+
queryFn: (ctx) => client.products.search(query, params, ctx),
|
|
380
575
|
staleTime: PRODUCTS_STALE_TIME
|
|
381
576
|
});
|
|
382
577
|
}
|
|
383
578
|
function useProductNameSearch(term, params = {}, options = {}) {
|
|
384
579
|
const { client } = useEmporix();
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
580
|
+
return useEmporixQuery({
|
|
581
|
+
mode: "read-auth",
|
|
582
|
+
site: "full",
|
|
583
|
+
resource: "product-name-search",
|
|
584
|
+
args: [term, params],
|
|
585
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
389
586
|
enabled: typeof term === "string" && term.trim() !== "",
|
|
390
|
-
queryFn: () => client.products.searchByName(term, params, ctx),
|
|
587
|
+
queryFn: (ctx) => client.products.searchByName(term, params, ctx),
|
|
391
588
|
staleTime: PRODUCTS_STALE_TIME
|
|
392
589
|
});
|
|
393
590
|
}
|
|
394
591
|
function useProductsByCodes(codes, options = {}) {
|
|
395
592
|
const { client } = useEmporix();
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
siteCode,
|
|
403
|
-
language
|
|
404
|
-
}),
|
|
593
|
+
return useEmporixQuery({
|
|
594
|
+
mode: "read-auth",
|
|
595
|
+
site: "full",
|
|
596
|
+
resource: "products-by-codes",
|
|
597
|
+
args: [codes, options.chunkSize],
|
|
598
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
405
599
|
enabled: codes.length > 0,
|
|
406
|
-
queryFn: () => client.products.searchByCodes(
|
|
600
|
+
queryFn: (ctx) => client.products.searchByCodes(
|
|
407
601
|
codes,
|
|
408
602
|
options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
|
|
409
603
|
ctx
|
|
@@ -411,13 +605,17 @@ function useProductsByCodes(codes, options = {}) {
|
|
|
411
605
|
staleTime: 3e4
|
|
412
606
|
});
|
|
413
607
|
}
|
|
608
|
+
|
|
609
|
+
// src/hooks/use-shopping-lists.ts
|
|
610
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
611
|
+
var import_emporix_sdk7 = require("@viu/emporix-sdk");
|
|
414
612
|
var SHOPPING_LIST_STALE_TIME = 3e4;
|
|
415
613
|
var INVALIDATE_KEY = ["emporix", "shopping-lists"];
|
|
416
614
|
function useShoppingLists(opts = {}) {
|
|
417
615
|
const { client } = useEmporix();
|
|
418
616
|
const ctx = useCustomerOnlyCtx();
|
|
419
617
|
const { siteCode, language } = useReadSite();
|
|
420
|
-
return
|
|
618
|
+
return (0, import_react_query7.useQuery)({
|
|
421
619
|
queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
|
|
422
620
|
queryFn: () => client.shoppingLists.list(ctx, opts),
|
|
423
621
|
staleTime: SHOPPING_LIST_STALE_TIME
|
|
@@ -426,8 +624,8 @@ function useShoppingLists(opts = {}) {
|
|
|
426
624
|
function useCreateShoppingList() {
|
|
427
625
|
const { client } = useEmporix();
|
|
428
626
|
const ctx = useCustomerOnlyCtx();
|
|
429
|
-
const qc =
|
|
430
|
-
return
|
|
627
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
628
|
+
return (0, import_react_query7.useMutation)({
|
|
431
629
|
mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
|
|
432
630
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
433
631
|
});
|
|
@@ -435,8 +633,8 @@ function useCreateShoppingList() {
|
|
|
435
633
|
function useDeleteShoppingList() {
|
|
436
634
|
const { client } = useEmporix();
|
|
437
635
|
const ctx = useCustomerOnlyCtx();
|
|
438
|
-
const qc =
|
|
439
|
-
return
|
|
636
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
637
|
+
return (0, import_react_query7.useMutation)({
|
|
440
638
|
mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
|
|
441
639
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
442
640
|
});
|
|
@@ -444,8 +642,8 @@ function useDeleteShoppingList() {
|
|
|
444
642
|
function useAddToShoppingList() {
|
|
445
643
|
const { client } = useEmporix();
|
|
446
644
|
const ctx = useCustomerOnlyCtx();
|
|
447
|
-
const qc =
|
|
448
|
-
return
|
|
645
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
646
|
+
return (0, import_react_query7.useMutation)({
|
|
449
647
|
mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
|
|
450
648
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
451
649
|
});
|
|
@@ -453,8 +651,8 @@ function useAddToShoppingList() {
|
|
|
453
651
|
function useRemoveFromShoppingList() {
|
|
454
652
|
const { client } = useEmporix();
|
|
455
653
|
const ctx = useCustomerOnlyCtx();
|
|
456
|
-
const qc =
|
|
457
|
-
return
|
|
654
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
655
|
+
return (0, import_react_query7.useMutation)({
|
|
458
656
|
mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
|
|
459
657
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
460
658
|
});
|
|
@@ -462,25 +660,27 @@ function useRemoveFromShoppingList() {
|
|
|
462
660
|
function useSetShoppingListItemQuantity() {
|
|
463
661
|
const { client } = useEmporix();
|
|
464
662
|
const ctx = useCustomerOnlyCtx();
|
|
465
|
-
const qc =
|
|
466
|
-
return
|
|
663
|
+
const qc = (0, import_react_query7.useQueryClient)();
|
|
664
|
+
return (0, import_react_query7.useMutation)({
|
|
467
665
|
mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
|
|
468
666
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
|
|
469
667
|
});
|
|
470
668
|
}
|
|
669
|
+
|
|
670
|
+
// src/hooks/use-variant-children.ts
|
|
671
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
672
|
+
var import_emporix_sdk8 = require("@viu/emporix-sdk");
|
|
471
673
|
var VARIANT_CHILDREN_STALE_TIME = 6e4;
|
|
472
674
|
function useVariantChildren(parentVariantId, options = {}) {
|
|
473
675
|
const { client } = useEmporix();
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
{ tenant: client.tenant, authKind: ctx.kind, siteCode, language }
|
|
481
|
-
),
|
|
676
|
+
return useEmporixQuery({
|
|
677
|
+
mode: "read-auth",
|
|
678
|
+
site: "full",
|
|
679
|
+
resource: "variant-children",
|
|
680
|
+
args: [parentVariantId, { pageSize: options.pageSize }],
|
|
681
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
482
682
|
enabled: typeof parentVariantId === "string" && parentVariantId !== "",
|
|
483
|
-
queryFn: () => client.products.listVariantChildren(
|
|
683
|
+
queryFn: (ctx) => client.products.listVariantChildren(
|
|
484
684
|
parentVariantId,
|
|
485
685
|
options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
486
686
|
ctx
|
|
@@ -488,35 +688,45 @@ function useVariantChildren(parentVariantId, options = {}) {
|
|
|
488
688
|
staleTime: VARIANT_CHILDREN_STALE_TIME
|
|
489
689
|
});
|
|
490
690
|
}
|
|
691
|
+
|
|
692
|
+
// src/hooks/use-categories.ts
|
|
693
|
+
var import_react_query9 = require("@tanstack/react-query");
|
|
694
|
+
var import_emporix_sdk9 = require("@viu/emporix-sdk");
|
|
491
695
|
var CATEGORIES_STALE_TIME = 5 * 6e4;
|
|
492
696
|
function useCategory(categoryId, options = {}) {
|
|
493
697
|
const { client } = useEmporix();
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
698
|
+
return useEmporixQuery({
|
|
699
|
+
mode: "read-auth",
|
|
700
|
+
site: "full",
|
|
701
|
+
resource: "category",
|
|
702
|
+
args: [categoryId],
|
|
703
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
704
|
+
queryFn: (ctx) => client.categories.get(categoryId, ctx),
|
|
499
705
|
staleTime: CATEGORIES_STALE_TIME
|
|
500
706
|
});
|
|
501
707
|
}
|
|
502
708
|
function useSubcategories(categoryId, params = {}, options = {}) {
|
|
503
709
|
const { client } = useEmporix();
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
710
|
+
return useEmporixQuery({
|
|
711
|
+
mode: "read-auth",
|
|
712
|
+
site: "full",
|
|
713
|
+
resource: "subcategories",
|
|
714
|
+
args: [categoryId ?? null, params],
|
|
715
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
508
716
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
509
|
-
queryFn: () => client.categories.subcategories(categoryId, params, ctx),
|
|
717
|
+
queryFn: (ctx) => client.categories.subcategories(categoryId, params, ctx),
|
|
510
718
|
staleTime: CATEGORIES_STALE_TIME
|
|
511
719
|
});
|
|
512
720
|
}
|
|
513
721
|
function useCategories(params = {}, options = {}) {
|
|
514
722
|
const { client } = useEmporix();
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
723
|
+
return useEmporixQuery({
|
|
724
|
+
mode: "read-auth",
|
|
725
|
+
site: "full",
|
|
726
|
+
resource: "categories",
|
|
727
|
+
args: [params],
|
|
728
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
729
|
+
queryFn: (ctx) => client.categories.list(params, ctx),
|
|
520
730
|
staleTime: CATEGORIES_STALE_TIME
|
|
521
731
|
});
|
|
522
732
|
}
|
|
@@ -535,22 +745,26 @@ function useCategoriesInfinite(params = {}, options = {}) {
|
|
|
535
745
|
}
|
|
536
746
|
function useCategoryTree(options = {}) {
|
|
537
747
|
const { client } = useEmporix();
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
748
|
+
return useEmporixQuery({
|
|
749
|
+
mode: "read-auth",
|
|
750
|
+
site: "full",
|
|
751
|
+
resource: "category-tree",
|
|
752
|
+
args: [],
|
|
753
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
754
|
+
queryFn: (ctx) => client.categories.tree(ctx),
|
|
543
755
|
staleTime: CATEGORIES_STALE_TIME
|
|
544
756
|
});
|
|
545
757
|
}
|
|
546
758
|
function useProductsInCategory(categoryId, params = {}, options = {}) {
|
|
547
759
|
const { client } = useEmporix();
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
760
|
+
return useEmporixQuery({
|
|
761
|
+
mode: "read-auth",
|
|
762
|
+
site: "full",
|
|
763
|
+
resource: "products-in-category",
|
|
764
|
+
args: [categoryId, params],
|
|
765
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
552
766
|
enabled: typeof categoryId === "string" && categoryId !== "",
|
|
553
|
-
queryFn: () => client.categories.productsIn(categoryId, params, ctx),
|
|
767
|
+
queryFn: (ctx) => client.categories.productsIn(categoryId, params, ctx),
|
|
554
768
|
staleTime: CATEGORIES_STALE_TIME
|
|
555
769
|
});
|
|
556
770
|
}
|
|
@@ -569,32 +783,36 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
|
|
|
569
783
|
staleTime: CATEGORIES_STALE_TIME
|
|
570
784
|
});
|
|
571
785
|
}
|
|
786
|
+
|
|
787
|
+
// src/hooks/use-cart.ts
|
|
788
|
+
var import_react6 = require("react");
|
|
789
|
+
var import_react_query10 = require("@tanstack/react-query");
|
|
790
|
+
var import_emporix_sdk10 = require("@viu/emporix-sdk");
|
|
572
791
|
function useCart(cartId, options = {}) {
|
|
573
|
-
const { client
|
|
574
|
-
const { ctx } = useReadAuth(options.auth);
|
|
575
|
-
const { siteCode, language } = useReadSite();
|
|
792
|
+
const { client } = useEmporix();
|
|
576
793
|
const { activeCompany } = useActiveCompany();
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
794
|
+
const storedCartId = useCartId();
|
|
795
|
+
const resolvedId = cartId ?? storedCartId ?? void 0;
|
|
796
|
+
return useEmporixQuery({
|
|
797
|
+
mode: "read-auth",
|
|
798
|
+
site: "full",
|
|
799
|
+
resource: "cart",
|
|
800
|
+
args: [resolvedId ?? null, activeCompany?.id ?? null],
|
|
801
|
+
...options.auth ? { authOverride: options.auth } : {},
|
|
584
802
|
enabled: resolvedId !== void 0,
|
|
585
|
-
queryFn: () => client.carts.get(resolvedId, ctx)
|
|
803
|
+
queryFn: (ctx) => client.carts.get(resolvedId, ctx)
|
|
586
804
|
});
|
|
587
805
|
}
|
|
588
806
|
function useCartMutations(cartId) {
|
|
589
807
|
const { client, storage } = useEmporix();
|
|
590
|
-
const qc =
|
|
808
|
+
const qc = (0, import_react_query10.useQueryClient)();
|
|
591
809
|
const { ctx } = useReadAuth();
|
|
592
810
|
const { siteCode, language } = useReadSite();
|
|
593
811
|
const { activeCompany } = useActiveCompany();
|
|
594
812
|
const resolveId = () => {
|
|
595
813
|
const id = cartId ?? storage.getCartId();
|
|
596
814
|
if (!id) {
|
|
597
|
-
throw new
|
|
815
|
+
throw new import_emporix_sdk10.EmporixError(
|
|
598
816
|
"useCartMutations: no cartId available \u2014 pass one explicitly or call useActiveCart({ create: true }) first"
|
|
599
817
|
);
|
|
600
818
|
}
|
|
@@ -606,7 +824,7 @@ function useCartMutations(cartId) {
|
|
|
606
824
|
{ tenant: client.tenant, authKind: ctx.kind, siteCode, language }
|
|
607
825
|
);
|
|
608
826
|
function make(run, optimistic) {
|
|
609
|
-
return
|
|
827
|
+
return (0, import_react_query10.useMutation)({
|
|
610
828
|
mutationFn: async (vars) => run(resolveId(), vars),
|
|
611
829
|
onMutate: async (vars) => {
|
|
612
830
|
const id = resolveId();
|
|
@@ -663,9 +881,9 @@ function useCartMutations(cartId) {
|
|
|
663
881
|
}
|
|
664
882
|
function useCreateCart() {
|
|
665
883
|
const { client, storage } = useEmporix();
|
|
666
|
-
const qc =
|
|
884
|
+
const qc = (0, import_react_query10.useQueryClient)();
|
|
667
885
|
const { ctx } = useReadAuth();
|
|
668
|
-
return
|
|
886
|
+
return (0, import_react_query10.useMutation)({
|
|
669
887
|
mutationFn: (input) => client.carts.create(input, ctx),
|
|
670
888
|
onSuccess: async (cart) => {
|
|
671
889
|
if (cart.cartId) storage.setCartId(cart.cartId);
|
|
@@ -675,21 +893,13 @@ function useCreateCart() {
|
|
|
675
893
|
}
|
|
676
894
|
function useActiveCart(opts) {
|
|
677
895
|
const { client, storage } = useEmporix();
|
|
678
|
-
const qc =
|
|
896
|
+
const qc = (0, import_react_query10.useQueryClient)();
|
|
679
897
|
const { ctx } = useReadAuth(opts?.auth);
|
|
680
898
|
const { siteCode: activeSite } = useReadSite();
|
|
681
899
|
const { activeCompany } = useActiveCompany();
|
|
682
|
-
const
|
|
900
|
+
const cartId = useCartId();
|
|
683
901
|
const effectiveLegalEntityId = opts?.legalEntityId ?? activeCompany?.id;
|
|
684
|
-
|
|
685
|
-
if (!storage.subscribeAll) return;
|
|
686
|
-
return storage.subscribeAll((key) => {
|
|
687
|
-
if (key !== "cartId") return;
|
|
688
|
-
const next = storage.getCartId();
|
|
689
|
-
setCartId((prev) => prev === next ? prev : next);
|
|
690
|
-
});
|
|
691
|
-
}, [storage]);
|
|
692
|
-
react.useEffect(() => {
|
|
902
|
+
(0, import_react6.useEffect)(() => {
|
|
693
903
|
if (cartId !== null) return;
|
|
694
904
|
if (!opts?.create) return;
|
|
695
905
|
const siteCode = activeSite ?? client.config?.credentials?.storefront?.context?.siteCode;
|
|
@@ -706,7 +916,6 @@ function useActiveCart(opts) {
|
|
|
706
916
|
if (cancelled) return;
|
|
707
917
|
if (cart?.id) {
|
|
708
918
|
storage.setCartId(cart.id);
|
|
709
|
-
setCartId(cart.id);
|
|
710
919
|
}
|
|
711
920
|
}).catch(() => {
|
|
712
921
|
});
|
|
@@ -718,13 +927,18 @@ function useActiveCart(opts) {
|
|
|
718
927
|
const data = cartId === null ? null : inner.data;
|
|
719
928
|
return { ...inner, data };
|
|
720
929
|
}
|
|
930
|
+
|
|
931
|
+
// src/hooks/use-checkout.ts
|
|
932
|
+
var import_react_query11 = require("@tanstack/react-query");
|
|
933
|
+
var import_emporix_sdk11 = require("@viu/emporix-sdk");
|
|
721
934
|
var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
|
|
722
935
|
function customerOnlyCtx(token) {
|
|
723
936
|
if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
|
|
724
|
-
return
|
|
937
|
+
return import_emporix_sdk11.auth.customer(token);
|
|
725
938
|
}
|
|
726
939
|
function useCheckout() {
|
|
727
|
-
const { client } = useEmporix();
|
|
940
|
+
const { client, storage } = useEmporix();
|
|
941
|
+
const qc = (0, import_react_query11.useQueryClient)();
|
|
728
942
|
const { ctx } = useReadAuth();
|
|
729
943
|
const { activeCompany } = useActiveCompany();
|
|
730
944
|
const withLE = (input) => {
|
|
@@ -732,26 +946,32 @@ function useCheckout() {
|
|
|
732
946
|
if ("legalEntityId" in input) return input;
|
|
733
947
|
return { ...input, legalEntityId: activeCompany.id };
|
|
734
948
|
};
|
|
735
|
-
const
|
|
949
|
+
const onOrderPlaced = () => {
|
|
950
|
+
storage.setCartId(null);
|
|
951
|
+
qc.removeQueries({ queryKey: ["emporix", "cart-bootstrap"] });
|
|
952
|
+
};
|
|
953
|
+
const placeOrder = (0, import_react_query11.useMutation)({
|
|
736
954
|
mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
|
|
737
955
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
738
956
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
739
|
-
})
|
|
957
|
+
}),
|
|
958
|
+
onSuccess: onOrderPlaced
|
|
740
959
|
});
|
|
741
|
-
const placeOrderFromQuote =
|
|
960
|
+
const placeOrderFromQuote = (0, import_react_query11.useMutation)({
|
|
742
961
|
mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
|
|
743
962
|
...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
|
|
744
963
|
...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
|
|
745
|
-
})
|
|
964
|
+
}),
|
|
965
|
+
onSuccess: onOrderPlaced
|
|
746
966
|
});
|
|
747
967
|
return { placeOrder, placeOrderFromQuote };
|
|
748
968
|
}
|
|
749
969
|
function usePaymentModes(options = {}) {
|
|
750
|
-
const { client
|
|
751
|
-
const token =
|
|
970
|
+
const { client } = useEmporix();
|
|
971
|
+
const token = useCustomerToken();
|
|
752
972
|
const { siteCode } = useReadSite();
|
|
753
973
|
const { activeCompany } = useActiveCompany();
|
|
754
|
-
return
|
|
974
|
+
return (0, import_react_query11.useQuery)({
|
|
755
975
|
queryKey: emporixKey(
|
|
756
976
|
"payment-modes",
|
|
757
977
|
[activeCompany?.id ?? null],
|
|
@@ -762,12 +982,16 @@ function usePaymentModes(options = {}) {
|
|
|
762
982
|
staleTime: PAYMENT_MODES_STALE_TIME
|
|
763
983
|
});
|
|
764
984
|
}
|
|
985
|
+
|
|
986
|
+
// src/hooks/use-match-prices.ts
|
|
987
|
+
var import_react_query12 = require("@tanstack/react-query");
|
|
988
|
+
var import_emporix_sdk12 = require("@viu/emporix-sdk");
|
|
765
989
|
var PRICES_STALE_TIME = 6e4;
|
|
766
990
|
function useMatchPrices(input, options = {}) {
|
|
767
991
|
const { client } = useEmporix();
|
|
768
992
|
const { siteCode } = useReadSite();
|
|
769
|
-
const ctx = options.customerToken ?
|
|
770
|
-
return
|
|
993
|
+
const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
|
|
994
|
+
return (0, import_react_query12.useQuery)({
|
|
771
995
|
queryKey: [
|
|
772
996
|
"emporix",
|
|
773
997
|
"match-prices",
|
|
@@ -778,12 +1002,16 @@ function useMatchPrices(input, options = {}) {
|
|
|
778
1002
|
staleTime: PRICES_STALE_TIME
|
|
779
1003
|
});
|
|
780
1004
|
}
|
|
1005
|
+
|
|
1006
|
+
// src/hooks/use-match-prices-chunked.ts
|
|
1007
|
+
var import_react_query13 = require("@tanstack/react-query");
|
|
1008
|
+
var import_emporix_sdk13 = require("@viu/emporix-sdk");
|
|
781
1009
|
var PRICES_STALE_TIME2 = 6e4;
|
|
782
1010
|
function useMatchPricesChunked(input, options = {}) {
|
|
783
1011
|
const { client } = useEmporix();
|
|
784
1012
|
const { siteCode } = useReadSite();
|
|
785
|
-
const ctx = options.customerToken ?
|
|
786
|
-
return
|
|
1013
|
+
const ctx = options.customerToken ? import_emporix_sdk13.auth.customer(options.customerToken) : import_emporix_sdk13.auth.anonymous();
|
|
1014
|
+
return (0, import_react_query13.useQuery)({
|
|
787
1015
|
queryKey: [
|
|
788
1016
|
"emporix",
|
|
789
1017
|
"match-prices-chunked",
|
|
@@ -815,16 +1043,20 @@ function useProductMedia(productId) {
|
|
|
815
1043
|
const data = q.data?.productMedia;
|
|
816
1044
|
return { data, isLoading: q.isLoading, error: q.error };
|
|
817
1045
|
}
|
|
1046
|
+
|
|
1047
|
+
// src/hooks/use-my-segments.ts
|
|
1048
|
+
var import_react_query14 = require("@tanstack/react-query");
|
|
1049
|
+
var import_emporix_sdk14 = require("@viu/emporix-sdk");
|
|
818
1050
|
var SEGMENTS_STALE_TIME = 5 * 6e4;
|
|
819
1051
|
function customerCtx(token) {
|
|
820
1052
|
if (!token) throw new Error("requires a customer token in storage");
|
|
821
|
-
return
|
|
1053
|
+
return import_emporix_sdk14.auth.customer(token);
|
|
822
1054
|
}
|
|
823
1055
|
function useMySegments(query = {}) {
|
|
824
|
-
const { client
|
|
825
|
-
const token =
|
|
1056
|
+
const { client } = useEmporix();
|
|
1057
|
+
const token = useCustomerToken();
|
|
826
1058
|
const { siteCode, language } = useReadSite();
|
|
827
|
-
return
|
|
1059
|
+
return (0, import_react_query14.useQuery)({
|
|
828
1060
|
queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
|
|
829
1061
|
enabled: token !== null,
|
|
830
1062
|
queryFn: () => client.segments.list(query, customerCtx(token)),
|
|
@@ -832,10 +1064,10 @@ function useMySegments(query = {}) {
|
|
|
832
1064
|
});
|
|
833
1065
|
}
|
|
834
1066
|
function useMySegmentItems(query = {}) {
|
|
835
|
-
const { client
|
|
836
|
-
const token =
|
|
1067
|
+
const { client } = useEmporix();
|
|
1068
|
+
const token = useCustomerToken();
|
|
837
1069
|
const { siteCode, language } = useReadSite();
|
|
838
|
-
return
|
|
1070
|
+
return (0, import_react_query14.useQuery)({
|
|
839
1071
|
queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
|
|
840
1072
|
enabled: token !== null,
|
|
841
1073
|
queryFn: () => client.segments.listItems(query, customerCtx(token)),
|
|
@@ -843,10 +1075,10 @@ function useMySegmentItems(query = {}) {
|
|
|
843
1075
|
});
|
|
844
1076
|
}
|
|
845
1077
|
function useMySegmentCategoryTree(query = {}) {
|
|
846
|
-
const { client
|
|
847
|
-
const token =
|
|
1078
|
+
const { client } = useEmporix();
|
|
1079
|
+
const token = useCustomerToken();
|
|
848
1080
|
const { siteCode, language } = useReadSite();
|
|
849
|
-
return
|
|
1081
|
+
return (0, import_react_query14.useQuery)({
|
|
850
1082
|
queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
|
|
851
1083
|
enabled: token !== null,
|
|
852
1084
|
queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
|
|
@@ -854,10 +1086,10 @@ function useMySegmentCategoryTree(query = {}) {
|
|
|
854
1086
|
});
|
|
855
1087
|
}
|
|
856
1088
|
function useMySegmentProducts(query = {}) {
|
|
857
|
-
const { client
|
|
858
|
-
const token =
|
|
1089
|
+
const { client } = useEmporix();
|
|
1090
|
+
const token = useCustomerToken();
|
|
859
1091
|
const { siteCode, language } = useReadSite();
|
|
860
|
-
return
|
|
1092
|
+
return (0, import_react_query14.useQuery)({
|
|
861
1093
|
queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
|
|
862
1094
|
enabled: token !== null,
|
|
863
1095
|
queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
|
|
@@ -865,8 +1097,8 @@ function useMySegmentProducts(query = {}) {
|
|
|
865
1097
|
});
|
|
866
1098
|
}
|
|
867
1099
|
function useMySegmentProductsInfinite(query = {}) {
|
|
868
|
-
const { client
|
|
869
|
-
const token =
|
|
1100
|
+
const { client } = useEmporix();
|
|
1101
|
+
const token = useCustomerToken();
|
|
870
1102
|
const { siteCode, language } = useReadSite();
|
|
871
1103
|
return useEmporixInfinite({
|
|
872
1104
|
queryKey: [
|
|
@@ -884,10 +1116,10 @@ function useMySegmentProductsInfinite(query = {}) {
|
|
|
884
1116
|
});
|
|
885
1117
|
}
|
|
886
1118
|
function useMySegmentCategories(query = {}) {
|
|
887
|
-
const { client
|
|
888
|
-
const token =
|
|
1119
|
+
const { client } = useEmporix();
|
|
1120
|
+
const token = useCustomerToken();
|
|
889
1121
|
const { siteCode, language } = useReadSite();
|
|
890
|
-
return
|
|
1122
|
+
return (0, import_react_query14.useQuery)({
|
|
891
1123
|
queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
|
|
892
1124
|
enabled: token !== null,
|
|
893
1125
|
queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
|
|
@@ -895,8 +1127,8 @@ function useMySegmentCategories(query = {}) {
|
|
|
895
1127
|
});
|
|
896
1128
|
}
|
|
897
1129
|
function useMySegmentCategoriesInfinite(query = {}) {
|
|
898
|
-
const { client
|
|
899
|
-
const token =
|
|
1130
|
+
const { client } = useEmporix();
|
|
1131
|
+
const token = useCustomerToken();
|
|
900
1132
|
const { siteCode, language } = useReadSite();
|
|
901
1133
|
return useEmporixInfinite({
|
|
902
1134
|
queryKey: [
|
|
@@ -913,11 +1145,15 @@ function useMySegmentCategoriesInfinite(query = {}) {
|
|
|
913
1145
|
staleTime: SEGMENTS_STALE_TIME
|
|
914
1146
|
});
|
|
915
1147
|
}
|
|
1148
|
+
|
|
1149
|
+
// src/hooks/use-customer-profile.ts
|
|
1150
|
+
var import_react_query15 = require("@tanstack/react-query");
|
|
1151
|
+
var import_emporix_sdk15 = require("@viu/emporix-sdk");
|
|
916
1152
|
function useUpdateCustomer() {
|
|
917
1153
|
const { client } = useEmporix();
|
|
918
1154
|
const ctx = useCustomerOnlyCtx();
|
|
919
|
-
const qc =
|
|
920
|
-
return
|
|
1155
|
+
const qc = (0, import_react_query15.useQueryClient)();
|
|
1156
|
+
return (0, import_react_query15.useMutation)({
|
|
921
1157
|
mutationFn: (patch) => client.customers.update(patch, ctx),
|
|
922
1158
|
onSuccess: () => {
|
|
923
1159
|
void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
|
|
@@ -927,17 +1163,21 @@ function useUpdateCustomer() {
|
|
|
927
1163
|
function useChangePassword() {
|
|
928
1164
|
const { client } = useEmporix();
|
|
929
1165
|
const ctx = useCustomerOnlyCtx();
|
|
930
|
-
return
|
|
1166
|
+
return (0, import_react_query15.useMutation)({
|
|
931
1167
|
mutationFn: (input) => client.customers.changePassword(input, ctx)
|
|
932
1168
|
});
|
|
933
1169
|
}
|
|
1170
|
+
|
|
1171
|
+
// src/hooks/use-customer-addresses.ts
|
|
1172
|
+
var import_react_query16 = require("@tanstack/react-query");
|
|
1173
|
+
var import_emporix_sdk16 = require("@viu/emporix-sdk");
|
|
934
1174
|
var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
|
|
935
1175
|
function useCustomerAddresses(options = {}) {
|
|
936
|
-
const { client
|
|
937
|
-
const token =
|
|
1176
|
+
const { client } = useEmporix();
|
|
1177
|
+
const token = useCustomerToken();
|
|
938
1178
|
const { activeCompany } = useActiveCompany();
|
|
939
|
-
const ctx = options.auth ?? (token ?
|
|
940
|
-
return
|
|
1179
|
+
const ctx = options.auth ?? (token ? import_emporix_sdk16.auth.customer(token) : null);
|
|
1180
|
+
return (0, import_react_query16.useQuery)({
|
|
941
1181
|
queryKey: [
|
|
942
1182
|
...ADDRESSES_KEY,
|
|
943
1183
|
{ tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
|
|
@@ -949,39 +1189,49 @@ function useCustomerAddresses(options = {}) {
|
|
|
949
1189
|
function useAddressMutations() {
|
|
950
1190
|
const { client } = useEmporix();
|
|
951
1191
|
const ctx = useCustomerOnlyCtx();
|
|
952
|
-
const qc =
|
|
1192
|
+
const qc = (0, import_react_query16.useQueryClient)();
|
|
953
1193
|
const invalidate = () => {
|
|
954
1194
|
void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
|
|
955
1195
|
};
|
|
956
1196
|
return {
|
|
957
|
-
add:
|
|
1197
|
+
add: (0, import_react_query16.useMutation)({
|
|
958
1198
|
mutationFn: (input) => client.customers.addresses.add(input, ctx),
|
|
959
1199
|
onSuccess: invalidate
|
|
960
1200
|
}),
|
|
961
|
-
update:
|
|
1201
|
+
update: (0, import_react_query16.useMutation)({
|
|
962
1202
|
mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
|
|
963
1203
|
onSuccess: invalidate
|
|
964
1204
|
}),
|
|
965
|
-
remove:
|
|
1205
|
+
remove: (0, import_react_query16.useMutation)({
|
|
966
1206
|
mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
|
|
967
1207
|
onSuccess: invalidate
|
|
968
1208
|
})
|
|
969
1209
|
};
|
|
970
1210
|
}
|
|
1211
|
+
|
|
1212
|
+
// src/hooks/use-password-reset.ts
|
|
1213
|
+
var import_react_query17 = require("@tanstack/react-query");
|
|
1214
|
+
var import_emporix_sdk17 = require("@viu/emporix-sdk");
|
|
971
1215
|
function usePasswordReset() {
|
|
972
1216
|
const { client } = useEmporix();
|
|
973
|
-
const anonCtx =
|
|
1217
|
+
const anonCtx = import_emporix_sdk17.auth.anonymous();
|
|
974
1218
|
return {
|
|
975
|
-
request:
|
|
1219
|
+
request: (0, import_react_query17.useMutation)({
|
|
976
1220
|
mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
|
|
977
1221
|
}),
|
|
978
|
-
confirm:
|
|
1222
|
+
confirm: (0, import_react_query17.useMutation)({
|
|
979
1223
|
mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
|
|
980
1224
|
})
|
|
981
1225
|
};
|
|
982
1226
|
}
|
|
1227
|
+
|
|
1228
|
+
// src/hooks/use-sites.ts
|
|
1229
|
+
var import_react_query18 = require("@tanstack/react-query");
|
|
1230
|
+
|
|
1231
|
+
// src/hooks/use-site-context.ts
|
|
1232
|
+
var import_react7 = require("react");
|
|
983
1233
|
function useSiteContext() {
|
|
984
|
-
const ctx =
|
|
1234
|
+
const ctx = (0, import_react7.useContext)(EmporixSiteContext);
|
|
985
1235
|
if (!ctx) {
|
|
986
1236
|
throw new Error("useSiteContext must be used within an EmporixProvider");
|
|
987
1237
|
}
|
|
@@ -993,7 +1243,7 @@ var SITES_STALE_TIME = 10 * 6e4;
|
|
|
993
1243
|
function useSites(options = {}) {
|
|
994
1244
|
const { client } = useEmporix();
|
|
995
1245
|
const { ctx } = useReadAuth(options.auth);
|
|
996
|
-
return
|
|
1246
|
+
return (0, import_react_query18.useQuery)({
|
|
997
1247
|
queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
998
1248
|
queryFn: () => client.sites.list(ctx),
|
|
999
1249
|
staleTime: SITES_STALE_TIME
|
|
@@ -1002,7 +1252,7 @@ function useSites(options = {}) {
|
|
|
1002
1252
|
function useDefaultSite(options = {}) {
|
|
1003
1253
|
const { client } = useEmporix();
|
|
1004
1254
|
const { ctx } = useReadAuth(options.auth);
|
|
1005
|
-
return
|
|
1255
|
+
return (0, import_react_query18.useQuery)({
|
|
1006
1256
|
queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1007
1257
|
queryFn: () => client.sites.current(ctx),
|
|
1008
1258
|
staleTime: SITES_STALE_TIME
|
|
@@ -1013,79 +1263,97 @@ function useActiveSite(options = {}) {
|
|
|
1013
1263
|
const { data: sites } = useSites(options);
|
|
1014
1264
|
return siteCode ? sites?.find((s) => s.code === siteCode) : void 0;
|
|
1015
1265
|
}
|
|
1266
|
+
|
|
1267
|
+
// src/hooks/use-my-companies.ts
|
|
1268
|
+
var import_react_query19 = require("@tanstack/react-query");
|
|
1269
|
+
var import_emporix_sdk18 = require("@viu/emporix-sdk");
|
|
1016
1270
|
function useMyCompanies() {
|
|
1017
|
-
const { client
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
enabled: token !== null,
|
|
1025
|
-
queryFn: () => client.companies.listMine(emporixSdk.auth.customer(token))
|
|
1271
|
+
const { client } = useEmporix();
|
|
1272
|
+
return useEmporixQuery({
|
|
1273
|
+
mode: "customer",
|
|
1274
|
+
site: "none",
|
|
1275
|
+
resource: "companies",
|
|
1276
|
+
args: ["mine"],
|
|
1277
|
+
queryFn: (ctx) => client.companies.listMine(ctx)
|
|
1026
1278
|
});
|
|
1027
1279
|
}
|
|
1280
|
+
|
|
1281
|
+
// src/hooks/use-company.ts
|
|
1282
|
+
var import_react_query20 = require("@tanstack/react-query");
|
|
1283
|
+
var import_emporix_sdk19 = require("@viu/emporix-sdk");
|
|
1028
1284
|
function useCompany(legalEntityId) {
|
|
1029
|
-
const { client
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
queryFn: () => client.companies.get(legalEntityId, emporixSdk.auth.customer(token))
|
|
1285
|
+
const { client } = useEmporix();
|
|
1286
|
+
return useEmporixQuery({
|
|
1287
|
+
mode: "customer",
|
|
1288
|
+
site: "none",
|
|
1289
|
+
resource: "companies",
|
|
1290
|
+
args: [legalEntityId ?? null],
|
|
1291
|
+
enabled: legalEntityId !== void 0,
|
|
1292
|
+
queryFn: (ctx) => client.companies.get(legalEntityId, ctx)
|
|
1038
1293
|
});
|
|
1039
1294
|
}
|
|
1295
|
+
|
|
1296
|
+
// src/hooks/use-company-contacts.ts
|
|
1297
|
+
var import_react_query21 = require("@tanstack/react-query");
|
|
1298
|
+
var import_emporix_sdk20 = require("@viu/emporix-sdk");
|
|
1040
1299
|
function useCompanyContacts(legalEntityId) {
|
|
1041
|
-
const { client
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
queryFn: () => client.contacts.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
|
|
1300
|
+
const { client } = useEmporix();
|
|
1301
|
+
return useEmporixQuery({
|
|
1302
|
+
mode: "customer",
|
|
1303
|
+
site: "none",
|
|
1304
|
+
resource: "companies",
|
|
1305
|
+
args: ["contacts", legalEntityId ?? null],
|
|
1306
|
+
enabled: legalEntityId !== void 0,
|
|
1307
|
+
queryFn: (ctx) => client.contacts.listForCompany(legalEntityId, ctx)
|
|
1050
1308
|
});
|
|
1051
1309
|
}
|
|
1310
|
+
|
|
1311
|
+
// src/hooks/use-company-locations.ts
|
|
1312
|
+
var import_react_query22 = require("@tanstack/react-query");
|
|
1313
|
+
var import_emporix_sdk21 = require("@viu/emporix-sdk");
|
|
1052
1314
|
function useCompanyLocations(legalEntityId) {
|
|
1053
|
-
const { client
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
queryFn: () => client.locations.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
|
|
1315
|
+
const { client } = useEmporix();
|
|
1316
|
+
return useEmporixQuery({
|
|
1317
|
+
mode: "customer",
|
|
1318
|
+
site: "none",
|
|
1319
|
+
resource: "companies",
|
|
1320
|
+
args: ["locations", legalEntityId ?? null],
|
|
1321
|
+
enabled: legalEntityId !== void 0,
|
|
1322
|
+
queryFn: (ctx) => client.locations.listForCompany(legalEntityId, ctx)
|
|
1062
1323
|
});
|
|
1063
1324
|
}
|
|
1325
|
+
|
|
1326
|
+
// src/hooks/use-company-groups.ts
|
|
1327
|
+
var import_react_query23 = require("@tanstack/react-query");
|
|
1328
|
+
var import_emporix_sdk22 = require("@viu/emporix-sdk");
|
|
1064
1329
|
function useCompanyGroups(legalEntityId) {
|
|
1065
|
-
const { client
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
queryFn: () => client.customerGroups.listForCompany(legalEntityId, emporixSdk.auth.customer(token))
|
|
1330
|
+
const { client } = useEmporix();
|
|
1331
|
+
return useEmporixQuery({
|
|
1332
|
+
mode: "customer",
|
|
1333
|
+
site: "none",
|
|
1334
|
+
resource: "companies",
|
|
1335
|
+
args: ["groups", legalEntityId ?? null],
|
|
1336
|
+
enabled: legalEntityId !== void 0,
|
|
1337
|
+
queryFn: (ctx) => client.customerGroups.listForCompany(legalEntityId, ctx)
|
|
1074
1338
|
});
|
|
1075
1339
|
}
|
|
1340
|
+
|
|
1341
|
+
// src/hooks/use-company-mutations.ts
|
|
1342
|
+
var import_react_query24 = require("@tanstack/react-query");
|
|
1343
|
+
var import_emporix_sdk23 = require("@viu/emporix-sdk");
|
|
1076
1344
|
function useCustomerAuthResolver() {
|
|
1077
1345
|
const { storage } = useEmporix();
|
|
1078
1346
|
return () => {
|
|
1079
1347
|
const token = storage.getCustomerToken();
|
|
1080
1348
|
if (!token) throw new Error("Mutation requires a logged-in customer token");
|
|
1081
|
-
return
|
|
1349
|
+
return import_emporix_sdk23.auth.customer(token);
|
|
1082
1350
|
};
|
|
1083
1351
|
}
|
|
1084
1352
|
function useCreateCompany() {
|
|
1085
1353
|
const { client } = useEmporix();
|
|
1086
1354
|
const resolveAuth = useCustomerAuthResolver();
|
|
1087
|
-
const qc =
|
|
1088
|
-
return
|
|
1355
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1356
|
+
return (0, import_react_query24.useMutation)({
|
|
1089
1357
|
mutationFn: (input) => client.companies.create(input, resolveAuth()),
|
|
1090
1358
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
|
|
1091
1359
|
});
|
|
@@ -1093,8 +1361,8 @@ function useCreateCompany() {
|
|
|
1093
1361
|
function useUpdateCompany() {
|
|
1094
1362
|
const { client } = useEmporix();
|
|
1095
1363
|
const resolveAuth = useCustomerAuthResolver();
|
|
1096
|
-
const qc =
|
|
1097
|
-
return
|
|
1364
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1365
|
+
return (0, import_react_query24.useMutation)({
|
|
1098
1366
|
mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
|
|
1099
1367
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1100
1368
|
});
|
|
@@ -1102,8 +1370,8 @@ function useUpdateCompany() {
|
|
|
1102
1370
|
function useDeleteCompany() {
|
|
1103
1371
|
const { client } = useEmporix();
|
|
1104
1372
|
const resolveAuth = useCustomerAuthResolver();
|
|
1105
|
-
const qc =
|
|
1106
|
-
return
|
|
1373
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1374
|
+
return (0, import_react_query24.useMutation)({
|
|
1107
1375
|
mutationFn: (id) => client.companies.delete(id, resolveAuth()),
|
|
1108
1376
|
onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
|
|
1109
1377
|
});
|
|
@@ -1111,8 +1379,8 @@ function useDeleteCompany() {
|
|
|
1111
1379
|
function useAssignContact() {
|
|
1112
1380
|
const { client } = useEmporix();
|
|
1113
1381
|
const resolveAuth = useCustomerAuthResolver();
|
|
1114
|
-
const qc =
|
|
1115
|
-
return
|
|
1382
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1383
|
+
return (0, import_react_query24.useMutation)({
|
|
1116
1384
|
mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
|
|
1117
1385
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1118
1386
|
});
|
|
@@ -1120,8 +1388,8 @@ function useAssignContact() {
|
|
|
1120
1388
|
function useUpdateContactAssignment() {
|
|
1121
1389
|
const { client } = useEmporix();
|
|
1122
1390
|
const resolveAuth = useCustomerAuthResolver();
|
|
1123
|
-
const qc =
|
|
1124
|
-
return
|
|
1391
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1392
|
+
return (0, import_react_query24.useMutation)({
|
|
1125
1393
|
mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
|
|
1126
1394
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1127
1395
|
});
|
|
@@ -1129,8 +1397,8 @@ function useUpdateContactAssignment() {
|
|
|
1129
1397
|
function useUnassignContact() {
|
|
1130
1398
|
const { client } = useEmporix();
|
|
1131
1399
|
const resolveAuth = useCustomerAuthResolver();
|
|
1132
|
-
const qc =
|
|
1133
|
-
return
|
|
1400
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1401
|
+
return (0, import_react_query24.useMutation)({
|
|
1134
1402
|
mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
|
|
1135
1403
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
|
|
1136
1404
|
});
|
|
@@ -1138,8 +1406,8 @@ function useUnassignContact() {
|
|
|
1138
1406
|
function useCreateLocation() {
|
|
1139
1407
|
const { client } = useEmporix();
|
|
1140
1408
|
const resolveAuth = useCustomerAuthResolver();
|
|
1141
|
-
const qc =
|
|
1142
|
-
return
|
|
1409
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1410
|
+
return (0, import_react_query24.useMutation)({
|
|
1143
1411
|
mutationFn: (input) => client.locations.create(input, resolveAuth()),
|
|
1144
1412
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1145
1413
|
});
|
|
@@ -1147,8 +1415,8 @@ function useCreateLocation() {
|
|
|
1147
1415
|
function useUpdateLocation() {
|
|
1148
1416
|
const { client } = useEmporix();
|
|
1149
1417
|
const resolveAuth = useCustomerAuthResolver();
|
|
1150
|
-
const qc =
|
|
1151
|
-
return
|
|
1418
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1419
|
+
return (0, import_react_query24.useMutation)({
|
|
1152
1420
|
mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
|
|
1153
1421
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1154
1422
|
});
|
|
@@ -1156,8 +1424,8 @@ function useUpdateLocation() {
|
|
|
1156
1424
|
function useDeleteLocation() {
|
|
1157
1425
|
const { client } = useEmporix();
|
|
1158
1426
|
const resolveAuth = useCustomerAuthResolver();
|
|
1159
|
-
const qc =
|
|
1160
|
-
return
|
|
1427
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1428
|
+
return (0, import_react_query24.useMutation)({
|
|
1161
1429
|
mutationFn: (id) => client.locations.delete(id, resolveAuth()),
|
|
1162
1430
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
|
|
1163
1431
|
});
|
|
@@ -1165,8 +1433,8 @@ function useDeleteLocation() {
|
|
|
1165
1433
|
function useAddGroupMember() {
|
|
1166
1434
|
const { client } = useEmporix();
|
|
1167
1435
|
const resolveAuth = useCustomerAuthResolver();
|
|
1168
|
-
const qc =
|
|
1169
|
-
return
|
|
1436
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1437
|
+
return (0, import_react_query24.useMutation)({
|
|
1170
1438
|
mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
|
|
1171
1439
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1172
1440
|
});
|
|
@@ -1174,19 +1442,22 @@ function useAddGroupMember() {
|
|
|
1174
1442
|
function useRemoveGroupMember() {
|
|
1175
1443
|
const { client } = useEmporix();
|
|
1176
1444
|
const resolveAuth = useCustomerAuthResolver();
|
|
1177
|
-
const qc =
|
|
1178
|
-
return
|
|
1445
|
+
const qc = (0, import_react_query24.useQueryClient)();
|
|
1446
|
+
return (0, import_react_query24.useMutation)({
|
|
1179
1447
|
mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
|
|
1180
1448
|
onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
|
|
1181
1449
|
});
|
|
1182
1450
|
}
|
|
1451
|
+
|
|
1452
|
+
// src/hooks/use-company-switcher.ts
|
|
1453
|
+
var import_react8 = require("react");
|
|
1183
1454
|
function useCompanySwitcher() {
|
|
1184
1455
|
const ctx = useActiveCompany();
|
|
1185
|
-
const switchFn =
|
|
1456
|
+
const switchFn = (0, import_react8.useCallback)(
|
|
1186
1457
|
(legalEntityId) => ctx.setActiveCompany(legalEntityId),
|
|
1187
1458
|
[ctx]
|
|
1188
1459
|
);
|
|
1189
|
-
const clearFn =
|
|
1460
|
+
const clearFn = (0, import_react8.useCallback)(() => ctx.setActiveCompany(null), [ctx]);
|
|
1190
1461
|
return {
|
|
1191
1462
|
companies: ctx.myCompanies,
|
|
1192
1463
|
active: ctx.activeCompany,
|
|
@@ -1195,23 +1466,27 @@ function useCompanySwitcher() {
|
|
|
1195
1466
|
clear: clearFn
|
|
1196
1467
|
};
|
|
1197
1468
|
}
|
|
1469
|
+
|
|
1470
|
+
// src/hooks/use-cloud-functions.ts
|
|
1471
|
+
var import_react_query25 = require("@tanstack/react-query");
|
|
1472
|
+
var import_emporix_sdk24 = require("@viu/emporix-sdk");
|
|
1198
1473
|
function useInvokeCloudFunction() {
|
|
1199
1474
|
const { client, storage } = useEmporix();
|
|
1200
|
-
return
|
|
1475
|
+
return (0, import_react_query25.useMutation)({
|
|
1201
1476
|
mutationFn: (vars) => {
|
|
1202
1477
|
const { functionId, auth: authOverride, ...options } = vars;
|
|
1203
1478
|
const token = storage.getCustomerToken();
|
|
1204
|
-
const authCtx = authOverride ?? (token ?
|
|
1479
|
+
const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
|
|
1205
1480
|
return client.cloudFunctions.invoke(functionId, options, authCtx);
|
|
1206
1481
|
}
|
|
1207
1482
|
});
|
|
1208
1483
|
}
|
|
1209
1484
|
function useCloudFunction(functionId, options, queryOptions) {
|
|
1210
|
-
const { client
|
|
1211
|
-
const token =
|
|
1485
|
+
const { client } = useEmporix();
|
|
1486
|
+
const token = useCustomerToken();
|
|
1212
1487
|
const { auth: authOverride, ...invokeOptions } = options ?? {};
|
|
1213
|
-
const authCtx = authOverride ?? (token ?
|
|
1214
|
-
return
|
|
1488
|
+
const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
|
|
1489
|
+
return (0, import_react_query25.useQuery)({
|
|
1215
1490
|
queryKey: emporixKey(
|
|
1216
1491
|
"cloud-function",
|
|
1217
1492
|
[functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
|
|
@@ -1226,20 +1501,21 @@ function useCloudFunction(functionId, options, queryOptions) {
|
|
|
1226
1501
|
)
|
|
1227
1502
|
});
|
|
1228
1503
|
}
|
|
1504
|
+
|
|
1505
|
+
// src/hooks/use-my-orders.ts
|
|
1506
|
+
var import_react_query26 = require("@tanstack/react-query");
|
|
1507
|
+
var import_emporix_sdk25 = require("@viu/emporix-sdk");
|
|
1229
1508
|
function useMyOrders(options = {}) {
|
|
1230
|
-
const { client
|
|
1509
|
+
const { client } = useEmporix();
|
|
1231
1510
|
const { activeCompany } = useActiveCompany();
|
|
1232
|
-
const { siteCode
|
|
1233
|
-
const token = storage.getCustomerToken();
|
|
1511
|
+
const { siteCode } = useReadSite();
|
|
1234
1512
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1235
|
-
return
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
),
|
|
1241
|
-
enabled: token !== null,
|
|
1242
|
-
queryFn: () => client.orders.listMine(emporixSdk.auth.customer(token), {
|
|
1513
|
+
return useEmporixQuery({
|
|
1514
|
+
mode: "customer",
|
|
1515
|
+
site: "full",
|
|
1516
|
+
resource: "orders",
|
|
1517
|
+
args: ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
|
|
1518
|
+
queryFn: (ctx) => client.orders.listMine(ctx, {
|
|
1243
1519
|
...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
|
|
1244
1520
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1245
1521
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1249,11 +1525,14 @@ function useMyOrders(options = {}) {
|
|
|
1249
1525
|
})
|
|
1250
1526
|
});
|
|
1251
1527
|
}
|
|
1528
|
+
|
|
1529
|
+
// src/hooks/use-my-orders-infinite.ts
|
|
1530
|
+
var import_emporix_sdk26 = require("@viu/emporix-sdk");
|
|
1252
1531
|
function useMyOrdersInfinite(options = {}) {
|
|
1253
|
-
const { client
|
|
1532
|
+
const { client } = useEmporix();
|
|
1254
1533
|
const { activeCompany } = useActiveCompany();
|
|
1255
1534
|
const { siteCode, language } = useReadSite();
|
|
1256
|
-
const token =
|
|
1535
|
+
const token = useCustomerToken();
|
|
1257
1536
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1258
1537
|
return useEmporixInfinite({
|
|
1259
1538
|
queryKey: emporixKey(
|
|
@@ -1262,7 +1541,7 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1262
1541
|
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1263
1542
|
),
|
|
1264
1543
|
enabled: token !== null,
|
|
1265
|
-
fetchPage: (pageNumber) => client.orders.listMine(
|
|
1544
|
+
fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk26.auth.customer(token), {
|
|
1266
1545
|
pageNumber,
|
|
1267
1546
|
...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
|
|
1268
1547
|
...options.status !== void 0 ? { status: options.status } : {},
|
|
@@ -1272,28 +1551,33 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1272
1551
|
})
|
|
1273
1552
|
});
|
|
1274
1553
|
}
|
|
1554
|
+
|
|
1555
|
+
// src/hooks/use-order.ts
|
|
1556
|
+
var import_react_query27 = require("@tanstack/react-query");
|
|
1557
|
+
var import_emporix_sdk27 = require("@viu/emporix-sdk");
|
|
1275
1558
|
function useOrder(orderId, options = {}) {
|
|
1276
|
-
const { client
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
}),
|
|
1285
|
-
enabled: token !== null && orderId !== void 0,
|
|
1286
|
-
queryFn: () => client.orders.get(
|
|
1559
|
+
const { client } = useEmporix();
|
|
1560
|
+
return useEmporixQuery({
|
|
1561
|
+
mode: "customer",
|
|
1562
|
+
site: "language",
|
|
1563
|
+
resource: "orders",
|
|
1564
|
+
args: [orderId ?? null],
|
|
1565
|
+
enabled: orderId !== void 0,
|
|
1566
|
+
queryFn: (ctx) => client.orders.get(
|
|
1287
1567
|
orderId,
|
|
1288
|
-
|
|
1568
|
+
ctx,
|
|
1289
1569
|
options.saasToken ? { saasToken: options.saasToken } : {}
|
|
1290
1570
|
)
|
|
1291
1571
|
});
|
|
1292
1572
|
}
|
|
1573
|
+
|
|
1574
|
+
// src/hooks/use-cancel-order.ts
|
|
1575
|
+
var import_react_query28 = require("@tanstack/react-query");
|
|
1576
|
+
var import_emporix_sdk28 = require("@viu/emporix-sdk");
|
|
1293
1577
|
function useCancelOrder() {
|
|
1294
1578
|
const { client, storage } = useEmporix();
|
|
1295
|
-
const qc =
|
|
1296
|
-
return
|
|
1579
|
+
const qc = (0, import_react_query28.useQueryClient)();
|
|
1580
|
+
return (0, import_react_query28.useMutation)({
|
|
1297
1581
|
mutationKey: ["emporix", "orders", "cancel"],
|
|
1298
1582
|
mutationFn: async (input) => {
|
|
1299
1583
|
const token = storage.getCustomerToken();
|
|
@@ -1301,7 +1585,7 @@ function useCancelOrder() {
|
|
|
1301
1585
|
const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
|
|
1302
1586
|
await client.orders.cancel(
|
|
1303
1587
|
orderId,
|
|
1304
|
-
|
|
1588
|
+
import_emporix_sdk28.auth.customer(token),
|
|
1305
1589
|
saasToken ? { saasToken } : {}
|
|
1306
1590
|
);
|
|
1307
1591
|
},
|
|
@@ -1310,10 +1594,14 @@ function useCancelOrder() {
|
|
|
1310
1594
|
})
|
|
1311
1595
|
});
|
|
1312
1596
|
}
|
|
1597
|
+
|
|
1598
|
+
// src/hooks/use-order-transition.ts
|
|
1599
|
+
var import_react_query29 = require("@tanstack/react-query");
|
|
1600
|
+
var import_emporix_sdk29 = require("@viu/emporix-sdk");
|
|
1313
1601
|
function useOrderTransition() {
|
|
1314
1602
|
const { client, storage } = useEmporix();
|
|
1315
|
-
const qc =
|
|
1316
|
-
return
|
|
1603
|
+
const qc = (0, import_react_query29.useQueryClient)();
|
|
1604
|
+
return (0, import_react_query29.useMutation)({
|
|
1317
1605
|
mutationKey: ["emporix", "orders", "transition"],
|
|
1318
1606
|
mutationFn: async ({ orderId, status, comment, saasToken }) => {
|
|
1319
1607
|
const token = storage.getCustomerToken();
|
|
@@ -1321,7 +1609,7 @@ function useOrderTransition() {
|
|
|
1321
1609
|
await client.orders.transition(
|
|
1322
1610
|
orderId,
|
|
1323
1611
|
status,
|
|
1324
|
-
|
|
1612
|
+
import_emporix_sdk29.auth.customer(token),
|
|
1325
1613
|
{
|
|
1326
1614
|
...comment !== void 0 ? { comment } : {},
|
|
1327
1615
|
...saasToken !== void 0 ? { saasToken } : {}
|
|
@@ -1333,15 +1621,19 @@ function useOrderTransition() {
|
|
|
1333
1621
|
})
|
|
1334
1622
|
});
|
|
1335
1623
|
}
|
|
1624
|
+
|
|
1625
|
+
// src/hooks/use-reorder.ts
|
|
1626
|
+
var import_react_query30 = require("@tanstack/react-query");
|
|
1627
|
+
var import_emporix_sdk30 = require("@viu/emporix-sdk");
|
|
1336
1628
|
function useReorder() {
|
|
1337
1629
|
const { client, storage } = useEmporix();
|
|
1338
|
-
const qc =
|
|
1339
|
-
return
|
|
1630
|
+
const qc = (0, import_react_query30.useQueryClient)();
|
|
1631
|
+
return (0, import_react_query30.useMutation)({
|
|
1340
1632
|
mutationKey: ["emporix", "orders", "reorder"],
|
|
1341
1633
|
mutationFn: async ({ orderId, saasToken }) => {
|
|
1342
1634
|
const token = storage.getCustomerToken();
|
|
1343
1635
|
if (!token) throw new Error("useReorder: requires a logged-in customer");
|
|
1344
|
-
const ctx =
|
|
1636
|
+
const ctx = import_emporix_sdk30.auth.customer(token);
|
|
1345
1637
|
const order = await qc.fetchQuery({
|
|
1346
1638
|
queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1347
1639
|
queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
|
|
@@ -1386,10 +1678,14 @@ function useReorder() {
|
|
|
1386
1678
|
}
|
|
1387
1679
|
});
|
|
1388
1680
|
}
|
|
1681
|
+
|
|
1682
|
+
// src/hooks/use-sales-order.ts
|
|
1683
|
+
var import_react_query31 = require("@tanstack/react-query");
|
|
1684
|
+
var import_emporix_sdk31 = require("@viu/emporix-sdk");
|
|
1389
1685
|
function useSalesOrder(orderId, authCtx) {
|
|
1390
1686
|
const { client } = useEmporix();
|
|
1391
1687
|
const { language } = useReadSite();
|
|
1392
|
-
return
|
|
1688
|
+
return (0, import_react_query31.useQuery)({
|
|
1393
1689
|
queryKey: emporixKey("salesorders", [orderId ?? null], {
|
|
1394
1690
|
tenant: client.tenant,
|
|
1395
1691
|
authKind: authCtx?.kind ?? "anonymous",
|
|
@@ -1399,17 +1695,21 @@ function useSalesOrder(orderId, authCtx) {
|
|
|
1399
1695
|
queryFn: () => client.salesOrders.get(orderId, authCtx)
|
|
1400
1696
|
});
|
|
1401
1697
|
}
|
|
1698
|
+
|
|
1699
|
+
// src/hooks/use-update-sales-order.ts
|
|
1700
|
+
var import_react_query32 = require("@tanstack/react-query");
|
|
1701
|
+
var import_emporix_sdk32 = require("@viu/emporix-sdk");
|
|
1402
1702
|
function useUpdateSalesOrder() {
|
|
1403
1703
|
const { client } = useEmporix();
|
|
1404
|
-
const qc =
|
|
1405
|
-
return
|
|
1704
|
+
const qc = (0, import_react_query32.useQueryClient)();
|
|
1705
|
+
return (0, import_react_query32.useMutation)({
|
|
1406
1706
|
mutationKey: ["emporix", "salesorders", "update"],
|
|
1407
|
-
mutationFn: async ({ orderId, patch, auth:
|
|
1408
|
-
if (!
|
|
1707
|
+
mutationFn: async ({ orderId, patch, auth: auth20, recalculate }) => {
|
|
1708
|
+
if (!auth20) throw new Error("useUpdateSalesOrder: requires an auth context");
|
|
1409
1709
|
return client.salesOrders.update(
|
|
1410
1710
|
orderId,
|
|
1411
1711
|
patch,
|
|
1412
|
-
|
|
1712
|
+
auth20,
|
|
1413
1713
|
recalculate !== void 0 ? { recalculate } : {}
|
|
1414
1714
|
);
|
|
1415
1715
|
},
|
|
@@ -1420,11 +1720,15 @@ function useUpdateSalesOrder() {
|
|
|
1420
1720
|
}
|
|
1421
1721
|
});
|
|
1422
1722
|
}
|
|
1723
|
+
|
|
1724
|
+
// src/hooks/use-availability.ts
|
|
1725
|
+
var import_react_query33 = require("@tanstack/react-query");
|
|
1726
|
+
var import_emporix_sdk33 = require("@viu/emporix-sdk");
|
|
1423
1727
|
var AVAILABILITY_STALE_TIME = 3e4;
|
|
1424
1728
|
function useAvailability(productId, siteCode, options = {}) {
|
|
1425
1729
|
const { client } = useEmporix();
|
|
1426
|
-
const ctx = options.customerToken ?
|
|
1427
|
-
return
|
|
1730
|
+
const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
|
|
1731
|
+
return (0, import_react_query33.useQuery)({
|
|
1428
1732
|
queryKey: [
|
|
1429
1733
|
"emporix",
|
|
1430
1734
|
"availability",
|
|
@@ -1443,11 +1747,15 @@ function useAvailability(productId, siteCode, options = {}) {
|
|
|
1443
1747
|
staleTime: AVAILABILITY_STALE_TIME
|
|
1444
1748
|
});
|
|
1445
1749
|
}
|
|
1750
|
+
|
|
1751
|
+
// src/hooks/use-availabilities.ts
|
|
1752
|
+
var import_react_query34 = require("@tanstack/react-query");
|
|
1753
|
+
var import_emporix_sdk34 = require("@viu/emporix-sdk");
|
|
1446
1754
|
var AVAILABILITY_STALE_TIME2 = 3e4;
|
|
1447
1755
|
function useAvailabilities(productIds, siteCode, options = {}) {
|
|
1448
1756
|
const { client } = useEmporix();
|
|
1449
|
-
const ctx = options.customerToken ?
|
|
1450
|
-
return
|
|
1757
|
+
const ctx = options.customerToken ? import_emporix_sdk34.auth.customer(options.customerToken) : import_emporix_sdk34.auth.anonymous();
|
|
1758
|
+
return (0, import_react_query34.useQuery)({
|
|
1451
1759
|
queryKey: [
|
|
1452
1760
|
"emporix",
|
|
1453
1761
|
"availabilities",
|
|
@@ -1466,29 +1774,35 @@ function useAvailabilities(productIds, siteCode, options = {}) {
|
|
|
1466
1774
|
staleTime: AVAILABILITY_STALE_TIME2
|
|
1467
1775
|
});
|
|
1468
1776
|
}
|
|
1777
|
+
|
|
1778
|
+
// src/hooks/use-coupons.ts
|
|
1779
|
+
var import_react_query35 = require("@tanstack/react-query");
|
|
1469
1780
|
var INVALIDATE_KEY2 = ["emporix", "coupons"];
|
|
1470
1781
|
function useValidateCoupon() {
|
|
1471
1782
|
const { client } = useEmporix();
|
|
1472
1783
|
const { ctx } = useReadAuth();
|
|
1473
|
-
return
|
|
1784
|
+
return (0, import_react_query35.useMutation)({
|
|
1474
1785
|
mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
|
|
1475
1786
|
});
|
|
1476
1787
|
}
|
|
1477
1788
|
function useRedeemCoupon() {
|
|
1478
1789
|
const { client } = useEmporix();
|
|
1479
1790
|
const { ctx } = useReadAuth();
|
|
1480
|
-
const qc =
|
|
1481
|
-
return
|
|
1791
|
+
const qc = (0, import_react_query35.useQueryClient)();
|
|
1792
|
+
return (0, import_react_query35.useMutation)({
|
|
1482
1793
|
mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
|
|
1483
1794
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
|
|
1484
1795
|
});
|
|
1485
1796
|
}
|
|
1797
|
+
|
|
1798
|
+
// src/hooks/use-reward-points.ts
|
|
1799
|
+
var import_react_query36 = require("@tanstack/react-query");
|
|
1486
1800
|
var STALE = 3e4;
|
|
1487
1801
|
var INVALIDATE_KEY3 = ["emporix", "reward-points"];
|
|
1488
1802
|
function useMyRewardPoints() {
|
|
1489
1803
|
const { client } = useEmporix();
|
|
1490
1804
|
const ctx = useCustomerOnlyCtx();
|
|
1491
|
-
return
|
|
1805
|
+
return (0, import_react_query36.useQuery)({
|
|
1492
1806
|
queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1493
1807
|
queryFn: () => client.rewardPoints.getMyPoints(ctx),
|
|
1494
1808
|
staleTime: STALE
|
|
@@ -1497,7 +1811,7 @@ function useMyRewardPoints() {
|
|
|
1497
1811
|
function useMyRewardPointsSummary() {
|
|
1498
1812
|
const { client } = useEmporix();
|
|
1499
1813
|
const ctx = useCustomerOnlyCtx();
|
|
1500
|
-
return
|
|
1814
|
+
return (0, import_react_query36.useQuery)({
|
|
1501
1815
|
queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1502
1816
|
queryFn: () => client.rewardPoints.getMySummary(ctx),
|
|
1503
1817
|
staleTime: STALE
|
|
@@ -1506,7 +1820,7 @@ function useMyRewardPointsSummary() {
|
|
|
1506
1820
|
function useRedeemOptions() {
|
|
1507
1821
|
const { client } = useEmporix();
|
|
1508
1822
|
const { ctx } = useReadAuth();
|
|
1509
|
-
return
|
|
1823
|
+
return (0, import_react_query36.useQuery)({
|
|
1510
1824
|
queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1511
1825
|
queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
|
|
1512
1826
|
staleTime: STALE
|
|
@@ -1515,18 +1829,21 @@ function useRedeemOptions() {
|
|
|
1515
1829
|
function useRedeemRewardPoints() {
|
|
1516
1830
|
const { client } = useEmporix();
|
|
1517
1831
|
const ctx = useCustomerOnlyCtx();
|
|
1518
|
-
const qc =
|
|
1519
|
-
return
|
|
1832
|
+
const qc = (0, import_react_query36.useQueryClient)();
|
|
1833
|
+
return (0, import_react_query36.useMutation)({
|
|
1520
1834
|
mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
|
|
1521
1835
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
|
|
1522
1836
|
});
|
|
1523
1837
|
}
|
|
1838
|
+
|
|
1839
|
+
// src/hooks/use-returns.ts
|
|
1840
|
+
var import_react_query37 = require("@tanstack/react-query");
|
|
1524
1841
|
var STALE2 = 3e4;
|
|
1525
1842
|
var INVALIDATE_KEY4 = ["emporix", "returns"];
|
|
1526
1843
|
function useMyReturns(opts = {}) {
|
|
1527
1844
|
const { client } = useEmporix();
|
|
1528
1845
|
const ctx = useCustomerOnlyCtx();
|
|
1529
|
-
return
|
|
1846
|
+
return (0, import_react_query37.useQuery)({
|
|
1530
1847
|
queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1531
1848
|
queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
|
|
1532
1849
|
staleTime: STALE2
|
|
@@ -1535,7 +1852,7 @@ function useMyReturns(opts = {}) {
|
|
|
1535
1852
|
function useReturn(returnId) {
|
|
1536
1853
|
const { client } = useEmporix();
|
|
1537
1854
|
const ctx = useCustomerOnlyCtx();
|
|
1538
|
-
return
|
|
1855
|
+
return (0, import_react_query37.useQuery)({
|
|
1539
1856
|
queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1540
1857
|
queryFn: () => client.returns.getReturn(returnId, ctx),
|
|
1541
1858
|
enabled: Boolean(returnId),
|
|
@@ -1545,18 +1862,21 @@ function useReturn(returnId) {
|
|
|
1545
1862
|
function useCreateReturn() {
|
|
1546
1863
|
const { client } = useEmporix();
|
|
1547
1864
|
const ctx = useCustomerOnlyCtx();
|
|
1548
|
-
const qc =
|
|
1549
|
-
return
|
|
1865
|
+
const qc = (0, import_react_query37.useQueryClient)();
|
|
1866
|
+
return (0, import_react_query37.useMutation)({
|
|
1550
1867
|
mutationFn: (input) => client.returns.createReturn(input, ctx),
|
|
1551
1868
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
|
|
1552
1869
|
});
|
|
1553
1870
|
}
|
|
1871
|
+
|
|
1872
|
+
// src/hooks/use-approvals.ts
|
|
1873
|
+
var import_react_query38 = require("@tanstack/react-query");
|
|
1554
1874
|
var STALE3 = 3e4;
|
|
1555
1875
|
var INVALIDATE_KEY5 = ["emporix", "approvals"];
|
|
1556
1876
|
function useApprovals(opts = {}) {
|
|
1557
1877
|
const { client } = useEmporix();
|
|
1558
1878
|
const ctx = useCustomerOnlyCtx();
|
|
1559
|
-
return
|
|
1879
|
+
return (0, import_react_query38.useQuery)({
|
|
1560
1880
|
queryKey: emporixKey("approvals", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1561
1881
|
queryFn: () => client.approvals.listApprovals(opts.query ?? {}, ctx),
|
|
1562
1882
|
staleTime: STALE3
|
|
@@ -1565,7 +1885,7 @@ function useApprovals(opts = {}) {
|
|
|
1565
1885
|
function useApproval(approvalId) {
|
|
1566
1886
|
const { client } = useEmporix();
|
|
1567
1887
|
const ctx = useCustomerOnlyCtx();
|
|
1568
|
-
return
|
|
1888
|
+
return (0, import_react_query38.useQuery)({
|
|
1569
1889
|
queryKey: emporixKey("approvals", [approvalId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
|
|
1570
1890
|
queryFn: () => client.approvals.getApproval(approvalId, ctx),
|
|
1571
1891
|
enabled: Boolean(approvalId),
|
|
@@ -1575,8 +1895,8 @@ function useApproval(approvalId) {
|
|
|
1575
1895
|
function useCreateApproval() {
|
|
1576
1896
|
const { client } = useEmporix();
|
|
1577
1897
|
const ctx = useCustomerOnlyCtx();
|
|
1578
|
-
const qc =
|
|
1579
|
-
return
|
|
1898
|
+
const qc = (0, import_react_query38.useQueryClient)();
|
|
1899
|
+
return (0, import_react_query38.useMutation)({
|
|
1580
1900
|
mutationFn: (input) => client.approvals.createApproval(input, ctx),
|
|
1581
1901
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
|
|
1582
1902
|
});
|
|
@@ -1584,101 +1904,102 @@ function useCreateApproval() {
|
|
|
1584
1904
|
function useUpdateApproval() {
|
|
1585
1905
|
const { client } = useEmporix();
|
|
1586
1906
|
const ctx = useCustomerOnlyCtx();
|
|
1587
|
-
const qc =
|
|
1588
|
-
return
|
|
1907
|
+
const qc = (0, import_react_query38.useQueryClient)();
|
|
1908
|
+
return (0, import_react_query38.useMutation)({
|
|
1589
1909
|
mutationFn: ({ approvalId, ops }) => client.approvals.updateApproval(approvalId, ops, ctx),
|
|
1590
1910
|
onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY5 })
|
|
1591
1911
|
});
|
|
1592
1912
|
}
|
|
1593
|
-
|
|
1594
|
-
exports
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1913
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1914
|
+
0 && (module.exports = {
|
|
1915
|
+
useActiveCart,
|
|
1916
|
+
useActiveSite,
|
|
1917
|
+
useAddGroupMember,
|
|
1918
|
+
useAddToShoppingList,
|
|
1919
|
+
useAddressMutations,
|
|
1920
|
+
useApproval,
|
|
1921
|
+
useApprovals,
|
|
1922
|
+
useAssignContact,
|
|
1923
|
+
useAvailabilities,
|
|
1924
|
+
useAvailability,
|
|
1925
|
+
useCancelOrder,
|
|
1926
|
+
useCart,
|
|
1927
|
+
useCartMutations,
|
|
1928
|
+
useCategories,
|
|
1929
|
+
useCategoriesInfinite,
|
|
1930
|
+
useCategory,
|
|
1931
|
+
useCategoryTree,
|
|
1932
|
+
useChangePassword,
|
|
1933
|
+
useCheckout,
|
|
1934
|
+
useCloudFunction,
|
|
1935
|
+
useCompany,
|
|
1936
|
+
useCompanyContacts,
|
|
1937
|
+
useCompanyGroups,
|
|
1938
|
+
useCompanyLocations,
|
|
1939
|
+
useCompanySwitcher,
|
|
1940
|
+
useCreateApproval,
|
|
1941
|
+
useCreateCart,
|
|
1942
|
+
useCreateCompany,
|
|
1943
|
+
useCreateLocation,
|
|
1944
|
+
useCreateReturn,
|
|
1945
|
+
useCreateShoppingList,
|
|
1946
|
+
useCustomerAddresses,
|
|
1947
|
+
useCustomerSession,
|
|
1948
|
+
useDefaultSite,
|
|
1949
|
+
useDeleteCompany,
|
|
1950
|
+
useDeleteLocation,
|
|
1951
|
+
useDeleteShoppingList,
|
|
1952
|
+
useInvokeCloudFunction,
|
|
1953
|
+
useMatchPrices,
|
|
1954
|
+
useMatchPricesChunked,
|
|
1955
|
+
useMyCompanies,
|
|
1956
|
+
useMyOrders,
|
|
1957
|
+
useMyOrdersInfinite,
|
|
1958
|
+
useMyReturns,
|
|
1959
|
+
useMyRewardPoints,
|
|
1960
|
+
useMyRewardPointsSummary,
|
|
1961
|
+
useMySegmentCategories,
|
|
1962
|
+
useMySegmentCategoriesInfinite,
|
|
1963
|
+
useMySegmentCategoryTree,
|
|
1964
|
+
useMySegmentItems,
|
|
1965
|
+
useMySegmentProducts,
|
|
1966
|
+
useMySegmentProductsInfinite,
|
|
1967
|
+
useMySegments,
|
|
1968
|
+
useOrder,
|
|
1969
|
+
useOrderTransition,
|
|
1970
|
+
usePasswordReset,
|
|
1971
|
+
usePaymentModes,
|
|
1972
|
+
useProduct,
|
|
1973
|
+
useProductByCode,
|
|
1974
|
+
useProductMedia,
|
|
1975
|
+
useProductNameSearch,
|
|
1976
|
+
useProductSearch,
|
|
1977
|
+
useProducts,
|
|
1978
|
+
useProductsByCodes,
|
|
1979
|
+
useProductsInCategory,
|
|
1980
|
+
useProductsInCategoryInfinite,
|
|
1981
|
+
useProductsInfinite,
|
|
1982
|
+
useRedeemCoupon,
|
|
1983
|
+
useRedeemOptions,
|
|
1984
|
+
useRedeemRewardPoints,
|
|
1985
|
+
useRemoveFromShoppingList,
|
|
1986
|
+
useRemoveGroupMember,
|
|
1987
|
+
useReorder,
|
|
1988
|
+
useReturn,
|
|
1989
|
+
useSalesOrder,
|
|
1990
|
+
useSetShoppingListItemQuantity,
|
|
1991
|
+
useShoppingLists,
|
|
1992
|
+
useSiteContext,
|
|
1993
|
+
useSites,
|
|
1994
|
+
useSubcategories,
|
|
1995
|
+
useUnassignContact,
|
|
1996
|
+
useUpdateApproval,
|
|
1997
|
+
useUpdateCompany,
|
|
1998
|
+
useUpdateContactAssignment,
|
|
1999
|
+
useUpdateCustomer,
|
|
2000
|
+
useUpdateLocation,
|
|
2001
|
+
useUpdateSalesOrder,
|
|
2002
|
+
useValidateCoupon,
|
|
2003
|
+
useVariantChildren
|
|
2004
|
+
});
|
|
1684
2005
|
//# sourceMappingURL=hooks.cjs.map
|