@viu/emporix-sdk-react 2.10.0 → 2.12.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
@@ -12,6 +12,7 @@ var DEFAULT_TOKEN_KEY = "emporix.customerToken";
12
12
  var CART_KEY = "emporix.cartId";
13
13
  var ANON_KEY = "emporix.anonymousSession";
14
14
  var SITE_KEY = "emporix.siteCode";
15
+ var LANGUAGE_KEY = "emporix.language";
15
16
  var ACTIVE_LE_KEY = "emporix.activeLegalEntityId";
16
17
  var REFRESH_KEY = "emporix.refreshToken";
17
18
  function createLocalStorageStorage(opts = {}) {
@@ -54,6 +55,12 @@ function createLocalStorageStorage(opts = {}) {
54
55
  else ls.setItem(SITE_KEY, code);
55
56
  all.notify("siteCode");
56
57
  },
58
+ getLanguage: () => ls.getItem(LANGUAGE_KEY),
59
+ setLanguage: (l) => {
60
+ if (l === null) ls.removeItem(LANGUAGE_KEY);
61
+ else ls.setItem(LANGUAGE_KEY, l);
62
+ all.notify("language");
63
+ },
57
64
  getActiveLegalEntityId: () => ls.getItem(ACTIVE_LE_KEY),
58
65
  setActiveLegalEntityId: (id) => {
59
66
  if (id === null) ls.removeItem(ACTIVE_LE_KEY);
@@ -75,6 +82,7 @@ var DEFAULT_TOKEN_NAME = "emporix.customerToken";
75
82
  var CART_NAME = "emporix.cartId";
76
83
  var ANON_NAME = "emporix.anonymousSession";
77
84
  var SITE_NAME = "emporix.siteCode";
85
+ var LANGUAGE_NAME = "emporix.language";
78
86
  var ACTIVE_LE_NAME = "emporix.activeLegalEntityId";
79
87
  var REFRESH_NAME = "emporix.refreshToken";
80
88
  function createCookieStorage(opts = {}) {
@@ -121,6 +129,11 @@ function createCookieStorage(opts = {}) {
121
129
  writeCookie(SITE_NAME, code);
122
130
  all.notify("siteCode");
123
131
  },
132
+ getLanguage: () => readCookie(LANGUAGE_NAME),
133
+ setLanguage: (l) => {
134
+ writeCookie(LANGUAGE_NAME, l);
135
+ all.notify("language");
136
+ },
124
137
  getActiveLegalEntityId: () => readCookie(ACTIVE_LE_NAME),
125
138
  setActiveLegalEntityId: (id) => {
126
139
  writeCookie(ACTIVE_LE_NAME, id);
@@ -172,6 +185,7 @@ function createMemoryStorage(opts = {}) {
172
185
  let cartId = null;
173
186
  let anon = null;
174
187
  let siteCode = null;
188
+ let language = null;
175
189
  let activeLegalEntityId = null;
176
190
  let refreshToken = null;
177
191
  const tokenListeners = /* @__PURE__ */ new Set();
@@ -202,6 +216,11 @@ function createMemoryStorage(opts = {}) {
202
216
  siteCode = code;
203
217
  all.notify("siteCode");
204
218
  },
219
+ getLanguage: () => language,
220
+ setLanguage: (l) => {
221
+ language = l;
222
+ all.notify("language");
223
+ },
205
224
  getActiveLegalEntityId: () => activeLegalEntityId,
206
225
  setActiveLegalEntityId: (id) => {
207
226
  activeLegalEntityId = id;
@@ -377,6 +396,7 @@ function EmporixProvider({
377
396
  storage,
378
397
  initialCustomerToken,
379
398
  initialSiteCode,
399
+ initialLanguage,
380
400
  initialActiveLegalEntityId,
381
401
  onTelemetry,
382
402
  autoRefreshCustomerToken,
@@ -530,6 +550,7 @@ function EmporixProvider({
530
550
  client,
531
551
  storage: value.storage,
532
552
  ...initialSiteCode !== void 0 ? { initialSiteCode } : {},
553
+ ...initialLanguage !== void 0 ? { initialLanguage } : {},
533
554
  children: /* @__PURE__ */ jsxRuntime.jsx(
534
555
  CompanyContextProvider,
535
556
  {
@@ -546,6 +567,7 @@ function SiteContextProvider({
546
567
  client,
547
568
  storage,
548
569
  initialSiteCode,
570
+ initialLanguage,
549
571
  children
550
572
  }) {
551
573
  const qc = reactQuery.useQueryClient();
@@ -558,11 +580,17 @@ function SiteContextProvider({
558
580
  const [currency, setCurrencyState] = react.useState(
559
581
  () => client.config?.credentials?.storefront?.context?.currency ?? null
560
582
  );
583
+ const [language, setLanguageState] = react.useState(() => {
584
+ if (initialLanguage !== void 0) return initialLanguage;
585
+ const fromStorage = storage.getLanguage();
586
+ if (fromStorage !== null) return fromStorage;
587
+ return client.config?.credentials?.storefront?.context?.language ?? null;
588
+ });
561
589
  const [targetLocation, setTargetLocation] = react.useState(null);
562
590
  const [isSwitching, setIsSwitching] = react.useState(false);
563
591
  const [switchError, setSwitchError] = react.useState(null);
564
592
  react.useEffect(() => {
565
- if (!siteCode || currency !== null && targetLocation !== null) return;
593
+ if (!siteCode || currency !== null && targetLocation !== null && language !== null) return;
566
594
  let cancelled = false;
567
595
  const token = storage.getCustomerToken();
568
596
  const authCtx = token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous();
@@ -579,12 +607,19 @@ function SiteContextProvider({
579
607
  if (cancelled) return;
580
608
  if (currency === null) setCurrencyState(site.currency);
581
609
  setTargetLocation(site.homeBase?.address?.country ?? null);
610
+ if (language === null && site.defaultLanguage) {
611
+ setLanguageState(site.defaultLanguage);
612
+ client.setStorefrontContext({ language: site.defaultLanguage });
613
+ }
582
614
  }).catch(() => {
583
615
  });
584
616
  return () => {
585
617
  cancelled = true;
586
618
  };
587
619
  }, [siteCode]);
620
+ react.useEffect(() => {
621
+ if (language) client.setStorefrontContext({ language });
622
+ }, []);
588
623
  const setSite = react.useCallback(
589
624
  async (code) => {
590
625
  storage.setSiteCode(code);
@@ -615,6 +650,10 @@ function SiteContextProvider({
615
650
  const nextTarget = site.homeBase?.address?.country ?? null;
616
651
  setCurrencyState(nextCurrency);
617
652
  setTargetLocation(nextTarget);
653
+ if (site.languages && !site.languages.includes(language ?? "") && site.defaultLanguage) {
654
+ setLanguageState(site.defaultLanguage);
655
+ client.setStorefrontContext({ language: site.defaultLanguage });
656
+ }
618
657
  await client.sessionContext.patch(
619
658
  {
620
659
  siteCode: code,
@@ -629,7 +668,7 @@ function SiteContextProvider({
629
668
  setIsSwitching(false);
630
669
  }
631
670
  },
632
- [client, storage, qc]
671
+ [client, storage, qc, language]
633
672
  );
634
673
  const setCurrency = react.useCallback(
635
674
  async (next) => {
@@ -654,17 +693,42 @@ function SiteContextProvider({
654
693
  },
655
694
  [client, storage, qc, siteCode]
656
695
  );
696
+ const setLanguage = react.useCallback(
697
+ async (next) => {
698
+ storage.setLanguage(next);
699
+ setLanguageState(next);
700
+ setSwitchError(null);
701
+ client.setStorefrontContext({ language: next });
702
+ void qc.invalidateQueries({ queryKey: ["emporix"] });
703
+ setIsSwitching(true);
704
+ try {
705
+ const token = storage.getCustomerToken();
706
+ const authCtx = token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous();
707
+ await client.sessionContext.patch(
708
+ { language: next, ...siteCode ? { siteCode } : {} },
709
+ authCtx
710
+ );
711
+ } catch (e) {
712
+ setSwitchError(e instanceof Error ? e : new Error(String(e)));
713
+ } finally {
714
+ setIsSwitching(false);
715
+ }
716
+ },
717
+ [client, storage, qc, siteCode]
718
+ );
657
719
  const value = react.useMemo(
658
720
  () => ({
659
721
  siteCode,
660
722
  currency,
661
723
  targetLocation,
724
+ language,
662
725
  setSite,
663
726
  setCurrency,
727
+ setLanguage,
664
728
  isSwitching,
665
729
  switchError
666
730
  }),
667
- [siteCode, currency, targetLocation, setSite, setCurrency, isSwitching, switchError]
731
+ [siteCode, currency, targetLocation, language, setSite, setCurrency, setLanguage, isSwitching, switchError]
668
732
  );
669
733
  return /* @__PURE__ */ jsxRuntime.jsx(EmporixSiteContext.Provider, { value, children });
670
734
  }
@@ -937,7 +1001,7 @@ function useCustomerOnlyCtx() {
937
1001
  }
938
1002
  function useReadSite() {
939
1003
  const ctx = react.useContext(EmporixSiteContext);
940
- return { siteCode: ctx?.siteCode ?? null };
1004
+ return { siteCode: ctx?.siteCode ?? null, language: ctx?.language ?? null };
941
1005
  }
942
1006
 
943
1007
  // src/hooks/internal/query-keys.ts
@@ -949,6 +1013,9 @@ function emporixKey(resource, args, context) {
949
1013
  if (context.siteCode !== void 0) {
950
1014
  meta.siteCode = context.siteCode;
951
1015
  }
1016
+ if (context.language !== void 0) {
1017
+ meta.language = context.language;
1018
+ }
952
1019
  return ["emporix", resource, ...args, meta];
953
1020
  }
954
1021
  function useEmporixInfinite(opts) {
@@ -967,9 +1034,9 @@ var PRODUCTS_STALE_TIME = 6e4;
967
1034
  function useProduct(productId, options = {}) {
968
1035
  const { client } = useEmporix();
969
1036
  const { ctx } = useReadAuth(options.auth);
970
- const { siteCode } = useReadSite();
1037
+ const { siteCode, language } = useReadSite();
971
1038
  return reactQuery.useQuery({
972
- queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1039
+ queryKey: emporixKey("product", [productId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
973
1040
  queryFn: () => client.products.get(productId, void 0, ctx),
974
1041
  staleTime: PRODUCTS_STALE_TIME
975
1042
  });
@@ -977,9 +1044,9 @@ function useProduct(productId, options = {}) {
977
1044
  function useProducts(params = {}, options = {}) {
978
1045
  const { client } = useEmporix();
979
1046
  const { ctx } = useReadAuth(options.auth);
980
- const { siteCode } = useReadSite();
1047
+ const { siteCode, language } = useReadSite();
981
1048
  return reactQuery.useQuery({
982
- queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1049
+ queryKey: emporixKey("products", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
983
1050
  queryFn: () => client.products.list(params, ctx),
984
1051
  staleTime: PRODUCTS_STALE_TIME
985
1052
  });
@@ -987,9 +1054,9 @@ function useProducts(params = {}, options = {}) {
987
1054
  function useProductsInfinite(params = {}, options = {}) {
988
1055
  const { client } = useEmporix();
989
1056
  const { ctx } = useReadAuth(options.auth);
990
- const { siteCode } = useReadSite();
1057
+ const { siteCode, language } = useReadSite();
991
1058
  return useEmporixInfinite({
992
- queryKey: emporixKey("products-infinite", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1059
+ queryKey: emporixKey("products-infinite", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
993
1060
  fetchPage: (pageNumber) => client.products.list(
994
1061
  params.pageSize !== void 0 ? { pageNumber, pageSize: params.pageSize } : { pageNumber },
995
1062
  ctx
@@ -1000,9 +1067,9 @@ function useProductsInfinite(params = {}, options = {}) {
1000
1067
  function useProductByCode(code, options = {}) {
1001
1068
  const { client } = useEmporix();
1002
1069
  const { ctx } = useReadAuth(options.auth);
1003
- const { siteCode } = useReadSite();
1070
+ const { siteCode, language } = useReadSite();
1004
1071
  return reactQuery.useQuery({
1005
- queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1072
+ queryKey: emporixKey("product-by-code", [code], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1006
1073
  enabled: typeof code === "string" && code !== "",
1007
1074
  queryFn: () => client.products.getByCode(code, ctx),
1008
1075
  staleTime: PRODUCTS_STALE_TIME
@@ -1011,9 +1078,9 @@ function useProductByCode(code, options = {}) {
1011
1078
  function useProductSearch(query, params = {}, options = {}) {
1012
1079
  const { client } = useEmporix();
1013
1080
  const { ctx } = useReadAuth(options.auth);
1014
- const { siteCode } = useReadSite();
1081
+ const { siteCode, language } = useReadSite();
1015
1082
  return reactQuery.useQuery({
1016
- queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1083
+ queryKey: emporixKey("product-search", [query, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1017
1084
  enabled: typeof query === "string" && query.trim() !== "",
1018
1085
  queryFn: () => client.products.search(query, params, ctx),
1019
1086
  staleTime: PRODUCTS_STALE_TIME
@@ -1022,9 +1089,9 @@ function useProductSearch(query, params = {}, options = {}) {
1022
1089
  function useProductNameSearch(term, params = {}, options = {}) {
1023
1090
  const { client } = useEmporix();
1024
1091
  const { ctx } = useReadAuth(options.auth);
1025
- const { siteCode } = useReadSite();
1092
+ const { siteCode, language } = useReadSite();
1026
1093
  return reactQuery.useQuery({
1027
- queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1094
+ queryKey: emporixKey("product-name-search", [term, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1028
1095
  enabled: typeof term === "string" && term.trim() !== "",
1029
1096
  queryFn: () => client.products.searchByName(term, params, ctx),
1030
1097
  staleTime: PRODUCTS_STALE_TIME
@@ -1033,12 +1100,13 @@ function useProductNameSearch(term, params = {}, options = {}) {
1033
1100
  function useProductsByCodes(codes, options = {}) {
1034
1101
  const { client } = useEmporix();
1035
1102
  const { ctx } = useReadAuth(options.auth);
1036
- const { siteCode } = useReadSite();
1103
+ const { siteCode, language } = useReadSite();
1037
1104
  return reactQuery.useQuery({
1038
1105
  queryKey: emporixKey("products-by-codes", [codes, options.chunkSize], {
1039
1106
  tenant: client.tenant,
1040
1107
  authKind: ctx.kind,
1041
- siteCode
1108
+ siteCode,
1109
+ language
1042
1110
  }),
1043
1111
  enabled: codes.length > 0,
1044
1112
  queryFn: () => client.products.searchByCodes(
@@ -1054,9 +1122,9 @@ var INVALIDATE_KEY = ["emporix", "shopping-lists"];
1054
1122
  function useShoppingLists(opts = {}) {
1055
1123
  const { client } = useEmporix();
1056
1124
  const ctx = useCustomerOnlyCtx();
1057
- const { siteCode } = useReadSite();
1125
+ const { siteCode, language } = useReadSite();
1058
1126
  return reactQuery.useQuery({
1059
- queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1127
+ queryKey: emporixKey("shopping-lists", [opts.name ?? null], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1060
1128
  queryFn: () => client.shoppingLists.list(ctx, opts),
1061
1129
  staleTime: SHOPPING_LIST_STALE_TIME
1062
1130
  });
@@ -1110,12 +1178,12 @@ var VARIANT_CHILDREN_STALE_TIME = 6e4;
1110
1178
  function useVariantChildren(parentVariantId, options = {}) {
1111
1179
  const { client } = useEmporix();
1112
1180
  const { ctx } = useReadAuth(options.auth);
1113
- const { siteCode } = useReadSite();
1181
+ const { siteCode, language } = useReadSite();
1114
1182
  return reactQuery.useQuery({
1115
1183
  queryKey: emporixKey(
1116
1184
  "variant-children",
1117
1185
  [parentVariantId, { pageSize: options.pageSize }],
1118
- { tenant: client.tenant, authKind: ctx.kind, siteCode }
1186
+ { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1119
1187
  ),
1120
1188
  enabled: typeof parentVariantId === "string" && parentVariantId !== "",
1121
1189
  queryFn: () => client.products.listVariantChildren(
@@ -1130,9 +1198,9 @@ var CATEGORIES_STALE_TIME = 5 * 6e4;
1130
1198
  function useCategory(categoryId, options = {}) {
1131
1199
  const { client } = useEmporix();
1132
1200
  const { ctx } = useReadAuth(options.auth);
1133
- const { siteCode } = useReadSite();
1201
+ const { siteCode, language } = useReadSite();
1134
1202
  return reactQuery.useQuery({
1135
- queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1203
+ queryKey: emporixKey("category", [categoryId], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1136
1204
  queryFn: () => client.categories.get(categoryId, ctx),
1137
1205
  staleTime: CATEGORIES_STALE_TIME
1138
1206
  });
@@ -1140,9 +1208,9 @@ function useCategory(categoryId, options = {}) {
1140
1208
  function useSubcategories(categoryId, params = {}, options = {}) {
1141
1209
  const { client } = useEmporix();
1142
1210
  const { ctx } = useReadAuth(options.auth);
1143
- const { siteCode } = useReadSite();
1211
+ const { siteCode, language } = useReadSite();
1144
1212
  return reactQuery.useQuery({
1145
- queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1213
+ queryKey: emporixKey("subcategories", [categoryId ?? null, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1146
1214
  enabled: typeof categoryId === "string" && categoryId !== "",
1147
1215
  queryFn: () => client.categories.subcategories(categoryId, params, ctx),
1148
1216
  staleTime: CATEGORIES_STALE_TIME
@@ -1151,9 +1219,9 @@ function useSubcategories(categoryId, params = {}, options = {}) {
1151
1219
  function useCategories(params = {}, options = {}) {
1152
1220
  const { client } = useEmporix();
1153
1221
  const { ctx } = useReadAuth(options.auth);
1154
- const { siteCode } = useReadSite();
1222
+ const { siteCode, language } = useReadSite();
1155
1223
  return reactQuery.useQuery({
1156
- queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1224
+ queryKey: emporixKey("categories", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1157
1225
  queryFn: () => client.categories.list(params, ctx),
1158
1226
  staleTime: CATEGORIES_STALE_TIME
1159
1227
  });
@@ -1161,9 +1229,9 @@ function useCategories(params = {}, options = {}) {
1161
1229
  function useCategoriesInfinite(params = {}, options = {}) {
1162
1230
  const { client } = useEmporix();
1163
1231
  const { ctx } = useReadAuth(options.auth);
1164
- const { siteCode } = useReadSite();
1232
+ const { siteCode, language } = useReadSite();
1165
1233
  return useEmporixInfinite({
1166
- queryKey: emporixKey("categories-infinite", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1234
+ queryKey: emporixKey("categories-infinite", [params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1167
1235
  fetchPage: (pageNumber) => client.categories.list(
1168
1236
  params.pageSize !== void 0 ? { pageNumber, pageSize: params.pageSize } : { pageNumber },
1169
1237
  ctx
@@ -1174,9 +1242,9 @@ function useCategoriesInfinite(params = {}, options = {}) {
1174
1242
  function useCategoryTree(options = {}) {
1175
1243
  const { client } = useEmporix();
1176
1244
  const { ctx } = useReadAuth(options.auth);
1177
- const { siteCode } = useReadSite();
1245
+ const { siteCode, language } = useReadSite();
1178
1246
  return reactQuery.useQuery({
1179
- queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1247
+ queryKey: emporixKey("category-tree", [], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1180
1248
  queryFn: () => client.categories.tree(ctx),
1181
1249
  staleTime: CATEGORIES_STALE_TIME
1182
1250
  });
@@ -1184,9 +1252,9 @@ function useCategoryTree(options = {}) {
1184
1252
  function useProductsInCategory(categoryId, params = {}, options = {}) {
1185
1253
  const { client } = useEmporix();
1186
1254
  const { ctx } = useReadAuth(options.auth);
1187
- const { siteCode } = useReadSite();
1255
+ const { siteCode, language } = useReadSite();
1188
1256
  return reactQuery.useQuery({
1189
- queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1257
+ queryKey: emporixKey("products-in-category", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1190
1258
  enabled: typeof categoryId === "string" && categoryId !== "",
1191
1259
  queryFn: () => client.categories.productsIn(categoryId, params, ctx),
1192
1260
  staleTime: CATEGORIES_STALE_TIME
@@ -1195,9 +1263,9 @@ function useProductsInCategory(categoryId, params = {}, options = {}) {
1195
1263
  function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
1196
1264
  const { client } = useEmporix();
1197
1265
  const { ctx } = useReadAuth(options.auth);
1198
- const { siteCode } = useReadSite();
1266
+ const { siteCode, language } = useReadSite();
1199
1267
  return useEmporixInfinite({
1200
- queryKey: emporixKey("products-in-category-infinite", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode }),
1268
+ queryKey: emporixKey("products-in-category-infinite", [categoryId, params], { tenant: client.tenant, authKind: ctx.kind, siteCode, language }),
1201
1269
  enabled: typeof categoryId === "string" && categoryId !== "",
1202
1270
  fetchPage: (pageNumber) => client.categories.productsIn(
1203
1271
  categoryId,
@@ -1210,14 +1278,14 @@ function useProductsInCategoryInfinite(categoryId, params = {}, options = {}) {
1210
1278
  function useCart(cartId, options = {}) {
1211
1279
  const { client, storage } = useEmporix();
1212
1280
  const { ctx } = useReadAuth(options.auth);
1213
- const { siteCode } = useReadSite();
1281
+ const { siteCode, language } = useReadSite();
1214
1282
  const { activeCompany } = useActiveCompany();
1215
1283
  const resolvedId = cartId ?? storage.getCartId() ?? void 0;
1216
1284
  return reactQuery.useQuery({
1217
1285
  queryKey: emporixKey(
1218
1286
  "cart",
1219
1287
  [resolvedId ?? null, activeCompany?.id ?? null],
1220
- { tenant: client.tenant, authKind: ctx.kind, siteCode }
1288
+ { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1221
1289
  ),
1222
1290
  enabled: resolvedId !== void 0,
1223
1291
  queryFn: () => client.carts.get(resolvedId, ctx)
@@ -1227,7 +1295,7 @@ function useCartMutations(cartId) {
1227
1295
  const { client, storage } = useEmporix();
1228
1296
  const qc = reactQuery.useQueryClient();
1229
1297
  const { ctx } = useReadAuth();
1230
- const { siteCode } = useReadSite();
1298
+ const { siteCode, language } = useReadSite();
1231
1299
  const { activeCompany } = useActiveCompany();
1232
1300
  const resolveId = () => {
1233
1301
  const id = cartId ?? storage.getCartId();
@@ -1241,7 +1309,7 @@ function useCartMutations(cartId) {
1241
1309
  const keyFor = (id) => emporixKey(
1242
1310
  "cart",
1243
1311
  [id, activeCompany?.id ?? null],
1244
- { tenant: client.tenant, authKind: ctx.kind, siteCode }
1312
+ { tenant: client.tenant, authKind: ctx.kind, siteCode, language }
1245
1313
  );
1246
1314
  function make(run, optimistic) {
1247
1315
  return reactQuery.useMutation({
@@ -1461,9 +1529,9 @@ function customerCtx(token) {
1461
1529
  function useMySegments(query = {}) {
1462
1530
  const { client, storage } = useEmporix();
1463
1531
  const token = storage.getCustomerToken();
1464
- const { siteCode } = useReadSite();
1532
+ const { siteCode, language } = useReadSite();
1465
1533
  return reactQuery.useQuery({
1466
- queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode }],
1534
+ queryKey: ["emporix", "segment", "list", { tenant: client.tenant, query, siteCode, language }],
1467
1535
  enabled: token !== null,
1468
1536
  queryFn: () => client.segments.list(query, customerCtx(token)),
1469
1537
  staleTime: SEGMENTS_STALE_TIME
@@ -1472,9 +1540,9 @@ function useMySegments(query = {}) {
1472
1540
  function useMySegmentItems(query = {}) {
1473
1541
  const { client, storage } = useEmporix();
1474
1542
  const token = storage.getCustomerToken();
1475
- const { siteCode } = useReadSite();
1543
+ const { siteCode, language } = useReadSite();
1476
1544
  return reactQuery.useQuery({
1477
- queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode }],
1545
+ queryKey: ["emporix", "segment", "items", { tenant: client.tenant, query, siteCode, language }],
1478
1546
  enabled: token !== null,
1479
1547
  queryFn: () => client.segments.listItems(query, customerCtx(token)),
1480
1548
  staleTime: SEGMENTS_STALE_TIME
@@ -1483,9 +1551,9 @@ function useMySegmentItems(query = {}) {
1483
1551
  function useMySegmentCategoryTree(query = {}) {
1484
1552
  const { client, storage } = useEmporix();
1485
1553
  const token = storage.getCustomerToken();
1486
- const { siteCode } = useReadSite();
1554
+ const { siteCode, language } = useReadSite();
1487
1555
  return reactQuery.useQuery({
1488
- queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode }],
1556
+ queryKey: ["emporix", "segment", "categoryTree", { tenant: client.tenant, query, siteCode, language }],
1489
1557
  enabled: token !== null,
1490
1558
  queryFn: () => client.segments.getCategoryTree(query, customerCtx(token)),
1491
1559
  staleTime: SEGMENTS_STALE_TIME
@@ -1494,9 +1562,9 @@ function useMySegmentCategoryTree(query = {}) {
1494
1562
  function useMySegmentProducts(query = {}) {
1495
1563
  const { client, storage } = useEmporix();
1496
1564
  const token = storage.getCustomerToken();
1497
- const { siteCode } = useReadSite();
1565
+ const { siteCode, language } = useReadSite();
1498
1566
  return reactQuery.useQuery({
1499
- queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode }],
1567
+ queryKey: ["emporix", "segment", "myProducts", { tenant: client.tenant, query, siteCode, language }],
1500
1568
  enabled: token !== null,
1501
1569
  queryFn: () => client.segments.listMyProducts(query, customerCtx(token)),
1502
1570
  staleTime: SEGMENTS_STALE_TIME
@@ -1505,13 +1573,13 @@ function useMySegmentProducts(query = {}) {
1505
1573
  function useMySegmentProductsInfinite(query = {}) {
1506
1574
  const { client, storage } = useEmporix();
1507
1575
  const token = storage.getCustomerToken();
1508
- const { siteCode } = useReadSite();
1576
+ const { siteCode, language } = useReadSite();
1509
1577
  return useEmporixInfinite({
1510
1578
  queryKey: [
1511
1579
  "emporix",
1512
1580
  "segment",
1513
1581
  "myProductsInfinite",
1514
- { tenant: client.tenant, query, siteCode }
1582
+ { tenant: client.tenant, query, siteCode, language }
1515
1583
  ],
1516
1584
  enabled: token !== null,
1517
1585
  fetchPage: (pageNumber) => client.segments.listMyProducts(
@@ -1524,9 +1592,9 @@ function useMySegmentProductsInfinite(query = {}) {
1524
1592
  function useMySegmentCategories(query = {}) {
1525
1593
  const { client, storage } = useEmporix();
1526
1594
  const token = storage.getCustomerToken();
1527
- const { siteCode } = useReadSite();
1595
+ const { siteCode, language } = useReadSite();
1528
1596
  return reactQuery.useQuery({
1529
- queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode }],
1597
+ queryKey: ["emporix", "segment", "myCategories", { tenant: client.tenant, query, siteCode, language }],
1530
1598
  enabled: token !== null,
1531
1599
  queryFn: () => client.segments.listMyCategories(query, customerCtx(token)),
1532
1600
  staleTime: SEGMENTS_STALE_TIME
@@ -1535,13 +1603,13 @@ function useMySegmentCategories(query = {}) {
1535
1603
  function useMySegmentCategoriesInfinite(query = {}) {
1536
1604
  const { client, storage } = useEmporix();
1537
1605
  const token = storage.getCustomerToken();
1538
- const { siteCode } = useReadSite();
1606
+ const { siteCode, language } = useReadSite();
1539
1607
  return useEmporixInfinite({
1540
1608
  queryKey: [
1541
1609
  "emporix",
1542
1610
  "segment",
1543
1611
  "myCategoriesInfinite",
1544
- { tenant: client.tenant, query, siteCode }
1612
+ { tenant: client.tenant, query, siteCode, language }
1545
1613
  ],
1546
1614
  enabled: token !== null,
1547
1615
  fetchPage: (pageNumber) => client.segments.listMyCategories(
@@ -1826,17 +1894,48 @@ function useCompanySwitcher() {
1826
1894
  clear: clearFn
1827
1895
  };
1828
1896
  }
1897
+ function useInvokeCloudFunction() {
1898
+ const { client, storage } = useEmporix();
1899
+ return reactQuery.useMutation({
1900
+ mutationFn: (vars) => {
1901
+ const { functionId, auth: authOverride, ...options } = vars;
1902
+ const token = storage.getCustomerToken();
1903
+ const authCtx = authOverride ?? (token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous());
1904
+ return client.cloudFunctions.invoke(functionId, options, authCtx);
1905
+ }
1906
+ });
1907
+ }
1908
+ function useCloudFunction(functionId, options, queryOptions) {
1909
+ const { client, storage } = useEmporix();
1910
+ const token = storage.getCustomerToken();
1911
+ const { auth: authOverride, ...invokeOptions } = options ?? {};
1912
+ const authCtx = authOverride ?? (token ? emporixSdk.auth.customer(token) : emporixSdk.auth.anonymous());
1913
+ return reactQuery.useQuery({
1914
+ queryKey: emporixKey(
1915
+ "cloud-function",
1916
+ [functionId ?? null, invokeOptions.path ?? null, invokeOptions.query ?? null],
1917
+ { tenant: client.tenant, authKind: token ? "customer" : "anonymous" }
1918
+ ),
1919
+ enabled: (queryOptions?.enabled ?? true) && functionId !== void 0,
1920
+ ...queryOptions?.staleTime !== void 0 ? { staleTime: queryOptions.staleTime } : {},
1921
+ queryFn: () => client.cloudFunctions.invoke(
1922
+ functionId,
1923
+ { method: "GET", ...invokeOptions },
1924
+ authCtx
1925
+ )
1926
+ });
1927
+ }
1829
1928
  function useMyOrders(options = {}) {
1830
1929
  const { client, storage } = useEmporix();
1831
1930
  const { activeCompany } = useActiveCompany();
1832
- const { siteCode } = useReadSite();
1931
+ const { siteCode, language } = useReadSite();
1833
1932
  const token = storage.getCustomerToken();
1834
1933
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1835
1934
  return reactQuery.useQuery({
1836
1935
  queryKey: emporixKey(
1837
1936
  "orders",
1838
1937
  ["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
1839
- { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode }
1938
+ { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1840
1939
  ),
1841
1940
  enabled: token !== null,
1842
1941
  queryFn: () => client.orders.listMine(emporixSdk.auth.customer(token), {
@@ -1852,14 +1951,14 @@ function useMyOrders(options = {}) {
1852
1951
  function useMyOrdersInfinite(options = {}) {
1853
1952
  const { client, storage } = useEmporix();
1854
1953
  const { activeCompany } = useActiveCompany();
1855
- const { siteCode } = useReadSite();
1954
+ const { siteCode, language } = useReadSite();
1856
1955
  const token = storage.getCustomerToken();
1857
1956
  const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
1858
1957
  return useEmporixInfinite({
1859
1958
  queryKey: emporixKey(
1860
1959
  "orders",
1861
1960
  ["mine-infinite", effectiveLE ?? null, options.status ?? null, options.pageSize ?? null],
1862
- { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode }
1961
+ { tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
1863
1962
  ),
1864
1963
  enabled: token !== null,
1865
1964
  fetchPage: (pageNumber) => client.orders.listMine(emporixSdk.auth.customer(token), {
@@ -1875,10 +1974,12 @@ function useMyOrdersInfinite(options = {}) {
1875
1974
  function useOrder(orderId, options = {}) {
1876
1975
  const { client, storage } = useEmporix();
1877
1976
  const token = storage.getCustomerToken();
1977
+ const { language } = useReadSite();
1878
1978
  return reactQuery.useQuery({
1879
1979
  queryKey: emporixKey("orders", [orderId ?? null], {
1880
1980
  tenant: client.tenant,
1881
- authKind: token ? "customer" : "anonymous"
1981
+ authKind: token ? "customer" : "anonymous",
1982
+ language
1882
1983
  }),
1883
1984
  enabled: token !== null && orderId !== void 0,
1884
1985
  queryFn: () => client.orders.get(
@@ -1986,10 +2087,12 @@ function useReorder() {
1986
2087
  }
1987
2088
  function useSalesOrder(orderId, authCtx) {
1988
2089
  const { client } = useEmporix();
2090
+ const { language } = useReadSite();
1989
2091
  return reactQuery.useQuery({
1990
2092
  queryKey: emporixKey("salesorders", [orderId ?? null], {
1991
2093
  tenant: client.tenant,
1992
- authKind: authCtx?.kind ?? "anonymous"
2094
+ authKind: authCtx?.kind ?? "anonymous",
2095
+ language
1993
2096
  }),
1994
2097
  enabled: orderId !== void 0 && authCtx !== void 0,
1995
2098
  queryFn: () => client.salesOrders.get(orderId, authCtx)
@@ -2000,12 +2103,12 @@ function useUpdateSalesOrder() {
2000
2103
  const qc = reactQuery.useQueryClient();
2001
2104
  return reactQuery.useMutation({
2002
2105
  mutationKey: ["emporix", "salesorders", "update"],
2003
- mutationFn: async ({ orderId, patch, auth: auth26, recalculate }) => {
2004
- if (!auth26) throw new Error("useUpdateSalesOrder: requires an auth context");
2106
+ mutationFn: async ({ orderId, patch, auth: auth27, recalculate }) => {
2107
+ if (!auth27) throw new Error("useUpdateSalesOrder: requires an auth context");
2005
2108
  return client.salesOrders.update(
2006
2109
  orderId,
2007
2110
  patch,
2008
- auth26,
2111
+ auth27,
2009
2112
  recalculate !== void 0 ? { recalculate } : {}
2010
2113
  );
2011
2114
  },
@@ -2212,6 +2315,7 @@ exports.useCategory = useCategory;
2212
2315
  exports.useCategoryTree = useCategoryTree;
2213
2316
  exports.useChangePassword = useChangePassword;
2214
2317
  exports.useCheckout = useCheckout;
2318
+ exports.useCloudFunction = useCloudFunction;
2215
2319
  exports.useCompany = useCompany;
2216
2320
  exports.useCompanyContacts = useCompanyContacts;
2217
2321
  exports.useCompanyGroups = useCompanyGroups;
@@ -2231,6 +2335,7 @@ exports.useDeleteShoppingList = useDeleteShoppingList;
2231
2335
  exports.useEmporix = useEmporix;
2232
2336
  exports.useEmporixErrorHandler = useEmporixErrorHandler;
2233
2337
  exports.useEmporixTelemetry = useEmporixTelemetry;
2338
+ exports.useInvokeCloudFunction = useInvokeCloudFunction;
2234
2339
  exports.useMatchPrices = useMatchPrices;
2235
2340
  exports.useMatchPricesChunked = useMatchPricesChunked;
2236
2341
  exports.useMyCompanies = useMyCompanies;