@twin.org/node-core 0.9.4-next.4 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/builders/engineEnvBuilder.js +365 -466
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +2 -5
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/helper/envHelpers.js +0 -39
- package/dist/es/builders/helper/envHelpers.js.map +1 -1
- package/dist/es/cli.js +1 -1
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/bootstrapDev.js +3 -3
- package/dist/es/commands/bootstrapDev.js.map +1 -1
- package/dist/es/commands/help.js +1 -1
- package/dist/es/commands/help.js.map +1 -1
- package/dist/es/commands/identityCreate.js +2 -2
- package/dist/es/commands/identityCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodCreate.js +2 -2
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -1
- package/dist/es/commands/userCreate.js +1 -1
- package/dist/es/commands/userCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyCreate.js +1 -1
- package/dist/es/commands/vaultKeyCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyImport.js +1 -1
- package/dist/es/commands/vaultKeyImport.js.map +1 -1
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
- package/dist/es/models/engineEnvironmentVariableKeys.js +2 -13
- package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -1
- package/dist/es/models/engineServerEnvironmentVariableKeys.js +0 -1
- package/dist/es/models/engineServerEnvironmentVariableKeys.js.map +1 -1
- package/dist/es/node.js +21 -40
- package/dist/es/node.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +0 -7
- package/dist/types/builders/helper/envHelpers.d.ts +0 -30
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +8 -44
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +0 -4
- package/docs/changelog.md +24 -171
- package/docs/reference/index.md +0 -1
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +13 -85
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +0 -8
- package/locales/en.json +1 -3
- package/package.json +34 -34
- package/dist/es/models/deprecatedEnvironmentVariableKeys.js +0 -16
- package/dist/es/models/deprecatedEnvironmentVariableKeys.js.map +0 -1
- package/dist/types/models/deprecatedEnvironmentVariableKeys.d.ts +0 -7
- package/docs/reference/functions/isMailboxEnabled.md +0 -20
|
@@ -5,7 +5,7 @@ import { AuthenticationAdminComponentType, AuthenticationAuditComponentType, Aut
|
|
|
5
5
|
import { TraceparentHelper } from "@twin.org/tracing-models";
|
|
6
6
|
import { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from "../defaults.js";
|
|
7
7
|
import { isTelemetryEnabled, isTracingEnabled } from "./engineEnvBuilder.js";
|
|
8
|
-
import { commaSeparatedListToArray, envKeyIntegerPairs
|
|
8
|
+
import { commaSeparatedListToArray, envKeyIntegerPairs } from "./helper/envHelpers.js";
|
|
9
9
|
/**
|
|
10
10
|
* Handles the configuration of the server.
|
|
11
11
|
* @param envVars The environment variables for the engine server.
|
|
@@ -25,10 +25,7 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
25
25
|
exposedHeaders: commaSeparatedListToArray(envVars.httpExposedHeaders, undefined),
|
|
26
26
|
corsOrigins: commaSeparatedListToArray(envVars.corsOrigins, undefined),
|
|
27
27
|
bodyLimits: envKeyIntegerPairs(envVars, "httpBodyLimits"),
|
|
28
|
-
publicOrigin: Coerce.string(envVars.publicOrigin)
|
|
29
|
-
customWebConfig: {
|
|
30
|
-
pluginTimeout: envMs(envVars, "fastifyPluginTimeout", 30000)
|
|
31
|
-
}
|
|
28
|
+
publicOrigin: Coerce.string(envVars.publicOrigin)
|
|
32
29
|
};
|
|
33
30
|
const tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
|
|
34
31
|
const apiKeyHeader = envVars.authApiKeyHeader ?? "x-api-key";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineServerEnvBuilder.js","sourceRoot":"","sources":["../../../src/builders/engineServerEnvBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,2BAA2B,EAC3B,+BAA+B,EAE/B,wBAAwB,EAExB,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,8BAA8B,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE7E,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE9F;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CACnD,OAAmE,EACnE,sBAA4E,EAC5E,gBAAmC,EACnC,UAAuB,EACvB,eAAwB,EACxB,WAAoB;IAEpB,MAAM,gBAAgB,GAAsB;QAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACjC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACjC,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC;QAClE,cAAc,EAAE,yBAAyB,CAAC,OAAO,CA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D,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,KAAK,MAAM,UAAU,IAAI,KAAK,EAAE,CAAC;gBAChC,IAAI,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACzC,MAAM,UAAU,GAAG,WAAW,YAAY,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;oBAChG,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;oBAC7C,IAAI,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;wBACtC,UAAU,CAAC,QAAQ,GAAG,gBAAgB,CAAC;oBACxC,CAAC;oBACD,MAAM;gBACP,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,YAAY,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA8B;IACzE,OAAO,CACN,OAAO,CAAC,sBAAsB,KAAK,gCAAgC,CAAC,aAAa;QACjF,OAAO,CAAC,iBAAiB,KAAK,2BAA2B,CAAC,aAAa,CACvE,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IServerInfo, IWebServerOptions } from \"@twin.org/api-models\";\nimport { ContextIdKeys } from \"@twin.org/context\";\nimport { Coerce, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCoreConfig } from \"@twin.org/engine-models\";\nimport { addDefaultRestPaths, addDefaultSocketPaths } from \"@twin.org/engine-server\";\nimport {\n\tAuthenticationAdminComponentType,\n\tAuthenticationAuditComponentType,\n\tAuthenticationComponentType,\n\tAuthenticationRateComponentType,\n\ttype IEngineServerConfig,\n\tInformationComponentType,\n\ttype MimeTypeProcessorType,\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType\n} from \"@twin.org/engine-server-types\";\nimport { TraceparentHelper } from \"@twin.org/tracing-models\";\nimport { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from \"../defaults.js\";\nimport { isTelemetryEnabled, isTracingEnabled } from \"./engineEnvBuilder.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport { commaSeparatedListToArray, envKeyIntegerPairs, envMs } from \"./helper/envHelpers.js\";\n\n/**\n * Handles the configuration of the server.\n * @param envVars The environment variables for the engine server.\n * @param availableContextIdKeys The context ID keys.\n * @param coreEngineConfig The core engine config.\n * @param serverInfo The server information.\n * @param openApiSpecPath The path to the open api spec.\n * @param favIconPath The path to the favicon.\n * @returns The config for the core and the server.\n */\nexport async function buildEngineServerConfiguration(\n\tenvVars: IEnvironmentVariables & { [id: string]: string | unknown },\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[],\n\tcoreEngineConfig: IEngineCoreConfig,\n\tserverInfo: IServerInfo,\n\topenApiSpecPath?: string,\n\tfavIconPath?: string\n): Promise<IEngineServerConfig> {\n\tconst webServerOptions: IWebServerOptions = {\n\t\tport: Coerce.number(envVars.port),\n\t\thost: Coerce.string(envVars.host),\n\t\tmethods: commaSeparatedListToArray(envVars.httpMethods, undefined),\n\t\tallowedHeaders: commaSeparatedListToArray(envVars.httpAllowedHeaders, undefined),\n\t\texposedHeaders: commaSeparatedListToArray(envVars.httpExposedHeaders, undefined),\n\t\tcorsOrigins: commaSeparatedListToArray(envVars.corsOrigins, undefined),\n\t\tbodyLimits: envKeyIntegerPairs(envVars, \"httpBodyLimits\"),\n\t\tpublicOrigin: Coerce.string(envVars.publicOrigin),\n\t\tcustomWebConfig: {\n\t\t\tpluginTimeout: envMs(envVars, \"fastifyPluginTimeout\", 30000)\n\t\t}\n\t};\n\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tconst apiKeyHeader = envVars.authApiKeyHeader ?? \"x-api-key\";\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(apiKeyHeader)) {\n\t\t\twebServerOptions.allowedHeaders.push(apiKeyHeader);\n\t\t}\n\t}\n\n\tif (isTracingEnabled(envVars)) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(TraceparentHelper.HEADER_NAME)) {\n\t\t\twebServerOptions.allowedHeaders.push(TraceparentHelper.HEADER_NAME);\n\t\t}\n\t}\n\n\tconst serverConfig: IEngineServerConfig = {\n\t\t...coreEngineConfig,\n\t\tweb: webServerOptions,\n\t\ttypes: {\n\t\t\t...coreEngineConfig.types,\n\t\t\tinformationComponent: [\n\t\t\t\t{\n\t\t\t\t\ttype: InformationComponentType.Service,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tserverInfo,\n\t\t\t\t\t\t\topenApiSpecPath,\n\t\t\t\t\t\t\tfavIconPath\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t};\n\n\tif (Is.stringValue(envVars.mimeTypeProcessors)) {\n\t\tconst mimeTypeProcessors = commaSeparatedListToArray(envVars.mimeTypeProcessors);\n\n\t\tif (Is.arrayValue(mimeTypeProcessors)) {\n\t\t\tserverConfig.types.mimeTypeProcessor ??= [];\n\t\t\tfor (const mimeTypeProcessor of mimeTypeProcessors) {\n\t\t\t\tserverConfig.types.mimeTypeProcessor.push({\n\t\t\t\t\ttype: mimeTypeProcessor as MimeTypeProcessorType\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tserverConfig.types.restRouteProcessor ??= [];\n\tserverConfig.types.socketRouteProcessor ??= [];\n\n\tavailableContextIdKeys.push({\n\t\tkey: ContextIdKeys.Node,\n\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t});\n\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.ContextId,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.ContextId,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t}\n\t\t}\n\t});\n\n\tif (tenantEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Tenant,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tenant,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tapiKeyName: apiKeyHeader\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Tenant,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tapiKeyName: apiKeyHeader\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t} else {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.SingleTenant\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.SingleTenant\n\t\t});\n\t}\n\n\tif (!coreEngineConfig.silent) {\n\t\tconst includeBody = Coerce.boolean(envVars.routeLoggingIncludeBody) ?? coreEngineConfig.debug;\n\t\tconst fullBase64 = Coerce.boolean(envVars.routeLoggingFullBase64) ?? false;\n\t\tconst obfuscateProperties = commaSeparatedListToArray<string>(\n\t\t\tenvVars.routeLoggingObfuscateProperties,\n\t\t\tundefined\n\t\t);\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.RestRoute\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.SocketRoute\n\t});\n\n\tconst authAdminProcessorType = envVars.authAdminProcessorType;\n\tconst authProcessorType = envVars.authProcessorType;\n\n\tif (\n\t\tauthAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||\n\t\tauthProcessorType === AuthenticationComponentType.EntityStorage\n\t) {\n\t\tserverConfig.types.authenticationRateComponent ??= [];\n\t\tserverConfig.types.authenticationRateComponent.push({\n\t\t\ttype: AuthenticationRateComponentType.EntityStorage\n\t\t});\n\n\t\tserverConfig.types.authenticationAuditComponent ??= [];\n\t\tserverConfig.types.authenticationAuditComponent.push({\n\t\t\ttype: AuthenticationAuditComponentType.EntityStorage\n\t\t});\n\t}\n\n\tif (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage) {\n\t\tserverConfig.types.authenticationAdminComponent ??= [];\n\t\tserverConfig.types.authenticationAdminComponent.push({\n\t\t\ttype: AuthenticationAdminComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (authProcessorType === AuthenticationComponentType.EntityStorage) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.User,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.authenticationComponent ??= [];\n\t\tserverConfig.types.authenticationComponent.push({\n\t\t\ttype: AuthenticationComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tif (tenantEnabled) {\n\t\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\t\ttype: RestRouteProcessorType.TenantOverride,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {}\n\t\t\t\t}\n\t\t\t});\n\t\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\t\ttype: SocketRouteProcessorType.TenantOverride,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tif (isTelemetryEnabled(envVars)) {\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Metrics,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\texcludePaths: commaSeparatedListToArray<string>(\n\t\t\t\t\t\tenvVars.routeMetricsExcludePaths,\n\t\t\t\t\t\tundefined\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (isTracingEnabled(envVars)) {\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tracing,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\texcludePaths: commaSeparatedListToArray<string>(\n\t\t\t\t\t\tenvVars.routeTracingExcludePaths,\n\t\t\t\t\t\tundefined\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\taddDefaultRestPaths(serverConfig);\n\taddDefaultSocketPaths(serverConfig);\n\n\t// See if any of the rest paths should be overridden by environment variables and update the config accordingly\n\t// Should be in the format TWIN_REST_PATH_<COMPONENT_TYPE> e.g. TWIN_REST_PATH_TENANT_ADMIN=my-tenants\n\tfor (const componentType in serverConfig.types) {\n\t\tconst types = serverConfig.types[componentType];\n\n\t\tif (Is.arrayValue(types)) {\n\t\t\tfor (const typeConfig of types) {\n\t\t\t\tif (Is.stringValue(typeConfig.restPath)) {\n\t\t\t\t\tconst envVarName = `restPath${StringHelper.pascalCase(componentType.replace(\"Component\", \"\"))}`;\n\t\t\t\t\tconst overrideRestPath = envVars[envVarName];\n\t\t\t\t\tif (Is.stringValue(overrideRestPath)) {\n\t\t\t\t\t\ttypeConfig.restPath = overrideRestPath;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn serverConfig;\n}\n\n/**\n * Checks if the authentication entity storage subsystem is required.\n * Returns true when any component that depends on the authentication entity storage subsystem is enabled.\n * @param envVars The environment variables.\n * @returns True if authentication entity storage is enabled.\n */\nexport function isAuthEntityStorageRequired(envVars: IEnvironmentVariables): boolean {\n\treturn (\n\t\tenvVars.authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||\n\t\tenvVars.authProcessorType === AuthenticationComponentType.EntityStorage\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"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,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;oBAChG,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;oBAC7C,IAAI,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;wBACtC,UAAU,CAAC,QAAQ,GAAG,gBAAgB,CAAC;oBACxC,CAAC;oBACD,MAAM;gBACP,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,YAAY,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA8B;IACzE,OAAO,CACN,OAAO,CAAC,sBAAsB,KAAK,gCAAgC,CAAC,aAAa;QACjF,OAAO,CAAC,iBAAiB,KAAK,2BAA2B,CAAC,aAAa,CACvE,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IServerInfo, IWebServerOptions } from \"@twin.org/api-models\";\nimport { ContextIdKeys } from \"@twin.org/context\";\nimport { Coerce, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCoreConfig } from \"@twin.org/engine-models\";\nimport { addDefaultRestPaths, addDefaultSocketPaths } from \"@twin.org/engine-server\";\nimport {\n\tAuthenticationAdminComponentType,\n\tAuthenticationAuditComponentType,\n\tAuthenticationComponentType,\n\tAuthenticationRateComponentType,\n\ttype IEngineServerConfig,\n\tInformationComponentType,\n\ttype MimeTypeProcessorType,\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType\n} from \"@twin.org/engine-server-types\";\nimport { TraceparentHelper } from \"@twin.org/tracing-models\";\nimport { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from \"../defaults.js\";\nimport { isTelemetryEnabled, isTracingEnabled } from \"./engineEnvBuilder.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport { commaSeparatedListToArray, envKeyIntegerPairs } from \"./helper/envHelpers.js\";\n\n/**\n * Handles the configuration of the server.\n * @param envVars The environment variables for the engine server.\n * @param availableContextIdKeys The context ID keys.\n * @param coreEngineConfig The core engine config.\n * @param serverInfo The server information.\n * @param openApiSpecPath The path to the open api spec.\n * @param favIconPath The path to the favicon.\n * @returns The config for the core and the server.\n */\nexport async function buildEngineServerConfiguration(\n\tenvVars: IEnvironmentVariables & { [id: string]: string | unknown },\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[],\n\tcoreEngineConfig: IEngineCoreConfig,\n\tserverInfo: IServerInfo,\n\topenApiSpecPath?: string,\n\tfavIconPath?: string\n): Promise<IEngineServerConfig> {\n\tconst webServerOptions: IWebServerOptions = {\n\t\tport: Coerce.number(envVars.port),\n\t\thost: Coerce.string(envVars.host),\n\t\tmethods: commaSeparatedListToArray(envVars.httpMethods, undefined),\n\t\tallowedHeaders: commaSeparatedListToArray(envVars.httpAllowedHeaders, undefined),\n\t\texposedHeaders: commaSeparatedListToArray(envVars.httpExposedHeaders, undefined),\n\t\tcorsOrigins: commaSeparatedListToArray(envVars.corsOrigins, undefined),\n\t\tbodyLimits: envKeyIntegerPairs(envVars, \"httpBodyLimits\"),\n\t\tpublicOrigin: Coerce.string(envVars.publicOrigin)\n\t};\n\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tconst apiKeyHeader = envVars.authApiKeyHeader ?? \"x-api-key\";\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(apiKeyHeader)) {\n\t\t\twebServerOptions.allowedHeaders.push(apiKeyHeader);\n\t\t}\n\t}\n\n\tif (isTracingEnabled(envVars)) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(TraceparentHelper.HEADER_NAME)) {\n\t\t\twebServerOptions.allowedHeaders.push(TraceparentHelper.HEADER_NAME);\n\t\t}\n\t}\n\n\tconst serverConfig: IEngineServerConfig = {\n\t\t...coreEngineConfig,\n\t\tweb: webServerOptions,\n\t\ttypes: {\n\t\t\t...coreEngineConfig.types,\n\t\t\tinformationComponent: [\n\t\t\t\t{\n\t\t\t\t\ttype: InformationComponentType.Service,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tserverInfo,\n\t\t\t\t\t\t\topenApiSpecPath,\n\t\t\t\t\t\t\tfavIconPath\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t};\n\n\tif (Is.stringValue(envVars.mimeTypeProcessors)) {\n\t\tconst mimeTypeProcessors = commaSeparatedListToArray(envVars.mimeTypeProcessors);\n\n\t\tif (Is.arrayValue(mimeTypeProcessors)) {\n\t\t\tserverConfig.types.mimeTypeProcessor ??= [];\n\t\t\tfor (const mimeTypeProcessor of mimeTypeProcessors) {\n\t\t\t\tserverConfig.types.mimeTypeProcessor.push({\n\t\t\t\t\ttype: mimeTypeProcessor as MimeTypeProcessorType\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tserverConfig.types.restRouteProcessor ??= [];\n\tserverConfig.types.socketRouteProcessor ??= [];\n\n\tavailableContextIdKeys.push({\n\t\tkey: ContextIdKeys.Node,\n\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t});\n\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.ContextId,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.ContextId,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t}\n\t\t}\n\t});\n\n\tif (tenantEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Tenant,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tenant,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tapiKeyName: apiKeyHeader\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Tenant,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tapiKeyName: apiKeyHeader\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t} else {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.SingleTenant\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.SingleTenant\n\t\t});\n\t}\n\n\tif (!coreEngineConfig.silent) {\n\t\tconst includeBody = Coerce.boolean(envVars.routeLoggingIncludeBody) ?? coreEngineConfig.debug;\n\t\tconst fullBase64 = Coerce.boolean(envVars.routeLoggingFullBase64) ?? false;\n\t\tconst obfuscateProperties = commaSeparatedListToArray<string>(\n\t\t\tenvVars.routeLoggingObfuscateProperties,\n\t\t\tundefined\n\t\t);\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.RestRoute\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.SocketRoute\n\t});\n\n\tconst authAdminProcessorType = envVars.authAdminProcessorType;\n\tconst authProcessorType = envVars.authProcessorType;\n\n\tif (\n\t\tauthAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||\n\t\tauthProcessorType === AuthenticationComponentType.EntityStorage\n\t) {\n\t\tserverConfig.types.authenticationRateComponent ??= [];\n\t\tserverConfig.types.authenticationRateComponent.push({\n\t\t\ttype: AuthenticationRateComponentType.EntityStorage\n\t\t});\n\n\t\tserverConfig.types.authenticationAuditComponent ??= [];\n\t\tserverConfig.types.authenticationAuditComponent.push({\n\t\t\ttype: AuthenticationAuditComponentType.EntityStorage\n\t\t});\n\t}\n\n\tif (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage) {\n\t\tserverConfig.types.authenticationAdminComponent ??= [];\n\t\tserverConfig.types.authenticationAdminComponent.push({\n\t\t\ttype: AuthenticationAdminComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (authProcessorType === AuthenticationComponentType.EntityStorage) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.User,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.authenticationComponent ??= [];\n\t\tserverConfig.types.authenticationComponent.push({\n\t\t\ttype: AuthenticationComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tif (tenantEnabled) {\n\t\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\t\ttype: RestRouteProcessorType.TenantOverride,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {}\n\t\t\t\t}\n\t\t\t});\n\t\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\t\ttype: SocketRouteProcessorType.TenantOverride,\n\t\t\t\toptions: {\n\t\t\t\t\tconfig: {}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tif (isTelemetryEnabled(envVars)) {\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Metrics,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\texcludePaths: commaSeparatedListToArray<string>(\n\t\t\t\t\t\tenvVars.routeMetricsExcludePaths,\n\t\t\t\t\t\tundefined\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (isTracingEnabled(envVars)) {\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tracing,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\texcludePaths: commaSeparatedListToArray<string>(\n\t\t\t\t\t\tenvVars.routeTracingExcludePaths,\n\t\t\t\t\t\tundefined\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\taddDefaultRestPaths(serverConfig);\n\taddDefaultSocketPaths(serverConfig);\n\n\t// See if any of the rest paths should be overridden by environment variables and update the config accordingly\n\t// Should be in the format TWIN_REST_PATH_<COMPONENT_TYPE> e.g. TWIN_REST_PATH_TENANT_ADMIN=my-tenants\n\tfor (const componentType in serverConfig.types) {\n\t\tconst types = serverConfig.types[componentType];\n\n\t\tif (Is.arrayValue(types)) {\n\t\t\tfor (const typeConfig of types) {\n\t\t\t\tif (Is.stringValue(typeConfig.restPath)) {\n\t\t\t\t\tconst envVarName = `restPath${StringHelper.pascalCase(componentType.replace(\"Component\", \"\"))}`;\n\t\t\t\t\tconst overrideRestPath = envVars[envVarName];\n\t\t\t\t\tif (Is.stringValue(overrideRestPath)) {\n\t\t\t\t\t\ttypeConfig.restPath = overrideRestPath;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn serverConfig;\n}\n\n/**\n * Checks if the authentication entity storage subsystem is required.\n * Returns true when any component that depends on the authentication entity storage subsystem is enabled.\n * @param envVars The environment variables.\n * @returns True if authentication entity storage is enabled.\n */\nexport function isAuthEntityStorageRequired(envVars: IEnvironmentVariables): boolean {\n\treturn (\n\t\tenvVars.authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||\n\t\tenvVars.authProcessorType === AuthenticationComponentType.EntityStorage\n\t);\n}\n"]}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
// Copyright 2026 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { Coerce, GeneralError, Is } from "@twin.org/core";
|
|
4
|
-
export function envString(envVars, key, defaultValue) {
|
|
5
|
-
const value = envVars[key];
|
|
6
|
-
return Is.stringValue(value) ? value : defaultValue;
|
|
7
|
-
}
|
|
8
|
-
export function envChoice(envVars, key, choices, defaultValue) {
|
|
9
|
-
const value = envVars[key];
|
|
10
|
-
if (!Is.stringValue(value)) {
|
|
11
|
-
return defaultValue;
|
|
12
|
-
}
|
|
13
|
-
if (!choices.includes(value)) {
|
|
14
|
-
throw new GeneralError("node", "invalidEnvVarValue", {
|
|
15
|
-
key,
|
|
16
|
-
value,
|
|
17
|
-
type: choices.join(" | ")
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
4
|
export function envBoolean(envVars, key, defaultValue) {
|
|
23
5
|
const value = envVars[key];
|
|
24
6
|
if (!Is.stringValue(value)) {
|
|
@@ -132,27 +114,6 @@ export function envMinToMs(envVars, key, defaultValue) {
|
|
|
132
114
|
}
|
|
133
115
|
return n * 60_000;
|
|
134
116
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Converts a comma separated list to an array.
|
|
137
|
-
* @param envVars The environment variables object.
|
|
138
|
-
* @param key The property name of the env var.
|
|
139
|
-
* @param expectedValues An optional array of expected values.
|
|
140
|
-
* @param defaultValue The default value to return when the list is empty or undefined.
|
|
141
|
-
* @throws GeneralError if the list contains a value not in the expected values.
|
|
142
|
-
* @returns The array.
|
|
143
|
-
*/
|
|
144
|
-
export function envListToArray(envVars, key, expectedValues, defaultValue = []) {
|
|
145
|
-
const value = envVars[key];
|
|
146
|
-
const values = commaSeparatedListToArray(value, defaultValue);
|
|
147
|
-
if (Is.arrayValue(expectedValues) && !values.every(item => expectedValues.includes(item))) {
|
|
148
|
-
throw new GeneralError("node", "invalidEnvVarValue", {
|
|
149
|
-
key,
|
|
150
|
-
value,
|
|
151
|
-
type: expectedValues.join(" | ")
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return values;
|
|
155
|
-
}
|
|
156
117
|
/**
|
|
157
118
|
* Converts a comma separated list to an array.
|
|
158
119
|
* @param value The comma separated list.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envHelpers.js","sourceRoot":"","sources":["../../../../src/builders/helper/envHelpers.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCA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D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAExD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3C,IACC,KAAK,CAAC,MAAM,KAAK,CAAC;YAClB,CAAC,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC;YACxB,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;YACtB,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,EAChC,CAAC;YACF,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,mBAAmB,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACrF,CAAC;QACD,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, GeneralError, Is } from \"@twin.org/core\";\n\n/**\n * Returns an env var as a string when it holds a non-empty value, falling back to the supplied default.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to read.\n * @param defaultValue The value to return when the env var is absent or empty. Omit to return undefined when absent.\n * @returns The string value, the default, or undefined when absent and no default given.\n */\nexport function envString<T>(envVars: T, key: keyof T, defaultValue: string): string;\nexport function envString<T>(envVars: T, key: keyof T): string | undefined;\nexport function envString<T>(envVars: T, key: keyof T, defaultValue?: string): string | undefined {\n\tconst value = envVars[key];\n\treturn Is.stringValue(value) ? value : defaultValue;\n}\n\n/**\n * Returns an env var constrained to one of the supplied choices, falling back to the supplied default.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to read.\n * @param choices The permitted values for the env var.\n * @param defaultValue The value to return when the env var is absent or empty. Omit to return undefined when absent.\n * @returns The matching choice, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but is not one of the choices.\n */\nexport function envChoice<T, U extends string>(\n\tenvVars: T,\n\tkey: keyof T,\n\tchoices: readonly U[],\n\tdefaultValue: U\n): U;\nexport function envChoice<T, U extends string>(\n\tenvVars: T,\n\tkey: keyof T,\n\tchoices: readonly U[]\n): U | undefined;\nexport function envChoice<T, U extends string>(\n\tenvVars: T,\n\tkey: keyof T,\n\tchoices: readonly U[],\n\tdefaultValue?: U\n): U | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tif (!choices.includes(value as U)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", {\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\ttype: choices.join(\" | \")\n\t\t});\n\t}\n\treturn value as U;\n}\n\n/**\n * Coerces an env var to a boolean, falling back to the supplied default when not set.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The boolean value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to a boolean.\n */\nexport function envBoolean<T>(envVars: T, key: keyof T, defaultValue: boolean): boolean;\nexport function envBoolean<T>(envVars: T, key: keyof T): boolean | undefined;\nexport function envBoolean<T>(\n\tenvVars: T,\n\tkey: keyof T,\n\tdefaultValue?: boolean\n): boolean | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.boolean(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"boolean\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that is already in milliseconds to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The millisecond value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envMs<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envMs<T>(envVars: T, key: keyof T): number | undefined;\nexport function envMs<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that represents an integer count or size to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The count, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envCount<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envCount<T>(envVars: T, key: keyof T): number | undefined;\nexport function envCount<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that represents an integer to an actual integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The integer, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envInteger<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envInteger<T>(envVars: T, key: keyof T): number | undefined;\nexport function envInteger<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Returns an env var as a typed object. Accepts a pre-parsed object, an inline JSON object string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent or cannot be parsed.\n * @returns The parsed object, or the default when absent or the value cannot be parsed.\n */\nexport function envObject<T, U>(envVars: T, key: keyof T, defaultValue: U): U;\n/**\n * Returns an env var as a typed object. Accepts a pre-parsed object, an inline JSON object string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @returns The parsed object, or undefined when the var is absent or the value cannot be parsed.\n */\nexport function envObject<T, U>(envVars: T, key: keyof T): U | undefined;\nexport function envObject<T, U>(envVars: T, key: keyof T, defaultValue?: U): U | undefined {\n\tconst value: unknown = envVars[key];\n\tif (Is.undefined(value)) {\n\t\treturn defaultValue;\n\t}\n\treturn Coerce.object<U>(value) ?? defaultValue;\n}\n\n/**\n * Returns an env var as a typed array. Accepts a pre-parsed array, an inline JSON array string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent or cannot be parsed.\n * @returns The parsed array, or the default when absent or the value cannot be parsed.\n */\nexport function envArray<T, U>(envVars: T, key: keyof T, defaultValue: U[]): U[];\n/**\n * Returns an env var as a typed array. Accepts a pre-parsed array, an inline JSON array string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @returns The parsed array, or undefined when the var is absent or the value cannot be parsed.\n */\nexport function envArray<T, U>(envVars: T, key: keyof T): U[] | undefined;\nexport function envArray<T, U>(envVars: T, key: keyof T, defaultValue?: U[]): U[] | undefined {\n\tconst value: unknown = envVars[key];\n\tif (Is.undefined(value)) {\n\t\treturn defaultValue;\n\t}\n\treturn Coerce.array<U>(value) ?? defaultValue;\n}\n\n/**\n * Coerces an env var that is already in seconds to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The second value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envSeconds<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envSeconds<T>(envVars: T, key: keyof T): number | undefined;\nexport function envSeconds<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that is already in minutes to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The minute value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envMinutes<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envMinutes<T>(envVars: T, key: keyof T): number | undefined;\nexport function envMinutes<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that is a datetime string, throwing when the value is set but not a valid datetime.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The datetime ISO string, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to a datetime.\n */\nexport function envDateTime<T>(envVars: T, key: keyof T, defaultValue: string): string;\nexport function envDateTime<T>(envVars: T, key: keyof T): string | undefined;\nexport function envDateTime<T>(\n\tenvVars: T,\n\tkey: keyof T,\n\tdefaultValue?: string\n): string | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.dateTime(value) ?? Coerce.date(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"datetime\" });\n\t}\n\treturn result.toISOString();\n}\n\n/**\n * Coerces an env var to an integer and converts from seconds to milliseconds.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The value in milliseconds, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envSecToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envSecToMs<T>(envVars: T, key: keyof T): number | undefined;\nexport function envSecToMs<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst n = Coerce.integer(value);\n\tif (Is.empty(n)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn n * 1000;\n}\n\n/**\n * Coerces an env var to an integer and converts from minutes to milliseconds.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The value in milliseconds, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envMinToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envMinToMs<T>(envVars: T, key: keyof T): number | undefined;\nexport function envMinToMs<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst n = Coerce.integer(value);\n\tif (Is.empty(n)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn n * 60_000;\n}\n\n/**\n * Converts a comma separated list to an array.\n * @param envVars The environment variables object.\n * @param key The property name of the env var.\n * @param expectedValues An optional array of expected values.\n * @param defaultValue The default value to return when the list is empty or undefined.\n * @throws GeneralError if the list contains a value not in the expected values.\n * @returns The array.\n */\nexport function envListToArray<T, U>(\n\tenvVars: T,\n\tkey: keyof T,\n\texpectedValues?: U[],\n\tdefaultValue: U[] | undefined = []\n): U[] {\n\tconst value = envVars[key];\n\n\tconst values = commaSeparatedListToArray<U>(value as string, defaultValue);\n\n\tif (Is.arrayValue(expectedValues) && !values.every(item => expectedValues.includes(item))) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", {\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\ttype: expectedValues.join(\" | \")\n\t\t});\n\t}\n\n\treturn values;\n}\n\n/**\n * Converts a comma separated list to an array.\n * @param value The comma separated list.\n * @param defaultValue The default value to return when the list is empty or undefined.\n * @returns The array.\n */\nexport function commaSeparatedListToArray<U>(\n\tvalue: string | undefined,\n\tdefaultValue: U[] | undefined = []\n): U[] {\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\treturn value\n\t\t.split(\",\")\n\t\t.map(item => item.trim())\n\t\t.filter(item => item.length > 0) as U[];\n}\n\n/**\n * Gets named key integer pairs from an env var holding comma separated key=integer pairs.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to read.\n * @returns The named key integer pairs, or undefined when the env var is absent or empty.\n * @throws GeneralError if an entry is not a unique name=value pair with an integer value.\n */\nexport function envKeyIntegerPairs<T>(\n\tenvVars: T,\n\tkey: keyof T\n): { [key: string]: number } | undefined {\n\tconst entries = commaSeparatedListToArray<string>(envVars[key] as string | undefined, undefined);\n\tif (!Is.arrayValue(entries)) {\n\t\treturn undefined;\n\t}\n\n\tconst keyValues: { [name: string]: number } = {};\n\tfor (const entry of entries) {\n\t\tconst parts = entry.split(\"=\").map(part => part.trim());\n\n\t\tconst keyPart = parts[0];\n\t\tconst valuePart = Coerce.integer(parts[1]);\n\t\tif (\n\t\t\tparts.length !== 2 ||\n\t\t\t!Is.stringValue(keyPart) ||\n\t\t\t!Is.integer(valuePart) ||\n\t\t\t!Is.undefined(keyValues[keyPart])\n\t\t) {\n\t\t\tthrow new GeneralError(\"node\", \"invalidEnvVarPair\", { key: keyPart, value: entry });\n\t\t}\n\t\tkeyValues[keyPart] = valuePart;\n\t}\n\n\treturn keyValues;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"envHelpers.js","sourceRoot":"","sources":["../../../../src/builders/helper/envHelpers.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAY1D,MAAM,UAAU,UAAU,CACzB,OAAU,EACV,GAAY,EACZ,YAAsB;IAEtB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,YAAY,CAAC;IACrB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC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KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACrF,CAAC;QACD,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Coerce, GeneralError, Is } from \"@twin.org/core\";\n\n/**\n * Coerces an env var to a boolean, falling back to the supplied default when not set.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The boolean value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to a boolean.\n */\nexport function envBoolean<T>(envVars: T, key: keyof T, defaultValue: boolean): boolean;\nexport function envBoolean<T>(envVars: T, key: keyof T): boolean | undefined;\nexport function envBoolean<T>(\n\tenvVars: T,\n\tkey: keyof T,\n\tdefaultValue?: boolean\n): boolean | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.boolean(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"boolean\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that is already in milliseconds to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The millisecond value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envMs<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envMs<T>(envVars: T, key: keyof T): number | undefined;\nexport function envMs<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that represents an integer count or size to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The count, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envCount<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envCount<T>(envVars: T, key: keyof T): number | undefined;\nexport function envCount<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that represents an integer to an actual integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The integer, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envInteger<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envInteger<T>(envVars: T, key: keyof T): number | undefined;\nexport function envInteger<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Returns an env var as a typed object. Accepts a pre-parsed object, an inline JSON object string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent or cannot be parsed.\n * @returns The parsed object, or the default when absent or the value cannot be parsed.\n */\nexport function envObject<T, U>(envVars: T, key: keyof T, defaultValue: U): U;\n/**\n * Returns an env var as a typed object. Accepts a pre-parsed object, an inline JSON object string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @returns The parsed object, or undefined when the var is absent or the value cannot be parsed.\n */\nexport function envObject<T, U>(envVars: T, key: keyof T): U | undefined;\nexport function envObject<T, U>(envVars: T, key: keyof T, defaultValue?: U): U | undefined {\n\tconst value: unknown = envVars[key];\n\tif (Is.undefined(value)) {\n\t\treturn defaultValue;\n\t}\n\treturn Coerce.object<U>(value) ?? defaultValue;\n}\n\n/**\n * Returns an env var as a typed array. Accepts a pre-parsed array, an inline JSON array string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent or cannot be parsed.\n * @returns The parsed array, or the default when absent or the value cannot be parsed.\n */\nexport function envArray<T, U>(envVars: T, key: keyof T, defaultValue: U[]): U[];\n/**\n * Returns an env var as a typed array. Accepts a pre-parsed array, an inline JSON array string,\n * or a value already expanded from a @json: file reference.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @returns The parsed array, or undefined when the var is absent or the value cannot be parsed.\n */\nexport function envArray<T, U>(envVars: T, key: keyof T): U[] | undefined;\nexport function envArray<T, U>(envVars: T, key: keyof T, defaultValue?: U[]): U[] | undefined {\n\tconst value: unknown = envVars[key];\n\tif (Is.undefined(value)) {\n\t\treturn defaultValue;\n\t}\n\treturn Coerce.array<U>(value) ?? defaultValue;\n}\n\n/**\n * Coerces an env var that is already in seconds to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The second value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envSeconds<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envSeconds<T>(envVars: T, key: keyof T): number | undefined;\nexport function envSeconds<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that is already in minutes to an integer.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The minute value, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envMinutes<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envMinutes<T>(envVars: T, key: keyof T): number | undefined;\nexport function envMinutes<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.integer(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn result;\n}\n\n/**\n * Coerces an env var that is a datetime string, throwing when the value is set but not a valid datetime.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The datetime ISO string, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to a datetime.\n */\nexport function envDateTime<T>(envVars: T, key: keyof T, defaultValue: string): string;\nexport function envDateTime<T>(envVars: T, key: keyof T): string | undefined;\nexport function envDateTime<T>(\n\tenvVars: T,\n\tkey: keyof T,\n\tdefaultValue?: string\n): string | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst result = Coerce.dateTime(value) ?? Coerce.date(value);\n\tif (Is.empty(result)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"datetime\" });\n\t}\n\treturn result.toISOString();\n}\n\n/**\n * Coerces an env var to an integer and converts from seconds to milliseconds.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The value in milliseconds, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envSecToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envSecToMs<T>(envVars: T, key: keyof T): number | undefined;\nexport function envSecToMs<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst n = Coerce.integer(value);\n\tif (Is.empty(n)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn n * 1000;\n}\n\n/**\n * Coerces an env var to an integer and converts from minutes to milliseconds.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to coerce.\n * @param defaultValue The value to return when the env var is absent. Omit to return undefined when absent.\n * @returns The value in milliseconds, the default, or undefined when absent and no default given.\n * @throws GeneralError if the value is set but cannot be coerced to an integer.\n */\nexport function envMinToMs<T>(envVars: T, key: keyof T, defaultValue: number): number;\nexport function envMinToMs<T>(envVars: T, key: keyof T): number | undefined;\nexport function envMinToMs<T>(envVars: T, key: keyof T, defaultValue?: number): number | undefined {\n\tconst value = envVars[key];\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\tconst n = Coerce.integer(value);\n\tif (Is.empty(n)) {\n\t\tthrow new GeneralError(\"node\", \"invalidEnvVarValue\", { key, value, type: \"integer\" });\n\t}\n\treturn n * 60_000;\n}\n\n/**\n * Converts a comma separated list to an array.\n * @param value The comma separated list.\n * @param defaultValue The default value to return when the list is empty or undefined.\n * @returns The array.\n */\nexport function commaSeparatedListToArray<U>(\n\tvalue: string | undefined,\n\tdefaultValue: U[] | undefined = []\n): U[] {\n\tif (!Is.stringValue(value)) {\n\t\treturn defaultValue;\n\t}\n\treturn value\n\t\t.split(\",\")\n\t\t.map(item => item.trim())\n\t\t.filter(item => item.length > 0) as U[];\n}\n\n/**\n * Gets named key integer pairs from an env var holding comma separated key=integer pairs.\n * @param envVars The environment variables object.\n * @param key The property name of the env var to read.\n * @returns The named key integer pairs, or undefined when the env var is absent or empty.\n * @throws GeneralError if an entry is not a unique name=value pair with an integer value.\n */\nexport function envKeyIntegerPairs<T>(\n\tenvVars: T,\n\tkey: keyof T\n): { [key: string]: number } | undefined {\n\tconst entries = commaSeparatedListToArray<string>(envVars[key] as string | undefined, undefined);\n\tif (!Is.arrayValue(entries)) {\n\t\treturn undefined;\n\t}\n\n\tconst keyValues: { [name: string]: number } = {};\n\tfor (const entry of entries) {\n\t\tconst parts = entry.split(\"=\").map(part => part.trim());\n\n\t\tconst keyPart = parts[0];\n\t\tconst valuePart = Coerce.integer(parts[1]);\n\t\tif (\n\t\t\tparts.length !== 2 ||\n\t\t\t!Is.stringValue(keyPart) ||\n\t\t\t!Is.integer(valuePart) ||\n\t\t\t!Is.undefined(keyValues[keyPart])\n\t\t) {\n\t\t\tthrow new GeneralError(\"node\", \"invalidEnvVarPair\", { key: keyPart, value: entry });\n\t\t}\n\t\tkeyValues[keyPart] = valuePart;\n\t}\n\n\treturn keyValues;\n}\n"]}
|
package/dist/es/cli.js
CHANGED
|
@@ -143,7 +143,7 @@ export function constructCliCommand(processEnv, cliArgs) {
|
|
|
143
143
|
param: commandDefParam.key
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
|
-
if (Is.
|
|
146
|
+
if (!Is.empty(paramValue)) {
|
|
147
147
|
cliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;
|
|
148
148
|
}
|
|
149
149
|
if (foundParamIndex >= 0) {
|
package/dist/es/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|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CAAC,kBAAkB,CAAC,CAAC;IAChD,8BAA8B,CAAC,kBAAkB,CAAC,CAAC;IACnD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;AACxD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, GeneralError, I18n, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport * as dotenv from \"dotenv\";\nimport { commaSeparatedListToArray } from \"./builders/helper/envHelpers.js\";\nimport { getCommandDefinitionBootstrapDev } from \"./commands/bootstrapDev.js\";\nimport { getCommandDefinitionHelp } from \"./commands/help.js\";\nimport { getCommandDefinitionIdentityCreate } from \"./commands/identityCreate.js\";\nimport { getCommandDefinitionIdentityImport } from \"./commands/identityImports.js\";\nimport { getCommandDefinitionIdentityList } from \"./commands/identityList.js\";\nimport { getCommandDefinitionIdentityResolve } from \"./commands/identityResolve.js\";\nimport { getCommandDefinitionIdentityVerifiableCredentialCreate } from \"./commands/identityVerifiableCredentialCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodCreate } from \"./commands/identityVerificationMethodCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodImport } from \"./commands/identityVerificationMethodImport.js\";\nimport { getCommandDefinitionNodeIdentityGet } from \"./commands/nodeIdentityGet.js\";\nimport { getCommandDefinitionNodeIdentitySet } from \"./commands/nodeIdentitySet.js\";\nimport { getCommandDefinitionNodeOrgIdGet } from \"./commands/nodeOrgIdGet.js\";\nimport { getCommandDefinitionNodeOrgIdSet } from \"./commands/nodeOrgIdSet.js\";\nimport { getCommandDefinitionOrgUsersList } from \"./commands/orgUsersList.js\";\nimport { getCommandDefinitionRemoveTenantOrgAlias } from \"./commands/removeTenantOrgAlias.js\";\nimport { getCommandDefinitionTenantCreate } from \"./commands/tenantCreate.js\";\nimport { getCommandDefinitionTenantGet } from \"./commands/tenantGet.js\";\nimport { getCommandDefinitionTenantImport } from \"./commands/tenantImport.js\";\nimport { getCommandDefinitionTenantList } from \"./commands/tenantList.js\";\nimport { getCommandDefinitionTenantListByOrg } from \"./commands/tenantListByOrg.js\";\nimport { getCommandDefinitionTenantOrgIdSet } from \"./commands/tenantOrgIdSet.js\";\nimport { getCommandDefinitionTenantUpdate } from \"./commands/tenantUpdate.js\";\nimport { getCommandDefinitionUserCreate } from \"./commands/userCreate.js\";\nimport { getCommandDefinitionUserGet } from \"./commands/userGet.js\";\nimport { getCommandDefinitionUserUpdate } from \"./commands/userUpdate.js\";\nimport { getCommandDefinitionVaultKeyCreate } from \"./commands/vaultKeyCreate.js\";\nimport { getCommandDefinitionVaultKeyImport } from \"./commands/vaultKeyImport.js\";\nimport type { CliCommandParamType } from \"./models/cliCommandParamType.js\";\nimport type { ICliArgs } from \"./models/ICliArgs.js\";\nimport type { ICliCommand } from \"./models/ICliCommand.js\";\nimport type { ICliCommandDefinition } from \"./models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"./models/IEnvironmentVariables.js\";\n\nconst commandDefinitions: { [id: string]: ICliCommandDefinition } = {};\n\n/**\n * Parse command line arguments.\n * @param args The command line arguments.\n * @returns The parsed command line arguments.\n */\nexport function parseCommandLineArgs(args?: string[]): ICliArgs {\n\tlet nodePath;\n\tlet scriptPath;\n\tlet options:\n\t\t| {\n\t\t\t\tkey: string;\n\t\t\t\tvalue: string;\n\t\t }[]\n\t\t| undefined;\n\n\tif (Is.arrayValue(args)) {\n\t\tif (args.length > 0) {\n\t\t\tnodePath = args[0];\n\t\t}\n\t\tif (args.length > 1) {\n\t\t\tscriptPath = args[1];\n\t\t}\n\t\tif (args.length > 2) {\n\t\t\toptions = [];\n\n\t\t\tfor (let i = 2; i < args.length; i++) {\n\t\t\t\tconst arg = args[i];\n\t\t\t\tconst equalIndex = arg.indexOf(\"=\");\n\t\t\t\tif (equalIndex > 0) {\n\t\t\t\t\tconst key = arg.slice(0, equalIndex).trim();\n\t\t\t\t\tconst value = arg.slice(equalIndex + 1).trim();\n\t\t\t\t\tif (key.startsWith(\"--\")) {\n\t\t\t\t\t\toptions.push({ key: key.slice(2), value });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\toptions.push({ key: arg, value: \"\" });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tnodePath,\n\t\tscriptPath,\n\t\toptions\n\t};\n}\n\n/**\n * Construct the CLI command from the parsed arguments.\n * @param processEnv The environment variables from the process.\n * @param cliArgs The parsed CLI arguments.\n * @returns The constructed CLI command.\n * @throws GeneralError if the command is missing.\n */\nexport function constructCliCommand(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\tcliArgs: ICliArgs\n): ICliCommand | undefined {\n\tif (Is.arrayValue(cliArgs.options)) {\n\t\tconst command = cliArgs.options[0];\n\n\t\t// If the first option is --help, we can display help for all commands\n\t\tif (command.key === \"--help\") {\n\t\t\treturn {\n\t\t\t\tdefinition: commandDefinitions.help,\n\t\t\t\tparams: {}\n\t\t\t};\n\t\t}\n\n\t\t// In cases where no command but env-prefix is provided, we just return\n\t\tif (command.key === \"env-prefix\") {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlet resolvedKey = command.key;\n\t\tif (!commandDefinitions[resolvedKey]) {\n\t\t\tconst aliasEntry = Object.entries(commandDefinitions).find(([, def]) =>\n\t\t\t\tdef.aliases?.includes(command.key)\n\t\t\t);\n\t\t\tif (aliasEntry) {\n\t\t\t\tresolvedKey = aliasEntry[0];\n\t\t\t\tCLIDisplay.warning(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.deprecatedAlias\", {\n\t\t\t\t\t\talias: command.key,\n\t\t\t\t\t\tcommand: resolvedKey\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliCommandMissing\", { command: command.key });\n\t\t\t}\n\t\t}\n\n\t\t// We have a valid command, check for --help for that command\n\t\tconst hasHelp = cliArgs.options.find(option => option.key === \"--help\");\n\t\tif (hasHelp) {\n\t\t\treturn {\n\t\t\t\tdefinition: commandDefinitions.help,\n\t\t\t\tparams: {\n\t\t\t\t\tcommand: resolvedKey\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tprocessEnvOptions(processEnv, cliArgs.options);\n\n\t\tconst cliParams: { [id: string]: CliCommandParamType } = {};\n\t\tconst allParamKeys = cliArgs.options\n\t\t\t.map(option => option.key)\n\t\t\t.filter(key => key !== command.key);\n\n\t\tfor (const commandDefParam of commandDefinitions[resolvedKey].params) {\n\t\t\tconst foundParamIndex =\n\t\t\t\tcliArgs.options?.findIndex(option => option.key === commandDefParam.key) ?? -1;\n\t\t\tconst foundParam = foundParamIndex >= 0 ? cliArgs.options?.[foundParamIndex] : undefined;\n\n\t\t\tlet paramValue;\n\t\t\tif (commandDefParam.type === \"number\") {\n\t\t\t\tparamValue = Coerce.number(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t} else if (commandDefParam.type === \"boolean\") {\n\t\t\t\tparamValue = Coerce.boolean(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t} else {\n\t\t\t\tparamValue = Coerce.string(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t}\n\n\t\t\tconst required = commandDefParam.required ?? true;\n\t\t\tif (Is.empty(paramValue) && required) {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliCommandParamMissing\", {\n\t\t\t\t\tcommand: command.key,\n\t\t\t\t\tparam: commandDefParam.key\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (Is.notEmpty(paramValue)) {\n\t\t\t\tcliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;\n\t\t\t}\n\n\t\t\tif (foundParamIndex >= 0) {\n\t\t\t\tconst paramIndex = allParamKeys.indexOf(commandDefParam.key);\n\t\t\t\tif (paramIndex >= 0) {\n\t\t\t\t\tallParamKeys.splice(paramIndex, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (allParamKeys.length > 0) {\n\t\t\tthrow new GeneralError(\"node\", \"cliCommandParamExtra\", {\n\t\t\t\tcommand: command.key,\n\t\t\t\tparams: allParamKeys.join(\", \")\n\t\t\t});\n\t\t}\n\n\t\tif (commandDefinitions[resolvedKey].params.find(param => param.key === \"output-env-prefix\")) {\n\t\t\tcliParams.outputEnvPrefix = (Coerce.string(cliParams.outputEnvPrefix) ?? \"\").toUpperCase();\n\t\t\tcliParams.outputEnvPrefix =\n\t\t\t\tcliParams.outputEnvPrefix.length > 0 && !cliParams.outputEnvPrefix.endsWith(\"_\")\n\t\t\t\t\t? `${cliParams.outputEnvPrefix}_`\n\t\t\t\t\t: cliParams.outputEnvPrefix;\n\t\t}\n\n\t\treturn {\n\t\t\tdefinition: commandDefinitions[resolvedKey],\n\t\t\tparams: cliParams\n\t\t};\n\t}\n}\n\n/**\n * Execute the CLI command.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param cliCommand The CLI command to execute.\n */\nexport async function executeCommand(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables,\n\tcliCommand: ICliCommand\n): Promise<void> {\n\tconst requiresEngineStarted = cliCommand.definition.requiresEngineStarted ?? true;\n\n\ttry {\n\t\tif (requiresEngineStarted) {\n\t\t\tawait engineCore.start(true);\n\t\t}\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.command\"),\n\t\t\tcliCommand.definition.command\n\t\t);\n\t\tfor (const paramKey in cliCommand.params) {\n\t\t\tCLIDisplay.value(paramKey, Coerce.string(cliCommand.params[paramKey]), 1);\n\t\t}\n\t\tCLIDisplay.break();\n\n\t\tawait ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {\n\t\t\tawait cliCommand.definition.action(engineCore, envVars, cliCommand.params);\n\t\t});\n\t} catch (error) {\n\t\tCLIDisplay.spinnerStop();\n\n\t\tthrow error;\n\t} finally {\n\t\tif (requiresEngineStarted) {\n\t\t\tCLIDisplay.break();\n\t\t\tawait engineCore.stop();\n\t\t}\n\t}\n}\n\n/**\n * Load the env files and process the options.\n * @param processEnv The environment variables from the process.\n * @param options The options.\n * @returns The substituted options, mutated in place with env variable values resolved.\n * @throws GeneralError if an env file has errors.\n */\nexport function processEnvOptions(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: {\n\t\tkey: string;\n\t\tvalue: string;\n\t}[]\n): void {\n\tconst inputEnv = options.find(option => option.key === \"load-env\")?.value;\n\n\tif (Is.stringValue(inputEnv)) {\n\t\tconst envFiles = commaSeparatedListToArray<string>(inputEnv);\n\t\tfor (const envFile of envFiles) {\n\t\t\tconst output = dotenv.config({\n\t\t\t\tpath: envFile,\n\t\t\t\tquiet: true\n\t\t\t});\n\n\t\t\tif (output.error) {\n\t\t\t\tthrow output.error;\n\t\t\t}\n\n\t\t\tif (Is.objectValue(output.parsed)) {\n\t\t\t\tfor (const key in output.parsed) {\n\t\t\t\t\tprocessEnv[key] = output.parsed[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn substituteEnvOptions(processEnv, options);\n}\n\n/**\n * Process options and replace any env variables with their values.\n * @param processEnv The environment variables from the process.\n * @param options The options.\n * @throws GeneralError if an env variable is missing.\n */\nexport function substituteEnvOptions(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: {\n\t\tkey: string;\n\t\tvalue: string;\n\t}[]\n): void {\n\tfor (const option of options) {\n\t\tif (option.value.startsWith(\"!\")) {\n\t\t\tconst envVar = processEnv[option.value.slice(1)];\n\t\t\tif (!Is.stringValue(envVar)) {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliEnvVarMissing\", { envVar: option.value.slice(1) });\n\t\t\t}\n\t\t\toption.value = envVar;\n\t\t}\n\t}\n}\n\n/**\n * Register all built-in CLI command definitions into the shared command map.\n */\nexport function registerCommands(): void {\n\tgetCommandDefinitionHelp(commandDefinitions);\n\tgetCommandDefinitionBootstrapDev(commandDefinitions);\n\tgetCommandDefinitionIdentityCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityImport(commandDefinitions);\n\tgetCommandDefinitionIdentityList(commandDefinitions);\n\tgetCommandDefinitionIdentityResolve(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);\n\tgetCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);\n\tgetCommandDefinitionNodeIdentityGet(commandDefinitions);\n\tgetCommandDefinitionNodeIdentitySet(commandDefinitions);\n\tgetCommandDefinitionOrgUsersList(commandDefinitions);\n\tgetCommandDefinitionRemoveTenantOrgAlias(commandDefinitions);\n\tgetCommandDefinitionNodeOrgIdGet(commandDefinitions);\n\tgetCommandDefinitionNodeOrgIdSet(commandDefinitions);\n\tgetCommandDefinitionTenantOrgIdSet(commandDefinitions);\n\tgetCommandDefinitionTenantCreate(commandDefinitions);\n\tgetCommandDefinitionTenantGet(commandDefinitions);\n\tgetCommandDefinitionTenantImport(commandDefinitions);\n\tgetCommandDefinitionTenantList(commandDefinitions);\n\tgetCommandDefinitionTenantListByOrg(commandDefinitions);\n\tgetCommandDefinitionTenantUpdate(commandDefinitions);\n\tgetCommandDefinitionUserCreate(commandDefinitions);\n\tgetCommandDefinitionUserGet(commandDefinitions);\n\tgetCommandDefinitionUserUpdate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyCreate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyImport(commandDefinitions);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO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DX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, GeneralError, I18n, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport * as dotenv from \"dotenv\";\nimport { commaSeparatedListToArray } from \"./builders/helper/envHelpers.js\";\nimport { getCommandDefinitionBootstrapDev } from \"./commands/bootstrapDev.js\";\nimport { getCommandDefinitionHelp } from \"./commands/help.js\";\nimport { getCommandDefinitionIdentityCreate } from \"./commands/identityCreate.js\";\nimport { getCommandDefinitionIdentityImport } from \"./commands/identityImports.js\";\nimport { getCommandDefinitionIdentityList } from \"./commands/identityList.js\";\nimport { getCommandDefinitionIdentityResolve } from \"./commands/identityResolve.js\";\nimport { getCommandDefinitionIdentityVerifiableCredentialCreate } from \"./commands/identityVerifiableCredentialCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodCreate } from \"./commands/identityVerificationMethodCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodImport } from \"./commands/identityVerificationMethodImport.js\";\nimport { getCommandDefinitionNodeIdentityGet } from \"./commands/nodeIdentityGet.js\";\nimport { getCommandDefinitionNodeIdentitySet } from \"./commands/nodeIdentitySet.js\";\nimport { getCommandDefinitionNodeOrgIdGet } from \"./commands/nodeOrgIdGet.js\";\nimport { getCommandDefinitionNodeOrgIdSet } from \"./commands/nodeOrgIdSet.js\";\nimport { getCommandDefinitionOrgUsersList } from \"./commands/orgUsersList.js\";\nimport { getCommandDefinitionRemoveTenantOrgAlias } from \"./commands/removeTenantOrgAlias.js\";\nimport { getCommandDefinitionTenantCreate } from \"./commands/tenantCreate.js\";\nimport { getCommandDefinitionTenantGet } from \"./commands/tenantGet.js\";\nimport { getCommandDefinitionTenantImport } from \"./commands/tenantImport.js\";\nimport { getCommandDefinitionTenantList } from \"./commands/tenantList.js\";\nimport { getCommandDefinitionTenantListByOrg } from \"./commands/tenantListByOrg.js\";\nimport { getCommandDefinitionTenantOrgIdSet } from \"./commands/tenantOrgIdSet.js\";\nimport { getCommandDefinitionTenantUpdate } from \"./commands/tenantUpdate.js\";\nimport { getCommandDefinitionUserCreate } from \"./commands/userCreate.js\";\nimport { getCommandDefinitionUserGet } from \"./commands/userGet.js\";\nimport { getCommandDefinitionUserUpdate } from \"./commands/userUpdate.js\";\nimport { getCommandDefinitionVaultKeyCreate } from \"./commands/vaultKeyCreate.js\";\nimport { getCommandDefinitionVaultKeyImport } from \"./commands/vaultKeyImport.js\";\nimport type { CliCommandParamType } from \"./models/cliCommandParamType.js\";\nimport type { ICliArgs } from \"./models/ICliArgs.js\";\nimport type { ICliCommand } from \"./models/ICliCommand.js\";\nimport type { ICliCommandDefinition } from \"./models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"./models/IEnvironmentVariables.js\";\n\nconst commandDefinitions: { [id: string]: ICliCommandDefinition } = {};\n\n/**\n * Parse command line arguments.\n * @param args The command line arguments.\n * @returns The parsed command line arguments.\n */\nexport function parseCommandLineArgs(args?: string[]): ICliArgs {\n\tlet nodePath;\n\tlet scriptPath;\n\tlet options:\n\t\t| {\n\t\t\t\tkey: string;\n\t\t\t\tvalue: string;\n\t\t }[]\n\t\t| undefined;\n\n\tif (Is.arrayValue(args)) {\n\t\tif (args.length > 0) {\n\t\t\tnodePath = args[0];\n\t\t}\n\t\tif (args.length > 1) {\n\t\t\tscriptPath = args[1];\n\t\t}\n\t\tif (args.length > 2) {\n\t\t\toptions = [];\n\n\t\t\tfor (let i = 2; i < args.length; i++) {\n\t\t\t\tconst arg = args[i];\n\t\t\t\tconst equalIndex = arg.indexOf(\"=\");\n\t\t\t\tif (equalIndex > 0) {\n\t\t\t\t\tconst key = arg.slice(0, equalIndex).trim();\n\t\t\t\t\tconst value = arg.slice(equalIndex + 1).trim();\n\t\t\t\t\tif (key.startsWith(\"--\")) {\n\t\t\t\t\t\toptions.push({ key: key.slice(2), value });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\toptions.push({ key: arg, value: \"\" });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tnodePath,\n\t\tscriptPath,\n\t\toptions\n\t};\n}\n\n/**\n * Construct the CLI command from the parsed arguments.\n * @param processEnv The environment variables from the process.\n * @param cliArgs The parsed CLI arguments.\n * @returns The constructed CLI command.\n * @throws GeneralError if the command is missing.\n */\nexport function constructCliCommand(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\tcliArgs: ICliArgs\n): ICliCommand | undefined {\n\tif (Is.arrayValue(cliArgs.options)) {\n\t\tconst command = cliArgs.options[0];\n\n\t\t// If the first option is --help, we can display help for all commands\n\t\tif (command.key === \"--help\") {\n\t\t\treturn {\n\t\t\t\tdefinition: commandDefinitions.help,\n\t\t\t\tparams: {}\n\t\t\t};\n\t\t}\n\n\t\t// In cases where no command but env-prefix is provided, we just return\n\t\tif (command.key === \"env-prefix\") {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlet resolvedKey = command.key;\n\t\tif (!commandDefinitions[resolvedKey]) {\n\t\t\tconst aliasEntry = Object.entries(commandDefinitions).find(([, def]) =>\n\t\t\t\tdef.aliases?.includes(command.key)\n\t\t\t);\n\t\t\tif (aliasEntry) {\n\t\t\t\tresolvedKey = aliasEntry[0];\n\t\t\t\tCLIDisplay.warning(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.deprecatedAlias\", {\n\t\t\t\t\t\talias: command.key,\n\t\t\t\t\t\tcommand: resolvedKey\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliCommandMissing\", { command: command.key });\n\t\t\t}\n\t\t}\n\n\t\t// We have a valid command, check for --help for that command\n\t\tconst hasHelp = cliArgs.options.find(option => option.key === \"--help\");\n\t\tif (hasHelp) {\n\t\t\treturn {\n\t\t\t\tdefinition: commandDefinitions.help,\n\t\t\t\tparams: {\n\t\t\t\t\tcommand: resolvedKey\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tprocessEnvOptions(processEnv, cliArgs.options);\n\n\t\tconst cliParams: { [id: string]: CliCommandParamType } = {};\n\t\tconst allParamKeys = cliArgs.options\n\t\t\t.map(option => option.key)\n\t\t\t.filter(key => key !== command.key);\n\n\t\tfor (const commandDefParam of commandDefinitions[resolvedKey].params) {\n\t\t\tconst foundParamIndex =\n\t\t\t\tcliArgs.options?.findIndex(option => option.key === commandDefParam.key) ?? -1;\n\t\t\tconst foundParam = foundParamIndex >= 0 ? cliArgs.options?.[foundParamIndex] : undefined;\n\n\t\t\tlet paramValue;\n\t\t\tif (commandDefParam.type === \"number\") {\n\t\t\t\tparamValue = Coerce.number(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t} else if (commandDefParam.type === \"boolean\") {\n\t\t\t\tparamValue = Coerce.boolean(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t} else {\n\t\t\t\tparamValue = Coerce.string(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t}\n\n\t\t\tconst required = commandDefParam.required ?? true;\n\t\t\tif (Is.empty(paramValue) && required) {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliCommandParamMissing\", {\n\t\t\t\t\tcommand: command.key,\n\t\t\t\t\tparam: commandDefParam.key\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!Is.empty(paramValue)) {\n\t\t\t\tcliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;\n\t\t\t}\n\n\t\t\tif (foundParamIndex >= 0) {\n\t\t\t\tconst paramIndex = allParamKeys.indexOf(commandDefParam.key);\n\t\t\t\tif (paramIndex >= 0) {\n\t\t\t\t\tallParamKeys.splice(paramIndex, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (allParamKeys.length > 0) {\n\t\t\tthrow new GeneralError(\"node\", \"cliCommandParamExtra\", {\n\t\t\t\tcommand: command.key,\n\t\t\t\tparams: allParamKeys.join(\", \")\n\t\t\t});\n\t\t}\n\n\t\tif (commandDefinitions[resolvedKey].params.find(param => param.key === \"output-env-prefix\")) {\n\t\t\tcliParams.outputEnvPrefix = (Coerce.string(cliParams.outputEnvPrefix) ?? \"\").toUpperCase();\n\t\t\tcliParams.outputEnvPrefix =\n\t\t\t\tcliParams.outputEnvPrefix.length > 0 && !cliParams.outputEnvPrefix.endsWith(\"_\")\n\t\t\t\t\t? `${cliParams.outputEnvPrefix}_`\n\t\t\t\t\t: cliParams.outputEnvPrefix;\n\t\t}\n\n\t\treturn {\n\t\t\tdefinition: commandDefinitions[resolvedKey],\n\t\t\tparams: cliParams\n\t\t};\n\t}\n}\n\n/**\n * Execute the CLI command.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param cliCommand The CLI command to execute.\n */\nexport async function executeCommand(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables,\n\tcliCommand: ICliCommand\n): Promise<void> {\n\tconst requiresEngineStarted = cliCommand.definition.requiresEngineStarted ?? true;\n\n\ttry {\n\t\tif (requiresEngineStarted) {\n\t\t\tawait engineCore.start(true);\n\t\t}\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.command\"),\n\t\t\tcliCommand.definition.command\n\t\t);\n\t\tfor (const paramKey in cliCommand.params) {\n\t\t\tCLIDisplay.value(paramKey, Coerce.string(cliCommand.params[paramKey]), 1);\n\t\t}\n\t\tCLIDisplay.break();\n\n\t\tawait ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {\n\t\t\tawait cliCommand.definition.action(engineCore, envVars, cliCommand.params);\n\t\t});\n\t} catch (error) {\n\t\tCLIDisplay.spinnerStop();\n\n\t\tthrow error;\n\t} finally {\n\t\tif (requiresEngineStarted) {\n\t\t\tCLIDisplay.break();\n\t\t\tawait engineCore.stop();\n\t\t}\n\t}\n}\n\n/**\n * Load the env files and process the options.\n * @param processEnv The environment variables from the process.\n * @param options The options.\n * @returns The substituted options, mutated in place with env variable values resolved.\n * @throws GeneralError if an env file has errors.\n */\nexport function processEnvOptions(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: {\n\t\tkey: string;\n\t\tvalue: string;\n\t}[]\n): void {\n\tconst inputEnv = options.find(option => option.key === \"load-env\")?.value;\n\n\tif (Is.stringValue(inputEnv)) {\n\t\tconst envFiles = commaSeparatedListToArray<string>(inputEnv);\n\t\tfor (const envFile of envFiles) {\n\t\t\tconst output = dotenv.config({\n\t\t\t\tpath: envFile,\n\t\t\t\tquiet: true\n\t\t\t});\n\n\t\t\tif (output.error) {\n\t\t\t\tthrow output.error;\n\t\t\t}\n\n\t\t\tif (Is.objectValue(output.parsed)) {\n\t\t\t\tfor (const key in output.parsed) {\n\t\t\t\t\tprocessEnv[key] = output.parsed[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn substituteEnvOptions(processEnv, options);\n}\n\n/**\n * Process options and replace any env variables with their values.\n * @param processEnv The environment variables from the process.\n * @param options The options.\n * @throws GeneralError if an env variable is missing.\n */\nexport function substituteEnvOptions(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: {\n\t\tkey: string;\n\t\tvalue: string;\n\t}[]\n): void {\n\tfor (const option of options) {\n\t\tif (option.value.startsWith(\"!\")) {\n\t\t\tconst envVar = processEnv[option.value.slice(1)];\n\t\t\tif (!Is.stringValue(envVar)) {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliEnvVarMissing\", { envVar: option.value.slice(1) });\n\t\t\t}\n\t\t\toption.value = envVar;\n\t\t}\n\t}\n}\n\n/**\n * Register all built-in CLI command definitions into the shared command map.\n */\nexport function registerCommands(): void {\n\tgetCommandDefinitionHelp(commandDefinitions);\n\tgetCommandDefinitionBootstrapDev(commandDefinitions);\n\tgetCommandDefinitionIdentityCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityImport(commandDefinitions);\n\tgetCommandDefinitionIdentityList(commandDefinitions);\n\tgetCommandDefinitionIdentityResolve(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);\n\tgetCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);\n\tgetCommandDefinitionNodeIdentityGet(commandDefinitions);\n\tgetCommandDefinitionNodeIdentitySet(commandDefinitions);\n\tgetCommandDefinitionOrgUsersList(commandDefinitions);\n\tgetCommandDefinitionRemoveTenantOrgAlias(commandDefinitions);\n\tgetCommandDefinitionNodeOrgIdGet(commandDefinitions);\n\tgetCommandDefinitionNodeOrgIdSet(commandDefinitions);\n\tgetCommandDefinitionTenantOrgIdSet(commandDefinitions);\n\tgetCommandDefinitionTenantCreate(commandDefinitions);\n\tgetCommandDefinitionTenantGet(commandDefinitions);\n\tgetCommandDefinitionTenantImport(commandDefinitions);\n\tgetCommandDefinitionTenantList(commandDefinitions);\n\tgetCommandDefinitionTenantListByOrg(commandDefinitions);\n\tgetCommandDefinitionTenantUpdate(commandDefinitions);\n\tgetCommandDefinitionUserCreate(commandDefinitions);\n\tgetCommandDefinitionUserGet(commandDefinitions);\n\tgetCommandDefinitionUserUpdate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyCreate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyImport(commandDefinitions);\n}\n"]}
|
|
@@ -109,7 +109,7 @@ export async function bootstrapDev(engineCore, envVars, params) {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
const defaultAttestationConnectorType = engineCore.getRegisteredInstanceTypeOptional("attestationConnector");
|
|
112
|
-
if (Is.
|
|
112
|
+
if (!Is.empty(defaultAttestationConnectorType)) {
|
|
113
113
|
CLIDisplay.break();
|
|
114
114
|
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-dev.labels.attestationMethodCreate"));
|
|
115
115
|
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
@@ -120,7 +120,7 @@ export async function bootstrapDev(engineCore, envVars, params) {
|
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
const defaultImmutableProofComponentType = engineCore.getRegisteredInstanceTypeOptional("immutableProofComponent");
|
|
123
|
-
if (Is.
|
|
123
|
+
if (!Is.empty(defaultImmutableProofComponentType)) {
|
|
124
124
|
CLIDisplay.break();
|
|
125
125
|
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-dev.labels.immutableProofMethodCreate"));
|
|
126
126
|
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
@@ -264,7 +264,7 @@ async function resolveDefaultTenant(engineCore) {
|
|
|
264
264
|
}
|
|
265
265
|
cursor = result.cursor;
|
|
266
266
|
} while (Is.stringValue(cursor));
|
|
267
|
-
if (Is.
|
|
267
|
+
if (!Is.empty(firstTenant)) {
|
|
268
268
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.bootstrap-dev.labels.tenantFallback"), firstTenant.id);
|
|
269
269
|
}
|
|
270
270
|
return firstTenant;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrapDev.js","sourceRoot":"","sources":["../../../src/commands/bootstrapDev.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,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;AAElF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAM7E,MA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;IACH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IAuthenticationAdminComponent } from \"@twin.org/api-auth-entity-storage-models\";\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { identityCreate } from \"./identityCreate.js\";\nimport { identityVerificationMethodCreate } from \"./identityVerificationMethodCreate.js\";\nimport { tenantCreate } from \"./tenantCreate.js\";\nimport { userCreate } from \"./userCreate.js\";\nimport { vaultKeyCreate } from \"./vaultKeyCreate.js\";\nimport { commaSeparatedListToArray } from \"../builders/helper/envHelpers.js\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"bootstrap-dev\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionBootstrapDev(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\taliases: [\"bootstrap-legacy\"],\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.bootstrap-dev.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.bootstrap-dev.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-dev.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-dev.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => bootstrapDev(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for development bootstrap.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @returns A promise that resolves when the bootstrap sequence has completed.\n */\nexport async function bootstrapDev(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {}\n): Promise<void> {\n\tconst features = commaSeparatedListToArray(envVars.features ?? \"admin-user,wallet\");\n\n\tconst state = engineCore.getState();\n\tconst requireWallet = features.includes(\"wallet\");\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tlet nodeId = state.nodeId ?? envVars.nodeIdentity;\n\tlet organizationId = tenantEnabled ? undefined : state.nodeOrganizationId;\n\tlet tenant: { id: string; organizationId: string } | undefined;\n\n\tif (features.length === 0) {\n\t\tthrow new GeneralError(\"bootstrapDev\", \"noFeaturesEnabled\");\n\t}\n\n\tCLIDisplay.break();\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeIdentityCreate\")\n\t);\n\n\tconst nodeIdentity = await identityCreate(engineCore, envVars, {\n\t\tidentity: nodeId,\n\t\tmnemonic: envVars.nodeMnemonic,\n\t\tfundWallet: requireWallet,\n\t\tnodeId: true\n\t});\n\n\tnodeId = nodeIdentity.did;\n\n\tCLIDisplay.break();\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeAuthKeyCreate\")\n\t);\n\tawait vaultKeyCreate(engineCore, envVars, {\n\t\tidentity: nodeId,\n\t\tkeyType: \"Ed25519\",\n\t\tkeyId: envVars.authSigningKeyId,\n\t\toverwriteMode: \"skip\"\n\t});\n\n\t// Always create the organisation identity first so it can be associated with\n\t// the tenant (multi-tenant) or the node (single-tenant) immediately after.\n\t// The trust verification method is always added to the organisation identities.\n\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.organisationCreate\")\n\t\t);\n\n\t\tif (tenantEnabled) {\n\t\t\tconst existingTenant = Is.stringValue(envVars.tenantId)\n\t\t\t\t? await resolveTenantById(engineCore, envVars.tenantId)\n\t\t\t\t: await resolveDefaultTenant(engineCore);\n\t\t\torganizationId = existingTenant?.organizationId;\n\t\t}\n\n\t\tconst organisation = await identityCreate(engineCore, envVars, {\n\t\t\tidentity: organizationId ?? envVars.organizationIdentity,\n\t\t\tmnemonic: envVars.organizationMnemonic,\n\t\t\tfundWallet: requireWallet\n\t\t});\n\t\torganizationId = organisation.did;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.trustVerificationMethodCreate\")\n\t\t);\n\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\tidentity: organisation.did,\n\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\tverificationMethodId: envVars.trustVerificationMethodId,\n\t\t\toverwriteMode: \"skip\"\n\t\t});\n\n\t\tif (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.blobStorageKeyCreate\")\n\t\t\t);\n\t\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\t\tidentity: organizationId,\n\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\tkeyId: envVars.blobStorageEncryptionKeyId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tconst defaultAttestationConnectorType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\tif (Is.notEmpty(defaultAttestationConnectorType)) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.attestationMethodCreate\")\n\t\t\t);\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: organizationId,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.attestationVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tconst defaultImmutableProofComponentType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\tif (Is.notEmpty(defaultImmutableProofComponentType)) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.immutableProofMethodCreate\")\n\t\t\t);\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: organizationId,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.immutableProofVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\t// In single-tenant mode, record the org DID in state so the node can resolve its\n\t\t// organisation without a tenant lookup.\n\t\tif (!tenantEnabled && !Is.stringValue(state.nodeOrganizationId)) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeOrganizationIdSet\")\n\t\t\t);\n\t\t\tstate.nodeOrganizationId = organisation.did;\n\t\t\tengineCore.setStateDirty();\n\t\t\tCLIDisplay.done();\n\t\t}\n\t});\n\n\tif (tenantEnabled) {\n\t\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\t\t// Resolve an existing tenant so a re-run does not create a duplicate.\n\t\t\t// When a specific tenant ID is configured, look it up directly;\n\t\t\t// otherwise search for the first tenant labelled \"Tenant\".\n\t\t\tif (Is.stringValue(envVars.tenantId)) {\n\t\t\t\ttenant = await resolveTenantById(engineCore, envVars.tenantId);\n\t\t\t} else {\n\t\t\t\ttenant = await resolveDefaultTenant(engineCore);\n\t\t\t}\n\n\t\t\t// Still empty so create a new tenant for the node and associate it with the organisation.\n\t\t\tif (Is.empty(tenant)) {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeTenantCreate\")\n\t\t\t\t);\n\t\t\t\tconst tenantDetails = await tenantCreate(engineCore, envVars, {\n\t\t\t\t\ttenantId: envVars.tenantId,\n\t\t\t\t\tapiKey: envVars.tenantApiKey,\n\t\t\t\t\tlabel: \"Tenant\",\n\t\t\t\t\torganizationId\n\t\t\t\t});\n\n\t\t\t\ttenant = {\n\t\t\t\t\tid: tenantDetails.tenantId,\n\t\t\t\t\torganizationId: organizationId ?? tenantDetails.organizationId ?? \"\"\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\t}\n\n\tif (features.includes(\"admin-user\")) {\n\t\tawait ContextIdStore.run(\n\t\t\t{ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenant?.id },\n\t\t\tasync () => {\n\t\t\t\tconst orgDid = await resolveOrganizationDid(engineCore, tenantEnabled, tenant?.id);\n\t\t\t\tconst effectiveAdminEmail =\n\t\t\t\t\tenvVars.adminUserName ?? `admin@${tenantEnabled ? \"tenant\" : \"node\"}`;\n\t\t\t\tconst adminUser = await resolveDefaultAdminUser(engineCore, effectiveAdminEmail);\n\t\t\t\tlet userDid = adminUser?.userIdentity;\n\n\t\t\t\tif (Is.empty(adminUser)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.adminIdentityCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tconst result = await identityCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: envVars.adminUserIdentity,\n\t\t\t\t\t\tmnemonic: envVars.adminUserMnemonic,\n\t\t\t\t\t\tcontroller: orgDid\n\t\t\t\t\t});\n\n\t\t\t\t\tuserDid = result.did;\n\t\t\t\t}\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.adminUserCreate\")\n\t\t\t\t);\n\t\t\t\tawait userCreate(engineCore, envVars, {\n\t\t\t\t\tuserIdentity: userDid,\n\t\t\t\t\torganizationIdentity: orgDid,\n\t\t\t\t\ttenantId: tenant?.id,\n\t\t\t\t\temail: envVars.adminUserName ?? `admin@${tenantEnabled ? \"tenant\" : \"node\"}`,\n\t\t\t\t\tpassword: envVars.adminUserPassword,\n\t\t\t\t\tscope:\n\t\t\t\t\t\tenvVars.adminUserScope ??\n\t\t\t\t\t\t(tenantEnabled\n\t\t\t\t\t\t\t? [\"global-admin\", \"tenant-admin\", \"user-admin\"]\n\t\t\t\t\t\t\t: [\"global-admin\", \"user-admin\"]\n\t\t\t\t\t\t).join(\",\"),\n\t\t\t\t\tgivenName: tenantEnabled ? \"Tenant\" : \"Node\",\n\t\t\t\t\tfamilyName: \"Admin\",\n\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n}\n\n/**\n * Resolve the organisation DID from node state (single-tenant) or the tenant entry (multi-tenant).\n * @param engineCore The engine core.\n * @param tenantEnabled Whether multi-tenancy is enabled.\n * @param tenantId The active tenant ID (multi-tenant only).\n * @returns The organisation DID.\n * @throws GeneralError if the organisation has not been associated yet.\n * @internal\n */\nasync function resolveOrganizationDid(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\ttenantEnabled: boolean,\n\ttenantId: string | undefined\n): Promise<string> {\n\tif (tenantEnabled) {\n\t\tif (Is.stringValue(tenantId)) {\n\t\t\tconst tenantAdminComponentType =\n\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\t\t\tif (Is.stringValue(tenantAdminComponentType)) {\n\t\t\t\tconst tenantAdminComponent =\n\t\t\t\t\tComponentFactory.get<ITenantAdminComponent>(tenantAdminComponentType);\n\t\t\t\tconst tenant = await tenantAdminComponent.get(tenantId);\n\t\t\t\tif (Is.stringValue(tenant.organizationId)) {\n\t\t\t\t\treturn tenant.organizationId;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconst state = engineCore.getState();\n\t\tif (Is.stringValue(state.nodeOrganizationId)) {\n\t\t\treturn state.nodeOrganizationId;\n\t\t}\n\t}\n\n\tthrow new GeneralError(\"bootstrapDev\", \"organizationNotSet\");\n}\n\n/**\n * Resolve the default tenant id for re-bootstrap when multi-tenancy is enabled.\n * @param engineCore The engine core.\n * @returns The tenant id if one exists in storage.\n * @internal\n */\nasync function resolveDefaultTenant(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>\n): Promise<{ id: string; organizationId: string } | undefined> {\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\treturn undefined;\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tlet cursor: string | undefined;\n\tlet firstTenant: { id: string; organizationId: string } | undefined;\n\n\tdo {\n\t\tconst result = await tenantAdminService.query(\n\t\t\tundefined,\n\t\t\t[\"id\", \"organizationId\", \"label\"],\n\t\t\tcursor\n\t\t);\n\t\tconst nodeTenant = result.tenants.find(tenant => tenant.label === \"Tenant\");\n\t\tif (nodeTenant) {\n\t\t\treturn {\n\t\t\t\tid: nodeTenant.id,\n\t\t\t\torganizationId: nodeTenant.organizationId ?? \"\"\n\t\t\t};\n\t\t}\n\n\t\tif (Is.empty(firstTenant) && Is.arrayValue(result.tenants)) {\n\t\t\tfirstTenant = {\n\t\t\t\tid: result.tenants[0].id,\n\t\t\t\torganizationId: result.tenants[0].organizationId ?? \"\"\n\t\t\t};\n\t\t}\n\n\t\tcursor = result.cursor;\n\t} while (Is.stringValue(cursor));\n\n\tif (Is.notEmpty(firstTenant)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.tenantFallback\"),\n\t\t\tfirstTenant.id\n\t\t);\n\t}\n\n\treturn firstTenant;\n}\n\n/**\n * Resolve the admin user by email for idempotent re-bootstrap.\n * @param engineCore The engine core.\n * @param email The email address of the admin user to look up.\n * @returns The admin user if one exists in storage.\n * @internal\n */\nasync function resolveDefaultAdminUser(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\temail: string\n): Promise<{ email: string; userIdentity: string; organizationIdentity: string } | undefined> {\n\tconst defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"authenticationAdminComponent\"\n\t);\n\tconst authenticationAdminComponent = ComponentFactory.get<IAuthenticationAdminComponent>(\n\t\tdefaultAuthenticationAdminComponentType\n\t);\n\n\ttry {\n\t\treturn await authenticationAdminComponent.get(email);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolve a tenant by its specific ID for idempotent re-bootstrap.\n * @param engineCore The engine core.\n * @param tenantId The tenant ID to look up.\n * @returns The tenant if found, otherwise undefined.\n * @internal\n */\nasync function resolveTenantById(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\ttenantId: string\n): Promise<{ id: string; organizationId: string } | undefined> {\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\treturn undefined;\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\ttry {\n\t\tconst found = await tenantAdminService.get(tenantId);\n\t\treturn {\n\t\t\tid: found.id,\n\t\t\torganizationId: found.organizationId ?? \"\"\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bootstrapDev.js","sourceRoot":"","sources":["../../../src/commands/bootstrapDev.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,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;AAElF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAM7E,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,OAAO,EAAE,CAAC,kBAAkB,CAAC;QAC7B,WAAW,EAAE,IAAI,CAAC,aAA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KAAK,CACf,IAAI,CAAC,aAAa,CAAC,uDAAuD,CAAC,EAC3E,WAAW,CAAC,EAAE,CACd,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,uBAAuB,CACrC,UAA4D,EAC5D,KAAa;IAEb,MAAM,uCAAuC,GAAG,UAAU,CAAC,yBAAyB,CACnF,8BAA8B,CAC9B,CAAC;IACF,MAAM,4BAA4B,GAAG,gBAAgB,CAAC,GAAG,CACxD,uCAAuC,CACvC,CAAC;IAEF,IAAI,CAAC;QACJ,OAAO,MAAM,4BAA4B,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,iBAAiB,CAC/B,UAA4D,EAC5D,QAAgB;IAEhB,MAAM,+BAA+B,GACpC,UAAU,CAAC,iCAAiC,CAAC,sBAAsB,CAAC,CAAC;IAEtE,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,+BAA+B,CAAC,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAC9C,+BAA+B,CAC/B,CAAC;IAEF,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrD,OAAO;YACN,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,cAAc,EAAE,KAAK,CAAC,cAAc,IAAI,EAAE;SAC1C,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IAuthenticationAdminComponent } from \"@twin.org/api-auth-entity-storage-models\";\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { identityCreate } from \"./identityCreate.js\";\nimport { identityVerificationMethodCreate } from \"./identityVerificationMethodCreate.js\";\nimport { tenantCreate } from \"./tenantCreate.js\";\nimport { userCreate } from \"./userCreate.js\";\nimport { vaultKeyCreate } from \"./vaultKeyCreate.js\";\nimport { commaSeparatedListToArray } from \"../builders/helper/envHelpers.js\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"bootstrap-dev\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionBootstrapDev(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\taliases: [\"bootstrap-legacy\"],\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.bootstrap-dev.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.bootstrap-dev.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-dev.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-dev.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => bootstrapDev(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for development bootstrap.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @returns A promise that resolves when the bootstrap sequence has completed.\n */\nexport async function bootstrapDev(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {}\n): Promise<void> {\n\tconst features = commaSeparatedListToArray(envVars.features ?? \"admin-user,wallet\");\n\n\tconst state = engineCore.getState();\n\tconst requireWallet = features.includes(\"wallet\");\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tlet nodeId = state.nodeId ?? envVars.nodeIdentity;\n\tlet organizationId = tenantEnabled ? undefined : state.nodeOrganizationId;\n\tlet tenant: { id: string; organizationId: string } | undefined;\n\n\tif (features.length === 0) {\n\t\tthrow new GeneralError(\"bootstrapDev\", \"noFeaturesEnabled\");\n\t}\n\n\tCLIDisplay.break();\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeIdentityCreate\")\n\t);\n\n\tconst nodeIdentity = await identityCreate(engineCore, envVars, {\n\t\tidentity: nodeId,\n\t\tmnemonic: envVars.nodeMnemonic,\n\t\tfundWallet: requireWallet,\n\t\tnodeId: true\n\t});\n\n\tnodeId = nodeIdentity.did;\n\n\tCLIDisplay.break();\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeAuthKeyCreate\")\n\t);\n\tawait vaultKeyCreate(engineCore, envVars, {\n\t\tidentity: nodeId,\n\t\tkeyType: \"Ed25519\",\n\t\tkeyId: envVars.authSigningKeyId,\n\t\toverwriteMode: \"skip\"\n\t});\n\n\t// Always create the organisation identity first so it can be associated with\n\t// the tenant (multi-tenant) or the node (single-tenant) immediately after.\n\t// The trust verification method is always added to the organisation identities.\n\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.organisationCreate\")\n\t\t);\n\n\t\tif (tenantEnabled) {\n\t\t\tconst existingTenant = Is.stringValue(envVars.tenantId)\n\t\t\t\t? await resolveTenantById(engineCore, envVars.tenantId)\n\t\t\t\t: await resolveDefaultTenant(engineCore);\n\t\t\torganizationId = existingTenant?.organizationId;\n\t\t}\n\n\t\tconst organisation = await identityCreate(engineCore, envVars, {\n\t\t\tidentity: organizationId ?? envVars.organizationIdentity,\n\t\t\tmnemonic: envVars.organizationMnemonic,\n\t\t\tfundWallet: requireWallet\n\t\t});\n\t\torganizationId = organisation.did;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.trustVerificationMethodCreate\")\n\t\t);\n\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\tidentity: organisation.did,\n\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\tverificationMethodId: envVars.trustVerificationMethodId,\n\t\t\toverwriteMode: \"skip\"\n\t\t});\n\n\t\tif (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.blobStorageKeyCreate\")\n\t\t\t);\n\t\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\t\tidentity: organizationId,\n\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\tkeyId: envVars.blobStorageEncryptionKeyId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tconst defaultAttestationConnectorType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\tif (!Is.empty(defaultAttestationConnectorType)) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.attestationMethodCreate\")\n\t\t\t);\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: organizationId,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.attestationVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tconst defaultImmutableProofComponentType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\tif (!Is.empty(defaultImmutableProofComponentType)) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.immutableProofMethodCreate\")\n\t\t\t);\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: organizationId,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.immutableProofVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\t// In single-tenant mode, record the org DID in state so the node can resolve its\n\t\t// organisation without a tenant lookup.\n\t\tif (!tenantEnabled && !Is.stringValue(state.nodeOrganizationId)) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeOrganizationIdSet\")\n\t\t\t);\n\t\t\tstate.nodeOrganizationId = organisation.did;\n\t\t\tengineCore.setStateDirty();\n\t\t\tCLIDisplay.done();\n\t\t}\n\t});\n\n\tif (tenantEnabled) {\n\t\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\t\t// Resolve an existing tenant so a re-run does not create a duplicate.\n\t\t\t// When a specific tenant ID is configured, look it up directly;\n\t\t\t// otherwise search for the first tenant labelled \"Tenant\".\n\t\t\tif (Is.stringValue(envVars.tenantId)) {\n\t\t\t\ttenant = await resolveTenantById(engineCore, envVars.tenantId);\n\t\t\t} else {\n\t\t\t\ttenant = await resolveDefaultTenant(engineCore);\n\t\t\t}\n\n\t\t\t// Still empty so create a new tenant for the node and associate it with the organisation.\n\t\t\tif (Is.empty(tenant)) {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.nodeTenantCreate\")\n\t\t\t\t);\n\t\t\t\tconst tenantDetails = await tenantCreate(engineCore, envVars, {\n\t\t\t\t\ttenantId: envVars.tenantId,\n\t\t\t\t\tapiKey: envVars.tenantApiKey,\n\t\t\t\t\tlabel: \"Tenant\",\n\t\t\t\t\torganizationId\n\t\t\t\t});\n\n\t\t\t\ttenant = {\n\t\t\t\t\tid: tenantDetails.tenantId,\n\t\t\t\t\torganizationId: organizationId ?? tenantDetails.organizationId ?? \"\"\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\t}\n\n\tif (features.includes(\"admin-user\")) {\n\t\tawait ContextIdStore.run(\n\t\t\t{ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenant?.id },\n\t\t\tasync () => {\n\t\t\t\tconst orgDid = await resolveOrganizationDid(engineCore, tenantEnabled, tenant?.id);\n\t\t\t\tconst effectiveAdminEmail =\n\t\t\t\t\tenvVars.adminUserName ?? `admin@${tenantEnabled ? \"tenant\" : \"node\"}`;\n\t\t\t\tconst adminUser = await resolveDefaultAdminUser(engineCore, effectiveAdminEmail);\n\t\t\t\tlet userDid = adminUser?.userIdentity;\n\n\t\t\t\tif (Is.empty(adminUser)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.adminIdentityCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tconst result = await identityCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: envVars.adminUserIdentity,\n\t\t\t\t\t\tmnemonic: envVars.adminUserMnemonic,\n\t\t\t\t\t\tcontroller: orgDid\n\t\t\t\t\t});\n\n\t\t\t\t\tuserDid = result.did;\n\t\t\t\t}\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.adminUserCreate\")\n\t\t\t\t);\n\t\t\t\tawait userCreate(engineCore, envVars, {\n\t\t\t\t\tuserIdentity: userDid,\n\t\t\t\t\torganizationIdentity: orgDid,\n\t\t\t\t\ttenantId: tenant?.id,\n\t\t\t\t\temail: envVars.adminUserName ?? `admin@${tenantEnabled ? \"tenant\" : \"node\"}`,\n\t\t\t\t\tpassword: envVars.adminUserPassword,\n\t\t\t\t\tscope:\n\t\t\t\t\t\tenvVars.adminUserScope ??\n\t\t\t\t\t\t(tenantEnabled\n\t\t\t\t\t\t\t? [\"global-admin\", \"tenant-admin\", \"user-admin\"]\n\t\t\t\t\t\t\t: [\"global-admin\", \"user-admin\"]\n\t\t\t\t\t\t).join(\",\"),\n\t\t\t\t\tgivenName: tenantEnabled ? \"Tenant\" : \"Node\",\n\t\t\t\t\tfamilyName: \"Admin\",\n\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n}\n\n/**\n * Resolve the organisation DID from node state (single-tenant) or the tenant entry (multi-tenant).\n * @param engineCore The engine core.\n * @param tenantEnabled Whether multi-tenancy is enabled.\n * @param tenantId The active tenant ID (multi-tenant only).\n * @returns The organisation DID.\n * @throws GeneralError if the organisation has not been associated yet.\n * @internal\n */\nasync function resolveOrganizationDid(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\ttenantEnabled: boolean,\n\ttenantId: string | undefined\n): Promise<string> {\n\tif (tenantEnabled) {\n\t\tif (Is.stringValue(tenantId)) {\n\t\t\tconst tenantAdminComponentType =\n\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\t\t\tif (Is.stringValue(tenantAdminComponentType)) {\n\t\t\t\tconst tenantAdminComponent =\n\t\t\t\t\tComponentFactory.get<ITenantAdminComponent>(tenantAdminComponentType);\n\t\t\t\tconst tenant = await tenantAdminComponent.get(tenantId);\n\t\t\t\tif (Is.stringValue(tenant.organizationId)) {\n\t\t\t\t\treturn tenant.organizationId;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tconst state = engineCore.getState();\n\t\tif (Is.stringValue(state.nodeOrganizationId)) {\n\t\t\treturn state.nodeOrganizationId;\n\t\t}\n\t}\n\n\tthrow new GeneralError(\"bootstrapDev\", \"organizationNotSet\");\n}\n\n/**\n * Resolve the default tenant id for re-bootstrap when multi-tenancy is enabled.\n * @param engineCore The engine core.\n * @returns The tenant id if one exists in storage.\n * @internal\n */\nasync function resolveDefaultTenant(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>\n): Promise<{ id: string; organizationId: string } | undefined> {\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\treturn undefined;\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tlet cursor: string | undefined;\n\tlet firstTenant: { id: string; organizationId: string } | undefined;\n\n\tdo {\n\t\tconst result = await tenantAdminService.query(\n\t\t\tundefined,\n\t\t\t[\"id\", \"organizationId\", \"label\"],\n\t\t\tcursor\n\t\t);\n\t\tconst nodeTenant = result.tenants.find(tenant => tenant.label === \"Tenant\");\n\t\tif (nodeTenant) {\n\t\t\treturn {\n\t\t\t\tid: nodeTenant.id,\n\t\t\t\torganizationId: nodeTenant.organizationId ?? \"\"\n\t\t\t};\n\t\t}\n\n\t\tif (Is.empty(firstTenant) && Is.arrayValue(result.tenants)) {\n\t\t\tfirstTenant = {\n\t\t\t\tid: result.tenants[0].id,\n\t\t\t\torganizationId: result.tenants[0].organizationId ?? \"\"\n\t\t\t};\n\t\t}\n\n\t\tcursor = result.cursor;\n\t} while (Is.stringValue(cursor));\n\n\tif (!Is.empty(firstTenant)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-dev.labels.tenantFallback\"),\n\t\t\tfirstTenant.id\n\t\t);\n\t}\n\n\treturn firstTenant;\n}\n\n/**\n * Resolve the admin user by email for idempotent re-bootstrap.\n * @param engineCore The engine core.\n * @param email The email address of the admin user to look up.\n * @returns The admin user if one exists in storage.\n * @internal\n */\nasync function resolveDefaultAdminUser(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\temail: string\n): Promise<{ email: string; userIdentity: string; organizationIdentity: string } | undefined> {\n\tconst defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"authenticationAdminComponent\"\n\t);\n\tconst authenticationAdminComponent = ComponentFactory.get<IAuthenticationAdminComponent>(\n\t\tdefaultAuthenticationAdminComponentType\n\t);\n\n\ttry {\n\t\treturn await authenticationAdminComponent.get(email);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Resolve a tenant by its specific ID for idempotent re-bootstrap.\n * @param engineCore The engine core.\n * @param tenantId The tenant ID to look up.\n * @returns The tenant if found, otherwise undefined.\n * @internal\n */\nasync function resolveTenantById(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\ttenantId: string\n): Promise<{ id: string; organizationId: string } | undefined> {\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\treturn undefined;\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\ttry {\n\t\tconst found = await tenantAdminService.get(tenantId);\n\t\treturn {\n\t\t\tid: found.id,\n\t\t\torganizationId: found.organizationId ?? \"\"\n\t\t};\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
package/dist/es/commands/help.js
CHANGED
|
@@ -66,7 +66,7 @@ function displayCommandHelp(commandDefinition) {
|
|
|
66
66
|
if (Is.stringValue(param.extendedType)) {
|
|
67
67
|
typeParts.push(param.extendedType);
|
|
68
68
|
}
|
|
69
|
-
if (Is.
|
|
69
|
+
if (!Is.empty(param.defaultValue)) {
|
|
70
70
|
typeParts.push(`${defaultLabel}: '${param.defaultValue}'`);
|
|
71
71
|
}
|
|
72
72
|
if (param.required) {
|