@intlayer/core 9.1.3 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/localization/index.cjs +4 -0
- package/dist/cjs/localization/proxyMode.cjs +92 -0
- package/dist/cjs/localization/proxyMode.cjs.map +1 -0
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/localization/index.mjs +2 -1
- package/dist/esm/localization/proxyMode.mjs +87 -0
- package/dist/esm/localization/proxyMode.mjs.map +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/localization/index.d.ts +2 -1
- package/dist/types/localization/proxyMode.d.ts +92 -0
- package/dist/types/localization/proxyMode.d.ts.map +1 -0
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -86,6 +86,7 @@ const require_localization_getLocaleFromPath = require('./localization/getLocale
|
|
|
86
86
|
const require_localization_getLocaleLang = require('./localization/getLocaleLang.cjs');
|
|
87
87
|
const require_localization_getLocaleName = require('./localization/getLocaleName.cjs');
|
|
88
88
|
const require_localization_localeMapper = require('./localization/localeMapper.cjs');
|
|
89
|
+
const require_localization_proxyMode = require('./localization/proxyMode.cjs');
|
|
89
90
|
const require_localization_validatePrefix = require('./localization/validatePrefix.cjs');
|
|
90
91
|
const require_markdown_constants = require('./markdown/constants.cjs');
|
|
91
92
|
const require_markdown_utils = require('./markdown/utils.cjs');
|
|
@@ -214,6 +215,7 @@ exports.filePlugin = require_interpreter_getContent_plugins.filePlugin;
|
|
|
214
215
|
exports.filterMissingTranslationsOnlyPlugin = require_deepTransformPlugins_getFilterMissingTranslationsContent.filterMissingTranslationsOnlyPlugin;
|
|
215
216
|
exports.filterTranslationsOnlyPlugin = require_deepTransformPlugins_getFilterTranslationsOnlyContent.filterTranslationsOnlyPlugin;
|
|
216
217
|
exports.findMatchingCondition = require_interpreter_getEnumeration.findMatchingCondition;
|
|
218
|
+
exports.formatProxyEnabledMessage = require_localization_proxyMode.formatProxyEnabledMessage;
|
|
217
219
|
exports.gender = require_transpiler_gender_gender.gender;
|
|
218
220
|
exports.genderPlugin = require_interpreter_getContent_plugins.genderPlugin;
|
|
219
221
|
exports.generateListItemPrefix = require_markdown_constants.generateListItemPrefix;
|
|
@@ -303,6 +305,7 @@ exports.intlayerToPortableObjectFormatter = require_messageFormat_po.intlayerToP
|
|
|
303
305
|
exports.intlayerToVueI18nFormatter = require_messageFormat_vue_i18n.intlayerToVueI18nFormatter;
|
|
304
306
|
exports.isInterpolableWrapperNode = require_interpreter_interpolableNode.isInterpolableWrapperNode;
|
|
305
307
|
exports.isLocaleExclusiveOnDomain = require_localization_domainUtils.isLocaleExclusiveOnDomain;
|
|
308
|
+
exports.isProxyStorageLocaleEnabled = require_localization_proxyMode.isProxyStorageLocaleEnabled;
|
|
306
309
|
exports.isQualifiedDictionaryGroup = require_dictionaryManipulator_qualifiedDictionary.isQualifiedDictionaryGroup;
|
|
307
310
|
exports.isQualifiedDynamicLoaderMap = require_dictionaryManipulator_qualifiedDictionary.isQualifiedDynamicLoaderMap;
|
|
308
311
|
exports.isSameKeyPath = require_utils_isSameKeyPath.isSameKeyPath;
|
|
@@ -359,6 +362,7 @@ exports.resolveDictionaryArgument = require_dictionaryManipulator_qualifiedDicti
|
|
|
359
362
|
exports.resolveMessage = require_messageFormat_resolveMessage.resolveMessage;
|
|
360
363
|
exports.resolveMessageNode = require_messageFormat_resolveMessage.resolveMessageNode;
|
|
361
364
|
exports.resolveProviderVariant = require_dictionaryManipulator_qualifiedDictionary.resolveProviderVariant;
|
|
365
|
+
exports.resolveProxyMode = require_localization_proxyMode.resolveProxyMode;
|
|
362
366
|
exports.resolveQualifiedDictionary = require_dictionaryManipulator_qualifiedDictionary.resolveQualifiedDictionary;
|
|
363
367
|
exports.resolveQualifiedDynamicContent = require_dictionaryManipulator_qualifiedDictionary.resolveQualifiedDynamicContent;
|
|
364
368
|
exports.resolveQualifiedDynamicContentAsync = require_dictionaryManipulator_qualifiedDictionary.resolveQualifiedDynamicContentAsync;
|
|
@@ -16,9 +16,11 @@ const require_localization_getLocaleFromPath = require('./getLocaleFromPath.cjs'
|
|
|
16
16
|
const require_localization_getLocaleLang = require('./getLocaleLang.cjs');
|
|
17
17
|
const require_localization_getLocaleName = require('./getLocaleName.cjs');
|
|
18
18
|
const require_localization_localeMapper = require('./localeMapper.cjs');
|
|
19
|
+
const require_localization_proxyMode = require('./proxyMode.cjs');
|
|
19
20
|
const require_localization_validatePrefix = require('./validatePrefix.cjs');
|
|
20
21
|
|
|
21
22
|
exports.comparePaths = require_localization_comparePaths.comparePaths;
|
|
23
|
+
exports.formatProxyEnabledMessage = require_localization_proxyMode.formatProxyEnabledMessage;
|
|
22
24
|
exports.generateSitemap = require_localization_generateSitemap.generateSitemap;
|
|
23
25
|
exports.generateSitemapUrl = require_localization_generateSitemap.generateSitemapUrl;
|
|
24
26
|
exports.getBrowserLocale = require_localization_getBrowserLocale.getBrowserLocale;
|
|
@@ -40,10 +42,12 @@ exports.getPrefix = require_localization_getPrefix.getPrefix;
|
|
|
40
42
|
exports.getRewritePath = require_localization_rewriteUtils.getRewritePath;
|
|
41
43
|
exports.getRewriteRules = require_localization_rewriteUtils.getRewriteRules;
|
|
42
44
|
exports.isLocaleExclusiveOnDomain = require_localization_domainUtils.isLocaleExclusiveOnDomain;
|
|
45
|
+
exports.isProxyStorageLocaleEnabled = require_localization_proxyMode.isProxyStorageLocaleEnabled;
|
|
43
46
|
exports.localeDetector = require_localization_localeDetector.localeDetector;
|
|
44
47
|
exports.localeFlatMap = require_localization_localeMapper.localeFlatMap;
|
|
45
48
|
exports.localeMap = require_localization_localeMapper.localeMap;
|
|
46
49
|
exports.localeRecord = require_localization_localeMapper.localeRecord;
|
|
47
50
|
exports.localeResolver = require_localization_localeResolver.localeResolver;
|
|
48
51
|
exports.normalizePath = require_localization_comparePaths.normalizePath;
|
|
52
|
+
exports.resolveProxyMode = require_localization_proxyMode.resolveProxyMode;
|
|
49
53
|
exports.validatePrefix = require_localization_validatePrefix.validatePrefix;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
4
|
+
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
5
|
+
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
6
|
+
|
|
7
|
+
//#region src/localization/proxyMode.ts
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the effective {@link ProxyMode} from the `routing.enableProxy`
|
|
10
|
+
* configuration value.
|
|
11
|
+
*
|
|
12
|
+
* `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by
|
|
13
|
+
* `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate
|
|
14
|
+
* the branches guarded by the resolved mode. The variable is only emitted for
|
|
15
|
+
* the two explicit states; its absence means `'auto'` and defers to the
|
|
16
|
+
* configuration value read at runtime.
|
|
17
|
+
*
|
|
18
|
+
* @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.
|
|
19
|
+
* @returns The resolved proxy mode.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* resolveProxyMode(undefined); // 'auto'
|
|
24
|
+
* resolveProxyMode(true); // 'forced'
|
|
25
|
+
* resolveProxyMode(false); // 'disabled'
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const resolveProxyMode = (enableProxy) => {
|
|
29
|
+
if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === "false") return "disabled";
|
|
30
|
+
if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === "true") return "forced";
|
|
31
|
+
if (enableProxy === false) return "disabled";
|
|
32
|
+
if (enableProxy === true) return "forced";
|
|
33
|
+
return "auto";
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Indicates whether the proxy may use the locale held in storage (cookie or
|
|
37
|
+
* header) as a source when deciding which locale a request resolves to.
|
|
38
|
+
*
|
|
39
|
+
* Auto mode suppresses it on development and preview servers only. Every other
|
|
40
|
+
* combination keeps the stored locale active, which notably preserves the
|
|
41
|
+
* behaviour of `createIntlayerProxyHandler` when it is mounted manually in a
|
|
42
|
+
* production Nitro server.
|
|
43
|
+
*
|
|
44
|
+
* Suppressing the read affects redirect *sources* only — the locale is still
|
|
45
|
+
* persisted onto responses, the URL locale prefix still wins over everything,
|
|
46
|
+
* and `Accept-Language` detection still applies as the fallback.
|
|
47
|
+
*
|
|
48
|
+
* @param proxyMode - The resolved proxy mode.
|
|
49
|
+
* @param isDevServer - Whether a development or preview server is serving the app.
|
|
50
|
+
* @returns `true` when the stored locale may drive locale resolution.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only
|
|
55
|
+
* isProxyStorageLocaleEnabled('auto', false); // true — production
|
|
56
|
+
* isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
const isProxyStorageLocaleEnabled = (proxyMode, isDevServer) => !(proxyMode === "auto" && isDevServer);
|
|
60
|
+
/**
|
|
61
|
+
* Builds the line announcing that a server has mounted the locale-routing
|
|
62
|
+
* proxy.
|
|
63
|
+
*
|
|
64
|
+
* Shared by every integration (Vite plugin, Next.js middleware) so the reported
|
|
65
|
+
* state cannot drift between them: when the stored locale is suppressed the
|
|
66
|
+
* message says so, which would otherwise look like a broken proxy to anyone
|
|
67
|
+
* testing locale switching with a cookie already set.
|
|
68
|
+
*
|
|
69
|
+
* Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto
|
|
70
|
+
* mode only suppresses storage on a dev server, so a mode-based signature would
|
|
71
|
+
* let a production caller — such as the Nitro production handler — announce a
|
|
72
|
+
* suppression that is not actually in effect.
|
|
73
|
+
*
|
|
74
|
+
* @param isStorageLocaleSuppressed - Whether the stored locale is barred from
|
|
75
|
+
* driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.
|
|
76
|
+
* @returns An ANSI-coloured, ready-to-log message.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* formatProxyEnabledMessage(true);
|
|
81
|
+
* // Intlayer proxy enabled - storage redirection disabled for dev purpose
|
|
82
|
+
* formatProxyEnabledMessage(false);
|
|
83
|
+
* // Intlayer proxy enabled
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
const formatProxyEnabledMessage = (isStorageLocaleSuppressed) => [`Intlayer proxy ${(0, _intlayer_config_logger.colorize)("enabled", _intlayer_config_colors.GREEN)}`, isStorageLocaleSuppressed && (0, _intlayer_config_logger.colorize)("- storage redirection disabled for dev purpose", _intlayer_config_colors.GREY)].filter(Boolean).join(" ");
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
exports.formatProxyEnabledMessage = formatProxyEnabledMessage;
|
|
90
|
+
exports.isProxyStorageLocaleEnabled = isProxyStorageLocaleEnabled;
|
|
91
|
+
exports.resolveProxyMode = resolveProxyMode;
|
|
92
|
+
//# sourceMappingURL=proxyMode.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxyMode.cjs","names":["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 '- storage redirection disabled for dev 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;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BxC,MAAa,6BACX,8BAEA,CACE,wDAA2B,WAAWA,wBAAW,KAAK,KACtD,mEAEI,kDACAA,wBAAW,IACb,CACJ,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -85,6 +85,7 @@ import { getLocaleFromPath } from "./localization/getLocaleFromPath.mjs";
|
|
|
85
85
|
import { getLocaleLang } from "./localization/getLocaleLang.mjs";
|
|
86
86
|
import { getLocaleName } from "./localization/getLocaleName.mjs";
|
|
87
87
|
import { localeFlatMap, localeMap, localeRecord } from "./localization/localeMapper.mjs";
|
|
88
|
+
import { formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./localization/proxyMode.mjs";
|
|
88
89
|
import { validatePrefix } from "./localization/validatePrefix.mjs";
|
|
89
90
|
import { 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, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, 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_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex } from "./markdown/constants.mjs";
|
|
90
91
|
import { allowInline, anyScopeRegex, attributeValueToNodePropValue, blockRegex, captureNothing, cx, get, inlineRegex, normalizeAttributeKey, normalizeWhitespace, parseBlock, parseCaptureInline, parseInline, parseSimpleInline, parseStyleAttribute, parseTableAlign, parseTableAlignCapture, parseTableCells, parseTableRow, qualifies, renderNothing, sanitizer, simpleInlineRegex, slugify, some, startsWith, trimEnd, trimLeadingWhitespaceOutsideFences, unescapeString, unquote } from "./markdown/utils.mjs";
|
|
@@ -100,4 +101,4 @@ import { interpolateMessage, parseTaggedMessage, resolveMessage, resolveMessageN
|
|
|
100
101
|
import { isSameKeyPath } from "./utils/isSameKeyPath.mjs";
|
|
101
102
|
import { stringifyYaml } from "./utils/stringifyYaml.mjs";
|
|
102
103
|
|
|
103
|
-
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, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, 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_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_HTML_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, 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, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveDictionaryArgument, resolveMessage, resolveMessageNode, resolveProviderVariant, 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 };
|
|
104
|
+
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, CAPTURE_LETTER_AFTER_HYPHEN, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, CODE_INLINE_R, COMPOSITE_ID_SEPARATOR, CONSECUTIVE_NEWLINE_R, CR_NEWLINE_R, CUSTOM_COMPONENT_R, CachedIntl, CachedIntl as Intl, DEFAULT_VARIANT_ID, DO_NOT_PROCESS_HTML_ELEMENTS, DURATION_DELAY_TRIGGER, FOOTNOTE_R, FOOTNOTE_REFERENCE_R, FORMFEED_R, FRONT_MATTER_R, GFM_TASK_R, HEADING_ATX_COMPLIANT_R, HEADING_R, HEADING_SETEXT_R, HTML_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_R, HTML_TAGS, INLINE_SKIP_R, INTERPOLATION_R, LINK_AUTOLINK_BARE_URL_R, LINK_AUTOLINK_R, LIST_LOOKBEHIND_R, LOOKAHEAD, LocaleStorage, LocaleStorageClient, LocaleStorageServer, NAMED_CODES_TO_UNICODE, NP_TABLE_R, ORDERED, ORDERED_LIST_BULLET, ORDERED_LIST_ITEM_PREFIX, ORDERED_LIST_ITEM_PREFIX_R, ORDERED_LIST_ITEM_R, ORDERED_LIST_R, PARAGRAPH_R, Priority, QUALIFIER_DYNAMIC_TYPES_KEY, QUALIFIER_ORDER, REFERENCE_IMAGE_OR_LINK, REFERENCE_IMAGE_R, REFERENCE_LINK_R, RuleType, SHORTCODE_R, SHOULD_RENDER_AS_BLOCK_R, 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_PLAIN_R, TEXT_STRIKETHROUGHED_R, TRIM_STARTING_NEWLINES, UNESCAPE_R, UNORDERED, UNORDERED_LIST_BULLET, UNORDERED_LIST_ITEM_PREFIX, UNORDERED_LIST_ITEM_PREFIX_R, UNORDERED_LIST_ITEM_R, UNORDERED_LIST_R, VOID_HTML_ELEMENTS, allowInline, anyScopeRegex, attributeValueToNodePropValue, bindIntl, blockRegex, buildMaskPlugin, captureNothing, checkIsURLAbsolute, checkMissingLocalesPlugin, compact, comparePaths, compile, compileWithOptions, condition as cond, conditionPlugin, createCompiler, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, 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, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveDictionaryArgument, resolveMessage, resolveMessageNode, 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 };
|
|
@@ -15,6 +15,7 @@ import { getLocaleFromPath } from "./getLocaleFromPath.mjs";
|
|
|
15
15
|
import { getLocaleLang } from "./getLocaleLang.mjs";
|
|
16
16
|
import { getLocaleName } from "./getLocaleName.mjs";
|
|
17
17
|
import { localeFlatMap, localeMap, localeRecord } from "./localeMapper.mjs";
|
|
18
|
+
import { formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./proxyMode.mjs";
|
|
18
19
|
import { validatePrefix } from "./validatePrefix.mjs";
|
|
19
20
|
|
|
20
|
-
export { comparePaths, generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getDomainHostname, getDomainOrigin, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getRewritePath, getRewriteRules, isLocaleExclusiveOnDomain, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, normalizePath, validatePrefix };
|
|
21
|
+
export { comparePaths, formatProxyEnabledMessage, generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getDomainHostname, getDomainOrigin, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getRewritePath, getRewriteRules, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, normalizePath, resolveProxyMode, validatePrefix };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { colorize } from "@intlayer/config/logger";
|
|
2
|
+
import * as ANSIColors from "@intlayer/config/colors";
|
|
3
|
+
|
|
4
|
+
//#region src/localization/proxyMode.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the effective {@link ProxyMode} from the `routing.enableProxy`
|
|
7
|
+
* configuration value.
|
|
8
|
+
*
|
|
9
|
+
* `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by
|
|
10
|
+
* `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate
|
|
11
|
+
* the branches guarded by the resolved mode. The variable is only emitted for
|
|
12
|
+
* the two explicit states; its absence means `'auto'` and defers to the
|
|
13
|
+
* configuration value read at runtime.
|
|
14
|
+
*
|
|
15
|
+
* @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.
|
|
16
|
+
* @returns The resolved proxy mode.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* resolveProxyMode(undefined); // 'auto'
|
|
21
|
+
* resolveProxyMode(true); // 'forced'
|
|
22
|
+
* resolveProxyMode(false); // 'disabled'
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const resolveProxyMode = (enableProxy) => {
|
|
26
|
+
if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === "false") return "disabled";
|
|
27
|
+
if (process.env.INTLAYER_ROUTING_ENABLE_PROXY === "true") return "forced";
|
|
28
|
+
if (enableProxy === false) return "disabled";
|
|
29
|
+
if (enableProxy === true) return "forced";
|
|
30
|
+
return "auto";
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Indicates whether the proxy may use the locale held in storage (cookie or
|
|
34
|
+
* header) as a source when deciding which locale a request resolves to.
|
|
35
|
+
*
|
|
36
|
+
* Auto mode suppresses it on development and preview servers only. Every other
|
|
37
|
+
* combination keeps the stored locale active, which notably preserves the
|
|
38
|
+
* behaviour of `createIntlayerProxyHandler` when it is mounted manually in a
|
|
39
|
+
* production Nitro server.
|
|
40
|
+
*
|
|
41
|
+
* Suppressing the read affects redirect *sources* only — the locale is still
|
|
42
|
+
* persisted onto responses, the URL locale prefix still wins over everything,
|
|
43
|
+
* and `Accept-Language` detection still applies as the fallback.
|
|
44
|
+
*
|
|
45
|
+
* @param proxyMode - The resolved proxy mode.
|
|
46
|
+
* @param isDevServer - Whether a development or preview server is serving the app.
|
|
47
|
+
* @returns `true` when the stored locale may drive locale resolution.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only
|
|
52
|
+
* isProxyStorageLocaleEnabled('auto', false); // true — production
|
|
53
|
+
* isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
const isProxyStorageLocaleEnabled = (proxyMode, isDevServer) => !(proxyMode === "auto" && isDevServer);
|
|
57
|
+
/**
|
|
58
|
+
* Builds the line announcing that a server has mounted the locale-routing
|
|
59
|
+
* proxy.
|
|
60
|
+
*
|
|
61
|
+
* Shared by every integration (Vite plugin, Next.js middleware) so the reported
|
|
62
|
+
* state cannot drift between them: when the stored locale is suppressed the
|
|
63
|
+
* message says so, which would otherwise look like a broken proxy to anyone
|
|
64
|
+
* testing locale switching with a cookie already set.
|
|
65
|
+
*
|
|
66
|
+
* Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto
|
|
67
|
+
* mode only suppresses storage on a dev server, so a mode-based signature would
|
|
68
|
+
* let a production caller — such as the Nitro production handler — announce a
|
|
69
|
+
* suppression that is not actually in effect.
|
|
70
|
+
*
|
|
71
|
+
* @param isStorageLocaleSuppressed - Whether the stored locale is barred from
|
|
72
|
+
* driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.
|
|
73
|
+
* @returns An ANSI-coloured, ready-to-log message.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* formatProxyEnabledMessage(true);
|
|
78
|
+
* // Intlayer proxy enabled - storage redirection disabled for dev purpose
|
|
79
|
+
* formatProxyEnabledMessage(false);
|
|
80
|
+
* // Intlayer proxy enabled
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
const formatProxyEnabledMessage = (isStorageLocaleSuppressed) => [`Intlayer proxy ${colorize("enabled", ANSIColors.GREEN)}`, isStorageLocaleSuppressed && colorize("- storage redirection disabled for dev purpose", ANSIColors.GREY)].filter(Boolean).join(" ");
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode };
|
|
87
|
+
//# sourceMappingURL=proxyMode.mjs.map
|
|
@@ -0,0 +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 '- storage redirection disabled for dev 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;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BxC,MAAa,6BACX,8BAEA,CACE,kBAAkB,SAAS,WAAW,WAAW,KAAK,KACtD,6BACE,SACE,kDACA,WAAW,IACb,CACJ,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ import { getPathWithoutLocale } from "./localization/getPathWithoutLocale.js";
|
|
|
85
85
|
import { localeDetector } from "./localization/localeDetector.js";
|
|
86
86
|
import { localeFlatMap, localeMap, localeRecord } from "./localization/localeMapper.js";
|
|
87
87
|
import { localeResolver } from "./localization/localeResolver.js";
|
|
88
|
+
import { ProxyMode, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./localization/proxyMode.js";
|
|
88
89
|
import { LocalizedPathResult, getCanonicalPath, getInternalPath, getLocalizedPath, getRewritePath, getRewriteRules } from "./localization/rewriteUtils.js";
|
|
89
90
|
import { validatePrefix } from "./localization/validatePrefix.js";
|
|
90
91
|
import "./localization/index.js";
|
|
@@ -110,4 +111,4 @@ import { CookieBuildAttributes, LocaleStorage, LocaleStorageClient, LocaleStorag
|
|
|
110
111
|
import { YamlRecord, YamlValue, parseYaml } from "./utils/parseYaml.js";
|
|
111
112
|
import { stringifyYaml } from "./utils/stringifyYaml.js";
|
|
112
113
|
import "./utils/index.js";
|
|
113
|
-
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, 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, CUSTOM_COMPONENT_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, DURATION_DELAY_TRIGGER, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, 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_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_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, LIST_LOOKBEHIND_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListType, type LocaleDomainMap, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, 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, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, Priority, PriorityValue, 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, type Rule, type RuleOutput, RuleType, RuleTypeValue, type Rules, 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_PLAIN_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, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, isInterpolableWrapperNode, isLocaleExclusiveOnDomain, 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, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveDictionaryArgument, resolveMessage, resolveMessageNode, resolveProviderVariant, 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 };
|
|
114
|
+
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, 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, CUSTOM_COMPONENT_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, DURATION_DELAY_TRIGGER, DateTimePreset, DeepTransformContent, DotPath, DynamicDictionaryLoader, type ElementType, EnterFormat, EnumerationCond, EnumerationContent, EnumerationContentState, type EscapedTextNode, 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_BLOCK_ELEMENT_R, HTML_CHAR_CODE_R, HTML_COMMENT_R, HTML_CUSTOM_ATTR_R, HTML_LEFT_TRIM_AMOUNT_R, HTML_SELF_CLOSING_ELEMENT_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, LIST_LOOKBEHIND_R, LOOKAHEAD, type LinkAngleBraceNode, type LinkBareURLNode, type LinkNode, ListType, type LocaleDomainMap, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, type LocalizedPathResult, MarkdownContent, MarkdownContentConstructor, type MarkdownContext, type MarkdownOptions, type MarkdownRuntime, type HTMLValidationIssue as MarkdownValidationIssue, MarkdownValidationResult, type MarkedTextNode, MessageFormatDialect, MessageValues, NAMED_CODES_TO_UNICODE, NP_TABLE_R, NestedCond, NestedContent, NestedContentState, 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, type ParagraphNode, type ParseState, ParsedMarkdown, type Parser, type ParserResult, Plugins, PluralCategory, PluralCond, PluralContent, PluralContentState, PortableObject, 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, type Rule, type RuleOutput, RuleType, RuleTypeValue, type Rules, 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_PLAIN_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, createRenderer, currency, cx, date, deepTransformNode, editDictionaryByKeyPath, enumeration as enu, enumerationPlugin, fallbackPlugin, type file, type fileContent, filePlugin, filterMissingTranslationsOnlyPlugin, filterTranslationsOnlyPlugin, findMatchingCondition, formatProxyEnabledMessage, gender, genderPlugin, generateListItemPrefix, generateListItemPrefixRegex, generateListItemRegex, generateListRegex, generateSitemap, generateSitemapUrl, get, getBasePlugins, getBrowserLocale, getCachedIntl, getCanonicalPath, getCondition, getContent, getContentNodeByKeyPath, getCookie, getDefaultNode, getDictionary, getDictionaryCompositeIds, getDictionaryQualifierIds, getDictionaryQualifierTypes, getDictionarySelectorCacheKey, getDomainHostname, getDomainOrigin, getEditedContent, getEditedDictionary, getEmptyNode, getEnumeration, getFilterMissingTranslationsContent, getFilterMissingTranslationsDictionary, getFilterTranslationsOnlyContent, getFilterTranslationsOnlyDictionary, getFilteredLocalesContent, getFilteredLocalesDictionary, getGender, getHTML, getHTMLTextDir, getInsertion, getInsertionValues, getInternalPath, getInterpolableContent, getIntlayer, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, getLocaleLang, getLocaleName, getLocalizedContent, getLocalizedPath, getLocalizedUrl, getMarkdownMetadata, getMaskContent, getMissingLocalesContent, getMissingLocalesContentFromDictionary, getMultilingualDictionary, getMultilingualUrls, getNesting, getNodeChildren, getNodeType, getPathWithoutLocale, getPerLocaleDictionary, getPlural, getPrefix, getReplacedValuesContent, getRewritePath, getRewriteRules, getSelect, getSplittedContent, getSplittedDictionaryContent, getTranslation, getVariantIds, html, i18nextToIntlayerFormatter, icuToIntlayerFormatter, inlineRegex, insertion as insert, insertContentInDictionary, insertionPlugin, interpolateMessage, intlayerToI18nextFormatter, intlayerToICUFormatter, intlayerToPortableObjectFormatter, intlayerToVueI18nFormatter, 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, rebuildInterpolableContent, reconstructQualifiedEntry, relativeTime, removeContentNodeByKeyPath, renameContentNodeByKeyPath, renderFor, renderMarkdownAst, renderNothing, resolveDictionaryArgument, resolveMessage, resolveMessageNode, 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 };
|
|
@@ -14,6 +14,7 @@ import { getPathWithoutLocale } from "./getPathWithoutLocale.js";
|
|
|
14
14
|
import { localeDetector } from "./localeDetector.js";
|
|
15
15
|
import { localeFlatMap, localeMap, localeRecord } from "./localeMapper.js";
|
|
16
16
|
import { localeResolver } from "./localeResolver.js";
|
|
17
|
+
import { ProxyMode, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "./proxyMode.js";
|
|
17
18
|
import { LocalizedPathResult, getCanonicalPath, getInternalPath, getLocalizedPath, getRewritePath, getRewriteRules } from "./rewriteUtils.js";
|
|
18
19
|
import { validatePrefix } from "./validatePrefix.js";
|
|
19
|
-
export { type GenerateSitemapOptions, type GetPrefixOptions, type GetPrefixResult, type LocaleDomainMap, type LocalizedPathResult, type SitemapUrlEntry, comparePaths, generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getDomainHostname, getDomainOrigin, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getRewritePath, getRewriteRules, isLocaleExclusiveOnDomain, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, normalizePath, validatePrefix };
|
|
20
|
+
export { type GenerateSitemapOptions, type GetPrefixOptions, type GetPrefixResult, type LocaleDomainMap, type LocalizedPathResult, type ProxyMode, type SitemapUrlEntry, comparePaths, formatProxyEnabledMessage, generateSitemap, generateSitemapUrl, getBrowserLocale, getCanonicalPath, getDomainHostname, getDomainOrigin, getHTMLTextDir, getInternalPath, getLocale, getLocaleFromDomain, getLocaleFromPath, getLocaleLang, getLocaleName, getLocalizedPath, getLocalizedUrl, getMultilingualUrls, getPathWithoutLocale, getPrefix, getRewritePath, getRewriteRules, isLocaleExclusiveOnDomain, isProxyStorageLocaleEnabled, localeDetector, localeFlatMap, localeMap, localeRecord, localeResolver, normalizePath, resolveProxyMode, validatePrefix };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
//#region src/localization/proxyMode.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Effective mode of the Intlayer locale-routing proxy, resolved from the
|
|
4
|
+
* `routing.enableProxy` configuration option.
|
|
5
|
+
*
|
|
6
|
+
* - `'auto'` — the option was left unset. The proxy is registered, but it stays
|
|
7
|
+
* URL-driven while a development or preview server is serving the app: the
|
|
8
|
+
* stored locale (cookie / header) is not used as a redirect source, so a
|
|
9
|
+
* stale cookie cannot silently pull every navigation to another locale. In
|
|
10
|
+
* production the mode behaves exactly like `'forced'`.
|
|
11
|
+
* - `'forced'` — the option was explicitly set to `true`. Full proxy behaviour
|
|
12
|
+
* in every environment, storage-driven redirects included.
|
|
13
|
+
* - `'disabled'` — the option was explicitly set to `false`. The proxy is not
|
|
14
|
+
* registered at all (Vite) or becomes a pass-through (Next.js).
|
|
15
|
+
*/
|
|
16
|
+
type ProxyMode = 'auto' | 'forced' | 'disabled';
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the effective {@link ProxyMode} from the `routing.enableProxy`
|
|
19
|
+
* configuration value.
|
|
20
|
+
*
|
|
21
|
+
* `process.env.INTLAYER_ROUTING_ENABLE_PROXY` is injected at build time by
|
|
22
|
+
* `getConfigEnvVars` and takes precedence, so bundlers can dead-code-eliminate
|
|
23
|
+
* the branches guarded by the resolved mode. The variable is only emitted for
|
|
24
|
+
* the two explicit states; its absence means `'auto'` and defers to the
|
|
25
|
+
* configuration value read at runtime.
|
|
26
|
+
*
|
|
27
|
+
* @param enableProxy - The `routing.enableProxy` value; `undefined` means auto.
|
|
28
|
+
* @returns The resolved proxy mode.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* resolveProxyMode(undefined); // 'auto'
|
|
33
|
+
* resolveProxyMode(true); // 'forced'
|
|
34
|
+
* resolveProxyMode(false); // 'disabled'
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare const resolveProxyMode: (enableProxy?: boolean) => ProxyMode;
|
|
38
|
+
/**
|
|
39
|
+
* Indicates whether the proxy may use the locale held in storage (cookie or
|
|
40
|
+
* header) as a source when deciding which locale a request resolves to.
|
|
41
|
+
*
|
|
42
|
+
* Auto mode suppresses it on development and preview servers only. Every other
|
|
43
|
+
* combination keeps the stored locale active, which notably preserves the
|
|
44
|
+
* behaviour of `createIntlayerProxyHandler` when it is mounted manually in a
|
|
45
|
+
* production Nitro server.
|
|
46
|
+
*
|
|
47
|
+
* Suppressing the read affects redirect *sources* only — the locale is still
|
|
48
|
+
* persisted onto responses, the URL locale prefix still wins over everything,
|
|
49
|
+
* and `Accept-Language` detection still applies as the fallback.
|
|
50
|
+
*
|
|
51
|
+
* @param proxyMode - The resolved proxy mode.
|
|
52
|
+
* @param isDevServer - Whether a development or preview server is serving the app.
|
|
53
|
+
* @returns `true` when the stored locale may drive locale resolution.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* isProxyStorageLocaleEnabled('auto', true); // false — dev server, URL-driven only
|
|
58
|
+
* isProxyStorageLocaleEnabled('auto', false); // true — production
|
|
59
|
+
* isProxyStorageLocaleEnabled('forced', true); // true — explicitly opted in
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const isProxyStorageLocaleEnabled: (proxyMode: ProxyMode, isDevServer: boolean) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Builds the line announcing that a server has mounted the locale-routing
|
|
65
|
+
* proxy.
|
|
66
|
+
*
|
|
67
|
+
* Shared by every integration (Vite plugin, Next.js middleware) so the reported
|
|
68
|
+
* state cannot drift between them: when the stored locale is suppressed the
|
|
69
|
+
* message says so, which would otherwise look like a broken proxy to anyone
|
|
70
|
+
* testing locale switching with a cookie already set.
|
|
71
|
+
*
|
|
72
|
+
* Takes the suppression flag rather than the {@link ProxyMode} on purpose. Auto
|
|
73
|
+
* mode only suppresses storage on a dev server, so a mode-based signature would
|
|
74
|
+
* let a production caller — such as the Nitro production handler — announce a
|
|
75
|
+
* suppression that is not actually in effect.
|
|
76
|
+
*
|
|
77
|
+
* @param isStorageLocaleSuppressed - Whether the stored locale is barred from
|
|
78
|
+
* driving redirects, i.e. the negation of {@link isProxyStorageLocaleEnabled}.
|
|
79
|
+
* @returns An ANSI-coloured, ready-to-log message.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* formatProxyEnabledMessage(true);
|
|
84
|
+
* // Intlayer proxy enabled - storage redirection disabled for dev purpose
|
|
85
|
+
* formatProxyEnabledMessage(false);
|
|
86
|
+
* // Intlayer proxy enabled
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare const formatProxyEnabledMessage: (isStorageLocaleSuppressed: boolean) => string;
|
|
90
|
+
//#endregion
|
|
91
|
+
export { ProxyMode, formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode };
|
|
92
|
+
//# sourceMappingURL=proxyMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxyMode.d.ts","names":[],"sources":["../../../src/localization/proxyMode.ts"],"mappings":";;;;;;;;;;;;;;;KAiBY;;;;;;;;;;;;;;;;;;;;;cAsBC,mBAAgB,0BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;cAkC5C,8BAA2B,WAC3B,WAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BT,4BAAyB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -172,11 +172,11 @@
|
|
|
172
172
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
173
173
|
},
|
|
174
174
|
"dependencies": {
|
|
175
|
-
"@intlayer/api": "9.
|
|
176
|
-
"@intlayer/config": "9.
|
|
177
|
-
"@intlayer/dictionaries-entry": "9.
|
|
178
|
-
"@intlayer/types": "9.
|
|
179
|
-
"@intlayer/unmerged-dictionaries-entry": "9.
|
|
175
|
+
"@intlayer/api": "9.2.0",
|
|
176
|
+
"@intlayer/config": "9.2.0",
|
|
177
|
+
"@intlayer/dictionaries-entry": "9.2.0",
|
|
178
|
+
"@intlayer/types": "9.2.0",
|
|
179
|
+
"@intlayer/unmerged-dictionaries-entry": "9.2.0",
|
|
180
180
|
"defu": "6.1.7"
|
|
181
181
|
},
|
|
182
182
|
"devDependencies": {
|