@twin.org/node-core 0.9.2-next.9 → 0.9.3-next.1

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 (38) hide show
  1. package/dist/es/builders/engineEnvBuilder.js +162 -83
  2. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  3. package/dist/es/builders/engineServerEnvBuilder.js +50 -14
  4. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  5. package/dist/es/builders/extensionsBuilder.js +5 -4
  6. package/dist/es/builders/extensionsBuilder.js.map +1 -1
  7. package/dist/es/builders/helper/envHelpers.js +60 -74
  8. package/dist/es/builders/helper/envHelpers.js.map +1 -1
  9. package/dist/es/cli.js +2 -1
  10. package/dist/es/cli.js.map +1 -1
  11. package/dist/es/commands/bootstrapDev.js +5 -5
  12. package/dist/es/commands/bootstrapDev.js.map +1 -1
  13. package/dist/es/commands/userCreate.js +8 -3
  14. package/dist/es/commands/userCreate.js.map +1 -1
  15. package/dist/es/commands/userUpdate.js +5 -2
  16. package/dist/es/commands/userUpdate.js.map +1 -1
  17. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  18. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  19. package/dist/es/models/engineEnvironmentVariableKeys.js +11 -0
  20. package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -1
  21. package/dist/es/models/engineServerEnvironmentVariableKeys.js +4 -1
  22. package/dist/es/models/engineServerEnvironmentVariableKeys.js.map +1 -1
  23. package/dist/es/node.js +3 -7
  24. package/dist/es/node.js.map +1 -1
  25. package/dist/es/start.js +3 -2
  26. package/dist/es/start.js.map +1 -1
  27. package/dist/types/builders/engineEnvBuilder.d.ts +9 -2
  28. package/dist/types/builders/helper/envHelpers.d.ts +81 -21
  29. package/dist/types/models/IEngineEnvironmentVariables.d.ts +49 -2
  30. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +12 -0
  31. package/docs/changelog.md +249 -0
  32. package/docs/reference/functions/{isTelemetryRequired.md → isTelemetryEnabled.md} +3 -3
  33. package/docs/reference/functions/isTracingEnabled.md +20 -0
  34. package/docs/reference/index.md +2 -1
  35. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +108 -2
  36. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +24 -0
  37. package/locales/en.json +1 -0
  38. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/start.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACN,iBAAiB,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EACN,0BAA0B,EAC1B,gCAAgC,EAChC,kBAAkB,EAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAQ1C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAC1B,WAAqC,EACrC,gBAAmC,EACnC,OAA4D,EAC5D,UAAwB,EACxB,sBAA6E;IAS7E,MAAM,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IACxF,MAAM,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAEpF,MAAM,qBAAqB,GAA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QACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;gBACzE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC5B,CAAC;QACF,CAAC;QACD,MAAM,GAAG,IAAI,CAAC;IACf,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAEjC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO;IACR,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QACpC,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC9C,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,uCAAuC,EAAE;gBAC3D,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;gBACvB,cAAc,EAAE,KAAK,CAAC,kBAAkB;aACxC,CAAC,CACF,CAAC;YACF,MAAM,oBAAoB,CAAC,MAAM,CAAC;gBACjC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;gBACjB,cAAc,EAAE,KAAK,CAAC,kBAAkB;aACxC,CAAC,CAAC;YACH,OAAO;QACR,CAAC;IACF,CAAC;IAED,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,8BAA8B,EAAE;QAC9D,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;KAChC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport { Engine } from \"@twin.org/engine\";\nimport { FileStateStorage } from \"@twin.org/engine-core\";\nimport {\n\tEngineCoreFactory,\n\ttype IEngineCore,\n\ttype IEngineCoreConfig\n} from \"@twin.org/engine-models\";\nimport { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { BlobStorageConnectorType, EntityStorageConnectorType } from \"@twin.org/engine-types\";\nimport {\n\textensionsInitialiseEngine,\n\textensionsInitialiseEngineServer,\n\tshutdownExtensions\n} from \"./builders/extensionsBuilder.js\";\nimport { executeCommand } from \"./cli.js\";\nimport type { ICliCommand } from \"./models/ICliCommand.js\";\nimport type { IEngineEnvironmentVariables } from \"./models/IEngineEnvironmentVariables.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\";\n\n/**\n * Start the engine server.\n * @param nodeOptions Optional run options for the engine server.\n * @param nodeEngineConfig The configuration for the engine server.\n * @param envVars The environment variables.\n * @param cliCommand The constructed CLI command (optional).\n * @param availableContextIdKeys The context ID keys available for operation.\n * @returns The engine server.\n */\nexport async function start(\n\tnodeOptions: INodeOptions | undefined,\n\tnodeEngineConfig: INodeEngineConfig,\n\tenvVars: IEnvironmentVariables & IEngineEnvironmentVariables,\n\tcliCommand?: ICliCommand,\n\tavailableContextIdKeys?: { key: string; requiredHandlerFeatures: 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\tconst entityStorageConnectorType = envVars.entityStorageConnectorType?.split(\",\") ?? [];\n\tconst blobStorageConnectorType = envVars.blobStorageConnectorType?.split(\",\") ?? [];\n\n\tconst requiresEngineStarted = cliCommand?.definition?.requiresEngineStarted ?? true;\n\tconst requiresNodeIdentity = cliCommand?.definition?.requiresNodeIdentity ?? true;\n\tconst requiresOrgIdentity = cliCommand?.definition?.requiresOrgIdentity ?? true;\n\n\t// File connectors (blob/entity) and the default file-based state storage all\n\t// persist to disk under storageFileRoot, so it must be set when any of them is in use.\n\tif (\n\t\t(entityStorageConnectorType.includes(EntityStorageConnectorType.File) ||\n\t\t\tblobStorageConnectorType.includes(BlobStorageConnectorType.File) ||\n\t\t\tIs.empty(nodeOptions?.stateStorage)) &&\n\t\t!Is.stringValue(envVars.storageFileRoot) &&\n\t\trequiresEngineStarted\n\t) {\n\t\tthrow new GeneralError(\"node\", \"storageFileRootNotSet\", {\n\t\t\tstorageFileRoot: `${nodeOptions?.envPrefix ?? \"\"}STORAGE_FILE_ROOT`\n\t\t});\n\t}\n\n\t// Create the engine instance using file state storage unless one is configured in options\n\tconst engine = new Engine<IEngineServerConfig, INodeEngineState>({\n\t\tconfig: nodeEngineConfig,\n\t\tstateStorage: requiresEngineStarted\n\t\t\t? (nodeOptions?.stateStorage ?? new FileStateStorage(envVars.stateFilename ?? \"\"))\n\t\t\t: undefined,\n\t\tcustomBootstrap: async engineCore => {\n\t\t\tconfigureContextIds(\n\t\t\t\tengineCore,\n\t\t\t\tenvVars,\n\t\t\t\trequiresEngineStarted,\n\t\t\t\trequiresNodeIdentity,\n\t\t\t\trequiresOrgIdentity\n\t\t\t);\n\t\t\tif (!Is.objectValue(cliCommand) && requiresEngineStarted) {\n\t\t\t\tawait ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {\n\t\t\t\t\tawait enforceTenantOrganizationIds(engineCore, envVars);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\tconfigureContextIdKeys(engine, availableContextIdKeys);\n\n\t// Construct the server with the engine.\n\tconst server = new EngineServer({ engineCore: engine });\n\n\t// Extend the engine.\n\tif (Is.function(nodeOptions?.extendEngine)) {\n\t\tawait engine.logInfo(I18n.formatMessage(\"node.extendingEngine\"));\n\t\tawait nodeOptions.extendEngine(engine);\n\t}\n\n\tawait extensionsInitialiseEngine(envVars, engine);\n\n\t// Extend the engine server.\n\tif (Is.function(nodeOptions?.extendEngineServer)) {\n\t\tawait engine.logInfo(I18n.formatMessage(\"node.extendingEngineServer\"));\n\t\tawait nodeOptions?.extendEngineServer(server);\n\t}\n\n\tawait extensionsInitialiseEngineServer(envVars, engine, server);\n\n\t// Need to register the engine with the factory so that background tasks\n\t// can clone it to spawn new instances.\n\tEngineCoreFactory.register(\"engine\", () => engine);\n\n\tif (Is.objectValue(cliCommand)) {\n\t\tawait executeCommand(engine, envVars, cliCommand);\n\t} else {\n\t\ttry {\n\t\t\t// Start the server, which also starts the engine.\n\t\t\tawait server.start();\n\n\t\t\treturn {\n\t\t\t\tengine,\n\t\t\t\tserver,\n\t\t\t\tshutdown: async () => {\n\t\t\t\t\tawait shutdownExtensions(envVars, engine);\n\t\t\t\t\tawait server.stop();\n\t\t\t\t}\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tawait shutdownExtensions(envVars, engine);\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\n/**\n * Populate the engine context IDs from the current engine state.\n * @param engine The engine to configure.\n * @param envVars The environment variables.\n * @param requiresEngineStarted Whether the engine is required to be started.\n * @param requiresNodeIdentity Whether the node identity is required.\n * @param requiresOrgIdentity Whether the organization identity is required.\n * @throws GeneralError if the node identity or organization ID is required but not set.\n */\nfunction configureContextIds(\n\tengine: IEngineCore<IEngineCoreConfig, INodeEngineState>,\n\tenvVars: IEngineEnvironmentVariables,\n\trequiresEngineStarted: boolean,\n\trequiresNodeIdentity: boolean,\n\trequiresOrgIdentity: boolean\n): void {\n\tconst state = engine.getState();\n\n\tif (requiresEngineStarted) {\n\t\tif (Is.stringValue(state.nodeId)) {\n\t\t\tengine.addContextId(ContextIdKeys.Node, state.nodeId);\n\t\t} else if (requiresNodeIdentity) {\n\t\t\tthrow new GeneralError(\"node\", \"nodeIdentityNotSet\");\n\t\t}\n\n\t\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\t\tif (!tenantEnabled) {\n\t\t\tif (Is.stringValue(state.nodeOrganizationId)) {\n\t\t\t\tengine.addContextId(ContextIdKeys.Organization, state.nodeOrganizationId);\n\t\t\t} else if (requiresOrgIdentity) {\n\t\t\t\tthrow new GeneralError(\"node\", \"nodeOrganizationIdNotSet\");\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Configure the available context ID keys on the engine.\n * @param engine The engine to configure.\n * @param availableContextIdKeys The available context ID keys.\n */\nfunction configureContextIdKeys(\n\tengine: IEngineCore<IEngineCoreConfig, INodeEngineState>,\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] | undefined\n): void {\n\tif (Is.arrayValue(availableContextIdKeys)) {\n\t\tconst added: string[] = [];\n\t\tfor (const availableContextIdKey of availableContextIdKeys) {\n\t\t\tif (!added.includes(availableContextIdKey.key)) {\n\t\t\t\tengine.addContextIdKey(\n\t\t\t\t\tavailableContextIdKey.key,\n\t\t\t\t\tavailableContextIdKey.requiredHandlerFeatures\n\t\t\t\t);\n\t\t\t\tadded.push(availableContextIdKey.key);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Scan all tenants for a missing organization ID.\n * If exactly one tenant is missing and the node's own organization ID is available in state,\n * the value is automatically applied and persisted (legacy migration path).\n * If multiple tenants are missing, or the single missing tenant cannot be auto-recovered,\n * startup is blocked with an error listing the affected tenant IDs.\n * @param engineCore The engine core.\n * @param envVars The environment variables.\n * @returns A promise that resolves when all tenants have valid organization IDs.\n * @throws GeneralError if multiple tenants are missing their organization ID and cannot be auto-recovered.\n */\nasync function enforceTenantOrganizationIds(\n\tengineCore: IEngineCore<IEngineCoreConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables\n): Promise<void> {\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tif (!tenantEnabled) {\n\t\treturn;\n\t}\n\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\tif (!Is.stringValue(type)) {\n\t\treturn;\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\tconst missingIds: string[] = [];\n\tlet cursor: string | undefined;\n\n\tdo {\n\t\tconst { tenants, cursor: next } = await tenantAdminComponent.query(\n\t\t\tundefined,\n\t\t\t[\"id\", \"organizationId\"],\n\t\t\tcursor\n\t\t);\n\t\tfor (const tenant of tenants) {\n\t\t\tif (Is.stringValue(tenant.id) && !Is.stringValue(tenant.organizationId)) {\n\t\t\t\tmissingIds.push(tenant.id);\n\t\t\t}\n\t\t}\n\t\tcursor = next;\n\t} while (Is.stringValue(cursor));\n\n\tif (missingIds.length === 0) {\n\t\treturn;\n\t}\n\n\tif (missingIds.length === 1) {\n\t\tconst state = engineCore.getState();\n\t\tif (Is.stringValue(state.nodeOrganizationId)) {\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.tenantOrganizationIdAutoAssigned\", {\n\t\t\t\t\ttenantId: missingIds[0],\n\t\t\t\t\torganizationId: state.nodeOrganizationId\n\t\t\t\t})\n\t\t\t);\n\t\t\tawait tenantAdminComponent.update({\n\t\t\t\tid: missingIds[0],\n\t\t\t\torganizationId: state.nodeOrganizationId\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t}\n\n\tthrow new GeneralError(\"node\", \"tenantsWithoutOrganizationId\", {\n\t\ttenantIds: missingIds.join(\", \")\n\t});\n}\n"]}
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/start.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACl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AC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QACpC,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC9C,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,uCAAuC,EAAE;gBAC3D,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;gBACvB,cAAc,EAAE,KAAK,CAAC,kBAAkB;aACxC,CAAC,CACF,CAAC;YACF,MAAM,oBAAoB,CAAC,MAAM,CAAC;gBACjC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;gBACjB,cAAc,EAAE,KAAK,CAAC,kBAAkB;aACxC,CAAC,CAAC;YACH,OAAO;QACR,CAAC;IACF,CAAC;IAED,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,8BAA8B,EAAE;QAC9D,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;KAChC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport { Engine } from \"@twin.org/engine\";\nimport { FileStateStorage } from \"@twin.org/engine-core\";\nimport {\n\tEngineCoreFactory,\n\ttype IEngineCore,\n\ttype IEngineCoreConfig\n} from \"@twin.org/engine-models\";\nimport { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { BlobStorageConnectorType, EntityStorageConnectorType } from \"@twin.org/engine-types\";\nimport {\n\textensionsInitialiseEngine,\n\textensionsInitialiseEngineServer,\n\tshutdownExtensions\n} from \"./builders/extensionsBuilder.js\";\nimport { commaSeparatedListToArray } from \"./builders/helper/envHelpers.js\";\nimport { executeCommand } from \"./cli.js\";\nimport type { ICliCommand } from \"./models/ICliCommand.js\";\nimport type { IEngineEnvironmentVariables } from \"./models/IEngineEnvironmentVariables.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\";\n\n/**\n * Start the engine server.\n * @param nodeOptions Optional run options for the engine server.\n * @param nodeEngineConfig The configuration for the engine server.\n * @param envVars The environment variables.\n * @param cliCommand The constructed CLI command (optional).\n * @param availableContextIdKeys The context ID keys available for operation.\n * @returns The engine server.\n */\nexport async function start(\n\tnodeOptions: INodeOptions | undefined,\n\tnodeEngineConfig: INodeEngineConfig,\n\tenvVars: IEnvironmentVariables & IEngineEnvironmentVariables,\n\tcliCommand?: ICliCommand,\n\tavailableContextIdKeys?: { key: string; requiredHandlerFeatures: 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\tconst entityStorageConnectorType = commaSeparatedListToArray(envVars.entityStorageConnectorType);\n\tconst blobStorageConnectorType = commaSeparatedListToArray(envVars.blobStorageConnectorType);\n\n\tconst requiresEngineStarted = cliCommand?.definition?.requiresEngineStarted ?? true;\n\tconst requiresNodeIdentity = cliCommand?.definition?.requiresNodeIdentity ?? true;\n\tconst requiresOrgIdentity = cliCommand?.definition?.requiresOrgIdentity ?? true;\n\n\t// File connectors (blob/entity) and the default file-based state storage all\n\t// persist to disk under storageFileRoot, so it must be set when any of them is in use.\n\tif (\n\t\t(entityStorageConnectorType.includes(EntityStorageConnectorType.File) ||\n\t\t\tblobStorageConnectorType.includes(BlobStorageConnectorType.File) ||\n\t\t\tIs.empty(nodeOptions?.stateStorage)) &&\n\t\t!Is.stringValue(envVars.storageFileRoot) &&\n\t\trequiresEngineStarted\n\t) {\n\t\tthrow new GeneralError(\"node\", \"storageFileRootNotSet\", {\n\t\t\tstorageFileRoot: `${nodeOptions?.envPrefix ?? \"\"}STORAGE_FILE_ROOT`\n\t\t});\n\t}\n\n\t// Create the engine instance using file state storage unless one is configured in options\n\tconst engine = new Engine<IEngineServerConfig, INodeEngineState>({\n\t\tconfig: nodeEngineConfig,\n\t\tstateStorage: requiresEngineStarted\n\t\t\t? (nodeOptions?.stateStorage ?? new FileStateStorage(envVars.stateFilename ?? \"\"))\n\t\t\t: undefined,\n\t\tcustomBootstrap: async engineCore => {\n\t\t\tconfigureContextIds(\n\t\t\t\tengineCore,\n\t\t\t\tenvVars,\n\t\t\t\trequiresEngineStarted,\n\t\t\t\trequiresNodeIdentity,\n\t\t\t\trequiresOrgIdentity\n\t\t\t);\n\t\t\tif (!Is.objectValue(cliCommand) && requiresEngineStarted) {\n\t\t\t\tawait ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {\n\t\t\t\t\tawait enforceTenantOrganizationIds(engineCore, envVars);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\tconfigureContextIdKeys(engine, availableContextIdKeys);\n\n\t// Construct the server with the engine.\n\tconst server = new EngineServer({ engineCore: engine });\n\n\t// Extend the engine.\n\tif (Is.function(nodeOptions?.extendEngine)) {\n\t\tawait engine.logInfo(I18n.formatMessage(\"node.extendingEngine\"));\n\t\tawait nodeOptions.extendEngine(engine);\n\t}\n\n\tawait extensionsInitialiseEngine(envVars, engine);\n\n\t// Extend the engine server.\n\tif (Is.function(nodeOptions?.extendEngineServer)) {\n\t\tawait engine.logInfo(I18n.formatMessage(\"node.extendingEngineServer\"));\n\t\tawait nodeOptions?.extendEngineServer(server);\n\t}\n\n\tawait extensionsInitialiseEngineServer(envVars, engine, server);\n\n\t// Need to register the engine with the factory so that background tasks\n\t// can clone it to spawn new instances.\n\tEngineCoreFactory.register(\"engine\", () => engine);\n\n\tif (Is.objectValue(cliCommand)) {\n\t\tawait executeCommand(engine, envVars, cliCommand);\n\t} else {\n\t\ttry {\n\t\t\t// Start the server, which also starts the engine.\n\t\t\tawait server.start();\n\n\t\t\treturn {\n\t\t\t\tengine,\n\t\t\t\tserver,\n\t\t\t\tshutdown: async () => {\n\t\t\t\t\tawait shutdownExtensions(envVars, engine);\n\t\t\t\t\tawait server.stop();\n\t\t\t\t}\n\t\t\t};\n\t\t} catch (err) {\n\t\t\tawait shutdownExtensions(envVars, engine);\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n\n/**\n * Populate the engine context IDs from the current engine state.\n * @param engine The engine to configure.\n * @param envVars The environment variables.\n * @param requiresEngineStarted Whether the engine is required to be started.\n * @param requiresNodeIdentity Whether the node identity is required.\n * @param requiresOrgIdentity Whether the organization identity is required.\n * @throws GeneralError if the node identity or organization ID is required but not set.\n */\nfunction configureContextIds(\n\tengine: IEngineCore<IEngineCoreConfig, INodeEngineState>,\n\tenvVars: IEngineEnvironmentVariables,\n\trequiresEngineStarted: boolean,\n\trequiresNodeIdentity: boolean,\n\trequiresOrgIdentity: boolean\n): void {\n\tconst state = engine.getState();\n\n\tif (requiresEngineStarted) {\n\t\tif (Is.stringValue(state.nodeId)) {\n\t\t\tengine.addContextId(ContextIdKeys.Node, state.nodeId);\n\t\t} else if (requiresNodeIdentity) {\n\t\t\tthrow new GeneralError(\"node\", \"nodeIdentityNotSet\");\n\t\t}\n\n\t\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\t\tif (!tenantEnabled) {\n\t\t\tif (Is.stringValue(state.nodeOrganizationId)) {\n\t\t\t\tengine.addContextId(ContextIdKeys.Organization, state.nodeOrganizationId);\n\t\t\t} else if (requiresOrgIdentity) {\n\t\t\t\tthrow new GeneralError(\"node\", \"nodeOrganizationIdNotSet\");\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Configure the available context ID keys on the engine.\n * @param engine The engine to configure.\n * @param availableContextIdKeys The available context ID keys.\n */\nfunction configureContextIdKeys(\n\tengine: IEngineCore<IEngineCoreConfig, INodeEngineState>,\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] | undefined\n): void {\n\tif (Is.arrayValue(availableContextIdKeys)) {\n\t\tconst added: string[] = [];\n\t\tfor (const availableContextIdKey of availableContextIdKeys) {\n\t\t\tif (!added.includes(availableContextIdKey.key)) {\n\t\t\t\tengine.addContextIdKey(\n\t\t\t\t\tavailableContextIdKey.key,\n\t\t\t\t\tavailableContextIdKey.requiredHandlerFeatures\n\t\t\t\t);\n\t\t\t\tadded.push(availableContextIdKey.key);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Scan all tenants for a missing organization ID.\n * If exactly one tenant is missing and the node's own organization ID is available in state,\n * the value is automatically applied and persisted (legacy migration path).\n * If multiple tenants are missing, or the single missing tenant cannot be auto-recovered,\n * startup is blocked with an error listing the affected tenant IDs.\n * @param engineCore The engine core.\n * @param envVars The environment variables.\n * @returns A promise that resolves when all tenants have valid organization IDs.\n * @throws GeneralError if multiple tenants are missing their organization ID and cannot be auto-recovered.\n */\nasync function enforceTenantOrganizationIds(\n\tengineCore: IEngineCore<IEngineCoreConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables\n): Promise<void> {\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tif (!tenantEnabled) {\n\t\treturn;\n\t}\n\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\tif (!Is.stringValue(type)) {\n\t\treturn;\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\tconst missingIds: string[] = [];\n\tlet cursor: string | undefined;\n\n\tdo {\n\t\tconst { tenants, cursor: next } = await tenantAdminComponent.query(\n\t\t\tundefined,\n\t\t\t[\"id\", \"organizationId\"],\n\t\t\tcursor\n\t\t);\n\t\tfor (const tenant of tenants) {\n\t\t\tif (Is.stringValue(tenant.id) && !Is.stringValue(tenant.organizationId)) {\n\t\t\t\tmissingIds.push(tenant.id);\n\t\t\t}\n\t\t}\n\t\tcursor = next;\n\t} while (Is.stringValue(cursor));\n\n\tif (missingIds.length === 0) {\n\t\treturn;\n\t}\n\n\tif (missingIds.length === 1) {\n\t\tconst state = engineCore.getState();\n\t\tif (Is.stringValue(state.nodeOrganizationId)) {\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.tenantOrganizationIdAutoAssigned\", {\n\t\t\t\t\ttenantId: missingIds[0],\n\t\t\t\t\torganizationId: state.nodeOrganizationId\n\t\t\t\t})\n\t\t\t);\n\t\t\tawait tenantAdminComponent.update({\n\t\t\t\tid: missingIds[0],\n\t\t\t\torganizationId: state.nodeOrganizationId\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t}\n\n\tthrow new GeneralError(\"node\", \"tenantsWithoutOrganizationId\", {\n\t\ttenantIds: missingIds.join(\", \")\n\t});\n}\n"]}
@@ -59,9 +59,16 @@ export declare function isTaskSchedulerRequired(envVars: IEngineEnvironmentVaria
59
59
  */
60
60
  export declare function isAutomationRequired(envVars: IEngineEnvironmentVariables): boolean;
61
61
  /**
62
- * Checks if the telemetry subsystem is required.
62
+ * Checks if the telemetry subsystem is enabled.
63
63
  * Returns true when any component that depends on the telemetry subsystem is enabled.
64
64
  * @param envVars The environment variables.
65
65
  * @returns True if telemetry is enabled.
66
66
  */
67
- export declare function isTelemetryRequired(envVars: IEngineEnvironmentVariables): boolean;
67
+ export declare function isTelemetryEnabled(envVars: IEngineEnvironmentVariables): boolean;
68
+ /**
69
+ * Checks if the tracing subsystem is enabled.
70
+ * Returns true when any component that depends on the tracing subsystem is enabled.
71
+ * @param envVars The environment variables.
72
+ * @returns True if tracing is enabled.
73
+ */
74
+ export declare function isTracingEnabled(envVars: IEngineEnvironmentVariables): boolean;
@@ -1,4 +1,3 @@
1
- import type { IEngineEnvironmentVariables } from "../../models/IEngineEnvironmentVariables.js";
2
1
  /**
3
2
  * Coerces an env var to a boolean, falling back to the supplied default when not set.
4
3
  * @param envVars The environment variables object.
@@ -7,75 +6,136 @@ import type { IEngineEnvironmentVariables } from "../../models/IEngineEnvironmen
7
6
  * @returns The boolean value, the default, or undefined when absent and no default given.
8
7
  * @throws GeneralError if the value is set but cannot be coerced to a boolean.
9
8
  */
10
- export declare function envBoolean(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables, defaultValue: boolean): boolean;
11
- export declare function envBoolean(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): boolean | undefined;
9
+ export declare function envBoolean<T>(envVars: T, key: keyof T, defaultValue: boolean): boolean;
10
+ export declare function envBoolean<T>(envVars: T, key: keyof T): boolean | undefined;
12
11
  /**
13
12
  * Coerces an env var that is already in milliseconds to an integer.
14
13
  * @param envVars The environment variables object.
15
14
  * @param key The property name of the env var to coerce.
16
- * @returns The millisecond value, or undefined when not set.
15
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
16
+ * @returns The millisecond value, the default, or undefined when absent and no default given.
17
17
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
18
18
  */
19
- export declare function envMs(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
19
+ export declare function envMs<T>(envVars: T, key: keyof T, defaultValue: number): number;
20
+ export declare function envMs<T>(envVars: T, key: keyof T): number | undefined;
20
21
  /**
21
22
  * Coerces an env var that represents an integer count or size to an integer.
22
23
  * @param envVars The environment variables object.
23
24
  * @param key The property name of the env var to coerce.
24
- * @returns The count, or undefined when not set.
25
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
26
+ * @returns The count, the default, or undefined when absent and no default given.
25
27
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
26
28
  */
27
- export declare function envCount(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
29
+ export declare function envCount<T>(envVars: T, key: keyof T, defaultValue: number): number;
30
+ export declare function envCount<T>(envVars: T, key: keyof T): number | undefined;
28
31
  /**
29
- * Coerces an env var that represents an integer to an integer.
32
+ * Coerces an env var that represents an integer to an actual integer.
30
33
  * @param envVars The environment variables object.
31
34
  * @param key The property name of the env var to coerce.
32
- * @returns The integer, or undefined when not set.
35
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
36
+ * @returns The integer, the default, or undefined when absent and no default given.
33
37
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
34
38
  */
35
- export declare function envInteger(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
39
+ export declare function envInteger<T>(envVars: T, key: keyof T, defaultValue: number): number;
40
+ export declare function envInteger<T>(envVars: T, key: keyof T): number | undefined;
41
+ /**
42
+ * Returns an env var as a typed object. Accepts a pre-parsed object, an inline JSON object string,
43
+ * or a value already expanded from a @json: file reference.
44
+ * @param envVars The environment variables object.
45
+ * @param key The property name of the env var to coerce.
46
+ * @param defaultValue The value to return when the env var is absent or cannot be parsed.
47
+ * @returns The parsed object, or the default when absent or the value cannot be parsed.
48
+ */
49
+ export declare function envObject<T, U>(envVars: T, key: keyof T, defaultValue: U): U;
50
+ /**
51
+ * Returns an env var as a typed object. Accepts a pre-parsed object, an inline JSON object string,
52
+ * or a value already expanded from a @json: file reference.
53
+ * @param envVars The environment variables object.
54
+ * @param key The property name of the env var to coerce.
55
+ * @returns The parsed object, or undefined when the var is absent or the value cannot be parsed.
56
+ */
57
+ export declare function envObject<T, U>(envVars: T, key: keyof T): U | undefined;
58
+ /**
59
+ * Returns an env var as a typed array. Accepts a pre-parsed array, an inline JSON array string,
60
+ * or a value already expanded from a @json: file reference.
61
+ * @param envVars The environment variables object.
62
+ * @param key The property name of the env var to coerce.
63
+ * @param defaultValue The value to return when the env var is absent or cannot be parsed.
64
+ * @returns The parsed array, or the default when absent or the value cannot be parsed.
65
+ */
66
+ export declare function envArray<T, U>(envVars: T, key: keyof T, defaultValue: U[]): U[];
67
+ /**
68
+ * Returns an env var as a typed array. Accepts a pre-parsed array, an inline JSON array string,
69
+ * or a value already expanded from a @json: file reference.
70
+ * @param envVars The environment variables object.
71
+ * @param key The property name of the env var to coerce.
72
+ * @returns The parsed array, or undefined when the var is absent or the value cannot be parsed.
73
+ */
74
+ export declare function envArray<T, U>(envVars: T, key: keyof T): U[] | undefined;
36
75
  /**
37
76
  * Coerces an env var that is already in seconds to an integer.
38
77
  * @param envVars The environment variables object.
39
78
  * @param key The property name of the env var to coerce.
40
- * @returns The second value, or undefined when not set.
79
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
80
+ * @returns The second value, the default, or undefined when absent and no default given.
41
81
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
42
82
  */
43
- export declare function envSeconds(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
83
+ export declare function envSeconds<T>(envVars: T, key: keyof T, defaultValue: number): number;
84
+ export declare function envSeconds<T>(envVars: T, key: keyof T): number | undefined;
44
85
  /**
45
86
  * Coerces an env var that is already in minutes to an integer.
46
87
  * @param envVars The environment variables object.
47
88
  * @param key The property name of the env var to coerce.
48
- * @returns The minute value, or undefined when not set.
89
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
90
+ * @returns The minute value, the default, or undefined when absent and no default given.
49
91
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
50
92
  */
51
- export declare function envMinutes(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
93
+ export declare function envMinutes<T>(envVars: T, key: keyof T, defaultValue: number): number;
94
+ export declare function envMinutes<T>(envVars: T, key: keyof T): number | undefined;
52
95
  /**
53
96
  * Coerces an env var that is a datetime string, throwing when the value is set but not a valid datetime.
54
97
  * @param envVars The environment variables object.
55
98
  * @param key The property name of the env var to coerce.
56
- * @returns The datetime string, or undefined when not set.
99
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
100
+ * @returns The datetime ISO string, the default, or undefined when absent and no default given.
57
101
  * @throws GeneralError if the value is set but cannot be coerced to a datetime.
58
102
  */
59
- export declare function envDateTime(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): string | undefined;
103
+ export declare function envDateTime<T>(envVars: T, key: keyof T, defaultValue: string): string;
104
+ export declare function envDateTime<T>(envVars: T, key: keyof T): string | undefined;
60
105
  /**
61
106
  * Coerces an env var to an integer and converts from seconds to milliseconds.
62
107
  * @param envVars The environment variables object.
63
108
  * @param key The property name of the env var to coerce.
64
- * @returns The value in milliseconds, or undefined when not set.
109
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
110
+ * @returns The value in milliseconds, the default, or undefined when absent and no default given.
65
111
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
66
112
  */
67
- export declare function envSecToMs(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
113
+ export declare function envSecToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;
114
+ export declare function envSecToMs<T>(envVars: T, key: keyof T): number | undefined;
68
115
  /**
69
116
  * Coerces an env var to an integer and converts from minutes to milliseconds.
70
117
  * @param envVars The environment variables object.
71
118
  * @param key The property name of the env var to coerce.
72
- * @returns The value in milliseconds, or undefined when not set.
119
+ * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.
120
+ * @returns The value in milliseconds, the default, or undefined when absent and no default given.
73
121
  * @throws GeneralError if the value is set but cannot be coerced to an integer.
74
122
  */
75
- export declare function envMinToMs(envVars: IEngineEnvironmentVariables, key: keyof IEngineEnvironmentVariables): number | undefined;
123
+ export declare function envMinToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;
124
+ export declare function envMinToMs<T>(envVars: T, key: keyof T): number | undefined;
76
125
  /**
77
126
  * Converts a comma separated list to an array.
78
127
  * @param value The comma separated list.
128
+ * @param defaultValue The default value to return when the list is empty or undefined.
79
129
  * @returns The array.
80
130
  */
81
- export declare function commaSeparatedListToArray<T>(value: string | undefined): T[];
131
+ export declare function commaSeparatedListToArray<U>(value: string | undefined, defaultValue?: U[] | undefined): U[];
132
+ /**
133
+ * Gets named key integer pairs from an env var holding comma separated key=integer pairs.
134
+ * @param envVars The environment variables object.
135
+ * @param key The property name of the env var to read.
136
+ * @returns The named key integer pairs, or undefined when the env var is absent or empty.
137
+ * @throws GeneralError if an entry is not a unique name=value pair with an integer value.
138
+ */
139
+ export declare function envKeyIntegerPairs<T>(envVars: T, key: keyof T): {
140
+ [key: string]: number;
141
+ } | undefined;
@@ -412,6 +412,10 @@ export interface IEngineEnvironmentVariables {
412
412
  * The number of rotated log files to retain when using the file logging connector, defaults to 5. Set to 0 or negative to keep all rotated files.
413
413
  */
414
414
  loggingFileMaxRetainedFiles?: string;
415
+ /**
416
+ * A list of components to exclude from telemetry, can be a comma separated list of component Class names e.g. "ComponentA,ComponentB".
417
+ */
418
+ telemetrySilentComponents?: string;
415
419
  /**
416
420
  * The name of the OpenTelemetry logger, only required if using open-telemetry as logging connector, defaults to twin-logging.
417
421
  */
@@ -477,7 +481,7 @@ export interface IEngineEnvironmentVariables {
477
481
  */
478
482
  messagingPushNotificationConnector?: string;
479
483
  /**
480
- * The type of telemetry connector: entity-storage.
484
+ * The type of telemetry connector, comma-separated for multiple: entity-storage, open-telemetry, silent.
481
485
  */
482
486
  telemetryConnector?: string;
483
487
  /**
@@ -508,12 +512,39 @@ export interface IEngineEnvironmentVariables {
508
512
  * Maximum number of values retained per telemetry metric (count-based history cap). Defaults to 1440.
509
513
  */
510
514
  telemetryMetricsProducerMaxHistory?: string;
515
+ /**
516
+ * The batch size for the telemetry connector, set to 1 to disable size-based flushing.
517
+ */
518
+ telemetryBatchSize?: string;
519
+ /**
520
+ * The batch flush interval in seconds for the telemetry connector, how often to flush when using batching, defaults to 5 seconds.
521
+ */
522
+ telemetryBatchFlushInterval?: string;
523
+ /**
524
+ * The maximum number of metric values to hold in the write-ahead cache for the telemetry connector. Set to 0 for unlimited.
525
+ * @default 1000
526
+ */
527
+ telemetryMaxCacheSize?: string;
511
528
  /**
512
529
  * The mutex timeout in milliseconds for the telemetry connector.
513
530
  */
514
531
  telemetryMutexTimeout?: string;
515
532
  /**
516
- * The type of tracing connector: entity-storage, open-telemetry.
533
+ * The maximum number of metric definitions held in the in-memory definition cache for the telemetry connector.
534
+ * @default 100
535
+ */
536
+ telemetryMetricDefinitionCacheCapacity?: string;
537
+ /**
538
+ * The time-to-idle in milliseconds for cached metric definitions in the telemetry connector.
539
+ * @default 3600000
540
+ */
541
+ telemetryMetricDefinitionCacheTtiMs?: string;
542
+ /**
543
+ * A list of components to exclude from tracing, can be a comma separated list of component Class names e.g. "ComponentA,ComponentB".
544
+ */
545
+ tracingSilentComponents?: string;
546
+ /**
547
+ * The type of tracing connector, comma-separated for multiple: entity-storage, open-telemetry, console, silent.
517
548
  */
518
549
  tracingConnector?: string;
519
550
  /**
@@ -576,6 +607,14 @@ export interface IEngineEnvironmentVariables {
576
607
  * The mutex timeout in milliseconds for the DID resolution cache. Only used when using the IOTA identity connector and caching is enabled.
577
608
  */
578
609
  identityDidResolutionCacheMutexTimeout?: string;
610
+ /**
611
+ * The number of times to retry resolving a DID after a write operation (create, update, or delete) to confirm propagation. Only used when using the IOTA identity connector.
612
+ */
613
+ identityDidResolutionRetries?: string;
614
+ /**
615
+ * The delay in milliseconds between DID resolution retries after a write operation. Only used when using the IOTA identity connector.
616
+ */
617
+ identityDidResolutionRetryDelay?: string;
579
618
  /**
580
619
  * The type of identity resolver connector: entity-storage, iota.
581
620
  */
@@ -816,6 +855,14 @@ export interface IEngineEnvironmentVariables {
816
855
  * The mutex timeout in milliseconds for the dataspace agreement cache.
817
856
  */
818
857
  dataspaceAgreementCacheMutexTimeout?: string;
858
+ /**
859
+ * The time in milliseconds after which an unused agreement is eligible for removal.
860
+ */
861
+ dataspaceAgreementUnusedThreshold?: string;
862
+ /**
863
+ * The interval in milliseconds between agreement sweep runs.
864
+ */
865
+ dataspaceAgreementSweepInterval?: string;
819
866
  /**
820
867
  * The number of times to retry failed data plane tasks.
821
868
  */
@@ -26,6 +26,10 @@ export interface IEngineServerEnvironmentVariables {
26
26
  * The CORS headers to expose.
27
27
  */
28
28
  httpExposedHeaders?: string;
29
+ /**
30
+ * Named request body limits in bytes as comma separated name=bytes pairs, e.g. default=2097152,large=26214400.
31
+ */
32
+ httpBodyLimits?: string;
29
33
  /**
30
34
  * The public origin URL for the API e.g. https://api.example.com:1234
31
35
  */
@@ -62,4 +66,12 @@ export interface IEngineServerEnvironmentVariables {
62
66
  * List of properties to obfuscate in the REST logging output, comma separated.
63
67
  */
64
68
  routeLoggingObfuscateProperties?: string;
69
+ /**
70
+ * Comma-separated list of URL path prefixes excluded from metrics collection.
71
+ */
72
+ routeMetricsExcludePaths?: string;
73
+ /**
74
+ * Comma-separated list of URL path prefixes excluded from tracing.
75
+ */
76
+ routeTracingExcludePaths?: string;
65
77
  }