@twin.org/node-core 0.0.3-next.51 → 0.0.3-next.53
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 +19 -38
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +16 -4
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/cli.js +6 -2
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/bootstrapLegacy.js +110 -34
- package/dist/es/commands/bootstrapLegacy.js.map +1 -1
- package/dist/es/commands/identityCreate.js +29 -0
- 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/identityVerifiableCredentialCreate.js +1 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodCreate.js +1 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodImport.js +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -1
- package/dist/es/commands/nodeSetIdentity.js +1 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -1
- package/dist/es/commands/removeTenantOrgAlias.js +81 -0
- package/dist/es/commands/removeTenantOrgAlias.js.map +1 -0
- package/dist/es/commands/setNodeOrgId.js +60 -0
- package/dist/es/commands/setNodeOrgId.js.map +1 -0
- package/dist/es/commands/setTenantOrgId.js +158 -0
- package/dist/es/commands/setTenantOrgId.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +41 -7
- package/dist/es/commands/tenantCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyCreate.js +1 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyImport.js +1 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -1
- package/dist/es/defaults.js +1 -3
- package/dist/es/defaults.js.map +1 -1
- package/dist/es/models/ICliCommandDefinition.js.map +1 -1
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeEngineState.js.map +1 -1
- package/dist/es/node.js +2 -2
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +74 -9
- package/dist/es/start.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +1 -12
- package/dist/types/commands/bootstrapLegacy.d.ts +2 -2
- package/dist/types/commands/identityCreate.d.ts +4 -0
- package/dist/types/commands/removeTenantOrgAlias.d.ts +22 -0
- package/dist/types/commands/setNodeOrgId.d.ts +22 -0
- package/dist/types/commands/setTenantOrgId.d.ts +55 -0
- package/dist/types/commands/tenantCreate.d.ts +3 -0
- package/dist/types/defaults.d.ts +0 -1
- package/dist/types/models/ICliCommandDefinition.d.ts +5 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +8 -4
- package/dist/types/models/INodeEngineState.d.ts +5 -0
- package/docs/changelog.md +14 -0
- package/docs/reference/functions/buildEngineConfiguration.md +1 -7
- package/docs/reference/index.md +0 -2
- package/docs/reference/interfaces/ICliCommandDefinition.md +14 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +16 -8
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +24 -12
- package/docs/reference/interfaces/INodeEngineState.md +9 -0
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +24 -12
- package/locales/en.json +96 -34
- package/package.json +1 -1
- package/dist/es/commands/tenantToken.js +0 -97
- package/dist/es/commands/tenantToken.js.map +0 -1
- package/dist/types/commands/tenantToken.d.ts +0 -28
- package/docs/reference/functions/isUrlTransformerRequired.md +0 -20
- package/docs/reference/variables/URL_TRANSFORMER_ENCRYPTION_KEY_ID.md +0 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { Did } from "@twin.org/identity-models";
|
|
4
|
+
const COMMAND_NAME = "remove-tenant-org-alias";
|
|
5
|
+
/**
|
|
6
|
+
* Get the command definition parameters.
|
|
7
|
+
* @param commandDefinitions The registered command definitions.
|
|
8
|
+
*/
|
|
9
|
+
export function getCommandDefinitionRemoveTenantOrgAlias(commandDefinitions) {
|
|
10
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
11
|
+
command: COMMAND_NAME,
|
|
12
|
+
description: I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.description"),
|
|
13
|
+
example: I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.example"),
|
|
14
|
+
requiresNodeIdentity: false,
|
|
15
|
+
requiresOrgIdentity: false,
|
|
16
|
+
params: [
|
|
17
|
+
{
|
|
18
|
+
key: "env-prefix",
|
|
19
|
+
type: "string",
|
|
20
|
+
description: I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.params.env-prefix.description"),
|
|
21
|
+
required: false
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: "tenant-id",
|
|
25
|
+
type: "string",
|
|
26
|
+
extendedType: "hex(32)",
|
|
27
|
+
description: I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.params.tenant-id.description"),
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: "alias",
|
|
32
|
+
type: "string",
|
|
33
|
+
extendedType: "did",
|
|
34
|
+
description: I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.params.alias.description"),
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "load-env",
|
|
39
|
+
type: "string",
|
|
40
|
+
description: I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.params.load-env.description"),
|
|
41
|
+
required: false
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
action: async (engineCore, envVars, params) => removeTenantOrgAlias(engineCore, envVars, params)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Command for removing an alias from the tenant organization ID legacy list.
|
|
49
|
+
* @param engineCore The engine core.
|
|
50
|
+
* @param envVars The environment variables for the node.
|
|
51
|
+
* @param params The parameters for the command.
|
|
52
|
+
* @param params.tenantId The tenant ID to update.
|
|
53
|
+
* @param params.alias The alias to remove from the legacy list.
|
|
54
|
+
*/
|
|
55
|
+
export async function removeTenantOrgAlias(engineCore, envVars, params) {
|
|
56
|
+
const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
57
|
+
if (!Is.stringValue(defaultTenantAdminComponentType)) {
|
|
58
|
+
throw new GeneralError("removeTenantOrgAlias", "tenantAdminComponentNotRegistered");
|
|
59
|
+
}
|
|
60
|
+
Guards.stringHexLength("removeTenantOrgAlias", "tenant-id", params.tenantId, 32);
|
|
61
|
+
Did.guard("removeTenantOrgAlias", "alias", params.alias);
|
|
62
|
+
const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
|
|
63
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.labels.reading"));
|
|
64
|
+
const tenant = await tenantAdminComponent.get(params.tenantId);
|
|
65
|
+
const legacy = [...(tenant.organizationIdLegacy ?? [])];
|
|
66
|
+
const index = legacy.indexOf(params.alias);
|
|
67
|
+
if (index < 0) {
|
|
68
|
+
throw new GeneralError("removeTenantOrgAlias", "aliasNotFound", { alias: params.alias });
|
|
69
|
+
}
|
|
70
|
+
legacy.splice(index, 1);
|
|
71
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.labels.updating"));
|
|
72
|
+
CLIDisplay.spinnerStart();
|
|
73
|
+
await tenantAdminComponent.update({
|
|
74
|
+
id: params.tenantId,
|
|
75
|
+
organizationIdLegacy: legacy
|
|
76
|
+
});
|
|
77
|
+
CLIDisplay.spinnerStop();
|
|
78
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.remove-tenant-org-alias.labels.removed"));
|
|
79
|
+
CLIDisplay.done();
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=removeTenantOrgAlias.js.map
|
|
@@ -0,0 +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,EAA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C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,YAAY,CAAC,sBAAsB,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAExB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,2DAA2D,CAAC,CAAC,CAAC;IACjG,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,oBAAoB,CAAC,MAAM,CAAC;QACjC,EAAE,EAAE,MAAM,CAAC,QAAQ;QACnB,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 */\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\tid: params.tenantId,\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"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { Coerce, GeneralError, I18n } from "@twin.org/core";
|
|
5
|
+
import { Did } from "@twin.org/identity-models";
|
|
6
|
+
const COMMAND_NAME = "set-node-org-id";
|
|
7
|
+
/**
|
|
8
|
+
* Get the command definition parameters.
|
|
9
|
+
* @param commandDefinitions The registered command definitions.
|
|
10
|
+
*/
|
|
11
|
+
export function getCommandDefinitionSetNodeOrgId(commandDefinitions) {
|
|
12
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
13
|
+
command: COMMAND_NAME,
|
|
14
|
+
description: I18n.formatMessage("node.cli.commands.set-node-org-id.description"),
|
|
15
|
+
example: I18n.formatMessage("node.cli.commands.set-node-org-id.example"),
|
|
16
|
+
requiresNodeIdentity: false,
|
|
17
|
+
requiresOrgIdentity: false,
|
|
18
|
+
params: [
|
|
19
|
+
{
|
|
20
|
+
key: "env-prefix",
|
|
21
|
+
type: "string",
|
|
22
|
+
description: I18n.formatMessage("node.cli.commands.set-node-org-id.params.env-prefix.description"),
|
|
23
|
+
required: false
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: "organization-id",
|
|
27
|
+
type: "string",
|
|
28
|
+
extendedType: "did",
|
|
29
|
+
description: I18n.formatMessage("node.cli.commands.set-node-org-id.params.organization-id.description"),
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "load-env",
|
|
34
|
+
type: "string",
|
|
35
|
+
description: I18n.formatMessage("node.cli.commands.set-node-org-id.params.load-env.description"),
|
|
36
|
+
required: false
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
action: async (engineCore, envVars, params) => setNodeOrgId(engineCore, envVars, params)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Command for setting the node organization ID.
|
|
44
|
+
* @param engineCore The engine core.
|
|
45
|
+
* @param envVars The environment variables for the node.
|
|
46
|
+
* @param params The parameters for the command.
|
|
47
|
+
* @param params.organizationId The organization ID to set.
|
|
48
|
+
*/
|
|
49
|
+
export async function setNodeOrgId(engineCore, envVars, params) {
|
|
50
|
+
if (Coerce.boolean(envVars.tenantEnabled) ?? false) {
|
|
51
|
+
throw new GeneralError("setNodeOrgId", "notAvailableInMultiTenantMode");
|
|
52
|
+
}
|
|
53
|
+
Did.guard("setNodeOrgId", "organizationId", params.organizationId);
|
|
54
|
+
const state = engineCore.getState();
|
|
55
|
+
state.nodeOrganizationId = params.organizationId;
|
|
56
|
+
engineCore.setStateDirty();
|
|
57
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.set-node-org-id.labels.stored"));
|
|
58
|
+
CLIDisplay.done();
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=setNodeOrgId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setNodeOrgId.js","sourceRoot":"","sources":["../../../src/commands/setNodeOrgId.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAMhD,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,+CAA+C,CAAC;QAChF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC;QACxE,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,iEAAiE,CACjE;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,iBAAiB;gBACtB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,KAAK;gBACnB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,sEAAsE,CACtE;gBACD,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,+DAA+D,CAC/D;gBACD,QAAQ,EAAE,KAAK;aACf;SACD;QACD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC;KACxF,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,UAA4D,EAC5D,OAAkC,EAClC,MAEC;IAED,IAAI,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 */\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"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { ComparisonOperator, LogicalOperator } from "@twin.org/entity";
|
|
4
|
+
import { Did } from "@twin.org/identity-models";
|
|
5
|
+
const COMMAND_NAME = "set-tenant-org-id";
|
|
6
|
+
/**
|
|
7
|
+
* Get the command definition parameters.
|
|
8
|
+
* @param commandDefinitions The registered command definitions.
|
|
9
|
+
*/
|
|
10
|
+
export function getCommandDefinitionSetTenantOrgId(commandDefinitions) {
|
|
11
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
12
|
+
command: COMMAND_NAME,
|
|
13
|
+
description: I18n.formatMessage("node.cli.commands.set-tenant-org-id.description"),
|
|
14
|
+
example: I18n.formatMessage("node.cli.commands.set-tenant-org-id.example"),
|
|
15
|
+
requiresNodeIdentity: false,
|
|
16
|
+
requiresOrgIdentity: false,
|
|
17
|
+
params: [
|
|
18
|
+
{
|
|
19
|
+
key: "env-prefix",
|
|
20
|
+
type: "string",
|
|
21
|
+
description: I18n.formatMessage("node.cli.commands.set-tenant-org-id.params.env-prefix.description"),
|
|
22
|
+
required: false
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "tenant-id",
|
|
26
|
+
type: "string",
|
|
27
|
+
extendedType: "hex(32)",
|
|
28
|
+
description: I18n.formatMessage("node.cli.commands.set-tenant-org-id.params.tenant-id.description"),
|
|
29
|
+
required: true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "organization-id",
|
|
33
|
+
type: "string",
|
|
34
|
+
extendedType: "did",
|
|
35
|
+
description: I18n.formatMessage("node.cli.commands.set-tenant-org-id.params.organization-id.description"),
|
|
36
|
+
required: true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: "load-env",
|
|
40
|
+
type: "string",
|
|
41
|
+
description: I18n.formatMessage("node.cli.commands.set-tenant-org-id.params.load-env.description"),
|
|
42
|
+
required: false
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
action: async (engineCore, envVars, params) => setTenantOrgId(engineCore, envVars, params)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Command for setting the organization ID on a tenant.
|
|
50
|
+
* @param engineCore The engine core.
|
|
51
|
+
* @param envVars The environment variables for the node.
|
|
52
|
+
* @param params The parameters for the command.
|
|
53
|
+
* @param params.tenantId The tenant ID to update.
|
|
54
|
+
* @param params.organizationId The organization ID to set.
|
|
55
|
+
*/
|
|
56
|
+
export async function setTenantOrgId(engineCore, envVars, params) {
|
|
57
|
+
Guards.stringHexLength("setTenantOrgId", "tenant-id", params.tenantId, 32);
|
|
58
|
+
Did.guard("setTenantOrgId", "organizationId", params.organizationId);
|
|
59
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.set-tenant-org-id.labels.updating"));
|
|
60
|
+
CLIDisplay.spinnerStart();
|
|
61
|
+
await applyOrganizationIdToTenant(engineCore, params.tenantId, params.organizationId);
|
|
62
|
+
CLIDisplay.spinnerStop();
|
|
63
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.set-tenant-org-id.labels.stored"));
|
|
64
|
+
CLIDisplay.done();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Assert that no other tenant already holds the given organization ID.
|
|
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.
|
|
105
|
+
* @param engineCore The engine core used to look up the tenantAdminComponent.
|
|
106
|
+
* @param tenantId The ID of the tenant to update.
|
|
107
|
+
* @param newOrganizationId The new organization DID to set.
|
|
108
|
+
* @param options Optional display and behaviour overrides.
|
|
109
|
+
* @param options.sectionLabel When set, emits CLIDisplay.break+section before and CLIDisplay.done after.
|
|
110
|
+
* @param options.required When false, returns silently when the component is not registered (default true).
|
|
111
|
+
*/
|
|
112
|
+
export async function applyOrganizationIdToTenant(engineCore, tenantId, newOrganizationId, options) {
|
|
113
|
+
const type = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
114
|
+
if (!Is.stringValue(type)) {
|
|
115
|
+
if (options?.required ?? true) {
|
|
116
|
+
throw new GeneralError("applyOrganizationIdToTenant", "tenantAdminComponentNotRegistered");
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (Is.stringValue(options?.sectionLabel)) {
|
|
121
|
+
CLIDisplay.break();
|
|
122
|
+
CLIDisplay.section(options.sectionLabel);
|
|
123
|
+
}
|
|
124
|
+
const tenantAdminComponent = ComponentFactory.get(type);
|
|
125
|
+
await assertOrganizationIdUnique(tenantAdminComponent, newOrganizationId, tenantId);
|
|
126
|
+
const tenant = await tenantAdminComponent.get(tenantId);
|
|
127
|
+
const { id, legacy } = updateLegacyOrganizationId(tenant.organizationId, tenant.organizationIdLegacy, newOrganizationId);
|
|
128
|
+
await tenantAdminComponent.update({
|
|
129
|
+
id: tenantId,
|
|
130
|
+
organizationId: id,
|
|
131
|
+
organizationIdLegacy: legacy
|
|
132
|
+
});
|
|
133
|
+
if (Is.stringValue(options?.sectionLabel)) {
|
|
134
|
+
CLIDisplay.done();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
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
|
+
//# sourceMappingURL=setTenantOrgId.js.map
|
|
@@ -0,0 +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,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,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,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,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EA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,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,6 +1,8 @@
|
|
|
1
1
|
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
|
+
import { Did } from "@twin.org/identity-models";
|
|
5
|
+
import { assertOrganizationIdUnique } from "./setTenantOrgId.js";
|
|
4
6
|
const COMMAND_NAME = "tenant-create";
|
|
5
7
|
/**
|
|
6
8
|
* Get the command definition parameters.
|
|
@@ -32,6 +34,13 @@ export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
|
32
34
|
description: I18n.formatMessage("node.cli.commands.tenant-create.params.api-key.description"),
|
|
33
35
|
required: false
|
|
34
36
|
},
|
|
37
|
+
{
|
|
38
|
+
key: "organization-id",
|
|
39
|
+
type: "string",
|
|
40
|
+
extendedType: "did",
|
|
41
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.organization-id.description"),
|
|
42
|
+
required: true
|
|
43
|
+
},
|
|
35
44
|
{
|
|
36
45
|
key: "public-origin",
|
|
37
46
|
type: "string",
|
|
@@ -80,6 +89,7 @@ export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
|
80
89
|
* @param params The parameters for the command.
|
|
81
90
|
* @param params.apiKey The api key to add.
|
|
82
91
|
* @param params.tenantId The tenant ID to add the api key to.
|
|
92
|
+
* @param params.organizationId The organization DID to associate with the tenant.
|
|
83
93
|
* @param params.label The label for the api key.
|
|
84
94
|
* @param params.publicOrigin The public URL origin for the tenant.
|
|
85
95
|
* @param params.outputJson The output .json file to store the command output.
|
|
@@ -94,6 +104,9 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
94
104
|
if (Is.stringValue(params.apiKey)) {
|
|
95
105
|
Guards.stringHexLength("tenantCreate", "api-key", params.apiKey, 32);
|
|
96
106
|
}
|
|
107
|
+
if (Is.stringValue(params.organizationId)) {
|
|
108
|
+
Did.guard("tenantCreate", "organization-id", params.organizationId);
|
|
109
|
+
}
|
|
97
110
|
if (Is.stringValue(params.publicOrigin)) {
|
|
98
111
|
Url.guard("tenantCreate", "public-origin", params.publicOrigin);
|
|
99
112
|
}
|
|
@@ -102,34 +115,55 @@ export async function tenantCreate(engineCore, envVars, params) {
|
|
|
102
115
|
throw new GeneralError("tenantCreate", "tenantAdminComponentNotRegistered");
|
|
103
116
|
}
|
|
104
117
|
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
118
|
+
if (Is.stringValue(params.organizationId)) {
|
|
119
|
+
await assertOrganizationIdUnique(tenantAdminService, params.organizationId);
|
|
120
|
+
}
|
|
105
121
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-create.labels.creating"));
|
|
106
122
|
const apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();
|
|
107
123
|
const tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();
|
|
124
|
+
const organizationId = params.organizationId;
|
|
108
125
|
const label = params.label ?? "";
|
|
109
126
|
const publicOrigin = params.publicOrigin ?? "";
|
|
110
127
|
await tenantAdminService.create({
|
|
111
128
|
id: tenantId,
|
|
112
129
|
apiKey,
|
|
130
|
+
organizationId,
|
|
113
131
|
label,
|
|
114
132
|
publicOrigin
|
|
115
133
|
});
|
|
116
134
|
CLIDisplay.break();
|
|
117
135
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.tenantId"), tenantId);
|
|
118
136
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.apiKey"), apiKey);
|
|
137
|
+
if (Is.stringValue(organizationId)) {
|
|
138
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.organizationId"), organizationId);
|
|
139
|
+
}
|
|
119
140
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.label"), label);
|
|
120
141
|
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.publicOrigin"), publicOrigin);
|
|
121
142
|
CLIDisplay.break();
|
|
122
|
-
const json = {
|
|
143
|
+
const json = {
|
|
144
|
+
apiKey,
|
|
145
|
+
tenantId,
|
|
146
|
+
label,
|
|
147
|
+
publicOrigin
|
|
148
|
+
};
|
|
149
|
+
if (Is.stringValue(organizationId)) {
|
|
150
|
+
json.organizationId = organizationId;
|
|
151
|
+
}
|
|
123
152
|
if (Is.stringValue(params.outputJson)) {
|
|
124
153
|
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
125
154
|
}
|
|
126
155
|
if (Is.stringValue(params.outputEnv)) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
`${
|
|
130
|
-
`${
|
|
131
|
-
`${
|
|
132
|
-
|
|
156
|
+
const prefix = params.outputEnvPrefix ?? "";
|
|
157
|
+
const envLines = [
|
|
158
|
+
`${prefix}API_KEY="${apiKey}"`,
|
|
159
|
+
`${prefix}TENANT_ID="${tenantId}"`,
|
|
160
|
+
`${prefix}LABEL="${label}"`,
|
|
161
|
+
`${prefix}PUBLIC_ORIGIN="${publicOrigin}"`
|
|
162
|
+
];
|
|
163
|
+
if (Is.stringValue(organizationId)) {
|
|
164
|
+
envLines.splice(2, 0, `${prefix}ORGANIZATION_ID="${organizationId}"`);
|
|
165
|
+
}
|
|
166
|
+
await CLIUtils.writeEnvFile(params.outputEnv, envLines, false);
|
|
133
167
|
}
|
|
134
168
|
CLIDisplay.done();
|
|
135
169
|
return json;
|
|
@@ -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,E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C,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"]}
|
|
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,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,EA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-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"]}
|
|
@@ -15,6 +15,7 @@ export function getCommandDefinitionVaultKeyCreate(commandDefinitions) {
|
|
|
15
15
|
description: I18n.formatMessage("node.cli.commands.vault-key-create.description"),
|
|
16
16
|
example: I18n.formatMessage("node.cli.commands.vault-key-create.example"),
|
|
17
17
|
requiresNodeIdentity: false,
|
|
18
|
+
requiresOrgIdentity: false,
|
|
18
19
|
params: [
|
|
19
20
|
{
|
|
20
21
|
key: "env-prefix",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vaultKeyCreate.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM7E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;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,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,sBAAsB,eAAe,GAAG,CAAC,CAAC;YACtF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;gBACnC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,oBAAoB,aAAa,GAAG,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,mBAAmB,YAAY,GAAG,CAAC,CAAC;YAChF,CAAC;YACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;IACF,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 { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-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 = \"vault-key-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyCreate(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.vault-key-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-create.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.vault-key-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: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.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: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-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: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\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.vault-key-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.vault-key-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.vault-key-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.vault-key-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) => vaultKeyCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a vault 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.identity The DID to create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.overwriteMode The mode to use when a user with the same identity already exists.\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 vault key details or undefined if skipped.\n */\nexport async function vaultKeyCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tidentity: string;\n\t\t\tkeyId: string;\n\t\t\tkeyType?: string;\n\t\t\tprivateKeyBase64?: string;\n\t\t\tpublicKeyBase64?: string;\n\t\t\tprivateKeyHex?: string;\n\t\t\tpublicKeyHex?: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"vaultKeyCreate\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyCreate\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyCreate\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createVaultKey = true;\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t} catch {}\n\n\tif (!Is.empty(existingKey)) {\n\t\tif (params.overwriteMode === \"error\") {\n\t\t\tthrow new GeneralError(\"vaultKeyCreate\", \"vaultKeyAlreadyExists\");\n\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\tcreateVaultKey = false;\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.skipping\"));\n\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.overwriting\"));\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t}\n\n\tlet json;\n\tif (createVaultKey) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.creating\"));\n\t\tCLIDisplay.spinnerStart();\n\n\t\tawait vaultConnector.createKey(\n\t\t\tfullKeyId,\n\t\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType]\n\t\t);\n\n\t\tconst key = await vaultConnector.getKey(fullKeyId);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.created\"));\n\n\t\tconst privateKeyBase64 = key.privateKey ? Converter.bytesToBase64(key.privateKey) : undefined;\n\t\tconst publicKeyBase64 = key.publicKey ? Converter.bytesToBase64(key.publicKey) : undefined;\n\t\tconst privateKeyHex = key.privateKey ? Converter.bytesToHex(key.privateKey, true) : undefined;\n\t\tconst publicKeyHex = key.publicKey ? Converter.bytesToHex(key.publicKey, true) : undefined;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyId\"),\n\t\t\tparams.keyId\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyType\"),\n\t\t\tparams.keyType\n\t\t);\n\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyBase64\"),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyBase64\"),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyHex\"),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyHex\"),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\t\t}\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tidentity: params.identity,\n\t\t\tkeyId: params.keyId,\n\t\t\tkeyType: params.keyType,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64,\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex\n\t\t};\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst outputParams = [\n\t\t\t\t`${params.outputEnvPrefix}IDENTITY=\"${params.identity}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_ID=\"${params.keyId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_TYPE=\"${params.keyType}\"`\n\t\t\t];\n\n\t\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_HEX=\"${privateKeyHex}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_HEX=\"${publicKeyHex}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, outputParams, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vaultKeyCreate.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,Q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GAAG,MAAM,CAAC,eAAe,WAAW,MAAM,CAAC,KAAK,GAAG;gBACnD,GAAG,MAAM,CAAC,eAAe,aAAa,MAAM,CAAC,OAAO,GAAG;aACvD,CAAC;YAEF,IAAI,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBACtC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,uBAAuB,gBAAgB,GAAG,CAAC,CAAC;YACxF,CAAC;YAED,IAAI,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC;gBACrC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,sBAAsB,eAAe,GAAG,CAAC,CAAC;YACtF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;gBACnC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,oBAAoB,aAAa,GAAG,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,mBAAmB,YAAY,GAAG,CAAC,CAAC;YAChF,CAAC;YACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;IACF,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 { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-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 = \"vault-key-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyCreate(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.vault-key-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-create.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.vault-key-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: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.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: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-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: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\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.vault-key-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.vault-key-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.vault-key-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.vault-key-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) => vaultKeyCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a vault 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.identity The DID to create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.overwriteMode The mode to use when a user with the same identity already exists.\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 vault key details or undefined if skipped.\n */\nexport async function vaultKeyCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tidentity: string;\n\t\t\tkeyId: string;\n\t\t\tkeyType?: string;\n\t\t\tprivateKeyBase64?: string;\n\t\t\tpublicKeyBase64?: string;\n\t\t\tprivateKeyHex?: string;\n\t\t\tpublicKeyHex?: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"vaultKeyCreate\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyCreate\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyCreate\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createVaultKey = true;\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t} catch {}\n\n\tif (!Is.empty(existingKey)) {\n\t\tif (params.overwriteMode === \"error\") {\n\t\t\tthrow new GeneralError(\"vaultKeyCreate\", \"vaultKeyAlreadyExists\");\n\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\tcreateVaultKey = false;\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.skipping\"));\n\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.overwriting\"));\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t}\n\n\tlet json;\n\tif (createVaultKey) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.creating\"));\n\t\tCLIDisplay.spinnerStart();\n\n\t\tawait vaultConnector.createKey(\n\t\t\tfullKeyId,\n\t\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType]\n\t\t);\n\n\t\tconst key = await vaultConnector.getKey(fullKeyId);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.created\"));\n\n\t\tconst privateKeyBase64 = key.privateKey ? Converter.bytesToBase64(key.privateKey) : undefined;\n\t\tconst publicKeyBase64 = key.publicKey ? Converter.bytesToBase64(key.publicKey) : undefined;\n\t\tconst privateKeyHex = key.privateKey ? Converter.bytesToHex(key.privateKey, true) : undefined;\n\t\tconst publicKeyHex = key.publicKey ? Converter.bytesToHex(key.publicKey, true) : undefined;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyId\"),\n\t\t\tparams.keyId\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyType\"),\n\t\t\tparams.keyType\n\t\t);\n\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyBase64\"),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyBase64\"),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyHex\"),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyHex\"),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\t\t}\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tidentity: params.identity,\n\t\t\tkeyId: params.keyId,\n\t\t\tkeyType: params.keyType,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64,\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex\n\t\t};\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst outputParams = [\n\t\t\t\t`${params.outputEnvPrefix}IDENTITY=\"${params.identity}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_ID=\"${params.keyId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_TYPE=\"${params.keyType}\"`\n\t\t\t];\n\n\t\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_HEX=\"${privateKeyHex}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_HEX=\"${publicKeyHex}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, outputParams, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -16,6 +16,7 @@ export function getCommandDefinitionVaultKeyImport(commandDefinitions) {
|
|
|
16
16
|
description: I18n.formatMessage("node.cli.commands.vault-key-import.description"),
|
|
17
17
|
example: I18n.formatMessage("node.cli.commands.vault-key-import.example"),
|
|
18
18
|
requiresNodeIdentity: false,
|
|
19
|
+
requiresOrgIdentity: false,
|
|
19
20
|
params: [
|
|
20
21
|
{
|
|
21
22
|
key: "env-prefix",
|