@twin.org/node-core 0.0.3-next.5 → 0.0.3-next.51
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 +472 -198
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +89 -32
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/extensionsBuilder.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 +178 -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 +326 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityImports.js +81 -0
- package/dist/es/commands/identityImports.js.map +1 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js +145 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodCreate.js +227 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js +125 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
- package/dist/es/commands/nodeSetIdentity.js +63 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +137 -0
- package/dist/es/commands/tenantCreate.js.map +1 -0
- package/dist/es/commands/tenantImport.js +95 -0
- package/dist/es/commands/tenantImport.js.map +1 -0
- package/dist/es/commands/tenantToken.js +97 -0
- package/dist/es/commands/tenantToken.js.map +1 -0
- package/dist/es/commands/tenantUpdate.js +93 -0
- package/dist/es/commands/tenantUpdate.js.map +1 -0
- package/dist/es/commands/userCreate.js +239 -0
- package/dist/es/commands/userCreate.js.map +1 -0
- package/dist/es/commands/userUpdate.js +154 -0
- package/dist/es/commands/userUpdate.js.map +1 -0
- package/dist/es/commands/vaultKeyCreate.js +190 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -0
- package/dist/es/commands/vaultKeyImport.js +103 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -0
- package/dist/es/defaults.js +18 -2
- package/dist/es/defaults.js.map +1 -1
- package/dist/es/index.js +11 -4
- 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/models/nodeExtensionInitialiseEngineMethod.js +2 -0
- package/dist/es/models/nodeExtensionInitialiseEngineMethod.js.map +1 -0
- package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js +2 -0
- package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js.map +1 -0
- package/dist/es/models/nodeExtensionInitialiseMethod.js +2 -0
- package/dist/es/models/nodeExtensionInitialiseMethod.js.map +1 -0
- package/dist/es/models/nodeExtensionShutdownMethod.js +4 -0
- package/dist/es/models/nodeExtensionShutdownMethod.js.map +1 -0
- package/dist/es/node.js +86 -39
- package/dist/es/node.js.map +1 -1
- package/dist/es/{server.js → start.js} +72 -27
- package/dist/es/start.js.map +1 -0
- package/dist/es/utils.js +21 -25
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +67 -1
- package/dist/types/builders/engineServerEnvBuilder.d.ts +11 -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/tenantCreate.d.ts +38 -0
- package/dist/types/commands/tenantImport.d.ts +26 -0
- package/dist/types/commands/tenantToken.d.ts +28 -0
- package/dist/types/commands/tenantUpdate.d.ts +26 -0
- package/dist/types/commands/userCreate.d.ts +51 -0
- package/dist/types/commands/userUpdate.d.ts +40 -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 +10 -2
- package/dist/types/index.d.ts +11 -4
- 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 +41 -0
- package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +132 -99
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +8 -0
- package/dist/types/models/INodeEngineState.d.ts +0 -12
- 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/models/nodeExtensionInitialiseEngineMethod.d.ts +7 -0
- package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +8 -0
- package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +8 -0
- package/dist/types/models/nodeExtensionShutdownMethod.d.ts +5 -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 +611 -178
- 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/isAuthEntityStorageRequired.md +20 -0
- package/docs/reference/functions/isAutomationRequired.md +20 -0
- package/docs/reference/functions/isBackgroundTasksRequired.md +20 -0
- package/docs/reference/functions/isFederatedCatalogueRequired.md +20 -0
- package/docs/reference/functions/isImmutableProofRequired.md +20 -0
- package/docs/reference/functions/isRightsManagementRequired.md +23 -0
- package/docs/reference/functions/isTaskSchedulerRequired.md +20 -0
- package/docs/reference/functions/isTelemetryRequired.md +20 -0
- package/docs/reference/functions/isTrustRequired.md +20 -0
- package/docs/reference/functions/isUrlTransformerRequired.md +20 -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 +26 -14
- 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 +87 -0
- package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +418 -369
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +546 -445
- package/docs/reference/interfaces/IModuleProtocol.md +3 -3
- package/docs/reference/interfaces/INodeEngineState.md +2 -26
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +564 -539
- 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/docs/reference/variables/URL_TRANSFORMER_ENCRYPTION_KEY_ID.md +3 -0
- package/locales/en.json +605 -30
- package/package.json +10 -6
- package/dist/es/bootstrap.js +0 -366
- package/dist/es/bootstrap.js.map +0 -1
- package/dist/es/identity.js +0 -182
- package/dist/es/identity.js.map +0 -1
- package/dist/es/models/nodeExtensionMethods.js +0 -2
- package/dist/es/models/nodeExtensionMethods.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.map +0 -1
- package/dist/types/bootstrap.d.ts +0 -68
- package/dist/types/identity.d.ts +0 -14
- package/dist/types/models/nodeExtensionMethods.d.ts +0 -27
- 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/SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID.md +0 -3
- package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { I18n, Is, NotFoundError } from "@twin.org/core";
|
|
5
|
+
import { Did, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
|
|
6
|
+
const COMMAND_NAME = "node-set-identity";
|
|
7
|
+
/**
|
|
8
|
+
* Get the command definition parameters.
|
|
9
|
+
* @param commandDefinitions The registered command definitions.
|
|
10
|
+
*/
|
|
11
|
+
export function getCommandDefinitionNodeSetIdentity(commandDefinitions) {
|
|
12
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
13
|
+
command: COMMAND_NAME,
|
|
14
|
+
description: I18n.formatMessage("node.cli.commands.node-set-identity.description"),
|
|
15
|
+
example: I18n.formatMessage("node.cli.commands.node-set-identity.example"),
|
|
16
|
+
requiresNodeIdentity: false,
|
|
17
|
+
params: [
|
|
18
|
+
{
|
|
19
|
+
key: "env-prefix",
|
|
20
|
+
type: "string",
|
|
21
|
+
description: I18n.formatMessage("node.cli.commands.node-set-identity.params.env-prefix.description"),
|
|
22
|
+
required: false
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "identity",
|
|
26
|
+
type: "string",
|
|
27
|
+
description: I18n.formatMessage("node.cli.commands.node-set-identity.params.identity.description"),
|
|
28
|
+
extendedType: "did",
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "load-env",
|
|
33
|
+
type: "string",
|
|
34
|
+
description: I18n.formatMessage("node.cli.commands.node-set-identity.params.load-env.description"),
|
|
35
|
+
required: false
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
action: async (engineCore, envVars, params) => nodeSetIdentity(engineCore, envVars, params)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Command for setting a node identity.
|
|
43
|
+
* @param engineCore The engine core.
|
|
44
|
+
* @param envVars The environment variables for the node.
|
|
45
|
+
* @param params The parameters for the command.
|
|
46
|
+
* @param params.identity The DID to set for the node.
|
|
47
|
+
*/
|
|
48
|
+
export async function nodeSetIdentity(engineCore, envVars, params) {
|
|
49
|
+
Did.guard("nodeSetIdentity", "identity", params.identity);
|
|
50
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-identity.labels.resolvingIdentity"));
|
|
51
|
+
const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
|
|
52
|
+
const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
|
|
53
|
+
const identityDocument = await identityResolverConnector.resolveDocument(params.identity);
|
|
54
|
+
if (Is.empty(identityDocument)) {
|
|
55
|
+
throw new NotFoundError("nodeSetIdentity", "identityNotFound", params.identity);
|
|
56
|
+
}
|
|
57
|
+
const state = engineCore.getState();
|
|
58
|
+
state.nodeId = params.identity;
|
|
59
|
+
engineCore.setStateDirty();
|
|
60
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-identity.labels.stored"));
|
|
61
|
+
CLIDisplay.done();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=nodeSetIdentity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeSetIdentity.js","sourceRoot":"","sources":["../../../src/commands/nodeSetIdentity.ts"],"names":[],"mappings":"AAAA,g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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\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.node-set-identity.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: \"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"]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { TenantIdHelper } from "@twin.org/api-tenant-processor";
|
|
2
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
3
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
4
|
+
const COMMAND_NAME = "tenant-create";
|
|
5
|
+
/**
|
|
6
|
+
* Get the command definition parameters.
|
|
7
|
+
* @param commandDefinitions The registered command definitions.
|
|
8
|
+
*/
|
|
9
|
+
export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
10
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
11
|
+
command: COMMAND_NAME,
|
|
12
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.description"),
|
|
13
|
+
example: I18n.formatMessage("node.cli.commands.tenant-create.example"),
|
|
14
|
+
params: [
|
|
15
|
+
{
|
|
16
|
+
key: "env-prefix",
|
|
17
|
+
type: "string",
|
|
18
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.env-prefix.description"),
|
|
19
|
+
required: false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: "tenant-id",
|
|
23
|
+
type: "string",
|
|
24
|
+
extendedType: "hex(32)",
|
|
25
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.tenant-id.description"),
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "api-key",
|
|
30
|
+
type: "string",
|
|
31
|
+
extendedType: "hex(32)",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.api-key.description"),
|
|
33
|
+
required: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "public-origin",
|
|
37
|
+
type: "string",
|
|
38
|
+
extendedType: "url",
|
|
39
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.public-origin.description"),
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: "label",
|
|
44
|
+
type: "string",
|
|
45
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.label.description"),
|
|
46
|
+
required: false
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "load-env",
|
|
50
|
+
type: "string",
|
|
51
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.load-env.description"),
|
|
52
|
+
required: false
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
key: "output-json",
|
|
56
|
+
type: "string",
|
|
57
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-json.description"),
|
|
58
|
+
required: false
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: "output-env",
|
|
62
|
+
type: "string",
|
|
63
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-env.description"),
|
|
64
|
+
required: false
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "output-env-prefix",
|
|
68
|
+
type: "string",
|
|
69
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-env-prefix.description"),
|
|
70
|
+
required: false
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
action: async (engineCore, envVars, params) => tenantCreate(engineCore, envVars, params)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Command for creating a tenant.
|
|
78
|
+
* @param engineCore The engine core.
|
|
79
|
+
* @param envVars The environment variables for the node.
|
|
80
|
+
* @param params The parameters for the command.
|
|
81
|
+
* @param params.apiKey The api key to add.
|
|
82
|
+
* @param params.tenantId The tenant ID to add the api key to.
|
|
83
|
+
* @param params.label The label for the api key.
|
|
84
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
85
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
86
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
87
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
88
|
+
* @returns The created tenant details.
|
|
89
|
+
*/
|
|
90
|
+
export async function tenantCreate(engineCore, envVars, params) {
|
|
91
|
+
if (Is.stringValue(params.tenantId)) {
|
|
92
|
+
Guards.stringHexLength("tenantCreate", "tenant-id", params.tenantId, 32);
|
|
93
|
+
}
|
|
94
|
+
if (Is.stringValue(params.apiKey)) {
|
|
95
|
+
Guards.stringHexLength("tenantCreate", "api-key", params.apiKey, 32);
|
|
96
|
+
}
|
|
97
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
98
|
+
Url.guard("tenantCreate", "public-origin", params.publicOrigin);
|
|
99
|
+
}
|
|
100
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
101
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
102
|
+
throw new GeneralError("tenantCreate", "tenantAdminComponentNotRegistered");
|
|
103
|
+
}
|
|
104
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
105
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-create.labels.creating"));
|
|
106
|
+
const apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();
|
|
107
|
+
const tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();
|
|
108
|
+
const label = params.label ?? "";
|
|
109
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
110
|
+
await tenantAdminService.create({
|
|
111
|
+
id: tenantId,
|
|
112
|
+
apiKey,
|
|
113
|
+
label,
|
|
114
|
+
publicOrigin
|
|
115
|
+
});
|
|
116
|
+
CLIDisplay.break();
|
|
117
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.tenantId"), tenantId);
|
|
118
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.apiKey"), apiKey);
|
|
119
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.label"), label);
|
|
120
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.publicOrigin"), publicOrigin);
|
|
121
|
+
CLIDisplay.break();
|
|
122
|
+
const json = { apiKey, tenantId, label, publicOrigin };
|
|
123
|
+
if (Is.stringValue(params.outputJson)) {
|
|
124
|
+
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
125
|
+
}
|
|
126
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
127
|
+
await CLIUtils.writeEnvFile(params.outputEnv, [
|
|
128
|
+
`${params.outputEnvPrefix}API_KEY="${apiKey}"`,
|
|
129
|
+
`${params.outputEnvPrefix}TENANT_ID="${tenantId}"`,
|
|
130
|
+
`${params.outputEnvPrefix}LABEL="${label}"`,
|
|
131
|
+
`${params.outputEnvPrefix}PUBLIC_ORIGIN="${publicOrigin}"`
|
|
132
|
+
], false);
|
|
133
|
+
}
|
|
134
|
+
CLIDisplay.done();
|
|
135
|
+
return json;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=tenantCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,U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AU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,EACzE,YAAY,CACZ,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IACvD,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QACtC,MAAM,QAAQ,CAAC,YAAY,CAC1B,MAAM,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;YAC3C,GAAG,MAAM,CAAC,eAAe,kBAAkB,YAAY,GAAG;SAC1D,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\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.tenant-create.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: \"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.create({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tlabel,\n\t\tpublicOrigin\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"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-import";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-import.example"),
|
|
13
|
+
params: [
|
|
14
|
+
{
|
|
15
|
+
key: "env-prefix",
|
|
16
|
+
type: "string",
|
|
17
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.env-prefix.description"),
|
|
18
|
+
required: false
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "tenant-id",
|
|
22
|
+
type: "string",
|
|
23
|
+
extendedType: "hex(32)",
|
|
24
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.tenant-id.description"),
|
|
25
|
+
required: true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "api-key",
|
|
29
|
+
type: "string",
|
|
30
|
+
extendedType: "hex(32)",
|
|
31
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.api-key.description"),
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "label",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.label.description"),
|
|
38
|
+
required: false
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "public-origin",
|
|
42
|
+
type: "string",
|
|
43
|
+
extendedType: "url",
|
|
44
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.public-origin.description"),
|
|
45
|
+
required: false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "load-env",
|
|
49
|
+
type: "string",
|
|
50
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.load-env.description"),
|
|
51
|
+
required: false
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
action: async (engineCore, envVars, params) => tenantImport(engineCore, envVars, params)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Command for importing a tenant.
|
|
59
|
+
* @param engineCore The engine core.
|
|
60
|
+
* @param envVars The environment variables for the node.
|
|
61
|
+
* @param params The parameters for the command.
|
|
62
|
+
* @param params.apiKey The api key to import.
|
|
63
|
+
* @param params.tenantId The tenant ID to import the api key to.
|
|
64
|
+
* @param params.label The label for the api key.
|
|
65
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
66
|
+
*/
|
|
67
|
+
export async function tenantImport(engineCore, envVars, params) {
|
|
68
|
+
Guards.stringHexLength("tenantImport", "tenant-id", params.tenantId, 32);
|
|
69
|
+
Guards.stringHexLength("tenantImport", "api-key", params.apiKey, 32);
|
|
70
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
71
|
+
Url.guard("tenantImport", "public-origin", params.publicOrigin);
|
|
72
|
+
}
|
|
73
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
74
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
75
|
+
throw new GeneralError("tenantImport", "tenantAdminComponentNotRegistered");
|
|
76
|
+
}
|
|
77
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
78
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.importing"));
|
|
79
|
+
CLIDisplay.spinnerStart();
|
|
80
|
+
const apiKey = params.apiKey;
|
|
81
|
+
const tenantId = params.tenantId;
|
|
82
|
+
const label = params.label ?? "";
|
|
83
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
84
|
+
await tenantAdminService.create({
|
|
85
|
+
id: tenantId,
|
|
86
|
+
apiKey,
|
|
87
|
+
label,
|
|
88
|
+
publicOrigin
|
|
89
|
+
});
|
|
90
|
+
CLIDisplay.spinnerStop();
|
|
91
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.imported"));
|
|
92
|
+
CLIDisplay.break();
|
|
93
|
+
CLIDisplay.done();
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=tenantImport.js.map
|
|
@@ -0,0 +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,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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vF,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\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.tenant-import.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: \"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.create({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tlabel,\n\t\tpublicOrigin\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,97 @@
|
|
|
1
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-token";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantToken(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-token.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-token.example"),
|
|
13
|
+
params: [
|
|
14
|
+
{
|
|
15
|
+
key: "tenant-id",
|
|
16
|
+
type: "string",
|
|
17
|
+
extendedType: "hex(32)",
|
|
18
|
+
description: I18n.formatMessage("node.cli.commands.tenant-token.params.tenant-id.description"),
|
|
19
|
+
required: false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: "api-key",
|
|
23
|
+
type: "string",
|
|
24
|
+
extendedType: "hex(32)",
|
|
25
|
+
description: I18n.formatMessage("node.cli.commands.tenant-token.params.api-key.description"),
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "load-env",
|
|
30
|
+
type: "string",
|
|
31
|
+
description: I18n.formatMessage("node.cli.commands.tenant-token.params.load-env.description"),
|
|
32
|
+
required: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "output-json",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: I18n.formatMessage("node.cli.commands.tenant-token.params.output-json.description"),
|
|
38
|
+
required: false
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
action: async (engineCore, envVars, params) => tenantToken(engineCore, envVars, params)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Command for generating the x-enc-tenant-token token value for a tenant.
|
|
46
|
+
* @param engineCore The engine core.
|
|
47
|
+
* @param envVars The environment variables for the node.
|
|
48
|
+
* @param params The parameters for the command.
|
|
49
|
+
* @param params.tenantId The tenant ID to generate the token for.
|
|
50
|
+
* @param params.apiKey The API key to look up the tenant ID from.
|
|
51
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
52
|
+
* @returns The tenant ID and generated encrypted token.
|
|
53
|
+
*/
|
|
54
|
+
export async function tenantToken(engineCore, envVars, params) {
|
|
55
|
+
if (!Is.stringValue(params.tenantId) && !Is.stringValue(params.apiKey)) {
|
|
56
|
+
throw new GeneralError("tenantToken", "tenantIdOrApiKeyRequired");
|
|
57
|
+
}
|
|
58
|
+
if (Is.stringValue(params.tenantId)) {
|
|
59
|
+
Guards.stringHexLength("tenantToken", "tenant-id", params.tenantId, 32);
|
|
60
|
+
}
|
|
61
|
+
if (Is.stringValue(params.apiKey)) {
|
|
62
|
+
Guards.stringHexLength("tenantToken", "api-key", params.apiKey, 32);
|
|
63
|
+
}
|
|
64
|
+
const urlTransformerComponentType = engineCore.getRegisteredInstanceTypeOptional("urlTransformerComponent");
|
|
65
|
+
if (!Is.stringValue(urlTransformerComponentType)) {
|
|
66
|
+
throw new GeneralError("tenantToken", "urlTransformerComponentNotRegistered");
|
|
67
|
+
}
|
|
68
|
+
const urlTransformer = ComponentFactory.get(urlTransformerComponentType);
|
|
69
|
+
// CLI commands skip component starts (engineCore.start(true)), so the URL transformer
|
|
70
|
+
// service's _nodeId is never initialized. Starting it here within the ContextIdStore
|
|
71
|
+
// context (set by executeCommand) lets it pick up the nodeId correctly.
|
|
72
|
+
await urlTransformer.start?.();
|
|
73
|
+
let tenantId = params.tenantId;
|
|
74
|
+
if (!Is.stringValue(tenantId)) {
|
|
75
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
76
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
77
|
+
throw new GeneralError("tenantToken", "tenantAdminComponentNotRegistered");
|
|
78
|
+
}
|
|
79
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
80
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-token.labels.lookingUp"));
|
|
81
|
+
const tenant = await tenantAdminService.getByApiKey(params.apiKey);
|
|
82
|
+
tenantId = tenant.id;
|
|
83
|
+
}
|
|
84
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-token.labels.generating"));
|
|
85
|
+
const token = await urlTransformer.encryptParam(tenantId);
|
|
86
|
+
CLIDisplay.break();
|
|
87
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-token.labels.tenantId"), tenantId);
|
|
88
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-token.labels.token"), token);
|
|
89
|
+
CLIDisplay.break();
|
|
90
|
+
const json = { tenantId, token };
|
|
91
|
+
if (Is.stringValue(params.outputJson)) {
|
|
92
|
+
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
93
|
+
}
|
|
94
|
+
CLIDisplay.done();
|
|
95
|
+
return json;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=tenantToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantToken.js","sourceRoot":"","sources":["../../../src/commands/tenantToken.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAKlF,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC;;;GAGG;AACH,MAAM,UAAU,+BAA+B,CAAC,kBAE/C;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;QAC7E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,wCAAwC,CAAC;QACrE,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,6DAA6D,CAC7D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,SAAS;gBACd,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,2DAA2D,CAC3D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,4DAA4D,CAC5D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,aAAa;gBAClB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,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AAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9D,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, IUrlTransformerComponent } from \"@twin.org/api-models\";\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-token\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantToken(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-token.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-token.example\"),\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-token.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-token.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: \"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-token.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-token.params.output-json.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) => tenantToken(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for generating the x-enc-tenant-token token value for 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.tenantId The tenant ID to generate the token for.\n * @param params.apiKey The API key to look up the tenant ID from.\n * @param params.outputJson The output .json file to store the command output.\n * @returns The tenant ID and generated encrypted token.\n */\nexport async function tenantToken(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t\tapiKey?: string;\n\t\toutputJson?: string;\n\t}\n): Promise<{ tenantId: string; token: string }> {\n\tif (!Is.stringValue(params.tenantId) && !Is.stringValue(params.apiKey)) {\n\t\tthrow new GeneralError(\"tenantToken\", \"tenantIdOrApiKeyRequired\");\n\t}\n\n\tif (Is.stringValue(params.tenantId)) {\n\t\tGuards.stringHexLength(\"tenantToken\", \"tenant-id\", params.tenantId, 32);\n\t}\n\n\tif (Is.stringValue(params.apiKey)) {\n\t\tGuards.stringHexLength(\"tenantToken\", \"api-key\", params.apiKey, 32);\n\t}\n\n\tconst urlTransformerComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"urlTransformerComponent\");\n\n\tif (!Is.stringValue(urlTransformerComponentType)) {\n\t\tthrow new GeneralError(\"tenantToken\", \"urlTransformerComponentNotRegistered\");\n\t}\n\n\tconst urlTransformer = ComponentFactory.get<IUrlTransformerComponent>(\n\t\turlTransformerComponentType\n\t);\n\n\t// CLI commands skip component starts (engineCore.start(true)), so the URL transformer\n\t// service's _nodeId is never initialized. Starting it here within the ContextIdStore\n\t// context (set by executeCommand) lets it pick up the nodeId correctly.\n\tawait urlTransformer.start?.();\n\n\tlet tenantId = params.tenantId;\n\n\tif (!Is.stringValue(tenantId)) {\n\t\tconst tenantAdminServiceComponentType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\t\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\t\tthrow new GeneralError(\"tenantToken\", \"tenantAdminComponentNotRegistered\");\n\t\t}\n\n\t\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\t\ttenantAdminServiceComponentType\n\t\t);\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-token.labels.lookingUp\"));\n\n\t\tconst tenant = await tenantAdminService.getByApiKey(params.apiKey as string);\n\t\ttenantId = tenant.id;\n\t}\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-token.labels.generating\"));\n\n\tconst token = await urlTransformer.encryptParam(tenantId);\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-token.labels.tenantId\"), tenantId);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-token.labels.token\"), token);\n\tCLIDisplay.break();\n\n\tconst json = { tenantId, token };\n\tif (Is.stringValue(params.outputJson)) {\n\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, 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
|
+
params: [
|
|
14
|
+
{
|
|
15
|
+
key: "env-prefix",
|
|
16
|
+
type: "string",
|
|
17
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.env-prefix.description"),
|
|
18
|
+
required: false
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "tenant-id",
|
|
22
|
+
type: "string",
|
|
23
|
+
extendedType: "hex(32)",
|
|
24
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.tenant-id.description"),
|
|
25
|
+
required: true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "api-key",
|
|
29
|
+
type: "string",
|
|
30
|
+
extendedType: "hex(32)",
|
|
31
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.api-key.description"),
|
|
32
|
+
required: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "label",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.label.description"),
|
|
38
|
+
required: false
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "public-origin",
|
|
42
|
+
type: "string",
|
|
43
|
+
extendedType: "url",
|
|
44
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.public-origin.description"),
|
|
45
|
+
required: false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "load-env",
|
|
49
|
+
type: "string",
|
|
50
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.load-env.description"),
|
|
51
|
+
required: false
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
action: async (engineCore, envVars, params) => tenantUpdate(engineCore, envVars, params)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Command for updating a tenant.
|
|
59
|
+
* @param engineCore The engine core.
|
|
60
|
+
* @param envVars The environment variables for the node.
|
|
61
|
+
* @param params The parameters for the command.
|
|
62
|
+
* @param params.apiKey The api key to update.
|
|
63
|
+
* @param params.tenantId The tenant ID to update the api key to.
|
|
64
|
+
* @param params.label The label for the api key.
|
|
65
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
66
|
+
*/
|
|
67
|
+
export async function tenantUpdate(engineCore, envVars, params) {
|
|
68
|
+
Guards.stringHexLength("tenantUpdate", "tenant-id", params.tenantId, 32);
|
|
69
|
+
if (Is.stringValue(params.apiKey)) {
|
|
70
|
+
Guards.stringHexLength("tenantUpdate", "api-key", params.apiKey, 32);
|
|
71
|
+
}
|
|
72
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
73
|
+
Url.guard("tenantUpdate", "public-origin", params.publicOrigin);
|
|
74
|
+
}
|
|
75
|
+
const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceType("tenantAdminComponent");
|
|
76
|
+
if (!Is.stringValue(defaultTenantAdminComponentType)) {
|
|
77
|
+
throw new GeneralError("tenantUpdate", "tenantAdminComponentNotRegistered");
|
|
78
|
+
}
|
|
79
|
+
const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
|
|
80
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updating"));
|
|
81
|
+
CLIDisplay.spinnerStart();
|
|
82
|
+
await tenantAdminComponent.update({
|
|
83
|
+
id: params.tenantId,
|
|
84
|
+
apiKey: params.apiKey,
|
|
85
|
+
label: params.label,
|
|
86
|
+
publicOrigin: params.publicOrigin
|
|
87
|
+
});
|
|
88
|
+
CLIDisplay.spinnerStop();
|
|
89
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updated"));
|
|
90
|
+
CLIDisplay.break();
|
|
91
|
+
CLIDisplay.done();
|
|
92
|
+
}
|
|
93
|
+
//# 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,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,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,+DAA+D,CAC/D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;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,KAAK;aACf;YACD;gBACC,GAAG,EAAE,OAAO;gBACZ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,C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EAAE,mCAAmC,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,GAAG,CAChD,+BAA+B,CAC/B,CAAC;IAEF,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC,CAAC;IACvF,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,oBAAoB,CAAC,MAAM,CAAC;QACjC,EAAE,EAAE,MAAM,CAAC,QAAQ;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,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 { 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-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\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.tenant-update.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: \"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\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-update.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tawait tenantAdminComponent.update({\n\t\tid: params.tenantId,\n\t\tapiKey: params.apiKey,\n\t\tlabel: params.label,\n\t\tpublicOrigin: params.publicOrigin\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"]}
|