@viu/emporix-sdk-react 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/{chunk-SMJ5IQZJ.js → chunk-4YDWCA7A.js} +51 -6
- package/dist/chunk-4YDWCA7A.js.map +1 -0
- package/dist/{chunk-KLLY4YD7.js → chunk-KOVOQJ5F.js} +82 -67
- package/dist/chunk-KOVOQJ5F.js.map +1 -0
- package/dist/{chunk-FBQY2N7S.js → chunk-VMDBYVWG.js} +21 -2
- package/dist/chunk-VMDBYVWG.js.map +1 -0
- package/dist/hooks.cjs +79 -63
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +3 -3
- package/dist/index.cjs +146 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/{provider--y2yz3Jj.d.ts → provider-Bcb-tOpS.d.ts} +17 -2
- package/dist/{provider-CfgMAu8B.d.cts → provider-Ddo7aSOI.d.cts} +17 -2
- package/dist/provider.cjs +54 -3
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +1 -1
- package/dist/provider.d.ts +1 -1
- package/dist/provider.js +2 -2
- package/dist/storage.cjs +19 -0
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.cts +3 -1
- package/dist/storage.d.ts +3 -1
- package/dist/storage.js +1 -1
- package/dist/{use-returns-DDH_HnPS.d.cts → use-returns-DT98Ptod.d.cts} +9 -2
- package/dist/{use-returns-vxGoBH1I.d.ts → use-returns-uZJiO46w.d.ts} +9 -2
- package/package.json +3 -3
- package/dist/chunk-FBQY2N7S.js.map +0 -1
- package/dist/chunk-KLLY4YD7.js.map +0 -1
- package/dist/chunk-SMJ5IQZJ.js.map +0 -1
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(
|
|
@@ -1618,6 +1686,15 @@ function usePasswordReset() {
|
|
|
1618
1686
|
})
|
|
1619
1687
|
};
|
|
1620
1688
|
}
|
|
1689
|
+
function useSiteContext() {
|
|
1690
|
+
const ctx = react.useContext(EmporixSiteContext);
|
|
1691
|
+
if (!ctx) {
|
|
1692
|
+
throw new Error("useSiteContext must be used within an EmporixProvider");
|
|
1693
|
+
}
|
|
1694
|
+
return ctx;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// src/hooks/use-sites.ts
|
|
1621
1698
|
var SITES_STALE_TIME = 10 * 6e4;
|
|
1622
1699
|
function useSites(options = {}) {
|
|
1623
1700
|
const { client } = useEmporix();
|
|
@@ -1637,12 +1714,10 @@ function useDefaultSite(options = {}) {
|
|
|
1637
1714
|
staleTime: SITES_STALE_TIME
|
|
1638
1715
|
});
|
|
1639
1716
|
}
|
|
1640
|
-
function
|
|
1641
|
-
const
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
}
|
|
1645
|
-
return ctx;
|
|
1717
|
+
function useActiveSite(options = {}) {
|
|
1718
|
+
const { siteCode } = useSiteContext();
|
|
1719
|
+
const { data: sites } = useSites(options);
|
|
1720
|
+
return siteCode ? sites?.find((s) => s.code === siteCode) : void 0;
|
|
1646
1721
|
}
|
|
1647
1722
|
function useMyCompanies() {
|
|
1648
1723
|
const { client, storage } = useEmporix();
|
|
@@ -1860,14 +1935,14 @@ function useCloudFunction(functionId, options, queryOptions) {
|
|
|
1860
1935
|
function useMyOrders(options = {}) {
|
|
1861
1936
|
const { client, storage } = useEmporix();
|
|
1862
1937
|
const { activeCompany } = useActiveCompany();
|
|
1863
|
-
const { siteCode } = useReadSite();
|
|
1938
|
+
const { siteCode, language } = useReadSite();
|
|
1864
1939
|
const token = storage.getCustomerToken();
|
|
1865
1940
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1866
1941
|
return reactQuery.useQuery({
|
|
1867
1942
|
queryKey: emporixKey(
|
|
1868
1943
|
"orders",
|
|
1869
1944
|
["mine", effectiveLE ?? null, options.status ?? null, options.pageNumber ?? 1, options.pageSize ?? null],
|
|
1870
|
-
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode }
|
|
1945
|
+
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1871
1946
|
),
|
|
1872
1947
|
enabled: token !== null,
|
|
1873
1948
|
queryFn: () => client.orders.listMine(emporixSdk.auth.customer(token), {
|
|
@@ -1883,14 +1958,14 @@ function useMyOrders(options = {}) {
|
|
|
1883
1958
|
function useMyOrdersInfinite(options = {}) {
|
|
1884
1959
|
const { client, storage } = useEmporix();
|
|
1885
1960
|
const { activeCompany } = useActiveCompany();
|
|
1886
|
-
const { siteCode } = useReadSite();
|
|
1961
|
+
const { siteCode, language } = useReadSite();
|
|
1887
1962
|
const token = storage.getCustomerToken();
|
|
1888
1963
|
const effectiveLE = options.legalEntityId === null ? void 0 : options.legalEntityId ?? activeCompany?.id;
|
|
1889
1964
|
return useEmporixInfinite({
|
|
1890
1965
|
queryKey: emporixKey(
|
|
1891
1966
|
"orders",
|
|
1892
1967
|
["mine-infinite", effectiveLE ?? null, options.status ?? null, options.pageSize ?? null],
|
|
1893
|
-
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode }
|
|
1968
|
+
{ tenant: client.tenant, authKind: token ? "customer" : "anonymous", siteCode, language }
|
|
1894
1969
|
),
|
|
1895
1970
|
enabled: token !== null,
|
|
1896
1971
|
fetchPage: (pageNumber) => client.orders.listMine(emporixSdk.auth.customer(token), {
|
|
@@ -1906,10 +1981,12 @@ function useMyOrdersInfinite(options = {}) {
|
|
|
1906
1981
|
function useOrder(orderId, options = {}) {
|
|
1907
1982
|
const { client, storage } = useEmporix();
|
|
1908
1983
|
const token = storage.getCustomerToken();
|
|
1984
|
+
const { language } = useReadSite();
|
|
1909
1985
|
return reactQuery.useQuery({
|
|
1910
1986
|
queryKey: emporixKey("orders", [orderId ?? null], {
|
|
1911
1987
|
tenant: client.tenant,
|
|
1912
|
-
authKind: token ? "customer" : "anonymous"
|
|
1988
|
+
authKind: token ? "customer" : "anonymous",
|
|
1989
|
+
language
|
|
1913
1990
|
}),
|
|
1914
1991
|
enabled: token !== null && orderId !== void 0,
|
|
1915
1992
|
queryFn: () => client.orders.get(
|
|
@@ -2017,10 +2094,12 @@ function useReorder() {
|
|
|
2017
2094
|
}
|
|
2018
2095
|
function useSalesOrder(orderId, authCtx) {
|
|
2019
2096
|
const { client } = useEmporix();
|
|
2097
|
+
const { language } = useReadSite();
|
|
2020
2098
|
return reactQuery.useQuery({
|
|
2021
2099
|
queryKey: emporixKey("salesorders", [orderId ?? null], {
|
|
2022
2100
|
tenant: client.tenant,
|
|
2023
|
-
authKind: authCtx?.kind ?? "anonymous"
|
|
2101
|
+
authKind: authCtx?.kind ?? "anonymous",
|
|
2102
|
+
language
|
|
2024
2103
|
}),
|
|
2025
2104
|
enabled: orderId !== void 0 && authCtx !== void 0,
|
|
2026
2105
|
queryFn: () => client.salesOrders.get(orderId, authCtx)
|
|
@@ -2228,6 +2307,7 @@ exports.prefetchOrder = prefetchOrder;
|
|
|
2228
2307
|
exports.prefetchProduct = prefetchProduct;
|
|
2229
2308
|
exports.useActiveCart = useActiveCart;
|
|
2230
2309
|
exports.useActiveCompany = useActiveCompany;
|
|
2310
|
+
exports.useActiveSite = useActiveSite;
|
|
2231
2311
|
exports.useAddGroupMember = useAddGroupMember;
|
|
2232
2312
|
exports.useAddToShoppingList = useAddToShoppingList;
|
|
2233
2313
|
exports.useAddressMutations = useAddressMutations;
|