@twin.org/node-core 0.0.3-next.3 → 0.0.3-next.31
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/README.md +3 -1
- package/dist/es/builders/engineEnvBuilder.js +194 -123
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +63 -24
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/cli.js +247 -0
- package/dist/es/cli.js.map +1 -0
- package/dist/es/commands/bootstrapLegacy.js +186 -0
- package/dist/es/commands/bootstrapLegacy.js.map +1 -0
- package/dist/es/commands/help.js +85 -0
- package/dist/es/commands/help.js.map +1 -0
- package/dist/es/commands/identityCreate.js +316 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityImports.js +82 -0
- package/dist/es/commands/identityImports.js.map +1 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodCreate.js +228 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js +126 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
- package/dist/es/commands/nodeSetIdentity.js +64 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -0
- package/dist/es/commands/nodeSetTenant.js +68 -0
- package/dist/es/commands/nodeSetTenant.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +139 -0
- package/dist/es/commands/tenantCreate.js.map +1 -0
- package/dist/es/commands/tenantImport.js +97 -0
- package/dist/es/commands/tenantImport.js.map +1 -0
- package/dist/es/commands/tenantUpdate.js +94 -0
- package/dist/es/commands/tenantUpdate.js.map +1 -0
- package/dist/es/commands/userCreate.js +212 -0
- package/dist/es/commands/userCreate.js.map +1 -0
- package/dist/es/commands/userUpdate.js +132 -0
- package/dist/es/commands/userUpdate.js.map +1 -0
- package/dist/es/commands/vaultKeyCreate.js +191 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -0
- package/dist/es/commands/vaultKeyImport.js +104 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -0
- package/dist/es/defaults.js +17 -1
- package/dist/es/defaults.js.map +1 -1
- package/dist/es/index.js +7 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ICliArgs.js +4 -0
- package/dist/es/models/ICliArgs.js.map +1 -0
- package/dist/es/models/ICliCommand.js +2 -0
- package/dist/es/models/ICliCommand.js.map +1 -0
- package/dist/es/models/ICliCommandDefinition.js +2 -0
- package/dist/es/models/ICliCommandDefinition.js.map +1 -0
- package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
- package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeEngineState.js.map +1 -1
- package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeOptions.js.map +1 -1
- package/dist/es/models/cliCommandParamType.js +4 -0
- package/dist/es/models/cliCommandParamType.js.map +1 -0
- package/dist/es/node.js +84 -39
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +139 -0
- package/dist/es/start.js.map +1 -0
- package/dist/es/utils.js +12 -22
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +1 -1
- package/dist/types/builders/engineServerEnvBuilder.d.ts +4 -2
- package/dist/types/cli.d.ts +56 -0
- package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
- package/dist/types/commands/help.d.ts +23 -0
- package/dist/types/commands/identityCreate.d.ts +39 -0
- package/dist/types/commands/identityImports.d.ts +24 -0
- package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
- package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
- package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
- package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
- package/dist/types/commands/nodeSetTenant.d.ts +22 -0
- package/dist/types/commands/tenantCreate.d.ts +38 -0
- package/dist/types/commands/tenantImport.d.ts +26 -0
- package/dist/types/commands/tenantUpdate.d.ts +26 -0
- package/dist/types/commands/userCreate.d.ts +49 -0
- package/dist/types/commands/userUpdate.d.ts +38 -0
- package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
- package/dist/types/commands/vaultKeyImport.d.ts +28 -0
- package/dist/types/defaults.d.ts +9 -1
- package/dist/types/index.d.ts +7 -3
- package/dist/types/models/ICliArgs.d.ts +20 -0
- package/dist/types/models/ICliCommand.d.ts +17 -0
- package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
- package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +72 -56
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
- package/dist/types/models/INodeEngineState.d.ts +0 -8
- package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
- package/dist/types/models/INodeOptions.d.ts +6 -2
- package/dist/types/models/cliCommandParamType.d.ts +4 -0
- package/dist/types/node.d.ts +5 -4
- package/dist/types/{server.d.ts → start.d.ts} +4 -2
- package/dist/types/utils.d.ts +6 -8
- package/docs/changelog.md +206 -1
- package/docs/examples.md +99 -1
- package/docs/reference/functions/buildConfiguration.md +1 -1
- package/docs/reference/functions/buildEngineServerConfiguration.md +1 -1
- package/docs/reference/functions/constructCliCommand.md +27 -0
- package/docs/reference/functions/executeCommand.md +29 -0
- package/docs/reference/functions/getEnvDefaults.md +19 -0
- package/docs/reference/functions/getScriptDirectory.md +19 -0
- package/docs/reference/functions/parseCommandLineArgs.md +19 -0
- package/docs/reference/functions/processEnvOptions.md +27 -0
- package/docs/reference/functions/registerCommands.md +9 -0
- package/docs/reference/functions/resolvePackageEntryPoint.md +2 -2
- package/docs/reference/functions/run.md +8 -2
- package/docs/reference/functions/start.md +9 -3
- package/docs/reference/functions/substituteEnvOptions.md +25 -0
- package/docs/reference/index.md +14 -12
- package/docs/reference/interfaces/ICacheMetadata.md +3 -3
- package/docs/reference/interfaces/ICliArgs.md +35 -0
- package/docs/reference/interfaces/ICliCommand.md +23 -0
- package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
- package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +349 -313
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +434 -370
- package/docs/reference/interfaces/IModuleProtocol.md +3 -3
- package/docs/reference/interfaces/INodeEngineState.md +4 -20
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +448 -464
- package/docs/reference/interfaces/INodeOptions.md +44 -36
- package/docs/reference/interfaces/IProtocolHandlerResult.md +2 -2
- package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +1 -1
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +1 -1
- package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +1 -1
- package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +1 -1
- package/docs/reference/variables/ModuleProtocol.md +5 -5
- package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
- package/locales/en.json +589 -30
- package/package.json +6 -4
- package/dist/es/bootstrap.js +0 -360
- package/dist/es/bootstrap.js.map +0 -1
- package/dist/es/identity.js +0 -169
- package/dist/es/identity.js.map +0 -1
- package/dist/es/models/nodeFeatures.js +0 -21
- package/dist/es/models/nodeFeatures.js.map +0 -1
- package/dist/es/server.js +0 -81
- package/dist/es/server.js.map +0 -1
- package/dist/types/bootstrap.d.ts +0 -68
- package/dist/types/identity.d.ts +0 -14
- package/dist/types/models/nodeFeatures.d.ts +0 -21
- package/docs/detailed-guide.md +0 -129
- package/docs/reference/functions/bootstrap.md +0 -29
- package/docs/reference/functions/bootstrapAuth.md +0 -35
- package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
- package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
- package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
- package/docs/reference/functions/bootstrapNodeId.md +0 -35
- package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
- package/docs/reference/functions/bootstrapTenantId.md +0 -35
- package/docs/reference/functions/getFeatures.md +0 -19
- package/docs/reference/type-aliases/NodeFeatures.md +0 -5
- package/docs/reference/variables/NodeFeatures.md +0 -25
- package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
|
@@ -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,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACN,gCAAgC,EAChC,2BAA2B,EAE3B,wBAAwB,EAExB,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,mBAAmB,EACnB,8BAA8B,EAC9B,iCAAiC,EACjC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CACnD,OAA0C,EAC1C,sBAAsE,EACtE,gBAAmC,EACnC,UAAuB,EACvB,eAAwB,EACxB,WAAoB;IAEpB,MAAM,gBAAgB,GAAsB;QAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI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 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 } from \"@twin.org/core\";\nimport type { IEngineCoreConfig } from \"@twin.org/engine-models\";\nimport { addDefaultRestPaths, addDefaultSocketPaths } from \"@twin.org/engine-server\";\nimport {\n\tAuthenticationAdminComponentType,\n\tAuthenticationComponentType,\n\ttype IEngineServerConfig,\n\tInformationComponentType,\n\ttype MimeTypeProcessorType,\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType\n} from \"@twin.org/engine-server-types\";\nimport type { HttpMethod } from \"@twin.org/web\";\nimport {\n\tAUTH_SIGNING_KEY_ID,\n\tCONTEXT_ID_HANDLER_FEATURE_DID,\n\tCONTEXT_ID_HANDLER_FEATURE_TENANT\n} from \"../defaults.js\";\nimport type { IEngineServerEnvironmentVariables } from \"../models/IEngineServerEnvironmentVariables.js\";\nimport { NodeFeatures } from \"../models/nodeFeatures.js\";\nimport { getFeatures } from \"../utils.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: IEngineServerEnvironmentVariables,\n\tavailableContextIdKeys: { key: string; componentFeatures: 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: Is.stringValue(envVars.httpMethods)\n\t\t\t? (envVars.httpMethods.split(\",\") as HttpMethod[])\n\t\t\t: undefined,\n\t\tallowedHeaders: Is.stringValue(envVars.httpAllowedHeaders)\n\t\t\t? envVars.httpAllowedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\texposedHeaders: Is.stringValue(envVars.httpExposedHeaders)\n\t\t\t? envVars.httpExposedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\tcorsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(\",\") : undefined\n\t};\n\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(\"x-api-key\")) {\n\t\t\twebServerOptions.allowedHeaders.push(\"x-api-key\");\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 = envVars.mimeTypeProcessors.split(\",\");\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\tconst features = getFeatures(envVars);\n\tconst hasNodeId = features.includes(NodeFeatures.NodeId);\n\n\tif (hasNodeId) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Node,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (tenantEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Tenant,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tenant\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Tenant\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 = Is.stringValue(envVars.routeLoggingObfuscateProperties)\n\t\t\t? envVars.routeLoggingObfuscateProperties.split(\",\")\n\t\t\t: undefined;\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\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.SocketRoute,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\n\tconst authAdminProcessorType = envVars.authAdminProcessorType;\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\tconst authProcessorType = envVars.authProcessorType;\n\tif (authProcessorType === AuthenticationComponentType.EntityStorage) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.User,\n\t\t\tcomponentFeatures: [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 ?? AUTH_SIGNING_KEY_ID\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 ?? AUTH_SIGNING_KEY_ID\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 ?? AUTH_SIGNING_KEY_ID\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (Coerce.boolean(envVars.vcAuthenticationEnabled) ?? false) {\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.AuthVerifiableCredential\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.AuthVerifiableCredential\n\t\t});\n\t}\n\n\taddDefaultRestPaths(serverConfig);\n\taddDefaultSocketPaths(serverConfig);\n\n\treturn serverConfig;\n}\n"]}
|
|
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,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,2BAA2B,EAC3B,+BAA+B,EAC/B,oBAAoB,EAEpB,wBAAwB,EAExB,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,8BAA8B,EAAE,iCAAiC,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,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAEhD,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","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, GeneralError, Is, StringHelper, Url } 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\tHostingComponentType,\n\ttype IEngineServerConfig,\n\tInformationComponentType,\n\ttype MimeTypeProcessorType,\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType\n} from \"@twin.org/engine-server-types\";\nimport type { HttpMethod } from \"@twin.org/web\";\nimport { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from \"../defaults.js\";\nimport type { IEngineServerEnvironmentVariables } from \"../models/IEngineServerEnvironmentVariables.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: IEngineServerEnvironmentVariables & { [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: Is.stringValue(envVars.httpMethods)\n\t\t\t? (envVars.httpMethods.split(\",\") as HttpMethod[])\n\t\t\t: undefined,\n\t\tallowedHeaders: Is.stringValue(envVars.httpAllowedHeaders)\n\t\t\t? envVars.httpAllowedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\texposedHeaders: Is.stringValue(envVars.httpExposedHeaders)\n\t\t\t? envVars.httpExposedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\tcorsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(\",\") : undefined\n\t};\n\n\tconst localOrigin = `http://${webServerOptions.host ?? \"localhost\"}:${webServerOptions.port ?? 3000}`;\n\n\tlet publicOrigin;\n\tif (Is.stringValue(envVars.publicOrigin)) {\n\t\tconst publicUrl = Url.tryParseExact(envVars.publicOrigin);\n\t\tif (!Is.empty(publicUrl)) {\n\t\t\tconst urlParts = publicUrl.parts();\n\t\t\tpublicOrigin = `${urlParts.schema}://${urlParts.host}${Is.integer(urlParts.port) ? `:${urlParts.port}` : \"\"}`;\n\t\t} else {\n\t\t\tthrow new GeneralError(\"node\", \"invalidPublicOrigin\", { publicOrigin: envVars.publicOrigin });\n\t\t}\n\t}\n\n\tconst nodeIdentityEnabled = Coerce.boolean(envVars.nodeIdentityEnabled) ?? true;\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(\"x-api-key\")) {\n\t\t\twebServerOptions.allowedHeaders.push(\"x-api-key\");\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\thostingComponent: [\n\t\t\t\t{\n\t\t\t\t\ttype: HostingComponentType.Service,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tlocalOrigin,\n\t\t\t\t\t\t\tpublicOrigin\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 = envVars.mimeTypeProcessors.split(\",\");\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\tif (nodeIdentityEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Node,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (tenantEnabled) {\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});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Tenant\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 = Is.stringValue(envVars.routeLoggingObfuscateProperties)\n\t\t\t? envVars.routeLoggingObfuscateProperties.split(\",\")\n\t\t\t: undefined;\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\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.SocketRoute,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\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.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\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}\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\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"]}
|
package/dist/es/cli.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { ContextIdStore } from "@twin.org/context";
|
|
5
|
+
import { Coerce, GeneralError, I18n, Is, StringHelper } from "@twin.org/core";
|
|
6
|
+
import * as dotenv from "dotenv";
|
|
7
|
+
import { getCommandDefinitionBootstrapLegacy } from "./commands/bootstrapLegacy.js";
|
|
8
|
+
import { getCommandDefinitionHelp } from "./commands/help.js";
|
|
9
|
+
import { getCommandDefinitionIdentityCreate } from "./commands/identityCreate.js";
|
|
10
|
+
import { getCommandDefinitionIdentityImport } from "./commands/identityImports.js";
|
|
11
|
+
import { getCommandDefinitionIdentityVerifiableCredentialCreate } from "./commands/identityVerifiableCredentialCreate.js";
|
|
12
|
+
import { getCommandDefinitionIdentityVerificationMethodCreate } from "./commands/identityVerificationMethodCreate.js";
|
|
13
|
+
import { getCommandDefinitionIdentityVerificationMethodImport } from "./commands/identityVerificationMethodImport.js";
|
|
14
|
+
import { getCommandDefinitionNodeSetIdentity } from "./commands/nodeSetIdentity.js";
|
|
15
|
+
import { getCommandDefinitionNodeSetTenant } from "./commands/nodeSetTenant.js";
|
|
16
|
+
import { getCommandDefinitionTenantCreate } from "./commands/tenantCreate.js";
|
|
17
|
+
import { getCommandDefinitionTenantImport } from "./commands/tenantImport.js";
|
|
18
|
+
import { getCommandDefinitionTenantUpdate } from "./commands/tenantUpdate.js";
|
|
19
|
+
import { getCommandDefinitionUserCreate } from "./commands/userCreate.js";
|
|
20
|
+
import { getCommandDefinitionUserUpdate } from "./commands/userUpdate.js";
|
|
21
|
+
import { getCommandDefinitionVaultKeyCreate } from "./commands/vaultKeyCreate.js";
|
|
22
|
+
import { getCommandDefinitionVaultKeyImport } from "./commands/vaultKeyImport.js";
|
|
23
|
+
const commandDefinitions = {};
|
|
24
|
+
/**
|
|
25
|
+
* Parse command line arguments.
|
|
26
|
+
* @param args The command line arguments.
|
|
27
|
+
* @returns The parsed command line arguments.
|
|
28
|
+
*/
|
|
29
|
+
export function parseCommandLineArgs(args) {
|
|
30
|
+
let nodePath;
|
|
31
|
+
let scriptPath;
|
|
32
|
+
let options;
|
|
33
|
+
if (Is.arrayValue(args)) {
|
|
34
|
+
if (args.length > 0) {
|
|
35
|
+
nodePath = args[0];
|
|
36
|
+
}
|
|
37
|
+
if (args.length > 1) {
|
|
38
|
+
scriptPath = args[1];
|
|
39
|
+
}
|
|
40
|
+
if (args.length > 2) {
|
|
41
|
+
options = [];
|
|
42
|
+
for (let i = 2; i < args.length; i++) {
|
|
43
|
+
const arg = args[i];
|
|
44
|
+
const equalIndex = arg.indexOf("=");
|
|
45
|
+
if (equalIndex > 0) {
|
|
46
|
+
const key = arg.slice(0, equalIndex).trim();
|
|
47
|
+
const value = arg.slice(equalIndex + 1).trim();
|
|
48
|
+
if (key.startsWith("--")) {
|
|
49
|
+
options.push({ key: key.slice(2), value });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
options.push({ key: arg, value: "" });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
nodePath,
|
|
60
|
+
scriptPath,
|
|
61
|
+
options
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Construct the CLI command from the parsed arguments.
|
|
66
|
+
* @param processEnv The environment variables from the process.
|
|
67
|
+
* @param cliArgs The parsed CLI arguments.
|
|
68
|
+
* @returns The constructed CLI command.
|
|
69
|
+
* @throws GeneralError if the command is missing.
|
|
70
|
+
*/
|
|
71
|
+
export function constructCliCommand(processEnv, cliArgs) {
|
|
72
|
+
if (Is.arrayValue(cliArgs.options)) {
|
|
73
|
+
const command = cliArgs.options[0];
|
|
74
|
+
// If the first option is --help, we can display help for all commands
|
|
75
|
+
if (command.key === "--help") {
|
|
76
|
+
return {
|
|
77
|
+
definition: commandDefinitions.help,
|
|
78
|
+
params: {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// In cases where no command but env-prefix is provided, we just return
|
|
82
|
+
if (command.key === "env-prefix") {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (!commandDefinitions[command.key]) {
|
|
86
|
+
throw new GeneralError("node", "cliCommandMissing", { command: command.key });
|
|
87
|
+
}
|
|
88
|
+
// We have a valid command, check for --help for that command
|
|
89
|
+
const hasHelp = cliArgs.options.find(option => option.key === "--help");
|
|
90
|
+
if (hasHelp) {
|
|
91
|
+
return {
|
|
92
|
+
definition: commandDefinitions.help,
|
|
93
|
+
params: {
|
|
94
|
+
command: command.key
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
processEnvOptions(processEnv, cliArgs.options);
|
|
99
|
+
const cliParams = {};
|
|
100
|
+
const allParamKeys = cliArgs.options
|
|
101
|
+
.map(option => option.key)
|
|
102
|
+
.filter(key => key !== command.key);
|
|
103
|
+
for (const commandDefParam of commandDefinitions[command.key].params) {
|
|
104
|
+
const foundParamIndex = cliArgs.options?.findIndex(option => option.key === commandDefParam.key) ?? -1;
|
|
105
|
+
const foundParam = foundParamIndex >= 0 ? cliArgs.options?.[foundParamIndex] : undefined;
|
|
106
|
+
let paramValue;
|
|
107
|
+
if (commandDefParam.type === "number") {
|
|
108
|
+
paramValue = Coerce.number(foundParam?.value ?? commandDefParam.defaultValue);
|
|
109
|
+
}
|
|
110
|
+
else if (commandDefParam.type === "boolean") {
|
|
111
|
+
paramValue = Coerce.boolean(foundParam?.value ?? commandDefParam.defaultValue);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
paramValue = Coerce.string(foundParam?.value ?? commandDefParam.defaultValue);
|
|
115
|
+
}
|
|
116
|
+
const required = commandDefParam.required ?? true;
|
|
117
|
+
if (Is.empty(paramValue) && required) {
|
|
118
|
+
throw new GeneralError("node", "cliCommandParamMissing", {
|
|
119
|
+
command: command.key,
|
|
120
|
+
param: commandDefParam.key
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (!Is.empty(paramValue)) {
|
|
124
|
+
cliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;
|
|
125
|
+
}
|
|
126
|
+
if (foundParamIndex >= 0) {
|
|
127
|
+
allParamKeys.splice(allParamKeys.indexOf(commandDefParam.key), 1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (allParamKeys.length > 0) {
|
|
131
|
+
throw new GeneralError("node", "cliCommandParamExtra", {
|
|
132
|
+
command: command.key,
|
|
133
|
+
params: allParamKeys.join(", ")
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (commandDefinitions[command.key].params.find(param => param.key === "output-env-prefix")) {
|
|
137
|
+
cliParams.outputEnvPrefix = (Coerce.string(cliParams.outputEnvPrefix) ?? "").toUpperCase();
|
|
138
|
+
cliParams.outputEnvPrefix =
|
|
139
|
+
cliParams.outputEnvPrefix.length > 0 && !cliParams.outputEnvPrefix.endsWith("_")
|
|
140
|
+
? `${cliParams.outputEnvPrefix}_`
|
|
141
|
+
: cliParams.outputEnvPrefix;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
definition: commandDefinitions[command.key],
|
|
145
|
+
params: cliParams
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Execute the CLI command.
|
|
151
|
+
* @param engineCore The engine core.
|
|
152
|
+
* @param envVars The environment variables for the node.
|
|
153
|
+
* @param cliCommand The CLI command to execute.
|
|
154
|
+
*/
|
|
155
|
+
export async function executeCommand(engineCore, envVars, cliCommand) {
|
|
156
|
+
const requiresEngineStarted = cliCommand.definition.requiresEngineStarted ?? true;
|
|
157
|
+
try {
|
|
158
|
+
if (requiresEngineStarted) {
|
|
159
|
+
await engineCore.start(true);
|
|
160
|
+
}
|
|
161
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.command"), cliCommand.definition.command);
|
|
162
|
+
for (const paramKey in cliCommand.params) {
|
|
163
|
+
CLIDisplay.value(paramKey, Coerce.string(cliCommand.params[paramKey]), 1);
|
|
164
|
+
}
|
|
165
|
+
CLIDisplay.break();
|
|
166
|
+
await ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {
|
|
167
|
+
await cliCommand.definition.action(engineCore, envVars, cliCommand.params);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
CLIDisplay.spinnerStop();
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
if (requiresEngineStarted) {
|
|
176
|
+
CLIDisplay.break();
|
|
177
|
+
await engineCore.stop();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load the env files and process the options.
|
|
183
|
+
* @param processEnv The environment variables from the process.
|
|
184
|
+
* @param options The options.
|
|
185
|
+
* @returns The processed parameters.
|
|
186
|
+
* @throws GeneralError if an env file has errors.
|
|
187
|
+
*/
|
|
188
|
+
export function processEnvOptions(processEnv, options) {
|
|
189
|
+
const inputEnv = options.find(option => option.key === "load-env")?.value;
|
|
190
|
+
if (Is.stringValue(inputEnv)) {
|
|
191
|
+
const envFiles = inputEnv.split(",").map(f => f.trim());
|
|
192
|
+
for (const envFile of envFiles) {
|
|
193
|
+
const output = dotenv.config({
|
|
194
|
+
path: envFile,
|
|
195
|
+
quiet: true
|
|
196
|
+
});
|
|
197
|
+
if (output.error) {
|
|
198
|
+
throw output.error;
|
|
199
|
+
}
|
|
200
|
+
if (Is.objectValue(output.parsed)) {
|
|
201
|
+
for (const key in output.parsed) {
|
|
202
|
+
processEnv[key] = output.parsed[key];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return substituteEnvOptions(processEnv, options);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Process options and replace any env variables with their values.
|
|
211
|
+
* @param processEnv The environment variables from the process.
|
|
212
|
+
* @param options The options.
|
|
213
|
+
* @throws GeneralError if an env variable is missing.
|
|
214
|
+
*/
|
|
215
|
+
export function substituteEnvOptions(processEnv, options) {
|
|
216
|
+
for (const option of options) {
|
|
217
|
+
if (option.value.startsWith("!")) {
|
|
218
|
+
const envVar = processEnv[option.value.slice(1)];
|
|
219
|
+
if (!Is.stringValue(envVar)) {
|
|
220
|
+
throw new GeneralError("node", "cliEnvVarMissing", { envVar: option.value.slice(1) });
|
|
221
|
+
}
|
|
222
|
+
option.value = envVar;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Register available CLI commands.
|
|
228
|
+
*/
|
|
229
|
+
export function registerCommands() {
|
|
230
|
+
getCommandDefinitionHelp(commandDefinitions);
|
|
231
|
+
getCommandDefinitionBootstrapLegacy(commandDefinitions);
|
|
232
|
+
getCommandDefinitionIdentityCreate(commandDefinitions);
|
|
233
|
+
getCommandDefinitionIdentityImport(commandDefinitions);
|
|
234
|
+
getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);
|
|
235
|
+
getCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);
|
|
236
|
+
getCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);
|
|
237
|
+
getCommandDefinitionNodeSetIdentity(commandDefinitions);
|
|
238
|
+
getCommandDefinitionNodeSetTenant(commandDefinitions);
|
|
239
|
+
getCommandDefinitionTenantCreate(commandDefinitions);
|
|
240
|
+
getCommandDefinitionTenantImport(commandDefinitions);
|
|
241
|
+
getCommandDefinitionTenantUpdate(commandDefinitions);
|
|
242
|
+
getCommandDefinitionUserCreate(commandDefinitions);
|
|
243
|
+
getCommandDefinitionUserUpdate(commandDefinitions);
|
|
244
|
+
getCommandDefinitionVaultKeyCreate(commandDefinitions);
|
|
245
|
+
getCommandDefinitionVaultKeyImport(commandDefinitions);
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9E,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,mCAAmC,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,sDAAsD,EAAE,MAAM,kDAAkD,CAAC;AAC1H,OAAO,EAAE,oDAAoD,EAAE,MAAM,gDAAgD,CAAC;AACtH,OAAO,EAAE,oDAAoD,EAAE,MAAM,gDAAgD,CAAC;AACtH,OAAO,EAAE,mCAAmC,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,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":["// 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 { getCommandDefinitionBootstrapLegacy } from \"./commands/bootstrapLegacy.js\";\nimport { getCommandDefinitionHelp } from \"./commands/help.js\";\nimport { getCommandDefinitionIdentityCreate } from \"./commands/identityCreate.js\";\nimport { getCommandDefinitionIdentityImport } from \"./commands/identityImports.js\";\nimport { getCommandDefinitionIdentityVerifiableCredentialCreate } from \"./commands/identityVerifiableCredentialCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodCreate } from \"./commands/identityVerificationMethodCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodImport } from \"./commands/identityVerificationMethodImport.js\";\nimport { getCommandDefinitionNodeSetIdentity } from \"./commands/nodeSetIdentity.js\";\nimport { getCommandDefinitionNodeSetTenant } from \"./commands/nodeSetTenant.js\";\nimport { getCommandDefinitionTenantCreate } from \"./commands/tenantCreate.js\";\nimport { getCommandDefinitionTenantImport } from \"./commands/tenantImport.js\";\nimport { getCommandDefinitionTenantUpdate } from \"./commands/tenantUpdate.js\";\nimport { getCommandDefinitionUserCreate } from \"./commands/userCreate.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 { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.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\tif (!commandDefinitions[command.key]) {\n\t\t\tthrow new GeneralError(\"node\", \"cliCommandMissing\", { command: command.key });\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: command.key\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[command.key].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\tallParamKeys.splice(allParamKeys.indexOf(commandDefParam.key), 1);\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[command.key].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[command.key],\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: INodeEnvironmentVariables,\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 processed parameters.\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 = inputEnv.split(\",\").map(f => f.trim());\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 available CLI commands.\n */\nexport function registerCommands(): void {\n\tgetCommandDefinitionHelp(commandDefinitions);\n\tgetCommandDefinitionBootstrapLegacy(commandDefinitions);\n\tgetCommandDefinitionIdentityCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityImport(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);\n\tgetCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);\n\tgetCommandDefinitionNodeSetIdentity(commandDefinitions);\n\tgetCommandDefinitionNodeSetTenant(commandDefinitions);\n\tgetCommandDefinitionTenantCreate(commandDefinitions);\n\tgetCommandDefinitionTenantImport(commandDefinitions);\n\tgetCommandDefinitionTenantUpdate(commandDefinitions);\n\tgetCommandDefinitionUserCreate(commandDefinitions);\n\tgetCommandDefinitionUserUpdate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyCreate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyImport(commandDefinitions);\n}\n"]}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
5
|
+
import { Coerce, Converter, GeneralError, I18n, Is } from "@twin.org/core";
|
|
6
|
+
import { identityCreate } from "./identityCreate.js";
|
|
7
|
+
import { identityVerificationMethodCreate } from "./identityVerificationMethodCreate.js";
|
|
8
|
+
import { nodeSetIdentity } from "./nodeSetIdentity.js";
|
|
9
|
+
import { nodeSetTenant } from "./nodeSetTenant.js";
|
|
10
|
+
import { tenantCreate } from "./tenantCreate.js";
|
|
11
|
+
import { userCreate } from "./userCreate.js";
|
|
12
|
+
import { vaultKeyCreate } from "./vaultKeyCreate.js";
|
|
13
|
+
import { vaultKeyImport } from "./vaultKeyImport.js";
|
|
14
|
+
const COMMAND_NAME = "bootstrap-legacy";
|
|
15
|
+
/**
|
|
16
|
+
* Get the command definition parameters.
|
|
17
|
+
* @param commandDefinitions The registered command definitions.
|
|
18
|
+
*/
|
|
19
|
+
export function getCommandDefinitionBootstrapLegacy(commandDefinitions) {
|
|
20
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
21
|
+
command: COMMAND_NAME,
|
|
22
|
+
description: I18n.formatMessage("node.cli.commands.bootstrap-legacy.description"),
|
|
23
|
+
example: I18n.formatMessage("node.cli.commands.bootstrap-legacy.example"),
|
|
24
|
+
requiresNodeIdentity: false,
|
|
25
|
+
requiresTenantId: false,
|
|
26
|
+
params: [
|
|
27
|
+
{
|
|
28
|
+
key: "env-prefix",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: I18n.formatMessage("node.cli.commands.bootstrap-legacy.params.env-prefix.description"),
|
|
31
|
+
required: false
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: "load-env",
|
|
35
|
+
type: "string",
|
|
36
|
+
description: I18n.formatMessage("node.cli.commands.bootstrap-legacy.params.load-env.description"),
|
|
37
|
+
required: false
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
action: async (engineCore, envVars, params) => bootstrapLegacy(engineCore, envVars, params)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Command for legacy bootstrap.
|
|
45
|
+
* @param engineCore The engine core.
|
|
46
|
+
* @param envVars The environment variables for the node.
|
|
47
|
+
* @param params The parameters for the command.
|
|
48
|
+
*/
|
|
49
|
+
export async function bootstrapLegacy(engineCore, envVars, params) {
|
|
50
|
+
const features = (envVars.features ?? "")
|
|
51
|
+
.split(",")
|
|
52
|
+
.map(f => f.trim())
|
|
53
|
+
.filter(f => f.length > 0);
|
|
54
|
+
const state = engineCore.getState();
|
|
55
|
+
const requireWallet = features.includes("node-wallet");
|
|
56
|
+
let tenantId = state.nodeTenantId;
|
|
57
|
+
let nodeId = state.nodeId;
|
|
58
|
+
if (features.length === 0) {
|
|
59
|
+
throw new GeneralError("bootstrapLegacy", "noFeaturesEnabled");
|
|
60
|
+
}
|
|
61
|
+
if (features.includes("node-identity") && Is.empty(nodeId)) {
|
|
62
|
+
CLIDisplay.break();
|
|
63
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeIdentityCreate"));
|
|
64
|
+
const nodeIdentity = await identityCreate(engineCore, envVars, {
|
|
65
|
+
identity: envVars.nodeIdentity,
|
|
66
|
+
mnemonic: envVars.nodeMnemonic,
|
|
67
|
+
fundWallet: requireWallet
|
|
68
|
+
});
|
|
69
|
+
nodeId = nodeIdentity.did;
|
|
70
|
+
CLIDisplay.break();
|
|
71
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeAuthKeyCreate"));
|
|
72
|
+
await vaultKeyCreate(engineCore, envVars, {
|
|
73
|
+
identity: nodeIdentity.did,
|
|
74
|
+
keyType: "Ed25519",
|
|
75
|
+
keyId: envVars.authSigningKeyId,
|
|
76
|
+
overwriteMode: "skip"
|
|
77
|
+
});
|
|
78
|
+
if (Coerce.boolean(envVars.trustEnabled) ?? false) {
|
|
79
|
+
CLIDisplay.break();
|
|
80
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.trustVerificationMethodCreate"));
|
|
81
|
+
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
82
|
+
identity: nodeIdentity.did,
|
|
83
|
+
verificationMethodType: "assertionMethod",
|
|
84
|
+
verificationMethodId: envVars.trustVerificationMethodId,
|
|
85
|
+
overwriteMode: "skip"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if ((Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) &&
|
|
89
|
+
Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {
|
|
90
|
+
CLIDisplay.break();
|
|
91
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.synchronisedStorageKeyAdd"));
|
|
92
|
+
await vaultKeyImport(engineCore, envVars, {
|
|
93
|
+
identity: nodeIdentity.did,
|
|
94
|
+
keyType: "ChaCha20Poly1305",
|
|
95
|
+
keyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,
|
|
96
|
+
privateKeyHex: Converter.bytesToHex(Converter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey))
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
CLIDisplay.break();
|
|
100
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeIdentitySet"));
|
|
101
|
+
await nodeSetIdentity(engineCore, envVars, {
|
|
102
|
+
identity: nodeId
|
|
103
|
+
});
|
|
104
|
+
const tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
|
|
105
|
+
if (tenantEnabled && Is.empty(tenantId)) {
|
|
106
|
+
await ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {
|
|
107
|
+
CLIDisplay.break();
|
|
108
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeTenantCreate"));
|
|
109
|
+
const tenantDetails = await tenantCreate(engineCore, envVars, {
|
|
110
|
+
tenantId: envVars.tenantId,
|
|
111
|
+
apiKey: envVars.tenantApiKey,
|
|
112
|
+
label: "Node"
|
|
113
|
+
});
|
|
114
|
+
CLIDisplay.break();
|
|
115
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeTenantSet"));
|
|
116
|
+
await nodeSetTenant(engineCore, envVars, {
|
|
117
|
+
tenantId: tenantDetails.tenantId
|
|
118
|
+
});
|
|
119
|
+
tenantId = tenantDetails.tenantId;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (features.includes("node-admin-user")) {
|
|
124
|
+
await ContextIdStore.run({ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenantId }, async () => {
|
|
125
|
+
CLIDisplay.break();
|
|
126
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.organisationCreate"));
|
|
127
|
+
const organisation = await identityCreate(engineCore, envVars, {
|
|
128
|
+
identity: envVars.organizationIdentity,
|
|
129
|
+
mnemonic: envVars.organizationMnemonic,
|
|
130
|
+
fundWallet: requireWallet
|
|
131
|
+
});
|
|
132
|
+
if (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {
|
|
133
|
+
CLIDisplay.break();
|
|
134
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.blobStorageKeyCreate"));
|
|
135
|
+
await vaultKeyCreate(engineCore, envVars, {
|
|
136
|
+
identity: organisation.did,
|
|
137
|
+
keyType: "ChaCha20Poly1305",
|
|
138
|
+
keyId: envVars.blobStorageEncryptionKeyId,
|
|
139
|
+
overwriteMode: "skip"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
const defaultAttestationConnectorType = engineCore.getRegisteredInstanceTypeOptional("attestationConnector");
|
|
143
|
+
if (!Is.empty(defaultAttestationConnectorType)) {
|
|
144
|
+
CLIDisplay.break();
|
|
145
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.attestationMethodCreate"));
|
|
146
|
+
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
147
|
+
identity: organisation.did,
|
|
148
|
+
verificationMethodType: "assertionMethod",
|
|
149
|
+
verificationMethodId: envVars.attestationVerificationMethodId,
|
|
150
|
+
overwriteMode: "skip"
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const defaultImmutableProofComponentType = engineCore.getRegisteredInstanceTypeOptional("immutableProofComponent");
|
|
154
|
+
if (!Is.empty(defaultImmutableProofComponentType)) {
|
|
155
|
+
CLIDisplay.break();
|
|
156
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.immutableProofMethodCreate"));
|
|
157
|
+
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
158
|
+
identity: organisation.did,
|
|
159
|
+
verificationMethodType: "assertionMethod",
|
|
160
|
+
verificationMethodId: envVars.immutableProofVerificationMethodId,
|
|
161
|
+
overwriteMode: "skip"
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
CLIDisplay.break();
|
|
165
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.adminIdentityCreate"));
|
|
166
|
+
const adminUserIdentity = await identityCreate(engineCore, envVars, {
|
|
167
|
+
identity: envVars.adminUserIdentity,
|
|
168
|
+
mnemonic: envVars.adminUserMnemonic,
|
|
169
|
+
controller: organisation.did
|
|
170
|
+
});
|
|
171
|
+
CLIDisplay.break();
|
|
172
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.adminUserCreate"));
|
|
173
|
+
await userCreate(engineCore, envVars, {
|
|
174
|
+
userIdentity: adminUserIdentity.did,
|
|
175
|
+
organizationIdentity: organisation.did,
|
|
176
|
+
email: envVars.adminUserName ?? "admin@node",
|
|
177
|
+
password: envVars.adminUserPassword,
|
|
178
|
+
scope: "tenant-admin",
|
|
179
|
+
givenName: "Node",
|
|
180
|
+
familyName: "Admin",
|
|
181
|
+
overwriteMode: "skip"
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=bootstrapLegacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrapLegacy.js","sourceRoot":"","sources":["../../../src/commands/bootstrapLegacy.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EA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AAU,EAAE,OAAO;gBACnB,aAAa,EAAE,MAAM;aACrB,CAAC,CAAC;QACJ,CAAC,CACD,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, Converter, 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 { nodeSetIdentity } from \"./nodeSetIdentity.js\";\nimport { nodeSetTenant } from \"./nodeSetTenant.js\";\nimport { tenantCreate } from \"./tenantCreate.js\";\nimport { userCreate } from \"./userCreate.js\";\nimport { vaultKeyCreate } from \"./vaultKeyCreate.js\";\nimport { vaultKeyImport } from \"./vaultKeyImport.js\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"bootstrap-legacy\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionBootstrapLegacy(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.bootstrap-legacy.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.bootstrap-legacy.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: 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-legacy.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-legacy.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) => bootstrapLegacy(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for legacy 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 */\nexport async function bootstrapLegacy(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables & {\n\t\t/**\n\t\t * The features that are enabled on the node.\n\t\t * @default []\n\t\t */\n\t\tfeatures?: string;\n\n\t\t/**\n\t\t * The identity of the node which, if empty and node-identity feature is enabled it will be generated.\n\t\t */\n\t\tnodeIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the identity, if empty and node-identity feature is enabled it will be randomly generated.\n\t\t */\n\t\tnodeMnemonic?: string;\n\n\t\t/**\n\t\t * A tenant id to use as a default for the node.\n\t\t */\n\t\ttenantId?: string;\n\n\t\t/**\n\t\t * A tenant api key to use as a default for the node.\n\t\t */\n\t\ttenantApiKey?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the organization of the user, if one is not provided it will be generated\n\t\t */\n\t\torganizationIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the organization, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\torganizationMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the identity of the user, if one is not provided it will be generated\n\t\t */\n\t\tadminUserIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the admin user, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\tadminUserMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the name of the user.\n\t\t * @default admin@node\n\t\t */\n\t\tadminUserName?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the password of the user, if empty it will be randomly generated.\n\t\t */\n\t\tadminUserPassword?: string;\n\t},\n\tparams: {}\n): Promise<void> {\n\tconst features = (envVars.features ?? \"\")\n\t\t.split(\",\")\n\t\t.map(f => f.trim())\n\t\t.filter(f => f.length > 0);\n\n\tconst state = engineCore.getState();\n\tconst requireWallet = features.includes(\"node-wallet\");\n\tlet tenantId = state.nodeTenantId;\n\tlet nodeId = state.nodeId;\n\n\tif (features.length === 0) {\n\t\tthrow new GeneralError(\"bootstrapLegacy\", \"noFeaturesEnabled\");\n\t}\n\n\tif (features.includes(\"node-identity\") && Is.empty(nodeId)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentityCreate\")\n\t\t);\n\n\t\tconst nodeIdentity = await identityCreate(engineCore, envVars, {\n\t\t\tidentity: envVars.nodeIdentity,\n\t\t\tmnemonic: envVars.nodeMnemonic,\n\t\t\tfundWallet: requireWallet\n\t\t});\n\n\t\tnodeId = nodeIdentity.did;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeAuthKeyCreate\")\n\t\t);\n\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\tidentity: nodeIdentity.did,\n\t\t\tkeyType: \"Ed25519\",\n\t\t\tkeyId: envVars.authSigningKeyId,\n\t\t\toverwriteMode: \"skip\"\n\t\t});\n\n\t\tif (Coerce.boolean(envVars.trustEnabled) ?? false) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.trustVerificationMethodCreate\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.trustVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\t(Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) &&\n\t\t\tIs.stringBase64(envVars.synchronisedStorageBlobStorageKey)\n\t\t) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.synchronisedStorageKeyAdd\")\n\t\t\t);\n\t\t\tawait vaultKeyImport(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\tkeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,\n\t\t\t\tprivateKeyHex: Converter.bytesToHex(\n\t\t\t\t\tConverter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey)\n\t\t\t\t)\n\t\t\t});\n\t\t}\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentitySet\")\n\t\t);\n\t\tawait nodeSetIdentity(engineCore, envVars, {\n\t\t\tidentity: nodeId\n\t\t});\n\n\t\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\t\tif (tenantEnabled && Is.empty(tenantId)) {\n\t\t\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.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: \"Node\"\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-legacy.labels.nodeTenantSet\")\n\t\t\t\t);\n\t\t\t\tawait nodeSetTenant(engineCore, envVars, {\n\t\t\t\t\ttenantId: tenantDetails.tenantId\n\t\t\t\t});\n\n\t\t\t\ttenantId = tenantDetails.tenantId;\n\t\t\t});\n\t\t}\n\t}\n\n\tif (features.includes(\"node-admin-user\")) {\n\t\tawait ContextIdStore.run(\n\t\t\t{ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenantId },\n\t\t\tasync () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.organisationCreate\")\n\t\t\t\t);\n\t\t\t\tconst organisation = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.organizationIdentity,\n\t\t\t\t\tmnemonic: envVars.organizationMnemonic,\n\t\t\t\t\tfundWallet: requireWallet\n\t\t\t\t});\n\n\t\t\t\tif (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {\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-legacy.labels.blobStorageKeyCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\t\t\tkeyId: envVars.blobStorageEncryptionKeyId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultAttestationConnectorType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\t\t\tif (!Is.empty(defaultAttestationConnectorType)) {\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-legacy.labels.attestationMethodCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.attestationVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultImmutableProofComponentType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\t\t\tif (!Is.empty(defaultImmutableProofComponentType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.immutableProofMethodCreate\"\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.immutableProofVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\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-legacy.labels.adminIdentityCreate\")\n\t\t\t\t);\n\t\t\t\tconst adminUserIdentity = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.adminUserIdentity,\n\t\t\t\t\tmnemonic: envVars.adminUserMnemonic,\n\t\t\t\t\tcontroller: organisation.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-legacy.labels.adminUserCreate\")\n\t\t\t\t);\n\t\t\t\tawait userCreate(engineCore, envVars, {\n\t\t\t\t\tuserIdentity: adminUserIdentity.did,\n\t\t\t\t\torganizationIdentity: organisation.did,\n\t\t\t\t\temail: envVars.adminUserName ?? \"admin@node\",\n\t\t\t\t\tpassword: envVars.adminUserPassword,\n\t\t\t\t\tscope: \"tenant-admin\",\n\t\t\t\t\tgivenName: \"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"]}
|