@intlayer/config 8.6.1 → 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 +47 -0
- package/dist/cjs/envVars/envVars.cjs.map +1 -0
- package/dist/cjs/envVars/index.cjs +5 -0
- package/dist/cjs/utils/extractErrorMessage.cjs +12 -4
- package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -1
- package/dist/cjs/utils/getUsedNodeTypes.cjs +56 -0
- package/dist/cjs/utils/getUsedNodeTypes.cjs.map +1 -0
- package/dist/cjs/utils/index.cjs +5 -0
- package/dist/esm/configFile/buildBrowserConfiguration.mjs +2 -2
- package/dist/esm/configFile/buildBrowserConfiguration.mjs.map +1 -1
- package/dist/esm/envVars/envVars.mjs +44 -0
- package/dist/esm/envVars/envVars.mjs.map +1 -0
- package/dist/esm/envVars/index.mjs +3 -0
- package/dist/esm/utils/cacheDisk.mjs +4 -4
- package/dist/esm/utils/cacheDisk.mjs.map +1 -1
- package/dist/esm/utils/extractErrorMessage.mjs +12 -4
- package/dist/esm/utils/extractErrorMessage.mjs.map +1 -1
- package/dist/esm/utils/getUsedNodeTypes.mjs +51 -0
- package/dist/esm/utils/getUsedNodeTypes.mjs.map +1 -0
- package/dist/esm/utils/index.mjs +2 -1
- package/dist/types/configFile/configurationSchema.d.ts +7 -7
- package/dist/types/envVars/envVars.d.ts +31 -0
- package/dist/types/envVars/envVars.d.ts.map +1 -0
- package/dist/types/envVars/index.d.ts +2 -0
- package/dist/types/utils/getUsedNodeTypes.d.ts +20 -0
- package/dist/types/utils/getUsedNodeTypes.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +2 -1
- package/package.json +10 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/envVars/envVars.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a list of unused NodeType keys into env-var definitions.
|
|
6
|
+
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* formatNodeTypeToEnvVar(['enumeration'])
|
|
10
|
+
* // { 'INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
11
|
+
*
|
|
12
|
+
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
13
|
+
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
14
|
+
*/
|
|
15
|
+
const formatNodeTypeToEnvVar = (nodeTypes, addProcessEnv = false) => nodeTypes.reduce((acc, nodeType) => {
|
|
16
|
+
acc[addProcessEnv ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}` : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`] = "\"false\"";
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
/**
|
|
20
|
+
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
21
|
+
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
22
|
+
* rewrite logic, storage mechanisms, and editor code.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* getConfigEnvVars(config)
|
|
26
|
+
* // { INTLAYER_ROUTING_MODE: '"prefix-no-default"', INTLAYER_ROUTING_REWRITE_RULES: '"false"', ... }
|
|
27
|
+
*
|
|
28
|
+
* getConfigEnvVars(config, true)
|
|
29
|
+
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
30
|
+
*/
|
|
31
|
+
const getConfigEnvVars = (config, addProcessEnv = false) => {
|
|
32
|
+
const prefix = addProcessEnv ? "process.env." : "";
|
|
33
|
+
const { routing, editor } = config;
|
|
34
|
+
const envVars = { [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode) };
|
|
35
|
+
if (!routing.rewrite) envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = "\"false\"";
|
|
36
|
+
if (routing.storage.cookies.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = "\"false\"";
|
|
37
|
+
if (routing.storage.localStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = "\"false\"";
|
|
38
|
+
if (routing.storage.sessionStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = "\"false\"";
|
|
39
|
+
if (routing.storage.headers.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = "\"false\"";
|
|
40
|
+
if (editor?.enabled === false) envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = "\"false\"";
|
|
41
|
+
return envVars;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.formatNodeTypeToEnvVar = formatNodeTypeToEnvVar;
|
|
46
|
+
exports.getConfigEnvVars = getConfigEnvVars;
|
|
47
|
+
//# sourceMappingURL=envVars.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_envVars_envVars = require('./envVars.cjs');
|
|
3
|
+
|
|
4
|
+
exports.formatNodeTypeToEnvVar = require_envVars_envVars.formatNodeTypeToEnvVar;
|
|
5
|
+
exports.getConfigEnvVars = require_envVars_envVars.getConfigEnvVars;
|
|
@@ -2,11 +2,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
//#region src/utils/extractErrorMessage.ts
|
|
4
4
|
const extractErrorMessage = (error) => {
|
|
5
|
-
const trimToSingleLine = (text) => text.split(/\r?\n/).map((
|
|
5
|
+
const trimToSingleLine = (text) => text.split(/\r?\n/).map((stringValue) => stringValue.trim()).filter(Boolean)[0] ?? text.trim();
|
|
6
6
|
const looksLikeJson = (value) => {
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
9
|
-
const first =
|
|
7
|
+
const stringValue = value.trim();
|
|
8
|
+
if (!stringValue) return false;
|
|
9
|
+
const first = stringValue[0];
|
|
10
10
|
return first === "{" || first === "[" || first === "\"";
|
|
11
11
|
};
|
|
12
12
|
const sanitizeUnexpectedTokenMessage = (text) => {
|
|
@@ -23,6 +23,14 @@ const extractErrorMessage = (error) => {
|
|
|
23
23
|
if (!value || typeof value !== "object") return void 0;
|
|
24
24
|
if (seen.has(value)) return void 0;
|
|
25
25
|
seen.add(value);
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
for (const item of value) {
|
|
28
|
+
const fromItem = pickFieldsFromObject(item, seen);
|
|
29
|
+
if (fromItem) return fromItem;
|
|
30
|
+
if (typeof item?.message === "string") return item.message;
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
26
34
|
const obj = value;
|
|
27
35
|
if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
|
|
28
36
|
if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractErrorMessage.cjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((
|
|
1
|
+
{"version":3,"file":"extractErrorMessage.cjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((stringValue) => stringValue.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const stringValue = value.trim();\n\n if (!stringValue) return false;\n const first = stringValue[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n\n if (seen.has(value)) return undefined;\n\n seen.add(value);\n\n // If the value itself is an array (e.g. ZodError.issues), iterate its items\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n return undefined;\n }\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n\n if (picked) return picked;\n\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":";;;AAAA,MAAa,uBAAuB,UAA2B;CAC7D,MAAM,oBAAoB,SACxB,KACG,MAAM,QAAQ,CACd,KAAK,gBAAgB,YAAY,MAAM,CAAC,CACxC,OAAO,QAAQ,CAAC,MAAM,KAAK,MAAM;CAEtC,MAAM,iBAAiB,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AO,iBAAiB,YAAY;GAErD,MAAM,YAAY,oBAAoB,MAAM,MAAiB;AAE7D,OAAI,aAAa,cAAc,4BAC7B,QAAO,iBAAiB,UAAU;AACpC,UAAO,iBAAiB,QAAQ;;EAKlC,MAAM,aAAa,qBAAqB,uBAD3B,IAAI,KAAc,CACqB;AAEpD,MAAI,YAAY;GACd,MAAM,UAAU,+BAA+B,WAAW;AAC1D,UAAO,mBAAmB,QAAQ,IAAI,iBAAiB,QAAQ;;AAGjE,MAAI;AAEF,UAAO,iBADY,KAAK,UAAU,MAAM,CACL;UAC7B;AACN,UAAO,iBAAiB,OAAO,MAAM,CAAC;;;AAI1C,QAAO"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
4
|
+
|
|
5
|
+
//#region src/utils/getUsedNodeTypes.ts
|
|
6
|
+
/** Recursively collect every `nodeType` string found in a value. */
|
|
7
|
+
const collectNodeTypes = (value, result) => {
|
|
8
|
+
if (!value || typeof value !== "object") return;
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
for (const item of value) collectNodeTypes(item, result);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const obj = value;
|
|
14
|
+
if (typeof obj.nodeType === "string") result.add(obj.nodeType);
|
|
15
|
+
for (const key of Object.keys(obj)) collectNodeTypes(obj[key], result);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns the set of NodeType strings actually used across the given
|
|
19
|
+
* built dictionaries.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const used = getUsedNodeTypes(getDictionaries(config));
|
|
23
|
+
* // Set { 'translation', 'enumeration' }
|
|
24
|
+
*/
|
|
25
|
+
const getUsedNodeTypes = (dictionaries) => {
|
|
26
|
+
const result = /* @__PURE__ */ new Set();
|
|
27
|
+
const dicts = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
28
|
+
for (const dict of dicts) collectNodeTypes(dict.content, result);
|
|
29
|
+
return [...result];
|
|
30
|
+
};
|
|
31
|
+
const getUnusedNodeTypes = (dictionaries) => {
|
|
32
|
+
const usedNodeTypes = getUsedNodeTypes(dictionaries);
|
|
33
|
+
return _intlayer_types_nodeType.PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
34
|
+
};
|
|
35
|
+
const getUsedNodeTypesAsync = async (dictionaries) => {
|
|
36
|
+
const dictionariesArray = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
37
|
+
const results = await Promise.all(dictionariesArray.map(async (dictionary) => {
|
|
38
|
+
const result = /* @__PURE__ */ new Set();
|
|
39
|
+
collectNodeTypes(dictionary.content, result);
|
|
40
|
+
return result;
|
|
41
|
+
}));
|
|
42
|
+
const finalResult = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const res of results) for (const val of res) finalResult.add(val);
|
|
44
|
+
return [...finalResult];
|
|
45
|
+
};
|
|
46
|
+
const getUnusedNodeTypesAsync = async (dictionaries) => {
|
|
47
|
+
const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);
|
|
48
|
+
return _intlayer_types_nodeType.PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.getUnusedNodeTypes = getUnusedNodeTypes;
|
|
53
|
+
exports.getUnusedNodeTypesAsync = getUnusedNodeTypesAsync;
|
|
54
|
+
exports.getUsedNodeTypes = getUsedNodeTypes;
|
|
55
|
+
exports.getUsedNodeTypesAsync = getUsedNodeTypesAsync;
|
|
56
|
+
//# sourceMappingURL=getUsedNodeTypes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUsedNodeTypes.cjs","names":["PLUGIN_NODE_TYPES"],"sources":["../../../src/utils/getUsedNodeTypes.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { PLUGIN_NODE_TYPES } from '@intlayer/types/nodeType';\n\nexport type PluginNodeType = (typeof PLUGIN_NODE_TYPES)[number];\n\n/** Recursively collect every `nodeType` string found in a value. */\nconst collectNodeTypes = (value: unknown, result: Set<string>): void => {\n if (!value || typeof value !== 'object') return;\n\n if (Array.isArray(value)) {\n for (const item of value) collectNodeTypes(item, result);\n return;\n }\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.nodeType === 'string') {\n result.add(obj.nodeType);\n }\n\n for (const key of Object.keys(obj)) {\n collectNodeTypes(obj[key], result);\n }\n};\n\n/**\n * Returns the set of NodeType strings actually used across the given\n * built dictionaries.\n *\n * @example\n * const used = getUsedNodeTypes(getDictionaries(config));\n * // Set { 'translation', 'enumeration' }\n */\nexport const getUsedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const result = new Set<PluginNodeType>();\n const dicts = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n for (const dict of dicts) {\n collectNodeTypes(dict.content, result);\n }\n\n return [...result];\n};\n\nexport const getUnusedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const usedNodeTypes = getUsedNodeTypes(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n\nexport const getUsedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const dictionariesArray = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n const results = await Promise.all(\n dictionariesArray.map(async (dictionary) => {\n const result = new Set<PluginNodeType>();\n\n collectNodeTypes(dictionary.content, result as Set<string>);\n\n return result;\n })\n );\n\n const finalResult = new Set<PluginNodeType>();\n\n for (const res of results) {\n for (const val of res) {\n finalResult.add(val);\n }\n }\n\n return [...finalResult];\n};\n\nexport const getUnusedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n"],"mappings":";;;;;;AAMA,MAAM,oBAAoB,OAAgB,WAA8B;AACtE,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU;AAEzC,KAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,OAAK,MAAM,QAAQ,MAAO,kBAAiB,MAAM,OAAO;AACxD;;CAGF,MAAM,MAAM;AAEZ,KAAI,OAAO,IAAI,aAAa,SAC1B,QAAO,IAAI,IAAI,SAAS;AAG1B,MAAK,MAAM,OAAO,OAAO,KAAK,IAAI,CAChC,kBAAiB,IAAI,MAAM,OAAO;;;;;;;;;;AAYtC,MAAa,oBACX,iBACqB;CACrB,MAAM,yBAAS,IAAI,KAAqB;CACxC,MAAM,QAAQ,MAAM,QAAQ,aAAa,GACrC,eACA,OAAO,OAAO,aAAa;AAE/B,MAAK,MAAM,QAAQ,MACjB,kBAAiB,KAAK,SAAS,OAAO;AAGxC,QAAO,CAAC,GAAG,OAAO;;AAGpB,MAAa,sBACX,iBACqB;CACrB,MAAM,gBAAgB,iBAAiB,aAAa;AAEpD,QAAOA,2CAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD;;AAGH,MAAa,wBAAwB,OACnC,iBAC8B;CAC9B,MAAM,oBAAoB,MAAM,QAAQ,aAAa,GACjD,eACA,OAAO,OAAO,aAAa;CAE/B,MAAM,UAAU,MAAM,QAAQ,IAC5B,kBAAkB,IAAI,OAAO,eAAe;EAC1C,MAAM,yBAAS,IAAI,KAAqB;AAExC,mBAAiB,WAAW,SAAS,OAAsB;AAE3D,SAAO;GACP,CACH;CAED,MAAM,8BAAc,IAAI,KAAqB;AAE7C,MAAK,MAAM,OAAO,QAChB,MAAK,MAAM,OAAO,IAChB,aAAY,IAAI,IAAI;AAIxB,QAAO,CAAC,GAAG,YAAY;;AAGzB,MAAa,0BAA0B,OACrC,iBAC8B;CAC9B,MAAM,gBAAgB,MAAM,sBAAsB,aAAa;AAE/D,QAAOA,2CAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD"}
|
package/dist/cjs/utils/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ const require_utils_clearModuleCache = require('./clearModuleCache.cjs');
|
|
|
10
10
|
const require_utils_compareVersions = require('./compareVersions.cjs');
|
|
11
11
|
const require_utils_extractErrorMessage = require('./extractErrorMessage.cjs');
|
|
12
12
|
const require_utils_getStorageAttributes = require('./getStorageAttributes.cjs');
|
|
13
|
+
const require_utils_getUsedNodeTypes = require('./getUsedNodeTypes.cjs');
|
|
13
14
|
const require_utils_logStack = require('./logStack.cjs');
|
|
14
15
|
const require_utils_parseFilePathPattern = require('./parseFilePathPattern.cjs');
|
|
15
16
|
const require_utils_retryManager = require('./retryManager.cjs');
|
|
@@ -36,6 +37,10 @@ exports.getExtension = require_utils_getExtension.getExtension;
|
|
|
36
37
|
exports.getPackageJsonPath = require_utils_getPackageJsonPath.getPackageJsonPath;
|
|
37
38
|
exports.getProjectRequire = require_utils_ESMxCJSHelpers.getProjectRequire;
|
|
38
39
|
exports.getStorageAttributes = require_utils_getStorageAttributes.getStorageAttributes;
|
|
40
|
+
exports.getUnusedNodeTypes = require_utils_getUsedNodeTypes.getUnusedNodeTypes;
|
|
41
|
+
exports.getUnusedNodeTypesAsync = require_utils_getUsedNodeTypes.getUnusedNodeTypesAsync;
|
|
42
|
+
exports.getUsedNodeTypes = require_utils_getUsedNodeTypes.getUsedNodeTypes;
|
|
43
|
+
exports.getUsedNodeTypesAsync = require_utils_getUsedNodeTypes.getUsedNodeTypesAsync;
|
|
39
44
|
exports.isESModule = require_utils_ESMxCJSHelpers.isESModule;
|
|
40
45
|
exports.kebabCaseToCamelCase = require_utils_stringFormatter_kebabCaseToCamelCase.kebabCaseToCamelCase;
|
|
41
46
|
exports.logStack = require_utils_logStack.logStack;
|
|
@@ -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.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;;AA0E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,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;CAOjC,eAAe,qBAAqB,iBAAiB;CACtD;;;;;;;AAQD,MAAa,sBACX,wBACkB;CAClB,M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,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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/envVars/envVars.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a list of unused NodeType keys into env-var definitions.
|
|
4
|
+
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* formatNodeTypeToEnvVar(['enumeration'])
|
|
8
|
+
* // { 'INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
9
|
+
*
|
|
10
|
+
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
11
|
+
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
12
|
+
*/
|
|
13
|
+
const formatNodeTypeToEnvVar = (nodeTypes, addProcessEnv = false) => nodeTypes.reduce((acc, nodeType) => {
|
|
14
|
+
acc[addProcessEnv ? `process.env.INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}` : `INTLAYER_NODE_TYPE_${nodeType.toUpperCase()}`] = "\"false\"";
|
|
15
|
+
return acc;
|
|
16
|
+
}, {});
|
|
17
|
+
/**
|
|
18
|
+
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
19
|
+
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
20
|
+
* rewrite logic, storage mechanisms, and editor code.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* getConfigEnvVars(config)
|
|
24
|
+
* // { INTLAYER_ROUTING_MODE: '"prefix-no-default"', INTLAYER_ROUTING_REWRITE_RULES: '"false"', ... }
|
|
25
|
+
*
|
|
26
|
+
* getConfigEnvVars(config, true)
|
|
27
|
+
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
28
|
+
*/
|
|
29
|
+
const getConfigEnvVars = (config, addProcessEnv = false) => {
|
|
30
|
+
const prefix = addProcessEnv ? "process.env." : "";
|
|
31
|
+
const { routing, editor } = config;
|
|
32
|
+
const envVars = { [`${prefix}INTLAYER_ROUTING_MODE`]: JSON.stringify(routing.mode) };
|
|
33
|
+
if (!routing.rewrite) envVars[`${prefix}INTLAYER_ROUTING_REWRITE_RULES`] = "\"false\"";
|
|
34
|
+
if (routing.storage.cookies.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_COOKIES`] = "\"false\"";
|
|
35
|
+
if (routing.storage.localStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_LOCALSTORAGE`] = "\"false\"";
|
|
36
|
+
if (routing.storage.sessionStorage.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_SESSIONSTORAGE`] = "\"false\"";
|
|
37
|
+
if (routing.storage.headers.length === 0) envVars[`${prefix}INTLAYER_ROUTING_STORAGE_HEADERS`] = "\"false\"";
|
|
38
|
+
if (editor?.enabled === false) envVars[`${prefix}INTLAYER_EDITOR_ENABLED`] = "\"false\"";
|
|
39
|
+
return envVars;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
44
|
+
//# sourceMappingURL=envVars.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -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;SAClB;C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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,EAC9D,UAAU,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O,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,10 +1,10 @@
|
|
|
1
1
|
//#region src/utils/extractErrorMessage.ts
|
|
2
2
|
const extractErrorMessage = (error) => {
|
|
3
|
-
const trimToSingleLine = (text) => text.split(/\r?\n/).map((
|
|
3
|
+
const trimToSingleLine = (text) => text.split(/\r?\n/).map((stringValue) => stringValue.trim()).filter(Boolean)[0] ?? text.trim();
|
|
4
4
|
const looksLikeJson = (value) => {
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
7
|
-
const first =
|
|
5
|
+
const stringValue = value.trim();
|
|
6
|
+
if (!stringValue) return false;
|
|
7
|
+
const first = stringValue[0];
|
|
8
8
|
return first === "{" || first === "[" || first === "\"";
|
|
9
9
|
};
|
|
10
10
|
const sanitizeUnexpectedTokenMessage = (text) => {
|
|
@@ -21,6 +21,14 @@ const extractErrorMessage = (error) => {
|
|
|
21
21
|
if (!value || typeof value !== "object") return void 0;
|
|
22
22
|
if (seen.has(value)) return void 0;
|
|
23
23
|
seen.add(value);
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
for (const item of value) {
|
|
26
|
+
const fromItem = pickFieldsFromObject(item, seen);
|
|
27
|
+
if (fromItem) return fromItem;
|
|
28
|
+
if (typeof item?.message === "string") return item.message;
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
24
32
|
const obj = value;
|
|
25
33
|
if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
|
|
26
34
|
if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractErrorMessage.mjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((
|
|
1
|
+
{"version":3,"file":"extractErrorMessage.mjs","names":[],"sources":["../../../src/utils/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((stringValue) => stringValue.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const stringValue = value.trim();\n\n if (!stringValue) return false;\n const first = stringValue[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n\n if (seen.has(value)) return undefined;\n\n seen.add(value);\n\n // If the value itself is an array (e.g. ZodError.issues), iterate its items\n\n if (Array.isArray(value)) {\n for (const item of value) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n return undefined;\n }\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n\n if (fromItem) return fromItem;\n\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n\n if (picked) return picked;\n\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":";AAAA,MAAa,uBAAuB,UAA2B;CAC7D,MAAM,oBAAoB,SACxB,KACG,MAAM,QAAQ,CACd,KAAK,gBAAgB,YAAY,MAAM,CAAC,CACxC,OAAO,QAAQ,CAAC,MAAM,KAAK,MAAM;CAEtC,MAAM,iBAAiB,UAA2B;EAChD,MAAM,cAAc,MAAM,MAAM;AAEhC,MAAI,CAAC,YAAa,QAAO;EACzB,MAAM,QAAQ,YAAY;AAC1B,SAAO,UAAU,OAAO,UAAU,OAAO,UAAU;;CAGrD,MAAM,kCAAkC,SAAyB;EAE/D,MAAM,IAAI,KAAK,MAAM;AAErB,MAAI,oBAAoB,KAAK,EAAE,IAAI,kBAAkB,KAAK,EAAE,EAAE;GAC5D,MAAM,SAAS,EAAE,MAAM,YAAY;AAEnC,OAAI,SAAS,GAAI,QAAO,OAAO;GAE/B,MAAM,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC,MAAM;AAEzD,OAAI,WAAY,QAAO;;AAEzB,SAAO;;CAGT,MAAM,wBACJ,OACA,SACuB;AACvB,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAEhD,MAAI,KAAK,IAAI,MAAM,CAAE,QAAO;AAE5B,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+
const collectNodeTypes = (value, result) => {
|
|
6
|
+
if (!value || typeof value !== "object") return;
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
for (const item of value) collectNodeTypes(item, result);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const obj = value;
|
|
12
|
+
if (typeof obj.nodeType === "string") result.add(obj.nodeType);
|
|
13
|
+
for (const key of Object.keys(obj)) collectNodeTypes(obj[key], result);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Returns the set of NodeType strings actually used across the given
|
|
17
|
+
* built dictionaries.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const used = getUsedNodeTypes(getDictionaries(config));
|
|
21
|
+
* // Set { 'translation', 'enumeration' }
|
|
22
|
+
*/
|
|
23
|
+
const getUsedNodeTypes = (dictionaries) => {
|
|
24
|
+
const result = /* @__PURE__ */ new Set();
|
|
25
|
+
const dicts = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
26
|
+
for (const dict of dicts) collectNodeTypes(dict.content, result);
|
|
27
|
+
return [...result];
|
|
28
|
+
};
|
|
29
|
+
const getUnusedNodeTypes = (dictionaries) => {
|
|
30
|
+
const usedNodeTypes = getUsedNodeTypes(dictionaries);
|
|
31
|
+
return PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
32
|
+
};
|
|
33
|
+
const getUsedNodeTypesAsync = async (dictionaries) => {
|
|
34
|
+
const dictionariesArray = Array.isArray(dictionaries) ? dictionaries : Object.values(dictionaries);
|
|
35
|
+
const results = await Promise.all(dictionariesArray.map(async (dictionary) => {
|
|
36
|
+
const result = /* @__PURE__ */ new Set();
|
|
37
|
+
collectNodeTypes(dictionary.content, result);
|
|
38
|
+
return result;
|
|
39
|
+
}));
|
|
40
|
+
const finalResult = /* @__PURE__ */ new Set();
|
|
41
|
+
for (const res of results) for (const val of res) finalResult.add(val);
|
|
42
|
+
return [...finalResult];
|
|
43
|
+
};
|
|
44
|
+
const getUnusedNodeTypesAsync = async (dictionaries) => {
|
|
45
|
+
const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);
|
|
46
|
+
return PLUGIN_NODE_TYPES.filter((nodeType) => !usedNodeTypes.includes(nodeType));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync };
|
|
51
|
+
//# sourceMappingURL=getUsedNodeTypes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUsedNodeTypes.mjs","names":[],"sources":["../../../src/utils/getUsedNodeTypes.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { PLUGIN_NODE_TYPES } from '@intlayer/types/nodeType';\n\nexport type PluginNodeType = (typeof PLUGIN_NODE_TYPES)[number];\n\n/** Recursively collect every `nodeType` string found in a value. */\nconst collectNodeTypes = (value: unknown, result: Set<string>): void => {\n if (!value || typeof value !== 'object') return;\n\n if (Array.isArray(value)) {\n for (const item of value) collectNodeTypes(item, result);\n return;\n }\n\n const obj = value as Record<string, unknown>;\n\n if (typeof obj.nodeType === 'string') {\n result.add(obj.nodeType);\n }\n\n for (const key of Object.keys(obj)) {\n collectNodeTypes(obj[key], result);\n }\n};\n\n/**\n * Returns the set of NodeType strings actually used across the given\n * built dictionaries.\n *\n * @example\n * const used = getUsedNodeTypes(getDictionaries(config));\n * // Set { 'translation', 'enumeration' }\n */\nexport const getUsedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const result = new Set<PluginNodeType>();\n const dicts = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n for (const dict of dicts) {\n collectNodeTypes(dict.content, result);\n }\n\n return [...result];\n};\n\nexport const getUnusedNodeTypes = (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): PluginNodeType[] => {\n const usedNodeTypes = getUsedNodeTypes(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n\nexport const getUsedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const dictionariesArray = Array.isArray(dictionaries)\n ? dictionaries\n : Object.values(dictionaries);\n\n const results = await Promise.all(\n dictionariesArray.map(async (dictionary) => {\n const result = new Set<PluginNodeType>();\n\n collectNodeTypes(dictionary.content, result as Set<string>);\n\n return result;\n })\n );\n\n const finalResult = new Set<PluginNodeType>();\n\n for (const res of results) {\n for (const val of res) {\n finalResult.add(val);\n }\n }\n\n return [...finalResult];\n};\n\nexport const getUnusedNodeTypesAsync = async (\n dictionaries: Record<string, Dictionary> | Dictionary[]\n): Promise<PluginNodeType[]> => {\n const usedNodeTypes = await getUsedNodeTypesAsync(dictionaries);\n\n return PLUGIN_NODE_TYPES.filter(\n (nodeType) => !usedNodeTypes.includes(nodeType)\n );\n};\n"],"mappings":";;;;AAMA,MAAM,oBAAoB,OAAgB,WAA8B;AACtE,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU;AAEzC,KAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,OAAK,MAAM,QAAQ,MAAO,kBAAiB,MAAM,OAAO;AACxD;;CAGF,MAAM,MAAM;AAEZ,KAAI,OAAO,IAAI,aAAa,SAC1B,QAAO,IAAI,IAAI,SAAS;AAG1B,MAAK,MAAM,OAAO,OAAO,KAAK,IAAI,CAChC,kBAAiB,IAAI,MAAM,OAAO;;;;;;;;;;AAYtC,MAAa,oBACX,iBACqB;CACrB,MAAM,yBAAS,IAAI,KAAqB;CACxC,MAAM,QAAQ,MAAM,QAAQ,aAAa,GACrC,eACA,OAAO,OAAO,aAAa;AAE/B,MAAK,MAAM,QAAQ,MACjB,kBAAiB,KAAK,SAAS,OAAO;AAGxC,QAAO,CAAC,GAAG,OAAO;;AAGpB,MAAa,sBACX,iBACqB;CACrB,MAAM,gBAAgB,iBAAiB,aAAa;AAEpD,QAAO,kBAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD;;AAGH,MAAa,wBAAwB,OACnC,iBAC8B;CAC9B,MAAM,oBAAoB,MAAM,QAAQ,aAAa,GACjD,eACA,OAAO,OAAO,aAAa;CAE/B,MAAM,UAAU,MAAM,QAAQ,IAC5B,kBAAkB,IAAI,OAAO,eAAe;EAC1C,MAAM,yBAAS,IAAI,KAAqB;AAExC,mBAAiB,WAAW,SAAS,OAAsB;AAE3D,SAAO;GACP,CACH;CAED,MAAM,8BAAc,IAAI,KAAqB;AAE7C,MAAK,MAAM,OAAO,QAChB,MAAK,MAAM,OAAO,IAChB,aAAY,IAAI,IAAI;AAIxB,QAAO,CAAC,GAAG,YAAY;;AAGzB,MAAa,0BAA0B,OACrC,iBAC8B;CAC9B,MAAM,gBAAgB,MAAM,sBAAsB,aAAa;AAE/D,QAAO,kBAAkB,QACtB,aAAa,CAAC,cAAc,SAAS,SAAS,CAChD"}
|
package/dist/esm/utils/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { clearModuleCache } from "./clearModuleCache.mjs";
|
|
|
9
9
|
import { compareVersions } from "./compareVersions.mjs";
|
|
10
10
|
import { extractErrorMessage } from "./extractErrorMessage.mjs";
|
|
11
11
|
import { getStorageAttributes } from "./getStorageAttributes.mjs";
|
|
12
|
+
import { getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync } from "./getUsedNodeTypes.mjs";
|
|
12
13
|
import { logStack } from "./logStack.mjs";
|
|
13
14
|
import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.mjs";
|
|
14
15
|
import { retryManager } from "./retryManager.mjs";
|
|
@@ -17,4 +18,4 @@ import { camelCaseToSentence } from "./stringFormatter/camelCaseToSentence.mjs";
|
|
|
17
18
|
import { kebabCaseToCamelCase } from "./stringFormatter/kebabCaseToCamelCase.mjs";
|
|
18
19
|
import { toLowerCamelCase } from "./stringFormatter/toLowerCamelCase.mjs";
|
|
19
20
|
|
|
20
|
-
export { cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
|
21
|
+
export { cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
|
@@ -20,9 +20,9 @@ declare const cookiesAttributesSchema: z.ZodObject<{
|
|
|
20
20
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
21
21
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
22
22
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
23
|
-
none: "none";
|
|
24
23
|
strict: "strict";
|
|
25
24
|
lax: "lax";
|
|
25
|
+
none: "none";
|
|
26
26
|
}>>;
|
|
27
27
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
28
28
|
}, z.core.$strip>;
|
|
@@ -47,9 +47,9 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
|
|
|
47
47
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
48
48
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
49
49
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
50
|
-
none: "none";
|
|
51
50
|
strict: "strict";
|
|
52
51
|
lax: "lax";
|
|
52
|
+
none: "none";
|
|
53
53
|
}>>;
|
|
54
54
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
55
55
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -72,9 +72,9 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
|
|
|
72
72
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
73
73
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
74
74
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
75
|
-
none: "none";
|
|
76
75
|
strict: "strict";
|
|
77
76
|
lax: "lax";
|
|
77
|
+
none: "none";
|
|
78
78
|
}>>;
|
|
79
79
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
80
80
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -155,9 +155,9 @@ declare const routingSchema: z.ZodObject<{
|
|
|
155
155
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
156
156
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
157
157
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
158
|
-
none: "none";
|
|
159
158
|
strict: "strict";
|
|
160
159
|
lax: "lax";
|
|
160
|
+
none: "none";
|
|
161
161
|
}>>;
|
|
162
162
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
163
163
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -180,9 +180,9 @@ declare const routingSchema: z.ZodObject<{
|
|
|
180
180
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
181
181
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
182
182
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
183
|
-
none: "none";
|
|
184
183
|
strict: "strict";
|
|
185
184
|
lax: "lax";
|
|
185
|
+
none: "none";
|
|
186
186
|
}>>;
|
|
187
187
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
188
188
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -349,9 +349,9 @@ declare const intlayerConfigSchema: z.ZodObject<{
|
|
|
349
349
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
350
350
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
351
351
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
352
|
-
none: "none";
|
|
353
352
|
strict: "strict";
|
|
354
353
|
lax: "lax";
|
|
354
|
+
none: "none";
|
|
355
355
|
}>>;
|
|
356
356
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
357
357
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -374,9 +374,9 @@ declare const intlayerConfigSchema: z.ZodObject<{
|
|
|
374
374
|
secure: z.ZodOptional<z.ZodBoolean>;
|
|
375
375
|
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
376
376
|
sameSite: z.ZodOptional<z.ZodEnum<{
|
|
377
|
-
none: "none";
|
|
378
377
|
strict: "strict";
|
|
379
378
|
lax: "lax";
|
|
379
|
+
none: "none";
|
|
380
380
|
}>>;
|
|
381
381
|
expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
|
|
382
382
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IntlayerConfig } from "@intlayer/types/config";
|
|
2
|
+
|
|
3
|
+
//#region src/envVars/envVars.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a list of unused NodeType keys into env-var definitions.
|
|
6
|
+
* Set to `"false"` so bundlers can eliminate the corresponding plugin code.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* formatNodeTypeToEnvVar(['enumeration'])
|
|
10
|
+
* // { 'INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
11
|
+
*
|
|
12
|
+
* formatNodeTypeToEnvVar(['enumeration'], true)
|
|
13
|
+
* // { 'process.env.INTLAYER_NODE_TYPE_ENUMERATION': '"false"' }
|
|
14
|
+
*/
|
|
15
|
+
declare const formatNodeTypeToEnvVar: (nodeTypes: string[], addProcessEnv?: boolean) => Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns env-var definitions for the full Intlayer config to be injected at
|
|
18
|
+
* build time. Allows bundlers to dead-code-eliminate unused routing modes,
|
|
19
|
+
* rewrite logic, storage mechanisms, and editor code.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* getConfigEnvVars(config)
|
|
23
|
+
* // { INTLAYER_ROUTING_MODE: '"prefix-no-default"', INTLAYER_ROUTING_REWRITE_RULES: '"false"', ... }
|
|
24
|
+
*
|
|
25
|
+
* getConfigEnvVars(config, true)
|
|
26
|
+
* // { 'process.env.INTLAYER_ROUTING_MODE': '"prefix-no-default"', ... }
|
|
27
|
+
*/
|
|
28
|
+
declare const getConfigEnvVars: (config: IntlayerConfig, addProcessEnv?: boolean) => Record<string, string>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { formatNodeTypeToEnvVar, getConfigEnvVars };
|
|
31
|
+
//# sourceMappingURL=envVars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
2
|
+
import { PLUGIN_NODE_TYPES } from "@intlayer/types/nodeType";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/getUsedNodeTypes.d.ts
|
|
5
|
+
type PluginNodeType = (typeof PLUGIN_NODE_TYPES)[number];
|
|
6
|
+
/**
|
|
7
|
+
* Returns the set of NodeType strings actually used across the given
|
|
8
|
+
* built dictionaries.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const used = getUsedNodeTypes(getDictionaries(config));
|
|
12
|
+
* // Set { 'translation', 'enumeration' }
|
|
13
|
+
*/
|
|
14
|
+
declare const getUsedNodeTypes: (dictionaries: Record<string, Dictionary> | Dictionary[]) => PluginNodeType[];
|
|
15
|
+
declare const getUnusedNodeTypes: (dictionaries: Record<string, Dictionary> | Dictionary[]) => PluginNodeType[];
|
|
16
|
+
declare const getUsedNodeTypesAsync: (dictionaries: Record<string, Dictionary> | Dictionary[]) => Promise<PluginNodeType[]>;
|
|
17
|
+
declare const getUnusedNodeTypesAsync: (dictionaries: Record<string, Dictionary> | Dictionary[]) => Promise<PluginNodeType[]>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { PluginNodeType, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync };
|
|
20
|
+
//# sourceMappingURL=getUsedNodeTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUsedNodeTypes.d.ts","names":[],"sources":["../../../src/utils/getUsedNodeTypes.ts"],"mappings":";;;;KAGY,cAAA,WAAyB,iBAAA;;AAArC;;;;;AA8BA;;cAAa,gBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,cAAA;AAAA,cAaU,kBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,cAAA;AAAA,cAQU,qBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,OAAA,CAAQ,cAAA;AAAA,cA0BE,uBAAA,GACX,YAAA,EAAc,MAAA,SAAe,UAAA,IAAc,UAAA,OAC1C,OAAA,CAAQ,cAAA"}
|
|
@@ -14,6 +14,7 @@ import { compareVersions } from "./compareVersions.js";
|
|
|
14
14
|
import { getExtension } from "./getExtension.js";
|
|
15
15
|
import { getPackageJsonPath } from "./getPackageJsonPath.js";
|
|
16
16
|
import { getStorageAttributes } from "./getStorageAttributes.js";
|
|
17
|
+
import { PluginNodeType, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync } from "./getUsedNodeTypes.js";
|
|
17
18
|
import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.js";
|
|
18
19
|
import { RetryManagerOptions, retryManager } from "./retryManager.js";
|
|
19
|
-
export { CacheKey, GetAliasOptions, RetryManagerOptions, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
|
20
|
+
export { CacheKey, GetAliasOptions, PluginNodeType, RetryManagerOptions, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, getUnusedNodeTypes, getUnusedNodeTypesAsync, getUsedNodeTypes, getUsedNodeTypesAsync, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
|
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": [
|
|
@@ -78,6 +78,11 @@
|
|
|
78
78
|
"require": "./dist/cjs/colors.cjs",
|
|
79
79
|
"import": "./dist/esm/colors.mjs"
|
|
80
80
|
},
|
|
81
|
+
"./envVars": {
|
|
82
|
+
"types": "./dist/types/envVars/index.d.ts",
|
|
83
|
+
"require": "./dist/cjs/envVars/index.cjs",
|
|
84
|
+
"import": "./dist/esm/envVars/index.mjs"
|
|
85
|
+
},
|
|
81
86
|
"./defaultValues": {
|
|
82
87
|
"types": "./dist/types/defaultValues/index.d.ts",
|
|
83
88
|
"require": "./dist/cjs/defaultValues/index.cjs",
|
|
@@ -108,6 +113,9 @@
|
|
|
108
113
|
"env": [
|
|
109
114
|
"./dist/types/loadEnvFile.d.ts"
|
|
110
115
|
],
|
|
116
|
+
"envVars": [
|
|
117
|
+
"./dist/types/envVars/index.d.ts"
|
|
118
|
+
],
|
|
111
119
|
"logger": [
|
|
112
120
|
"./dist/types/logger.d.ts"
|
|
113
121
|
],
|
|
@@ -144,7 +152,7 @@
|
|
|
144
152
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
145
153
|
},
|
|
146
154
|
"dependencies": {
|
|
147
|
-
"@intlayer/types": "8.6.
|
|
155
|
+
"@intlayer/types": "8.6.3",
|
|
148
156
|
"defu": "6.1.4",
|
|
149
157
|
"dotenv": "17.3.1",
|
|
150
158
|
"esbuild": "0.27.4",
|