@intlayer/core 9.5.5 → 9.5.7
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 +0 -1
- package/dist/cjs/localization/getLocaleFromRequest.cjs +31 -2
- package/dist/cjs/localization/getLocaleFromRequest.cjs.map +1 -1
- package/dist/cjs/localization/proxyMode.cjs +4 -1
- package/dist/cjs/localization/proxyMode.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/esm/localization/getLocaleFromRequest.mjs +31 -2
- package/dist/esm/localization/getLocaleFromRequest.mjs.map +1 -1
- package/dist/esm/localization/proxyMode.mjs +4 -1
- package/dist/esm/localization/proxyMode.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/localization/getLocaleFromRequest.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +2 -2
- package/dist/types/localization/proxyMode.d.ts +12 -1
- package/dist/types/localization/proxyMode.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -201,7 +201,6 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
|
|
|
201
201
|
<li><a href="https://intlayer.org/doc/environment/astro/vue" rel=''>Vue</a></li>
|
|
202
202
|
<li><a href="https://intlayer.org/doc/environment/astro/svelte" rel=''>Svelte</a></li>
|
|
203
203
|
<li><a href="https://intlayer.org/doc/environment/astro/solid" rel=''>Solid</a></li>
|
|
204
|
-
<li><a href="https://intlayer.org/doc/environment/astro/vanilla" rel=''>Vanilla JS</a></li>
|
|
205
204
|
<li><a href="https://intlayer.org/doc/environment/astro/lit" rel=''>Lit</a></li>
|
|
206
205
|
</ul>
|
|
207
206
|
</li>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_localization_getPrefix = require('./getPrefix.cjs');
|
|
2
3
|
const require_utils_getCookie = require('../utils/getCookie.cjs');
|
|
3
4
|
const require_localization_getLocale = require('./getLocale.cjs');
|
|
4
5
|
const require_localization_getLocaleFromPath = require('./getLocaleFromPath.cjs');
|
|
@@ -6,6 +7,34 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
6
7
|
|
|
7
8
|
//#region src/localization/getLocaleFromRequest.ts
|
|
8
9
|
/**
|
|
10
|
+
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
11
|
+
*/
|
|
12
|
+
const TREE_SHAKE_NO_PREFIX = process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYER_ROUTING_MODE !== "no-prefix";
|
|
13
|
+
/**
|
|
14
|
+
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
15
|
+
*/
|
|
16
|
+
const TREE_SHAKE_SEARCH_PARAMS = process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYER_ROUTING_MODE !== "search-params";
|
|
17
|
+
/**
|
|
18
|
+
* True when the build-time routing mode is known and is not a prefix-based
|
|
19
|
+
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
20
|
+
*/
|
|
21
|
+
const TREE_SHAKE_PREFIX_MODES = process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYER_ROUTING_MODE !== "prefix-all" && process.env.INTLAYER_ROUTING_MODE !== "prefix-no-default";
|
|
22
|
+
/**
|
|
23
|
+
* Locale explicitly carried by the URL, or `undefined` when it carries none.
|
|
24
|
+
*
|
|
25
|
+
* Unlike {@link getLocaleFromPath}, a missing `?locale=` in `search-params`
|
|
26
|
+
* mode is not read as the default locale: the request may still be served
|
|
27
|
+
* without the proxy that appends the param, so the stored locale and
|
|
28
|
+
* `Accept-Language` must get a chance to resolve it.
|
|
29
|
+
*/
|
|
30
|
+
const getExplicitUrlLocale = (url) => {
|
|
31
|
+
if (!TREE_SHAKE_SEARCH_PARAMS && _intlayer_config_built.routing?.mode === "search-params") {
|
|
32
|
+
const localeParam = new URL(url.toString(), "http://localhost").searchParams.get("locale");
|
|
33
|
+
return require_localization_getPrefix.isDeclaredLocale(localeParam) ? localeParam : void 0;
|
|
34
|
+
}
|
|
35
|
+
if (!TREE_SHAKE_PREFIX_MODES) return require_localization_getLocaleFromPath.getLocaleFromPath(url.toString());
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
9
38
|
* Resolves the locale of an incoming Web request.
|
|
10
39
|
*
|
|
11
40
|
* Priority:
|
|
@@ -19,8 +48,8 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
19
48
|
* ```
|
|
20
49
|
*/
|
|
21
50
|
const getLocaleFromRequest = async ({ url, headers }) => {
|
|
22
|
-
if (_intlayer_config_built.routing?.mode !== "no-prefix") {
|
|
23
|
-
const urlLocale =
|
|
51
|
+
if (TREE_SHAKE_NO_PREFIX || _intlayer_config_built.routing?.mode !== "no-prefix") {
|
|
52
|
+
const urlLocale = getExplicitUrlLocale(url);
|
|
24
53
|
if (urlLocale) return urlLocale;
|
|
25
54
|
}
|
|
26
55
|
return require_localization_getLocale.getLocale({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromRequest.cjs","names":["routing","getLocaleFromPath","getLocale","getCookie"],"sources":["../../../src/localization/getLocaleFromRequest.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"getLocaleFromRequest.cjs","names":["routing","isDeclaredLocale","getLocaleFromPath","getLocale","getCookie"],"sources":["../../../src/localization/getLocaleFromRequest.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getCookie } from '../utils/getCookie';\nimport { getLocale } from './getLocale';\nimport { getLocaleFromPath } from './getLocaleFromPath';\nimport { isDeclaredLocale } from './getPrefix';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n */\nconst TREE_SHAKE_NO_PREFIX =\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n */\nconst TREE_SHAKE_SEARCH_PARAMS =\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params';\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n */\nconst TREE_SHAKE_PREFIX_MODES =\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'prefix-all' &&\n process.env.INTLAYER_ROUTING_MODE !== 'prefix-no-default';\n\n/**\n * The part of a Web `Request` (or of a framework request context such as a\n * Remix `RequestContext`) the locale is resolved from.\n */\nexport type LocaleRequest = {\n url: string | URL;\n headers: Headers;\n};\n\n/**\n * Locale explicitly carried by the URL, or `undefined` when it carries none.\n *\n * Unlike {@link getLocaleFromPath}, a missing `?locale=` in `search-params`\n * mode is not read as the default locale: the request may still be served\n * without the proxy that appends the param, so the stored locale and\n * `Accept-Language` must get a chance to resolve it.\n */\nconst getExplicitUrlLocale = (\n url: string | URL\n): DeclaredLocales | undefined => {\n if (!TREE_SHAKE_SEARCH_PARAMS && routing?.mode === 'search-params') {\n const localeParam = new URL(\n url.toString(),\n 'http://localhost'\n ).searchParams.get('locale') as LocalesValues | null;\n\n return isDeclaredLocale(localeParam) ? localeParam : undefined;\n }\n\n if (!TREE_SHAKE_PREFIX_MODES) {\n return getLocaleFromPath(url.toString());\n }\n\n return undefined;\n};\n\n/**\n * Resolves the locale of an incoming Web request.\n *\n * Priority:\n * 1. The URL, in every routing mode but `no-prefix` (path prefix or `?locale=` search param).\n * 2. The locale persisted by the client (cookie or custom header).\n * 3. `Accept-Language` negotiation, falling back to the default locale.\n *\n * @example\n * ```ts\n * const locale = await getLocaleFromRequest(request);\n * ```\n */\nexport const getLocaleFromRequest = async ({\n url,\n headers,\n}: LocaleRequest): Promise<DeclaredLocales> => {\n if (TREE_SHAKE_NO_PREFIX || routing?.mode !== 'no-prefix') {\n const urlLocale = getExplicitUrlLocale(url);\n\n if (urlLocale) return urlLocale;\n }\n\n return getLocale({\n getHeader: (name) => headers.get(name),\n getCookie: (name) => getCookie(name, headers.get('cookie') ?? undefined),\n });\n};\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,uBACJ,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B;;;;AAKxC,MAAM,2BACJ,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B;;;;;AAMxC,MAAM,0BACJ,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,gBACtC,QAAQ,IAAI,0BAA0B;;;;;;;;;AAmBxC,MAAM,wBACJ,QACgC;CAChC,IAAI,CAAC,4BAA4BA,gCAAS,SAAS,iBAAiB;EAClE,MAAM,cAAc,IAAI,IACtB,IAAI,SAAS,GACb,kBACF,CAAC,CAAC,aAAa,IAAI,QAAQ;EAE3B,OAAOC,gDAAiB,WAAW,IAAI,cAAc;CACvD;CAEA,IAAI,CAAC,yBACH,OAAOC,yDAAkB,IAAI,SAAS,CAAC;AAI3C;;;;;;;;;;;;;;AAeA,MAAa,uBAAuB,OAAO,EACzC,KACA,cAC6C;CAC7C,IAAI,wBAAwBF,gCAAS,SAAS,aAAa;EACzD,MAAM,YAAY,qBAAqB,GAAG;EAE1C,IAAI,WAAW,OAAO;CACxB;CAEA,OAAOG,yCAAU;EACf,YAAY,SAAS,QAAQ,IAAI,IAAI;EACrC,YAAY,SAASC,kCAAU,MAAM,QAAQ,IAAI,QAAQ,KAAK,MAAS;CACzE,CAAC;AACH"}
|
|
@@ -73,17 +73,20 @@ const isProxyStorageLocaleEnabled = (proxyMode, isDevServer) => !(proxyMode ===
|
|
|
73
73
|
*
|
|
74
74
|
* @param isStorageLocaleSuppressed - Whether the stored locale is barred from
|
|
75
75
|
* driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.
|
|
76
|
+
* @param purpose - What the running process is, named in the suppression note.
|
|
76
77
|
* @returns An ANSI-coloured, ready-to-log message.
|
|
77
78
|
*
|
|
78
79
|
* @example
|
|
79
80
|
* ```ts
|
|
80
81
|
* formatProxyEnabledMessage(true);
|
|
81
82
|
* // Intlayer proxy enabled - storage redirection disabled for dev purpose
|
|
83
|
+
* formatProxyEnabledMessage(true, 'build');
|
|
84
|
+
* // Intlayer proxy enabled - storage redirection disabled for build purpose
|
|
82
85
|
* formatProxyEnabledMessage(false);
|
|
83
86
|
* // Intlayer proxy enabled
|
|
84
87
|
* ```
|
|
85
88
|
*/
|
|
86
|
-
const formatProxyEnabledMessage = (isStorageLocaleSuppressed) => [`Intlayer proxy ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`, isStorageLocaleSuppressed && (0, _intlayer_config_logger.colorize)(
|
|
89
|
+
const formatProxyEnabledMessage = (isStorageLocaleSuppressed, purpose = "dev") => [`Intlayer proxy ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`, isStorageLocaleSuppressed && (0, _intlayer_config_logger.colorize)(`- storage redirection disabled for ${purpose} purpose`, _intlayer_config_colors.GREY)].filter(Boolean).join(" ");
|
|
87
90
|
|
|
88
91
|
//#endregion
|
|
89
92
|
exports.formatProxyEnabledMessage = formatProxyEnabledMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyMode.cjs","names":["colorize","ANSIColors"],"sources":["../../../src/localization/proxyMode.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\n\n/**\n * Effective mode of the Intlayer locale-routing proxy, resolved from the\n * `routing.enableProxy` configuration option.\n *\n * - `'auto'` — the option was left unset. The proxy is registered, but it stays\n * URL-driven while a development or preview server is serving the app: the\n * stored locale (cookie / header) is not used as a redirect source, so a\n * stale cookie cannot silently pull every navigation to another locale. In\n * production the mode behaves exactly like `'forced'`.\n * - `'forced'` — the option was explicitly set to `true`. Full proxy behaviour\n * in every environment, storage-driven redirects included.\n * - `'disabled'` — the option was explicitly set to `false`. The proxy is not\n * registered at all (Vite) or becomes a pass-through (Next.js).\n */\nexport type ProxyMode = 'auto' | 'forced' | 'disabled';\n\n/**\n * Resolves the effective {@link ProxyMode} from the `routing.enableProxy`\n * configuration value.\n *\n * `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by\n * `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate\n * the branches guarded by the resolved mode. The variable is only emitted for\n * the two explicit states; its absence means `'auto'` and defers to the\n * configuration value read at runtime.\n *\n * @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.\n * @returns The resolved proxy mode.\n *\n * @example\n * ```ts\n * resolveProxyMode(undefined); // 'auto'\n * resolveProxyMode(true); // 'forced'\n * resolveProxyMode(false); // 'disabled'\n * ```\n */\nexport const resolveProxyMode = (enableProxy?: boolean): ProxyMode => {\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'false') return 'disabled';\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'true') return 'forced';\n\n if (enableProxy === false) return 'disabled';\n if (enableProxy === true) return 'forced';\n\n return 'auto';\n};\n\n/**\n * Indicates whether the proxy may use the locale held in storage (cookie or\n * header) as a source when deciding which locale a request resolves to.\n *\n * Auto mode suppresses it on development and preview servers only. Every other\n * combination keeps the stored locale active, which notably preserves the\n * behaviour of `createIntlayerProxyHandler` when it is mounted manually in a\n * production Nitro server.\n *\n * Suppressing the read affects redirect *sources* only — the locale is still\n * persisted onto responses, the URL locale prefix still wins over everything,\n * and `Accept-Language` detection still applies as the fallback.\n *\n * @param proxyMode - The resolved proxy mode.\n * @param isDevServer - Whether a development or preview server is serving the app.\n * @returns `true` when the stored locale may drive locale resolution.\n *\n * @example\n * ```ts\n * isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only\n * isProxyStorageLocaleEnabled('auto', false); // true — production\n * isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in\n * ```\n */\nexport const isProxyStorageLocaleEnabled = (\n proxyMode: ProxyMode,\n isDevServer: boolean\n): boolean => !(proxyMode === 'auto' && isDevServer);\n\n/**\n * Builds the line announcing that a server has mounted the locale-routing\n * proxy.\n *\n * Shared by every integration (Vite plugin, Next.js middleware) so the reported\n * state cannot drift between them: when the stored locale is suppressed the\n * message says so, which would otherwise look like a broken proxy to anyone\n * testing locale switching with a cookie already set.\n *\n * Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto\n * mode only suppresses storage on a dev server, so a mode-based signature would\n * let a production caller — such as the Nitro production handler — announce a\n * suppression that is not actually in effect.\n *\n * @param isStorageLocaleSuppressed - Whether the stored locale is barred from\n * driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.\n * @returns An ANSI-coloured, ready-to-log message.\n *\n * @example\n * ```ts\n * formatProxyEnabledMessage(true);\n * // Intlayer proxy enabled - storage redirection disabled for dev purpose\n * formatProxyEnabledMessage(false);\n * // Intlayer proxy enabled\n * ```\n */\nexport const formatProxyEnabledMessage = (\n isStorageLocaleSuppressed: boolean\n): string =>\n [\n `Intlayer proxy ${colorize('enabled', ANSIColors.GREEN)}`,\n isStorageLocaleSuppressed &&\n colorize(\n
|
|
1
|
+
{"version":3,"file":"proxyMode.cjs","names":["colorize","ANSIColors"],"sources":["../../../src/localization/proxyMode.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\n\n/**\n * Effective mode of the Intlayer locale-routing proxy, resolved from the\n * `routing.enableProxy` configuration option.\n *\n * - `'auto'` — the option was left unset. The proxy is registered, but it stays\n * URL-driven while a development or preview server is serving the app: the\n * stored locale (cookie / header) is not used as a redirect source, so a\n * stale cookie cannot silently pull every navigation to another locale. In\n * production the mode behaves exactly like `'forced'`.\n * - `'forced'` — the option was explicitly set to `true`. Full proxy behaviour\n * in every environment, storage-driven redirects included.\n * - `'disabled'` — the option was explicitly set to `false`. The proxy is not\n * registered at all (Vite) or becomes a pass-through (Next.js).\n */\nexport type ProxyMode = 'auto' | 'forced' | 'disabled';\n\n/**\n * Resolves the effective {@link ProxyMode} from the `routing.enableProxy`\n * configuration value.\n *\n * `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by\n * `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate\n * the branches guarded by the resolved mode. The variable is only emitted for\n * the two explicit states; its absence means `'auto'` and defers to the\n * configuration value read at runtime.\n *\n * @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.\n * @returns The resolved proxy mode.\n *\n * @example\n * ```ts\n * resolveProxyMode(undefined); // 'auto'\n * resolveProxyMode(true); // 'forced'\n * resolveProxyMode(false); // 'disabled'\n * ```\n */\nexport const resolveProxyMode = (enableProxy?: boolean): ProxyMode => {\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'false') return 'disabled';\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'true') return 'forced';\n\n if (enableProxy === false) return 'disabled';\n if (enableProxy === true) return 'forced';\n\n return 'auto';\n};\n\n/**\n * Indicates whether the proxy may use the locale held in storage (cookie or\n * header) as a source when deciding which locale a request resolves to.\n *\n * Auto mode suppresses it on development and preview servers only. Every other\n * combination keeps the stored locale active, which notably preserves the\n * behaviour of `createIntlayerProxyHandler` when it is mounted manually in a\n * production Nitro server.\n *\n * Suppressing the read affects redirect *sources* only — the locale is still\n * persisted onto responses, the URL locale prefix still wins over everything,\n * and `Accept-Language` detection still applies as the fallback.\n *\n * @param proxyMode - The resolved proxy mode.\n * @param isDevServer - Whether a development or preview server is serving the app.\n * @returns `true` when the stored locale may drive locale resolution.\n *\n * @example\n * ```ts\n * isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only\n * isProxyStorageLocaleEnabled('auto', false); // true — production\n * isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in\n * ```\n */\nexport const isProxyStorageLocaleEnabled = (\n proxyMode: ProxyMode,\n isDevServer: boolean\n): boolean => !(proxyMode === 'auto' && isDevServer);\n\n/**\n * Why the stored locale is not driving redirects while a process runs.\n *\n * - `'dev'` — a development or preview server keeps routing URL-driven.\n * - `'build'` — a build only prerenders pages, which are served to every\n * visitor and therefore never read a cookie.\n */\nexport type ProxyStorageSuppressionPurpose = 'dev' | 'build';\n\n/**\n * Builds the line announcing that a server has mounted the locale-routing\n * proxy.\n *\n * Shared by every integration (Vite plugin, Next.js middleware) so the reported\n * state cannot drift between them: when the stored locale is suppressed the\n * message says so, which would otherwise look like a broken proxy to anyone\n * testing locale switching with a cookie already set.\n *\n * Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto\n * mode only suppresses storage on a dev server, so a mode-based signature would\n * let a production caller — such as the Nitro production handler — announce a\n * suppression that is not actually in effect.\n *\n * @param isStorageLocaleSuppressed - Whether the stored locale is barred from\n * driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.\n * @param purpose - What the running process is, named in the suppression note.\n * @returns An ANSI-coloured, ready-to-log message.\n *\n * @example\n * ```ts\n * formatProxyEnabledMessage(true);\n * // Intlayer proxy enabled - storage redirection disabled for dev purpose\n * formatProxyEnabledMessage(true, 'build');\n * // Intlayer proxy enabled - storage redirection disabled for build purpose\n * formatProxyEnabledMessage(false);\n * // Intlayer proxy enabled\n * ```\n */\nexport const formatProxyEnabledMessage = (\n isStorageLocaleSuppressed: boolean,\n purpose: ProxyStorageSuppressionPurpose = 'dev'\n): string =>\n [\n `Intlayer proxy ${colorize('enabled', ANSIColors.GREEN)}`,\n isStorageLocaleSuppressed &&\n colorize(\n `- storage redirection disabled for ${purpose} purpose`,\n ANSIColors.GREY\n ),\n ]\n .filter(Boolean)\n .join(' ');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,oBAAoB,gBAAqC;CACpE,IAAI,QAAQ,IAAI,kCAAkC,SAAS,OAAO;CAClE,IAAI,QAAQ,IAAI,kCAAkC,QAAQ,OAAO;CAEjE,IAAI,gBAAgB,OAAO,OAAO;CAClC,IAAI,gBAAgB,MAAM,OAAO;CAEjC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,+BACX,WACA,gBACY,EAAE,cAAc,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCxC,MAAa,6BACX,2BACA,UAA0C,UAE1C,CACE,sBAAkBA,kCAAS,WAAWC,wBAAW,KAAK,KACtD,iCACED,kCACE,sCAAsC,QAAQ,WAC9CC,wBAAW,IACb,CACJ,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeStorage.cjs","names":["internationalization","routing","resolveExpiresToTimestamp","buildCookieString","getCookie"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { buildCookieString, resolveExpiresToTimestamp } from './cookieExpiry';\nimport { getCookie } from './getCookie';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when cookie storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_COOKIES =\n process.env.INTLAYER_ROUTING_STORAGE_COOKIES === 'false';\n\n/**\n * True when localStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_LOCAL_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_LOCALSTORAGE === 'false';\n\n/**\n * True when sessionStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_SESSION_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE === 'false';\n\n/**\n * True when header storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_HEADERS =\n process.env.INTLAYER_ROUTING_STORAGE_HEADERS === 'false';\n\n// ============================================================================\n// Shared types\n// ============================================================================\n\nexport type CookieBuildAttributes = {\n domain?: string;\n path?: string;\n secure?: boolean;\n httpOnly?: boolean;\n sameSite?: 'strict' | 'lax' | 'none';\n /**\n * Absolute expiry as milliseconds since epoch, ready for `cookieStore.set()`.\n * Already resolved from the normalized `expires` by\n * `resolveExpiresToTimestamp`.\n */\n expires?: number | undefined;\n};\n\n// ============================================================================\n// Client-specific types and functions\n// (cookies via browser APIs, localStorage, sessionStorage — no headers)\n// ============================================================================\n\nexport type LocaleStorageClientOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n};\n\n// cookieStore is part of the experimental Cookie Store API\ndeclare const cookieStore: any;\n\nexport const localeStorageOptions: LocaleStorageClientOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n/**\n * Retrieves the locale from browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not read from headers — use `getLocaleFromStorageServer` for that.\n */\nexport const getLocaleFromStorageClient = (\n options: LocaleStorageClientOptions = localeStorageOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES) {\n for (let i = 0; i < (routing.storage.cookies ?? []).length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies![i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) {\n for (let i = 0; i < (routing.storage.localStorage ?? []).length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage![i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not write to headers — use `setLocaleInStorageServer` for that.\n */\nexport const setLocaleInStorageClient = (\n locale: LocalesValues,\n options?: LocaleStorageClientOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i];\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Client-side locale storage utility.\n * Handles cookies (browser), localStorage and sessionStorage.\n * Does not access headers.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageClient(localeStorageOptions);\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageClient = (options: LocaleStorageClientOptions) => ({\n getLocale: () => getLocaleFromStorageClient(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageClient(locale, options),\n});\n\n// ============================================================================\n// Server-specific types and functions\n// (cookies via injected getter/setter, headers — no localStorage/sessionStorage)\n// ============================================================================\n\nexport type LocaleStorageServerOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from server-side storage mechanisms (cookies, headers).\n * Does not access localStorage or sessionStorage.\n * No browser cookie fallback — the caller must provide `getCookie`.\n */\nexport const getLocaleFromStorageServer = (\n options: LocaleStorageServerOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies[i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in server-side storage mechanisms (cookies, headers).\n * Does not write to localStorage or sessionStorage.\n */\nexport const setLocaleInStorageServer = (\n locale: LocalesValues,\n options?: LocaleStorageServerOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i].name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Server-side locale storage utility.\n * Handles cookies (via injected getter/setter) and headers.\n * Does not access localStorage or sessionStorage.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageServer({\n * getCookie: (name) => req.cookies[name],\n * setCookieStore: (name, value, attrs) => res.cookie(name, value, attrs),\n * getHeader: (name) => req.headers[name],\n * setHeader: (name, value) => res.setHeader(name, value),\n * });\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageServer = (options: LocaleStorageServerOptions) => ({\n getLocale: () => getLocaleFromStorageServer(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageServer(locale, options),\n});\n\n// ============================================================================\n// Deprecated: combined LocaleStorage\n// Use LocaleStorageClient or LocaleStorageServer instead\n// ============================================================================\n\n/**\n * @deprecated Use {@link LocaleStorageClientOptions} or {@link LocaleStorageServerOptions} instead.\n */\nexport type LocaleStorageOptions = LocaleStorageClientOptions &\n LocaleStorageServerOptions;\n\n/**\n * Retrieves the locale from all storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link getLocaleFromStorageClient} (browser) or\n * {@link getLocaleFromStorageServer} (server) instead.\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n const readCookie = (name: string): string | undefined => {\n try {\n const fromOption = options?.getCookie?.(name);\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n // Browser fallback kept for backward compatibility\n return getCookie(name);\n };\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const value = readCookie(routing.storage.cookies[i].name);\n if (isValidLocale(value)) return value;\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && routing.storage.localStorage) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage[i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in all configured storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link setLocaleInStorageClient} (browser) or\n * {@link setLocaleInStorageServer} (server) instead.\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i];\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i].name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in storage based on configuration.\n *\n * @deprecated Use {@link LocaleStorageClient} (browser) or\n * {@link LocaleStorageServer} (server) instead.\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":";;;;;;;;;AAaA,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;;;;AAKnD,MAAM,mCACJ,QAAQ,IAAI,0CAA0C;;;;AAKxD,MAAM,qCACJ,QAAQ,IAAI,4CAA4C;;;;AAK1D,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;AA4CnD,MAAa,uBAAmD;CAC9D,YAAY,SACV,SAAS,OACN,MAAM,GAAG,CAAC,CACV,MAAM,MAAM,EAAE,KAAK,CAAC,CAAC,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC,EAC3C,MAAM,GAAG,CAAC,CAAC;CACjB,mBAAmB,SAAiB,aAAa,QAAQ,IAAI;CAC7D,oBAAoB,SAAiB,eAAe,QAAQ,IAAI;CAChE,iBAAiB;CACjB,iBAAiB,MAAM,OAAO,eAC5B,YAAY,IAAI;EACd;EACA;EACA,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,SAAS,WAAW;EACpB,UAAU,WAAW;CACvB,CAAC;CACH,kBAAkB,OAAO,WAAW;EAElC,SAAS,SAAS;CACpB;CACA,oBAAoB,MAAM,UAAU,eAAe,QAAQ,MAAM,KAAK;CACtE,mBAAmB,MAAM,UAAU,aAAa,QAAQ,MAAM,KAAK;AACrE;;;;;;AAOA,MAAa,8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AQ,QAAQ,WAChB,SAAS,WAET,KAAK,IAAI,IAAI,GAAG,IAAIA,+BAAQ,QAAQ,QAAQ,QAAQ,KAClD,IAAI;EACF,QAAQ,UAAUA,+BAAQ,QAAQ,QAAQ,EAAE,CAAC,MAAM,MAAM;CAC3D,QAAQ,CAAC;AAGf;;;;;;;AAQA,MAAa,iBAAiB,aAAmC;CAC/D,iBAAiB,qBAAqB,OAAO;CAC7C,YAAY,WAA0B,mBAAmB,QAAQ,OAAO;AAC1E"}
|
|
1
|
+
{"version":3,"file":"localeStorage.cjs","names":["internationalization","routing","resolveExpiresToTimestamp","buildCookieString","getCookie"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { buildCookieString, resolveExpiresToTimestamp } from './cookieExpiry';\nimport { getCookie } from './getCookie';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when cookie storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_COOKIES =\n process.env.INTLAYER_ROUTING_STORAGE_COOKIES === 'false';\n\n/**\n * True when localStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_LOCAL_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_LOCALSTORAGE === 'false';\n\n/**\n * True when sessionStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_SESSION_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE === 'false';\n\n/**\n * True when header storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_HEADERS =\n process.env.INTLAYER_ROUTING_STORAGE_HEADERS === 'false';\n\n// ============================================================================\n// Shared types\n// ============================================================================\n\nexport type CookieBuildAttributes = {\n domain?: string;\n path?: string;\n secure?: boolean;\n httpOnly?: boolean;\n sameSite?: 'strict' | 'lax' | 'none';\n /**\n * Absolute expiry as milliseconds since epoch, ready for `cookieStore.set()`.\n * Already resolved from the normalized `expires` by\n * `resolveExpiresToTimestamp`.\n */\n expires?: number | undefined;\n};\n\n// ============================================================================\n// Client-specific types and functions\n// (cookies via browser APIs, localStorage, sessionStorage — no headers)\n// ============================================================================\n\nexport type LocaleStorageClientOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n};\n\n// cookieStore is part of the experimental Cookie Store API\ndeclare const cookieStore: any;\n\nexport const localeStorageOptions: LocaleStorageClientOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n/**\n * Retrieves the locale from browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not read from headers — use `getLocaleFromStorageServer` for that.\n */\nexport const getLocaleFromStorageClient = (\n options: LocaleStorageClientOptions = localeStorageOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES) {\n for (let i = 0; i < (routing.storage.cookies ?? []).length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies![i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) {\n for (let i = 0; i < (routing.storage.localStorage ?? []).length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage![i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not write to headers — use `setLocaleInStorageServer` for that.\n */\nexport const setLocaleInStorageClient = (\n locale: LocalesValues,\n options?: LocaleStorageClientOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i]!;\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Client-side locale storage utility.\n * Handles cookies (browser), localStorage and sessionStorage.\n * Does not access headers.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageClient(localeStorageOptions);\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageClient = (options: LocaleStorageClientOptions) => ({\n getLocale: () => getLocaleFromStorageClient(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageClient(locale, options),\n});\n\n// ============================================================================\n// Server-specific types and functions\n// (cookies via injected getter/setter, headers — no localStorage/sessionStorage)\n// ============================================================================\n\nexport type LocaleStorageServerOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from server-side storage mechanisms (cookies, headers).\n * Does not access localStorage or sessionStorage.\n * No browser cookie fallback — the caller must provide `getCookie`.\n */\nexport const getLocaleFromStorageServer = (\n options: LocaleStorageServerOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies[i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in server-side storage mechanisms (cookies, headers).\n * Does not write to localStorage or sessionStorage.\n */\nexport const setLocaleInStorageServer = (\n locale: LocalesValues,\n options?: LocaleStorageServerOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i]!;\n\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i]!.name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Server-side locale storage utility.\n * Handles cookies (via injected getter/setter) and headers.\n * Does not access localStorage or sessionStorage.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageServer({\n * getCookie: (name) => req.cookies[name],\n * setCookieStore: (name, value, attrs) => res.cookie(name, value, attrs),\n * getHeader: (name) => req.headers[name],\n * setHeader: (name, value) => res.setHeader(name, value),\n * });\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageServer = (options: LocaleStorageServerOptions) => ({\n getLocale: () => getLocaleFromStorageServer(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageServer(locale, options),\n});\n\n// ============================================================================\n// Deprecated: combined LocaleStorage\n// Use LocaleStorageClient or LocaleStorageServer instead\n// ============================================================================\n\n/**\n * @deprecated Use {@link LocaleStorageClientOptions} or {@link LocaleStorageServerOptions} instead.\n */\nexport type LocaleStorageOptions = LocaleStorageClientOptions &\n LocaleStorageServerOptions;\n\n/**\n * Retrieves the locale from all storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link getLocaleFromStorageClient} (browser) or\n * {@link getLocaleFromStorageServer} (server) instead.\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n const readCookie = (name: string): string | undefined => {\n try {\n const fromOption = options?.getCookie?.(name);\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n // Browser fallback kept for backward compatibility\n return getCookie(name);\n };\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const value = readCookie(routing.storage.cookies[i]!.name);\n if (isValidLocale(value)) return value;\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && routing.storage.localStorage) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage[i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in all configured storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link setLocaleInStorageClient} (browser) or\n * {@link setLocaleInStorageServer} (server) instead.\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i]!;\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i]!.name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in storage based on configuration.\n *\n * @deprecated Use {@link LocaleStorageClient} (browser) or\n * {@link LocaleStorageServer} (server) instead.\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":";;;;;;;;;AAaA,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;;;;AAKnD,MAAM,mCACJ,QAAQ,IAAI,0CAA0C;;;;AAKxD,MAAM,qCACJ,QAAQ,IAAI,4CAA4C;;;;AAK1D,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;AA4CnD,MAAa,uBAAmD;CAC9D,YAAY,SACV,SAAS,OACN,MAAM,GAAG,CAAC,CACV,MAAM,MAAM,EAAE,KAAK,CAAC,CAAC,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC,EAC3C,MAAM,GAAG,CAAC,CAAC;CACjB,mBAAmB,SAAiB,aAAa,QAAQ,IAAI;CAC7D,oBAAoB,SAAiB,eAAe,QAAQ,IAAI;CAChE,iBAAiB;CACjB,iBAAiB,MAAM,OAAO,eAC5B,YAAY,IAAI;EACd;EACA;EACA,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,SAAS,WAAW;EACpB,UAAU,WAAW;CACvB,CAAC;CACH,kBAAkB,OAAO,WAAW;EAElC,SAAS,SAAS;CACpB;CACA,oBAAoB,MAAM,UAAU,eAAe,QAAQ,MAAM,KAAK;CACtE,mBAAmB,MAAM,UAAU,aAAa,QAAQ,MAAM,KAAK;AACrE;;;;;;AAOA,MAAa,8BACX,UAAsC,yBACf;CACvB,MAAM,EAAE,YAAYA;CAEpB,IAAI,SAAS,oBAAoB,OAAO,OAAO;CAE/C,MAAM,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IAAI;EACF,QAAQ,UAAUA,+BAAQ,QAAQ,QAAQ,EAAE,CAAE,MAAM,MAAM;CAC5D,QAAQ,CAAC;AAGf;;;;;;;AAQA,MAAa,iBAAiB,aAAmC;CAC/D,iBAAiB,qBAAqB,OAAO;CAC7C,YAAY,WAA0B,mBAAmB,QAAQ,OAAO;AAC1E"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeclaredLocale } from "./getPrefix.mjs";
|
|
1
2
|
import { getCookie } from "../utils/getCookie.mjs";
|
|
2
3
|
import { getLocale } from "./getLocale.mjs";
|
|
3
4
|
import { getLocaleFromPath } from "./getLocaleFromPath.mjs";
|
|
@@ -5,6 +6,34 @@ import { routing } from "@intlayer/config/built";
|
|
|
5
6
|
|
|
6
7
|
//#region src/localization/getLocaleFromRequest.ts
|
|
7
8
|
/**
|
|
9
|
+
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
10
|
+
*/
|
|
11
|
+
const TREE_SHAKE_NO_PREFIX = process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYER_ROUTING_MODE !== "no-prefix";
|
|
12
|
+
/**
|
|
13
|
+
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
14
|
+
*/
|
|
15
|
+
const TREE_SHAKE_SEARCH_PARAMS = process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYER_ROUTING_MODE !== "search-params";
|
|
16
|
+
/**
|
|
17
|
+
* True when the build-time routing mode is known and is not a prefix-based
|
|
18
|
+
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
19
|
+
*/
|
|
20
|
+
const TREE_SHAKE_PREFIX_MODES = process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYER_ROUTING_MODE !== "prefix-all" && process.env.INTLAYER_ROUTING_MODE !== "prefix-no-default";
|
|
21
|
+
/**
|
|
22
|
+
* Locale explicitly carried by the URL, or `undefined` when it carries none.
|
|
23
|
+
*
|
|
24
|
+
* Unlike {@link getLocaleFromPath}, a missing `?locale=` in `search-params`
|
|
25
|
+
* mode is not read as the default locale: the request may still be served
|
|
26
|
+
* without the proxy that appends the param, so the stored locale and
|
|
27
|
+
* `Accept-Language` must get a chance to resolve it.
|
|
28
|
+
*/
|
|
29
|
+
const getExplicitUrlLocale = (url) => {
|
|
30
|
+
if (!TREE_SHAKE_SEARCH_PARAMS && routing?.mode === "search-params") {
|
|
31
|
+
const localeParam = new URL(url.toString(), "http://localhost").searchParams.get("locale");
|
|
32
|
+
return isDeclaredLocale(localeParam) ? localeParam : void 0;
|
|
33
|
+
}
|
|
34
|
+
if (!TREE_SHAKE_PREFIX_MODES) return getLocaleFromPath(url.toString());
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
8
37
|
* Resolves the locale of an incoming Web request.
|
|
9
38
|
*
|
|
10
39
|
* Priority:
|
|
@@ -18,8 +47,8 @@ import { routing } from "@intlayer/config/built";
|
|
|
18
47
|
* ```
|
|
19
48
|
*/
|
|
20
49
|
const getLocaleFromRequest = async ({ url, headers }) => {
|
|
21
|
-
if (routing?.mode !== "no-prefix") {
|
|
22
|
-
const urlLocale =
|
|
50
|
+
if (TREE_SHAKE_NO_PREFIX || routing?.mode !== "no-prefix") {
|
|
51
|
+
const urlLocale = getExplicitUrlLocale(url);
|
|
23
52
|
if (urlLocale) return urlLocale;
|
|
24
53
|
}
|
|
25
54
|
return getLocale({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromRequest.mjs","names":[],"sources":["../../../src/localization/getLocaleFromRequest.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport type {
|
|
1
|
+
{"version":3,"file":"getLocaleFromRequest.mjs","names":[],"sources":["../../../src/localization/getLocaleFromRequest.ts"],"sourcesContent":["import { routing } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getCookie } from '../utils/getCookie';\nimport { getLocale } from './getLocale';\nimport { getLocaleFromPath } from './getLocaleFromPath';\nimport { isDeclaredLocale } from './getPrefix';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n */\nconst TREE_SHAKE_NO_PREFIX =\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n */\nconst TREE_SHAKE_SEARCH_PARAMS =\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params';\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n */\nconst TREE_SHAKE_PREFIX_MODES =\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'prefix-all' &&\n process.env.INTLAYER_ROUTING_MODE !== 'prefix-no-default';\n\n/**\n * The part of a Web `Request` (or of a framework request context such as a\n * Remix `RequestContext`) the locale is resolved from.\n */\nexport type LocaleRequest = {\n url: string | URL;\n headers: Headers;\n};\n\n/**\n * Locale explicitly carried by the URL, or `undefined` when it carries none.\n *\n * Unlike {@link getLocaleFromPath}, a missing `?locale=` in `search-params`\n * mode is not read as the default locale: the request may still be served\n * without the proxy that appends the param, so the stored locale and\n * `Accept-Language` must get a chance to resolve it.\n */\nconst getExplicitUrlLocale = (\n url: string | URL\n): DeclaredLocales | undefined => {\n if (!TREE_SHAKE_SEARCH_PARAMS && routing?.mode === 'search-params') {\n const localeParam = new URL(\n url.toString(),\n 'http://localhost'\n ).searchParams.get('locale') as LocalesValues | null;\n\n return isDeclaredLocale(localeParam) ? localeParam : undefined;\n }\n\n if (!TREE_SHAKE_PREFIX_MODES) {\n return getLocaleFromPath(url.toString());\n }\n\n return undefined;\n};\n\n/**\n * Resolves the locale of an incoming Web request.\n *\n * Priority:\n * 1. The URL, in every routing mode but `no-prefix` (path prefix or `?locale=` search param).\n * 2. The locale persisted by the client (cookie or custom header).\n * 3. `Accept-Language` negotiation, falling back to the default locale.\n *\n * @example\n * ```ts\n * const locale = await getLocaleFromRequest(request);\n * ```\n */\nexport const getLocaleFromRequest = async ({\n url,\n headers,\n}: LocaleRequest): Promise<DeclaredLocales> => {\n if (TREE_SHAKE_NO_PREFIX || routing?.mode !== 'no-prefix') {\n const urlLocale = getExplicitUrlLocale(url);\n\n if (urlLocale) return urlLocale;\n }\n\n return getLocale({\n getHeader: (name) => headers.get(name),\n getCookie: (name) => getCookie(name, headers.get('cookie') ?? undefined),\n });\n};\n"],"mappings":";;;;;;;;;;AAiBA,MAAM,uBACJ,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B;;;;AAKxC,MAAM,2BACJ,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B;;;;;AAMxC,MAAM,0BACJ,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,gBACtC,QAAQ,IAAI,0BAA0B;;;;;;;;;AAmBxC,MAAM,wBACJ,QACgC;CAChC,IAAI,CAAC,4BAA4B,SAAS,SAAS,iBAAiB;EAClE,MAAM,cAAc,IAAI,IACtB,IAAI,SAAS,GACb,kBACF,CAAC,CAAC,aAAa,IAAI,QAAQ;EAE3B,OAAO,iBAAiB,WAAW,IAAI,cAAc;CACvD;CAEA,IAAI,CAAC,yBACH,OAAO,kBAAkB,IAAI,SAAS,CAAC;AAI3C;;;;;;;;;;;;;;AAeA,MAAa,uBAAuB,OAAO,EACzC,KACA,cAC6C;CAC7C,IAAI,wBAAwB,SAAS,SAAS,aAAa;EACzD,MAAM,YAAY,qBAAqB,GAAG;EAE1C,IAAI,WAAW,OAAO;CACxB;CAEA,OAAO,UAAU;EACf,YAAY,SAAS,QAAQ,IAAI,IAAI;EACrC,YAAY,SAAS,UAAU,MAAM,QAAQ,IAAI,QAAQ,KAAK,MAAS;CACzE,CAAC;AACH"}
|
|
@@ -70,17 +70,20 @@ const isProxyStorageLocaleEnabled = (proxyMode, isDevServer) => !(proxyMode ===
|
|
|
70
70
|
*
|
|
71
71
|
* @param isStorageLocaleSuppressed - Whether the stored locale is barred from
|
|
72
72
|
* driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.
|
|
73
|
+
* @param purpose - What the running process is, named in the suppression note.
|
|
73
74
|
* @returns An ANSI-coloured, ready-to-log message.
|
|
74
75
|
*
|
|
75
76
|
* @example
|
|
76
77
|
* ```ts
|
|
77
78
|
* formatProxyEnabledMessage(true);
|
|
78
79
|
* // Intlayer proxy enabled - storage redirection disabled for dev purpose
|
|
80
|
+
* formatProxyEnabledMessage(true, 'build');
|
|
81
|
+
* // Intlayer proxy enabled - storage redirection disabled for build purpose
|
|
79
82
|
* formatProxyEnabledMessage(false);
|
|
80
83
|
* // Intlayer proxy enabled
|
|
81
84
|
* ```
|
|
82
85
|
*/
|
|
83
|
-
const formatProxyEnabledMessage = (isStorageLocaleSuppressed) => [`Intlayer proxy ${colorize("enabled", ANSIColors.GREEN)}`, isStorageLocaleSuppressed && colorize(
|
|
86
|
+
const formatProxyEnabledMessage = (isStorageLocaleSuppressed, purpose = "dev") => [`Intlayer proxy ${colorize("enabled", ANSIColors.GREEN)}`, isStorageLocaleSuppressed && colorize(`- storage redirection disabled for ${purpose} purpose`, ANSIColors.GREY)].filter(Boolean).join(" ");
|
|
84
87
|
|
|
85
88
|
//#endregion
|
|
86
89
|
export { formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyMode.mjs","names":[],"sources":["../../../src/localization/proxyMode.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\n\n/**\n * Effective mode of the Intlayer locale-routing proxy, resolved from the\n * `routing.enableProxy` configuration option.\n *\n * - `'auto'` — the option was left unset. The proxy is registered, but it stays\n * URL-driven while a development or preview server is serving the app: the\n * stored locale (cookie / header) is not used as a redirect source, so a\n * stale cookie cannot silently pull every navigation to another locale. In\n * production the mode behaves exactly like `'forced'`.\n * - `'forced'` — the option was explicitly set to `true`. Full proxy behaviour\n * in every environment, storage-driven redirects included.\n * - `'disabled'` — the option was explicitly set to `false`. The proxy is not\n * registered at all (Vite) or becomes a pass-through (Next.js).\n */\nexport type ProxyMode = 'auto' | 'forced' | 'disabled';\n\n/**\n * Resolves the effective {@link ProxyMode} from the `routing.enableProxy`\n * configuration value.\n *\n * `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by\n * `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate\n * the branches guarded by the resolved mode. The variable is only emitted for\n * the two explicit states; its absence means `'auto'` and defers to the\n * configuration value read at runtime.\n *\n * @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.\n * @returns The resolved proxy mode.\n *\n * @example\n * ```ts\n * resolveProxyMode(undefined); // 'auto'\n * resolveProxyMode(true); // 'forced'\n * resolveProxyMode(false); // 'disabled'\n * ```\n */\nexport const resolveProxyMode = (enableProxy?: boolean): ProxyMode => {\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'false') return 'disabled';\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'true') return 'forced';\n\n if (enableProxy === false) return 'disabled';\n if (enableProxy === true) return 'forced';\n\n return 'auto';\n};\n\n/**\n * Indicates whether the proxy may use the locale held in storage (cookie or\n * header) as a source when deciding which locale a request resolves to.\n *\n * Auto mode suppresses it on development and preview servers only. Every other\n * combination keeps the stored locale active, which notably preserves the\n * behaviour of `createIntlayerProxyHandler` when it is mounted manually in a\n * production Nitro server.\n *\n * Suppressing the read affects redirect *sources* only — the locale is still\n * persisted onto responses, the URL locale prefix still wins over everything,\n * and `Accept-Language` detection still applies as the fallback.\n *\n * @param proxyMode - The resolved proxy mode.\n * @param isDevServer - Whether a development or preview server is serving the app.\n * @returns `true` when the stored locale may drive locale resolution.\n *\n * @example\n * ```ts\n * isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only\n * isProxyStorageLocaleEnabled('auto', false); // true — production\n * isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in\n * ```\n */\nexport const isProxyStorageLocaleEnabled = (\n proxyMode: ProxyMode,\n isDevServer: boolean\n): boolean => !(proxyMode === 'auto' && isDevServer);\n\n/**\n * Builds the line announcing that a server has mounted the locale-routing\n * proxy.\n *\n * Shared by every integration (Vite plugin, Next.js middleware) so the reported\n * state cannot drift between them: when the stored locale is suppressed the\n * message says so, which would otherwise look like a broken proxy to anyone\n * testing locale switching with a cookie already set.\n *\n * Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto\n * mode only suppresses storage on a dev server, so a mode-based signature would\n * let a production caller — such as the Nitro production handler — announce a\n * suppression that is not actually in effect.\n *\n * @param isStorageLocaleSuppressed - Whether the stored locale is barred from\n * driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.\n * @returns An ANSI-coloured, ready-to-log message.\n *\n * @example\n * ```ts\n * formatProxyEnabledMessage(true);\n * // Intlayer proxy enabled - storage redirection disabled for dev purpose\n * formatProxyEnabledMessage(false);\n * // Intlayer proxy enabled\n * ```\n */\nexport const formatProxyEnabledMessage = (\n isStorageLocaleSuppressed: boolean\n): string =>\n [\n `Intlayer proxy ${colorize('enabled', ANSIColors.GREEN)}`,\n isStorageLocaleSuppressed &&\n colorize(\n
|
|
1
|
+
{"version":3,"file":"proxyMode.mjs","names":[],"sources":["../../../src/localization/proxyMode.ts"],"sourcesContent":["import * as ANSIColors from '@intlayer/config/colors';\nimport { colorize } from '@intlayer/config/logger';\n\n/**\n * Effective mode of the Intlayer locale-routing proxy, resolved from the\n * `routing.enableProxy` configuration option.\n *\n * - `'auto'` — the option was left unset. The proxy is registered, but it stays\n * URL-driven while a development or preview server is serving the app: the\n * stored locale (cookie / header) is not used as a redirect source, so a\n * stale cookie cannot silently pull every navigation to another locale. In\n * production the mode behaves exactly like `'forced'`.\n * - `'forced'` — the option was explicitly set to `true`. Full proxy behaviour\n * in every environment, storage-driven redirects included.\n * - `'disabled'` — the option was explicitly set to `false`. The proxy is not\n * registered at all (Vite) or becomes a pass-through (Next.js).\n */\nexport type ProxyMode = 'auto' | 'forced' | 'disabled';\n\n/**\n * Resolves the effective {@link ProxyMode} from the `routing.enableProxy`\n * configuration value.\n *\n * `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by\n * `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate\n * the branches guarded by the resolved mode. The variable is only emitted for\n * the two explicit states; its absence means `'auto'` and defers to the\n * configuration value read at runtime.\n *\n * @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.\n * @returns The resolved proxy mode.\n *\n * @example\n * ```ts\n * resolveProxyMode(undefined); // 'auto'\n * resolveProxyMode(true); // 'forced'\n * resolveProxyMode(false); // 'disabled'\n * ```\n */\nexport const resolveProxyMode = (enableProxy?: boolean): ProxyMode => {\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'false') return 'disabled';\n if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === 'true') return 'forced';\n\n if (enableProxy === false) return 'disabled';\n if (enableProxy === true) return 'forced';\n\n return 'auto';\n};\n\n/**\n * Indicates whether the proxy may use the locale held in storage (cookie or\n * header) as a source when deciding which locale a request resolves to.\n *\n * Auto mode suppresses it on development and preview servers only. Every other\n * combination keeps the stored locale active, which notably preserves the\n * behaviour of `createIntlayerProxyHandler` when it is mounted manually in a\n * production Nitro server.\n *\n * Suppressing the read affects redirect *sources* only — the locale is still\n * persisted onto responses, the URL locale prefix still wins over everything,\n * and `Accept-Language` detection still applies as the fallback.\n *\n * @param proxyMode - The resolved proxy mode.\n * @param isDevServer - Whether a development or preview server is serving the app.\n * @returns `true` when the stored locale may drive locale resolution.\n *\n * @example\n * ```ts\n * isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only\n * isProxyStorageLocaleEnabled('auto', false); // true — production\n * isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in\n * ```\n */\nexport const isProxyStorageLocaleEnabled = (\n proxyMode: ProxyMode,\n isDevServer: boolean\n): boolean => !(proxyMode === 'auto' && isDevServer);\n\n/**\n * Why the stored locale is not driving redirects while a process runs.\n *\n * - `'dev'` — a development or preview server keeps routing URL-driven.\n * - `'build'` — a build only prerenders pages, which are served to every\n * visitor and therefore never read a cookie.\n */\nexport type ProxyStorageSuppressionPurpose = 'dev' | 'build';\n\n/**\n * Builds the line announcing that a server has mounted the locale-routing\n * proxy.\n *\n * Shared by every integration (Vite plugin, Next.js middleware) so the reported\n * state cannot drift between them: when the stored locale is suppressed the\n * message says so, which would otherwise look like a broken proxy to anyone\n * testing locale switching with a cookie already set.\n *\n * Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto\n * mode only suppresses storage on a dev server, so a mode-based signature would\n * let a production caller — such as the Nitro production handler — announce a\n * suppression that is not actually in effect.\n *\n * @param isStorageLocaleSuppressed - Whether the stored locale is barred from\n * driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.\n * @param purpose - What the running process is, named in the suppression note.\n * @returns An ANSI-coloured, ready-to-log message.\n *\n * @example\n * ```ts\n * formatProxyEnabledMessage(true);\n * // Intlayer proxy enabled - storage redirection disabled for dev purpose\n * formatProxyEnabledMessage(true, 'build');\n * // Intlayer proxy enabled - storage redirection disabled for build purpose\n * formatProxyEnabledMessage(false);\n * // Intlayer proxy enabled\n * ```\n */\nexport const formatProxyEnabledMessage = (\n isStorageLocaleSuppressed: boolean,\n purpose: ProxyStorageSuppressionPurpose = 'dev'\n): string =>\n [\n `Intlayer proxy ${colorize('enabled', ANSIColors.GREEN)}`,\n isStorageLocaleSuppressed &&\n colorize(\n `- storage redirection disabled for ${purpose} purpose`,\n ANSIColors.GREY\n ),\n ]\n .filter(Boolean)\n .join(' ');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,oBAAoB,gBAAqC;CACpE,IAAI,QAAQ,IAAI,kCAAkC,SAAS,OAAO;CAClE,IAAI,QAAQ,IAAI,kCAAkC,QAAQ,OAAO;CAEjE,IAAI,gBAAgB,OAAO,OAAO;CAClC,IAAI,gBAAgB,MAAM,OAAO;CAEjC,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,+BACX,WACA,gBACY,EAAE,cAAc,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCxC,MAAa,6BACX,2BACA,UAA0C,UAE1C,CACE,kBAAkB,SAAS,WAAW,WAAW,KAAK,KACtD,6BACE,SACE,sCAAsC,QAAQ,WAC9C,WAAW,IACb,CACJ,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeStorage.mjs","names":[],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { buildCookieString, resolveExpiresToTimestamp } from './cookieExpiry';\nimport { getCookie } from './getCookie';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when cookie storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_COOKIES =\n process.env.INTLAYER_ROUTING_STORAGE_COOKIES === 'false';\n\n/**\n * True when localStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_LOCAL_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_LOCALSTORAGE === 'false';\n\n/**\n * True when sessionStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_SESSION_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE === 'false';\n\n/**\n * True when header storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_HEADERS =\n process.env.INTLAYER_ROUTING_STORAGE_HEADERS === 'false';\n\n// ============================================================================\n// Shared types\n// ============================================================================\n\nexport type CookieBuildAttributes = {\n domain?: string;\n path?: string;\n secure?: boolean;\n httpOnly?: boolean;\n sameSite?: 'strict' | 'lax' | 'none';\n /**\n * Absolute expiry as milliseconds since epoch, ready for `cookieStore.set()`.\n * Already resolved from the normalized `expires` by\n * `resolveExpiresToTimestamp`.\n */\n expires?: number | undefined;\n};\n\n// ============================================================================\n// Client-specific types and functions\n// (cookies via browser APIs, localStorage, sessionStorage — no headers)\n// ============================================================================\n\nexport type LocaleStorageClientOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n};\n\n// cookieStore is part of the experimental Cookie Store API\ndeclare const cookieStore: any;\n\nexport const localeStorageOptions: LocaleStorageClientOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n/**\n * Retrieves the locale from browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not read from headers — use `getLocaleFromStorageServer` for that.\n */\nexport const getLocaleFromStorageClient = (\n options: LocaleStorageClientOptions = localeStorageOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES) {\n for (let i = 0; i < (routing.storage.cookies ?? []).length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies![i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) {\n for (let i = 0; i < (routing.storage.localStorage ?? []).length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage![i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not write to headers — use `setLocaleInStorageServer` for that.\n */\nexport const setLocaleInStorageClient = (\n locale: LocalesValues,\n options?: LocaleStorageClientOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i];\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Client-side locale storage utility.\n * Handles cookies (browser), localStorage and sessionStorage.\n * Does not access headers.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageClient(localeStorageOptions);\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageClient = (options: LocaleStorageClientOptions) => ({\n getLocale: () => getLocaleFromStorageClient(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageClient(locale, options),\n});\n\n// ============================================================================\n// Server-specific types and functions\n// (cookies via injected getter/setter, headers — no localStorage/sessionStorage)\n// ============================================================================\n\nexport type LocaleStorageServerOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from server-side storage mechanisms (cookies, headers).\n * Does not access localStorage or sessionStorage.\n * No browser cookie fallback — the caller must provide `getCookie`.\n */\nexport const getLocaleFromStorageServer = (\n options: LocaleStorageServerOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies[i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in server-side storage mechanisms (cookies, headers).\n * Does not write to localStorage or sessionStorage.\n */\nexport const setLocaleInStorageServer = (\n locale: LocalesValues,\n options?: LocaleStorageServerOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i].name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Server-side locale storage utility.\n * Handles cookies (via injected getter/setter) and headers.\n * Does not access localStorage or sessionStorage.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageServer({\n * getCookie: (name) => req.cookies[name],\n * setCookieStore: (name, value, attrs) => res.cookie(name, value, attrs),\n * getHeader: (name) => req.headers[name],\n * setHeader: (name, value) => res.setHeader(name, value),\n * });\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageServer = (options: LocaleStorageServerOptions) => ({\n getLocale: () => getLocaleFromStorageServer(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageServer(locale, options),\n});\n\n// ============================================================================\n// Deprecated: combined LocaleStorage\n// Use LocaleStorageClient or LocaleStorageServer instead\n// ============================================================================\n\n/**\n * @deprecated Use {@link LocaleStorageClientOptions} or {@link LocaleStorageServerOptions} instead.\n */\nexport type LocaleStorageOptions = LocaleStorageClientOptions &\n LocaleStorageServerOptions;\n\n/**\n * Retrieves the locale from all storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link getLocaleFromStorageClient} (browser) or\n * {@link getLocaleFromStorageServer} (server) instead.\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n const readCookie = (name: string): string | undefined => {\n try {\n const fromOption = options?.getCookie?.(name);\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n // Browser fallback kept for backward compatibility\n return getCookie(name);\n };\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const value = readCookie(routing.storage.cookies[i].name);\n if (isValidLocale(value)) return value;\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && routing.storage.localStorage) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage[i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i].name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i].name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in all configured storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link setLocaleInStorageClient} (browser) or\n * {@link setLocaleInStorageServer} (server) instead.\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i];\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i];\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i].name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in storage based on configuration.\n *\n * @deprecated Use {@link LocaleStorageClient} (browser) or\n * {@link LocaleStorageServer} (server) instead.\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":";;;;;;;;AAaA,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;;;;AAKnD,MAAM,mCACJ,QAAQ,IAAI,0CAA0C;;;;AAKxD,MAAM,qCACJ,QAAQ,IAAI,4CAA4C;;;;AAK1D,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;AA4CnD,MAAa,uBAAmD;CAC9D,YAAY,SACV,SAAS,OACN,MAAM,GAAG,CAAC,CACV,MAAM,MAAM,EAAE,KAAK,CAAC,CAAC,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC,EAC3C,MAAM,GAAG,CAAC,CAAC;CACjB,mBAAmB,SAAiB,aAAa,QAAQ,IAAI;CAC7D,oBAAoB,SAAiB,eAAe,QAAQ,IAAI;CAChE,iBAAiB;CACjB,iBAAiB,MAAM,OAAO,eAC5B,YAAY,IAAI;EACd;EACA;EACA,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,SAAS,WAAW;EACpB,UAAU,WAAW;CACvB,CAAC;CACH,kBAAkB,OAAO,WAAW;EAElC,SAAS,SAAS;CACpB;CACA,oBAAoB,MAAM,UAAU,eAAe,QAAQ,MAAM,KAAK;CACtE,mBAAmB,MAAM,UAAU,aAAa,QAAQ,MAAM,KAAK;AACrE;;;;;;AAOA,MAAa,8BACX,UAAsC,yBACf;CACvB,MAAM,EAAE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AM;CAC3D,QAAQ,CAAC;AAGf;;;;;;;AAQA,MAAa,iBAAiB,aAAmC;CAC/D,iBAAiB,qBAAqB,OAAO;CAC7C,YAAY,WAA0B,mBAAmB,QAAQ,OAAO;AAC1E"}
|
|
1
|
+
{"version":3,"file":"localeStorage.mjs","names":[],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { buildCookieString, resolveExpiresToTimestamp } from './cookieExpiry';\nimport { getCookie } from './getCookie';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when cookie storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_COOKIES =\n process.env.INTLAYER_ROUTING_STORAGE_COOKIES === 'false';\n\n/**\n * True when localStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_LOCAL_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_LOCALSTORAGE === 'false';\n\n/**\n * True when sessionStorage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_SESSION_STORAGE =\n process.env.INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE === 'false';\n\n/**\n * True when header storage is explicitly disabled at build time.\n */\nconst TREE_SHAKE_STORAGE_HEADERS =\n process.env.INTLAYER_ROUTING_STORAGE_HEADERS === 'false';\n\n// ============================================================================\n// Shared types\n// ============================================================================\n\nexport type CookieBuildAttributes = {\n domain?: string;\n path?: string;\n secure?: boolean;\n httpOnly?: boolean;\n sameSite?: 'strict' | 'lax' | 'none';\n /**\n * Absolute expiry as milliseconds since epoch, ready for `cookieStore.set()`.\n * Already resolved from the normalized `expires` by\n * `resolveExpiresToTimestamp`.\n */\n expires?: number | undefined;\n};\n\n// ============================================================================\n// Client-specific types and functions\n// (cookies via browser APIs, localStorage, sessionStorage — no headers)\n// ============================================================================\n\nexport type LocaleStorageClientOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n};\n\n// cookieStore is part of the experimental Cookie Store API\ndeclare const cookieStore: any;\n\nexport const localeStorageOptions: LocaleStorageClientOptions = {\n getCookie: (name: string) =>\n document.cookie\n .split(';')\n .find((c) => c.trim().startsWith(`${name}=`))\n ?.split('=')[1],\n getLocaleStorage: (name: string) => localStorage.getItem(name),\n getSessionStorage: (name: string) => sessionStorage.getItem(name),\n isCookieEnabled: true,\n setCookieStore: (name, value, attributes) =>\n cookieStore.set({\n name,\n value,\n path: attributes.path,\n domain: attributes.domain,\n expires: attributes.expires,\n sameSite: attributes.sameSite,\n }),\n setCookieString: (_name, cookie) => {\n // biome-ignore lint/suspicious/noDocumentCookie: set cookie fallback\n document.cookie = cookie;\n },\n setSessionStorage: (name, value) => sessionStorage.setItem(name, value),\n setLocaleStorage: (name, value) => localStorage.setItem(name, value),\n};\n\n/**\n * Retrieves the locale from browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not read from headers — use `getLocaleFromStorageServer` for that.\n */\nexport const getLocaleFromStorageClient = (\n options: LocaleStorageClientOptions = localeStorageOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES) {\n for (let i = 0; i < (routing.storage.cookies ?? []).length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies![i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) {\n for (let i = 0; i < (routing.storage.localStorage ?? []).length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage![i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in browser storage mechanisms\n * (cookies, localStorage, sessionStorage).\n * Does not write to headers — use `setLocaleInStorageServer` for that.\n */\nexport const setLocaleInStorageClient = (\n locale: LocalesValues,\n options?: LocaleStorageClientOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i]!;\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Client-side locale storage utility.\n * Handles cookies (browser), localStorage and sessionStorage.\n * Does not access headers.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageClient(localeStorageOptions);\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageClient = (options: LocaleStorageClientOptions) => ({\n getLocale: () => getLocaleFromStorageClient(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageClient(locale, options),\n});\n\n// ============================================================================\n// Server-specific types and functions\n// (cookies via injected getter/setter, headers — no localStorage/sessionStorage)\n// ============================================================================\n\nexport type LocaleStorageServerOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from server-side storage mechanisms (cookies, headers).\n * Does not access localStorage or sessionStorage.\n * No browser cookie fallback — the caller must provide `getCookie`.\n */\nexport const getLocaleFromStorageServer = (\n options: LocaleStorageServerOptions\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n try {\n const value = options?.getCookie?.(routing.storage.cookies[i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in server-side storage mechanisms (cookies, headers).\n * Does not write to localStorage or sessionStorage.\n */\nexport const setLocaleInStorageServer = (\n locale: LocalesValues,\n options?: LocaleStorageServerOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i]!;\n\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i]!.name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Server-side locale storage utility.\n * Handles cookies (via injected getter/setter) and headers.\n * Does not access localStorage or sessionStorage.\n *\n * @example\n * ```ts\n * const storage = LocaleStorageServer({\n * getCookie: (name) => req.cookies[name],\n * setCookieStore: (name, value, attrs) => res.cookie(name, value, attrs),\n * getHeader: (name) => req.headers[name],\n * setHeader: (name, value) => res.setHeader(name, value),\n * });\n * const locale = storage.getLocale();\n * storage.setLocale('fr');\n * ```\n */\nexport const LocaleStorageServer = (options: LocaleStorageServerOptions) => ({\n getLocale: () => getLocaleFromStorageServer(options),\n setLocale: (locale: LocalesValues) =>\n setLocaleInStorageServer(locale, options),\n});\n\n// ============================================================================\n// Deprecated: combined LocaleStorage\n// Use LocaleStorageClient or LocaleStorageServer instead\n// ============================================================================\n\n/**\n * @deprecated Use {@link LocaleStorageClientOptions} or {@link LocaleStorageServerOptions} instead.\n */\nexport type LocaleStorageOptions = LocaleStorageClientOptions &\n LocaleStorageServerOptions;\n\n/**\n * Retrieves the locale from all storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link getLocaleFromStorageClient} (browser) or\n * {@link getLocaleFromStorageServer} (server) instead.\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { locales } = internationalization;\n\n if (options?.isCookieEnabled === false) return undefined;\n\n const isValidLocale = (value: string | null | undefined): value is Locale =>\n !!value && locales.includes(value as Locale);\n\n const readCookie = (name: string): string | undefined => {\n try {\n const fromOption = options?.getCookie?.(name);\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n // Browser fallback kept for backward compatibility\n return getCookie(name);\n };\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const value = readCookie(routing.storage.cookies[i]!.name);\n if (isValidLocale(value)) return value;\n }\n }\n\n if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE && routing.storage.localStorage) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n try {\n const value = options?.getLocaleStorage?.(\n routing.storage.localStorage[i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_SESSION_STORAGE && routing.storage.sessionStorage) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n try {\n const value = options?.getSessionStorage?.(\n routing.storage.sessionStorage[i]!.name\n );\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n\n if (!TREE_SHAKE_STORAGE_HEADERS && routing.storage.headers) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n const value = options?.getHeader?.(routing.storage.headers[i]!.name);\n if (isValidLocale(value)) return value;\n } catch {}\n }\n }\n};\n\n/**\n * Stores the locale in all configured storage mechanisms\n * (cookies, localStorage, sessionStorage, headers).\n *\n * @deprecated Use {@link setLocaleInStorageClient} (browser) or\n * {@link setLocaleInStorageServer} (server) instead.\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n if (options?.isCookieEnabled === false) return;\n\n if (!TREE_SHAKE_STORAGE_COOKIES && routing.storage.cookies) {\n for (let i = 0; i < routing.storage.cookies.length; i++) {\n const { name, attributes } = routing.storage.cookies[i]!;\n try {\n if (options?.setCookieStore) {\n options.setCookieStore(name, locale, {\n ...attributes,\n expires: resolveExpiresToTimestamp(attributes.expires),\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n options.setCookieString(\n name,\n buildCookieString(name, locale, attributes)\n );\n }\n } catch {}\n }\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_LOCAL_STORAGE &&\n routing.storage.localStorage &&\n options?.setLocaleStorage\n ) {\n for (let i = 0; i < routing.storage.localStorage.length; i++) {\n const { name } = routing.storage.localStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getLocaleStorage) {\n if (options.getLocaleStorage(name)) continue;\n }\n options.setLocaleStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_SESSION_STORAGE &&\n routing.storage.sessionStorage &&\n options?.setSessionStorage\n ) {\n for (let i = 0; i < routing.storage.sessionStorage.length; i++) {\n const { name } = routing.storage.sessionStorage[i]!;\n try {\n if (!(options?.overwrite ?? true) && options?.getSessionStorage) {\n if (options.getSessionStorage(name)) continue;\n }\n options.setSessionStorage(name, locale);\n } catch {}\n }\n }\n\n if (\n !TREE_SHAKE_STORAGE_HEADERS &&\n routing.storage.headers &&\n options?.setHeader\n ) {\n for (let i = 0; i < routing.storage.headers.length; i++) {\n try {\n options.setHeader(routing.storage.headers[i]!.name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in storage based on configuration.\n *\n * @deprecated Use {@link LocaleStorageClient} (browser) or\n * {@link LocaleStorageServer} (server) instead.\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":";;;;;;;;AAaA,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;;;;AAKnD,MAAM,mCACJ,QAAQ,IAAI,0CAA0C;;;;AAKxD,MAAM,qCACJ,QAAQ,IAAI,4CAA4C;;;;AAK1D,MAAM,6BACJ,QAAQ,IAAI,qCAAqC;AA4CnD,MAAa,uBAAmD;CAC9D,YAAY,SACV,SAAS,OACN,MAAM,GAAG,CAAC,CACV,MAAM,MAAM,EAAE,KAAK,CAAC,CAAC,WAAW,GAAG,KAAK,EAAE,CAAC,CAAC,EAC3C,MAAM,GAAG,CAAC,CAAC;CACjB,mBAAmB,SAAiB,aAAa,QAAQ,IAAI;CAC7D,oBAAoB,SAAiB,eAAe,QAAQ,IAAI;CAChE,iBAAiB;CACjB,iBAAiB,MAAM,OAAO,eAC5B,YAAY,IAAI;EACd;EACA;EACA,MAAM,WAAW;EACjB,QAAQ,WAAW;EACnB,SAAS,WAAW;EACpB,UAAU,WAAW;CACvB,CAAC;CACH,kBAAkB,OAAO,WAAW;EAElC,SAAS,SAAS;CACpB;CACA,oBAAoB,MAAM,UAAU,eAAe,QAAQ,MAAM,KAAK;CACtE,mBAAmB,MAAM,UAAU,aAAa,QAAQ,MAAM,KAAK;AACrE;;;;;;AAOA,MAAa,8BACX,UAAsC,yBACf;CACvB,MAAM,EAAE,YAAY;CAEpB,IAAI,SAAS,oBAAoB,OAAO,OAAO;CAE/C,MAAM,iBAAiB,UACrB,CAAC,CAAC,SAAS,QAAQ,SAAS,KAAe;CAE7C,IAAI,CAAC,4BACH,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,QAAQ,WAAW,CAAC,EAAC,CAAE,QAAQ,KAC1D,IAAI;EACF,MAAM,QAAQ,SAAS,YAAY,QAAQ,QAAQ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Detector.js";
|
|
97
97
|
import { localeFlatMap, localeMap, localeRecord } from "./localization/localeMapper.js";
|
|
98
98
|
import { localeResolver } from "./localization/localeResolver.js";
|
|
99
|
-
import { ProxyMode, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./localization/proxyMode.js";
|
|
99
|
+
import { ProxyMode, ProxyStorageSuppressionPurpose, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./localization/proxyMode.js";
|
|
100
100
|
import { getPreloadLocale, resolveBrowserLocale } from "./localization/resolveBrowserLocale.js";
|
|
101
101
|
import { getRewriteRules } from "./localization/rewriteMatch.js";
|
|
102
102
|
import { LocalizedPathResult, getInternalPath, getRewritePath, resolveLocalizedPath } from "./localization/rewriteUtils.js";
|
|
@@ -124,4 +124,4 @@ import { CookieBuildAttributes, LocaleStorage, LocaleStorageClient, LocaleStorag
|
|
|
124
124
|
import { YamlRecord, YamlValue, parseYaml } from "./utils/parseYaml.js";
|
|
125
125
|
import { stringifyYaml } from "./utils/stringifyYaml.js";
|
|
126
126
|
import "./utils/index.js";
|
|
127
|
-
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, type BlockQuoteNode, BlockSyntaxProbe, type BoldTextNode, type BreakLineNode, type BreakThematicNode, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CachedIntl, CachedIntl as Intl, type CodeBlockNode, type CodeFencedNode, type CodeInlineNode, type CompileOptions, type ComponentOverrides, ConditionCond, ConditionContent, ConditionContentStates, CookieBuildAttributes, type CustomComponentNode, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, FileCond, type FileContent, type FileContentConstructor, type FootnoteNode, type FootnoteReferenceNode, type GFMTaskNode, GFM_TASK_R, Gender, GenderCond, GenderContent, GenderContentStates, type GenerateSitemapOptions, GetNestingResult, type GetPrefixOptions, type GetPrefixResult, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, type HTMLCommentNode, HTMLContent, HTMLContentConstructor, type HTMLNode, type HTMLSelfClosingNode, type HTMLTag, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_TAGS, type HeadingNode, type HeadingSetextNode, IInterpreterPlugin, IInterpreterPluginState, INLINE_SKIP_R, INTERPOLATION_R, type ImageNode, InsertionCond, InsertionContent, InsertionContentConstructor, InterpolableNode, IntlConstructorName, IsAny, type ItalicTextNode, JsonValue, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListFormatOptions, ListType, type LocaleDomainMap, type LocaleRequest, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, MarkdownReferences, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageFormatter, MessageResolver, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, NestedFieldReferences, type NestedParser, type NewlineNode, NodeProps, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, type OrderedListNode, PARAGRAPH_R, PRELOADED_DYNAMIC_KEY, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, PlainDynamicLoaderMap, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, PreloadableDynamicLoaderMap, PreloadedDynamicEntry, Priority, PriorityValue, type ProxyMode, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, QualifiedDynamicLoaderMap, QualifiedDynamicLoaderTree, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, type ReferenceImageNode, type ReferenceLinkNode, type ReferenceNode, type RenderRuleHook, ResolvedDynamicLoader, type Rule, type RuleOutput, RuleScope, RuleScopeValue, RuleType, RuleTypeValue, type Rules, SCOPE_BLOCK, SCOPE_BOTH, SCOPE_INLINE, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, SelectCond, SelectContent, SelectContentStates, SelectSelector, type SitemapUrlEntry, type StrikethroughTextNode, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, type TableNode, type TableSeparatorNode, TaggedMessageToken, type TextNode, TranslationCond, TranslationContent, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, UnionKeys, type UnorderedListNode, VOID_HTML_ELEMENTS, ValidDotPathsFor, ValueAtKey, WrappedIntl, YamlRecord, YamlValue, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createMessageResolver, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, findPlainDynamicLoader, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryAsync, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDictionaryTransformCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getIntlayerAsync, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromRequest, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPluginsCacheKey, getPlural, getPrefix, getPreloadLocale, getPreloadedDictionary, getReplacedValuesContent, getRewritePath, getRewriteRules, getRuleSet, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isDeclaredLocale, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, readTransformCache, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveBrowserLocale, resolveDictionaryArgument, resolveEffectiveVariantId, resolveLocalizedPath, resolveMessage, resolveMessageNode, resolveMessageNodeToString, resolvePlainDynamicLoader, resolveProviderVariant, resolveProxyMode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, serializeVariantChain, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter, writeTransformCache };
|
|
127
|
+
export { ATTRIBUTES_TO_SANITIZE, ATTRIBUTE_TO_NODE_PROP_MAP, ATTR_EXTRACTOR_R, BLOCKQUOTE_ALERT_R, BLOCKQUOTE_R, BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, BLOCK_END_R, BREAK_LINE_R, BREAK_THEMATIC_R, type BlockQuoteNode, BlockSyntaxProbe, type BoldTextNode, type BreakLineNode, type BreakThematicNode, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CachedIntl, CachedIntl as Intl, type CodeBlockNode, type CodeFencedNode, type CodeInlineNode, type CompileOptions, type ComponentOverrides, ConditionCond, ConditionContent, ConditionContentStates, CookieBuildAttributes, type CustomComponentNode, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, FENCE_DELIMITER_R, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, FileCond, type FileContent, type FileContentConstructor, type FootnoteNode, type FootnoteReferenceNode, type GFMTaskNode, GFM_TASK_R, Gender, GenderCond, GenderContent, GenderContentStates, type GenerateSitemapOptions, GetNestingResult, type GetPrefixOptions, type GetPrefixResult, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, type HTMLCommentNode, HTMLContent, HTMLContentConstructor, type HTMLNode, type HTMLSelfClosingNode, type HTMLTag, HTMLTagsType, HTMLValidationIssue, HTMLValidationResult, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_TAGS, type HeadingNode, type HeadingSetextNode, IInterpreterPlugin, IInterpreterPluginState, INLINE_SKIP_R, INTERPOLATION_R, type ImageNode, InsertionCond, InsertionContent, InsertionContentConstructor, InterpolableNode, IntlConstructorName, IsAny, type ItalicTextNode, JsonValue, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListFormatOptions, ListType, type LocaleDomainMap, type LocaleRequest, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, MarkdownReferences, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageFormatter, MessageResolver, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, NestedFieldReferences, type NestedParser, type NewlineNode, NodeProps, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, type OrderedListNode, PARAGRAPH_R, PRELOADED_DYNAMIC_KEY, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, PlainDynamicLoaderMap, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, PreloadableDynamicLoaderMap, PreloadedDynamicEntry, Priority, PriorityValue, type ProxyMode, type ProxyStorageSuppressionPurpose, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, QualifiedDynamicLoaderMap, QualifiedDynamicLoaderTree, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, type ReferenceImageNode, type ReferenceLinkNode, type ReferenceNode, type RenderRuleHook, ResolvedDynamicLoader, type Rule, type RuleOutput, RuleScope, RuleScopeValue, RuleType, RuleTypeValue, type Rules, SCOPE_BLOCK, SCOPE_BOTH, SCOPE_INLINE, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, SelectCond, SelectContent, SelectContentStates, SelectSelector, type SitemapUrlEntry, type StrikethroughTextNode, TABLE_CENTER_ALIGN, TABLE_LEFT_ALIGN, TABLE_RIGHT_ALIGN, TABLE_TRIM_PIPES, TAB_R, TEXT_BOLD_R, TEXT_EMPHASIZED_R, TEXT_ESCAPED_R, TEXT_MARKED_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, type TableNode, type TableSeparatorNode, TaggedMessageToken, type TextNode, TranslationCond, TranslationContent, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, UnionKeys, type UnorderedListNode, VOID_HTML_ELEMENTS, ValidDotPathsFor, ValueAtKey, WrappedIntl, YamlRecord, YamlValue, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createMessageResolver, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, findPlainDynamicLoader, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryAsync, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDictionaryTransformCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getIntlayerAsync, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromRequest, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNestedDictionaryGraph, getNestedDictionaryKeys, getNestedDictionaryReferences, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPluginsCacheKey, getPlural, getPrefix, getPreloadLocale, getPreloadedDictionary, getReplacedValuesContent, getRewritePath, getRewriteRules, getRuleSet, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isDeclaredLocale, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, isQualifiedDictionaryGroup, isQualifiedDynamicLoaderMap, isSameKeyPath, isValidElement, list, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, localeStorageOptions, markdown as md, mergeDictionaries, mergeQualifiedDictionaries, navigatePath, nesting as nest, nestedPlugin, normalizeAttributeKey, normalizeDictionaries, normalizeDictionary, normalizePath, normalizeWhitespace, number, orderDictionaries, parseBlock, parseCaptureInline, parseDictionarySelector, parseInline, parseMarkdown, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, parseTaggedMessage, parseYaml, parserFor, percentage, plural, pluralPlugin, portableObjectToIntlayerFormatter, presets, qualifies, readTransformCache, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveBrowserLocale, resolveDictionaryArgument, resolveEffectiveVariantId, resolveLocalizedPath, resolveMessage, resolveMessageNode, resolveMessageNodeToString, resolvePlainDynamicLoader, resolveProviderVariant, resolveProxyMode, resolveQualifiedDictionary, resolveQualifiedDynamicContent, resolveQualifiedDynamicContentAsync, sanitizer, select, selectPlugin, serializeVariant, serializeVariantChain, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer, simpleInlineRegex, slugify, some, splitInsertionTemplate, startsWith, stringifyYaml, translation as t, transformInterpolableNode, translationPlugin, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, units, unquote, updateNodeChildren, validateHTML, validateMarkdown, validatePrefix, vueI18nToIntlayerFormatter, writeTransformCache };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocaleFromRequest.d.ts","names":[],"sources":["../../../src/localization/getLocaleFromRequest.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"getLocaleFromRequest.d.ts","names":[],"sources":["../../../src/localization/getLocaleFromRequest.ts"],"mappings":";;;;;;YAyCY;EACV,cAAc;EACd,SAAS;;;;;;;;;;;;;;;qBA2CE,yBAAoB,KAAA,WAG9B,kBAAgB,QAAQ"}
|
|
@@ -17,9 +17,9 @@ import { getPathWithoutLocale } from "./getPathWithoutLocale.js";
|
|
|
17
17
|
import { localeDetector } from "./localeDetector.js";
|
|
18
18
|
import { localeFlatMap, localeMap, localeRecord } from "./localeMapper.js";
|
|
19
19
|
import { localeResolver } from "./localeResolver.js";
|
|
20
|
-
import { ProxyMode, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./proxyMode.js";
|
|
20
|
+
import { ProxyMode, ProxyStorageSuppressionPurpose, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./proxyMode.js";
|
|
21
21
|
import { getPreloadLocale, resolveBrowserLocale } from "./resolveBrowserLocale.js";
|
|
22
22
|
import { getRewriteRules } from "./rewriteMatch.js";
|
|
23
23
|
import { LocalizedPathResult, getInternalPath, getRewritePath, resolveLocalizedPath } from "./rewriteUtils.js";
|
|
24
24
|
import { validatePrefix } from "./validatePrefix.js";
|
|
25
|
-
export { type GenerateSitemapOptions, type GetPrefixOptions, type GetPrefixResult, type LocaleDomainMap, type LocaleRequest, type LocalizedPathResult, type ProxyMode, type SitemapUrlEntry, comparePaths, formatProxyEnabledMessage, generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getDomainHostname, getDomainOrigin, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromRequest, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getPreloadLocale, getRewritePath, getRewriteRules, isDeclaredLocale, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, normalizePath, resolveBrowserLocale, resolveLocalizedPath, resolveProxyMode, validatePrefix };
|
|
25
|
+
export { type GenerateSitemapOptions, type GetPrefixOptions, type GetPrefixResult, type LocaleDomainMap, type LocaleRequest, type LocalizedPathResult, type ProxyMode, type ProxyStorageSuppressionPurpose, type SitemapUrlEntry, comparePaths, formatProxyEnabledMessage, generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getDomainHostname, getDomainOrigin, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromRequest, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getPreloadLocale, getRewritePath, getRewriteRules, isDeclaredLocale, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, normalizePath, resolveBrowserLocale, resolveLocalizedPath, resolveProxyMode, validatePrefix };
|
|
@@ -60,6 +60,14 @@ export declare const resolveProxyMode: (enableProxy?: boolean) => ProxyMode;
|
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
export declare const isProxyStorageLocaleEnabled: (proxyMode: ProxyMode, isDevServer: boolean) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Why the stored locale is not driving redirects while a process runs.
|
|
65
|
+
*
|
|
66
|
+
* - `'dev'` — a development or preview server keeps routing URL-driven.
|
|
67
|
+
* - `'build'` — a build only prerenders pages, which are served to every
|
|
68
|
+
* visitor and therefore never read a cookie.
|
|
69
|
+
*/
|
|
70
|
+
export type ProxyStorageSuppressionPurpose = 'dev' | 'build';
|
|
63
71
|
/**
|
|
64
72
|
* Builds the line announcing that a server has mounted the locale-routing
|
|
65
73
|
* proxy.
|
|
@@ -76,16 +84,19 @@ export declare const isProxyStorageLocaleEnabled: (proxyMode: ProxyMode, isDevSe
|
|
|
76
84
|
*
|
|
77
85
|
* @param isStorageLocaleSuppressed - Whether the stored locale is barred from
|
|
78
86
|
* driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.
|
|
87
|
+
* @param purpose - What the running process is, named in the suppression note.
|
|
79
88
|
* @returns An ANSI-coloured, ready-to-log message.
|
|
80
89
|
*
|
|
81
90
|
* @example
|
|
82
91
|
* ```ts
|
|
83
92
|
* formatProxyEnabledMessage(true);
|
|
84
93
|
* // Intlayer proxy enabled - storage redirection disabled for dev purpose
|
|
94
|
+
* formatProxyEnabledMessage(true, 'build');
|
|
95
|
+
* // Intlayer proxy enabled - storage redirection disabled for build purpose
|
|
85
96
|
* formatProxyEnabledMessage(false);
|
|
86
97
|
* // Intlayer proxy enabled
|
|
87
98
|
* ```
|
|
88
99
|
*/
|
|
89
|
-
export declare const formatProxyEnabledMessage: (isStorageLocaleSuppressed: boolean) => string;
|
|
100
|
+
export declare const formatProxyEnabledMessage: (isStorageLocaleSuppressed: boolean, purpose?: ProxyStorageSuppressionPurpose) => string;
|
|
90
101
|
//#endregion
|
|
91
102
|
//# sourceMappingURL=proxyMode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyMode.d.ts","names":[],"sources":["../../../src/localization/proxyMode.ts"],"mappings":";;;;;;;;;;;;;;;YAiBY;;;;;;;;;;;;;;;;;;;;;qBAsBC,mBAAgB,0BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;qBAkC5C,8BAA2B,WAC3B,WAAS
|
|
1
|
+
{"version":3,"file":"proxyMode.d.ts","names":[],"sources":["../../../src/localization/proxyMode.ts"],"mappings":";;;;;;;;;;;;;;;YAiBY;;;;;;;;;;;;;;;;;;;;;qBAsBC,mBAAgB,0BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;qBAkC5C,8BAA2B,WAC3B,WAAS;;;;;;;;YAWV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA+BC,4BAAyB,oCACF,UACzB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -173,10 +173,10 @@
|
|
|
173
173
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
174
174
|
},
|
|
175
175
|
"dependencies": {
|
|
176
|
-
"@intlayer/api": "9.5.
|
|
177
|
-
"@intlayer/config": "9.5.
|
|
178
|
-
"@intlayer/dictionaries-entry": "9.5.
|
|
179
|
-
"@intlayer/types": "9.5.
|
|
176
|
+
"@intlayer/api": "9.5.6",
|
|
177
|
+
"@intlayer/config": "9.5.6",
|
|
178
|
+
"@intlayer/dictionaries-entry": "9.5.6",
|
|
179
|
+
"@intlayer/types": "9.5.6",
|
|
180
180
|
"defu": "6.1.7"
|
|
181
181
|
},
|
|
182
182
|
"devDependencies": {
|