@salesforce/storefront-next-runtime 0.3.1 → 0.4.0-alpha.1
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/README.md +82 -0
- package/dist/DesignComponent.js +37 -12
- package/dist/DesignComponent.js.map +1 -1
- package/dist/DesignContext.js +47 -2
- package/dist/DesignContext.js.map +1 -1
- package/dist/DesignFrame.js +1 -1
- package/dist/DesignRegion.js +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/custom-global-preferences.d.ts +20 -0
- package/dist/custom-global-preferences.d.ts.map +1 -0
- package/dist/custom-global-preferences.js +28 -0
- package/dist/custom-global-preferences.js.map +1 -0
- package/dist/custom-site-preferences.d.ts +20 -0
- package/dist/custom-site-preferences.d.ts.map +1 -0
- package/dist/custom-site-preferences.js +28 -0
- package/dist/custom-site-preferences.js.map +1 -0
- package/dist/data-store-custom-global-preferences.d.ts +2 -0
- package/dist/data-store-custom-global-preferences.js +6 -0
- package/dist/data-store-custom-site-preferences.d.ts +2 -0
- package/dist/data-store-custom-site-preferences.js +6 -0
- package/dist/data-store-gcp-preferences.d.ts +2 -0
- package/dist/data-store-gcp-preferences.js +6 -0
- package/dist/data-store.d.ts +97 -0
- package/dist/data-store.d.ts.map +1 -0
- package/dist/data-store.js +42 -0
- package/dist/data-store.js.map +1 -0
- package/dist/design-data.d.ts +82 -88
- package/dist/design-data.d.ts.map +1 -1
- package/dist/design-data.js +95 -57
- package/dist/design-data.js.map +1 -1
- package/dist/design-messaging.d.ts +2 -2
- package/dist/design-react-core.d.ts +2 -2
- package/dist/events.d.ts +34 -6
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +6 -6
- package/dist/events.js.map +1 -1
- package/dist/gcp-preferences.d.ts +52 -0
- package/dist/gcp-preferences.d.ts.map +1 -0
- package/dist/gcp-preferences.js +61 -0
- package/dist/gcp-preferences.js.map +1 -0
- package/dist/i18n-client.d.ts +38 -0
- package/dist/i18n-client.d.ts.map +1 -0
- package/dist/i18n-client.js +72 -0
- package/dist/i18n-client.js.map +1 -0
- package/dist/i18n.d.ts +63 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +98 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +60 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/messaging-api.js +3 -1
- package/dist/messaging-api.js.map +1 -1
- package/dist/scapi.d.ts +247 -2
- package/dist/scapi.d.ts.map +1 -1
- package/dist/scapi.js +1 -1
- package/dist/scapi.js.map +1 -1
- package/dist/site-context.d.ts +94 -18
- package/dist/site-context.d.ts.map +1 -1
- package/dist/site-context.js +2 -417
- package/dist/site-context2.js +513 -0
- package/dist/site-context2.js.map +1 -0
- package/dist/types2.d.ts +210 -0
- package/dist/types2.d.ts.map +1 -1
- package/dist/utils.js +179 -0
- package/dist/utils.js.map +1 -0
- package/package.json +63 -4
- package/dist/site-context.js.map +0 -1
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext as createContext$1, createCookie } from "react-router";
|
|
4
|
+
|
|
5
|
+
//#region src/site-context/site-context.tsx
|
|
6
|
+
const SiteContext = createContext(void 0);
|
|
7
|
+
/**
|
|
8
|
+
* Provides the current site context (site, locale, language, currency) to the component tree.
|
|
9
|
+
*
|
|
10
|
+
* Mounted in the template's root.tsx with the resolved values from the
|
|
11
|
+
* loader/middleware. The SDK has no react-i18next dependency, so `language`
|
|
12
|
+
* is passed as a prop from the template.
|
|
13
|
+
*/
|
|
14
|
+
function SiteProvider({ site, locale, language, currency, children }) {
|
|
15
|
+
const value = useMemo(() => ({
|
|
16
|
+
site,
|
|
17
|
+
locale,
|
|
18
|
+
language,
|
|
19
|
+
currency
|
|
20
|
+
}), [
|
|
21
|
+
site,
|
|
22
|
+
locale,
|
|
23
|
+
language,
|
|
24
|
+
currency
|
|
25
|
+
]);
|
|
26
|
+
return /* @__PURE__ */ jsx(SiteContext.Provider, {
|
|
27
|
+
value,
|
|
28
|
+
children
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* React hook to get the current site context.
|
|
33
|
+
* Returns `{ site, locale, language, currency }`.
|
|
34
|
+
* @throws If called outside of a SiteProvider
|
|
35
|
+
*/
|
|
36
|
+
function useSite() {
|
|
37
|
+
const value = useContext(SiteContext);
|
|
38
|
+
if (!value) throw new Error("useSite must be used within a SiteProvider");
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/site-context/build-url.ts
|
|
44
|
+
/**
|
|
45
|
+
* Parses search config string into key-value pairs, preserving ':param' placeholders.
|
|
46
|
+
* '?lng=:localeId&site=:siteId' → { lng: ':localeId', site: ':siteId' }
|
|
47
|
+
*/
|
|
48
|
+
function parseSearchConfig(search) {
|
|
49
|
+
const searchParams = new URLSearchParams(search);
|
|
50
|
+
const result = {};
|
|
51
|
+
for (const [key, value] of searchParams) result[key] = value;
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Extracts parameter names from a prefix string.
|
|
56
|
+
* '/:siteId/:localeId' → ['siteId', 'localeId']
|
|
57
|
+
*/
|
|
58
|
+
function extractPrefixParams(prefix) {
|
|
59
|
+
const matches = prefix.match(/:(\w+)/g);
|
|
60
|
+
return matches ? matches.map((m) => m.slice(1)) : [];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Splits a URL string into its component parts.
|
|
64
|
+
* '/product/123?color=red#details' → { pathname: '/product/123', search: 'color=red', hash: '#details' }
|
|
65
|
+
*/
|
|
66
|
+
function decomposeUrl(url) {
|
|
67
|
+
const hashIdx = url.indexOf("#");
|
|
68
|
+
const hash = hashIdx >= 0 ? url.slice(hashIdx) : "";
|
|
69
|
+
const withoutHash = hashIdx >= 0 ? url.slice(0, hashIdx) : url;
|
|
70
|
+
const searchIdx = withoutHash.indexOf("?");
|
|
71
|
+
const search = searchIdx >= 0 ? withoutHash.slice(searchIdx + 1) : "";
|
|
72
|
+
return {
|
|
73
|
+
pathname: searchIdx >= 0 ? withoutHash.slice(0, searchIdx) : withoutHash,
|
|
74
|
+
search,
|
|
75
|
+
hash
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolves a prefix template by replacing parameter placeholders with values.
|
|
80
|
+
* ('/:siteId/:localeId', { siteId: 'global', localeId: 'en-GB' }) → '/global/en-GB'
|
|
81
|
+
*/
|
|
82
|
+
function resolvePrefix(prefix, params) {
|
|
83
|
+
let resolved = prefix;
|
|
84
|
+
for (const paramName of extractPrefixParams(prefix)) {
|
|
85
|
+
const value = params[paramName];
|
|
86
|
+
if (value) resolved = resolved.replace(`:${paramName}`, value);
|
|
87
|
+
}
|
|
88
|
+
return resolved;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Strips the URL prefix segments from a pathname based on a prefix pattern.
|
|
92
|
+
* Since all routes are configured with the prefix baked in, segment counting is sufficient.
|
|
93
|
+
*
|
|
94
|
+
* @param pathname - Full pathname (e.g. '/global/en-GB/checkout')
|
|
95
|
+
* @param prefixPattern - URL prefix pattern from config (e.g. '/:siteId/:localeId')
|
|
96
|
+
* @returns Pathname with prefix stripped (e.g. '/checkout'), or original if
|
|
97
|
+
* the pathname has fewer segments than the prefix
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* stripPathPrefix('/global/en-GB/checkout', '/:siteId/:localeId') // → '/checkout'
|
|
101
|
+
* stripPathPrefix('/checkout', '/:siteId/:localeId') // → '/checkout' (fewer segments → unchanged)
|
|
102
|
+
* stripPathPrefix('/checkout', '') // → '/checkout' (no prefix configured)
|
|
103
|
+
* stripPathPrefix('/', '/:siteId/:localeId') // → '/'
|
|
104
|
+
*/
|
|
105
|
+
function stripPathPrefix(pathname, prefixPattern) {
|
|
106
|
+
if (!prefixPattern) return pathname;
|
|
107
|
+
const prefixSegmentCount = prefixPattern.split("/").filter(Boolean).length;
|
|
108
|
+
const pathSegments = pathname.split("/").filter(Boolean);
|
|
109
|
+
if (pathSegments.length <= prefixSegmentCount) return pathSegments.length === prefixSegmentCount ? "/" : pathname;
|
|
110
|
+
return `/${pathSegments.slice(prefixSegmentCount).join("/")}`;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sanitize a resolved prefix from a pathname if present.
|
|
114
|
+
* sanitizePrefix('/global/en-GB/product/123', '/global/en-GB') → '/product/123'
|
|
115
|
+
* sanitizePrefix('/product/123', '/global/en-GB') → '/product/123' (no-op)
|
|
116
|
+
*/
|
|
117
|
+
function sanitizePrefix(pathname, pathPrefix) {
|
|
118
|
+
if (!pathPrefix) return pathname;
|
|
119
|
+
if (pathname === pathPrefix) return "";
|
|
120
|
+
if (pathname.startsWith(`${pathPrefix}/`)) return pathname.slice(pathPrefix.length);
|
|
121
|
+
return pathname;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Builds a fully-qualified URL with site context prefix and search params.
|
|
125
|
+
*
|
|
126
|
+
* Only keys defined in urlConfig.search are set by site context. Any other query params
|
|
127
|
+
* already present on the `to` URL (including duplicate keys) are preserved as-is.
|
|
128
|
+
* e.g. to='/api/search?refine=color:blue&refine=size:M', search='?lng=:localeId'
|
|
129
|
+
* → '/api/search?refine=color:blue&refine=size:M&lng=en-GB'
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* buildUrl({ to: '/product/123', urlConfig: { prefix: '/:siteId', search: '?lng=:localeId' }, params: { siteId: 'global', localeId: 'en-GB' } })
|
|
133
|
+
* // → '/global/product/123?lng=en-GB'
|
|
134
|
+
*/
|
|
135
|
+
function buildUrl({ to, urlConfig, params }) {
|
|
136
|
+
if (!urlConfig) return to;
|
|
137
|
+
if (!to || to === "#" || to.startsWith("http") || to.startsWith("//")) return to;
|
|
138
|
+
const { pathname, search: existingSearch, hash } = decomposeUrl(to);
|
|
139
|
+
const pathPrefix = urlConfig.prefix && urlConfig.prefix !== "/" ? resolvePrefix(urlConfig.prefix, params) : "";
|
|
140
|
+
const path = pathPrefix ? `${pathPrefix}${sanitizePrefix(pathname, pathPrefix)}` : pathname;
|
|
141
|
+
const searchParams = new URLSearchParams(existingSearch);
|
|
142
|
+
if (urlConfig.search) {
|
|
143
|
+
const searchConfig = parseSearchConfig(urlConfig.search);
|
|
144
|
+
for (const [queryKey, value] of Object.entries(searchConfig)) if (value.startsWith(":")) {
|
|
145
|
+
const paramValue = params[value.slice(1)];
|
|
146
|
+
if (paramValue) searchParams.set(queryKey, paramValue);
|
|
147
|
+
} else searchParams.set(queryKey, value);
|
|
148
|
+
}
|
|
149
|
+
const search = searchParams.toString();
|
|
150
|
+
return `${path}${search ? `?${search}` : ""}${hash}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/site-context/utils.ts
|
|
155
|
+
/**
|
|
156
|
+
* Extract a string value from the URL path segment at the given index.
|
|
157
|
+
*/
|
|
158
|
+
function lookupFromPath(pathname, pathIndex) {
|
|
159
|
+
const pathSegments = pathname.split("/").filter(Boolean);
|
|
160
|
+
if (pathSegments.length <= pathIndex) return null;
|
|
161
|
+
return pathSegments[pathIndex];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Detect a string value from cookie using the given cookie parser.
|
|
165
|
+
*
|
|
166
|
+
* Returns a promise that resolves to the cookie value.
|
|
167
|
+
*/
|
|
168
|
+
async function readCookieFromRequest(request, cookie) {
|
|
169
|
+
const cookies = request.headers.get("Cookie");
|
|
170
|
+
if (!cookies) return null;
|
|
171
|
+
return await cookie.parse(cookies);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/site-context/site-detection.ts
|
|
176
|
+
/**
|
|
177
|
+
* Detect site reference from cookie.
|
|
178
|
+
*/
|
|
179
|
+
async function readSiteFromCookie(request, cookie) {
|
|
180
|
+
return readCookieFromRequest(request, cookie);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get site object using the site id or alias
|
|
184
|
+
* 1. Check siteIdentifier against each site's alias; if matched, return that site.
|
|
185
|
+
* 2. Else check against each site's id; if matched, return that site.
|
|
186
|
+
* 3. If no match, return null.
|
|
187
|
+
*/
|
|
188
|
+
function getSiteFromIdOrAlias(siteIdentifier, sites) {
|
|
189
|
+
if (!siteIdentifier) return null;
|
|
190
|
+
return sites.find((site) => site.alias === siteIdentifier || site.id === siteIdentifier) ?? null;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Resolve site using the configured detection order.
|
|
194
|
+
* Returns the first valid site from the first source that yields a valid value.
|
|
195
|
+
*/
|
|
196
|
+
async function resolveSite(request, settings) {
|
|
197
|
+
const { sites, defaultSiteId, siteDetectionConfig, siteCookie } = settings;
|
|
198
|
+
const requestUrl = new URL(request.url);
|
|
199
|
+
const basePathOffset = process.env.MRT_ENV_BASE_PATH ? process.env.MRT_ENV_BASE_PATH.split("/").filter(Boolean).length : 0;
|
|
200
|
+
const resolvers = {
|
|
201
|
+
path: () => Promise.resolve(lookupFromPath(requestUrl.pathname, siteDetectionConfig.lookupFromPathIndex + basePathOffset)),
|
|
202
|
+
querystring: () => Promise.resolve(requestUrl.searchParams.get(siteDetectionConfig.lookupQuerystring)),
|
|
203
|
+
header: () => Promise.resolve(request.headers.get(siteDetectionConfig.lookupHeader)),
|
|
204
|
+
cookie: async () => readSiteFromCookie(request, siteCookie)
|
|
205
|
+
};
|
|
206
|
+
for (const method of siteDetectionConfig.order) {
|
|
207
|
+
const resolvedSite = getSiteFromIdOrAlias(await resolvers[method]?.(), sites);
|
|
208
|
+
if (resolvedSite) return resolvedSite;
|
|
209
|
+
}
|
|
210
|
+
const site = getSiteFromIdOrAlias(defaultSiteId, sites);
|
|
211
|
+
if (!site) throw new Error(`Default site ${defaultSiteId} not found.`);
|
|
212
|
+
return site;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/site-context/configs.ts
|
|
217
|
+
const DEFAULT_CURRENCY_COOKIE_NAME = "currency";
|
|
218
|
+
/**
|
|
219
|
+
* Default site detection configuration
|
|
220
|
+
*/
|
|
221
|
+
const DEFAULT_SITE_DETECTION = {
|
|
222
|
+
order: [
|
|
223
|
+
"path",
|
|
224
|
+
"querystring",
|
|
225
|
+
"cookie",
|
|
226
|
+
"header"
|
|
227
|
+
],
|
|
228
|
+
lookupFromPathIndex: 0,
|
|
229
|
+
lookupQuerystring: "site",
|
|
230
|
+
lookupCookie: "site_id",
|
|
231
|
+
lookupHeader: "X-Site-Id",
|
|
232
|
+
caches: ["cookie"]
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Default locale detection configuration
|
|
236
|
+
*/
|
|
237
|
+
const DEFAULT_LOCALE_DETECTION = {
|
|
238
|
+
order: [
|
|
239
|
+
"path",
|
|
240
|
+
"querystring",
|
|
241
|
+
"cookie",
|
|
242
|
+
"header"
|
|
243
|
+
],
|
|
244
|
+
lookupFromPathIndex: 1,
|
|
245
|
+
lookupQuerystring: "lng",
|
|
246
|
+
lookupCookie: "lng",
|
|
247
|
+
lookupHeader: "Accept-Language",
|
|
248
|
+
caches: ["cookie"]
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/site-context/cookies.ts
|
|
253
|
+
/**
|
|
254
|
+
* Cookie options for site context cookies (site and locale)
|
|
255
|
+
*/
|
|
256
|
+
const COOKIE_OPTIONS = {
|
|
257
|
+
path: "/",
|
|
258
|
+
sameSite: "lax",
|
|
259
|
+
secure: process.env.NODE_ENV === "production",
|
|
260
|
+
httpOnly: true
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Creates a cookie instance with the given name.
|
|
264
|
+
*
|
|
265
|
+
* @param name - Cookie name
|
|
266
|
+
* @returns Cookie instance configured with site context options
|
|
267
|
+
*/
|
|
268
|
+
function createSiteContextCookie(name, options) {
|
|
269
|
+
return createCookie(name, {
|
|
270
|
+
...COOKIE_OPTIONS,
|
|
271
|
+
...options
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Creates a currency cookie instance with the given name.
|
|
276
|
+
*
|
|
277
|
+
* @param name - Cookie name
|
|
278
|
+
* @returns Cookie instance configured with site context cookie options
|
|
279
|
+
*/
|
|
280
|
+
function createCurrencyCookie(name, options) {
|
|
281
|
+
return createCookie(name, {
|
|
282
|
+
...COOKIE_OPTIONS,
|
|
283
|
+
...options
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* WeakMap to pass resolved locale from site context middleware to i18next's findLocale.
|
|
288
|
+
* WeakMap allows garbage collection when requests are done.
|
|
289
|
+
* This is necessary because findLocale() only receives the Request object, not the router context.
|
|
290
|
+
*/
|
|
291
|
+
const requestToLocaleMap = /* @__PURE__ */ new WeakMap();
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/site-context/locale-detection.ts
|
|
295
|
+
/**
|
|
296
|
+
* Read locale from cookie.
|
|
297
|
+
*/
|
|
298
|
+
async function readLocaleFromCookie(request, cookie) {
|
|
299
|
+
return readCookieFromRequest(request, cookie);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Get locale object using the locale id or alias.
|
|
303
|
+
* 1. Check localeIdOrAlias against each locale's alias; if matched, return that locale.
|
|
304
|
+
* 2. Else check against each locale's id; if matched, return that locale.
|
|
305
|
+
* 3. If no match, return null (caller should use defaultLocale).
|
|
306
|
+
*
|
|
307
|
+
* @param localeIdentifier - The locale id or alias to get the locale from. Null is allowed because this may come from
|
|
308
|
+
* extrenal sources such as cookies, headers, or query parameters.
|
|
309
|
+
* @param locales - The list of locales to search through.
|
|
310
|
+
* @returns The locale object if found, otherwise null.
|
|
311
|
+
*/
|
|
312
|
+
function getLocaleFromIdOrAlias(localeIdentifier, locales) {
|
|
313
|
+
if (!localeIdentifier) return null;
|
|
314
|
+
return locales.find((locale) => locale.alias === localeIdentifier || locale.id === localeIdentifier) ?? null;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Resolve locale using the configured detection order.
|
|
318
|
+
* Returns the first valid locale from the first source that yields a valid value.
|
|
319
|
+
*/
|
|
320
|
+
async function resolveLocale(request, settings, site) {
|
|
321
|
+
const { defaultLocale, localeDetectionConfig, localeCookie } = settings;
|
|
322
|
+
const { supportedLocales } = site;
|
|
323
|
+
let locale = null;
|
|
324
|
+
const requestUrl = new URL(request.url);
|
|
325
|
+
const basePathOffset = process.env.MRT_ENV_BASE_PATH ? process.env.MRT_ENV_BASE_PATH.split("/").filter(Boolean).length : 0;
|
|
326
|
+
const resolvers = {
|
|
327
|
+
path: () => Promise.resolve(lookupFromPath(requestUrl.pathname, localeDetectionConfig.lookupFromPathIndex + basePathOffset)),
|
|
328
|
+
querystring: () => Promise.resolve(requestUrl.searchParams.get(localeDetectionConfig.lookupQuerystring)),
|
|
329
|
+
header: () => Promise.resolve(request.headers.get(localeDetectionConfig.lookupHeader)),
|
|
330
|
+
cookie: async () => readLocaleFromCookie(request, localeCookie)
|
|
331
|
+
};
|
|
332
|
+
for (const method of localeDetectionConfig.order) {
|
|
333
|
+
const resolvedLocale = getLocaleFromIdOrAlias(await resolvers[method]?.(), supportedLocales);
|
|
334
|
+
if (resolvedLocale) return resolvedLocale;
|
|
335
|
+
}
|
|
336
|
+
if (!locale) locale = getLocaleFromIdOrAlias(defaultLocale, supportedLocales);
|
|
337
|
+
if (!locale) throw new Error(`Default locale ${defaultLocale} not found in the list of supported locales for site ${site.id}.`);
|
|
338
|
+
return locale;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/site-context/currency-detection.ts
|
|
343
|
+
/**
|
|
344
|
+
* Resolve the currency for the current request.
|
|
345
|
+
*
|
|
346
|
+
* Priority:
|
|
347
|
+
* 1. Cookie (user-selected currency, if valid for this site)
|
|
348
|
+
* 2. Locale's preferred currency (if valid for this site)
|
|
349
|
+
* 3. Site's default currency
|
|
350
|
+
*
|
|
351
|
+
* @param request - Incoming request
|
|
352
|
+
* @param currencyCookie - Cookie instance for reading the currency cookie
|
|
353
|
+
* @param site - Resolved site for this request
|
|
354
|
+
* @param locale - Resolved locale for this request
|
|
355
|
+
* @returns The resolved currency code
|
|
356
|
+
*/
|
|
357
|
+
async function resolveCurrency(request, currencyCookie, site, locale) {
|
|
358
|
+
const { supportedCurrencies, defaultCurrency } = site;
|
|
359
|
+
if (!supportedCurrencies || supportedCurrencies.length === 0) throw new Error(`Site "${site.id}" must have supportedCurrencies configured.`);
|
|
360
|
+
const cookieValue = await readCookieFromRequest(request, currencyCookie);
|
|
361
|
+
if (typeof cookieValue === "string" && supportedCurrencies.includes(cookieValue)) return cookieValue;
|
|
362
|
+
if (locale.preferredCurrency && supportedCurrencies.includes(locale.preferredCurrency)) return locale.preferredCurrency;
|
|
363
|
+
return defaultCurrency;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region src/site-context/middleware.ts
|
|
368
|
+
const siteContext = createContext$1(null);
|
|
369
|
+
/**
|
|
370
|
+
* Resolve site, locale, and currency from a request in one call.
|
|
371
|
+
*
|
|
372
|
+
* This is the recommended public entry point for site-context resolution.
|
|
373
|
+
* It encapsulates the required resolution order (site → locale → currency)
|
|
374
|
+
* so consumers don't need to manage the dependency chain manually.
|
|
375
|
+
*
|
|
376
|
+
* The individual resolvers (`resolveSite`, `resolveLocale`, `resolveCurrency`)
|
|
377
|
+
* are available as advanced utilities for cases that need fine-grained control.
|
|
378
|
+
*
|
|
379
|
+
* @param request - Incoming HTTP request
|
|
380
|
+
* @param settings - Fully resolved site settings (with detection config and cookies)
|
|
381
|
+
* @returns Resolved site, locale, and currency
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* const { site, locale, currency } = await resolveSiteContext(request, settings);
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
async function resolveSiteContext(request, settings) {
|
|
389
|
+
const site = await resolveSite(request, settings);
|
|
390
|
+
const locale = await resolveLocale(request, settings, site);
|
|
391
|
+
return {
|
|
392
|
+
site,
|
|
393
|
+
locale,
|
|
394
|
+
currency: await resolveCurrency(request, settings.currencyCookie, site, locale)
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Helper function to get site context cookies from router context.
|
|
399
|
+
* Useful in server actions and loaders that need to read/set cookies.
|
|
400
|
+
*
|
|
401
|
+
* @param context - Router context provider
|
|
402
|
+
* @returns Object with siteCookie and localeCookie instances, or null if context not set
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* export const action: ActionFunction = async ({ request, context }) => {
|
|
407
|
+
* const cookies = getSiteContextCookies(context);
|
|
408
|
+
* if (cookies) {
|
|
409
|
+
* const cookieHeader = await cookies.localeCookie.serialize(locale);
|
|
410
|
+
* // ... use cookieHeader
|
|
411
|
+
* }
|
|
412
|
+
* };
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
function getSiteContextCookies(context) {
|
|
416
|
+
const siteCtx = context.get(siteContext);
|
|
417
|
+
if (!siteCtx) return null;
|
|
418
|
+
return {
|
|
419
|
+
siteCookie: siteCtx.siteCookie,
|
|
420
|
+
localeCookie: siteCtx.localeCookie,
|
|
421
|
+
currencyCookie: siteCtx.currencyCookie
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Helper function to determine if cookies should be set based on:
|
|
426
|
+
* 1. Whether caching is enabled for each cookie type
|
|
427
|
+
* 2. Whether the resolved value differs from the existing cookie
|
|
428
|
+
* 3. Whether cookies were already set by actions/loaders in the response
|
|
429
|
+
*
|
|
430
|
+
* @param request - Incoming request
|
|
431
|
+
* @param response - Response from next()
|
|
432
|
+
* @param settings - Site context settings with cookie instances and detection config
|
|
433
|
+
* @param site - Resolved site for this request
|
|
434
|
+
* @param locale - Resolved locale for this request
|
|
435
|
+
* @param currency - Resolved currency for this request
|
|
436
|
+
* @returns Object with shouldSetSiteCookie, shouldSetLocaleCookie, and shouldSetCurrencyCookie booleans
|
|
437
|
+
*/
|
|
438
|
+
async function shouldSetCookies(request, response, settings, site, locale, currency) {
|
|
439
|
+
const cacheSite = settings.siteDetectionConfig.caches?.includes("cookie");
|
|
440
|
+
const cacheLocale = settings.localeDetectionConfig.caches?.includes("cookie");
|
|
441
|
+
const responseSetCookies = response.headers.getSetCookie?.() || [];
|
|
442
|
+
const isSettingSiteCookieInResponse = responseSetCookies.some((cookie) => cookie.startsWith(`${settings.siteCookie.name}=`));
|
|
443
|
+
const isSettingLocaleCookieInResponse = responseSetCookies.some((cookie) => cookie.startsWith(`${settings.localeCookie.name}=`));
|
|
444
|
+
const isSettingCurrencyCookieInResponse = responseSetCookies.some((cookie) => cookie.startsWith(`${settings.currencyCookie.name}=`));
|
|
445
|
+
const requestCookieHeader = request.headers.get("Cookie");
|
|
446
|
+
const [existingSiteCookie, existingLocaleCookie, existingCurrencyCookie] = await Promise.all([
|
|
447
|
+
settings.siteCookie.parse(requestCookieHeader),
|
|
448
|
+
settings.localeCookie.parse(requestCookieHeader),
|
|
449
|
+
settings.currencyCookie.parse(requestCookieHeader)
|
|
450
|
+
]);
|
|
451
|
+
return {
|
|
452
|
+
shouldSetSiteCookie: cacheSite && !isSettingSiteCookieInResponse && existingSiteCookie !== site.id,
|
|
453
|
+
shouldSetLocaleCookie: cacheLocale && !isSettingLocaleCookieInResponse && existingLocaleCookie !== locale.id,
|
|
454
|
+
shouldSetCurrencyCookie: !isSettingCurrencyCookieInResponse && existingCurrencyCookie !== currency
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Creates a site context middleware that resolves the current site from
|
|
459
|
+
* the request (path, cookie, header, query, or default) and stores the
|
|
460
|
+
* result in the router context.
|
|
461
|
+
*
|
|
462
|
+
* Does not import or read from app config context; the consumer supplies config.
|
|
463
|
+
*/
|
|
464
|
+
function createSiteContextMiddleware(config) {
|
|
465
|
+
const siteDetectionConfig = {
|
|
466
|
+
...DEFAULT_SITE_DETECTION,
|
|
467
|
+
...config.siteDetectionConfig
|
|
468
|
+
};
|
|
469
|
+
const localeDetectionConfig = {
|
|
470
|
+
...DEFAULT_LOCALE_DETECTION,
|
|
471
|
+
...config.localeDetectionConfig
|
|
472
|
+
};
|
|
473
|
+
const siteCookie = createSiteContextCookie(siteDetectionConfig.lookupCookie, config.cookieOptions);
|
|
474
|
+
const localeCookie = createSiteContextCookie(localeDetectionConfig.lookupCookie, config.cookieOptions);
|
|
475
|
+
const currencyCookie = createCurrencyCookie(config.currencyCookieName ?? DEFAULT_CURRENCY_COOKIE_NAME, config.cookieOptions);
|
|
476
|
+
const settings = {
|
|
477
|
+
...config,
|
|
478
|
+
siteDetectionConfig,
|
|
479
|
+
localeDetectionConfig,
|
|
480
|
+
siteCookie,
|
|
481
|
+
localeCookie,
|
|
482
|
+
currencyCookie
|
|
483
|
+
};
|
|
484
|
+
const siteContextMiddleware = async ({ request, context }, next) => {
|
|
485
|
+
const { site, locale, currency } = await resolveSiteContext(request, settings);
|
|
486
|
+
context.set(siteContext, {
|
|
487
|
+
site,
|
|
488
|
+
locale,
|
|
489
|
+
currency,
|
|
490
|
+
siteCookie: settings.siteCookie,
|
|
491
|
+
localeCookie: settings.localeCookie,
|
|
492
|
+
currencyCookie: settings.currencyCookie
|
|
493
|
+
});
|
|
494
|
+
requestToLocaleMap.set(request, locale.id);
|
|
495
|
+
const response = await next();
|
|
496
|
+
const { shouldSetSiteCookie, shouldSetLocaleCookie, shouldSetCurrencyCookie } = await shouldSetCookies(request, response, settings, site, locale, currency);
|
|
497
|
+
if (!shouldSetSiteCookie && !shouldSetLocaleCookie && !shouldSetCurrencyCookie) return response;
|
|
498
|
+
const [siteSetCookie, localeSetCookie, currencySetCookie] = await Promise.all([
|
|
499
|
+
shouldSetSiteCookie ? settings.siteCookie.serialize(site.id, { path: "/" }) : Promise.resolve(null),
|
|
500
|
+
shouldSetLocaleCookie ? settings.localeCookie.serialize(locale.id, { path: "/" }) : Promise.resolve(null),
|
|
501
|
+
shouldSetCurrencyCookie ? settings.currencyCookie.serialize(currency) : Promise.resolve(null)
|
|
502
|
+
]);
|
|
503
|
+
if (siteSetCookie) response.headers.append("Set-Cookie", siteSetCookie);
|
|
504
|
+
if (localeSetCookie) response.headers.append("Set-Cookie", localeSetCookie);
|
|
505
|
+
if (currencySetCookie) response.headers.append("Set-Cookie", currencySetCookie);
|
|
506
|
+
return response;
|
|
507
|
+
};
|
|
508
|
+
return siteContextMiddleware;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
//#endregion
|
|
512
|
+
export { requestToLocaleMap as a, sanitizePrefix as c, useSite as d, siteContext as i, stripPathPrefix as l, getSiteContextCookies as n, buildUrl as o, resolveSiteContext as r, resolvePrefix as s, createSiteContextMiddleware as t, SiteProvider as u };
|
|
513
|
+
//# sourceMappingURL=site-context2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-context2.js","names":["result: Record<string, string>","resolvers: Record<DetectionMethod, () => Promise<string | null>>","DEFAULT_SITE_DETECTION: Required<DetectionConfig>","DEFAULT_LOCALE_DETECTION: Required<DetectionConfig>","locale: Locale | null","resolvers: Record<DetectionMethod, () => Promise<string | null>>","createContext","siteDetectionConfig: SiteSettings['siteDetectionConfig']","localeDetectionConfig: SiteSettings['localeDetectionConfig']","settings: SiteSettings","siteContextMiddleware: MiddlewareFunction<Response>"],"sources":["../src/site-context/site-context.tsx","../src/site-context/build-url.ts","../src/site-context/utils.ts","../src/site-context/site-detection.ts","../src/site-context/configs.ts","../src/site-context/cookies.ts","../src/site-context/locale-detection.ts","../src/site-context/currency-detection.ts","../src/site-context/middleware.ts"],"sourcesContent":["/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createContext, useContext, useMemo, type PropsWithChildren } from 'react';\nimport type { Locale, Site } from './types';\n\n/**\n * The value provided by {@link SiteProvider} and returned by {@link useSite}.\n */\nexport type SiteContextValue = {\n /**\n * The resolved site configuration object for the current request.\n * Contains the site's supported locales, supported currencies, and default values.\n */\n site: Site;\n\n /**\n * The full locale object from the site's `supportedLocales` list for the current request.\n * Contains structured locale metadata: `id` (e.g. `\"en-GB\"`), optional `alias` (e.g. `\"en\"`),\n * and optional `preferredCurrency`.\n *\n */\n locale: Locale;\n\n /**\n * The current i18next language string (e.g. `\"en-GB\"`, `\"fr-FR\"`).\n * This is the value returned by `i18next.language` and drives which translation\n * namespace is active. Passed as a prop because the SDK has no react-i18next dependency.\n *\n * @see {@link SiteContextValue.locale} for the full locale object from site config.\n */\n language: string;\n\n /**\n * The active currency code for the current session (e.g. `\"USD\"`, `\"GBP\"`).\n * Resolved from the locale's `preferredCurrency`, a currency cookie, or the site's\n * `defaultCurrency`.\n */\n currency: string;\n};\n\nconst SiteContext = createContext<SiteContextValue | undefined>(undefined);\n\n/**\n * Provides the current site context (site, locale, language, currency) to the component tree.\n *\n * Mounted in the template's root.tsx with the resolved values from the\n * loader/middleware. The SDK has no react-i18next dependency, so `language`\n * is passed as a prop from the template.\n */\nexport function SiteProvider({ site, locale, language, currency, children }: PropsWithChildren<SiteContextValue>) {\n const value = useMemo(() => ({ site, locale, language, currency }), [site, locale, language, currency]);\n return <SiteContext.Provider value={value}>{children}</SiteContext.Provider>;\n}\n\n/**\n * React hook to get the current site context.\n * Returns `{ site, locale, language, currency }`.\n * @throws If called outside of a SiteProvider\n */\n// eslint-disable-next-line react-refresh/only-export-components\nexport function useSite(): SiteContextValue {\n const value = useContext(SiteContext);\n if (!value) {\n throw new Error('useSite must be used within a SiteProvider');\n }\n return value;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport type { Url } from '../config/types';\n\n/**\n * Parses search config string into key-value pairs, preserving ':param' placeholders.\n * '?lng=:localeId&site=:siteId' → { lng: ':localeId', site: ':siteId' }\n */\nexport function parseSearchConfig(search: string): Record<string, string> {\n const searchParams = new URLSearchParams(search);\n const result: Record<string, string> = {};\n for (const [key, value] of searchParams) {\n result[key] = value;\n }\n return result;\n}\n\n/**\n * Extracts parameter names from a prefix string.\n * '/:siteId/:localeId' → ['siteId', 'localeId']\n */\nexport function extractPrefixParams(prefix: string): string[] {\n const matches = prefix.match(/:(\\w+)/g);\n return matches ? matches.map((m) => m.slice(1)) : [];\n}\n\n/**\n * Splits a URL string into its component parts.\n * '/product/123?color=red#details' → { pathname: '/product/123', search: 'color=red', hash: '#details' }\n */\nexport function decomposeUrl(url: string): { pathname: string; search: string; hash: string } {\n const hashIdx = url.indexOf('#');\n const hash = hashIdx >= 0 ? url.slice(hashIdx) : '';\n const withoutHash = hashIdx >= 0 ? url.slice(0, hashIdx) : url;\n const searchIdx = withoutHash.indexOf('?');\n const search = searchIdx >= 0 ? withoutHash.slice(searchIdx + 1) : '';\n const pathname = searchIdx >= 0 ? withoutHash.slice(0, searchIdx) : withoutHash;\n return { pathname, search, hash };\n}\n\n/**\n * Resolves a prefix template by replacing parameter placeholders with values.\n * ('/:siteId/:localeId', { siteId: 'global', localeId: 'en-GB' }) → '/global/en-GB'\n */\nexport function resolvePrefix(prefix: string, params: Record<string, string>): string {\n let resolved = prefix;\n for (const paramName of extractPrefixParams(prefix)) {\n const value = params[paramName];\n if (value) {\n resolved = resolved.replace(`:${paramName}`, value);\n }\n }\n return resolved;\n}\n\n/**\n * Strips the URL prefix segments from a pathname based on a prefix pattern.\n * Since all routes are configured with the prefix baked in, segment counting is sufficient.\n *\n * @param pathname - Full pathname (e.g. '/global/en-GB/checkout')\n * @param prefixPattern - URL prefix pattern from config (e.g. '/:siteId/:localeId')\n * @returns Pathname with prefix stripped (e.g. '/checkout'), or original if\n * the pathname has fewer segments than the prefix\n *\n * @example\n * stripPathPrefix('/global/en-GB/checkout', '/:siteId/:localeId') // → '/checkout'\n * stripPathPrefix('/checkout', '/:siteId/:localeId') // → '/checkout' (fewer segments → unchanged)\n * stripPathPrefix('/checkout', '') // → '/checkout' (no prefix configured)\n * stripPathPrefix('/', '/:siteId/:localeId') // → '/'\n */\nexport function stripPathPrefix(pathname: string, prefixPattern: string): string {\n if (!prefixPattern) return pathname;\n\n const prefixSegmentCount = prefixPattern.split('/').filter(Boolean).length;\n const pathSegments = pathname.split('/').filter(Boolean);\n\n if (pathSegments.length <= prefixSegmentCount) {\n return pathSegments.length === prefixSegmentCount ? '/' : pathname;\n }\n\n return `/${pathSegments.slice(prefixSegmentCount).join('/')}`;\n}\n\n/**\n * Sanitize a resolved prefix from a pathname if present.\n * sanitizePrefix('/global/en-GB/product/123', '/global/en-GB') → '/product/123'\n * sanitizePrefix('/product/123', '/global/en-GB') → '/product/123' (no-op)\n */\nexport function sanitizePrefix(pathname: string, pathPrefix: string): string {\n if (!pathPrefix) return pathname;\n if (pathname === pathPrefix) return '';\n if (pathname.startsWith(`${pathPrefix}/`)) return pathname.slice(pathPrefix.length);\n return pathname;\n}\n\n/**\n * Builds a fully-qualified URL with site context prefix and search params.\n *\n * Only keys defined in urlConfig.search are set by site context. Any other query params\n * already present on the `to` URL (including duplicate keys) are preserved as-is.\n * e.g. to='/api/search?refine=color:blue&refine=size:M', search='?lng=:localeId'\n * → '/api/search?refine=color:blue&refine=size:M&lng=en-GB'\n *\n * @example\n * buildUrl({ to: '/product/123', urlConfig: { prefix: '/:siteId', search: '?lng=:localeId' }, params: { siteId: 'global', localeId: 'en-GB' } })\n * // → '/global/product/123?lng=en-GB'\n */\nexport function buildUrl({\n to,\n urlConfig,\n params,\n}: {\n to: string;\n urlConfig?: Url;\n params: Record<string, string>;\n}): string {\n if (!urlConfig) return to;\n if (!to || to === '#' || to.startsWith('http') || to.startsWith('//')) return to;\n\n const { pathname, search: existingSearch, hash } = decomposeUrl(to);\n\n const pathPrefix = urlConfig.prefix && urlConfig.prefix !== '/' ? resolvePrefix(urlConfig.prefix, params) : '';\n // sanitize prefix to make sure there is no prefix duplication at any case\n const path = pathPrefix ? `${pathPrefix}${sanitizePrefix(pathname, pathPrefix)}` : pathname;\n\n const searchParams = new URLSearchParams(existingSearch);\n if (urlConfig.search) {\n const searchConfig = parseSearchConfig(urlConfig.search);\n for (const [queryKey, value] of Object.entries(searchConfig)) {\n if (value.startsWith(':')) {\n const paramValue = params[value.slice(1)];\n if (paramValue) {\n searchParams.set(queryKey, paramValue);\n }\n } else {\n searchParams.set(queryKey, value);\n }\n }\n }\n\n const search = searchParams.toString();\n return `${path}${search ? `?${search}` : ''}${hash}`;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cookie } from 'react-router';\n\n/**\n * Extract a string value from the URL path segment at the given index.\n */\nexport function lookupFromPath(pathname: string, pathIndex: number): string | null {\n const pathSegments = pathname.split('/').filter(Boolean);\n\n if (pathSegments.length <= pathIndex) return null;\n\n return pathSegments[pathIndex];\n}\n\n/**\n * Detect a string value from cookie using the given cookie parser.\n *\n * Returns a promise that resolves to the cookie value.\n */\nexport async function readCookieFromRequest(request: Request, cookie: Cookie): Promise<string | null> {\n const cookies = request.headers.get('Cookie');\n if (!cookies) return null;\n\n const cookieValue = await cookie.parse(cookies);\n return cookieValue;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cookie } from 'react-router';\nimport type { Site, SiteSettings, DetectionMethod } from './types';\nimport { readCookieFromRequest, lookupFromPath } from './utils';\n\n/**\n * Detect site reference from cookie.\n */\nexport async function readSiteFromCookie(request: Request, cookie: Cookie): Promise<string | null> {\n return readCookieFromRequest(request, cookie);\n}\n\n/**\n * Get site object using the site id or alias\n * 1. Check siteIdentifier against each site's alias; if matched, return that site.\n * 2. Else check against each site's id; if matched, return that site.\n * 3. If no match, return null.\n */\nfunction getSiteFromIdOrAlias(siteIdentifier: string | null, sites: Site[]): Site | null {\n if (!siteIdentifier) return null;\n return sites.find((site) => site.alias === siteIdentifier || site.id === siteIdentifier) ?? null;\n}\n\n/**\n * Resolve site using the configured detection order.\n * Returns the first valid site from the first source that yields a valid value.\n */\nexport async function resolveSite(request: Request, settings: SiteSettings): Promise<Site> {\n const { sites, defaultSiteId, siteDetectionConfig, siteCookie } = settings;\n\n const requestUrl = new URL(request.url);\n\n // When a base path is configured (e.g., '/shop'), we need to skip its path segments.\n // React Router handles the base path internally for hooks like useParams or useLocation,\n // but it does not strip it from request.url. The offset is calculated dynamically from\n // the number of segments in the base path as future-proof in case we support multi-segment\n // base paths in the future.\n const basePathOffset = process.env.MRT_ENV_BASE_PATH\n ? process.env.MRT_ENV_BASE_PATH.split('/').filter(Boolean).length\n : 0;\n\n const resolvers: Record<DetectionMethod, () => Promise<string | null>> = {\n path: () =>\n Promise.resolve(\n lookupFromPath(requestUrl.pathname, siteDetectionConfig.lookupFromPathIndex + basePathOffset)\n ),\n querystring: () => Promise.resolve(requestUrl.searchParams.get(siteDetectionConfig.lookupQuerystring)),\n header: () => Promise.resolve(request.headers.get(siteDetectionConfig.lookupHeader)),\n cookie: async () => readSiteFromCookie(request, siteCookie),\n };\n\n for (const method of siteDetectionConfig.order) {\n const siteIdOrAlias = await resolvers[method]?.();\n const resolvedSite = getSiteFromIdOrAlias(siteIdOrAlias, sites);\n if (resolvedSite) return resolvedSite;\n }\n\n // If no site id was found, use the default site id\n const site = getSiteFromIdOrAlias(defaultSiteId, sites);\n\n // If default site id is invalid, throw an error\n if (!site) {\n throw new Error(`Default site ${defaultSiteId} not found.`);\n }\n\n return site;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { DetectionConfig } from './types';\n\nexport const DEFAULT_CURRENCY_COOKIE_NAME = 'currency';\n\n/**\n * Default site detection configuration\n */\nexport const DEFAULT_SITE_DETECTION: Required<DetectionConfig> = {\n order: ['path', 'querystring', 'cookie', 'header'],\n lookupFromPathIndex: 0,\n lookupQuerystring: 'site',\n lookupCookie: 'site_id',\n lookupHeader: 'X-Site-Id',\n caches: ['cookie'],\n};\n\n/**\n * Default locale detection configuration\n */\nexport const DEFAULT_LOCALE_DETECTION: Required<DetectionConfig> = {\n order: ['path', 'querystring', 'cookie', 'header'],\n lookupFromPathIndex: 1,\n lookupQuerystring: 'lng',\n lookupCookie: 'lng',\n lookupHeader: 'Accept-Language',\n caches: ['cookie'],\n};\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createCookie, type Cookie, type CookieOptions } from 'react-router';\n\n/**\n * Cookie options for site context cookies (site and locale)\n */\nexport const COOKIE_OPTIONS = {\n path: '/',\n sameSite: 'lax' as const,\n secure: process.env.NODE_ENV === 'production',\n httpOnly: true,\n};\n\n/**\n * Creates a cookie instance with the given name.\n *\n * @param name - Cookie name\n * @returns Cookie instance configured with site context options\n */\nexport function createSiteContextCookie(name: string, options?: CookieOptions): Cookie {\n return createCookie(name, { ...COOKIE_OPTIONS, ...options });\n}\n\n/**\n * Creates a currency cookie instance with the given name.\n *\n * @param name - Cookie name\n * @returns Cookie instance configured with site context cookie options\n */\nexport function createCurrencyCookie(name: string, options?: CookieOptions): Cookie {\n return createCookie(name, { ...COOKIE_OPTIONS, ...options });\n}\n\n/**\n * WeakMap to pass resolved locale from site context middleware to i18next's findLocale.\n * WeakMap allows garbage collection when requests are done.\n * This is necessary because findLocale() only receives the Request object, not the router context.\n */\nexport const requestToLocaleMap = new WeakMap<Request, string>();\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cookie } from 'react-router';\nimport type { DetectionMethod, Locale, SiteSettings, Site } from './types';\nimport { readCookieFromRequest, lookupFromPath } from './utils';\n\n/**\n * Read locale from cookie.\n */\nexport async function readLocaleFromCookie(request: Request, cookie: Cookie): Promise<string | null> {\n return readCookieFromRequest(request, cookie);\n}\n\n/**\n * Get locale object using the locale id or alias.\n * 1. Check localeIdOrAlias against each locale's alias; if matched, return that locale.\n * 2. Else check against each locale's id; if matched, return that locale.\n * 3. If no match, return null (caller should use defaultLocale).\n *\n * @param localeIdentifier - The locale id or alias to get the locale from. Null is allowed because this may come from\n * extrenal sources such as cookies, headers, or query parameters.\n * @param locales - The list of locales to search through.\n * @returns The locale object if found, otherwise null.\n */\nfunction getLocaleFromIdOrAlias(localeIdentifier: string | undefined | null, locales: Locale[]): Locale | null {\n if (!localeIdentifier) return null;\n return locales.find((locale) => locale.alias === localeIdentifier || locale.id === localeIdentifier) ?? null;\n}\n\n/**\n * Resolve locale using the configured detection order.\n * Returns the first valid locale from the first source that yields a valid value.\n */\nexport async function resolveLocale(request: Request, settings: SiteSettings, site: Site): Promise<Locale> {\n const { defaultLocale, localeDetectionConfig, localeCookie } = settings;\n const { supportedLocales } = site;\n\n let locale: Locale | null = null;\n const requestUrl = new URL(request.url);\n\n // When a base path is configured (e.g., '/shop'), we need to skip its path segments.\n // React Router handles the base path internally for hooks like useParams or useLocation,\n // but it does not strip it from request.url. The offset is calculated dynamically from\n // the number of segments in the base path as future-proof in case we support multi-segment\n // base paths in the future.\n const basePathOffset = process.env.MRT_ENV_BASE_PATH\n ? process.env.MRT_ENV_BASE_PATH.split('/').filter(Boolean).length\n : 0;\n\n const resolvers: Record<DetectionMethod, () => Promise<string | null>> = {\n path: () =>\n Promise.resolve(\n lookupFromPath(requestUrl.pathname, localeDetectionConfig.lookupFromPathIndex + basePathOffset)\n ),\n querystring: () => Promise.resolve(requestUrl.searchParams.get(localeDetectionConfig.lookupQuerystring)),\n header: () => Promise.resolve(request.headers.get(localeDetectionConfig.lookupHeader)),\n cookie: async () => readLocaleFromCookie(request, localeCookie),\n };\n\n for (const method of localeDetectionConfig.order) {\n const localeIdOrAlias = await resolvers[method]?.();\n const resolvedLocale = getLocaleFromIdOrAlias(localeIdOrAlias, supportedLocales);\n if (resolvedLocale) return resolvedLocale;\n }\n\n // If no locale was found, use the default locale\n if (!locale) {\n locale = getLocaleFromIdOrAlias(defaultLocale, supportedLocales);\n }\n\n // If default locale is invalid, throw an error\n if (!locale) {\n throw new Error(\n `Default locale ${defaultLocale} not found in the list of supported locales for site ${site.id}.`\n );\n }\n\n return locale;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Cookie } from 'react-router';\nimport type { Site, Locale } from './types';\nimport { readCookieFromRequest } from './utils';\n\n/**\n * Resolve the currency for the current request.\n *\n * Priority:\n * 1. Cookie (user-selected currency, if valid for this site)\n * 2. Locale's preferred currency (if valid for this site)\n * 3. Site's default currency\n *\n * @param request - Incoming request\n * @param currencyCookie - Cookie instance for reading the currency cookie\n * @param site - Resolved site for this request\n * @param locale - Resolved locale for this request\n * @returns The resolved currency code\n */\nexport async function resolveCurrency(\n request: Request,\n currencyCookie: Cookie,\n site: Site,\n locale: Locale\n): Promise<string> {\n const { supportedCurrencies, defaultCurrency } = site;\n\n if (!supportedCurrencies || supportedCurrencies.length === 0) {\n throw new Error(`Site \"${site.id}\" must have supportedCurrencies configured.`);\n }\n\n // 1. Try cookie\n const cookieValue = await readCookieFromRequest(request, currencyCookie);\n if (typeof cookieValue === 'string' && supportedCurrencies.includes(cookieValue)) {\n return cookieValue;\n }\n\n // 2. Try locale's preferred currency\n if (locale.preferredCurrency && supportedCurrencies.includes(locale.preferredCurrency)) {\n return locale.preferredCurrency;\n }\n\n // 3. Fall back to site default\n return defaultCurrency;\n}\n","/**\n * Copyright 2026 Salesforce, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext, type MiddlewareFunction, type RouterContextProvider } from 'react-router';\nimport { resolveSite } from './site-detection';\nimport type { SiteConfig, SiteContext, SiteSettings, Site, Locale } from './types';\nimport { DEFAULT_SITE_DETECTION, DEFAULT_LOCALE_DETECTION, DEFAULT_CURRENCY_COOKIE_NAME } from './configs';\nimport { createSiteContextCookie, createCurrencyCookie, requestToLocaleMap } from './cookies';\nimport { resolveLocale } from './locale-detection';\nimport { resolveCurrency } from './currency-detection';\n\nexport const siteContext = createContext<SiteContext | null>(null);\n\n/**\n * Resolved site context result from {@link resolveSiteContext}.\n */\nexport type ResolvedSiteContext = {\n site: Site;\n locale: Locale;\n currency: string;\n};\n\n/**\n * Resolve site, locale, and currency from a request in one call.\n *\n * This is the recommended public entry point for site-context resolution.\n * It encapsulates the required resolution order (site → locale → currency)\n * so consumers don't need to manage the dependency chain manually.\n *\n * The individual resolvers (`resolveSite`, `resolveLocale`, `resolveCurrency`)\n * are available as advanced utilities for cases that need fine-grained control.\n *\n * @param request - Incoming HTTP request\n * @param settings - Fully resolved site settings (with detection config and cookies)\n * @returns Resolved site, locale, and currency\n *\n * @example\n * ```typescript\n * const { site, locale, currency } = await resolveSiteContext(request, settings);\n * ```\n */\nexport async function resolveSiteContext(request: Request, settings: SiteSettings): Promise<ResolvedSiteContext> {\n const site = await resolveSite(request, settings);\n const locale = await resolveLocale(request, settings, site);\n const currency = await resolveCurrency(request, settings.currencyCookie, site, locale);\n return { site, locale, currency };\n}\n\ntype MiddlewareArgs = { request: Request; context: Readonly<RouterContextProvider> };\n\n/**\n * Helper function to get site context cookies from router context.\n * Useful in server actions and loaders that need to read/set cookies.\n *\n * @param context - Router context provider\n * @returns Object with siteCookie and localeCookie instances, or null if context not set\n *\n * @example\n * ```typescript\n * export const action: ActionFunction = async ({ request, context }) => {\n * const cookies = getSiteContextCookies(context);\n * if (cookies) {\n * const cookieHeader = await cookies.localeCookie.serialize(locale);\n * // ... use cookieHeader\n * }\n * };\n * ```\n */\nexport function getSiteContextCookies(context: Readonly<RouterContextProvider>) {\n const siteCtx = context.get(siteContext);\n if (!siteCtx) return null;\n return {\n siteCookie: siteCtx.siteCookie,\n localeCookie: siteCtx.localeCookie,\n currencyCookie: siteCtx.currencyCookie,\n };\n}\n\n/**\n * Helper function to determine if cookies should be set based on:\n * 1. Whether caching is enabled for each cookie type\n * 2. Whether the resolved value differs from the existing cookie\n * 3. Whether cookies were already set by actions/loaders in the response\n *\n * @param request - Incoming request\n * @param response - Response from next()\n * @param settings - Site context settings with cookie instances and detection config\n * @param site - Resolved site for this request\n * @param locale - Resolved locale for this request\n * @param currency - Resolved currency for this request\n * @returns Object with shouldSetSiteCookie, shouldSetLocaleCookie, and shouldSetCurrencyCookie booleans\n */\nasync function shouldSetCookies(\n request: Request,\n response: Response,\n settings: SiteSettings,\n site: Site,\n locale: Locale,\n currency: string\n): Promise<{ shouldSetSiteCookie: boolean; shouldSetLocaleCookie: boolean; shouldSetCurrencyCookie: boolean }> {\n const cacheSite = settings.siteDetectionConfig.caches?.includes('cookie');\n const cacheLocale = settings.localeDetectionConfig.caches?.includes('cookie');\n\n // Check if cookies were already set by actions/loaders in the response.\n // If they were, we don't want to override them.\n const responseSetCookies = response.headers.getSetCookie?.() || [];\n const isSettingSiteCookieInResponse = responseSetCookies.some((cookie) =>\n cookie.startsWith(`${settings.siteCookie.name}=`)\n );\n const isSettingLocaleCookieInResponse = responseSetCookies.some((cookie) =>\n cookie.startsWith(`${settings.localeCookie.name}=`)\n );\n const isSettingCurrencyCookieInResponse = responseSetCookies.some((cookie) =>\n cookie.startsWith(`${settings.currencyCookie.name}=`)\n );\n\n const requestCookieHeader = request.headers.get('Cookie');\n const [existingSiteCookie, existingLocaleCookie, existingCurrencyCookie] = await Promise.all([\n settings.siteCookie.parse(requestCookieHeader),\n settings.localeCookie.parse(requestCookieHeader),\n settings.currencyCookie.parse(requestCookieHeader),\n ]);\n\n // Set cookie if: doesn't exist yet OR resolved value differs from existing.\n // Skip if an action/loader already set it in the response.\n return {\n shouldSetSiteCookie: cacheSite && !isSettingSiteCookieInResponse && existingSiteCookie !== site.id,\n shouldSetLocaleCookie: cacheLocale && !isSettingLocaleCookieInResponse && existingLocaleCookie !== locale.id,\n shouldSetCurrencyCookie: !isSettingCurrencyCookieInResponse && existingCurrencyCookie !== currency,\n };\n}\n\n/**\n * Creates a site context middleware that resolves the current site from\n * the request (path, cookie, header, query, or default) and stores the\n * result in the router context.\n *\n * Does not import or read from app config context; the consumer supplies config.\n */\nexport function createSiteContextMiddleware(config: SiteConfig): MiddlewareFunction<Response> {\n // Merge config with defaults so every detection option has a value\n const siteDetectionConfig: SiteSettings['siteDetectionConfig'] = {\n ...DEFAULT_SITE_DETECTION,\n ...config.siteDetectionConfig,\n };\n const localeDetectionConfig: SiteSettings['localeDetectionConfig'] = {\n ...DEFAULT_LOCALE_DETECTION,\n ...config.localeDetectionConfig,\n };\n\n // Create cookies based on configured names and optional cookie options\n const siteCookie = createSiteContextCookie(siteDetectionConfig.lookupCookie, config.cookieOptions);\n const localeCookie = createSiteContextCookie(localeDetectionConfig.lookupCookie, config.cookieOptions);\n const currencyCookie = createCurrencyCookie(\n config.currencyCookieName ?? DEFAULT_CURRENCY_COOKIE_NAME,\n config.cookieOptions\n );\n\n const settings: SiteSettings = {\n ...config,\n siteDetectionConfig,\n localeDetectionConfig,\n siteCookie,\n localeCookie,\n currencyCookie,\n };\n\n const siteContextMiddleware: MiddlewareFunction<Response> = async (\n { request, context }: MiddlewareArgs,\n next: () => Promise<Response>\n ): Promise<Response> => {\n const { site, locale, currency } = await resolveSiteContext(request, settings);\n\n // Store full Site, Locale, Currency, and Cookie objects in context\n context.set(siteContext, {\n site,\n locale,\n currency,\n siteCookie: settings.siteCookie,\n localeCookie: settings.localeCookie,\n currencyCookie: settings.currencyCookie,\n });\n\n // Store locale in a WeakMap so i18next's findLocale can access it\n // This is necessary because findLocale only receives Request and cannot access the router context\n requestToLocaleMap.set(request, locale.id);\n\n const response = await next();\n\n // Determine if cookies should be set.\n // Actions that change currency (or site/locale) set their cookies directly on the response;\n // shouldSetCookies detects those Set-Cookie headers and skips to avoid overriding.\n const { shouldSetSiteCookie, shouldSetLocaleCookie, shouldSetCurrencyCookie } = await shouldSetCookies(\n request,\n response,\n settings,\n site,\n locale,\n currency\n );\n\n // Early return if no cookies need to be set\n if (!shouldSetSiteCookie && !shouldSetLocaleCookie && !shouldSetCurrencyCookie) {\n return response;\n }\n\n const [siteSetCookie, localeSetCookie, currencySetCookie] = await Promise.all([\n shouldSetSiteCookie ? settings.siteCookie.serialize(site.id, { path: '/' }) : Promise.resolve(null),\n shouldSetLocaleCookie ? settings.localeCookie.serialize(locale.id, { path: '/' }) : Promise.resolve(null),\n shouldSetCurrencyCookie ? settings.currencyCookie.serialize(currency) : Promise.resolve(null),\n ]);\n\n if (siteSetCookie) response.headers.append('Set-Cookie', siteSetCookie);\n if (localeSetCookie) response.headers.append('Set-Cookie', localeSetCookie);\n if (currencySetCookie) response.headers.append('Set-Cookie', currencySetCookie);\n\n return response;\n };\n\n return siteContextMiddleware;\n}\n"],"mappings":";;;;;AAqDA,MAAM,cAAc,cAA4C,OAAU;;;;;;;;AAS1E,SAAgB,aAAa,EAAE,MAAM,QAAQ,UAAU,UAAU,YAAiD;CAC9G,MAAM,QAAQ,eAAe;EAAE;EAAM;EAAQ;EAAU;EAAU,GAAG;EAAC;EAAM;EAAQ;EAAU;EAAS,CAAC;AACvG,QAAO,oBAAC,YAAY;EAAgB;EAAQ;GAAgC;;;;;;;AAShF,SAAgB,UAA4B;CACxC,MAAM,QAAQ,WAAW,YAAY;AACrC,KAAI,CAAC,MACD,OAAM,IAAI,MAAM,6CAA6C;AAEjE,QAAO;;;;;;;;;ACzDX,SAAgB,kBAAkB,QAAwC;CACtE,MAAM,eAAe,IAAI,gBAAgB,OAAO;CAChD,MAAMA,SAAiC,EAAE;AACzC,MAAK,MAAM,CAAC,KAAK,UAAU,aACvB,QAAO,OAAO;AAElB,QAAO;;;;;;AAOX,SAAgB,oBAAoB,QAA0B;CAC1D,MAAM,UAAU,OAAO,MAAM,UAAU;AACvC,QAAO,UAAU,QAAQ,KAAK,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE;;;;;;AAOxD,SAAgB,aAAa,KAAiE;CAC1F,MAAM,UAAU,IAAI,QAAQ,IAAI;CAChC,MAAM,OAAO,WAAW,IAAI,IAAI,MAAM,QAAQ,GAAG;CACjD,MAAM,cAAc,WAAW,IAAI,IAAI,MAAM,GAAG,QAAQ,GAAG;CAC3D,MAAM,YAAY,YAAY,QAAQ,IAAI;CAC1C,MAAM,SAAS,aAAa,IAAI,YAAY,MAAM,YAAY,EAAE,GAAG;AAEnE,QAAO;EAAE,UADQ,aAAa,IAAI,YAAY,MAAM,GAAG,UAAU,GAAG;EACjD;EAAQ;EAAM;;;;;;AAOrC,SAAgB,cAAc,QAAgB,QAAwC;CAClF,IAAI,WAAW;AACf,M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