@viu/emporix-sdk-react 2.14.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -136,6 +136,7 @@ var SITE_KEY = "emporix.siteCode";
136
136
  var LANGUAGE_KEY = "emporix.language";
137
137
  var ACTIVE_LE_KEY = "emporix.activeLegalEntityId";
138
138
  var REFRESH_KEY = "emporix.refreshToken";
139
+ var SAAS_KEY = "emporix.saasToken";
139
140
  function createLocalStorageStorage(opts = {}) {
140
141
  const tokenKey = opts.key ?? DEFAULT_TOKEN_KEY;
141
142
  const available = typeof globalThis !== "undefined" && typeof globalThis.localStorage !== "undefined";
@@ -194,6 +195,12 @@ function createLocalStorageStorage(opts = {}) {
194
195
  else ls.setItem(REFRESH_KEY, t);
195
196
  all.notify("refreshToken");
196
197
  },
198
+ getSaasToken: () => ls.getItem(SAAS_KEY),
199
+ setSaasToken: (t) => {
200
+ if (t === null) ls.removeItem(SAAS_KEY);
201
+ else ls.setItem(SAAS_KEY, t);
202
+ all.notify("saasToken");
203
+ },
197
204
  subscribeAll: (l) => all.add(l)
198
205
  };
199
206
  }
@@ -206,6 +213,7 @@ var SITE_NAME = "emporix.siteCode";
206
213
  var LANGUAGE_NAME = "emporix.language";
207
214
  var ACTIVE_LE_NAME = "emporix.activeLegalEntityId";
208
215
  var REFRESH_NAME = "emporix.refreshToken";
216
+ var SAAS_NAME = "emporix.saasToken";
209
217
  function createCookieStorage(opts = {}) {
210
218
  const tokenName = opts.name ?? DEFAULT_TOKEN_NAME;
211
219
  const sameSite = opts.sameSite ?? "lax";
@@ -265,6 +273,11 @@ function createCookieStorage(opts = {}) {
265
273
  writeCookie(REFRESH_NAME, t);
266
274
  all.notify("refreshToken");
267
275
  },
276
+ getSaasToken: () => readCookie(SAAS_NAME),
277
+ setSaasToken: (t) => {
278
+ writeCookie(SAAS_NAME, t);
279
+ all.notify("saasToken");
280
+ },
268
281
  subscribeAll: (l) => all.add(l)
269
282
  };
270
283
  }
@@ -309,6 +322,7 @@ function createMemoryStorage(opts = {}) {
309
322
  let language = null;
310
323
  let activeLegalEntityId = null;
311
324
  let refreshToken = null;
325
+ let saasToken = null;
312
326
  const tokenListeners = /* @__PURE__ */ new Set();
313
327
  const all = createListenerSet();
314
328
  return {
@@ -352,6 +366,11 @@ function createMemoryStorage(opts = {}) {
352
366
  refreshToken = t;
353
367
  all.notify("refreshToken");
354
368
  },
369
+ getSaasToken: () => saasToken,
370
+ setSaasToken: (t) => {
371
+ saasToken = t;
372
+ all.notify("saasToken");
373
+ },
355
374
  subscribeAll: (l) => all.add(l)
356
375
  };
357
376
  }
@@ -937,8 +956,8 @@ function getCustomerSessionStore(storage) {
937
956
  if (existing) return existing;
938
957
  let state = {
939
958
  token: storage.getCustomerToken(),
940
- refreshToken: null,
941
- saasToken: null
959
+ refreshToken: storage.getRefreshToken(),
960
+ saasToken: storage.getSaasToken?.() ?? null
942
961
  };
943
962
  const listeners = /* @__PURE__ */ new Set();
944
963
  const store = {
@@ -989,6 +1008,7 @@ function useCustomerSession() {
989
1008
  const result = await client.customers.login(input);
990
1009
  storage.setCustomerToken(result.customerToken);
991
1010
  storage.setRefreshToken(result.refreshToken || null);
1011
+ storage.setSaasToken?.(result.saasToken || null);
992
1012
  storage.setAnonymousSession(null);
993
1013
  setSession({
994
1014
  token: result.customerToken,
@@ -1022,6 +1042,7 @@ function useCustomerSession() {
1022
1042
  async (incoming) => {
1023
1043
  storage.setCustomerToken(incoming.customerToken);
1024
1044
  storage.setRefreshToken(incoming.refreshToken || null);
1045
+ storage.setSaasToken?.(incoming.saasToken || null);
1025
1046
  storage.setAnonymousSession(null);
1026
1047
  setSession({
1027
1048
  token: incoming.customerToken,
@@ -1066,6 +1087,7 @@ function useCustomerSession() {
1066
1087
  }
1067
1088
  storage.setCustomerToken(null);
1068
1089
  storage.setRefreshToken(null);
1090
+ storage.setSaasToken?.(null);
1069
1091
  storage.setActiveLegalEntityId(null);
1070
1092
  storage.setCartId(null);
1071
1093
  setSession(EMPTY_SESSION);
@@ -1082,6 +1104,7 @@ function useCustomerSession() {
1082
1104
  });
1083
1105
  storage.setCustomerToken(refreshed.customerToken);
1084
1106
  if (refreshed.refreshToken) storage.setRefreshToken(refreshed.refreshToken);
1107
+ if (refreshed.saasToken) storage.setSaasToken?.(refreshed.saasToken);
1085
1108
  setSession((s) => ({
1086
1109
  token: refreshed.customerToken,
1087
1110
  refreshToken: refreshed.refreshToken || s.refreshToken,
@@ -1154,8 +1177,8 @@ async function onboardCustomerCart(opts) {
1154
1177
  }
1155
1178
 
1156
1179
  // src/hooks/use-products.ts
1157
- var import_react_query5 = require("@tanstack/react-query");
1158
- var import_emporix_sdk5 = require("@viu/emporix-sdk");
1180
+ var import_react_query6 = require("@tanstack/react-query");
1181
+ var import_emporix_sdk6 = require("@viu/emporix-sdk");
1159
1182
 
1160
1183
  // src/hooks/internal/use-read-auth.ts
1161
1184
  var import_emporix_sdk4 = require("@viu/emporix-sdk");
@@ -1230,25 +1253,54 @@ function useEmporixInfinite(opts) {
1230
1253
  });
1231
1254
  }
1232
1255
 
1256
+ // src/hooks/internal/use-emporix-query.ts
1257
+ var import_react_query5 = require("@tanstack/react-query");
1258
+ var import_emporix_sdk5 = require("@viu/emporix-sdk");
1259
+ function useEmporixQuery(cfg) {
1260
+ const { client } = useEmporix();
1261
+ const token = useCustomerToken();
1262
+ const { siteCode, language } = useReadSite();
1263
+ const authOverride = cfg.mode === "read-auth" ? cfg.authOverride : void 0;
1264
+ const readCtx = authOverride ?? (token ? import_emporix_sdk5.auth.customer(token) : import_emporix_sdk5.auth.anonymous());
1265
+ const authKind = cfg.mode === "customer" ? token ? "customer" : "anonymous" : readCtx.kind;
1266
+ const resolvedCtx = cfg.mode === "customer" ? import_emporix_sdk5.auth.customer(token) : readCtx;
1267
+ const siteMeta = cfg.site === "full" ? { siteCode, language } : cfg.site === "language" ? { language } : {};
1268
+ const enabled = (cfg.enabled ?? true) && (cfg.mode === "customer" ? token !== null : true);
1269
+ return (0, import_react_query5.useQuery)({
1270
+ queryKey: emporixKey(cfg.resource, cfg.args, {
1271
+ tenant: client.tenant,
1272
+ authKind,
1273
+ ...siteMeta
1274
+ }),
1275
+ queryFn: () => cfg.queryFn(resolvedCtx),
1276
+ enabled,
1277
+ ...cfg.staleTime !== void 0 ? { staleTime: cfg.staleTime } : {}
1278
+ });
1279
+ }
1280
+
1233
1281
  // src/hooks/use-products.ts
1234
1282
  var PRODUCTS_STALE_TIME = 6e4;
1235
1283
  function useProduct(productId, options = {}) {
1236
1284
  const { client } = useEmporix();
1237
- const { ctx } = useReadAuth(options.auth);
1238
- const { siteCode, language } = useReadSite();
1239
- return (0, import_react_query5.useQuery)({
1240
- queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1241
- queryFn: () => client.products.get(productId, void 0, ctx),
1285
+ return useEmporixQuery({
1286
+ mode: "read-auth",
1287
+ site: "full",
1288
+ resource: "product",
1289
+ args: [productId],
1290
+ ...options.auth ? { authOverride: options.auth } : {},
1291
+ queryFn: (ctx) => client.products.get(productId, void 0, ctx),
1242
1292
  staleTime: PRODUCTS_STALE_TIME
1243
1293
  });
1244
1294
  }
1245
1295
  function useProducts(params = {}, options = {}) {
1246
1296
  const { client } = useEmporix();
1247
- const { ctx } = useReadAuth(options.auth);
1248
- const { siteCode, language } = useReadSite();
1249
- return (0, import_react_query5.useQuery)({
1250
- queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1251
- queryFn: () => client.products.list(params, ctx),
1297
+ return useEmporixQuery({
1298
+ mode: "read-auth",
1299
+ site: "full",
1300
+ resource: "products",
1301
+ args: [params],
1302
+ ...options.auth ? { authOverride: options.auth } : {},
1303
+ queryFn: (ctx) => client.products.list(params, ctx),
1252
1304
  staleTime: PRODUCTS_STALE_TIME
1253
1305
  });
1254
1306
  }
@@ -1267,50 +1319,53 @@ function useProductsInfinite(params = {}, options = {}) {
1267
1319
  }
1268
1320
  function useProductByCode(code, options = {}) {
1269
1321
  const { client } = useEmporix();
1270
- const { ctx } = useReadAuth(options.auth);
1271
- const { siteCode, language } = useReadSite();
1272
- return (0, import_react_query5.useQuery)({
1273
- queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1322
+ return useEmporixQuery({
1323
+ mode: "read-auth",
1324
+ site: "full",
1325
+ resource: "product-by-code",
1326
+ args: [code],
1327
+ ...options.auth ? { authOverride: options.auth } : {},
1274
1328
  enabled: typeof code === "string" && code !== "",
1275
- queryFn: () => client.products.getByCode(code, ctx),
1329
+ queryFn: (ctx) => client.products.getByCode(code, ctx),
1276
1330
  staleTime: PRODUCTS_STALE_TIME
1277
1331
  });
1278
1332
  }
1279
1333
  function useProductSearch(query, params = {}, options = {}) {
1280
1334
  const { client } = useEmporix();
1281
- const { ctx } = useReadAuth(options.auth);
1282
- const { siteCode, language } = useReadSite();
1283
- return (0, import_react_query5.useQuery)({
1284
- queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1335
+ return useEmporixQuery({
1336
+ mode: "read-auth",
1337
+ site: "full",
1338
+ resource: "product-search",
1339
+ args: [query, params],
1340
+ ...options.auth ? { authOverride: options.auth } : {},
1285
1341
  enabled: typeof query === "string" && query.trim() !== "",
1286
- queryFn: () => client.products.search(query, params, ctx),
1342
+ queryFn: (ctx) => client.products.search(query, params, ctx),
1287
1343
  staleTime: PRODUCTS_STALE_TIME
1288
1344
  });
1289
1345
  }
1290
1346
  function useProductNameSearch(term, params = {}, options = {}) {
1291
1347
  const { client } = useEmporix();
1292
- const { ctx } = useReadAuth(options.auth);
1293
- const { siteCode, language } = useReadSite();
1294
- return (0, import_react_query5.useQuery)({
1295
- queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1348
+ return useEmporixQuery({
1349
+ mode: "read-auth",
1350
+ site: "full",
1351
+ resource: "product-name-search",
1352
+ args: [term, params],
1353
+ ...options.auth ? { authOverride: options.auth } : {},
1296
1354
  enabled: typeof term === "string" && term.trim() !== "",
1297
- queryFn: () => client.products.searchByName(term, params, ctx),
1355
+ queryFn: (ctx) => client.products.searchByName(term, params, ctx),
1298
1356
  staleTime: PRODUCTS_STALE_TIME
1299
1357
  });
1300
1358
  }
1301
1359
  function useProductsByCodes(codes, options = {}) {
1302
1360
  const { client } = useEmporix();
1303
- const { ctx } = useReadAuth(options.auth);
1304
- const { siteCode, language } = useReadSite();
1305
- return (0, import_react_query5.useQuery)({
1306
- queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
1307
- tenant: client.tenant,
1308
- authKind: ctx.kind,
1309
- siteCode,
1310
- language
1311
- }),
1361
+ return useEmporixQuery({
1362
+ mode: "read-auth",
1363
+ site: "full",
1364
+ resource: "products-by-codes",
1365
+ args: [codes, options.chunkSize],
1366
+ ...options.auth ? { authOverride: options.auth } : {},
1312
1367
  enabled: codes.length > 0,
1313
- queryFn: () => client.products.searchByCodes(
1368
+ queryFn: (ctx) => client.products.searchByCodes(
1314
1369
  codes,
1315
1370
  options.chunkSize !== void 0 ? { chunkSize: options.chunkSize } : {},
1316
1371
  ctx
@@ -1320,15 +1375,15 @@ function useProductsByCodes(codes, options = {}) {
1320
1375
  }
1321
1376
 
1322
1377
  // src/hooks/use-shopping-lists.ts
1323
- var import_react_query6 = require("@tanstack/react-query");
1324
- var import_emporix_sdk6 = require("@viu/emporix-sdk");
1378
+ var import_react_query7 = require("@tanstack/react-query");
1379
+ var import_emporix_sdk7 = require("@viu/emporix-sdk");
1325
1380
  var SHOPPING_LIST_STALE_TIME = 3e4;
1326
1381
  var INVALIDATE_KEY = ["emporix", "shopping-lists"];
1327
1382
  function useShoppingLists(opts = {}) {
1328
1383
  const { client } = useEmporix();
1329
1384
  const ctx = useCustomerOnlyCtx();
1330
1385
  const { siteCode, language } = useReadSite();
1331
- return (0, import_react_query6.useQuery)({
1386
+ return (0, import_react_query7.useQuery)({
1332
1387
  queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1333
1388
  queryFn: () => client.shoppingLists.list(ctx, opts),
1334
1389
  staleTime: SHOPPING_LIST_STALE_TIME
@@ -1337,8 +1392,8 @@ function useShoppingLists(opts = {}) {
1337
1392
  function useCreateShoppingList() {
1338
1393
  const { client } = useEmporix();
1339
1394
  const ctx = useCustomerOnlyCtx();
1340
- const qc = (0, import_react_query6.useQueryClient)();
1341
- return (0, import_react_query6.useMutation)({
1395
+ const qc = (0, import_react_query7.useQueryClient)();
1396
+ return (0, import_react_query7.useMutation)({
1342
1397
  mutationFn: (draft) => client.shoppingLists.create(draft, ctx),
1343
1398
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1344
1399
  });
@@ -1346,8 +1401,8 @@ function useCreateShoppingList() {
1346
1401
  function useDeleteShoppingList() {
1347
1402
  const { client } = useEmporix();
1348
1403
  const ctx = useCustomerOnlyCtx();
1349
- const qc = (0, import_react_query6.useQueryClient)();
1350
- return (0, import_react_query6.useMutation)({
1404
+ const qc = (0, import_react_query7.useQueryClient)();
1405
+ return (0, import_react_query7.useMutation)({
1351
1406
  mutationFn: ({ customerId, name }) => client.shoppingLists.delete(customerId, ctx, name !== void 0 ? { name } : {}),
1352
1407
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1353
1408
  });
@@ -1355,8 +1410,8 @@ function useDeleteShoppingList() {
1355
1410
  function useAddToShoppingList() {
1356
1411
  const { client } = useEmporix();
1357
1412
  const ctx = useCustomerOnlyCtx();
1358
- const qc = (0, import_react_query6.useQueryClient)();
1359
- return (0, import_react_query6.useMutation)({
1413
+ const qc = (0, import_react_query7.useQueryClient)();
1414
+ return (0, import_react_query7.useMutation)({
1360
1415
  mutationFn: ({ customerId, listName, item }) => client.shoppingLists.addItem(customerId, listName, item, ctx),
1361
1416
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1362
1417
  });
@@ -1364,8 +1419,8 @@ function useAddToShoppingList() {
1364
1419
  function useRemoveFromShoppingList() {
1365
1420
  const { client } = useEmporix();
1366
1421
  const ctx = useCustomerOnlyCtx();
1367
- const qc = (0, import_react_query6.useQueryClient)();
1368
- return (0, import_react_query6.useMutation)({
1422
+ const qc = (0, import_react_query7.useQueryClient)();
1423
+ return (0, import_react_query7.useMutation)({
1369
1424
  mutationFn: ({ customerId, listName, productId }) => client.shoppingLists.removeItem(customerId, listName, productId, ctx),
1370
1425
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1371
1426
  });
@@ -1373,29 +1428,27 @@ function useRemoveFromShoppingList() {
1373
1428
  function useSetShoppingListItemQuantity() {
1374
1429
  const { client } = useEmporix();
1375
1430
  const ctx = useCustomerOnlyCtx();
1376
- const qc = (0, import_react_query6.useQueryClient)();
1377
- return (0, import_react_query6.useMutation)({
1431
+ const qc = (0, import_react_query7.useQueryClient)();
1432
+ return (0, import_react_query7.useMutation)({
1378
1433
  mutationFn: ({ customerId, listName, productId, quantity }) => client.shoppingLists.setItemQuantity(customerId, listName, productId, quantity, ctx),
1379
1434
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY })
1380
1435
  });
1381
1436
  }
1382
1437
 
1383
1438
  // src/hooks/use-variant-children.ts
1384
- var import_react_query7 = require("@tanstack/react-query");
1385
- var import_emporix_sdk7 = require("@viu/emporix-sdk");
1439
+ var import_react_query8 = require("@tanstack/react-query");
1440
+ var import_emporix_sdk8 = require("@viu/emporix-sdk");
1386
1441
  var VARIANT_CHILDREN_STALE_TIME = 6e4;
1387
1442
  function useVariantChildren(parentVariantId, options = {}) {
1388
1443
  const { client } = useEmporix();
1389
- const { ctx } = useReadAuth(options.auth);
1390
- const { siteCode, language } = useReadSite();
1391
- return (0, import_react_query7.useQuery)({
1392
- queryKey: emporixKey(
1393
- "variant-children",
1394
- [parentVariantId, { pageSize: options.pageSize }],
1395
- { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1396
- ),
1444
+ return useEmporixQuery({
1445
+ mode: "read-auth",
1446
+ site: "full",
1447
+ resource: "variant-children",
1448
+ args: [parentVariantId, { pageSize: options.pageSize }],
1449
+ ...options.auth ? { authOverride: options.auth } : {},
1397
1450
  enabled: typeof parentVariantId === "string" && parentVariantId !== "",
1398
- queryFn: () => client.products.listVariantChildren(
1451
+ queryFn: (ctx) => client.products.listVariantChildren(
1399
1452
  parentVariantId,
1400
1453
  options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
1401
1454
  ctx
@@ -1405,37 +1458,43 @@ function useVariantChildren(parentVariantId, options = {}) {
1405
1458
  }
1406
1459
 
1407
1460
  // src/hooks/use-categories.ts
1408
- var import_react_query8 = require("@tanstack/react-query");
1409
- var import_emporix_sdk8 = require("@viu/emporix-sdk");
1461
+ var import_react_query9 = require("@tanstack/react-query");
1462
+ var import_emporix_sdk9 = require("@viu/emporix-sdk");
1410
1463
  var CATEGORIES_STALE_TIME = 5 * 6e4;
1411
1464
  function useCategory(categoryId, options = {}) {
1412
1465
  const { client } = useEmporix();
1413
- const { ctx } = useReadAuth(options.auth);
1414
- const { siteCode, language } = useReadSite();
1415
- return (0, import_react_query8.useQuery)({
1416
- queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1417
- queryFn: () => client.categories.get(categoryId, ctx),
1466
+ return useEmporixQuery({
1467
+ mode: "read-auth",
1468
+ site: "full",
1469
+ resource: "category",
1470
+ args: [categoryId],
1471
+ ...options.auth ? { authOverride: options.auth } : {},
1472
+ queryFn: (ctx) => client.categories.get(categoryId, ctx),
1418
1473
  staleTime: CATEGORIES_STALE_TIME
1419
1474
  });
1420
1475
  }
1421
1476
  function useSubcategories(categoryId, params = {}, options = {}) {
1422
1477
  const { client } = useEmporix();
1423
- const { ctx } = useReadAuth(options.auth);
1424
- const { siteCode, language } = useReadSite();
1425
- return (0, import_react_query8.useQuery)({
1426
- queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1478
+ return useEmporixQuery({
1479
+ mode: "read-auth",
1480
+ site: "full",
1481
+ resource: "subcategories",
1482
+ args: [categoryId ?? null, params],
1483
+ ...options.auth ? { authOverride: options.auth } : {},
1427
1484
  enabled: typeof categoryId === "string" && categoryId !== "",
1428
- queryFn: () => client.categories.subcategories(categoryId, params, ctx),
1485
+ queryFn: (ctx) => client.categories.subcategories(categoryId, params, ctx),
1429
1486
  staleTime: CATEGORIES_STALE_TIME
1430
1487
  });
1431
1488
  }
1432
1489
  function useCategories(params = {}, options = {}) {
1433
1490
  const { client } = useEmporix();
1434
- const { ctx } = useReadAuth(options.auth);
1435
- const { siteCode, language } = useReadSite();
1436
- return (0, import_react_query8.useQuery)({
1437
- queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1438
- queryFn: () => client.categories.list(params, ctx),
1491
+ return useEmporixQuery({
1492
+ mode: "read-auth",
1493
+ site: "full",
1494
+ resource: "categories",
1495
+ args: [params],
1496
+ ...options.auth ? { authOverride: options.auth } : {},
1497
+ queryFn: (ctx) => client.categories.list(params, ctx),
1439
1498
  staleTime: CATEGORIES_STALE_TIME
1440
1499
  });
1441
1500
  }
@@ -1454,22 +1513,26 @@ function useCategoriesInfinite(params = {}, options = {}) {
1454
1513
  }
1455
1514
  function useCategoryTree(options = {}) {
1456
1515
  const { client } = useEmporix();
1457
- const { ctx } = useReadAuth(options.auth);
1458
- const { siteCode, language } = useReadSite();
1459
- return (0, import_react_query8.useQuery)({
1460
- queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1461
- queryFn: () => client.categories.tree(ctx),
1516
+ return useEmporixQuery({
1517
+ mode: "read-auth",
1518
+ site: "full",
1519
+ resource: "category-tree",
1520
+ args: [],
1521
+ ...options.auth ? { authOverride: options.auth } : {},
1522
+ queryFn: (ctx) => client.categories.tree(ctx),
1462
1523
  staleTime: CATEGORIES_STALE_TIME
1463
1524
  });
1464
1525
  }
1465
1526
  function useProductsInCategory(categoryId, params = {}, options = {}) {
1466
1527
  const { client } = useEmporix();
1467
- const { ctx } = useReadAuth(options.auth);
1468
- const { siteCode, language } = useReadSite();
1469
- return (0, import_react_query8.useQuery)({
1470
- queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1528
+ return useEmporixQuery({
1529
+ mode: "read-auth",
1530
+ site: "full",
1531
+ resource: "products-in-category",
1532
+ args: [categoryId, params],
1533
+ ...options.auth ? { authOverride: options.auth } : {},
1471
1534
  enabled: typeof categoryId === "string" && categoryId !== "",
1472
- queryFn: () => client.categories.productsIn(categoryId, params, ctx),
1535
+ queryFn: (ctx) => client.categories.productsIn(categoryId, params, ctx),
1473
1536
  staleTime: CATEGORIES_STALE_TIME
1474
1537
  });
1475
1538
  }
@@ -1491,35 +1554,33 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
1491
1554
 
1492
1555
  // src/hooks/use-cart.ts
1493
1556
  var import_react7 = require("react");
1494
- var import_react_query9 = require("@tanstack/react-query");
1495
- var import_emporix_sdk9 = require("@viu/emporix-sdk");
1557
+ var import_react_query10 = require("@tanstack/react-query");
1558
+ var import_emporix_sdk10 = require("@viu/emporix-sdk");
1496
1559
  function useCart(cartId, options = {}) {
1497
1560
  const { client } = useEmporix();
1498
- const { ctx } = useReadAuth(options.auth);
1499
- const { siteCode, language } = useReadSite();
1500
1561
  const { activeCompany } = useActiveCompany();
1501
1562
  const storedCartId = useCartId();
1502
1563
  const resolvedId = cartId ?? storedCartId ?? void 0;
1503
- return (0, import_react_query9.useQuery)({
1504
- queryKey: emporixKey(
1505
- "cart",
1506
- [resolvedId ?? null, activeCompany?.id ?? null],
1507
- { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1508
- ),
1564
+ return useEmporixQuery({
1565
+ mode: "read-auth",
1566
+ site: "full",
1567
+ resource: "cart",
1568
+ args: [resolvedId ?? null, activeCompany?.id ?? null],
1569
+ ...options.auth ? { authOverride: options.auth } : {},
1509
1570
  enabled: resolvedId !== void 0,
1510
- queryFn: () => client.carts.get(resolvedId, ctx)
1571
+ queryFn: (ctx) => client.carts.get(resolvedId, ctx)
1511
1572
  });
1512
1573
  }
1513
1574
  function useCartMutations(cartId) {
1514
1575
  const { client, storage } = useEmporix();
1515
- const qc = (0, import_react_query9.useQueryClient)();
1576
+ const qc = (0, import_react_query10.useQueryClient)();
1516
1577
  const { ctx } = useReadAuth();
1517
1578
  const { siteCode, language } = useReadSite();
1518
1579
  const { activeCompany } = useActiveCompany();
1519
1580
  const resolveId = () => {
1520
1581
  const id = cartId ?? storage.getCartId();
1521
1582
  if (!id) {
1522
- throw new import_emporix_sdk9.EmporixError(
1583
+ throw new import_emporix_sdk10.EmporixError(
1523
1584
  "useCartMutations: no cartId available \u2014 pass one explicitly or call useActiveCart({ create: true }) first"
1524
1585
  );
1525
1586
  }
@@ -1531,7 +1592,7 @@ function useCartMutations(cartId) {
1531
1592
  { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1532
1593
  );
1533
1594
  function make(run, optimistic) {
1534
- return (0, import_react_query9.useMutation)({
1595
+ return (0, import_react_query10.useMutation)({
1535
1596
  mutationFn: async (vars) => run(resolveId(), vars),
1536
1597
  onMutate: async (vars) => {
1537
1598
  const id = resolveId();
@@ -1588,9 +1649,9 @@ function useCartMutations(cartId) {
1588
1649
  }
1589
1650
  function useCreateCart() {
1590
1651
  const { client, storage } = useEmporix();
1591
- const qc = (0, import_react_query9.useQueryClient)();
1652
+ const qc = (0, import_react_query10.useQueryClient)();
1592
1653
  const { ctx } = useReadAuth();
1593
- return (0, import_react_query9.useMutation)({
1654
+ return (0, import_react_query10.useMutation)({
1594
1655
  mutationFn: (input) => client.carts.create(input, ctx),
1595
1656
  onSuccess: async (cart) => {
1596
1657
  if (cart.cartId) storage.setCartId(cart.cartId);
@@ -1600,7 +1661,7 @@ function useCreateCart() {
1600
1661
  }
1601
1662
  function useActiveCart(opts) {
1602
1663
  const { client, storage } = useEmporix();
1603
- const qc = (0, import_react_query9.useQueryClient)();
1664
+ const qc = (0, import_react_query10.useQueryClient)();
1604
1665
  const { ctx } = useReadAuth(opts?.auth);
1605
1666
  const { siteCode: activeSite } = useReadSite();
1606
1667
  const { activeCompany } = useActiveCompany();
@@ -1636,15 +1697,16 @@ function useActiveCart(opts) {
1636
1697
  }
1637
1698
 
1638
1699
  // src/hooks/use-checkout.ts
1639
- var import_react_query10 = require("@tanstack/react-query");
1640
- var import_emporix_sdk10 = require("@viu/emporix-sdk");
1700
+ var import_react_query11 = require("@tanstack/react-query");
1701
+ var import_emporix_sdk11 = require("@viu/emporix-sdk");
1641
1702
  var PAYMENT_MODES_STALE_TIME = 10 * 6e4;
1642
1703
  function customerOnlyCtx(token) {
1643
1704
  if (!token) throw new Error("usePaymentModes requires a logged-in customer token");
1644
- return import_emporix_sdk10.auth.customer(token);
1705
+ return import_emporix_sdk11.auth.customer(token);
1645
1706
  }
1646
1707
  function useCheckout() {
1647
- const { client } = useEmporix();
1708
+ const { client, storage } = useEmporix();
1709
+ const qc = (0, import_react_query11.useQueryClient)();
1648
1710
  const { ctx } = useReadAuth();
1649
1711
  const { activeCompany } = useActiveCompany();
1650
1712
  const withLE = (input) => {
@@ -1652,17 +1714,23 @@ function useCheckout() {
1652
1714
  if ("legalEntityId" in input) return input;
1653
1715
  return { ...input, legalEntityId: activeCompany.id };
1654
1716
  };
1655
- const placeOrder = (0, import_react_query10.useMutation)({
1717
+ const onOrderPlaced = () => {
1718
+ storage.setCartId(null);
1719
+ qc.removeQueries({ queryKey: ["emporix", "cart-bootstrap"] });
1720
+ };
1721
+ const placeOrder = (0, import_react_query11.useMutation)({
1656
1722
  mutationFn: (v) => client.checkout.placeOrder(withLE(v.input), ctx, {
1657
1723
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
1658
1724
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
1659
- })
1725
+ }),
1726
+ onSuccess: onOrderPlaced
1660
1727
  });
1661
- const placeOrderFromQuote = (0, import_react_query10.useMutation)({
1728
+ const placeOrderFromQuote = (0, import_react_query11.useMutation)({
1662
1729
  mutationFn: (v) => client.checkout.placeOrderFromQuote(withLE(v.input), ctx, {
1663
1730
  ...v.saasToken !== void 0 ? { saasToken: v.saasToken } : {},
1664
1731
  ...v.siteCode !== void 0 ? { siteCode: v.siteCode } : {}
1665
- })
1732
+ }),
1733
+ onSuccess: onOrderPlaced
1666
1734
  });
1667
1735
  return { placeOrder, placeOrderFromQuote };
1668
1736
  }
@@ -1671,7 +1739,7 @@ function usePaymentModes(options = {}) {
1671
1739
  const token = useCustomerToken();
1672
1740
  const { siteCode } = useReadSite();
1673
1741
  const { activeCompany } = useActiveCompany();
1674
- return (0, import_react_query10.useQuery)({
1742
+ return (0, import_react_query11.useQuery)({
1675
1743
  queryKey: emporixKey(
1676
1744
  "payment-modes",
1677
1745
  [activeCompany?.id ?? null],
@@ -1684,14 +1752,14 @@ function usePaymentModes(options = {}) {
1684
1752
  }
1685
1753
 
1686
1754
  // src/hooks/use-match-prices.ts
1687
- var import_react_query11 = require("@tanstack/react-query");
1688
- var import_emporix_sdk11 = require("@viu/emporix-sdk");
1755
+ var import_react_query12 = require("@tanstack/react-query");
1756
+ var import_emporix_sdk12 = require("@viu/emporix-sdk");
1689
1757
  var PRICES_STALE_TIME = 6e4;
1690
1758
  function useMatchPrices(input, options = {}) {
1691
1759
  const { client } = useEmporix();
1692
1760
  const { siteCode } = useReadSite();
1693
- const ctx = options.customerToken ? import_emporix_sdk11.auth.customer(options.customerToken) : import_emporix_sdk11.auth.anonymous();
1694
- return (0, import_react_query11.useQuery)({
1761
+ const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
1762
+ return (0, import_react_query12.useQuery)({
1695
1763
  queryKey: [
1696
1764
  "emporix",
1697
1765
  "match-prices",
@@ -1704,14 +1772,14 @@ function useMatchPrices(input, options = {}) {
1704
1772
  }
1705
1773
 
1706
1774
  // src/hooks/use-match-prices-chunked.ts
1707
- var import_react_query12 = require("@tanstack/react-query");
1708
- var import_emporix_sdk12 = require("@viu/emporix-sdk");
1775
+ var import_react_query13 = require("@tanstack/react-query");
1776
+ var import_emporix_sdk13 = require("@viu/emporix-sdk");
1709
1777
  var PRICES_STALE_TIME2 = 6e4;
1710
1778
  function useMatchPricesChunked(input, options = {}) {
1711
1779
  const { client } = useEmporix();
1712
1780
  const { siteCode } = useReadSite();
1713
- const ctx = options.customerToken ? import_emporix_sdk12.auth.customer(options.customerToken) : import_emporix_sdk12.auth.anonymous();
1714
- return (0, import_react_query12.useQuery)({
1781
+ const ctx = options.customerToken ? import_emporix_sdk13.auth.customer(options.customerToken) : import_emporix_sdk13.auth.anonymous();
1782
+ return (0, import_react_query13.useQuery)({
1715
1783
  queryKey: [
1716
1784
  "emporix",
1717
1785
  "match-prices-chunked",
@@ -1745,18 +1813,18 @@ function useProductMedia(productId) {
1745
1813
  }
1746
1814
 
1747
1815
  // src/hooks/use-my-segments.ts
1748
- var import_react_query13 = require("@tanstack/react-query");
1749
- var import_emporix_sdk13 = require("@viu/emporix-sdk");
1816
+ var import_react_query14 = require("@tanstack/react-query");
1817
+ var import_emporix_sdk14 = require("@viu/emporix-sdk");
1750
1818
  var SEGMENTS_STALE_TIME = 5 * 6e4;
1751
1819
  function customerCtx(token) {
1752
1820
  if (!token) throw new Error("requires a customer token in storage");
1753
- return import_emporix_sdk13.auth.customer(token);
1821
+ return import_emporix_sdk14.auth.customer(token);
1754
1822
  }
1755
1823
  function useMySegments(query = {}) {
1756
1824
  const { client } = useEmporix();
1757
1825
  const token = useCustomerToken();
1758
1826
  const { siteCode, language } = useReadSite();
1759
- return (0, import_react_query13.useQuery)({
1827
+ return (0, import_react_query14.useQuery)({
1760
1828
  queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
1761
1829
  enabled: token !== null,
1762
1830
  queryFn: () => client.segments.list(query, customerCtx(token)),
@@ -1767,7 +1835,7 @@ function useMySegmentItems(query = {}) {
1767
1835
  const { client } = useEmporix();
1768
1836
  const token = useCustomerToken();
1769
1837
  const { siteCode, language } = useReadSite();
1770
- return (0, import_react_query13.useQuery)({
1838
+ return (0, import_react_query14.useQuery)({
1771
1839
  queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
1772
1840
  enabled: token !== null,
1773
1841
  queryFn: () => client.segments.listItems(query, customerCtx(token)),
@@ -1778,7 +1846,7 @@ function useMySegmentCategoryTree(query = {}) {
1778
1846
  const { client } = useEmporix();
1779
1847
  const token = useCustomerToken();
1780
1848
  const { siteCode, language } = useReadSite();
1781
- return (0, import_react_query13.useQuery)({
1849
+ return (0, import_react_query14.useQuery)({
1782
1850
  queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
1783
1851
  enabled: token !== null,
1784
1852
  queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
@@ -1789,7 +1857,7 @@ function useMySegmentProducts(query = {}) {
1789
1857
  const { client } = useEmporix();
1790
1858
  const token = useCustomerToken();
1791
1859
  const { siteCode, language } = useReadSite();
1792
- return (0, import_react_query13.useQuery)({
1860
+ return (0, import_react_query14.useQuery)({
1793
1861
  queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
1794
1862
  enabled: token !== null,
1795
1863
  queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
@@ -1819,7 +1887,7 @@ function useMySegmentCategories(query = {}) {
1819
1887
  const { client } = useEmporix();
1820
1888
  const token = useCustomerToken();
1821
1889
  const { siteCode, language } = useReadSite();
1822
- return (0, import_react_query13.useQuery)({
1890
+ return (0, import_react_query14.useQuery)({
1823
1891
  queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
1824
1892
  enabled: token !== null,
1825
1893
  queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
@@ -1847,13 +1915,13 @@ function useMySegmentCategoriesInfinite(query = {}) {
1847
1915
  }
1848
1916
 
1849
1917
  // src/hooks/use-customer-profile.ts
1850
- var import_react_query14 = require("@tanstack/react-query");
1851
- var import_emporix_sdk14 = require("@viu/emporix-sdk");
1918
+ var import_react_query15 = require("@tanstack/react-query");
1919
+ var import_emporix_sdk15 = require("@viu/emporix-sdk");
1852
1920
  function useUpdateCustomer() {
1853
1921
  const { client } = useEmporix();
1854
1922
  const ctx = useCustomerOnlyCtx();
1855
- const qc = (0, import_react_query14.useQueryClient)();
1856
- return (0, import_react_query14.useMutation)({
1923
+ const qc = (0, import_react_query15.useQueryClient)();
1924
+ return (0, import_react_query15.useMutation)({
1857
1925
  mutationFn: (patch) => client.customers.update(patch, ctx),
1858
1926
  onSuccess: () => {
1859
1927
  void qc.invalidateQueries({ queryKey: ["emporix", "customer", "me"] });
@@ -1863,21 +1931,21 @@ function useUpdateCustomer() {
1863
1931
  function useChangePassword() {
1864
1932
  const { client } = useEmporix();
1865
1933
  const ctx = useCustomerOnlyCtx();
1866
- return (0, import_react_query14.useMutation)({
1934
+ return (0, import_react_query15.useMutation)({
1867
1935
  mutationFn: (input) => client.customers.changePassword(input, ctx)
1868
1936
  });
1869
1937
  }
1870
1938
 
1871
1939
  // src/hooks/use-customer-addresses.ts
1872
- var import_react_query15 = require("@tanstack/react-query");
1873
- var import_emporix_sdk15 = require("@viu/emporix-sdk");
1940
+ var import_react_query16 = require("@tanstack/react-query");
1941
+ var import_emporix_sdk16 = require("@viu/emporix-sdk");
1874
1942
  var ADDRESSES_KEY = ["emporix", "customer", "addresses"];
1875
1943
  function useCustomerAddresses(options = {}) {
1876
1944
  const { client } = useEmporix();
1877
1945
  const token = useCustomerToken();
1878
1946
  const { activeCompany } = useActiveCompany();
1879
- const ctx = options.auth ?? (token ? import_emporix_sdk15.auth.customer(token) : null);
1880
- return (0, import_react_query15.useQuery)({
1947
+ const ctx = options.auth ?? (token ? import_emporix_sdk16.auth.customer(token) : null);
1948
+ return (0, import_react_query16.useQuery)({
1881
1949
  queryKey: [
1882
1950
  ...ADDRESSES_KEY,
1883
1951
  { tenant: client.tenant, hasToken: token !== null, legalEntityId: activeCompany?.id ?? null }
@@ -1889,20 +1957,20 @@ function useCustomerAddresses(options = {}) {
1889
1957
  function useAddressMutations() {
1890
1958
  const { client } = useEmporix();
1891
1959
  const ctx = useCustomerOnlyCtx();
1892
- const qc = (0, import_react_query15.useQueryClient)();
1960
+ const qc = (0, import_react_query16.useQueryClient)();
1893
1961
  const invalidate = () => {
1894
1962
  void qc.invalidateQueries({ queryKey: ADDRESSES_KEY });
1895
1963
  };
1896
1964
  return {
1897
- add: (0, import_react_query15.useMutation)({
1965
+ add: (0, import_react_query16.useMutation)({
1898
1966
  mutationFn: (input) => client.customers.addresses.add(input, ctx),
1899
1967
  onSuccess: invalidate
1900
1968
  }),
1901
- update: (0, import_react_query15.useMutation)({
1969
+ update: (0, import_react_query16.useMutation)({
1902
1970
  mutationFn: ({ id, patch }) => client.customers.addresses.update(id, patch, ctx),
1903
1971
  onSuccess: invalidate
1904
1972
  }),
1905
- remove: (0, import_react_query15.useMutation)({
1973
+ remove: (0, import_react_query16.useMutation)({
1906
1974
  mutationFn: ({ id }) => client.customers.addresses.remove(id, ctx),
1907
1975
  onSuccess: invalidate
1908
1976
  })
@@ -1910,23 +1978,23 @@ function useAddressMutations() {
1910
1978
  }
1911
1979
 
1912
1980
  // src/hooks/use-password-reset.ts
1913
- var import_react_query16 = require("@tanstack/react-query");
1914
- var import_emporix_sdk16 = require("@viu/emporix-sdk");
1981
+ var import_react_query17 = require("@tanstack/react-query");
1982
+ var import_emporix_sdk17 = require("@viu/emporix-sdk");
1915
1983
  function usePasswordReset() {
1916
1984
  const { client } = useEmporix();
1917
- const anonCtx = import_emporix_sdk16.auth.anonymous();
1985
+ const anonCtx = import_emporix_sdk17.auth.anonymous();
1918
1986
  return {
1919
- request: (0, import_react_query16.useMutation)({
1987
+ request: (0, import_react_query17.useMutation)({
1920
1988
  mutationFn: (input) => client.customers.requestPasswordReset(input, anonCtx)
1921
1989
  }),
1922
- confirm: (0, import_react_query16.useMutation)({
1990
+ confirm: (0, import_react_query17.useMutation)({
1923
1991
  mutationFn: (input) => client.customers.confirmPasswordReset(input, anonCtx)
1924
1992
  })
1925
1993
  };
1926
1994
  }
1927
1995
 
1928
1996
  // src/hooks/use-sites.ts
1929
- var import_react_query17 = require("@tanstack/react-query");
1997
+ var import_react_query18 = require("@tanstack/react-query");
1930
1998
 
1931
1999
  // src/hooks/use-site-context.ts
1932
2000
  var import_react8 = require("react");
@@ -1943,7 +2011,7 @@ var SITES_STALE_TIME = 10 * 6e4;
1943
2011
  function useSites(options = {}) {
1944
2012
  const { client } = useEmporix();
1945
2013
  const { ctx } = useReadAuth(options.auth);
1946
- return (0, import_react_query17.useQuery)({
2014
+ return (0, import_react_query18.useQuery)({
1947
2015
  queryKey: emporixKey("sites", [], { tenant: client.tenant, authKind: ctx.kind }),
1948
2016
  queryFn: () => client.sites.list(ctx),
1949
2017
  staleTime: SITES_STALE_TIME
@@ -1952,7 +2020,7 @@ function useSites(options = {}) {
1952
2020
  function useDefaultSite(options = {}) {
1953
2021
  const { client } = useEmporix();
1954
2022
  const { ctx } = useReadAuth(options.auth);
1955
- return (0, import_react_query17.useQuery)({
2023
+ return (0, import_react_query18.useQuery)({
1956
2024
  queryKey: emporixKey("site-default", [], { tenant: client.tenant, authKind: ctx.kind }),
1957
2025
  queryFn: () => client.sites.current(ctx),
1958
2026
  staleTime: SITES_STALE_TIME
@@ -1965,101 +2033,95 @@ function useActiveSite(options = {}) {
1965
2033
  }
1966
2034
 
1967
2035
  // src/hooks/use-my-companies.ts
1968
- var import_react_query18 = require("@tanstack/react-query");
1969
- var import_emporix_sdk17 = require("@viu/emporix-sdk");
2036
+ var import_react_query19 = require("@tanstack/react-query");
2037
+ var import_emporix_sdk18 = require("@viu/emporix-sdk");
1970
2038
  function useMyCompanies() {
1971
2039
  const { client } = useEmporix();
1972
- const token = useCustomerToken();
1973
- return (0, import_react_query18.useQuery)({
1974
- queryKey: emporixKey("companies", ["mine"], {
1975
- tenant: client.tenant,
1976
- authKind: token ? "customer" : "anonymous"
1977
- }),
1978
- enabled: token !== null,
1979
- queryFn: () => client.companies.listMine(import_emporix_sdk17.auth.customer(token))
2040
+ return useEmporixQuery({
2041
+ mode: "customer",
2042
+ site: "none",
2043
+ resource: "companies",
2044
+ args: ["mine"],
2045
+ queryFn: (ctx) => client.companies.listMine(ctx)
1980
2046
  });
1981
2047
  }
1982
2048
 
1983
2049
  // src/hooks/use-company.ts
1984
- var import_react_query19 = require("@tanstack/react-query");
1985
- var import_emporix_sdk18 = require("@viu/emporix-sdk");
2050
+ var import_react_query20 = require("@tanstack/react-query");
2051
+ var import_emporix_sdk19 = require("@viu/emporix-sdk");
1986
2052
  function useCompany(legalEntityId) {
1987
2053
  const { client } = useEmporix();
1988
- const token = useCustomerToken();
1989
- return (0, import_react_query19.useQuery)({
1990
- queryKey: emporixKey("companies", [legalEntityId ?? null], {
1991
- tenant: client.tenant,
1992
- authKind: token ? "customer" : "anonymous"
1993
- }),
1994
- enabled: token !== null && legalEntityId !== void 0,
1995
- queryFn: () => client.companies.get(legalEntityId, import_emporix_sdk18.auth.customer(token))
2054
+ return useEmporixQuery({
2055
+ mode: "customer",
2056
+ site: "none",
2057
+ resource: "companies",
2058
+ args: [legalEntityId ?? null],
2059
+ enabled: legalEntityId !== void 0,
2060
+ queryFn: (ctx) => client.companies.get(legalEntityId, ctx)
1996
2061
  });
1997
2062
  }
1998
2063
 
1999
2064
  // src/hooks/use-company-contacts.ts
2000
- var import_react_query20 = require("@tanstack/react-query");
2001
- var import_emporix_sdk19 = require("@viu/emporix-sdk");
2065
+ var import_react_query21 = require("@tanstack/react-query");
2066
+ var import_emporix_sdk20 = require("@viu/emporix-sdk");
2002
2067
  function useCompanyContacts(legalEntityId) {
2003
- const { client, storage } = useEmporix();
2004
- const token = storage.getCustomerToken();
2005
- return (0, import_react_query20.useQuery)({
2006
- queryKey: emporixKey("companies", ["contacts", legalEntityId ?? null], {
2007
- tenant: client.tenant,
2008
- authKind: token ? "customer" : "anonymous"
2009
- }),
2010
- enabled: token !== null && legalEntityId !== void 0,
2011
- queryFn: () => client.contacts.listForCompany(legalEntityId, import_emporix_sdk19.auth.customer(token))
2068
+ const { client } = useEmporix();
2069
+ return useEmporixQuery({
2070
+ mode: "customer",
2071
+ site: "none",
2072
+ resource: "companies",
2073
+ args: ["contacts", legalEntityId ?? null],
2074
+ enabled: legalEntityId !== void 0,
2075
+ queryFn: (ctx) => client.contacts.listForCompany(legalEntityId, ctx)
2012
2076
  });
2013
2077
  }
2014
2078
 
2015
2079
  // src/hooks/use-company-locations.ts
2016
- var import_react_query21 = require("@tanstack/react-query");
2017
- var import_emporix_sdk20 = require("@viu/emporix-sdk");
2080
+ var import_react_query22 = require("@tanstack/react-query");
2081
+ var import_emporix_sdk21 = require("@viu/emporix-sdk");
2018
2082
  function useCompanyLocations(legalEntityId) {
2019
2083
  const { client } = useEmporix();
2020
- const token = useCustomerToken();
2021
- return (0, import_react_query21.useQuery)({
2022
- queryKey: emporixKey("companies", ["locations", legalEntityId ?? null], {
2023
- tenant: client.tenant,
2024
- authKind: token ? "customer" : "anonymous"
2025
- }),
2026
- enabled: token !== null && legalEntityId !== void 0,
2027
- queryFn: () => client.locations.listForCompany(legalEntityId, import_emporix_sdk20.auth.customer(token))
2084
+ return useEmporixQuery({
2085
+ mode: "customer",
2086
+ site: "none",
2087
+ resource: "companies",
2088
+ args: ["locations", legalEntityId ?? null],
2089
+ enabled: legalEntityId !== void 0,
2090
+ queryFn: (ctx) => client.locations.listForCompany(legalEntityId, ctx)
2028
2091
  });
2029
2092
  }
2030
2093
 
2031
2094
  // src/hooks/use-company-groups.ts
2032
- var import_react_query22 = require("@tanstack/react-query");
2033
- var import_emporix_sdk21 = require("@viu/emporix-sdk");
2095
+ var import_react_query23 = require("@tanstack/react-query");
2096
+ var import_emporix_sdk22 = require("@viu/emporix-sdk");
2034
2097
  function useCompanyGroups(legalEntityId) {
2035
2098
  const { client } = useEmporix();
2036
- const token = useCustomerToken();
2037
- return (0, import_react_query22.useQuery)({
2038
- queryKey: emporixKey("companies", ["groups", legalEntityId ?? null], {
2039
- tenant: client.tenant,
2040
- authKind: token ? "customer" : "anonymous"
2041
- }),
2042
- enabled: token !== null && legalEntityId !== void 0,
2043
- queryFn: () => client.customerGroups.listForCompany(legalEntityId, import_emporix_sdk21.auth.customer(token))
2099
+ return useEmporixQuery({
2100
+ mode: "customer",
2101
+ site: "none",
2102
+ resource: "companies",
2103
+ args: ["groups", legalEntityId ?? null],
2104
+ enabled: legalEntityId !== void 0,
2105
+ queryFn: (ctx) => client.customerGroups.listForCompany(legalEntityId, ctx)
2044
2106
  });
2045
2107
  }
2046
2108
 
2047
2109
  // src/hooks/use-company-mutations.ts
2048
- var import_react_query23 = require("@tanstack/react-query");
2049
- var import_emporix_sdk22 = require("@viu/emporix-sdk");
2110
+ var import_react_query24 = require("@tanstack/react-query");
2111
+ var import_emporix_sdk23 = require("@viu/emporix-sdk");
2050
2112
  function useCustomerAuthResolver() {
2051
2113
  const { storage } = useEmporix();
2052
2114
  return () => {
2053
2115
  const token = storage.getCustomerToken();
2054
2116
  if (!token) throw new Error("Mutation requires a logged-in customer token");
2055
- return import_emporix_sdk22.auth.customer(token);
2117
+ return import_emporix_sdk23.auth.customer(token);
2056
2118
  };
2057
2119
  }
2058
2120
  function useCreateCompany() {
2059
2121
  const { client } = useEmporix();
2060
2122
  const resolveAuth = useCustomerAuthResolver();
2061
- const qc = (0, import_react_query23.useQueryClient)();
2062
- return (0, import_react_query23.useMutation)({
2123
+ const qc = (0, import_react_query24.useQueryClient)();
2124
+ return (0, import_react_query24.useMutation)({
2063
2125
  mutationFn: (input) => client.companies.create(input, resolveAuth()),
2064
2126
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies", "mine"] })
2065
2127
  });
@@ -2067,8 +2129,8 @@ function useCreateCompany() {
2067
2129
  function useUpdateCompany() {
2068
2130
  const { client } = useEmporix();
2069
2131
  const resolveAuth = useCustomerAuthResolver();
2070
- const qc = (0, import_react_query23.useQueryClient)();
2071
- return (0, import_react_query23.useMutation)({
2132
+ const qc = (0, import_react_query24.useQueryClient)();
2133
+ return (0, import_react_query24.useMutation)({
2072
2134
  mutationFn: ({ id, patch }) => client.companies.update(id, patch, resolveAuth()),
2073
2135
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
2074
2136
  });
@@ -2076,8 +2138,8 @@ function useUpdateCompany() {
2076
2138
  function useDeleteCompany() {
2077
2139
  const { client } = useEmporix();
2078
2140
  const resolveAuth = useCustomerAuthResolver();
2079
- const qc = (0, import_react_query23.useQueryClient)();
2080
- return (0, import_react_query23.useMutation)({
2141
+ const qc = (0, import_react_query24.useQueryClient)();
2142
+ return (0, import_react_query24.useMutation)({
2081
2143
  mutationFn: (id) => client.companies.delete(id, resolveAuth()),
2082
2144
  onSuccess: () => qc.invalidateQueries({ queryKey: ["emporix", "companies"] })
2083
2145
  });
@@ -2085,8 +2147,8 @@ function useDeleteCompany() {
2085
2147
  function useAssignContact() {
2086
2148
  const { client } = useEmporix();
2087
2149
  const resolveAuth = useCustomerAuthResolver();
2088
- const qc = (0, import_react_query23.useQueryClient)();
2089
- return (0, import_react_query23.useMutation)({
2150
+ const qc = (0, import_react_query24.useQueryClient)();
2151
+ return (0, import_react_query24.useMutation)({
2090
2152
  mutationFn: (input) => client.contacts.assign(input, resolveAuth()),
2091
2153
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
2092
2154
  });
@@ -2094,8 +2156,8 @@ function useAssignContact() {
2094
2156
  function useUpdateContactAssignment() {
2095
2157
  const { client } = useEmporix();
2096
2158
  const resolveAuth = useCustomerAuthResolver();
2097
- const qc = (0, import_react_query23.useQueryClient)();
2098
- return (0, import_react_query23.useMutation)({
2159
+ const qc = (0, import_react_query24.useQueryClient)();
2160
+ return (0, import_react_query24.useMutation)({
2099
2161
  mutationFn: ({ id, patch }) => client.contacts.update(id, patch, resolveAuth()),
2100
2162
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
2101
2163
  });
@@ -2103,8 +2165,8 @@ function useUpdateContactAssignment() {
2103
2165
  function useUnassignContact() {
2104
2166
  const { client } = useEmporix();
2105
2167
  const resolveAuth = useCustomerAuthResolver();
2106
- const qc = (0, import_react_query23.useQueryClient)();
2107
- return (0, import_react_query23.useMutation)({
2168
+ const qc = (0, import_react_query24.useQueryClient)();
2169
+ return (0, import_react_query24.useMutation)({
2108
2170
  mutationFn: (id) => client.contacts.unassign(id, resolveAuth()),
2109
2171
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("contacts") })
2110
2172
  });
@@ -2112,8 +2174,8 @@ function useUnassignContact() {
2112
2174
  function useCreateLocation() {
2113
2175
  const { client } = useEmporix();
2114
2176
  const resolveAuth = useCustomerAuthResolver();
2115
- const qc = (0, import_react_query23.useQueryClient)();
2116
- return (0, import_react_query23.useMutation)({
2177
+ const qc = (0, import_react_query24.useQueryClient)();
2178
+ return (0, import_react_query24.useMutation)({
2117
2179
  mutationFn: (input) => client.locations.create(input, resolveAuth()),
2118
2180
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
2119
2181
  });
@@ -2121,8 +2183,8 @@ function useCreateLocation() {
2121
2183
  function useUpdateLocation() {
2122
2184
  const { client } = useEmporix();
2123
2185
  const resolveAuth = useCustomerAuthResolver();
2124
- const qc = (0, import_react_query23.useQueryClient)();
2125
- return (0, import_react_query23.useMutation)({
2186
+ const qc = (0, import_react_query24.useQueryClient)();
2187
+ return (0, import_react_query24.useMutation)({
2126
2188
  mutationFn: ({ id, patch }) => client.locations.update(id, patch, resolveAuth()),
2127
2189
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
2128
2190
  });
@@ -2130,8 +2192,8 @@ function useUpdateLocation() {
2130
2192
  function useDeleteLocation() {
2131
2193
  const { client } = useEmporix();
2132
2194
  const resolveAuth = useCustomerAuthResolver();
2133
- const qc = (0, import_react_query23.useQueryClient)();
2134
- return (0, import_react_query23.useMutation)({
2195
+ const qc = (0, import_react_query24.useQueryClient)();
2196
+ return (0, import_react_query24.useMutation)({
2135
2197
  mutationFn: (id) => client.locations.delete(id, resolveAuth()),
2136
2198
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("locations") })
2137
2199
  });
@@ -2139,8 +2201,8 @@ function useDeleteLocation() {
2139
2201
  function useAddGroupMember() {
2140
2202
  const { client } = useEmporix();
2141
2203
  const resolveAuth = useCustomerAuthResolver();
2142
- const qc = (0, import_react_query23.useQueryClient)();
2143
- return (0, import_react_query23.useMutation)({
2204
+ const qc = (0, import_react_query24.useQueryClient)();
2205
+ return (0, import_react_query24.useMutation)({
2144
2206
  mutationFn: ({ groupId, member }) => client.customerGroups.addMember(groupId, member, resolveAuth()),
2145
2207
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
2146
2208
  });
@@ -2148,8 +2210,8 @@ function useAddGroupMember() {
2148
2210
  function useRemoveGroupMember() {
2149
2211
  const { client } = useEmporix();
2150
2212
  const resolveAuth = useCustomerAuthResolver();
2151
- const qc = (0, import_react_query23.useQueryClient)();
2152
- return (0, import_react_query23.useMutation)({
2213
+ const qc = (0, import_react_query24.useQueryClient)();
2214
+ return (0, import_react_query24.useMutation)({
2153
2215
  mutationFn: ({ groupId, userId }) => client.customerGroups.removeMember(groupId, userId, resolveAuth()),
2154
2216
  onSuccess: () => qc.invalidateQueries({ predicate: (q) => q.queryKey.includes("groups") })
2155
2217
  });
@@ -2174,15 +2236,15 @@ function useCompanySwitcher() {
2174
2236
  }
2175
2237
 
2176
2238
  // src/hooks/use-cloud-functions.ts
2177
- var import_react_query24 = require("@tanstack/react-query");
2178
- var import_emporix_sdk23 = require("@viu/emporix-sdk");
2239
+ var import_react_query25 = require("@tanstack/react-query");
2240
+ var import_emporix_sdk24 = require("@viu/emporix-sdk");
2179
2241
  function useInvokeCloudFunction() {
2180
2242
  const { client, storage } = useEmporix();
2181
- return (0, import_react_query24.useMutation)({
2243
+ return (0, import_react_query25.useMutation)({
2182
2244
  mutationFn: (vars) => {
2183
2245
  const { functionId, auth: authOverride, ...options } = vars;
2184
2246
  const token = storage.getCustomerToken();
2185
- const authCtx = authOverride ?? (token ? import_emporix_sdk23.auth.customer(token) : import_emporix_sdk23.auth.anonymous());
2247
+ const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
2186
2248
  return client.cloudFunctions.invoke(functionId, options, authCtx);
2187
2249
  }
2188
2250
  });
@@ -2191,8 +2253,8 @@ function useCloudFunction(functionId, options, queryOptions) {
2191
2253
  const { client } = useEmporix();
2192
2254
  const token = useCustomerToken();
2193
2255
  const { auth: authOverride, ...invokeOptions } = options ?? {};
2194
- const authCtx = authOverride ?? (token ? import_emporix_sdk23.auth.customer(token) : import_emporix_sdk23.auth.anonymous());
2195
- return (0, import_react_query24.useQuery)({
2256
+ const authCtx = authOverride ?? (token ? import_emporix_sdk24.auth.customer(token) : import_emporix_sdk24.auth.anonymous());
2257
+ return (0, import_react_query25.useQuery)({
2196
2258
  queryKey: emporixKey(
2197
2259
  "cloud-function",
2198
2260
  [functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
@@ -2209,22 +2271,19 @@ function useCloudFunction(functionId, options, queryOptions) {
2209
2271
  }
2210
2272
 
2211
2273
  // src/hooks/use-my-orders.ts
2212
- var import_react_query25 = require("@tanstack/react-query");
2213
- var import_emporix_sdk24 = require("@viu/emporix-sdk");
2274
+ var import_react_query26 = require("@tanstack/react-query");
2275
+ var import_emporix_sdk25 = require("@viu/emporix-sdk");
2214
2276
  function useMyOrders(options = {}) {
2215
2277
  const { client } = useEmporix();
2216
2278
  const { activeCompany } = useActiveCompany();
2217
- const { siteCode, language } = useReadSite();
2218
- const token = useCustomerToken();
2279
+ const { siteCode } = useReadSite();
2219
2280
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
2220
- return (0, import_react_query25.useQuery)({
2221
- queryKey: emporixKey(
2222
- "orders",
2223
- ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
2224
- { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
2225
- ),
2226
- enabled: token !== null,
2227
- queryFn: () => client.orders.listMine(import_emporix_sdk24.auth.customer(token), {
2281
+ return useEmporixQuery({
2282
+ mode: "customer",
2283
+ site: "full",
2284
+ resource: "orders",
2285
+ args: ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
2286
+ queryFn: (ctx) => client.orders.listMine(ctx, {
2228
2287
  ...options.pageNumber !== void 0 ? { pageNumber: options.pageNumber } : {},
2229
2288
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
2230
2289
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -2236,7 +2295,7 @@ function useMyOrders(options = {}) {
2236
2295
  }
2237
2296
 
2238
2297
  // src/hooks/use-my-orders-infinite.ts
2239
- var import_emporix_sdk25 = require("@viu/emporix-sdk");
2298
+ var import_emporix_sdk26 = require("@viu/emporix-sdk");
2240
2299
  function useMyOrdersInfinite(options = {}) {
2241
2300
  const { client } = useEmporix();
2242
2301
  const { activeCompany } = useActiveCompany();
@@ -2250,7 +2309,7 @@ function useMyOrdersInfinite(options = {}) {
2250
2309
  { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
2251
2310
  ),
2252
2311
  enabled: token !== null,
2253
- fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk25.auth.customer(token), {
2312
+ fetchPage: (pageNumber) => client.orders.listMine(import_emporix_sdk26.auth.customer(token), {
2254
2313
  pageNumber,
2255
2314
  ...options.pageSize !== void 0 ? { pageSize: options.pageSize } : {},
2256
2315
  ...options.status !== void 0 ? { status: options.status } : {},
@@ -2262,34 +2321,31 @@ function useMyOrdersInfinite(options = {}) {
2262
2321
  }
2263
2322
 
2264
2323
  // src/hooks/use-order.ts
2265
- var import_react_query26 = require("@tanstack/react-query");
2266
- var import_emporix_sdk26 = require("@viu/emporix-sdk");
2324
+ var import_react_query27 = require("@tanstack/react-query");
2325
+ var import_emporix_sdk27 = require("@viu/emporix-sdk");
2267
2326
  function useOrder(orderId, options = {}) {
2268
2327
  const { client } = useEmporix();
2269
- const token = useCustomerToken();
2270
- const { language } = useReadSite();
2271
- return (0, import_react_query26.useQuery)({
2272
- queryKey: emporixKey("orders", [orderId ?? null], {
2273
- tenant: client.tenant,
2274
- authKind: token ? "customer" : "anonymous",
2275
- language
2276
- }),
2277
- enabled: token !== null && orderId !== void 0,
2278
- queryFn: () => client.orders.get(
2328
+ return useEmporixQuery({
2329
+ mode: "customer",
2330
+ site: "language",
2331
+ resource: "orders",
2332
+ args: [orderId ?? null],
2333
+ enabled: orderId !== void 0,
2334
+ queryFn: (ctx) => client.orders.get(
2279
2335
  orderId,
2280
- import_emporix_sdk26.auth.customer(token),
2336
+ ctx,
2281
2337
  options.saasToken ? { saasToken: options.saasToken } : {}
2282
2338
  )
2283
2339
  });
2284
2340
  }
2285
2341
 
2286
2342
  // src/hooks/use-cancel-order.ts
2287
- var import_react_query27 = require("@tanstack/react-query");
2288
- var import_emporix_sdk27 = require("@viu/emporix-sdk");
2343
+ var import_react_query28 = require("@tanstack/react-query");
2344
+ var import_emporix_sdk28 = require("@viu/emporix-sdk");
2289
2345
  function useCancelOrder() {
2290
2346
  const { client, storage } = useEmporix();
2291
- const qc = (0, import_react_query27.useQueryClient)();
2292
- return (0, import_react_query27.useMutation)({
2347
+ const qc = (0, import_react_query28.useQueryClient)();
2348
+ return (0, import_react_query28.useMutation)({
2293
2349
  mutationKey: ["emporix", "orders", "cancel"],
2294
2350
  mutationFn: async (input) => {
2295
2351
  const token = storage.getCustomerToken();
@@ -2297,7 +2353,7 @@ function useCancelOrder() {
2297
2353
  const { orderId, saasToken } = typeof input === "string" ? { orderId: input, saasToken: void 0 } : input;
2298
2354
  await client.orders.cancel(
2299
2355
  orderId,
2300
- import_emporix_sdk27.auth.customer(token),
2356
+ import_emporix_sdk28.auth.customer(token),
2301
2357
  saasToken ? { saasToken } : {}
2302
2358
  );
2303
2359
  },
@@ -2308,12 +2364,12 @@ function useCancelOrder() {
2308
2364
  }
2309
2365
 
2310
2366
  // src/hooks/use-order-transition.ts
2311
- var import_react_query28 = require("@tanstack/react-query");
2312
- var import_emporix_sdk28 = require("@viu/emporix-sdk");
2367
+ var import_react_query29 = require("@tanstack/react-query");
2368
+ var import_emporix_sdk29 = require("@viu/emporix-sdk");
2313
2369
  function useOrderTransition() {
2314
2370
  const { client, storage } = useEmporix();
2315
- const qc = (0, import_react_query28.useQueryClient)();
2316
- return (0, import_react_query28.useMutation)({
2371
+ const qc = (0, import_react_query29.useQueryClient)();
2372
+ return (0, import_react_query29.useMutation)({
2317
2373
  mutationKey: ["emporix", "orders", "transition"],
2318
2374
  mutationFn: async ({ orderId, status, comment, saasToken }) => {
2319
2375
  const token = storage.getCustomerToken();
@@ -2321,7 +2377,7 @@ function useOrderTransition() {
2321
2377
  await client.orders.transition(
2322
2378
  orderId,
2323
2379
  status,
2324
- import_emporix_sdk28.auth.customer(token),
2380
+ import_emporix_sdk29.auth.customer(token),
2325
2381
  {
2326
2382
  ...comment !== void 0 ? { comment } : {},
2327
2383
  ...saasToken !== void 0 ? { saasToken } : {}
@@ -2335,17 +2391,17 @@ function useOrderTransition() {
2335
2391
  }
2336
2392
 
2337
2393
  // src/hooks/use-reorder.ts
2338
- var import_react_query29 = require("@tanstack/react-query");
2339
- var import_emporix_sdk29 = require("@viu/emporix-sdk");
2394
+ var import_react_query30 = require("@tanstack/react-query");
2395
+ var import_emporix_sdk30 = require("@viu/emporix-sdk");
2340
2396
  function useReorder() {
2341
2397
  const { client, storage } = useEmporix();
2342
- const qc = (0, import_react_query29.useQueryClient)();
2343
- return (0, import_react_query29.useMutation)({
2398
+ const qc = (0, import_react_query30.useQueryClient)();
2399
+ return (0, import_react_query30.useMutation)({
2344
2400
  mutationKey: ["emporix", "orders", "reorder"],
2345
2401
  mutationFn: async ({ orderId, saasToken }) => {
2346
2402
  const token = storage.getCustomerToken();
2347
2403
  if (!token) throw new Error("useReorder: requires a logged-in customer");
2348
- const ctx = import_emporix_sdk29.auth.customer(token);
2404
+ const ctx = import_emporix_sdk30.auth.customer(token);
2349
2405
  const order = await qc.fetchQuery({
2350
2406
  queryKey: emporixKey("orders", [orderId], { tenant: client.tenant, authKind: ctx.kind }),
2351
2407
  queryFn: () => client.orders.get(orderId, ctx, saasToken ? { saasToken } : {})
@@ -2392,12 +2448,12 @@ function useReorder() {
2392
2448
  }
2393
2449
 
2394
2450
  // src/hooks/use-sales-order.ts
2395
- var import_react_query30 = require("@tanstack/react-query");
2396
- var import_emporix_sdk30 = require("@viu/emporix-sdk");
2451
+ var import_react_query31 = require("@tanstack/react-query");
2452
+ var import_emporix_sdk31 = require("@viu/emporix-sdk");
2397
2453
  function useSalesOrder(orderId, authCtx) {
2398
2454
  const { client } = useEmporix();
2399
2455
  const { language } = useReadSite();
2400
- return (0, import_react_query30.useQuery)({
2456
+ return (0, import_react_query31.useQuery)({
2401
2457
  queryKey: emporixKey("salesorders", [orderId ?? null], {
2402
2458
  tenant: client.tenant,
2403
2459
  authKind: authCtx?.kind ?? "anonymous",
@@ -2409,19 +2465,19 @@ function useSalesOrder(orderId, authCtx) {
2409
2465
  }
2410
2466
 
2411
2467
  // src/hooks/use-update-sales-order.ts
2412
- var import_react_query31 = require("@tanstack/react-query");
2413
- var import_emporix_sdk31 = require("@viu/emporix-sdk");
2468
+ var import_react_query32 = require("@tanstack/react-query");
2469
+ var import_emporix_sdk32 = require("@viu/emporix-sdk");
2414
2470
  function useUpdateSalesOrder() {
2415
2471
  const { client } = useEmporix();
2416
- const qc = (0, import_react_query31.useQueryClient)();
2417
- return (0, import_react_query31.useMutation)({
2472
+ const qc = (0, import_react_query32.useQueryClient)();
2473
+ return (0, import_react_query32.useMutation)({
2418
2474
  mutationKey: ["emporix", "salesorders", "update"],
2419
- mutationFn: async ({ orderId, patch, auth: auth27, recalculate }) => {
2420
- if (!auth27) throw new Error("useUpdateSalesOrder: requires an auth context");
2475
+ mutationFn: async ({ orderId, patch, auth: auth21, recalculate }) => {
2476
+ if (!auth21) throw new Error("useUpdateSalesOrder: requires an auth context");
2421
2477
  return client.salesOrders.update(
2422
2478
  orderId,
2423
2479
  patch,
2424
- auth27,
2480
+ auth21,
2425
2481
  recalculate !== void 0 ? { recalculate } : {}
2426
2482
  );
2427
2483
  },
@@ -2434,13 +2490,13 @@ function useUpdateSalesOrder() {
2434
2490
  }
2435
2491
 
2436
2492
  // src/hooks/use-availability.ts
2437
- var import_react_query32 = require("@tanstack/react-query");
2438
- var import_emporix_sdk32 = require("@viu/emporix-sdk");
2493
+ var import_react_query33 = require("@tanstack/react-query");
2494
+ var import_emporix_sdk33 = require("@viu/emporix-sdk");
2439
2495
  var AVAILABILITY_STALE_TIME = 3e4;
2440
2496
  function useAvailability(productId, siteCode, options = {}) {
2441
2497
  const { client } = useEmporix();
2442
- const ctx = options.customerToken ? import_emporix_sdk32.auth.customer(options.customerToken) : import_emporix_sdk32.auth.anonymous();
2443
- return (0, import_react_query32.useQuery)({
2498
+ const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
2499
+ return (0, import_react_query33.useQuery)({
2444
2500
  queryKey: [
2445
2501
  "emporix",
2446
2502
  "availability",
@@ -2461,13 +2517,13 @@ function useAvailability(productId, siteCode, options = {}) {
2461
2517
  }
2462
2518
 
2463
2519
  // src/hooks/use-availabilities.ts
2464
- var import_react_query33 = require("@tanstack/react-query");
2465
- var import_emporix_sdk33 = require("@viu/emporix-sdk");
2520
+ var import_react_query34 = require("@tanstack/react-query");
2521
+ var import_emporix_sdk34 = require("@viu/emporix-sdk");
2466
2522
  var AVAILABILITY_STALE_TIME2 = 3e4;
2467
2523
  function useAvailabilities(productIds, siteCode, options = {}) {
2468
2524
  const { client } = useEmporix();
2469
- const ctx = options.customerToken ? import_emporix_sdk33.auth.customer(options.customerToken) : import_emporix_sdk33.auth.anonymous();
2470
- return (0, import_react_query33.useQuery)({
2525
+ const ctx = options.customerToken ? import_emporix_sdk34.auth.customer(options.customerToken) : import_emporix_sdk34.auth.anonymous();
2526
+ return (0, import_react_query34.useQuery)({
2471
2527
  queryKey: [
2472
2528
  "emporix",
2473
2529
  "availabilities",
@@ -2488,33 +2544,33 @@ function useAvailabilities(productIds, siteCode, options = {}) {
2488
2544
  }
2489
2545
 
2490
2546
  // src/hooks/use-coupons.ts
2491
- var import_react_query34 = require("@tanstack/react-query");
2547
+ var import_react_query35 = require("@tanstack/react-query");
2492
2548
  var INVALIDATE_KEY2 = ["emporix", "coupons"];
2493
2549
  function useValidateCoupon() {
2494
2550
  const { client } = useEmporix();
2495
2551
  const { ctx } = useReadAuth();
2496
- return (0, import_react_query34.useMutation)({
2552
+ return (0, import_react_query35.useMutation)({
2497
2553
  mutationFn: ({ code, redemption }) => client.coupons.validateCoupon(code, redemption, ctx)
2498
2554
  });
2499
2555
  }
2500
2556
  function useRedeemCoupon() {
2501
2557
  const { client } = useEmporix();
2502
2558
  const { ctx } = useReadAuth();
2503
- const qc = (0, import_react_query34.useQueryClient)();
2504
- return (0, import_react_query34.useMutation)({
2559
+ const qc = (0, import_react_query35.useQueryClient)();
2560
+ return (0, import_react_query35.useMutation)({
2505
2561
  mutationFn: ({ code, redemption }) => client.coupons.redeemCoupon(code, redemption, ctx),
2506
2562
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY2 })
2507
2563
  });
2508
2564
  }
2509
2565
 
2510
2566
  // src/hooks/use-reward-points.ts
2511
- var import_react_query35 = require("@tanstack/react-query");
2567
+ var import_react_query36 = require("@tanstack/react-query");
2512
2568
  var STALE = 3e4;
2513
2569
  var INVALIDATE_KEY3 = ["emporix", "reward-points"];
2514
2570
  function useMyRewardPoints() {
2515
2571
  const { client } = useEmporix();
2516
2572
  const ctx = useCustomerOnlyCtx();
2517
- return (0, import_react_query35.useQuery)({
2573
+ return (0, import_react_query36.useQuery)({
2518
2574
  queryKey: emporixKey("reward-points", ["mine"], { tenant: client.tenant, authKind: ctx.kind }),
2519
2575
  queryFn: () => client.rewardPoints.getMyPoints(ctx),
2520
2576
  staleTime: STALE
@@ -2523,7 +2579,7 @@ function useMyRewardPoints() {
2523
2579
  function useMyRewardPointsSummary() {
2524
2580
  const { client } = useEmporix();
2525
2581
  const ctx = useCustomerOnlyCtx();
2526
- return (0, import_react_query35.useQuery)({
2582
+ return (0, import_react_query36.useQuery)({
2527
2583
  queryKey: emporixKey("reward-points", ["mine", "summary"], { tenant: client.tenant, authKind: ctx.kind }),
2528
2584
  queryFn: () => client.rewardPoints.getMySummary(ctx),
2529
2585
  staleTime: STALE
@@ -2532,7 +2588,7 @@ function useMyRewardPointsSummary() {
2532
2588
  function useRedeemOptions() {
2533
2589
  const { client } = useEmporix();
2534
2590
  const { ctx } = useReadAuth();
2535
- return (0, import_react_query35.useQuery)({
2591
+ return (0, import_react_query36.useQuery)({
2536
2592
  queryKey: emporixKey("reward-points", ["redeem-options"], { tenant: client.tenant, authKind: ctx.kind }),
2537
2593
  queryFn: () => client.rewardPoints.listRedeemOptions(ctx),
2538
2594
  staleTime: STALE
@@ -2541,21 +2597,21 @@ function useRedeemOptions() {
2541
2597
  function useRedeemRewardPoints() {
2542
2598
  const { client } = useEmporix();
2543
2599
  const ctx = useCustomerOnlyCtx();
2544
- const qc = (0, import_react_query35.useQueryClient)();
2545
- return (0, import_react_query35.useMutation)({
2600
+ const qc = (0, import_react_query36.useQueryClient)();
2601
+ return (0, import_react_query36.useMutation)({
2546
2602
  mutationFn: (input) => client.rewardPoints.redeemMyPoints(input, ctx),
2547
2603
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY3 })
2548
2604
  });
2549
2605
  }
2550
2606
 
2551
2607
  // src/hooks/use-returns.ts
2552
- var import_react_query36 = require("@tanstack/react-query");
2608
+ var import_react_query37 = require("@tanstack/react-query");
2553
2609
  var STALE2 = 3e4;
2554
2610
  var INVALIDATE_KEY4 = ["emporix", "returns"];
2555
2611
  function useMyReturns(opts = {}) {
2556
2612
  const { client } = useEmporix();
2557
2613
  const ctx = useCustomerOnlyCtx();
2558
- return (0, import_react_query36.useQuery)({
2614
+ return (0, import_react_query37.useQuery)({
2559
2615
  queryKey: emporixKey("returns", [opts.query ?? null], { tenant: client.tenant, authKind: ctx.kind }),
2560
2616
  queryFn: () => client.returns.listReturns(opts.query ?? {}, ctx),
2561
2617
  staleTime: STALE2
@@ -2564,7 +2620,7 @@ function useMyReturns(opts = {}) {
2564
2620
  function useReturn(returnId) {
2565
2621
  const { client } = useEmporix();
2566
2622
  const ctx = useCustomerOnlyCtx();
2567
- return (0, import_react_query36.useQuery)({
2623
+ return (0, import_react_query37.useQuery)({
2568
2624
  queryKey: emporixKey("returns", [returnId ?? null], { tenant: client.tenant, authKind: ctx.kind }),
2569
2625
  queryFn: () => client.returns.getReturn(returnId, ctx),
2570
2626
  enabled: Boolean(returnId),
@@ -2574,8 +2630,8 @@ function useReturn(returnId) {
2574
2630
  function useCreateReturn() {
2575
2631
  const { client } = useEmporix();
2576
2632
  const ctx = useCustomerOnlyCtx();
2577
- const qc = (0, import_react_query36.useQueryClient)();
2578
- return (0, import_react_query36.useMutation)({
2633
+ const qc = (0, import_react_query37.useQueryClient)();
2634
+ return (0, import_react_query37.useMutation)({
2579
2635
  mutationFn: (input) => client.returns.createReturn(input, ctx),
2580
2636
  onSuccess: () => void qc.invalidateQueries({ queryKey: INVALIDATE_KEY4 })
2581
2637
  });
@@ -2583,7 +2639,7 @@ function useCreateReturn() {
2583
2639
 
2584
2640
  // src/errors.tsx
2585
2641
  var import_react10 = require("react");
2586
- var import_emporix_sdk34 = require("@viu/emporix-sdk");
2642
+ var import_emporix_sdk35 = require("@viu/emporix-sdk");
2587
2643
  var EmporixErrorBoundary = class extends import_react10.Component {
2588
2644
  state = { error: null };
2589
2645
  static getDerivedStateFromError(error) {
@@ -2599,14 +2655,14 @@ var EmporixErrorBoundary = class extends import_react10.Component {
2599
2655
  };
2600
2656
  function useEmporixErrorHandler(handlers) {
2601
2657
  return (error) => {
2602
- if (error instanceof import_emporix_sdk34.EmporixAuthError) handlers.onAuthError?.(error);
2603
- else if (error instanceof import_emporix_sdk34.EmporixError) handlers.onError?.(error);
2658
+ if (error instanceof import_emporix_sdk35.EmporixAuthError) handlers.onAuthError?.(error);
2659
+ else if (error instanceof import_emporix_sdk35.EmporixError) handlers.onError?.(error);
2604
2660
  };
2605
2661
  }
2606
2662
 
2607
2663
  // src/ssr.ts
2608
- var import_emporix_sdk35 = require("@viu/emporix-sdk");
2609
- async function prefetchProduct(qc, client, productId, authCtx = import_emporix_sdk35.auth.anonymous(), opts = {}) {
2664
+ var import_emporix_sdk36 = require("@viu/emporix-sdk");
2665
+ async function prefetchProduct(qc, client, productId, authCtx = import_emporix_sdk36.auth.anonymous(), opts = {}) {
2610
2666
  await qc.prefetchQuery({
2611
2667
  queryKey: emporixKey("product", [productId], {
2612
2668
  tenant: client.tenant,