@twin.org/node-core 0.9.4 → 0.9.5-next.2

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.
Files changed (52) hide show
  1. package/dist/es/builders/engineEnvBuilder.js +554 -378
  2. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  3. package/dist/es/builders/engineServerEnvBuilder.js +5 -2
  4. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  5. package/dist/es/builders/helper/envHelpers.js +40 -9
  6. package/dist/es/builders/helper/envHelpers.js.map +1 -1
  7. package/dist/es/cli.js +1 -1
  8. package/dist/es/cli.js.map +1 -1
  9. package/dist/es/commands/bootstrapDev.js +3 -3
  10. package/dist/es/commands/bootstrapDev.js.map +1 -1
  11. package/dist/es/commands/help.js +1 -1
  12. package/dist/es/commands/help.js.map +1 -1
  13. package/dist/es/commands/identityCreate.js +2 -2
  14. package/dist/es/commands/identityCreate.js.map +1 -1
  15. package/dist/es/commands/identityVerificationMethodCreate.js +2 -2
  16. package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -1
  17. package/dist/es/commands/userCreate.js +1 -1
  18. package/dist/es/commands/userCreate.js.map +1 -1
  19. package/dist/es/commands/vaultKeyCreate.js +1 -1
  20. package/dist/es/commands/vaultKeyCreate.js.map +1 -1
  21. package/dist/es/commands/vaultKeyImport.js +1 -1
  22. package/dist/es/commands/vaultKeyImport.js.map +1 -1
  23. package/dist/es/defaults.js +51 -0
  24. package/dist/es/defaults.js.map +1 -1
  25. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  26. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  27. package/dist/es/models/deprecatedEnvironmentVariableKeys.js +16 -0
  28. package/dist/es/models/deprecatedEnvironmentVariableKeys.js.map +1 -0
  29. package/dist/es/models/engineEnvironmentVariableKeys.js +26 -5
  30. package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -1
  31. package/dist/es/models/engineServerEnvironmentVariableKeys.js +1 -0
  32. package/dist/es/models/engineServerEnvironmentVariableKeys.js.map +1 -1
  33. package/dist/es/node.js +40 -21
  34. package/dist/es/node.js.map +1 -1
  35. package/dist/types/builders/engineEnvBuilder.d.ts +7 -0
  36. package/dist/types/builders/helper/envHelpers.d.ts +59 -2
  37. package/dist/types/defaults.d.ts +27 -0
  38. package/dist/types/models/IEngineEnvironmentVariables.d.ts +115 -18
  39. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
  40. package/dist/types/models/deprecatedEnvironmentVariableKeys.d.ts +7 -0
  41. package/docs/changelog.md +169 -0
  42. package/docs/reference/functions/isMailboxEnabled.md +20 -0
  43. package/docs/reference/index.md +6 -0
  44. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +221 -32
  45. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +8 -0
  46. package/docs/reference/variables/COMPONENT_FACTORY_TYPE_NAME.md +5 -0
  47. package/docs/reference/variables/DEFAULT_HEALTH_EXCLUDE_CLONE_COMPONENTS.md +9 -0
  48. package/docs/reference/variables/DEFAULT_TRACING_FACADE_COMPONENT_EXCLUDE_TYPES.md +8 -0
  49. package/docs/reference/variables/DEFAULT_TRACING_FACADE_FACTORIES.md +5 -0
  50. package/docs/reference/variables/TRACING_FACADE_NAME.md +5 -0
  51. package/locales/en.json +3 -1
  52. package/package.json +35 -34
package/dist/es/node.js CHANGED
@@ -1,8 +1,7 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- import { execSync } from "node:child_process";
4
3
  import path from "node:path";
5
- import { CLIDisplay } from "@twin.org/cli-core";
4
+ import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
6
5
  import { Coerce, EnvHelper, GeneralError, Guards, I18n, Is } from "@twin.org/core";
7
6
  import { ModuleHelper } from "@twin.org/modules";
8
7
  import * as dotenv from "dotenv";
@@ -13,6 +12,7 @@ import { commaSeparatedListToArray } from "./builders/helper/envHelpers.js";
13
12
  import { constructCliCommand, parseCommandLineArgs, registerCommands } from "./cli.js";
14
13
  import { getEnvDefaults } from "./defaults.js";
15
14
  import { BOOTSTRAP_DEV_ENVIRONMENT_VARIABLE_KEYS } from "./models/bootstrapDevEnvironmentVariableKeys.js";
15
+ import { DEPRECATED_ENVIRONMENT_VARIABLE_KEYS } from "./models/deprecatedEnvironmentVariableKeys.js";
16
16
  import { ENGINE_ENVIRONMENT_VARIABLE_KEYS } from "./models/engineEnvironmentVariableKeys.js";
17
17
  import { ENGINE_SERVER_ENVIRONMENT_VARIABLE_KEYS } from "./models/engineServerEnvironmentVariableKeys.js";
18
18
  import { ModuleProtocol } from "./models/moduleProtocol.js";
@@ -20,7 +20,6 @@ import { NODE_ENVIRONMENT_VARIABLE_KEYS } from "./models/nodeEnvironmentVariable
20
20
  import { start } from "./start.js";
21
21
  import { createModuleImportUrl, fileExists, getExecutionDirectory, getExtensionsCacheDir, getScriptDirectory, handleHttpsProtocol, handleNpmProtocol, initialiseLocales, loadJsonFile, loadTextFile, parseModuleProtocol, resolvePackageEntryPoint } from "./utils.js";
22
22
  const moduleCache = {};
23
- let npmRootCache;
24
23
  /**
25
24
  * Run the node.
26
25
  * @param nodeOptions Optional configuration options for running the server.
@@ -34,7 +33,7 @@ export async function run(nodeOptions, args) {
34
33
  nodeOptions ??= {};
35
34
  const serverInfo = {
36
35
  name: nodeOptions?.serverName ?? "TWIN Node",
37
- version: nodeOptions?.serverVersion ?? "0.9.4" // x-release-please-version
36
+ version: nodeOptions?.serverVersion ?? "0.9.5-next.2" // x-release-please-version
38
37
  };
39
38
  CLIDisplay.header(serverInfo.name, serverInfo.version, "đŸŒŠī¸ ");
40
39
  if (!Is.stringValue(nodeOptions?.executionDirectory)) {
@@ -107,7 +106,7 @@ export async function run(nodeOptions, args) {
107
106
  debugEnabled = Coerce.boolean(nodeEnvVars.debug) ?? debugEnabled;
108
107
  CLIDisplay.break();
109
108
  const startResult = await start(nodeOptions, nodeEngineConfig, nodeEnvVars, cliCommand, availableContextIdKeys);
110
- if (!Is.empty(startResult)) {
109
+ if (Is.notEmpty(startResult)) {
111
110
  showErrorDetails = false;
112
111
  let isShuttingDown = false;
113
112
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
@@ -152,6 +151,30 @@ function matchesPatternSet(camelKey, patternSet) {
152
151
  }
153
152
  return false;
154
153
  }
154
+ /**
155
+ * Report any environment variables which are still recognised but no longer used.
156
+ * @param envVars The already-converted camelCase env variables.
157
+ * @param prefix The prefix used for the environment variables (e.g. "TWIN_").
158
+ */
159
+ function warnDeprecatedEnvVarKeys(envVars, prefix) {
160
+ for (const camelKey of Object.keys(envVars)) {
161
+ const replacements = DEPRECATED_ENVIRONMENT_VARIABLE_KEYS.get(camelKey);
162
+ if (!Is.undefined(replacements)) {
163
+ const key = EnvHelper.jsonKeyToEnvVarKey(camelKey, prefix);
164
+ if (Is.arrayValue(replacements)) {
165
+ CLIDisplay.warning(I18n.formatMessage("warn.node.deprecatedEnvVar", {
166
+ key,
167
+ replacements: replacements
168
+ .map(replacement => EnvHelper.jsonKeyToEnvVarKey(replacement, prefix))
169
+ .join(", ")
170
+ }));
171
+ }
172
+ else {
173
+ CLIDisplay.warning(I18n.formatMessage("warn.node.deprecatedEnvVarNoReplacement", { key }));
174
+ }
175
+ }
176
+ }
177
+ }
155
178
  /**
156
179
  * Validate that every key in envVars maps to a recognised property.
157
180
  * All unknown keys are collected, then reported together as a single error or warning.
@@ -171,7 +194,8 @@ function validateEnvVarKeys(envVars, prefix, allowSets) {
171
194
  const customSet = new Set(commaSeparatedListToArray(envVars.envAllowList).map(k => EnvHelper.envVarKeyToJsonKey(k.trim(), prefix)));
172
195
  const unknown = Object.keys(envVars)
173
196
  .filter(camelKey => !allowSets.some(set => matchesPatternSet(camelKey, set)) &&
174
- !matchesPatternSet(camelKey, customSet))
197
+ !matchesPatternSet(camelKey, customSet) &&
198
+ !DEPRECATED_ENVIRONMENT_VARIABLE_KEYS.has(camelKey))
175
199
  .map(camelKey => EnvHelper.jsonKeyToEnvVarKey(camelKey, prefix));
176
200
  if (unknown.length > 0) {
177
201
  if (mode === "error") {
@@ -217,6 +241,7 @@ export async function buildConfiguration(processEnv, options, serverInfo) {
217
241
  }
218
242
  }
219
243
  const envVars = EnvHelper.envToJson(processEnv, options.envPrefix ?? "");
244
+ warnDeprecatedEnvVarKeys(envVars, options.envPrefix ?? "");
220
245
  validateEnvVarKeys(envVars, options.envPrefix ?? "", [
221
246
  ENGINE_ENVIRONMENT_VARIABLE_KEYS,
222
247
  ENGINE_SERVER_ENVIRONMENT_VARIABLE_KEYS,
@@ -314,13 +339,15 @@ export function overrideModuleImport(executionDirectory, envVars) {
314
339
  }
315
340
  case ModuleProtocol.Default: {
316
341
  try {
317
- const packagePath = path.resolve(getNpmRootPath(), moduleName);
318
- const mainFile = await resolvePackageEntryPoint(packagePath, moduleName);
319
- const modulePath = path.resolve(packagePath, mainFile);
320
- const exists = await fileExists(modulePath);
321
- if (exists) {
322
- resolvedPath = modulePath;
323
- break;
342
+ const packagePath = await CLIUtils.findPackageRoot(moduleName, executionDirectory);
343
+ if (Is.stringValue(packagePath)) {
344
+ const mainFile = await resolvePackageEntryPoint(packagePath, moduleName);
345
+ const modulePath = path.resolve(packagePath, mainFile);
346
+ const exists = await fileExists(modulePath);
347
+ if (exists) {
348
+ resolvedPath = modulePath;
349
+ break;
350
+ }
324
351
  }
325
352
  }
326
353
  catch {
@@ -358,12 +385,4 @@ export function overrideModuleImport(executionDirectory, envVars) {
358
385
  };
359
386
  });
360
387
  }
361
- /**
362
- * Get the root path for npm modules by executing "npm root" command and cache it.
363
- * @returns The root path for npm modules.
364
- */
365
- function getNpmRootPath() {
366
- npmRootCache ??= execSync("npm root").toString().trim().replace(/\\/g, "/");
367
- return npmRootCache;
368
- }
369
388
  //# sourceMappingURL=node.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,gC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CAAC;wBACZ,YAAY,GAAG,UAAU,CAAC;oBAC3B,CAAC;gBACF,CAAC;gBAAC,MAAM,CAAC;oBACR,4CAA4C;gBAC7C,CAAC;gBACD,MAAM;YACP,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACjC,OAAO;gBACN,MAAM;gBACN,UAAU,EAAE,KAAK;aACjB,CAAC;QACH,CAAC;QAED,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACtB,YAAY,KAAK,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5E,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { IServerInfo } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { Coerce, EnvHelper, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { Engine } from \"@twin.org/engine\";\nimport type { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport * as dotenv from \"dotenv\";\nimport { buildEngineConfiguration } from \"./builders/engineEnvBuilder.js\";\nimport { buildEngineServerConfiguration } from \"./builders/engineServerEnvBuilder.js\";\nimport { extensionsConfiguration } from \"./builders/extensionsBuilder.js\";\nimport { commaSeparatedListToArray } from \"./builders/helper/envHelpers.js\";\nimport { constructCliCommand, parseCommandLineArgs, registerCommands } from \"./cli.js\";\nimport { getEnvDefaults } from \"./defaults.js\";\nimport { BOOTSTRAP_DEV_ENVIRONMENT_VARIABLE_KEYS } from \"./models/bootstrapDevEnvironmentVariableKeys.js\";\nimport { ENGINE_ENVIRONMENT_VARIABLE_KEYS } from \"./models/engineEnvironmentVariableKeys.js\";\nimport { ENGINE_SERVER_ENVIRONMENT_VARIABLE_KEYS } from \"./models/engineServerEnvironmentVariableKeys.js\";\nimport type { IEnvironmentVariables } from \"./models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\nimport { ModuleProtocol } from \"./models/moduleProtocol.js\";\nimport { NODE_ENVIRONMENT_VARIABLE_KEYS } from \"./models/nodeEnvironmentVariableKeys.js\";\nimport { start } from \"./start.js\";\nimport {\n\tcreateModuleImportUrl,\n\tfileExists,\n\tgetExecutionDirectory,\n\tgetExtensionsCacheDir,\n\tgetScriptDirectory,\n\thandleHttpsProtocol,\n\thandleNpmProtocol,\n\tinitialiseLocales,\n\tloadJsonFile,\n\tloadTextFile,\n\tparseModuleProtocol,\n\tresolvePackageEntryPoint\n} from \"./utils.js\";\n\nconst moduleCache: { [id: string]: unknown } = {};\nlet npmRootCache: string | undefined;\n\n/**\n * Run the node.\n * @param nodeOptions Optional configuration options for running the server.\n * @param args Optional command line arguments.\n * @returns A promise that resolves when the server is started containing a shutdown method.\n */\nexport async function run(\n\tnodeOptions?: INodeOptions,\n\targs?: string[]\n): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\tlet showErrorDetails = true;\n\tlet debugEnabled = true;\n\ttry {\n\t\tnodeOptions ??= {};\n\n\t\tconst serverInfo: IServerInfo = {\n\t\t\tname: nodeOptions?.serverName ?? \"TWIN Node\",\n\t\t\tversion: nodeOptions?.serverVersion ?? \"0.9.4\" // x-release-please-version\n\t\t};\n\n\t\tCLIDisplay.header(serverInfo.name, serverInfo.version, \"đŸŒŠī¸ \");\n\n\t\tif (!Is.stringValue(nodeOptions?.executionDirectory)) {\n\t\t\tnodeOptions.executionDirectory = getExecutionDirectory();\n\t\t}\n\t\tCLIDisplay.value(\"Execution Directory\", nodeOptions.executionDirectory);\n\n\t\tif (!Is.stringValue(nodeOptions?.scriptDirectory)) {\n\t\t\tnodeOptions.scriptDirectory = getScriptDirectory(args);\n\t\t}\n\t\tCLIDisplay.value(\"Script Directory\", nodeOptions.scriptDirectory);\n\n\t\tnodeOptions.localesDirectory =\n\t\t\tnodeOptions?.localesDirectory ??\n\t\t\tpath.resolve(path.join(nodeOptions.scriptDirectory, \"dist\", \"locales\"));\n\n\t\tCLIDisplay.value(\"Locales Directory\", nodeOptions.localesDirectory);\n\t\tawait initialiseLocales(nodeOptions.localesDirectory);\n\n\t\tnodeOptions.envPrefix ??= \"TWIN_\";\n\n\t\toverrideModuleImport(nodeOptions.executionDirectory ?? \"\");\n\n\t\tconst commandLineArgs = parseCommandLineArgs(args);\n\n\t\tconst hasEnvPrefix = commandLineArgs.options?.find(option => option.key === \"env-prefix\");\n\t\tif (hasEnvPrefix) {\n\t\t\tnodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;\n\t\t}\n\n\t\tCLIDisplay.value(\"Environment Variable Prefix\", nodeOptions.envPrefix);\n\n\t\t// This is the only location in the code base that should access process.env directly\n\t\t// So we can safely disable the linting rule here.\n\t\tlet finalEnvVars =\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tprocess.env as {\n\t\t\t\t[id: string]: string;\n\t\t\t};\n\n\t\tif (Is.objectValue(nodeOptions?.envVars)) {\n\t\t\tfinalEnvVars = {\n\t\t\t\t...finalEnvVars,\n\t\t\t\t...nodeOptions.envVars\n\t\t\t};\n\t\t}\n\n\t\tfinalEnvVars = {\n\t\t\t...getEnvDefaults(nodeOptions.envPrefix),\n\t\t\t...finalEnvVars\n\t\t};\n\n\t\tlet cliCommand;\n\t\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\t\tregisterCommands();\n\t\t\tcliCommand = constructCliCommand(finalEnvVars, commandLineArgs);\n\t\t}\n\n\t\tif (Is.object(cliCommand)) {\n\t\t\tfinalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= \"true\";\n\t\t} else {\n\t\t\tif (Is.empty(nodeOptions?.openApiSpecFile)) {\n\t\t\t\tconst specFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"docs\", \"open-api\", \"spec.json\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(specFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.openApiSpecFile = specFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.openApiSpecFile)) {\n\t\t\t\tCLIDisplay.value(\"OpenAPI Spec File\", nodeOptions.openApiSpecFile);\n\t\t\t}\n\n\t\t\tif (Is.empty(nodeOptions?.favIconFile)) {\n\t\t\t\tconst favIconFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"static\", \"favicon.png\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(favIconFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.favIconFile = favIconFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.favIconFile)) {\n\t\t\t\tCLIDisplay.value(\"Favicon File\", nodeOptions.favIconFile);\n\t\t\t}\n\t\t}\n\n\t\tconst { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(\n\t\t\tfinalEnvVars,\n\t\t\tnodeOptions,\n\t\t\tserverInfo\n\t\t);\n\n\t\tdebugEnabled = Coerce.boolean(nodeEnvVars.debug) ?? debugEnabled;\n\n\t\tCLIDisplay.break();\n\n\t\tconst startResult = await start(\n\t\t\tnodeOptions,\n\t\t\tnodeEngineConfig,\n\t\t\tnodeEnvVars,\n\t\t\tcliCommand,\n\t\t\tavailableContextIdKeys\n\t\t);\n\n\t\tif (!Is.empty(startResult)) {\n\t\t\tshowErrorDetails = false;\n\n\t\t\tlet isShuttingDown = false;\n\t\t\tfor (const signal of [\"SIGHUP\", \"SIGINT\", \"SIGTERM\"]) {\n\t\t\t\tprocess.on(signal, async () => {\n\t\t\t\t\tif (!isShuttingDown) {\n\t\t\t\t\t\tisShuttingDown = true;\n\t\t\t\t\t\tCLIDisplay.value(\"Terminate Signal\", signal);\n\t\t\t\t\t\tawait startResult.shutdown();\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn startResult;\n\t} catch (err) {\n\t\tif (nodeOptions?.disableProcessExitOnFailure ?? false) {\n\t\t\tthrow err;\n\t\t}\n\n\t\tif (showErrorDetails) {\n\t\t\tCLIDisplay.error(err, true, { includeAdditional: true, includeStack: debugEnabled });\n\t\t}\n\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Test whether a camelCase key matches an entry in a pattern set.\n * Entries ending with \"*\" are treated as prefix patterns; all others require an exact match.\n * @param camelKey The camelCase key to test.\n * @param patternSet The set of exact keys and/or wildcard patterns (e.g. \"restPath*\").\n * @returns True if the key matches any entry.\n */\nfunction matchesPatternSet(\n\tcamelKey: string,\n\tpatternSet: ReadonlySet<string> | Set<string>\n): boolean {\n\tif (patternSet.has(camelKey)) {\n\t\treturn true;\n\t}\n\tfor (const pattern of patternSet) {\n\t\tif (pattern.endsWith(\"*\") && camelKey.startsWith(pattern.slice(0, -1))) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Validate that every key in envVars maps to a recognised property.\n * All unknown keys are collected, then reported together as a single error or warning.\n * Raw env var names listed in the allow list (e.g. TWIN_MY_EXTENSION_SECRET, TWIN_REST_PATH_*) are always accepted.\n * Wildcard patterns ending with * are supported in both allow sets and the allow list.\n * @param envVars The already-converted camelCase env variables.\n * @param prefix The prefix used for the environment variables (e.g. \"TWIN_\").\n * @param allowSets An array of sets of allowed keys and/or wildcard patterns.\n * @throws GeneralError If any unknown env var properties are found and strict mode is \"error\", or if the strict mode value is invalid.\n */\nfunction validateEnvVarKeys(\n\tenvVars: { [id: string]: string | unknown },\n\tprefix: string,\n\tallowSets: ReadonlySet<string>[]\n): void {\n\tconst mode = Is.stringValue(envVars.strictEnv) ? envVars.strictEnv : \"error\";\n\tGuards.arrayOneOf(\"node\", `${prefix}STRICT_ENV`, mode, [\"error\", \"warn\", \"ignore\"]);\n\n\tif (mode === \"ignore\") {\n\t\treturn;\n\t}\n\n\tconst customSet = new Set(\n\t\tcommaSeparatedListToArray<string>(envVars.envAllowList as string).map(k =>\n\t\t\tEnvHelper.envVarKeyToJsonKey(k.trim(), prefix)\n\t\t)\n\t);\n\n\tconst unknown = Object.keys(envVars)\n\t\t.filter(\n\t\t\tcamelKey =>\n\t\t\t\t!allowSets.some(set => matchesPatternSet(camelKey, set)) &&\n\t\t\t\t!matchesPatternSet(camelKey, customSet)\n\t\t)\n\t\t.map(camelKey => EnvHelper.jsonKeyToEnvVarKey(camelKey, prefix));\n\n\tif (unknown.length > 0) {\n\t\tif (mode === \"error\") {\n\t\t\tthrow new GeneralError(\"node\", \"unknownEnvVars\", { keys: unknown.join(\", \"), prefix });\n\t\t}\n\t\tCLIDisplay.warning(\n\t\t\tI18n.formatMessage(\"warn.node.unknownEnvVars\", { keys: unknown.join(\", \"), prefix })\n\t\t);\n\t}\n}\n\n/**\n * Build the configuration for the TWIN Node.\n * @param processEnv The environment variables from the process.\n * @param options The options for running the server.\n * @param serverInfo The server information.\n * @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,\n * and options.\n */\nexport async function buildConfiguration(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: INodeOptions,\n\tserverInfo: IServerInfo\n): Promise<{\n\tnodeEnvVars: IEnvironmentVariables & { [id: string]: string | unknown };\n\tnodeEngineConfig: INodeEngineConfig;\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[];\n}> {\n\tconst availableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] = [];\n\n\tlet defaultEnvOnly = false;\n\tif (Is.empty(options?.envFilenames)) {\n\t\tconst envFile = path.resolve(path.join(options.executionDirectory ?? \"\", \".env\"));\n\t\tCLIDisplay.value(\"Default Environment File\", envFile);\n\t\toptions ??= {};\n\t\toptions.envFilenames = [envFile];\n\t\tdefaultEnvOnly = true;\n\t}\n\n\tif (Is.arrayValue(options?.envFilenames)) {\n\t\tconst output = dotenv.config({\n\t\t\tpath: options?.envFilenames,\n\t\t\tquiet: true\n\t\t});\n\n\t\t// We don't want to throw an error if the default environment file is not found.\n\t\t// Only if we have custom environment files.\n\t\tif (!defaultEnvOnly && output.error) {\n\t\t\tthrow output.error;\n\t\t}\n\n\t\tif (Is.objectValue(output.parsed)) {\n\t\t\tfor (const [key, value] of Object.entries(output.parsed)) {\n\t\t\t\t// Only set environment variables that are not already set in\n\t\t\t\t// the process environment or provided via options.envVars\n\t\t\t\tprocessEnv[key] ??= value;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst envVars = EnvHelper.envToJson<{ [id: string]: string | unknown }>(\n\t\tprocessEnv,\n\t\toptions.envPrefix ?? \"\"\n\t);\n\n\tvalidateEnvVarKeys(envVars, options.envPrefix ?? \"\", [\n\t\tENGINE_ENVIRONMENT_VARIABLE_KEYS,\n\t\tENGINE_SERVER_ENVIRONMENT_VARIABLE_KEYS,\n\t\tNODE_ENVIRONMENT_VARIABLE_KEYS,\n\t\tBOOTSTRAP_DEV_ENVIRONMENT_VARIABLE_KEYS\n\t]);\n\n\t// Expand any environment variables that use the @file: syntax\n\tconst keys = Object.keys(envVars);\n\tfor (const key of keys) {\n\t\tif (\n\t\t\tIs.stringValue(envVars[key]) &&\n\t\t\t(envVars[key].startsWith(\"@text:\") || envVars[key].startsWith(\"@json:\"))\n\t\t) {\n\t\t\tconst filePath = envVars[key].slice(6).trim();\n\t\t\tconst embeddedFile = path.resolve(path.join(options.executionDirectory ?? \"\", filePath));\n\n\t\t\tif (envVars[key].startsWith(\"@text:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from text file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadTextFile(embeddedFile);\n\t\t\t} else if (envVars[key].startsWith(\"@json:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from JSON file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadJsonFile(embeddedFile);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extend the environment variables with any additional custom configuration.\n\tif (Is.function(options?.extendEnvVars)) {\n\t\tCLIDisplay.task(\"Extending Environment Variables\");\n\t\tawait options.extendEnvVars(envVars);\n\t}\n\n\t// Build the engine configuration from the environment variables.\n\tconst coreConfig = await buildEngineConfiguration(envVars);\n\tconst engineServerConfig = await buildEngineServerConfiguration(\n\t\tenvVars,\n\t\tavailableContextIdKeys,\n\t\tcoreConfig,\n\t\tserverInfo,\n\t\toptions?.openApiSpecFile,\n\t\toptions?.favIconFile\n\t);\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.arrayValue(options?.configFilenames)) {\n\t\tfor (const configFile of options.configFilenames) {\n\t\t\tCLIDisplay.value(\"Loading Configuration File\", configFile);\n\t\t\tconst configFilePath = path.resolve(path.join(options.executionDirectory ?? \"\", configFile));\n\t\t\tconst config = await loadJsonFile(configFilePath);\n\t\t\tObject.assign(engineServerConfig, config);\n\t\t}\n\t}\n\n\tif (Is.objectValue(options?.config)) {\n\t\tCLIDisplay.task(\"Merging Custom Configuration\");\n\t\tObject.assign(engineServerConfig, options.config);\n\t}\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.function(options?.extendConfig)) {\n\t\tCLIDisplay.task(\"Extending Configuration\");\n\t\tawait options.extendConfig(envVars, engineServerConfig);\n\t}\n\n\tconst nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);\n\n\treturn { nodeEngineConfig, nodeEnvVars: envVars, availableContextIdKeys };\n}\n\n/**\n * Override module imports to support protocol-based loading (npm:, https:) and local files.\n * @param executionDirectory The execution directory for resolving local module paths.\n * @param envVars The environment variables containing extension configuration (optional, uses defaults if not provided).\n */\nexport function overrideModuleImport(\n\texecutionDirectory: string,\n\tenvVars?: IEnvironmentVariables\n): void {\n\tconst maxSizeMb = Coerce.number(envVars?.extensionsMaxSizeMb) ?? 10;\n\tconst cacheDirectory = envVars?.extensionsCacheDirectory;\n\n\tModuleHelper.overrideImport(async moduleName => {\n\t\tif (moduleCache[moduleName]) {\n\t\t\treturn {\n\t\t\t\tmodule: moduleCache[moduleName],\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\tconst parsed = parseModuleProtocol(moduleName);\n\t\tlet resolvedPath: string | undefined;\n\n\t\tswitch (parsed.protocol) {\n\t\t\tcase ModuleProtocol.Npm: {\n\t\t\t\tconst result = await handleNpmProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tcacheDirectory\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Https: {\n\t\t\t\tconst result = await handleHttpsProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tmaxSizeMb,\n\t\t\t\t\tcacheDirectory,\n\t\t\t\t\tenvVars?.extensionsCacheTtlHours,\n\t\t\t\t\tenvVars?.extensionsForceRefresh\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Http: {\n\t\t\t\tthrow new GeneralError(\"node\", \"insecureProtocol\", { protocol: ModuleProtocol.Http });\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Local: {\n\t\t\t\tlet localFilename = path.resolve(moduleName);\n\n\t\t\t\tlet exists = await fileExists(localFilename);\n\t\t\t\tif (!exists) {\n\t\t\t\t\tlocalFilename = path.resolve(executionDirectory, moduleName);\n\t\t\t\t\texists = await fileExists(localFilename);\n\t\t\t\t}\n\n\t\t\t\tif (exists) {\n\t\t\t\t\tresolvedPath = localFilename;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Default: {\n\t\t\t\ttry {\n\t\t\t\t\tconst packagePath = path.resolve(getNpmRootPath(), moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Continue to fallback resolution\n\t\t\t\t}\n\n\t\t\t\t// Fallback: resolve from npm protocol cache directory (installed via handleNpmProtocol)\n\t\t\t\ttry {\n\t\t\t\t\tconst cacheNpmRoot = path.resolve(\n\t\t\t\t\t\tgetExtensionsCacheDir(executionDirectory, ModuleProtocol.Npm, cacheDirectory),\n\t\t\t\t\t\t\"node_modules\"\n\t\t\t\t\t);\n\n\t\t\t\t\tconst packagePath = path.resolve(cacheNpmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// No cached resolution either; fall through\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Common module loading and caching logic\n\t\tif (resolvedPath) {\n\t\t\tconst module = await import(createModuleImportUrl(resolvedPath));\n\t\t\tmoduleCache[moduleName] = module;\n\t\t\treturn {\n\t\t\t\tmodule,\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tmodule: undefined,\n\t\t\tuseDefault: true\n\t\t};\n\t});\n}\n\n/**\n * Get the root path for npm modules by executing \"npm root\" command and cache it.\n * @returns The root path for npm modules.\n */\nfunction getNpmRootPath(): string {\n\tnpmRootCache ??= execSync(\"npm root\").toString().trim().replace(/\\\\/g, \"/\");\n\treturn npmRootCache;\n}\n"]}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAInF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,M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AE,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,EAC7E,cAAc,CACd,CAAC;oBAEF,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;oBAC3D,MAAM,QAAQ,GAAG,MAAM,wBAAwB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;oBACzE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;oBACvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE,CAAC;wBACZ,YAAY,GAAG,UAAU,CAAC;oBAC3B,CAAC;gBACF,CAAC;gBAAC,MAAM,CAAC;oBACR,4CAA4C;gBAC7C,CAAC;gBACD,MAAM;YACP,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACjC,OAAO;gBACN,MAAM;gBACN,UAAU,EAAE,KAAK;aACjB,CAAC;QACH,CAAC;QAED,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport type { IServerInfo } from \"@twin.org/api-models\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Coerce, EnvHelper, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { Engine } from \"@twin.org/engine\";\nimport type { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport * as dotenv from \"dotenv\";\nimport { buildEngineConfiguration } from \"./builders/engineEnvBuilder.js\";\nimport { buildEngineServerConfiguration } from \"./builders/engineServerEnvBuilder.js\";\nimport { extensionsConfiguration } from \"./builders/extensionsBuilder.js\";\nimport { commaSeparatedListToArray } from \"./builders/helper/envHelpers.js\";\nimport { constructCliCommand, parseCommandLineArgs, registerCommands } from \"./cli.js\";\nimport { getEnvDefaults } from \"./defaults.js\";\nimport { BOOTSTRAP_DEV_ENVIRONMENT_VARIABLE_KEYS } from \"./models/bootstrapDevEnvironmentVariableKeys.js\";\nimport { DEPRECATED_ENVIRONMENT_VARIABLE_KEYS } from \"./models/deprecatedEnvironmentVariableKeys.js\";\nimport { ENGINE_ENVIRONMENT_VARIABLE_KEYS } from \"./models/engineEnvironmentVariableKeys.js\";\nimport { ENGINE_SERVER_ENVIRONMENT_VARIABLE_KEYS } from \"./models/engineServerEnvironmentVariableKeys.js\";\nimport type { IEnvironmentVariables } from \"./models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\nimport { ModuleProtocol } from \"./models/moduleProtocol.js\";\nimport { NODE_ENVIRONMENT_VARIABLE_KEYS } from \"./models/nodeEnvironmentVariableKeys.js\";\nimport { start } from \"./start.js\";\nimport {\n\tcreateModuleImportUrl,\n\tfileExists,\n\tgetExecutionDirectory,\n\tgetExtensionsCacheDir,\n\tgetScriptDirectory,\n\thandleHttpsProtocol,\n\thandleNpmProtocol,\n\tinitialiseLocales,\n\tloadJsonFile,\n\tloadTextFile,\n\tparseModuleProtocol,\n\tresolvePackageEntryPoint\n} from \"./utils.js\";\n\nconst moduleCache: { [id: string]: unknown } = {};\n\n/**\n * Run the node.\n * @param nodeOptions Optional configuration options for running the server.\n * @param args Optional command line arguments.\n * @returns A promise that resolves when the server is started containing a shutdown method.\n */\nexport async function run(\n\tnodeOptions?: INodeOptions,\n\targs?: string[]\n): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\tlet showErrorDetails = true;\n\tlet debugEnabled = true;\n\ttry {\n\t\tnodeOptions ??= {};\n\n\t\tconst serverInfo: IServerInfo = {\n\t\t\tname: nodeOptions?.serverName ?? \"TWIN Node\",\n\t\t\tversion: nodeOptions?.serverVersion ?? \"0.9.5-next.2\" // x-release-please-version\n\t\t};\n\n\t\tCLIDisplay.header(serverInfo.name, serverInfo.version, \"đŸŒŠī¸ \");\n\n\t\tif (!Is.stringValue(nodeOptions?.executionDirectory)) {\n\t\t\tnodeOptions.executionDirectory = getExecutionDirectory();\n\t\t}\n\t\tCLIDisplay.value(\"Execution Directory\", nodeOptions.executionDirectory);\n\n\t\tif (!Is.stringValue(nodeOptions?.scriptDirectory)) {\n\t\t\tnodeOptions.scriptDirectory = getScriptDirectory(args);\n\t\t}\n\t\tCLIDisplay.value(\"Script Directory\", nodeOptions.scriptDirectory);\n\n\t\tnodeOptions.localesDirectory =\n\t\t\tnodeOptions?.localesDirectory ??\n\t\t\tpath.resolve(path.join(nodeOptions.scriptDirectory, \"dist\", \"locales\"));\n\n\t\tCLIDisplay.value(\"Locales Directory\", nodeOptions.localesDirectory);\n\t\tawait initialiseLocales(nodeOptions.localesDirectory);\n\n\t\tnodeOptions.envPrefix ??= \"TWIN_\";\n\n\t\toverrideModuleImport(nodeOptions.executionDirectory ?? \"\");\n\n\t\tconst commandLineArgs = parseCommandLineArgs(args);\n\n\t\tconst hasEnvPrefix = commandLineArgs.options?.find(option => option.key === \"env-prefix\");\n\t\tif (hasEnvPrefix) {\n\t\t\tnodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;\n\t\t}\n\n\t\tCLIDisplay.value(\"Environment Variable Prefix\", nodeOptions.envPrefix);\n\n\t\t// This is the only location in the code base that should access process.env directly\n\t\t// So we can safely disable the linting rule here.\n\t\tlet finalEnvVars =\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tprocess.env as {\n\t\t\t\t[id: string]: string;\n\t\t\t};\n\n\t\tif (Is.objectValue(nodeOptions?.envVars)) {\n\t\t\tfinalEnvVars = {\n\t\t\t\t...finalEnvVars,\n\t\t\t\t...nodeOptions.envVars\n\t\t\t};\n\t\t}\n\n\t\tfinalEnvVars = {\n\t\t\t...getEnvDefaults(nodeOptions.envPrefix),\n\t\t\t...finalEnvVars\n\t\t};\n\n\t\tlet cliCommand;\n\t\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\t\tregisterCommands();\n\t\t\tcliCommand = constructCliCommand(finalEnvVars, commandLineArgs);\n\t\t}\n\n\t\tif (Is.object(cliCommand)) {\n\t\t\tfinalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= \"true\";\n\t\t} else {\n\t\t\tif (Is.empty(nodeOptions?.openApiSpecFile)) {\n\t\t\t\tconst specFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"docs\", \"open-api\", \"spec.json\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(specFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.openApiSpecFile = specFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.openApiSpecFile)) {\n\t\t\t\tCLIDisplay.value(\"OpenAPI Spec File\", nodeOptions.openApiSpecFile);\n\t\t\t}\n\n\t\t\tif (Is.empty(nodeOptions?.favIconFile)) {\n\t\t\t\tconst favIconFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"static\", \"favicon.png\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(favIconFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.favIconFile = favIconFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.favIconFile)) {\n\t\t\t\tCLIDisplay.value(\"Favicon File\", nodeOptions.favIconFile);\n\t\t\t}\n\t\t}\n\n\t\tconst { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(\n\t\t\tfinalEnvVars,\n\t\t\tnodeOptions,\n\t\t\tserverInfo\n\t\t);\n\n\t\tdebugEnabled = Coerce.boolean(nodeEnvVars.debug) ?? debugEnabled;\n\n\t\tCLIDisplay.break();\n\n\t\tconst startResult = await start(\n\t\t\tnodeOptions,\n\t\t\tnodeEngineConfig,\n\t\t\tnodeEnvVars,\n\t\t\tcliCommand,\n\t\t\tavailableContextIdKeys\n\t\t);\n\n\t\tif (Is.notEmpty(startResult)) {\n\t\t\tshowErrorDetails = false;\n\n\t\t\tlet isShuttingDown = false;\n\t\t\tfor (const signal of [\"SIGHUP\", \"SIGINT\", \"SIGTERM\"]) {\n\t\t\t\tprocess.on(signal, async () => {\n\t\t\t\t\tif (!isShuttingDown) {\n\t\t\t\t\t\tisShuttingDown = true;\n\t\t\t\t\t\tCLIDisplay.value(\"Terminate Signal\", signal);\n\t\t\t\t\t\tawait startResult.shutdown();\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn startResult;\n\t} catch (err) {\n\t\tif (nodeOptions?.disableProcessExitOnFailure ?? false) {\n\t\t\tthrow err;\n\t\t}\n\n\t\tif (showErrorDetails) {\n\t\t\tCLIDisplay.error(err, true, { includeAdditional: true, includeStack: debugEnabled });\n\t\t}\n\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Test whether a camelCase key matches an entry in a pattern set.\n * Entries ending with \"*\" are treated as prefix patterns; all others require an exact match.\n * @param camelKey The camelCase key to test.\n * @param patternSet The set of exact keys and/or wildcard patterns (e.g. \"restPath*\").\n * @returns True if the key matches any entry.\n */\nfunction matchesPatternSet(\n\tcamelKey: string,\n\tpatternSet: ReadonlySet<string> | Set<string>\n): boolean {\n\tif (patternSet.has(camelKey)) {\n\t\treturn true;\n\t}\n\tfor (const pattern of patternSet) {\n\t\tif (pattern.endsWith(\"*\") && camelKey.startsWith(pattern.slice(0, -1))) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Report any environment variables which are still recognised but no longer used.\n * @param envVars The already-converted camelCase env variables.\n * @param prefix The prefix used for the environment variables (e.g. \"TWIN_\").\n */\nfunction warnDeprecatedEnvVarKeys(\n\tenvVars: { [id: string]: string | unknown },\n\tprefix: string\n): void {\n\tfor (const camelKey of Object.keys(envVars)) {\n\t\tconst replacements = DEPRECATED_ENVIRONMENT_VARIABLE_KEYS.get(camelKey);\n\t\tif (!Is.undefined(replacements)) {\n\t\t\tconst key = EnvHelper.jsonKeyToEnvVarKey(camelKey, prefix);\n\n\t\t\tif (Is.arrayValue(replacements)) {\n\t\t\t\tCLIDisplay.warning(\n\t\t\t\t\tI18n.formatMessage(\"warn.node.deprecatedEnvVar\", {\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\treplacements: replacements\n\t\t\t\t\t\t\t.map(replacement => EnvHelper.jsonKeyToEnvVarKey(replacement, prefix))\n\t\t\t\t\t\t\t.join(\", \")\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tCLIDisplay.warning(I18n.formatMessage(\"warn.node.deprecatedEnvVarNoReplacement\", { key }));\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Validate that every key in envVars maps to a recognised property.\n * All unknown keys are collected, then reported together as a single error or warning.\n * Raw env var names listed in the allow list (e.g. TWIN_MY_EXTENSION_SECRET, TWIN_REST_PATH_*) are always accepted.\n * Wildcard patterns ending with * are supported in both allow sets and the allow list.\n * @param envVars The already-converted camelCase env variables.\n * @param prefix The prefix used for the environment variables (e.g. \"TWIN_\").\n * @param allowSets An array of sets of allowed keys and/or wildcard patterns.\n * @throws GeneralError If any unknown env var properties are found and strict mode is \"error\", or if the strict mode value is invalid.\n */\nfunction validateEnvVarKeys(\n\tenvVars: { [id: string]: string | unknown },\n\tprefix: string,\n\tallowSets: ReadonlySet<string>[]\n): void {\n\tconst mode = Is.stringValue(envVars.strictEnv) ? envVars.strictEnv : \"error\";\n\tGuards.arrayOneOf(\"node\", `${prefix}STRICT_ENV`, mode, [\"error\", \"warn\", \"ignore\"]);\n\n\tif (mode === \"ignore\") {\n\t\treturn;\n\t}\n\n\tconst customSet = new Set(\n\t\tcommaSeparatedListToArray<string>(envVars.envAllowList as string).map(k =>\n\t\t\tEnvHelper.envVarKeyToJsonKey(k.trim(), prefix)\n\t\t)\n\t);\n\n\tconst unknown = Object.keys(envVars)\n\t\t.filter(\n\t\t\tcamelKey =>\n\t\t\t\t!allowSets.some(set => matchesPatternSet(camelKey, set)) &&\n\t\t\t\t!matchesPatternSet(camelKey, customSet) &&\n\t\t\t\t!DEPRECATED_ENVIRONMENT_VARIABLE_KEYS.has(camelKey)\n\t\t)\n\t\t.map(camelKey => EnvHelper.jsonKeyToEnvVarKey(camelKey, prefix));\n\n\tif (unknown.length > 0) {\n\t\tif (mode === \"error\") {\n\t\t\tthrow new GeneralError(\"node\", \"unknownEnvVars\", { keys: unknown.join(\", \"), prefix });\n\t\t}\n\t\tCLIDisplay.warning(\n\t\t\tI18n.formatMessage(\"warn.node.unknownEnvVars\", { keys: unknown.join(\", \"), prefix })\n\t\t);\n\t}\n}\n\n/**\n * Build the configuration for the TWIN Node.\n * @param processEnv The environment variables from the process.\n * @param options The options for running the server.\n * @param serverInfo The server information.\n * @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,\n * and options.\n */\nexport async function buildConfiguration(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: INodeOptions,\n\tserverInfo: IServerInfo\n): Promise<{\n\tnodeEnvVars: IEnvironmentVariables & { [id: string]: string | unknown };\n\tnodeEngineConfig: INodeEngineConfig;\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[];\n}> {\n\tconst availableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] = [];\n\n\tlet defaultEnvOnly = false;\n\tif (Is.empty(options?.envFilenames)) {\n\t\tconst envFile = path.resolve(path.join(options.executionDirectory ?? \"\", \".env\"));\n\t\tCLIDisplay.value(\"Default Environment File\", envFile);\n\t\toptions ??= {};\n\t\toptions.envFilenames = [envFile];\n\t\tdefaultEnvOnly = true;\n\t}\n\n\tif (Is.arrayValue(options?.envFilenames)) {\n\t\tconst output = dotenv.config({\n\t\t\tpath: options?.envFilenames,\n\t\t\tquiet: true\n\t\t});\n\n\t\t// We don't want to throw an error if the default environment file is not found.\n\t\t// Only if we have custom environment files.\n\t\tif (!defaultEnvOnly && output.error) {\n\t\t\tthrow output.error;\n\t\t}\n\n\t\tif (Is.objectValue(output.parsed)) {\n\t\t\tfor (const [key, value] of Object.entries(output.parsed)) {\n\t\t\t\t// Only set environment variables that are not already set in\n\t\t\t\t// the process environment or provided via options.envVars\n\t\t\t\tprocessEnv[key] ??= value;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst envVars = EnvHelper.envToJson<{ [id: string]: string | unknown }>(\n\t\tprocessEnv,\n\t\toptions.envPrefix ?? \"\"\n\t);\n\n\twarnDeprecatedEnvVarKeys(envVars, options.envPrefix ?? \"\");\n\n\tvalidateEnvVarKeys(envVars, options.envPrefix ?? \"\", [\n\t\tENGINE_ENVIRONMENT_VARIABLE_KEYS,\n\t\tENGINE_SERVER_ENVIRONMENT_VARIABLE_KEYS,\n\t\tNODE_ENVIRONMENT_VARIABLE_KEYS,\n\t\tBOOTSTRAP_DEV_ENVIRONMENT_VARIABLE_KEYS\n\t]);\n\n\t// Expand any environment variables that use the @file: syntax\n\tconst keys = Object.keys(envVars);\n\tfor (const key of keys) {\n\t\tif (\n\t\t\tIs.stringValue(envVars[key]) &&\n\t\t\t(envVars[key].startsWith(\"@text:\") || envVars[key].startsWith(\"@json:\"))\n\t\t) {\n\t\t\tconst filePath = envVars[key].slice(6).trim();\n\t\t\tconst embeddedFile = path.resolve(path.join(options.executionDirectory ?? \"\", filePath));\n\n\t\t\tif (envVars[key].startsWith(\"@text:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from text file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadTextFile(embeddedFile);\n\t\t\t} else if (envVars[key].startsWith(\"@json:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from JSON file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadJsonFile(embeddedFile);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extend the environment variables with any additional custom configuration.\n\tif (Is.function(options?.extendEnvVars)) {\n\t\tCLIDisplay.task(\"Extending Environment Variables\");\n\t\tawait options.extendEnvVars(envVars);\n\t}\n\n\t// Build the engine configuration from the environment variables.\n\tconst coreConfig = await buildEngineConfiguration(envVars);\n\tconst engineServerConfig = await buildEngineServerConfiguration(\n\t\tenvVars,\n\t\tavailableContextIdKeys,\n\t\tcoreConfig,\n\t\tserverInfo,\n\t\toptions?.openApiSpecFile,\n\t\toptions?.favIconFile\n\t);\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.arrayValue(options?.configFilenames)) {\n\t\tfor (const configFile of options.configFilenames) {\n\t\t\tCLIDisplay.value(\"Loading Configuration File\", configFile);\n\t\t\tconst configFilePath = path.resolve(path.join(options.executionDirectory ?? \"\", configFile));\n\t\t\tconst config = await loadJsonFile(configFilePath);\n\t\t\tObject.assign(engineServerConfig, config);\n\t\t}\n\t}\n\n\tif (Is.objectValue(options?.config)) {\n\t\tCLIDisplay.task(\"Merging Custom Configuration\");\n\t\tObject.assign(engineServerConfig, options.config);\n\t}\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.function(options?.extendConfig)) {\n\t\tCLIDisplay.task(\"Extending Configuration\");\n\t\tawait options.extendConfig(envVars, engineServerConfig);\n\t}\n\n\tconst nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);\n\n\treturn { nodeEngineConfig, nodeEnvVars: envVars, availableContextIdKeys };\n}\n\n/**\n * Override module imports to support protocol-based loading (npm:, https:) and local files.\n * @param executionDirectory The execution directory for resolving local module paths.\n * @param envVars The environment variables containing extension configuration (optional, uses defaults if not provided).\n */\nexport function overrideModuleImport(\n\texecutionDirectory: string,\n\tenvVars?: IEnvironmentVariables\n): void {\n\tconst maxSizeMb = Coerce.number(envVars?.extensionsMaxSizeMb) ?? 10;\n\tconst cacheDirectory = envVars?.extensionsCacheDirectory;\n\n\tModuleHelper.overrideImport(async moduleName => {\n\t\tif (moduleCache[moduleName]) {\n\t\t\treturn {\n\t\t\t\tmodule: moduleCache[moduleName],\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\tconst parsed = parseModuleProtocol(moduleName);\n\t\tlet resolvedPath: string | undefined;\n\n\t\tswitch (parsed.protocol) {\n\t\t\tcase ModuleProtocol.Npm: {\n\t\t\t\tconst result = await handleNpmProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tcacheDirectory\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Https: {\n\t\t\t\tconst result = await handleHttpsProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tmaxSizeMb,\n\t\t\t\t\tcacheDirectory,\n\t\t\t\t\tenvVars?.extensionsCacheTtlHours,\n\t\t\t\t\tenvVars?.extensionsForceRefresh\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Http: {\n\t\t\t\tthrow new GeneralError(\"node\", \"insecureProtocol\", { protocol: ModuleProtocol.Http });\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Local: {\n\t\t\t\tlet localFilename = path.resolve(moduleName);\n\n\t\t\t\tlet exists = await fileExists(localFilename);\n\t\t\t\tif (!exists) {\n\t\t\t\t\tlocalFilename = path.resolve(executionDirectory, moduleName);\n\t\t\t\t\texists = await fileExists(localFilename);\n\t\t\t\t}\n\n\t\t\t\tif (exists) {\n\t\t\t\t\tresolvedPath = localFilename;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Default: {\n\t\t\t\ttry {\n\t\t\t\t\tconst packagePath = await CLIUtils.findPackageRoot(moduleName, executionDirectory);\n\t\t\t\t\tif (Is.stringValue(packagePath)) {\n\t\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\t\tif (exists) {\n\t\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Continue to fallback resolution\n\t\t\t\t}\n\n\t\t\t\t// Fallback: resolve from npm protocol cache directory (installed via handleNpmProtocol)\n\t\t\t\ttry {\n\t\t\t\t\tconst cacheNpmRoot = path.resolve(\n\t\t\t\t\t\tgetExtensionsCacheDir(executionDirectory, ModuleProtocol.Npm, cacheDirectory),\n\t\t\t\t\t\t\"node_modules\"\n\t\t\t\t\t);\n\n\t\t\t\t\tconst packagePath = path.resolve(cacheNpmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// No cached resolution either; fall through\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Common module loading and caching logic\n\t\tif (resolvedPath) {\n\t\t\tconst module = await import(createModuleImportUrl(resolvedPath));\n\t\t\tmoduleCache[moduleName] = module;\n\t\t\treturn {\n\t\t\t\tmodule,\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tmodule: undefined,\n\t\t\tuseDefault: true\n\t\t};\n\t});\n}\n"]}
@@ -72,3 +72,10 @@ export declare function isTelemetryEnabled(envVars: IEngineEnvironmentVariables)
72
72
  * @returns True if tracing is enabled.
73
73
  */
74
74
  export declare function isTracingEnabled(envVars: IEngineEnvironmentVariables): boolean;
75
+ /**
76
+ * Checks if the mailbox subsystem is enabled.
77
+ * Returns true when any component that depends on the mailbox subsystem is enabled.
78
+ * @param envVars The environment variables.
79
+ * @returns True if mailbox is enabled.
80
+ */
81
+ export declare function isMailboxEnabled(envVars: IEngineEnvironmentVariables): boolean;
@@ -1,3 +1,23 @@
1
+ /**
2
+ * Returns an env var as a string when it holds a non-empty value, falling back to the supplied default.
3
+ * @param envVars The environment variables object.
4
+ * @param key The property name of the env var to read.
5
+ * @param defaultValue The value to return when the env var is absent or empty. Omit to return undefined when absent.
6
+ * @returns The string value, the default, or undefined when absent and no default given.
7
+ */
8
+ export declare function envString<T>(envVars: T, key: keyof T, defaultValue: string): string;
9
+ export declare function envString<T>(envVars: T, key: keyof T): string | undefined;
10
+ /**
11
+ * Returns an env var constrained to one of the supplied choices, falling back to the supplied default.
12
+ * @param envVars The environment variables object.
13
+ * @param key The property name of the env var to read.
14
+ * @param choices The permitted values for the env var.
15
+ * @param defaultValue The value to return when the env var is absent or empty. Omit to return undefined when absent.
16
+ * @returns The matching choice, the default, or undefined when absent and no default given.
17
+ * @throws GeneralError if the value is set but is not one of the choices.
18
+ */
19
+ export declare function envChoice<T, U extends string>(envVars: T, key: keyof T, choices: readonly U[], defaultValue: U): U;
20
+ export declare function envChoice<T, U extends string>(envVars: T, key: keyof T, choices: readonly U[]): U | undefined;
1
21
  /**
2
22
  * Coerces an env var to a boolean, falling back to the supplied default when not set.
3
23
  * @param envVars The environment variables object.
@@ -104,6 +124,7 @@ export declare function envDateTime<T>(envVars: T, key: keyof T, defaultValue: s
104
124
  export declare function envDateTime<T>(envVars: T, key: keyof T): string | undefined;
105
125
  /**
106
126
  * Coerces an env var to an integer and converts from seconds to milliseconds.
127
+ * Values of zero or less are returned unchanged so sentinels such as -1 keep their meaning.
107
128
  * @param envVars The environment variables object.
108
129
  * @param key The property name of the env var to coerce.
109
130
  * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
@@ -114,6 +135,7 @@ export declare function envSecToMs<T>(envVars: T, key: keyof T, defaultValue: nu
114
135
  export declare function envSecToMs<T>(envVars: T, key: keyof T): number | undefined;
115
136
  /**
116
137
  * Coerces an env var to an integer and converts from minutes to milliseconds.
138
+ * Values of zero or less are returned unchanged so sentinels such as -1 keep their meaning.
117
139
  * @param envVars The environment variables object.
118
140
  * @param key The property name of the env var to coerce.
119
141
  * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
@@ -122,13 +144,48 @@ export declare function envSecToMs<T>(envVars: T, key: keyof T): number | undefi
122
144
  */
123
145
  export declare function envMinToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;
124
146
  export declare function envMinToMs<T>(envVars: T, key: keyof T): number | undefined;
147
+ /**
148
+ * Converts a comma separated list to an array.
149
+ * @param envVars The environment variables object.
150
+ * @param key The property name of the env var.
151
+ * @param expectedValues An optional array of expected values.
152
+ * @throws GeneralError if the list contains a value not in the expected values.
153
+ * @returns The array, empty when the env var is absent.
154
+ */
155
+ export declare function envListToArray<T, U>(envVars: T, key: keyof T, expectedValues?: U[]): U[];
156
+ /**
157
+ * Converts a comma separated list to an array.
158
+ * @param envVars The environment variables object.
159
+ * @param key The property name of the env var.
160
+ * @param expectedValues An optional array of expected values.
161
+ * @param defaultValue The default value to return when the list is empty or undefined.
162
+ * @throws GeneralError if the list contains a value not in the expected values.
163
+ * @returns The array, or the default when the env var is absent.
164
+ */
165
+ export declare function envListToArray<T, U>(envVars: T, key: keyof T, expectedValues: U[] | undefined, defaultValue: U[]): U[];
166
+ /**
167
+ * Converts a comma separated list to an array.
168
+ * @param envVars The environment variables object.
169
+ * @param key The property name of the env var.
170
+ * @param expectedValues An optional array of expected values.
171
+ * @param defaultValue The default value to return when the list is empty or undefined.
172
+ * @throws GeneralError if the list contains a value not in the expected values.
173
+ * @returns The array, or the default when the env var is absent, which may be undefined.
174
+ */
175
+ export declare function envListToArray<T, U>(envVars: T, key: keyof T, expectedValues: U[] | undefined, defaultValue: U[] | undefined): U[] | undefined;
176
+ /**
177
+ * Converts a comma separated list to an array.
178
+ * @param value The comma separated list.
179
+ * @returns The array, empty when the list is empty or undefined.
180
+ */
181
+ export declare function commaSeparatedListToArray<U>(value: string | undefined): U[];
125
182
  /**
126
183
  * Converts a comma separated list to an array.
127
184
  * @param value The comma separated list.
128
185
  * @param defaultValue The default value to return when the list is empty or undefined.
129
- * @returns The array.
186
+ * @returns The array, or the default when the list is empty or undefined.
130
187
  */
131
- export declare function commaSeparatedListToArray<U>(value: string | undefined, defaultValue?: U[] | undefined): U[];
188
+ export declare function commaSeparatedListToArray<U>(value: string | undefined, defaultValue: U[] | undefined): U[] | undefined;
132
189
  /**
133
190
  * Gets named key integer pairs from an env var holding comma separated key=integer pairs.
134
191
  * @param envVars The environment variables object.
@@ -26,6 +26,33 @@ export declare const CONTEXT_ID_HANDLER_FEATURE_DID = "did";
26
26
  * Feature tag identifying the tenant context ID handler.
27
27
  */
28
28
  export declare const CONTEXT_ID_HANDLER_FEATURE_TENANT = "tenant";
29
+ /**
30
+ * The default component types excluded from the engine clone used by the application health
31
+ * background task. Each entry is a regular expression matched against the engine config type keys.
32
+ * None of the components in these groups implement healthApplication, and nothing that does
33
+ * implement it depends on them, so keeping them out of the clone removes the cost of constructing
34
+ * and starting them in the health worker.
35
+ */
36
+ export declare const DEFAULT_HEALTH_EXCLUDE_CLONE_COMPONENTS: string[];
37
+ /**
38
+ * The name the tracing facade is registered with in the facade factory
39
+ */
40
+ export declare const TRACING_FACADE_NAME = "tracing-facade";
41
+ /**
42
+ * The type name of the component factory.
43
+ */
44
+ export declare const COMPONENT_FACTORY_TYPE_NAME = "component";
45
+ /**
46
+ * The default factories the tracing facade is activated on.
47
+ */
48
+ export declare const DEFAULT_TRACING_FACADE_FACTORIES: string[];
49
+ /**
50
+ * The instance types the tracing facade is never applied to in the component factory, matched as
51
+ * regular expressions anywhere in the type name. The facade resolves the tracing and logging
52
+ * components while recording a span, so wrapping those results in an endless call chain. The
53
+ * remaining patterns cover the high volume infrastructure services whose spans carry little value.
54
+ */
55
+ export declare const DEFAULT_TRACING_FACADE_COMPONENT_EXCLUDE_TYPES: string[];
29
56
  /**
30
57
  * Get the default environment variables for the node.
31
58
  * @param envPrefix The environment variable prefix.
@@ -441,9 +441,9 @@ export interface IEngineEnvironmentVariables {
441
441
  */
442
442
  eventBusComponent?: string;
443
443
  /**
444
- * Are the messaging components enabled, defaults to false.
444
+ * The email protocol connector types, comma-separated: pop3, imap, gmail, outlook.
445
445
  */
446
- messagingEnabled?: string;
446
+ emailProtocolConnector?: string;
447
447
  /**
448
448
  * AWS SES region.
449
449
  */
@@ -469,9 +469,29 @@ export interface IEngineEnvironmentVariables {
469
469
  */
470
470
  awsMessagingPushNotificationApplications?: string;
471
471
  /**
472
- * The type of messaging email connector: entity-storage, aws.
472
+ * The type of messaging email connector: entity-storage, aws, smtp.
473
473
  */
474
474
  messagingEmailConnector?: string;
475
+ /**
476
+ * SMTP server hostname or IP address.
477
+ */
478
+ smtpHost?: string;
479
+ /**
480
+ * SMTP server port, defaults to 587.
481
+ */
482
+ smtpPort?: string;
483
+ /**
484
+ * Whether the SMTP connector uses TLS.
485
+ */
486
+ smtpSecure?: string;
487
+ /**
488
+ * SMTP authentication username.
489
+ */
490
+ smtpUsername?: string;
491
+ /**
492
+ * SMTP authentication password.
493
+ */
494
+ smtpPassword?: string;
475
495
  /**
476
496
  * The type of messaging sms connector: entity-storage, aws.
477
497
  */
@@ -526,9 +546,24 @@ export interface IEngineEnvironmentVariables {
526
546
  */
527
547
  telemetryMaxCacheSize?: string;
528
548
  /**
529
- * The mutex timeout in milliseconds for the telemetry connector.
549
+ * How long in milliseconds the telemetry connector waits for its background thread to confirm
550
+ * a flush before a read continues without it.
551
+ * @default 30000
552
+ */
553
+ telemetryFlushTimeout?: string;
554
+ /**
555
+ * How long in milliseconds the telemetry connector holds values so several share a single
556
+ * background task, instead of creating one task per value. Set to 0 to disable coalescing.
557
+ * @default 1000
530
558
  */
531
- telemetryMutexTimeout?: string;
559
+ telemetryTaskCoalesce?: string;
560
+ /**
561
+ * How long in milliseconds the telemetry connector allows with tasks outstanding and none of
562
+ * them completing before its background thread is treated as stalled and replaced. Set to 0
563
+ * to disable the check.
564
+ * @default 60000
565
+ */
566
+ telemetryTaskStallTimeout?: string;
532
567
  /**
533
568
  * The maximum number of metric definitions held in the in-memory definition cache for the telemetry connector.
534
569
  * @default 100
@@ -544,9 +579,47 @@ export interface IEngineEnvironmentVariables {
544
579
  */
545
580
  tracingSilentComponents?: string;
546
581
  /**
547
- * The type of tracing connector, comma-separated for multiple: entity-storage, open-telemetry, silent.
582
+ * The type of tracing connector, comma-separated for multiple: entity-storage, open-telemetry, console, silent.
548
583
  */
549
584
  tracingConnector?: string;
585
+ /**
586
+ * The type of facade to activate, comma-separated for multiple: tracing. When this is not set no
587
+ * facades are activated.
588
+ */
589
+ facade?: string;
590
+ /**
591
+ * The factories the tracing facade is activated on, as a comma separated list of factory type names
592
+ * e.g. "component,vault", replacing the default set rather than adding to it. Only applies when the
593
+ * tracing facade is activated.
594
+ */
595
+ tracingFacadeFactories?: string;
596
+ /**
597
+ * Additional instance types the tracing facade is not applied to in the component factory, as a comma
598
+ * separated list of regular expressions matched anywhere in the type name e.g. "^my-tracing-service$".
599
+ * These extend the types which are always excluded, "tracing", "telemetry", "metrics", "logging" and
600
+ * "platform", they do not replace them.
601
+ */
602
+ tracingFacadeComponentExcludeTypes?: string;
603
+ /**
604
+ * Additional parameter names the tracing facade does not record, as a comma separated list
605
+ * e.g. "ssn,accountNumber". These extend the names which are always excluded, they do not
606
+ * replace them.
607
+ */
608
+ tracingFacadeExcludeParams?: string;
609
+ /**
610
+ * Additional method names the tracing facade does not record a span for, as a comma separated
611
+ * list e.g. "health,ping". These extend the names which are always excluded, they do not
612
+ * replace them.
613
+ */
614
+ tracingFacadeExcludeMethods?: string;
615
+ /**
616
+ * The object values the tracing facade records, as a comma separated list of patterns matched
617
+ * against the end of "parameter" or "parameter.property", where the returned value is named
618
+ * "resolved" e.g. "filter.id,resolved.id". Naming the parameter records the whole object
619
+ * including any secrets it holds, naming a property records only that property. Object
620
+ * parameters and returned objects are omitted unless matched here.
621
+ */
622
+ tracingFacadeIncludeObjects?: string;
550
623
  /**
551
624
  * The name of the Open Telemetry tracer to use, only required if using open-telemetry as tracing connector, defaults to twin-node.
552
625
  */
@@ -563,10 +636,6 @@ export interface IEngineEnvironmentVariables {
563
636
  * The span processor: batch (default) or simple. Only used when TWIN_TRACING_CONNECTOR=open-telemetry.
564
637
  */
565
638
  openTelemetryTracingProcessor?: string;
566
- /**
567
- * The mutex timeout in milliseconds for the tracing connector.
568
- */
569
- tracingMutexTimeout?: string;
570
639
  /**
571
640
  * The type of faucet connector: entity-storage, iota.
572
641
  */
@@ -687,6 +756,12 @@ export interface IEngineEnvironmentVariables {
687
756
  * @default 10080
688
757
  */
689
758
  immutableProofTaskFailureRetainFor?: string;
759
+ /**
760
+ * How long in seconds the proof task worker stays idle before it shuts down.
761
+ * Set to 0 to shut it down after every task, or -1 to never shut it down.
762
+ * @default 60
763
+ */
764
+ immutableProofTaskWorkerIdleTimeout?: string;
690
765
  /**
691
766
  * How often in minutes the immutable proof reconciliation sweep runs.
692
767
  * @default 30
@@ -724,10 +799,6 @@ export interface IEngineEnvironmentVariables {
724
799
  * The identity verification method id to use with attestation.
725
800
  */
726
801
  attestationVerificationMethodId?: string;
727
- /**
728
- * Is the data processing enabled, defaults to false.
729
- */
730
- dataProcessingEnabled?: string;
731
802
  /**
732
803
  * The type of the default data converters, can be a comma separated list: json, xml.
733
804
  */
@@ -947,6 +1018,36 @@ export interface IEngineEnvironmentVariables {
947
1018
  * The interval in seconds for running the application health lifecycle (init, application, teardown), defaults to 300.
948
1019
  */
949
1020
  healthApplicationInterval?: string;
1021
+ /**
1022
+ * Comma separated list of regular expressions matched against the engine component type keys,
1023
+ * any which match are excluded from the engine clone used by the application health background
1024
+ * task. Defaults to the component groups which provide no application health checks.
1025
+ */
1026
+ healthExcludeCloneComponents?: string;
1027
+ /**
1028
+ * The maximum number of workers to use for processing background tasks, defaults to twice the number of CPU cores.
1029
+ */
1030
+ backgroundTaskMaxSystemWorkerCount?: string;
1031
+ /**
1032
+ * The interval in milliseconds to leave between background tasks, defaults to 100.
1033
+ */
1034
+ backgroundTaskInterval?: string;
1035
+ /**
1036
+ * The interval in milliseconds to leave between background task retries, defaults to 5000.
1037
+ */
1038
+ backgroundTaskRetryInterval?: string;
1039
+ /**
1040
+ * The interval in milliseconds between sweeps removing retained background tasks, defaults to 120000.
1041
+ */
1042
+ backgroundTaskCleanupInterval?: string;
1043
+ /**
1044
+ * The time in milliseconds to wait for each handler's workers to shut down before terminating them, defaults to 5000.
1045
+ */
1046
+ backgroundTaskWorkerShutdownTimeout?: string;
1047
+ /**
1048
+ * The maximum dispatches of a background task attempt before it is failed as interrupted, defaults to 3, set to -1 for no limit.
1049
+ */
1050
+ backgroundTaskMaxDispatchCount?: string;
950
1051
  /**
951
1052
  * The type of the automation action to create, comma separate for more than one connector.
952
1053
  * values: fetch
@@ -972,10 +1073,6 @@ export interface IEngineEnvironmentVariables {
972
1073
  * The mutex timeout in milliseconds for the document management component.
973
1074
  */
974
1075
  documentManagementMutexTimeout?: string;
975
- /**
976
- * The mutex timeout in milliseconds for the logging component.
977
- */
978
- loggingMutexTimeout?: string;
979
1076
  /**
980
1077
  * The mutex timeout in milliseconds for the memory and file entity storage connectors.
981
1078
  */
@@ -34,6 +34,10 @@ export interface IEngineServerEnvironmentVariables {
34
34
  * The public origin URL for the API e.g. https://api.example.com:1234
35
35
  */
36
36
  publicOrigin?: string;
37
+ /**
38
+ * The time in milliseconds Fastify waits for a plugin to load before failing, defaults to 30000.
39
+ */
40
+ fastifyPluginTimeout?: string;
37
41
  /**
38
42
  * The type of auth admin processor to use on the API: entity-storage.
39
43
  */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The camelCase property names which are no longer used, mapped to the keys which replace them.
3
+ * They are still recognised so an existing configuration does not fail validation, but each one
4
+ * reports a deprecation warning and has no effect on the engine configuration.
5
+ * An empty array is a key which has been withdrawn with nothing to replace it.
6
+ */
7
+ export declare const DEPRECATED_ENVIRONMENT_VARIABLE_KEYS: ReadonlyMap<string, readonly string[]>;