@twin.org/node-core 0.0.3-next.53 → 0.0.3-next.55
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 +52 -10
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +32 -32
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/extensionsBuilder.js +3 -3
- package/dist/es/builders/extensionsBuilder.js.map +1 -1
- package/dist/es/cli.js +6 -3
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/bootstrapLegacy.js +173 -116
- package/dist/es/commands/bootstrapLegacy.js.map +1 -1
- package/dist/es/commands/help.js +1 -0
- package/dist/es/commands/help.js.map +1 -1
- package/dist/es/commands/identityCreate.js +38 -16
- package/dist/es/commands/identityCreate.js.map +1 -1
- package/dist/es/commands/identityImports.js +1 -0
- package/dist/es/commands/identityImports.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodCreate.js +13 -11
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodImport.js +2 -1
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -1
- package/dist/es/commands/nodeSetIdentity.js +5 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -1
- package/dist/es/commands/removeTenantOrgAlias.js +3 -1
- package/dist/es/commands/removeTenantOrgAlias.js.map +1 -1
- package/dist/es/commands/setNodeOrgId.js +2 -0
- package/dist/es/commands/setNodeOrgId.js.map +1 -1
- package/dist/es/commands/setTenantOrgId.js +7 -66
- package/dist/es/commands/setTenantOrgId.js.map +1 -1
- package/dist/es/commands/tenantCreate.js +1 -7
- package/dist/es/commands/tenantCreate.js.map +1 -1
- package/dist/es/commands/tenantImport.js +17 -4
- package/dist/es/commands/tenantImport.js.map +1 -1
- package/dist/es/commands/tenantUpdate.js +21 -6
- package/dist/es/commands/tenantUpdate.js.map +1 -1
- package/dist/es/commands/vaultKeyImport.js +4 -3
- package/dist/es/commands/vaultKeyImport.js.map +1 -1
- package/dist/es/defaults.js +21 -0
- package/dist/es/defaults.js.map +1 -1
- package/dist/es/models/ICliArgs.js.map +1 -1
- package/dist/es/models/ICliCommand.js.map +1 -1
- package/dist/es/models/ICliCommandDefinition.js.map +1 -1
- package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -1
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
- package/dist/es/models/nodeExtensionInitialiseEngineMethod.js.map +1 -1
- package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js.map +1 -1
- package/dist/es/models/nodeExtensionInitialiseMethod.js.map +1 -1
- package/dist/es/models/nodeExtensionShutdownMethod.js.map +1 -1
- package/dist/es/node.js +1 -1
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +11 -13
- package/dist/es/start.js.map +1 -1
- package/dist/es/utils.js +5 -4
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +4 -4
- package/dist/types/builders/extensionsBuilder.d.ts +3 -3
- package/dist/types/cli.d.ts +2 -2
- package/dist/types/commands/bootstrapLegacy.d.ts +8 -7
- package/dist/types/commands/help.d.ts +1 -0
- package/dist/types/commands/identityCreate.d.ts +2 -0
- package/dist/types/commands/identityImports.d.ts +1 -0
- package/dist/types/commands/identityVerificationMethodImport.d.ts +2 -1
- package/dist/types/commands/nodeSetIdentity.d.ts +1 -0
- package/dist/types/commands/removeTenantOrgAlias.d.ts +2 -0
- package/dist/types/commands/setNodeOrgId.d.ts +2 -0
- package/dist/types/commands/setTenantOrgId.d.ts +5 -22
- package/dist/types/commands/tenantImport.d.ts +7 -4
- package/dist/types/commands/tenantUpdate.d.ts +5 -2
- package/dist/types/commands/vaultKeyImport.d.ts +4 -3
- package/dist/types/defaults.d.ts +21 -0
- package/dist/types/models/ICliArgs.d.ts +1 -1
- package/dist/types/models/ICliCommand.d.ts +1 -1
- package/dist/types/models/ICliCommandDefinition.d.ts +2 -2
- package/dist/types/models/ICliCommandDefinitionParam.d.ts +1 -1
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +0 -4
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
- package/dist/types/models/nodeExtensionInitialiseEngineMethod.d.ts +1 -0
- package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +1 -0
- package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +1 -0
- package/dist/types/models/nodeExtensionShutdownMethod.d.ts +1 -0
- package/dist/types/utils.d.ts +4 -3
- package/docs/changelog.md +15 -0
- package/docs/reference/functions/extensionsInitialiseEngine.md +1 -1
- package/docs/reference/functions/extensionsInitialiseEngineServer.md +1 -1
- package/docs/reference/functions/getScriptDirectory.md +1 -1
- package/docs/reference/functions/initialiseLocales.md +2 -0
- package/docs/reference/functions/isFederatedCatalogueRequired.md +3 -3
- package/docs/reference/functions/isRightsManagementRequired.md +1 -1
- package/docs/reference/functions/loadJsonFile.md +1 -1
- package/docs/reference/functions/loadTextFile.md +1 -1
- package/docs/reference/functions/processEnvOptions.md +1 -1
- package/docs/reference/functions/registerCommands.md +1 -1
- package/docs/reference/functions/shutdownExtensions.md +1 -1
- package/docs/reference/interfaces/ICliArgs.md +1 -1
- package/docs/reference/interfaces/ICliCommand.md +1 -1
- package/docs/reference/interfaces/ICliCommandDefinition.md +2 -2
- package/docs/reference/interfaces/ICliCommandDefinitionParam.md +1 -1
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +0 -8
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +8 -12
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +12 -12
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +2 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +2 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +2 -0
- package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +2 -0
- package/docs/reference/variables/ATTESTATION_VERIFICATION_METHOD_ID.md +2 -0
- package/docs/reference/variables/AUTH_SIGNING_KEY_ID.md +2 -0
- package/docs/reference/variables/BLOB_STORAGE_ENCRYPTION_KEY_ID.md +2 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +2 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +2 -0
- package/docs/reference/variables/IMMUTABLE_PROOF_VERIFICATION_METHOD_ID.md +2 -0
- package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +2 -0
- package/locales/en.json +17 -9
- package/package.json +1 -1
|
@@ -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,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,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,mEAAmE,CACnE;gBACD,QA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,CAAC;IAEpC,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC,CAAC;QAC3F,OAAO;IACR,CAAC;IAED,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\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.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 * @returns A promise that resolves when the node identity has been persisted.\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\n\tif (state.nodeId === params.identity) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-identity.labels.skipping\"));\n\t\treturn;\n\t}\n\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"]}
|
|
@@ -51,6 +51,8 @@ export function getCommandDefinitionRemoveTenantOrgAlias(commandDefinitions) {
|
|
|
51
51
|
* @param params The parameters for the command.
|
|
52
52
|
* @param params.tenantId The tenant ID to update.
|
|
53
53
|
* @param params.alias The alias to remove from the legacy list.
|
|
54
|
+
* @returns A promise that resolves when the alias has been removed.
|
|
55
|
+
* @throws GeneralError if the tenant admin component is not registered, or the alias is not found.
|
|
54
56
|
*/
|
|
55
57
|
export async function removeTenantOrgAlias(engineCore, envVars, params) {
|
|
56
58
|
const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
@@ -71,7 +73,7 @@ export async function removeTenantOrgAlias(engineCore, envVars, params) {
|
|
|
71
73
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.labels.updating"));
|
|
72
74
|
CLIDisplay.spinnerStart();
|
|
73
75
|
await tenantAdminComponent.update({
|
|
74
|
-
|
|
76
|
+
...tenant,
|
|
75
77
|
organizationIdLegacy: legacy
|
|
76
78
|
});
|
|
77
79
|
CLIDisplay.spinnerStop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeTenantOrgAlias.js","sourceRoot":"","sources":["../../../src/commands/removeTenantOrgAlias.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;AAElF,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,wCAAwC,CAAC,kBAExD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,uDAAuD,CAAC;QACxF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,mDAAmD,CAAC;QAChF,oBAAoB,EAAE,KAAK;QAC3B,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,yEAAyE,CACzE;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,wEAAwE,CACxE;gBACD,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,OAAO;gBACZ,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,oEAAoE,CACpE;gBACD,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,uEAAuE,CACvE;gBACD,QAAQ,EAAE,KAAK;aACf;SACD;QACD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,oBAAoB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC;KAChG,CAAC;AACH,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"removeTenantOrgAlias.js","sourceRoot":"","sources":["../../../src/commands/removeTenantOrgAlias.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAA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I,CAAC,IAAI,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAAC,CAAC;IACjG,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,oBAAoB,CAAC,MAAM,CAAC;QACjC,GAAG,MAAM;QACT,oBAAoB,EAAE,MAAM;KAC5B,CAAC,CAAC;IAEH,UAAU,CAAC,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,0DAA0D,CAAC,CAAC,CAAC;IAEhG,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 } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"remove-tenant-org-alias\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionRemoveTenantOrgAlias(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.remove-tenant-org-alias.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.remove-tenant-org-alias.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.remove-tenant-org-alias.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.remove-tenant-org-alias.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: \"alias\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.remove-tenant-org-alias.params.alias.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.remove-tenant-org-alias.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) => removeTenantOrgAlias(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for removing an alias from the tenant organization ID legacy list.\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 update.\n * @param params.alias The alias to remove from the legacy list.\n * @returns A promise that resolves when the alias has been removed.\n * @throws GeneralError if the tenant admin component is not registered, or the alias is not found.\n */\nexport async function removeTenantOrgAlias(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t\talias?: string;\n\t}\n): Promise<void> {\n\tconst defaultTenantAdminComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(defaultTenantAdminComponentType)) {\n\t\tthrow new GeneralError(\"removeTenantOrgAlias\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tGuards.stringHexLength(\"removeTenantOrgAlias\", \"tenant-id\", params.tenantId, 32);\n\n\tDid.guard(\"removeTenantOrgAlias\", \"alias\", params.alias);\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(\n\t\tdefaultTenantAdminComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.remove-tenant-org-alias.labels.reading\"));\n\n\tconst tenant = await tenantAdminComponent.get(params.tenantId);\n\tconst legacy = [...(tenant.organizationIdLegacy ?? [])];\n\tconst index = legacy.indexOf(params.alias);\n\n\tif (index < 0) {\n\t\tthrow new GeneralError(\"removeTenantOrgAlias\", \"aliasNotFound\", { alias: params.alias });\n\t}\n\n\tlegacy.splice(index, 1);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.remove-tenant-org-alias.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tawait tenantAdminComponent.update({\n\t\t...tenant,\n\t\torganizationIdLegacy: legacy\n\t});\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.remove-tenant-org-alias.labels.removed\"));\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -45,6 +45,8 @@ export function getCommandDefinitionSetNodeOrgId(commandDefinitions) {
|
|
|
45
45
|
* @param envVars The environment variables for the node.
|
|
46
46
|
* @param params The parameters for the command.
|
|
47
47
|
* @param params.organizationId The organization ID to set.
|
|
48
|
+
* @returns A promise that resolves when the node organization ID has been persisted.
|
|
49
|
+
* @throws GeneralError if called while multi-tenant mode is enabled.
|
|
48
50
|
*/
|
|
49
51
|
export async function setNodeOrgId(engineCore, envVars, params) {
|
|
50
52
|
if (Coerce.boolean(envVars.tenantEnabled) ?? false) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setNodeOrgId.js","sourceRoot":"","sources":["../../../src/commands/setNodeOrgId.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,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,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,CAAC;QACpD,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,+BAA+B,CAAC,CAAC;IACzE,CAAC;IAED,GAAG,CAAC,KAAK,CAAC,cAAc,EAAE,gBAAgB,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;IAEnE,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,KAAK,CAAC,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC;IACjD,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAEvF,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 { Coerce, GeneralError, I18n } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } 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 = \"set-node-org-id\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionSetNodeOrgId(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.set-node-org-id.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.set-node-org-id.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.set-node-org-id.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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.set-node-org-id.params.organization-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.set-node-org-id.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) => setNodeOrgId(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting the node organization ID.\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.organizationId The organization ID to set.\n * @returns A promise that resolves when the node organization ID has been persisted.\n * @throws GeneralError if called while multi-tenant mode is enabled.\n */\nexport async function setNodeOrgId(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\torganizationId?: string;\n\t}\n): Promise<void> {\n\tif (Coerce.boolean(envVars.tenantEnabled) ?? false) {\n\t\tthrow new GeneralError(\"setNodeOrgId\", \"notAvailableInMultiTenantMode\");\n\t}\n\n\tDid.guard(\"setNodeOrgId\", \"organizationId\", params.organizationId);\n\n\tconst state = engineCore.getState();\n\tstate.nodeOrganizationId = params.organizationId;\n\tengineCore.setStateDirty();\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.set-node-org-id.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
2
|
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
-
import { ComparisonOperator, LogicalOperator } from "@twin.org/entity";
|
|
4
3
|
import { Did } from "@twin.org/identity-models";
|
|
5
4
|
const COMMAND_NAME = "set-tenant-org-id";
|
|
6
5
|
/**
|
|
@@ -52,6 +51,7 @@ export function getCommandDefinitionSetTenantOrgId(commandDefinitions) {
|
|
|
52
51
|
* @param params The parameters for the command.
|
|
53
52
|
* @param params.tenantId The tenant ID to update.
|
|
54
53
|
* @param params.organizationId The organization ID to set.
|
|
54
|
+
* @returns A promise that resolves when the tenant organization ID has been stored.
|
|
55
55
|
*/
|
|
56
56
|
export async function setTenantOrgId(engineCore, envVars, params) {
|
|
57
57
|
Guards.stringHexLength("setTenantOrgId", "tenant-id", params.tenantId, 32);
|
|
@@ -64,50 +64,15 @@ export async function setTenantOrgId(engineCore, envVars, params) {
|
|
|
64
64
|
CLIDisplay.done();
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
* @param tenantAdminComponent The tenant admin component to query.
|
|
69
|
-
* @param newOrganizationId The organization DID to check.
|
|
70
|
-
* @param excludeTenantId When set, the tenant with this ID is excluded from the check (used when updating an existing tenant).
|
|
71
|
-
*/
|
|
72
|
-
export async function assertOrganizationIdUnique(tenantAdminComponent, newOrganizationId, excludeTenantId) {
|
|
73
|
-
const condition = excludeTenantId !== undefined
|
|
74
|
-
? {
|
|
75
|
-
conditions: [
|
|
76
|
-
{
|
|
77
|
-
property: "organizationId",
|
|
78
|
-
value: newOrganizationId,
|
|
79
|
-
comparison: ComparisonOperator.Equals
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
property: "id",
|
|
83
|
-
value: excludeTenantId,
|
|
84
|
-
comparison: ComparisonOperator.NotEquals
|
|
85
|
-
}
|
|
86
|
-
],
|
|
87
|
-
logicalOperator: LogicalOperator.And
|
|
88
|
-
}
|
|
89
|
-
: {
|
|
90
|
-
property: "organizationId",
|
|
91
|
-
value: newOrganizationId,
|
|
92
|
-
comparison: ComparisonOperator.Equals
|
|
93
|
-
};
|
|
94
|
-
const { tenants: conflicts } = await tenantAdminComponent.query(condition, ["id"], undefined, 1);
|
|
95
|
-
if (conflicts.length > 0) {
|
|
96
|
-
throw new GeneralError("applyOrganizationIdToTenant", "organizationIdAlreadyInUse", {
|
|
97
|
-
organizationId: newOrganizationId,
|
|
98
|
-
conflictingTenantId: conflicts[0].id
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Look up the tenant admin component, apply a new organization ID (moving the existing value to the
|
|
104
|
-
* legacy list), and save. Optionally wraps the operation with a CLI section header and done marker.
|
|
67
|
+
* Apply a new organization ID to a tenant.
|
|
105
68
|
* @param engineCore The engine core used to look up the tenantAdminComponent.
|
|
106
69
|
* @param tenantId The ID of the tenant to update.
|
|
107
70
|
* @param newOrganizationId The new organization DID to set.
|
|
108
71
|
* @param options Optional display and behaviour overrides.
|
|
109
|
-
* @param options.sectionLabel When set, emits
|
|
72
|
+
* @param options.sectionLabel When set, emits a CLI section header before and done marker after.
|
|
110
73
|
* @param options.required When false, returns silently when the component is not registered (default true).
|
|
74
|
+
* @returns A promise that resolves when the tenant record has been updated.
|
|
75
|
+
* @throws GeneralError if the component is required but not registered.
|
|
111
76
|
*/
|
|
112
77
|
export async function applyOrganizationIdToTenant(engineCore, tenantId, newOrganizationId, options) {
|
|
113
78
|
const type = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
@@ -122,37 +87,13 @@ export async function applyOrganizationIdToTenant(engineCore, tenantId, newOrgan
|
|
|
122
87
|
CLIDisplay.section(options.sectionLabel);
|
|
123
88
|
}
|
|
124
89
|
const tenantAdminComponent = ComponentFactory.get(type);
|
|
125
|
-
await assertOrganizationIdUnique(tenantAdminComponent, newOrganizationId, tenantId);
|
|
126
90
|
const tenant = await tenantAdminComponent.get(tenantId);
|
|
127
|
-
const { id, legacy } = updateLegacyOrganizationId(tenant.organizationId, tenant.organizationIdLegacy, newOrganizationId);
|
|
128
91
|
await tenantAdminComponent.update({
|
|
129
|
-
|
|
130
|
-
organizationId:
|
|
131
|
-
organizationIdLegacy: legacy
|
|
92
|
+
...tenant,
|
|
93
|
+
organizationId: newOrganizationId
|
|
132
94
|
});
|
|
133
95
|
if (Is.stringValue(options?.sectionLabel)) {
|
|
134
96
|
CLIDisplay.done();
|
|
135
97
|
}
|
|
136
98
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Update an organization ID, moving the current value to the legacy list.
|
|
139
|
-
* @param currentId The current organization ID.
|
|
140
|
-
* @param legacyIds The current list of legacy organization IDs.
|
|
141
|
-
* @param newId The new organization ID to set.
|
|
142
|
-
* @returns The updated id and legacy list.
|
|
143
|
-
*/
|
|
144
|
-
export function updateLegacyOrganizationId(currentId, legacyIds, newId) {
|
|
145
|
-
const legacy = [...(legacyIds ?? [])];
|
|
146
|
-
if (Is.stringValue(currentId) && currentId !== newId && !legacy.includes(currentId)) {
|
|
147
|
-
legacy.push(currentId);
|
|
148
|
-
}
|
|
149
|
-
const newIdIndex = legacy.indexOf(newId);
|
|
150
|
-
if (newIdIndex >= 0) {
|
|
151
|
-
legacy.splice(newIdIndex, 1);
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
id: newId,
|
|
155
|
-
legacy
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
99
|
//# sourceMappingURL=setTenantOrgId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setTenantOrgId.js","sourceRoot":"","sources":["../../../src/commands/setTenantOrgId.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,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AM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,0BAA0B,CAChD,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,oBAAoB,EAC3B,iBAAiB,CACjB,CAAC;IACF,MAAM,oBAAoB,CAAC,MAAM,CAAC;QACjC,EAAE,EAAE,QAAQ;QACZ,cAAc,EAAE,EAAE;QAClB,oBAAoB,EAAE,MAAM;KAC5B,CAAC,CAAC;IAEH,IAAI,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC;QAC3C,UAAU,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;AACF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACzC,SAA6B,EAC7B,SAA+B,EAC/B,KAAa;IAEb,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;IAEtC,IAAI,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACrF,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,IAAI,UAAU,IAAI,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO;QACN,EAAE,EAAE,KAAK;QACT,MAAM;KACN,CAAC;AACH,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 } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { ComparisonOperator, LogicalOperator } from \"@twin.org/entity\";\nimport { Did } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"set-tenant-org-id\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionSetTenantOrgId(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.set-tenant-org-id.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.set-tenant-org-id.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.set-tenant-org-id.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.set-tenant-org-id.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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.set-tenant-org-id.params.organization-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.set-tenant-org-id.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) => setTenantOrgId(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting the organization ID on 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 update.\n * @param params.organizationId The organization ID to set.\n */\nexport async function setTenantOrgId(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t\torganizationId?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"setTenantOrgId\", \"tenant-id\", params.tenantId, 32);\n\n\tDid.guard(\"setTenantOrgId\", \"organizationId\", params.organizationId);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.set-tenant-org-id.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tawait applyOrganizationIdToTenant(engineCore, params.tenantId, params.organizationId);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.set-tenant-org-id.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n\n/**\n * Assert that no other tenant already holds the given organization ID.\n * @param tenantAdminComponent The tenant admin component to query.\n * @param newOrganizationId The organization DID to check.\n * @param excludeTenantId When set, the tenant with this ID is excluded from the check (used when updating an existing tenant).\n */\nexport async function assertOrganizationIdUnique(\n\ttenantAdminComponent: ITenantAdminComponent,\n\tnewOrganizationId: string,\n\texcludeTenantId?: string\n): Promise<void> {\n\tconst condition =\n\t\texcludeTenantId !== undefined\n\t\t\t? {\n\t\t\t\t\tconditions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tproperty: \"organizationId\",\n\t\t\t\t\t\t\tvalue: newOrganizationId,\n\t\t\t\t\t\t\tcomparison: ComparisonOperator.Equals\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tproperty: \"id\",\n\t\t\t\t\t\t\tvalue: excludeTenantId,\n\t\t\t\t\t\t\tcomparison: ComparisonOperator.NotEquals\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\tlogicalOperator: LogicalOperator.And\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tproperty: \"organizationId\",\n\t\t\t\t\tvalue: newOrganizationId,\n\t\t\t\t\tcomparison: ComparisonOperator.Equals\n\t\t\t\t};\n\n\tconst { tenants: conflicts } = await tenantAdminComponent.query(condition, [\"id\"], undefined, 1);\n\n\tif (conflicts.length > 0) {\n\t\tthrow new GeneralError(\"applyOrganizationIdToTenant\", \"organizationIdAlreadyInUse\", {\n\t\t\torganizationId: newOrganizationId,\n\t\t\tconflictingTenantId: conflicts[0].id\n\t\t});\n\t}\n}\n\n/**\n * Look up the tenant admin component, apply a new organization ID (moving the existing value to the\n * legacy list), and save. Optionally wraps the operation with a CLI section header and done marker.\n * @param engineCore The engine core used to look up the tenantAdminComponent.\n * @param tenantId The ID of the tenant to update.\n * @param newOrganizationId The new organization DID to set.\n * @param options Optional display and behaviour overrides.\n * @param options.sectionLabel When set, emits CLIDisplay.break+section before and CLIDisplay.done after.\n * @param options.required When false, returns silently when the component is not registered (default true).\n */\nexport async function applyOrganizationIdToTenant(\n\tengineCore: IEngineCore,\n\ttenantId: string,\n\tnewOrganizationId: string,\n\toptions?: { sectionLabel?: string; required?: boolean }\n): Promise<void> {\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(type)) {\n\t\tif (options?.required ?? true) {\n\t\t\tthrow new GeneralError(\"applyOrganizationIdToTenant\", \"tenantAdminComponentNotRegistered\");\n\t\t}\n\t\treturn;\n\t}\n\n\tif (Is.stringValue(options?.sectionLabel)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(options.sectionLabel);\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\n\tawait assertOrganizationIdUnique(tenantAdminComponent, newOrganizationId, tenantId);\n\n\tconst tenant = await tenantAdminComponent.get(tenantId);\n\tconst { id, legacy } = updateLegacyOrganizationId(\n\t\ttenant.organizationId,\n\t\ttenant.organizationIdLegacy,\n\t\tnewOrganizationId\n\t);\n\tawait tenantAdminComponent.update({\n\t\tid: tenantId,\n\t\torganizationId: id,\n\t\torganizationIdLegacy: legacy\n\t});\n\n\tif (Is.stringValue(options?.sectionLabel)) {\n\t\tCLIDisplay.done();\n\t}\n}\n\n/**\n * Update an organization ID, moving the current value to the legacy list.\n * @param currentId The current organization ID.\n * @param legacyIds The current list of legacy organization IDs.\n * @param newId The new organization ID to set.\n * @returns The updated id and legacy list.\n */\nexport function updateLegacyOrganizationId(\n\tcurrentId: string | undefined,\n\tlegacyIds: string[] | undefined,\n\tnewId: string\n): { id: string; legacy: string[] } {\n\tconst legacy = [...(legacyIds ?? [])];\n\n\tif (Is.stringValue(currentId) && currentId !== newId && !legacy.includes(currentId)) {\n\t\tlegacy.push(currentId);\n\t}\n\n\tconst newIdIndex = legacy.indexOf(newId);\n\tif (newIdIndex >= 0) {\n\t\tlegacy.splice(newIdIndex, 1);\n\t}\n\n\treturn {\n\t\tid: newId,\n\t\tlegacy\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"setTenantOrgId.js","sourceRoot":"","sources":["../../../src/commands/setTenantOrgId.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;AAElF,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAEzC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,E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,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC;QAC3C,UAAU,CAAC,IAAI,EAAE,CAAC;IACnB,CAAC;AACF,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 } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"set-tenant-org-id\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionSetTenantOrgId(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.set-tenant-org-id.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.set-tenant-org-id.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.set-tenant-org-id.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.set-tenant-org-id.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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.set-tenant-org-id.params.organization-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.set-tenant-org-id.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) => setTenantOrgId(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting the organization ID on 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 update.\n * @param params.organizationId The organization ID to set.\n * @returns A promise that resolves when the tenant organization ID has been stored.\n */\nexport async function setTenantOrgId(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t\torganizationId?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"setTenantOrgId\", \"tenant-id\", params.tenantId, 32);\n\n\tDid.guard(\"setTenantOrgId\", \"organizationId\", params.organizationId);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.set-tenant-org-id.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tawait applyOrganizationIdToTenant(engineCore, params.tenantId, params.organizationId);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.set-tenant-org-id.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n\n/**\n * Apply a new organization ID to a tenant.\n * @param engineCore The engine core used to look up the tenantAdminComponent.\n * @param tenantId The ID of the tenant to update.\n * @param newOrganizationId The new organization DID to set.\n * @param options Optional display and behaviour overrides.\n * @param options.sectionLabel When set, emits a CLI section header before and done marker after.\n * @param options.required When false, returns silently when the component is not registered (default true).\n * @returns A promise that resolves when the tenant record has been updated.\n * @throws GeneralError if the component is required but not registered.\n */\nexport async function applyOrganizationIdToTenant(\n\tengineCore: IEngineCore,\n\ttenantId: string,\n\tnewOrganizationId: string,\n\toptions?: { sectionLabel?: string; required?: boolean }\n): Promise<void> {\n\tconst type = engineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(type)) {\n\t\tif (options?.required ?? true) {\n\t\t\tthrow new GeneralError(\"applyOrganizationIdToTenant\", \"tenantAdminComponentNotRegistered\");\n\t\t}\n\t\treturn;\n\t}\n\n\tif (Is.stringValue(options?.sectionLabel)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(options.sectionLabel);\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(type);\n\n\tconst tenant = await tenantAdminComponent.get(tenantId);\n\tawait tenantAdminComponent.update({\n\t\t...tenant,\n\t\torganizationId: newOrganizationId\n\t});\n\n\tif (Is.stringValue(options?.sectionLabel)) {\n\t\tCLIDisplay.done();\n\t}\n}\n"]}
|
|
@@ -2,7 +2,6 @@ import { TenantIdHelper } from "@twin.org/api-tenant-processor";
|
|
|
2
2
|
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
3
3
|
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
4
4
|
import { Did } from "@twin.org/identity-models";
|
|
5
|
-
import { assertOrganizationIdUnique } from "./setTenantOrgId.js";
|
|
6
5
|
const COMMAND_NAME = "tenant-create";
|
|
7
6
|
/**
|
|
8
7
|
* Get the command definition parameters.
|
|
@@ -104,9 +103,7 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
104
103
|
if (Is.stringValue(params.apiKey)) {
|
|
105
104
|
Guards.stringHexLength("tenantCreate", "api-key", params.apiKey, 32);
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
Did.guard("tenantCreate", "organization-id", params.organizationId);
|
|
109
|
-
}
|
|
106
|
+
Did.guard("tenantCreate", "organization-id", params.organizationId);
|
|
110
107
|
if (Is.stringValue(params.publicOrigin)) {
|
|
111
108
|
Url.guard("tenantCreate", "public-origin", params.publicOrigin);
|
|
112
109
|
}
|
|
@@ -115,9 +112,6 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
115
112
|
throw new GeneralError("tenantCreate", "tenantAdminComponentNotRegistered");
|
|
116
113
|
}
|
|
117
114
|
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
118
|
-
if (Is.stringValue(params.organizationId)) {
|
|
119
|
-
await assertOrganizationIdUnique(tenantAdminService, params.organizationId);
|
|
120
|
-
}
|
|
121
115
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-create.labels.creating"));
|
|
122
116
|
const apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();
|
|
123
117
|
const tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();
|
|
@@ -1 +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,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;AAEvF,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAIjE,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WA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,WAAW,CAAC,cAAc,CAAC,EAAE,CAAC;YACpC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,MAAM,oBAAoB,cAAc,GAAG,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChE,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 { Did } from \"@twin.org/identity-models\";\nimport { assertOrganizationIdUnique } from \"./setTenantOrgId.js\";\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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.organization-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: \"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.organizationId The organization DID to associate with the tenant.\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\torganizationId?: 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<{\n\tapiKey: string;\n\ttenantId: string;\n\torganizationId?: string;\n\tlabel: string;\n\tpublicOrigin: string;\n}> {\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.organizationId)) {\n\t\tDid.guard(\"tenantCreate\", \"organization-id\", params.organizationId);\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\tif (Is.stringValue(params.organizationId)) {\n\t\tawait assertOrganizationIdUnique(tenantAdminService, params.organizationId);\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 organizationId = params.organizationId;\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminService.create({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\torganizationId,\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\tif (Is.stringValue(organizationId)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-create.labels.organizationId\"),\n\t\t\torganizationId\n\t\t);\n\t}\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: {\n\t\tapiKey: string;\n\t\ttenantId: string;\n\t\torganizationId?: string;\n\t\tlabel: string;\n\t\tpublicOrigin: string;\n\t} = {\n\t\tapiKey,\n\t\ttenantId,\n\t\tlabel,\n\t\tpublicOrigin\n\t};\n\tif (Is.stringValue(organizationId)) {\n\t\tjson.organizationId = organizationId;\n\t}\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\tconst prefix = params.outputEnvPrefix ?? \"\";\n\t\tconst envLines = [\n\t\t\t`${prefix}API_KEY=\"${apiKey}\"`,\n\t\t\t`${prefix}TENANT_ID=\"${tenantId}\"`,\n\t\t\t`${prefix}LABEL=\"${label}\"`,\n\t\t\t`${prefix}PUBLIC_ORIGIN=\"${publicOrigin}\"`\n\t\t];\n\t\tif (Is.stringValue(organizationId)) {\n\t\t\tenvLines.splice(2, 0, `${prefix}ORGANIZATION_ID=\"${organizationId}\"`);\n\t\t}\n\t\tawait CLIUtils.writeEnvFile(params.outputEnv, envLines, false);\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;AAEvF,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,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E,CAAC;QACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChE,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 { Did } from \"@twin.org/identity-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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.organization-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: \"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.organizationId The organization DID to associate with the tenant.\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\torganizationId?: 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<{\n\tapiKey: string;\n\ttenantId: string;\n\torganizationId?: string;\n\tlabel: string;\n\tpublicOrigin: string;\n}> {\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\tDid.guard(\"tenantCreate\", \"organization-id\", params.organizationId);\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 organizationId = params.organizationId;\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminService.create({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\torganizationId,\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\tif (Is.stringValue(organizationId)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.tenant-create.labels.organizationId\"),\n\t\t\torganizationId\n\t\t);\n\t}\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: {\n\t\tapiKey: string;\n\t\ttenantId: string;\n\t\torganizationId?: string;\n\t\tlabel: string;\n\t\tpublicOrigin: string;\n\t} = {\n\t\tapiKey,\n\t\ttenantId,\n\t\tlabel,\n\t\tpublicOrigin\n\t};\n\tif (Is.stringValue(organizationId)) {\n\t\tjson.organizationId = organizationId;\n\t}\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\tconst prefix = params.outputEnvPrefix ?? \"\";\n\t\tconst envLines = [\n\t\t\t`${prefix}API_KEY=\"${apiKey}\"`,\n\t\t\t`${prefix}TENANT_ID=\"${tenantId}\"`,\n\t\t\t`${prefix}LABEL=\"${label}\"`,\n\t\t\t`${prefix}PUBLIC_ORIGIN=\"${publicOrigin}\"`\n\t\t];\n\t\tif (Is.stringValue(organizationId)) {\n\t\t\tenvLines.splice(2, 0, `${prefix}ORGANIZATION_ID=\"${organizationId}\"`);\n\t\t}\n\t\tawait CLIUtils.writeEnvFile(params.outputEnv, envLines, false);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
2
|
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
3
|
+
import { Did } from "@twin.org/identity-models";
|
|
3
4
|
const COMMAND_NAME = "tenant-import";
|
|
4
5
|
/**
|
|
5
6
|
* Get the command definition parameters.
|
|
@@ -31,6 +32,13 @@ export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
|
31
32
|
description: I18n.formatMessage("node.cli.commands.tenant-import.params.api-key.description"),
|
|
32
33
|
required: true
|
|
33
34
|
},
|
|
35
|
+
{
|
|
36
|
+
key: "organization-id",
|
|
37
|
+
type: "string",
|
|
38
|
+
extendedType: "did",
|
|
39
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.organization-id.description"),
|
|
40
|
+
required: true
|
|
41
|
+
},
|
|
34
42
|
{
|
|
35
43
|
key: "label",
|
|
36
44
|
type: "string",
|
|
@@ -55,18 +63,21 @@ export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
|
55
63
|
};
|
|
56
64
|
}
|
|
57
65
|
/**
|
|
58
|
-
* Command for importing a tenant.
|
|
66
|
+
* Command for importing a tenant with a known tenant ID and API key.
|
|
59
67
|
* @param engineCore The engine core.
|
|
60
68
|
* @param envVars The environment variables for the node.
|
|
61
69
|
* @param params The parameters for the command.
|
|
62
|
-
* @param params.apiKey The
|
|
63
|
-
* @param params.tenantId The tenant ID to import
|
|
64
|
-
* @param params.
|
|
70
|
+
* @param params.apiKey The API key to import.
|
|
71
|
+
* @param params.tenantId The tenant ID to import.
|
|
72
|
+
* @param params.organizationId The organization DID to associate with the tenant.
|
|
73
|
+
* @param params.label The label for the tenant.
|
|
65
74
|
* @param params.publicOrigin The public URL origin for the tenant.
|
|
75
|
+
* @returns A promise that resolves when the tenant record has been created.
|
|
66
76
|
*/
|
|
67
77
|
export async function tenantImport(engineCore, envVars, params) {
|
|
68
78
|
Guards.stringHexLength("tenantImport", "tenant-id", params.tenantId, 32);
|
|
69
79
|
Guards.stringHexLength("tenantImport", "api-key", params.apiKey, 32);
|
|
80
|
+
Did.guard("tenantImport", "organization-id", params.organizationId);
|
|
70
81
|
if (Is.stringValue(params.publicOrigin)) {
|
|
71
82
|
Url.guard("tenantImport", "public-origin", params.publicOrigin);
|
|
72
83
|
}
|
|
@@ -79,11 +90,13 @@ export async function tenantImport(engineCore, envVars, params) {
|
|
|
79
90
|
CLIDisplay.spinnerStart();
|
|
80
91
|
const apiKey = params.apiKey;
|
|
81
92
|
const tenantId = params.tenantId;
|
|
93
|
+
const organizationId = params.organizationId;
|
|
82
94
|
const label = params.label ?? "";
|
|
83
95
|
const publicOrigin = params.publicOrigin ?? "";
|
|
84
96
|
await tenantAdminService.create({
|
|
85
97
|
id: tenantId,
|
|
86
98
|
apiKey,
|
|
99
|
+
organizationId,
|
|
87
100
|
label,
|
|
88
101
|
publicOrigin
|
|
89
102
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenantImport.js","sourceRoot":"","sources":["../../../src/commands/tenantImport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UA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CAAC,cAAc,EAAE,eAAe,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,+BAA+B,GACpC,UAAU,CAAC,iCAAiC,CAAC,sBAAsB,CAAC,CAAC;IAEtE,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,+BAA+B,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,mCAAmC,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,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IACjC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;IAC/C,MAAM,kBAAkB,CAAC,MAAM,CAAC;QAC/B,EAAE,EAAE,QAAQ;QACZ,MAAM;QACN,cAAc;QACd,KAAK;QACL,YAAY;KACZ,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 { Did } from \"@twin.org/identity-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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.organization-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: \"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 with a known tenant ID and API key.\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.\n * @param params.organizationId The organization DID to associate with the tenant.\n * @param params.label The label for the tenant.\n * @param params.publicOrigin The public URL origin for the tenant.\n * @returns A promise that resolves when the tenant record has been created.\n */\nexport async function tenantImport(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\torganizationId?: 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\tDid.guard(\"tenantImport\", \"organization-id\", params.organizationId);\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 organizationId = params.organizationId;\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminService.create({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\torganizationId,\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"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
2
|
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
3
|
+
import { Did } from "@twin.org/identity-models";
|
|
3
4
|
const COMMAND_NAME = "tenant-update";
|
|
4
5
|
/**
|
|
5
6
|
* Get the command definition parameters.
|
|
@@ -31,6 +32,13 @@ export function getCommandDefinitionTenantUpdate(commandDefinitions) {
|
|
|
31
32
|
description: I18n.formatMessage("node.cli.commands.tenant-update.params.api-key.description"),
|
|
32
33
|
required: false
|
|
33
34
|
},
|
|
35
|
+
{
|
|
36
|
+
key: "organization-id",
|
|
37
|
+
type: "string",
|
|
38
|
+
extendedType: "did",
|
|
39
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.organization-id.description"),
|
|
40
|
+
required: false
|
|
41
|
+
},
|
|
34
42
|
{
|
|
35
43
|
key: "label",
|
|
36
44
|
type: "string",
|
|
@@ -60,15 +68,20 @@ export function getCommandDefinitionTenantUpdate(commandDefinitions) {
|
|
|
60
68
|
* @param envVars The environment variables for the node.
|
|
61
69
|
* @param params The parameters for the command.
|
|
62
70
|
* @param params.apiKey The api key to update.
|
|
63
|
-
* @param params.tenantId The tenant ID to update
|
|
64
|
-
* @param params.
|
|
71
|
+
* @param params.tenantId The tenant ID to update.
|
|
72
|
+
* @param params.organizationId The organization DID to associate with the tenant.
|
|
73
|
+
* @param params.label The label for the tenant.
|
|
65
74
|
* @param params.publicOrigin The public URL origin for the tenant.
|
|
75
|
+
* @returns A promise that resolves when the tenant record has been updated.
|
|
66
76
|
*/
|
|
67
77
|
export async function tenantUpdate(engineCore, envVars, params) {
|
|
68
78
|
Guards.stringHexLength("tenantUpdate", "tenant-id", params.tenantId, 32);
|
|
69
79
|
if (Is.stringValue(params.apiKey)) {
|
|
70
80
|
Guards.stringHexLength("tenantUpdate", "api-key", params.apiKey, 32);
|
|
71
81
|
}
|
|
82
|
+
if (Is.stringValue(params.organizationId)) {
|
|
83
|
+
Did.guard("tenantUpdate", "organization-id", params.organizationId);
|
|
84
|
+
}
|
|
72
85
|
if (Is.stringValue(params.publicOrigin)) {
|
|
73
86
|
Url.guard("tenantUpdate", "public-origin", params.publicOrigin);
|
|
74
87
|
}
|
|
@@ -79,11 +92,13 @@ export async function tenantUpdate(engineCore, envVars, params) {
|
|
|
79
92
|
const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
|
|
80
93
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updating"));
|
|
81
94
|
CLIDisplay.spinnerStart();
|
|
95
|
+
const tenant = await tenantAdminComponent.get(params.tenantId);
|
|
82
96
|
await tenantAdminComponent.update({
|
|
83
|
-
|
|
84
|
-
apiKey: params.apiKey,
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
...tenant,
|
|
98
|
+
...(Is.stringValue(params.apiKey) && { apiKey: params.apiKey }),
|
|
99
|
+
...(Is.stringValue(params.organizationId) && { organizationId: params.organizationId }),
|
|
100
|
+
...(Is.stringValue(params.label) && { label: params.label }),
|
|
101
|
+
...(Is.stringValue(params.publicOrigin) && { publicOrigin: params.publicOrigin })
|
|
87
102
|
});
|
|
88
103
|
CLIDisplay.spinnerStop();
|
|
89
104
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updated"));
|
|
@@ -1 +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;
|
|
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;AAEvF,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAIhD,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,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AAM,CAAC;QACjC,GAAG,MAAM;QACT,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QAC/D,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC;QACvF,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QAC5D,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC;KACjF,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 { Did } from \"@twin.org/identity-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: \"organization-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"did\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.organization-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: \"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.\n * @param params.organizationId The organization DID to associate with the tenant.\n * @param params.label The label for the tenant.\n * @param params.publicOrigin The public URL origin for the tenant.\n * @returns A promise that resolves when the tenant record has been updated.\n */\nexport async function tenantUpdate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\torganizationId?: 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.organizationId)) {\n\t\tDid.guard(\"tenantUpdate\", \"organization-id\", params.organizationId);\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\tconst tenant = await tenantAdminComponent.get(params.tenantId);\n\tawait tenantAdminComponent.update({\n\t\t...tenant,\n\t\t...(Is.stringValue(params.apiKey) && { apiKey: params.apiKey }),\n\t\t...(Is.stringValue(params.organizationId) && { organizationId: params.organizationId }),\n\t\t...(Is.stringValue(params.label) && { label: params.label }),\n\t\t...(Is.stringValue(params.publicOrigin) && { publicOrigin: 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"]}
|
|
@@ -66,10 +66,11 @@ export function getCommandDefinitionVaultKeyImport(commandDefinitions) {
|
|
|
66
66
|
* @param engineCore The engine core.
|
|
67
67
|
* @param envVars The environment variables for the node.
|
|
68
68
|
* @param params The parameters for the command.
|
|
69
|
-
* @param params.identity The DID to
|
|
70
|
-
* @param params.keyId The ID of the key to
|
|
71
|
-
* @param params.keyType The type of key to
|
|
69
|
+
* @param params.identity The DID to import the vault key for.
|
|
70
|
+
* @param params.keyId The ID of the key to import.
|
|
71
|
+
* @param params.keyType The type of key to import.
|
|
72
72
|
* @param params.privateKeyHex The private key in hexadecimal format.
|
|
73
|
+
* @returns A promise that resolves when the key has been imported into the vault.
|
|
73
74
|
*/
|
|
74
75
|
export async function vaultKeyImport(engineCore, envVars, params) {
|
|
75
76
|
Did.guard("vaultKeyImport", "identity", params.identity);
|