@twin.org/node-core 0.0.3-next.14 → 0.0.3-next.16
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 +3 -23
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +25 -2
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/cli.js +2 -0
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/nodeSetIdentity.js +9 -2
- package/dist/es/commands/nodeSetIdentity.js.map +1 -1
- package/dist/es/commands/nodeSetTenant.js +22 -6
- package/dist/es/commands/nodeSetTenant.js.map +1 -1
- package/dist/es/commands/tenantCreate.js +20 -6
- package/dist/es/commands/tenantCreate.js.map +1 -1
- package/dist/es/commands/tenantImport.js +16 -2
- package/dist/es/commands/tenantImport.js.map +1 -1
- package/dist/es/commands/tenantUpdate.js +98 -0
- package/dist/es/commands/tenantUpdate.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/node.js +1 -1
- package/dist/es/node.js.map +1 -1
- package/dist/types/commands/tenantCreate.d.ts +3 -0
- package/dist/types/commands/tenantImport.d.ts +2 -0
- package/dist/types/commands/tenantUpdate.d.ts +26 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +2 -6
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
- package/docs/changelog.md +15 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +3 -11
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +12 -16
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +16 -16
- package/locales/en.json +49 -4
- package/package.json +1 -1
package/dist/es/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names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AAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACjD,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,YAAY,CAAC,MAAM,EAAE,kBAAkB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACvF,CAAC;YACD,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC;QACvB,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC/B,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;IAC7C,mCAAmC,CAAC,kBAAkB,CAAC,CAAC;IACxD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,oDAAoD,CAAC,kBAAkB,CAAC,CAAC;IACzE,oDAAoD,CAAC,kBAAkB,CAAC,CAAC;IACzE,sDAAsD,CAAC,kBAAkB,CAAC,CAAC;IAC3E,mCAAmC,CAAC,kBAAkB,CAAC,CAAC;IACxD,iCAAiC,CAAC,kBAAkB,CAAC,CAAC;IACtD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,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 { 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 { getCommandDefinitionUserCreate } from \"./commands/userCreate.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 * Initialise the CLI.\n * @param processEnv The environment variables from the process.\n * @param args The command line arguments.\n * @returns The constructed CLI command if there is one.\n * @throws GeneralError if the command is missing or invalid.\n */\nexport function initCli(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\targs?: string[]\n): ICliCommand | undefined {\n\tconst commandLineArgs = parseCommandLineArgs(args);\n\tlet cliCommand;\n\n\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\tregisterCommands();\n\t\tcliCommand = constructCliCommand(processEnv, commandLineArgs);\n\t}\n\n\treturn cliCommand;\n}\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\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\tgetCommandDefinitionUserCreate(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,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,MAA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,CAAC,kBAAkB,CAAC,CAAC;IACxD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,oDAAoD,CAAC,kBAAkB,CAAC,CAAC;IACzE,oDAAoD,CAAC,kBAAkB,CAAC,CAAC;IACzE,sDAAsD,CAAC,kBAAkB,CAAC,CAAC;IAC3E,mCAAmC,CAAC,kBAAkB,CAAC,CAAC;IACxD,iCAAiC,CAAC,kBAAkB,CAAC,CAAC;IACtD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,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 { 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 { 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 * Initialise the CLI.\n * @param processEnv The environment variables from the process.\n * @param args The command line arguments.\n * @returns The constructed CLI command if there is one.\n * @throws GeneralError if the command is missing or invalid.\n */\nexport function initCli(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\targs?: string[]\n): ICliCommand | undefined {\n\tconst commandLineArgs = parseCommandLineArgs(args);\n\tlet cliCommand;\n\n\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\tregisterCommands();\n\t\tcliCommand = constructCliCommand(processEnv, commandLineArgs);\n\t}\n\n\treturn cliCommand;\n}\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\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\tgetCommandDefinitionVaultKeyCreate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyImport(commandDefinitions);\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright 2026 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
-
import { I18n } from "@twin.org/core";
|
|
5
|
-
import { Did } from "@twin.org/identity-models";
|
|
4
|
+
import { I18n, Is, NotFoundError } from "@twin.org/core";
|
|
5
|
+
import { Did, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
|
|
6
6
|
const COMMAND_NAME = "node-set-identity";
|
|
7
7
|
/**
|
|
8
8
|
* Get the command definition parameters.
|
|
@@ -42,6 +42,13 @@ export function getCommandDefinitionNodeSetIdentity(commandDefinitions) {
|
|
|
42
42
|
*/
|
|
43
43
|
export async function nodeSetIdentity(engineCore, envVars, params) {
|
|
44
44
|
Did.guard("nodeSetIdentity", "identity", params.identity);
|
|
45
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-identity.labels.resolvingIdentity"));
|
|
46
|
+
const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
|
|
47
|
+
const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
|
|
48
|
+
const identityDocument = await identityResolverConnector.resolveDocument(params.identity);
|
|
49
|
+
if (Is.empty(identityDocument)) {
|
|
50
|
+
throw new NotFoundError("nodeSetIdentity", "identityNotFound", params.identity);
|
|
51
|
+
}
|
|
45
52
|
const state = engineCore.getState();
|
|
46
53
|
state.nodeId = params.identity;
|
|
47
54
|
engineCore.setStateDirty();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeSetIdentity.js","sourceRoot":"","sources":["../../../src/commands/nodeSetIdentity.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"nodeSetIdentity.js","sourceRoot":"","sources":["../../../src/commands/nodeSetIdentity.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,GAAG,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAMlF,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,mCAAmC,CAAC,kBAEnD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC;QAClF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC1E,oBAAoB,EAAE,KAAK;QAC3B,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,iEAAiE,CACjE;gBACD,YAAY,EAAE,KAAK;gBACnB,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,iEAAiE,CACjE;gBACD,QAAQ,EAAE,KAAK;aACf;SACD;QACD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC;KAC3F,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,UAA4D,EAC5D,OAAkC,EAClC,MAEC;IAED,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE1D,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,8DAA8D,CAAC,CAClF,CAAC;IACF,MAAM,oCAAoC,GAAG,UAAU,CAAC,yBAAyB,CAChF,2BAA2B,CAC3B,CAAC;IAEF,MAAM,yBAAyB,GAAG,gCAAgC,CAAC,GAAG,CACrE,oCAAoC,CACpC,CAAC;IAEF,MAAM,gBAAgB,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1F,IAAI,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,aAAa,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjF,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC/B,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mDAAmD,CAAC,CAAC,CAAC;IAEzF,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { I18n, Is, NotFoundError } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityResolverConnectorFactory } from \"@twin.org/identity-models\";\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 = \"node-set-identity\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeSetIdentity(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.node-set-identity.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-set-identity.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-identity.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\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.node-set-identity.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) => nodeSetIdentity(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting a node identity.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to set for the node.\n */\nexport async function nodeSetIdentity(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"nodeSetIdentity\", \"identity\", params.identity);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"node.cli.commands.node-set-identity.labels.resolvingIdentity\")\n\t);\n\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverConnector\"\n\t);\n\n\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\tdefaultIdentityResolverConnectorType\n\t);\n\n\tconst identityDocument = await identityResolverConnector.resolveDocument(params.identity);\n\tif (Is.empty(identityDocument)) {\n\t\tthrow new NotFoundError(\"nodeSetIdentity\", \"identityNotFound\", params.identity);\n\t}\n\n\tconst state = engineCore.getState();\n\tstate.nodeId = params.identity;\n\tengineCore.setStateDirty();\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-identity.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
// Copyright 2026 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
1
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
-
import { Guards, I18n } from "@twin.org/core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, NotFoundError } from "@twin.org/core";
|
|
5
3
|
const COMMAND_NAME = "node-set-tenant";
|
|
6
4
|
/**
|
|
7
5
|
* Get the command definition parameters.
|
|
@@ -41,9 +39,27 @@ export function getCommandDefinitionNodeSetTenant(commandDefinitions) {
|
|
|
41
39
|
export async function nodeSetTenant(engineCore, envVars, params) {
|
|
42
40
|
Guards.stringHexLength("nodeSetTenant", "tenant-id", params.tenantId, 32);
|
|
43
41
|
const state = engineCore.getState();
|
|
44
|
-
state.nodeTenantId
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
if (state.nodeTenantId !== params.tenantId) {
|
|
43
|
+
const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceType("tenantAdminComponent");
|
|
44
|
+
if (!Is.stringValue(defaultTenantAdminComponentType)) {
|
|
45
|
+
throw new GeneralError("nodeSetTenant", "tenantAdminComponentNotRegistered");
|
|
46
|
+
}
|
|
47
|
+
const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
|
|
48
|
+
const tenant = await tenantAdminComponent.get(params.tenantId);
|
|
49
|
+
if (Is.empty(tenant)) {
|
|
50
|
+
throw new NotFoundError("nodeSetTenant", "tenantNotFound", params.tenantId);
|
|
51
|
+
}
|
|
52
|
+
const currentNodeTenants = await tenantAdminComponent.query({ isNodeTenant: true });
|
|
53
|
+
for (const currentNodeTenant of currentNodeTenants.tenants) {
|
|
54
|
+
currentNodeTenant.isNodeTenant = false;
|
|
55
|
+
await tenantAdminComponent.set(currentNodeTenant);
|
|
56
|
+
}
|
|
57
|
+
tenant.isNodeTenant = true;
|
|
58
|
+
await tenantAdminComponent.set(tenant);
|
|
59
|
+
state.nodeTenantId = params.tenantId;
|
|
60
|
+
engineCore.setStateDirty();
|
|
61
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-tenant.labels.stored"));
|
|
62
|
+
}
|
|
47
63
|
CLIDisplay.done();
|
|
48
64
|
}
|
|
49
65
|
//# sourceMappingURL=nodeSetTenant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeSetTenant.js","sourceRoot":"","sources":["../../../src/commands/nodeSetTenant.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodeSetTenant.js","sourceRoot":"","sources":["../../../src/commands/nodeSetTenant.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAOjG,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAAC,kBAEjD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EA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CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAE/D,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,aAAa,CAAC,eAAe,EAAE,gBAAgB,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QACpF,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAC5D,iBAAiB,CAAC,YAAY,GAAG,KAAK,CAAC;YACvC,MAAM,oBAAoB,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,MAAM,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEvC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrC,UAAU,CAAC,aAAa,EAAE,CAAC;QAE3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is, NotFoundError } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\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 = \"node-set-tenant\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeSetTenant(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.node-set-tenant.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-set-tenant.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-tenant.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\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.node-set-tenant.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) => nodeSetTenant(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting a node tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.tenantId The tenant id to set for the node.\n */\nexport async function nodeSetTenant(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"nodeSetTenant\", \"tenant-id\", params.tenantId, 32);\n\n\tconst state = engineCore.getState();\n\n\tif (state.nodeTenantId !== params.tenantId) {\n\t\tconst defaultTenantAdminComponentType =\n\t\t\tengineCore.getRegisteredInstanceType(\"tenantAdminComponent\");\n\n\t\tif (!Is.stringValue(defaultTenantAdminComponentType)) {\n\t\t\tthrow new GeneralError(\"nodeSetTenant\", \"tenantAdminComponentNotRegistered\");\n\t\t}\n\n\t\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(\n\t\t\tdefaultTenantAdminComponentType\n\t\t);\n\n\t\tconst tenant = await tenantAdminComponent.get(params.tenantId);\n\n\t\tif (Is.empty(tenant)) {\n\t\t\tthrow new NotFoundError(\"nodeSetTenant\", \"tenantNotFound\", params.tenantId);\n\t\t}\n\n\t\tconst currentNodeTenants = await tenantAdminComponent.query({ isNodeTenant: true });\n\t\tfor (const currentNodeTenant of currentNodeTenants.tenants) {\n\t\t\tcurrentNodeTenant.isNodeTenant = false;\n\t\t\tawait tenantAdminComponent.set(currentNodeTenant);\n\t\t}\n\n\t\ttenant.isNodeTenant = true;\n\t\tawait tenantAdminComponent.set(tenant);\n\n\t\tstate.nodeTenantId = params.tenantId;\n\t\tengineCore.setStateDirty();\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-tenant.labels.stored\"));\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
// Copyright 2026 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
1
|
import { TenantIdHelper } from "@twin.org/api-tenant-processor";
|
|
4
2
|
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
5
|
-
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
6
4
|
const COMMAND_NAME = "tenant-create";
|
|
7
5
|
/**
|
|
8
6
|
* Get the command definition parameters.
|
|
@@ -29,6 +27,13 @@ export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
|
29
27
|
description: I18n.formatMessage("node.cli.commands.tenant-create.params.api-key.description"),
|
|
30
28
|
required: false
|
|
31
29
|
},
|
|
30
|
+
{
|
|
31
|
+
key: "public-origin",
|
|
32
|
+
type: "string",
|
|
33
|
+
extendedType: "url",
|
|
34
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.public-origin.description"),
|
|
35
|
+
required: false
|
|
36
|
+
},
|
|
32
37
|
{
|
|
33
38
|
key: "label",
|
|
34
39
|
type: "string",
|
|
@@ -71,6 +76,7 @@ export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
|
71
76
|
* @param params.apiKey The api key to add.
|
|
72
77
|
* @param params.tenantId The tenant ID to add the api key to.
|
|
73
78
|
* @param params.label The label for the api key.
|
|
79
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
74
80
|
* @param params.outputJson The output .json file to store the command output.
|
|
75
81
|
* @param params.outputEnv The output .env file to store the command output.
|
|
76
82
|
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
@@ -83,6 +89,9 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
83
89
|
if (Is.stringValue(params.apiKey)) {
|
|
84
90
|
Guards.stringHexLength("tenantCreate", "api-key", params.apiKey, 32);
|
|
85
91
|
}
|
|
92
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
93
|
+
Url.guard("tenantCreate", "public-origin", params.publicOrigin);
|
|
94
|
+
}
|
|
86
95
|
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
87
96
|
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
88
97
|
throw new GeneralError("tenantCreate", "tenantAdminComponentNotRegistered");
|
|
@@ -92,18 +101,22 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
92
101
|
const apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();
|
|
93
102
|
const tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();
|
|
94
103
|
const label = params.label ?? "";
|
|
104
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
95
105
|
await tenantAdminService.set({
|
|
96
106
|
id: tenantId,
|
|
97
107
|
apiKey,
|
|
98
108
|
dateCreated: new Date(Date.now()).toISOString(),
|
|
99
|
-
label
|
|
109
|
+
label,
|
|
110
|
+
publicOrigin,
|
|
111
|
+
isNodeTenant: false
|
|
100
112
|
});
|
|
101
113
|
CLIDisplay.break();
|
|
102
114
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.tenantId"), tenantId);
|
|
103
115
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.apiKey"), apiKey);
|
|
104
116
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.label"), label);
|
|
117
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.publicOrigin"), publicOrigin);
|
|
105
118
|
CLIDisplay.break();
|
|
106
|
-
const json = { apiKey, tenantId, label };
|
|
119
|
+
const json = { apiKey, tenantId, label, publicOrigin };
|
|
107
120
|
if (Is.stringValue(params.outputJson)) {
|
|
108
121
|
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
109
122
|
}
|
|
@@ -111,7 +124,8 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
111
124
|
await CLIUtils.writeEnvFile(params.outputEnv, [
|
|
112
125
|
`${params.outputEnvPrefix}API_KEY="${apiKey}"`,
|
|
113
126
|
`${params.outputEnvPrefix}TENANT_ID="${tenantId}"`,
|
|
114
|
-
`${params.outputEnvPrefix}LABEL="${label}"
|
|
127
|
+
`${params.outputEnvPrefix}LABEL="${label}"`,
|
|
128
|
+
`${params.outputEnvPrefix}PUBLIC_ORIGIN="${publicOrigin}"`
|
|
115
129
|
], false);
|
|
116
130
|
}
|
|
117
131
|
CLIDisplay.done();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenantCreate.js","sourceRoot":"","sources":["../../../src/commands/tenantCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO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M,CAAC,SAAS,EAChB;YACC,GAAG,MAAM,CAAC,eAAe,YAAY,MAAM,GAAG;YAC9C,GAAG,MAAM,CAAC,eAAe,cAAc,QAAQ,GAAG;YAClD,GAAG,MAAM,CAAC,eAAe,UAAU,KAAK,GAAG;SAC3C,EACD,KAAK,CACL,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { TenantIdHelper, type ITenantAdminComponent } from \"@twin.org/api-tenant-processor\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantCreate(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.tenant-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-create.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.tenant-id.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: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.api-key.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: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-create.params.label.description\"),\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.tenant-create.params.load-env.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: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-json.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: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-env.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: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-env-prefix.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) => tenantCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to add.\n * @param params.tenantId The tenant ID to add the api key to.\n * @param params.label The label for the api key.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created tenant details.\n */\nexport async function tenantCreate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<{ apiKey: string; tenantId: string; label: string }> {\n\tif (Is.stringValue(params.tenantId)) {\n\t\tGuards.stringHexLength(\"tenantCreate\", \"tenant-id\", params.tenantId, 32);\n\t}\n\n\tif (Is.stringValue(params.apiKey)) {\n\t\tGuards.stringHexLength(\"tenantCreate\", \"api-key\", params.apiKey, 32);\n\t}\n\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\tthrow new GeneralError(\"tenantCreate\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.creating\"));\n\n\tconst apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();\n\tconst tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();\n\tconst label = params.label ?? \"\";\n\n\tawait tenantAdminService.set({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\tlabel\n\t});\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.tenantId\"), tenantId);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.apiKey\"), apiKey);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.label\"), label);\n\tCLIDisplay.break();\n\n\tconst json = { apiKey, tenantId, label };\n\tif (Is.stringValue(params.outputJson)) {\n\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t}\n\n\tif (Is.stringValue(params.outputEnv)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\tparams.outputEnv,\n\t\t\t[\n\t\t\t\t`${params.outputEnvPrefix}API_KEY=\"${apiKey}\"`,\n\t\t\t\t`${params.outputEnvPrefix}TENANT_ID=\"${tenantId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}LABEL=\"${label}\"`\n\t\t\t],\n\t\t\tfalse\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tenantCreate.js","sourceRoot":"","sources":["../../../src/commands/tenantCreate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAKvF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC9E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC;QACtE,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,8DAA8D,CAC9D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,SAAS;gBACd,IAAI,EAAE,QAAQ;gBACd,YAAY,EA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D,EACD,KAAK,CACL,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { TenantIdHelper } from \"@twin.org/api-tenant-processor\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantCreate(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.tenant-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-create.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.tenant-id.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: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.api-key.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: \"public-origin\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"url\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.public-origin.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: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-create.params.label.description\"),\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.tenant-create.params.load-env.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: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-json.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: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-env.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: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-env-prefix.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) => tenantCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to add.\n * @param params.tenantId The tenant ID to add the api key to.\n * @param params.label The label for the api key.\n * @param params.publicOrigin The public URL origin for the tenant.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created tenant details.\n */\nexport async function tenantCreate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\tpublicOrigin?: string;\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<{ apiKey: string; tenantId: string; label: string; publicOrigin: string }> {\n\tif (Is.stringValue(params.tenantId)) {\n\t\tGuards.stringHexLength(\"tenantCreate\", \"tenant-id\", params.tenantId, 32);\n\t}\n\n\tif (Is.stringValue(params.apiKey)) {\n\t\tGuards.stringHexLength(\"tenantCreate\", \"api-key\", params.apiKey, 32);\n\t}\n\n\tif (Is.stringValue(params.publicOrigin)) {\n\t\tUrl.guard(\"tenantCreate\", \"public-origin\", params.publicOrigin);\n\t}\n\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\tthrow new GeneralError(\"tenantCreate\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.creating\"));\n\n\tconst apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();\n\tconst tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminService.set({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\tlabel,\n\t\tpublicOrigin,\n\t\tisNodeTenant: false\n\t});\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.tenantId\"), tenantId);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.apiKey\"), apiKey);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.label\"), label);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-create.labels.publicOrigin\"),\n\t\tpublicOrigin\n\t);\n\tCLIDisplay.break();\n\n\tconst json = { apiKey, tenantId, label, publicOrigin };\n\tif (Is.stringValue(params.outputJson)) {\n\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t}\n\n\tif (Is.stringValue(params.outputEnv)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\tparams.outputEnv,\n\t\t\t[\n\t\t\t\t`${params.outputEnvPrefix}API_KEY=\"${apiKey}\"`,\n\t\t\t\t`${params.outputEnvPrefix}TENANT_ID=\"${tenantId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}LABEL=\"${label}\"`,\n\t\t\t\t`${params.outputEnvPrefix}PUBLIC_ORIGIN=\"${publicOrigin}\"`\n\t\t\t],\n\t\t\tfalse\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
-
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
3
3
|
const COMMAND_NAME = "tenant-import";
|
|
4
4
|
/**
|
|
5
5
|
* Get the command definition parameters.
|
|
@@ -32,6 +32,13 @@ export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
|
32
32
|
description: I18n.formatMessage("node.cli.commands.tenant-import.params.label.description"),
|
|
33
33
|
required: false
|
|
34
34
|
},
|
|
35
|
+
{
|
|
36
|
+
key: "public-origin",
|
|
37
|
+
type: "string",
|
|
38
|
+
extendedType: "url",
|
|
39
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.public-origin.description"),
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
35
42
|
{
|
|
36
43
|
key: "load-env",
|
|
37
44
|
type: "string",
|
|
@@ -50,10 +57,14 @@ export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
|
50
57
|
* @param params.apiKey The api key to import.
|
|
51
58
|
* @param params.tenantId The tenant ID to import the api key to.
|
|
52
59
|
* @param params.label The label for the api key.
|
|
60
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
53
61
|
*/
|
|
54
62
|
export async function tenantImport(engineCore, envVars, params) {
|
|
55
63
|
Guards.stringHexLength("tenantImport", "tenant-id", params.tenantId, 32);
|
|
56
64
|
Guards.stringHexLength("tenantImport", "api-key", params.apiKey, 32);
|
|
65
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
66
|
+
Url.guard("tenantImport", "public-origin", params.publicOrigin);
|
|
67
|
+
}
|
|
57
68
|
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
58
69
|
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
59
70
|
throw new GeneralError("tenantImport", "tenantAdminComponentNotRegistered");
|
|
@@ -64,11 +75,14 @@ export async function tenantImport(engineCore, envVars, params) {
|
|
|
64
75
|
const apiKey = params.apiKey;
|
|
65
76
|
const tenantId = params.tenantId;
|
|
66
77
|
const label = params.label ?? "";
|
|
78
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
67
79
|
await tenantAdminService.set({
|
|
68
80
|
id: tenantId,
|
|
69
81
|
apiKey,
|
|
70
82
|
dateCreated: new Date(Date.now()).toISOString(),
|
|
71
|
-
label
|
|
83
|
+
label,
|
|
84
|
+
publicOrigin,
|
|
85
|
+
isNodeTenant: false
|
|
72
86
|
});
|
|
73
87
|
CLIDisplay.spinnerStop();
|
|
74
88
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.imported"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenantImport.js","sourceRoot":"","sources":["../../../src/commands/tenantImport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"tenantImport.js","sourceRoot":"","sources":["../../../src/commands/tenantImport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAKvF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC9E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC;QACtE,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,8DAA8D,CAC9D;gBACD,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,SAAS;gBACd,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,4DAA4D,CAC5D;gBACD,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE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,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAC9C,+BAA+B,CAC/B,CAAC;IAEF,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,kDAAkD,CAAC,CAAC,CAAC;IACxF,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IACjC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAC/C,MAAM,kBAAkB,CAAC,GAAG,CAAC;QAC5B,EAAE,EAAE,QAAQ;QACZ,MAAM;QACN,WAAW,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;QAC/C,KAAK;QACL,YAAY;QACZ,YAAY,EAAE,KAAK;KACnB,CAAC,CAAC;IACH,UAAU,CAAC,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAEvF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantImport(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.tenant-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-import.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.api-key.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-import.params.label.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"public-origin\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"url\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.public-origin.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.tenant-import.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) => tenantImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to import.\n * @param params.tenantId The tenant ID to import the api key to.\n * @param params.label The label for the api key.\n * @param params.publicOrigin The public URL origin for the tenant.\n */\nexport async function tenantImport(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\tpublicOrigin?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"tenantImport\", \"tenant-id\", params.tenantId, 32);\n\tGuards.stringHexLength(\"tenantImport\", \"api-key\", params.apiKey, 32);\n\n\tif (Is.stringValue(params.publicOrigin)) {\n\t\tUrl.guard(\"tenantImport\", \"public-origin\", params.publicOrigin);\n\t}\n\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\tthrow new GeneralError(\"tenantImport\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-import.labels.importing\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst apiKey = params.apiKey;\n\tconst tenantId = params.tenantId;\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminService.set({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\tlabel,\n\t\tpublicOrigin,\n\t\tisNodeTenant: false\n\t});\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-import.labels.imported\"));\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, NotFoundError, Url } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-update";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantUpdate(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-update.example"),
|
|
13
|
+
requiresTenantId: false,
|
|
14
|
+
params: [
|
|
15
|
+
{
|
|
16
|
+
key: "tenant-id",
|
|
17
|
+
type: "string",
|
|
18
|
+
extendedType: "hex(32)",
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.tenant-id.description"),
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "api-key",
|
|
24
|
+
type: "string",
|
|
25
|
+
extendedType: "hex(32)",
|
|
26
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.api-key.description"),
|
|
27
|
+
required: false
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: "label",
|
|
31
|
+
type: "string",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.label.description"),
|
|
33
|
+
required: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "public-origin",
|
|
37
|
+
type: "string",
|
|
38
|
+
extendedType: "url",
|
|
39
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.public-origin.description"),
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: "load-env",
|
|
44
|
+
type: "string",
|
|
45
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.load-env.description"),
|
|
46
|
+
required: false
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
action: async (engineCore, envVars, params) => tenantUpdate(engineCore, envVars, params)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Command for updating a tenant.
|
|
54
|
+
* @param engineCore The engine core.
|
|
55
|
+
* @param envVars The environment variables for the node.
|
|
56
|
+
* @param params The parameters for the command.
|
|
57
|
+
* @param params.apiKey The api key to update.
|
|
58
|
+
* @param params.tenantId The tenant ID to update the api key to.
|
|
59
|
+
* @param params.label The label for the api key.
|
|
60
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
61
|
+
*/
|
|
62
|
+
export async function tenantUpdate(engineCore, envVars, params) {
|
|
63
|
+
Guards.stringHexLength("tenantUpdate", "tenant-id", params.tenantId, 32);
|
|
64
|
+
if (Is.stringValue(params.apiKey)) {
|
|
65
|
+
Guards.stringHexLength("tenantUpdate", "api-key", params.apiKey, 32);
|
|
66
|
+
}
|
|
67
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
68
|
+
Url.guard("tenantUpdate", "public-origin", params.publicOrigin);
|
|
69
|
+
}
|
|
70
|
+
const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceType("tenantAdminComponent");
|
|
71
|
+
if (!Is.stringValue(defaultTenantAdminComponentType)) {
|
|
72
|
+
throw new GeneralError("tenantUpdate", "tenantAdminComponentNotRegistered");
|
|
73
|
+
}
|
|
74
|
+
const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
|
|
75
|
+
const tenant = await tenantAdminComponent.get(params.tenantId);
|
|
76
|
+
if (Is.empty(tenant)) {
|
|
77
|
+
throw new NotFoundError("tenantUpdate", "tenantNotFound", params.tenantId);
|
|
78
|
+
}
|
|
79
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updating"));
|
|
80
|
+
CLIDisplay.spinnerStart();
|
|
81
|
+
const apiKey = params.apiKey;
|
|
82
|
+
const tenantId = params.tenantId;
|
|
83
|
+
const label = params.label ?? "";
|
|
84
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
85
|
+
await tenantAdminComponent.set({
|
|
86
|
+
id: tenantId,
|
|
87
|
+
apiKey: Is.stringValue(apiKey) ? apiKey : tenant.apiKey,
|
|
88
|
+
dateCreated: tenant.dateCreated,
|
|
89
|
+
label: Is.stringValue(label) ? label : tenant.label,
|
|
90
|
+
publicOrigin: Is.stringValue(publicOrigin) ? publicOrigin : tenant.publicOrigin,
|
|
91
|
+
isNodeTenant: tenant.isNodeTenant
|
|
92
|
+
});
|
|
93
|
+
CLIDisplay.spinnerStop();
|
|
94
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updated"));
|
|
95
|
+
CLIDisplay.break();
|
|
96
|
+
CLIDisplay.done();
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=tenantUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantUpdate.js","sourceRoot":"","sources":["../../../src/commands/tenantUpdate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,MAAM,EACN,IAAI,EACJ,EAAE,EACF,aAAa,EACb,GAAG,EACH,MAAM,gBAAgB,CAAC;AAKxB,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC9E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC;QACtE,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE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AC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM;QACvD,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;QACnD,YAAY,EAAE,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY;QAC/E,YAAY,EAAE,MAAM,CAAC,YAAY;KACjC,CAAC,CAAC;IACH,UAAU,CAAC,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC,CAAC,CAAC;IAEtF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport {\n\tComponentFactory,\n\tGeneralError,\n\tGuards,\n\tI18n,\n\tIs,\n\tNotFoundError,\n\tUrl\n} from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-update\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantUpdate(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.tenant-update.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-update.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.api-key.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: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-update.params.label.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"public-origin\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"url\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.public-origin.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.tenant-update.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) => tenantUpdate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for updating a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to update.\n * @param params.tenantId The tenant ID to update the api key to.\n * @param params.label The label for the api key.\n * @param params.publicOrigin The public URL origin for the tenant.\n */\nexport async function tenantUpdate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\tpublicOrigin?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"tenantUpdate\", \"tenant-id\", params.tenantId, 32);\n\n\tif (Is.stringValue(params.apiKey)) {\n\t\tGuards.stringHexLength(\"tenantUpdate\", \"api-key\", params.apiKey, 32);\n\t}\n\n\tif (Is.stringValue(params.publicOrigin)) {\n\t\tUrl.guard(\"tenantUpdate\", \"public-origin\", params.publicOrigin);\n\t}\n\n\tconst defaultTenantAdminComponentType =\n\t\tengineCore.getRegisteredInstanceType(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(defaultTenantAdminComponentType)) {\n\t\tthrow new GeneralError(\"tenantUpdate\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(\n\t\tdefaultTenantAdminComponentType\n\t);\n\n\tconst tenant = await tenantAdminComponent.get(params.tenantId);\n\n\tif (Is.empty(tenant)) {\n\t\tthrow new NotFoundError(\"tenantUpdate\", \"tenantNotFound\", params.tenantId);\n\t}\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-update.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst apiKey = params.apiKey;\n\tconst tenantId = params.tenantId;\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminComponent.set({\n\t\tid: tenantId,\n\t\tapiKey: Is.stringValue(apiKey) ? apiKey : tenant.apiKey,\n\t\tdateCreated: tenant.dateCreated,\n\t\tlabel: Is.stringValue(label) ? label : tenant.label,\n\t\tpublicOrigin: Is.stringValue(publicOrigin) ? publicOrigin : tenant.publicOrigin,\n\t\tisNodeTenant: tenant.isNodeTenant\n\t});\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-update.labels.updated\"));\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|