@intlayer/config 8.6.2 → 8.6.3
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/envVars/envVars.cjs +0 -75
- package/dist/cjs/envVars/envVars.cjs.map +1 -1
- package/dist/cjs/envVars/index.cjs +0 -9
- package/dist/esm/configFile/buildBrowserConfiguration.mjs +2 -2
- package/dist/esm/configFile/buildBrowserConfiguration.mjs.map +1 -1
- package/dist/esm/envVars/envVars.mjs +1 -67
- package/dist/esm/envVars/envVars.mjs.map +1 -1
- package/dist/esm/envVars/index.mjs +2 -2
- package/dist/esm/utils/cacheDisk.mjs +4 -4
- package/dist/esm/utils/cacheDisk.mjs.map +1 -1
- package/dist/types/envVars/envVars.d.ts +1 -67
- package/dist/types/envVars/envVars.d.ts.map +1 -1
- package/dist/types/envVars/index.d.ts +2 -2
- package/package.json +2 -2
|
@@ -2,72 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
//#region src/envVars/envVars.ts
|
|
4
4
|
/**
|
|
5
|
-
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
6
|
-
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* if (!TREE_SHAKE_NO_PREFIX && mode === '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
|
-
* @example
|
|
16
|
-
* if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }
|
|
17
|
-
*/
|
|
18
|
-
const TREE_SHAKE_SEARCH_PARAMS = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params";
|
|
19
|
-
/**
|
|
20
|
-
* True when the build-time routing mode is known and is not a prefix-based
|
|
21
|
-
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }
|
|
25
|
-
*/
|
|
26
|
-
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";
|
|
27
|
-
/**
|
|
28
|
-
* True when rewrite rules are explicitly disabled at build time
|
|
29
|
-
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* if (!TREE_SHAKE_REWRITE && rewrite) { ... }
|
|
33
|
-
*/
|
|
34
|
-
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
35
|
-
/**
|
|
36
|
-
* True when cookie storage is explicitly disabled at build time.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }
|
|
40
|
-
*/
|
|
41
|
-
const TREE_SHAKE_STORAGE_COOKIES = process.env["INTLAYER_ROUTING_STORAGE_COOKIES"] === "false";
|
|
42
|
-
/**
|
|
43
|
-
* True when localStorage is explicitly disabled at build time.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }
|
|
47
|
-
*/
|
|
48
|
-
const TREE_SHAKE_STORAGE_LOCAL_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_LOCALSTORAGE"] === "false";
|
|
49
|
-
/**
|
|
50
|
-
* True when sessionStorage is explicitly disabled at build time.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }
|
|
54
|
-
*/
|
|
55
|
-
const TREE_SHAKE_STORAGE_SESSION_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE"] === "false";
|
|
56
|
-
/**
|
|
57
|
-
* True when header storage is explicitly disabled at build time.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }
|
|
61
|
-
*/
|
|
62
|
-
const TREE_SHAKE_STORAGE_HEADERS = process.env["INTLAYER_ROUTING_STORAGE_HEADERS"] === "false";
|
|
63
|
-
/**
|
|
64
|
-
* True when the editor is explicitly disabled at build time.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* if (!TREE_SHAKE_EDITOR) { // editor logic }
|
|
68
|
-
*/
|
|
69
|
-
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
70
|
-
/**
|
|
71
5
|
* Converts a list of unused NodeType keys into env-var definitions.
|
|
72
6
|
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
73
7
|
*
|
|
@@ -108,15 +42,6 @@ const getConfigEnvVars = (config, addProcessEnv = false) => {
|
|
|
108
42
|
};
|
|
109
43
|
|
|
110
44
|
//#endregion
|
|
111
|
-
exports.TREE_SHAKE_EDITOR = TREE_SHAKE_EDITOR;
|
|
112
|
-
exports.TREE_SHAKE_NO_PREFIX = TREE_SHAKE_NO_PREFIX;
|
|
113
|
-
exports.TREE_SHAKE_PREFIX_MODES = TREE_SHAKE_PREFIX_MODES;
|
|
114
|
-
exports.TREE_SHAKE_REWRITE = TREE_SHAKE_REWRITE;
|
|
115
|
-
exports.TREE_SHAKE_SEARCH_PARAMS = TREE_SHAKE_SEARCH_PARAMS;
|
|
116
|
-
exports.TREE_SHAKE_STORAGE_COOKIES = TREE_SHAKE_STORAGE_COOKIES;
|
|
117
|
-
exports.TREE_SHAKE_STORAGE_HEADERS = TREE_SHAKE_STORAGE_HEADERS;
|
|
118
|
-
exports.TREE_SHAKE_STORAGE_LOCAL_STORAGE = TREE_SHAKE_STORAGE_LOCAL_STORAGE;
|
|
119
|
-
exports.TREE_SHAKE_STORAGE_SESSION_STORAGE = TREE_SHAKE_STORAGE_SESSION_STORAGE;
|
|
120
45
|
exports.formatNodeTypeToEnvVar = formatNodeTypeToEnvVar;
|
|
121
46
|
exports.getConfigEnvVars = getConfigEnvVars;
|
|
122
47
|
//# sourceMappingURL=envVars.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVars.cjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n
|
|
1
|
+
{"version":3,"file":"envVars.cjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Converts a list of unused NodeType keys into env-var definitions.\n * Set to `\"false\"` so bundlers can eliminate the corresponding plugin code.\n *\n * @example\n * formatNodeTypeToEnvVar(['enumeration'])\n * // { 'INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n *\n * formatNodeTypeToEnvVar(['enumeration'], true)\n * // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n addProcessEnv: boolean = false\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[\n addProcessEnv\n ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n ] = '\"false\"';\n return acc;\n },\n {} as Record<string, string>\n );\n\n/**\n * Returns env-var definitions for the full Intlayer config to be injected at\n * build time. Allows bundlers to dead-code-eliminate unused routing modes,\n * rewrite logic, storage mechanisms, and editor code.\n *\n * @example\n * getConfigEnvVars(config)\n * // { INTLAYER_ROUTING_MODE: '\"prefix-no-default\"', INTLAYER_ROUTING_REWRITE_RULES: '\"false\"', ... }\n *\n * getConfigEnvVars(config, true)\n * // { 'process.env.INTLAYER_ROUTING_MODE': '\"prefix-no-default\"', ... }\n */\nexport const getConfigEnvVars = (\n config: IntlayerConfig,\n addProcessEnv: boolean = false\n): Record<string, string> => {\n const prefix = addProcessEnv ? 'process.env.' : '';\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = '\"false\"';\n }\n\n if (routing.storage.cookies.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = '\"false\"';\n }\n\n if (routing.storage.localStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.sessionStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.headers.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = '\"false\"';\n }\n\n if (editor?.enabled === false) {\n envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = '\"false\"';\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,0BACX,WACA,gBAAyB,UAEzB,UAAU,QACP,KAAK,aAAa;AACjB,KACE,gBACI,kCAAkC,SAAS,aAAa,KACxD,sBAAsB,SAAS,aAAa,MAC9C;AACJ,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;AAcH,MAAa,oBACX,QACA,gBAAyB,UACE;CAC3B,MAAM,SAAS,gBAAgB,iBAAiB;CAChD,MAAM,EAAE,SAAS,WAAW;CAE5B,MAAM,UAAkC,GACrC,GAAG,OAAO,yBAAyB,KAAK,UAAU,QAAQ,KAAK,EACjE;AAED,KAAI,CAAC,QAAQ,QACX,SAAQ,GAAG,OAAO,mCAAmC;AAGvD,KAAI,QAAQ,QAAQ,QAAQ,WAAW,EACrC,SAAQ,GAAG,OAAO,qCAAqC;AAGzD,KAAI,QAAQ,QAAQ,aAAa,WAAW,EAC1C,SAAQ,GAAG,OAAO,0CAA0C;AAG9D,KAAI,QAAQ,QAAQ,eAAe,WAAW,EAC5C,SAAQ,GAAG,OAAO,4CAA4C;AAGhE,KAAI,QAAQ,QAAQ,QAAQ,WAAW,EACrC,SAAQ,GAAG,OAAO,qCAAqC;AAGzD,KAAI,QAAQ,YAAY,MACtB,SAAQ,GAAG,OAAO,4BAA4B;AAGhD,QAAO"}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_envVars_envVars = require('./envVars.cjs');
|
|
3
3
|
|
|
4
|
-
exports.TREE_SHAKE_EDITOR = require_envVars_envVars.TREE_SHAKE_EDITOR;
|
|
5
|
-
exports.TREE_SHAKE_NO_PREFIX = require_envVars_envVars.TREE_SHAKE_NO_PREFIX;
|
|
6
|
-
exports.TREE_SHAKE_PREFIX_MODES = require_envVars_envVars.TREE_SHAKE_PREFIX_MODES;
|
|
7
|
-
exports.TREE_SHAKE_REWRITE = require_envVars_envVars.TREE_SHAKE_REWRITE;
|
|
8
|
-
exports.TREE_SHAKE_SEARCH_PARAMS = require_envVars_envVars.TREE_SHAKE_SEARCH_PARAMS;
|
|
9
|
-
exports.TREE_SHAKE_STORAGE_COOKIES = require_envVars_envVars.TREE_SHAKE_STORAGE_COOKIES;
|
|
10
|
-
exports.TREE_SHAKE_STORAGE_HEADERS = require_envVars_envVars.TREE_SHAKE_STORAGE_HEADERS;
|
|
11
|
-
exports.TREE_SHAKE_STORAGE_LOCAL_STORAGE = require_envVars_envVars.TREE_SHAKE_STORAGE_LOCAL_STORAGE;
|
|
12
|
-
exports.TREE_SHAKE_STORAGE_SESSION_STORAGE = require_envVars_envVars.TREE_SHAKE_STORAGE_SESSION_STORAGE;
|
|
13
4
|
exports.formatNodeTypeToEnvVar = require_envVars_envVars.formatNodeTypeToEnvVar;
|
|
14
5
|
exports.getConfigEnvVars = require_envVars_envVars.getConfigEnvVars;
|
|
@@ -3,7 +3,7 @@ import { getStorageAttributes } from "../utils/getStorageAttributes.mjs";
|
|
|
3
3
|
import { APPLICATION_URL, BACKEND_URL, CMS_URL, DICTIONARY_PRIORITY_STRATEGY, EDITOR_URL, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, PORT } from "../defaultValues/editor.mjs";
|
|
4
4
|
import { DEFAULT_LOCALE, LOCALES, REQUIRED_LOCALES, STRICT_MODE } from "../defaultValues/internationalization.mjs";
|
|
5
5
|
import { MODE, PREFIX } from "../defaultValues/log.mjs";
|
|
6
|
-
import
|
|
6
|
+
import configPackageJson from "@intlayer/types/package.json" with { type: "json" };
|
|
7
7
|
|
|
8
8
|
//#region src/configFile/buildBrowserConfiguration.ts
|
|
9
9
|
/**
|
|
@@ -115,7 +115,7 @@ const buildBrowserConfiguration = (customConfig) => {
|
|
|
115
115
|
},
|
|
116
116
|
metadata: {
|
|
117
117
|
name: "Intlayer",
|
|
118
|
-
version:
|
|
118
|
+
version: configPackageJson.version,
|
|
119
119
|
doc: "https://intlayer.org/docs"
|
|
120
120
|
}
|
|
121
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildBrowserConfiguration.mjs","names":[],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n CustomRoutingConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\nimport { getStorageAttributes } from '../utils/getStorageAttributes';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<CustomRoutingConfig>\n): RoutingConfig => {\n const storage = customConfiguration?.storage ?? STORAGE;\n\n return {\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: getStorageAttributes(storage),\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n };\n};\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.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;GAAS;GAAe;EAChD;EACA,QAAQ;EACR,KAAK;GAAE;GAAM;GAAQ;EACrB,UAAU;GACR,MAAM;GACN,SAAS,YAAY;GACrB,KAAK;GACN;EACF;;;;;;;;;;;;;AAcH,MAAa,+BACX,YAC2B;CAC3B,sBAAsB;EACpB,SAAS,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
|
|
1
|
+
{"version":3,"file":"buildBrowserConfiguration.mjs","names":["packageJson"],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n CustomRoutingConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\nimport { getStorageAttributes } from '../utils/getStorageAttributes';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<CustomRoutingConfig>\n): RoutingConfig => {\n const storage = customConfiguration?.storage ?? STORAGE;\n\n return {\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: getStorageAttributes(storage),\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n };\n};\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;;AA0EA,MAAa,mCACX,yBACgC;CAOhC,SAAS,qBAAqB,WAAW;CAWzC,iBACE,qBAAqB,mBACrB,qBAAqB,WACrB;CAUF,YAAY,qBAAqB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S,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
|
|
@@ -1,71 +1,5 @@
|
|
|
1
1
|
//#region src/envVars/envVars.ts
|
|
2
2
|
/**
|
|
3
|
-
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
4
|
-
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }
|
|
8
|
-
*/
|
|
9
|
-
const TREE_SHAKE_NO_PREFIX = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix";
|
|
10
|
-
/**
|
|
11
|
-
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* if (!TREE_SHAKE_SEARCH_PARAMS && mode === '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
|
-
* @example
|
|
22
|
-
* if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }
|
|
23
|
-
*/
|
|
24
|
-
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";
|
|
25
|
-
/**
|
|
26
|
-
* True when rewrite rules are explicitly disabled at build time
|
|
27
|
-
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* if (!TREE_SHAKE_REWRITE && rewrite) { ... }
|
|
31
|
-
*/
|
|
32
|
-
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
33
|
-
/**
|
|
34
|
-
* True when cookie storage is explicitly disabled at build time.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }
|
|
38
|
-
*/
|
|
39
|
-
const TREE_SHAKE_STORAGE_COOKIES = process.env["INTLAYER_ROUTING_STORAGE_COOKIES"] === "false";
|
|
40
|
-
/**
|
|
41
|
-
* True when localStorage is explicitly disabled at build time.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }
|
|
45
|
-
*/
|
|
46
|
-
const TREE_SHAKE_STORAGE_LOCAL_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_LOCALSTORAGE"] === "false";
|
|
47
|
-
/**
|
|
48
|
-
* True when sessionStorage is explicitly disabled at build time.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }
|
|
52
|
-
*/
|
|
53
|
-
const TREE_SHAKE_STORAGE_SESSION_STORAGE = process.env["INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE"] === "false";
|
|
54
|
-
/**
|
|
55
|
-
* True when header storage is explicitly disabled at build time.
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }
|
|
59
|
-
*/
|
|
60
|
-
const TREE_SHAKE_STORAGE_HEADERS = process.env["INTLAYER_ROUTING_STORAGE_HEADERS"] === "false";
|
|
61
|
-
/**
|
|
62
|
-
* True when the editor is explicitly disabled at build time.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* if (!TREE_SHAKE_EDITOR) { // editor logic }
|
|
66
|
-
*/
|
|
67
|
-
const TREE_SHAKE_EDITOR = process.env["INTLAYER_EDITOR_ENABLED"] === "false";
|
|
68
|
-
/**
|
|
69
3
|
* Converts a list of unused NodeType keys into env-var definitions.
|
|
70
4
|
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
71
5
|
*
|
|
@@ -106,5 +40,5 @@ const getConfigEnvVars = (config, addProcessEnv = false) => {
|
|
|
106
40
|
};
|
|
107
41
|
|
|
108
42
|
//#endregion
|
|
109
|
-
export {
|
|
43
|
+
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
110
44
|
//# sourceMappingURL=envVars.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVars.mjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n
|
|
1
|
+
{"version":3,"file":"envVars.mjs","names":[],"sources":["../../../src/envVars/envVars.ts"],"sourcesContent":["import type { IntlayerConfig } from '@intlayer/types/config';\n\n/**\n * Converts a list of unused NodeType keys into env-var definitions.\n * Set to `\"false\"` so bundlers can eliminate the corresponding plugin code.\n *\n * @example\n * formatNodeTypeToEnvVar(['enumeration'])\n * // { 'INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n *\n * formatNodeTypeToEnvVar(['enumeration'], true)\n * // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '\"false\"' }\n */\nexport const formatNodeTypeToEnvVar = (\n nodeTypes: string[],\n addProcessEnv: boolean = false\n): Record<string, string> =>\n nodeTypes.reduce(\n (acc, nodeType) => {\n acc[\n addProcessEnv\n ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`\n ] = '\"false\"';\n return acc;\n },\n {} as Record<string, string>\n );\n\n/**\n * Returns env-var definitions for the full Intlayer config to be injected at\n * build time. Allows bundlers to dead-code-eliminate unused routing modes,\n * rewrite logic, storage mechanisms, and editor code.\n *\n * @example\n * getConfigEnvVars(config)\n * // { INTLAYER_ROUTING_MODE: '\"prefix-no-default\"', INTLAYER_ROUTING_REWRITE_RULES: '\"false\"', ... }\n *\n * getConfigEnvVars(config, true)\n * // { 'process.env.INTLAYER_ROUTING_MODE': '\"prefix-no-default\"', ... }\n */\nexport const getConfigEnvVars = (\n config: IntlayerConfig,\n addProcessEnv: boolean = false\n): Record<string, string> => {\n const prefix = addProcessEnv ? 'process.env.' : '';\n const { routing, editor } = config;\n\n const envVars: Record<string, string> = {\n [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode),\n };\n\n if (!routing.rewrite) {\n envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = '\"false\"';\n }\n\n if (routing.storage.cookies.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = '\"false\"';\n }\n\n if (routing.storage.localStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.sessionStorage.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = '\"false\"';\n }\n\n if (routing.storage.headers.length === 0) {\n envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = '\"false\"';\n }\n\n if (editor?.enabled === false) {\n envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = '\"false\"';\n }\n\n return envVars;\n};\n"],"mappings":";;;;;;;;;;;;AAaA,MAAa,0BACX,WACA,gBAAyB,UAEzB,UAAU,QACP,KAAK,aAAa;AACjB,KACE,gBACI,kCAAkC,SAAS,aAAa,KACxD,sBAAsB,SAAS,aAAa,MAC9C;AACJ,QAAO;GAET,EAAE,CACH;;;;;;;;;;;;;AAcH,MAAa,oBACX,QACA,gBAAyB,UACE;CAC3B,MAAM,SAAS,gBAAgB,iBAAiB;CAChD,MAAM,EAAE,SAAS,WAAW;CAE5B,MAAM,UAAkC,GACrC,GAAG,OAAO,yBAAyB,KAAK,UAAU,QAAQ,KAAK,EACjE;AAED,KAAI,CAAC,QAAQ,QACX,SAAQ,GAAG,OAAO,mCAAmC;AAGvD,KAAI,QAAQ,QAAQ,QAAQ,WAAW,EACrC,SAAQ,GAAG,OAAO,qCAAqC;AAGzD,KAAI,QAAQ,QAAQ,aAAa,WAAW,EAC1C,SAAQ,GAAG,OAAO,0CAA0C;AAG9D,KAAI,QAAQ,QAAQ,eAAe,WAAW,EAC5C,SAAQ,GAAG,OAAO,4CAA4C;AAGhE,KAAI,QAAQ,QAAQ,QAAQ,WAAW,EACrC,SAAQ,GAAG,OAAO,qCAAqC;AAGzD,KAAI,QAAQ,YAAY,MACtB,SAAQ,GAAG,OAAO,4BAA4B;AAGhD,QAAO"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.mjs";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
@@ -3,7 +3,7 @@ import { basename, dirname, join } from "node:path";
|
|
|
3
3
|
import { mkdir, readFile, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { deserialize, serialize } from "node:v8";
|
|
5
5
|
import { gunzipSync, gzipSync } from "node:zlib";
|
|
6
|
-
import
|
|
6
|
+
import configPackageJson from "@intlayer/types/package.json" with { type: "json" };
|
|
7
7
|
|
|
8
8
|
//#region src/utils/cacheDisk.ts
|
|
9
9
|
const DEFAULTS = { compress: true };
|
|
@@ -60,7 +60,7 @@ const cacheDisk = (intlayerConfig, keys, options) => {
|
|
|
60
60
|
const maybeObj = deserialized;
|
|
61
61
|
if (!!maybeObj && typeof maybeObj === "object" && typeof maybeObj.version === "string" && typeof maybeObj.timestamp === "number" && Object.hasOwn(maybeObj, "data")) {
|
|
62
62
|
const entry = maybeObj;
|
|
63
|
-
if (entry.version !==
|
|
63
|
+
if (entry.version !== configPackageJson.version) {
|
|
64
64
|
try {
|
|
65
65
|
await unlink(filePath);
|
|
66
66
|
} catch {}
|
|
@@ -96,7 +96,7 @@ const cacheDisk = (intlayerConfig, keys, options) => {
|
|
|
96
96
|
try {
|
|
97
97
|
await ensureDir(dirname(filePath));
|
|
98
98
|
const envelope = {
|
|
99
|
-
version:
|
|
99
|
+
version: configPackageJson.version,
|
|
100
100
|
timestamp: Date.now(),
|
|
101
101
|
data: value
|
|
102
102
|
};
|
|
@@ -151,7 +151,7 @@ const cacheDisk = (intlayerConfig, keys, options) => {
|
|
|
151
151
|
const maybeObj = deserialize(flag === 1 ? gunzipSync(raw) : raw);
|
|
152
152
|
if (!!maybeObj && typeof maybeObj === "object" && typeof maybeObj.version === "string" && typeof maybeObj.timestamp === "number" && Object.hasOwn(maybeObj, "data")) {
|
|
153
153
|
const entry = maybeObj;
|
|
154
|
-
if (entry.version !==
|
|
154
|
+
if (entry.version !== configPackageJson.version) return false;
|
|
155
155
|
if (typeof maxTimeMs === "number" && maxTimeMs > 0) {
|
|
156
156
|
if (Date.now() - entry.timestamp > maxTimeMs) return false;
|
|
157
157
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheDisk.mjs","names":["configPackageJson"],"sources":["../../../src/utils/cacheDisk.ts"],"sourcesContent":["import {\n mkdir,\n readFile,\n rename,\n rm,\n stat,\n unlink,\n writeFile,\n} from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\nimport { deserialize, serialize } from 'node:v8';\nimport { gunzipSync, gzipSync } from 'node:zlib';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport configPackageJson from '@intlayer/types/package.json' with {\n type: 'json',\n};\nimport { type CacheKey, clearAllCache, computeKeyId } from './cacheMemory';\n\n/** ------------------------- Persistence layer ------------------------- **/\n\n/** Cache envelope structure stored on disk */\ntype CacheEnvelope = {\n /** Version of the config package (for cache invalidation) */\n version: string;\n /** Timestamp when the cache entry was created (in milliseconds) */\n timestamp: number;\n /** Data payload (the actual cached value) */\n data: unknown;\n};\n\ntype LocalCacheOptions = {\n /** Preferred new option name */\n persistent?: boolean;\n /** Time-to-live in ms; if expired, disk entry is ignored. */\n ttlMs?: number;\n /** Max age in ms based on stored creation timestamp; invalidates on exceed. */\n maxTimeMs?: number;\n /** Optional namespace to separate different logical caches. */\n namespace?: string;\n /** Gzip values on disk (on by default for blobs > 1KB). */\n compress?: boolean;\n};\n\nconst DEFAULTS: Required<Pick<LocalCacheOptions, 'compress'>> = {\n compress: true,\n};\n\nconst ensureDir = async (dir: string) => {\n await mkdir(dir, { recursive: true });\n};\n\nconst atomicWriteFile = async (\n file: string,\n data: Buffer,\n tempDir?: string\n) => {\n if (tempDir) {\n try {\n await ensureDir(tempDir);\n } catch {}\n }\n\n const tempFileName = `${basename(file)}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;\n const tmp = tempDir\n ? join(tempDir, tempFileName)\n : `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;\n try {\n await writeFile(tmp, data);\n await rename(tmp, file);\n } catch (error) {\n try {\n await rm(tmp, { force: true });\n } catch {\n // Ignore\n }\n throw error;\n }\n};\n\nconst shouldUseCompression = (buf: Buffer, force?: boolean) =>\n force === true || (force !== false && buf.byteLength > 1024);\n\n/** Derive on-disk path from config dir + namespace + key id. */\nconst cachePath = (cacheDir: string, id: string, ns?: string) =>\n join(cacheDir, ns ? join(ns, id) : id);\n\n/** ------------------------- Local cache facade ------------------------- **/\n\nconst cacheMap = new Map<string, any>();\n\n/** Clears the in-memory portion of the disk cache without touching disk files. */\nexport const clearDiskCacheMemory = (): void => {\n cacheMap.clear();\n};\n\nexport const cacheDisk = (\n intlayerConfig: IntlayerConfig,\n keys: CacheKey[],\n options?: LocalCacheOptions\n) => {\n const { cacheDir, tempDir } = intlayerConfig.system;\n const buildCacheEnabled = intlayerConfig.build.cache ?? true;\n const persistent =\n options?.persistent === true ||\n (typeof options?.persistent === 'undefined' && buildCacheEnabled);\n\n const { compress, ttlMs, maxTimeMs, namespace } = {\n ...DEFAULTS,\n ...options,\n };\n\n // single stable id for this key tuple (works for both memory & disk)\n const id = computeKeyId(keys);\n const filePath = cachePath(cacheDir, id, namespace);\n\n const readFromDisk = async (): Promise<unknown | undefined> => {\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n\n if (!statValue) return undefined;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return undefined;\n }\n let raw = await readFile(filePath);\n // header: 1 byte flag (0x00 raw, 0x01 gzip)\n const flag = raw[0];\n\n raw = raw.subarray(1);\n\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n let value: unknown;\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof (maybeObj as any).version === 'string' &&\n typeof (maybeObj as any).timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n\n if (entry.version !== configPackageJson.version) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n\n value = entry.data;\n } else {\n // Backward compatibility: old entries had raw serialized value.\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n value = deserialized;\n }\n\n // hydrate memory cache as well\n cacheMap.set(id, value);\n return value;\n } catch {\n return undefined;\n }\n };\n\n const writeToDisk = async (value: unknown) => {\n try {\n await ensureDir(dirname(filePath));\n const envelope: CacheEnvelope = {\n version: configPackageJson.version,\n timestamp: Date.now(),\n data: value,\n };\n const payload = Buffer.from(serialize(envelope));\n\n const gz = shouldUseCompression(payload, compress)\n ? gzipSync(payload)\n : payload;\n\n // prepend a 1-byte header indicating compression\n const buf = Buffer.concat([\n Buffer.from([gz === payload ? 0x00 : 0x01]),\n gz,\n ]);\n\n await atomicWriteFile(filePath, buf, tempDir);\n } catch {\n // swallow disk errors for cache writes\n }\n };\n\n return {\n /** In-memory first, then disk (if enabled), otherwise undefined. */\n get: async <T>(): Promise<T | undefined> => {\n const mem = cacheMap.get(id);\n\n if (mem !== undefined) return mem as T;\n\n if (persistent && buildCacheEnabled) {\n return (await readFromDisk()) as T | undefined;\n }\n return undefined;\n },\n /** Sets in-memory (always) and persists to disk if enabled. */\n set: async (value: unknown): Promise<void> => {\n cacheMap.set(id, value);\n\n if (persistent && buildCacheEnabled) {\n await writeToDisk(value);\n }\n },\n /** Clears only this entry from memory and disk. */\n clear: async (): Promise<void> => {\n cacheMap.delete(id);\n\n try {\n await unlink(filePath);\n } catch {}\n },\n /** Clears ALL cached entries (memory Map and entire cacheDir namespace if persistent). */\n clearAll: async (): Promise<void> => {\n clearAllCache();\n if (persistent && buildCacheEnabled) {\n // remove only the current namespace (if provided), else the root dir\n const base = namespace ? join(cacheDir, namespace) : cacheDir;\n\n try {\n await rm(base, { recursive: true, force: true });\n } catch {}\n\n try {\n await mkdir(base, { recursive: true });\n } catch {}\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n isValid: async (): Promise<boolean> => {\n const cachedValue = cacheMap.get(id);\n if (cachedValue !== undefined) return true;\n\n // If persistence is disabled or build cache disabled, only memory can be valid\n if (!persistent || !buildCacheEnabled) return false;\n\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n if (!statValue) return false;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return false;\n }\n\n let raw = await readFile(filePath);\n const flag = raw[0];\n raw = raw.subarray(1);\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof maybeObj.version === 'string' &&\n typeof maybeObj.timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n if (entry.version !== configPackageJson.version) return false;\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) return false;\n }\n return true;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) return false;\n }\n return true;\n } catch {\n return false;\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n id,\n /** Expose the absolute file path for debugging. */\n filePath,\n };\n};\n"],"mappings":";;;;;;;;AA2CA,MAAM,WAA0D,EAC9D,UAAU,MACX;AAED,MAAM,YAAY,OAAO,QAAgB;AACvC,OAAM,MAAM,KAAK,EAAE,WAAW,MAAM,CAAC;;AAGvC,MAAM,kBAAkB,OACtB,MACA,MACA,YACG;AACH,KAAI,QACF,KAAI;AACF,QAAM,UAAU,QAAQ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W,QAAO;;AAE9B,YAAO;;AAGT,QAAI,OAAO,cAAc,YAAY,YAAY,GAE/C;SADY,KAAK,KAAK,GAAG,UAAU,UACzB,UAAW,QAAO;;AAE9B,WAAO;WACD;AACN,WAAO;;;EAIX;EAEA;EACD"}
|
|
1
|
+
{"version":3,"file":"cacheDisk.mjs","names":[],"sources":["../../../src/utils/cacheDisk.ts"],"sourcesContent":["import {\n mkdir,\n readFile,\n rename,\n rm,\n stat,\n unlink,\n writeFile,\n} from 'node:fs/promises';\nimport { basename, dirname, join } from 'node:path';\nimport { deserialize, serialize } from 'node:v8';\nimport { gunzipSync, gzipSync } from 'node:zlib';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport configPackageJson from '@intlayer/types/package.json' with {\n type: 'json',\n};\nimport { type CacheKey, clearAllCache, computeKeyId } from './cacheMemory';\n\n/** ------------------------- Persistence layer ------------------------- **/\n\n/** Cache envelope structure stored on disk */\ntype CacheEnvelope = {\n /** Version of the config package (for cache invalidation) */\n version: string;\n /** Timestamp when the cache entry was created (in milliseconds) */\n timestamp: number;\n /** Data payload (the actual cached value) */\n data: unknown;\n};\n\ntype LocalCacheOptions = {\n /** Preferred new option name */\n persistent?: boolean;\n /** Time-to-live in ms; if expired, disk entry is ignored. */\n ttlMs?: number;\n /** Max age in ms based on stored creation timestamp; invalidates on exceed. */\n maxTimeMs?: number;\n /** Optional namespace to separate different logical caches. */\n namespace?: string;\n /** Gzip values on disk (on by default for blobs > 1KB). */\n compress?: boolean;\n};\n\nconst DEFAULTS: Required<Pick<LocalCacheOptions, 'compress'>> = {\n compress: true,\n};\n\nconst ensureDir = async (dir: string) => {\n await mkdir(dir, { recursive: true });\n};\n\nconst atomicWriteFile = async (\n file: string,\n data: Buffer,\n tempDir?: string\n) => {\n if (tempDir) {\n try {\n await ensureDir(tempDir);\n } catch {}\n }\n\n const tempFileName = `${basename(file)}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;\n const tmp = tempDir\n ? join(tempDir, tempFileName)\n : `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;\n try {\n await writeFile(tmp, data);\n await rename(tmp, file);\n } catch (error) {\n try {\n await rm(tmp, { force: true });\n } catch {\n // Ignore\n }\n throw error;\n }\n};\n\nconst shouldUseCompression = (buf: Buffer, force?: boolean) =>\n force === true || (force !== false && buf.byteLength > 1024);\n\n/** Derive on-disk path from config dir + namespace + key id. */\nconst cachePath = (cacheDir: string, id: string, ns?: string) =>\n join(cacheDir, ns ? join(ns, id) : id);\n\n/** ------------------------- Local cache facade ------------------------- **/\n\nconst cacheMap = new Map<string, any>();\n\n/** Clears the in-memory portion of the disk cache without touching disk files. */\nexport const clearDiskCacheMemory = (): void => {\n cacheMap.clear();\n};\n\nexport const cacheDisk = (\n intlayerConfig: IntlayerConfig,\n keys: CacheKey[],\n options?: LocalCacheOptions\n) => {\n const { cacheDir, tempDir } = intlayerConfig.system;\n const buildCacheEnabled = intlayerConfig.build.cache ?? true;\n const persistent =\n options?.persistent === true ||\n (typeof options?.persistent === 'undefined' && buildCacheEnabled);\n\n const { compress, ttlMs, maxTimeMs, namespace } = {\n ...DEFAULTS,\n ...options,\n };\n\n // single stable id for this key tuple (works for both memory & disk)\n const id = computeKeyId(keys);\n const filePath = cachePath(cacheDir, id, namespace);\n\n const readFromDisk = async (): Promise<unknown | undefined> => {\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n\n if (!statValue) return undefined;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return undefined;\n }\n let raw = await readFile(filePath);\n // header: 1 byte flag (0x00 raw, 0x01 gzip)\n const flag = raw[0];\n\n raw = raw.subarray(1);\n\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n let value: unknown;\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof (maybeObj as any).version === 'string' &&\n typeof (maybeObj as any).timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n\n if (entry.version !== configPackageJson.version) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n\n value = entry.data;\n } else {\n // Backward compatibility: old entries had raw serialized value.\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) {\n try {\n await unlink(filePath);\n } catch {}\n return undefined;\n }\n }\n value = deserialized;\n }\n\n // hydrate memory cache as well\n cacheMap.set(id, value);\n return value;\n } catch {\n return undefined;\n }\n };\n\n const writeToDisk = async (value: unknown) => {\n try {\n await ensureDir(dirname(filePath));\n const envelope: CacheEnvelope = {\n version: configPackageJson.version,\n timestamp: Date.now(),\n data: value,\n };\n const payload = Buffer.from(serialize(envelope));\n\n const gz = shouldUseCompression(payload, compress)\n ? gzipSync(payload)\n : payload;\n\n // prepend a 1-byte header indicating compression\n const buf = Buffer.concat([\n Buffer.from([gz === payload ? 0x00 : 0x01]),\n gz,\n ]);\n\n await atomicWriteFile(filePath, buf, tempDir);\n } catch {\n // swallow disk errors for cache writes\n }\n };\n\n return {\n /** In-memory first, then disk (if enabled), otherwise undefined. */\n get: async <T>(): Promise<T | undefined> => {\n const mem = cacheMap.get(id);\n\n if (mem !== undefined) return mem as T;\n\n if (persistent && buildCacheEnabled) {\n return (await readFromDisk()) as T | undefined;\n }\n return undefined;\n },\n /** Sets in-memory (always) and persists to disk if enabled. */\n set: async (value: unknown): Promise<void> => {\n cacheMap.set(id, value);\n\n if (persistent && buildCacheEnabled) {\n await writeToDisk(value);\n }\n },\n /** Clears only this entry from memory and disk. */\n clear: async (): Promise<void> => {\n cacheMap.delete(id);\n\n try {\n await unlink(filePath);\n } catch {}\n },\n /** Clears ALL cached entries (memory Map and entire cacheDir namespace if persistent). */\n clearAll: async (): Promise<void> => {\n clearAllCache();\n if (persistent && buildCacheEnabled) {\n // remove only the current namespace (if provided), else the root dir\n const base = namespace ? join(cacheDir, namespace) : cacheDir;\n\n try {\n await rm(base, { recursive: true, force: true });\n } catch {}\n\n try {\n await mkdir(base, { recursive: true });\n } catch {}\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n isValid: async (): Promise<boolean> => {\n const cachedValue = cacheMap.get(id);\n if (cachedValue !== undefined) return true;\n\n // If persistence is disabled or build cache disabled, only memory can be valid\n if (!persistent || !buildCacheEnabled) return false;\n\n try {\n const statValue = await stat(filePath).catch(() => undefined);\n if (!statValue) return false;\n\n if (typeof ttlMs === 'number' && ttlMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > ttlMs) return false;\n }\n\n let raw = await readFile(filePath);\n const flag = raw[0];\n raw = raw.subarray(1);\n const payload = flag === 0x01 ? gunzipSync(raw) : raw;\n const deserialized = deserialize(payload) as unknown;\n\n const maybeObj = deserialized as Record<string, unknown> | null;\n const isEnvelope =\n !!maybeObj &&\n typeof maybeObj === 'object' &&\n typeof maybeObj.version === 'string' &&\n typeof maybeObj.timestamp === 'number' &&\n Object.hasOwn(maybeObj, 'data');\n\n if (isEnvelope) {\n const entry = maybeObj as CacheEnvelope;\n if (entry.version !== configPackageJson.version) return false;\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - entry.timestamp;\n if (age > maxTimeMs) return false;\n }\n return true;\n }\n\n if (typeof maxTimeMs === 'number' && maxTimeMs > 0) {\n const age = Date.now() - statValue.mtimeMs;\n if (age > maxTimeMs) return false;\n }\n return true;\n } catch {\n return false;\n }\n },\n /** Expose the computed id (useful if you want to key other structures). */\n id,\n /** Expose the absolute file path for debugging. */\n filePath,\n };\n};\n"],"mappings":";;;;;;;;AA2CA,MAAM,WAA0D,EAC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AC9B,OAAO,OAAO,UAAU,OAAO,EAEjB;KACd,MAAM,QAAQ;AACd,SAAI,MAAM,YAAY,kBAAkB,QAAS,QAAO;AAExD,SAAI,OAAO,cAAc,YAAY,YAAY,GAE/C;UADY,KAAK,KAAK,GAAG,MAAM,YACrB,UAAW,QAAO;;AAE9B,YAAO;;AAGT,QAAI,OAAO,cAAc,YAAY,YAAY,GAE/C;SADY,KAAK,KAAK,GAAG,UAAU,UACzB,UAAW,QAAO;;AAE9B,WAAO;WACD;AACN,WAAO;;;EAIX;EAEA;EACD"}
|
|
@@ -1,72 +1,6 @@
|
|
|
1
1
|
import { IntlayerConfig } from "@intlayer/types/config";
|
|
2
2
|
|
|
3
3
|
//#region src/envVars/envVars.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
6
|
-
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* if (!TREE_SHAKE_NO_PREFIX && mode === 'no-prefix') { ... }
|
|
10
|
-
*/
|
|
11
|
-
declare const TREE_SHAKE_NO_PREFIX: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* if (!TREE_SHAKE_SEARCH_PARAMS && mode === 'search-params') { ... }
|
|
17
|
-
*/
|
|
18
|
-
declare const TREE_SHAKE_SEARCH_PARAMS: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* True when the build-time routing mode is known and is not a prefix-based
|
|
21
|
-
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* if (!TREE_SHAKE_PREFIX_MODES && (mode === 'prefix-all' || mode === 'prefix-no-default')) { ... }
|
|
25
|
-
*/
|
|
26
|
-
declare const TREE_SHAKE_PREFIX_MODES: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* True when rewrite rules are explicitly disabled at build time
|
|
29
|
-
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* if (!TREE_SHAKE_REWRITE && rewrite) { ... }
|
|
33
|
-
*/
|
|
34
|
-
declare const TREE_SHAKE_REWRITE: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* True when cookie storage is explicitly disabled at build time.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* if (!TREE_SHAKE_STORAGE_COOKIES) { // cookie logic }
|
|
40
|
-
*/
|
|
41
|
-
declare const TREE_SHAKE_STORAGE_COOKIES: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* True when localStorage is explicitly disabled at build time.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* if (!TREE_SHAKE_STORAGE_LOCAL_STORAGE) { // localStorage logic }
|
|
47
|
-
*/
|
|
48
|
-
declare const TREE_SHAKE_STORAGE_LOCAL_STORAGE: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* True when sessionStorage is explicitly disabled at build time.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* if (!TREE_SHAKE_STORAGE_SESSION_STORAGE) { // sessionStorage logic }
|
|
54
|
-
*/
|
|
55
|
-
declare const TREE_SHAKE_STORAGE_SESSION_STORAGE: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* True when header storage is explicitly disabled at build time.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* if (!TREE_SHAKE_STORAGE_HEADERS) { // header logic }
|
|
61
|
-
*/
|
|
62
|
-
declare const TREE_SHAKE_STORAGE_HEADERS: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* True when the editor is explicitly disabled at build time.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* if (!TREE_SHAKE_EDITOR) { // editor logic }
|
|
68
|
-
*/
|
|
69
|
-
declare const TREE_SHAKE_EDITOR: boolean;
|
|
70
4
|
/**
|
|
71
5
|
* Converts a list of unused NodeType keys into env-var definitions.
|
|
72
6
|
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
@@ -93,5 +27,5 @@ declare const formatNodeTypeToEnvVar: (nodeTypes: string[], addProcessEnv?: bool
|
|
|
93
27
|
*/
|
|
94
28
|
declare const getConfigEnvVars: (config: IntlayerConfig, addProcessEnv?: boolean) => Record<string, string>;
|
|
95
29
|
//#endregion
|
|
96
|
-
export {
|
|
30
|
+
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
97
31
|
//# sourceMappingURL=envVars.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envVars.d.ts","names":[],"sources":["../../../src/envVars/envVars.ts"],"mappings":";;;;;AAaA
|
|
1
|
+
{"version":3,"file":"envVars.d.ts","names":[],"sources":["../../../src/envVars/envVars.ts"],"mappings":";;;;;AAaA;;;;;;;;;cAAa,sBAAA,GACX,SAAA,YACA,aAAA,eACC,MAAA;;;;;;;;;;;;;cAyBU,gBAAA,GACX,MAAA,EAAQ,cAAA,EACR,aAAA,eACC,MAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { formatNodeTypeToEnvVar, getConfigEnvVars } from "./envVars.js";
|
|
2
|
+
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/config",
|
|
3
|
-
"version": "8.6.
|
|
3
|
+
"version": "8.6.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.",
|
|
6
6
|
"keywords": [
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
153
153
|
},
|
|
154
154
|
"dependencies": {
|
|
155
|
-
"@intlayer/types": "8.6.
|
|
155
|
+
"@intlayer/types": "8.6.3",
|
|
156
156
|
"defu": "6.1.4",
|
|
157
157
|
"dotenv": "17.3.1",
|
|
158
158
|
"esbuild": "0.27.4",
|