@twin.org/node-core 0.0.3-next.1 → 0.0.3-next.10
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 +155 -74
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +24 -15
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/extensionsBuilder.js +26 -17
- package/dist/es/builders/extensionsBuilder.js.map +1 -1
- package/dist/es/cli.js +255 -0
- package/dist/es/cli.js.map +1 -0
- package/dist/es/commands/bootstrapLegacy.js +175 -0
- package/dist/es/commands/bootstrapLegacy.js.map +1 -0
- package/dist/es/commands/help.js +85 -0
- package/dist/es/commands/help.js.map +1 -0
- package/dist/es/commands/identityCreate.js +310 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityImports.js +76 -0
- package/dist/es/commands/identityImports.js.map +1 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js +140 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodCreate.js +208 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js +120 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
- package/dist/es/commands/nodeSetIdentity.js +51 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -0
- package/dist/es/commands/nodeSetTenant.js +49 -0
- package/dist/es/commands/nodeSetTenant.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +120 -0
- package/dist/es/commands/tenantCreate.js.map +1 -0
- package/dist/es/commands/tenantImport.js +78 -0
- package/dist/es/commands/tenantImport.js.map +1 -0
- package/dist/es/commands/userCreate.js +197 -0
- package/dist/es/commands/userCreate.js.map +1 -0
- package/dist/es/commands/vaultKeyCreate.js +185 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -0
- package/dist/es/commands/vaultKeyImport.js +98 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -0
- package/dist/es/defaults.js +20 -1
- package/dist/es/defaults.js.map +1 -1
- package/dist/es/index.js +7 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ICliArgs.js +4 -0
- package/dist/es/models/ICliArgs.js.map +1 -0
- package/dist/es/models/ICliCommand.js +2 -0
- package/dist/es/models/ICliCommand.js.map +1 -0
- package/dist/es/models/ICliCommandDefinition.js +2 -0
- package/dist/es/models/ICliCommandDefinition.js.map +1 -0
- package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
- package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeEngineState.js.map +1 -1
- package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
- package/dist/es/models/cliCommandParamType.js +4 -0
- package/dist/es/models/cliCommandParamType.js.map +1 -0
- package/dist/es/node.js +55 -35
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +128 -0
- package/dist/es/start.js.map +1 -0
- package/dist/es/utils.js +1 -22
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +4 -1
- package/dist/types/builders/engineServerEnvBuilder.d.ts +5 -2
- package/dist/types/cli.d.ts +66 -0
- package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
- package/dist/types/commands/help.d.ts +23 -0
- package/dist/types/commands/identityCreate.d.ts +39 -0
- package/dist/types/commands/identityImports.d.ts +24 -0
- package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
- package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
- package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
- package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
- package/dist/types/commands/nodeSetTenant.d.ts +22 -0
- package/dist/types/commands/tenantCreate.d.ts +35 -0
- package/dist/types/commands/tenantImport.d.ts +24 -0
- package/dist/types/commands/userCreate.d.ts +46 -0
- package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
- package/dist/types/commands/vaultKeyImport.d.ts +28 -0
- package/dist/types/defaults.d.ts +11 -1
- package/dist/types/index.d.ts +7 -3
- package/dist/types/models/ICliArgs.d.ts +20 -0
- package/dist/types/models/ICliCommand.d.ts +17 -0
- package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
- package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +51 -42
- package/dist/types/models/INodeEngineState.d.ts +0 -8
- package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
- package/dist/types/models/cliCommandParamType.d.ts +4 -0
- package/dist/types/node.d.ts +6 -2
- package/dist/types/{server.d.ts → start.d.ts} +7 -2
- package/dist/types/utils.d.ts +0 -8
- package/docs/changelog.md +63 -0
- package/docs/reference/functions/buildConfiguration.md +2 -2
- package/docs/reference/functions/buildEngineConfiguration.md +1 -1
- package/docs/reference/functions/buildEngineServerConfiguration.md +3 -3
- package/docs/reference/functions/constructCliCommand.md +27 -0
- package/docs/reference/functions/executeCommand.md +29 -0
- package/docs/reference/functions/getEnvDefaults.md +19 -0
- package/docs/reference/functions/initCli.md +27 -0
- package/docs/reference/functions/parseCommandLineArgs.md +19 -0
- package/docs/reference/functions/processEnvOptions.md +27 -0
- package/docs/reference/functions/registerCommands.md +9 -0
- package/docs/reference/functions/run.md +7 -1
- package/docs/reference/functions/start.md +10 -4
- package/docs/reference/functions/substituteEnvOptions.md +25 -0
- package/docs/reference/index.md +15 -12
- package/docs/reference/interfaces/ICliArgs.md +35 -0
- package/docs/reference/interfaces/ICliCommand.md +23 -0
- package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
- package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +90 -65
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +129 -88
- package/docs/reference/interfaces/INodeEngineState.md +0 -16
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +129 -172
- package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +3 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +3 -0
- package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +1 -1
- package/locales/en.json +463 -30
- package/package.json +3 -1
- package/dist/es/bootstrap.js +0 -374
- package/dist/es/bootstrap.js.map +0 -1
- package/dist/es/identity.js +0 -169
- package/dist/es/identity.js.map +0 -1
- package/dist/es/models/nodeFeatures.js +0 -21
- package/dist/es/models/nodeFeatures.js.map +0 -1
- package/dist/es/server.js +0 -74
- package/dist/es/server.js.map +0 -1
- package/dist/types/bootstrap.d.ts +0 -76
- package/dist/types/identity.d.ts +0 -14
- package/dist/types/models/nodeFeatures.d.ts +0 -21
- package/docs/reference/functions/bootstrap.md +0 -29
- package/docs/reference/functions/bootstrapAuth.md +0 -35
- package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
- package/docs/reference/functions/bootstrapContextIdHandlers.md +0 -35
- package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
- package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
- package/docs/reference/functions/bootstrapNodeId.md +0 -35
- package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
- package/docs/reference/functions/bootstrapTenantId.md +0 -35
- package/docs/reference/functions/getFeatures.md +0 -19
- package/docs/reference/type-aliases/NodeFeatures.md +0 -5
- package/docs/reference/variables/NodeFeatures.md +0 -25
|
@@ -0,0 +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,O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3B,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 } 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 = \"node-set-identity\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeSetIdentity(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.node-set-identity.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-set-identity.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-identity.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-identity.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => nodeSetIdentity(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting a node identity.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to set for the node.\n */\nexport async function nodeSetIdentity(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"nodeSetIdentity\", \"identity\", params.identity);\n\n\tconst state = engineCore.getState();\n\tstate.nodeId = params.identity;\n\tengineCore.setStateDirty();\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-identity.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { Guards, I18n } from "@twin.org/core";
|
|
5
|
+
const COMMAND_NAME = "node-set-tenant";
|
|
6
|
+
/**
|
|
7
|
+
* Get the command definition parameters.
|
|
8
|
+
* @param commandDefinitions The registered command definitions.
|
|
9
|
+
*/
|
|
10
|
+
export function getCommandDefinitionNodeSetTenant(commandDefinitions) {
|
|
11
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
12
|
+
command: COMMAND_NAME,
|
|
13
|
+
description: I18n.formatMessage("node.cli.commands.node-set-tenant.description"),
|
|
14
|
+
example: I18n.formatMessage("node.cli.commands.node-set-tenant.example"),
|
|
15
|
+
requiresTenantId: false,
|
|
16
|
+
params: [
|
|
17
|
+
{
|
|
18
|
+
key: "tenant-id",
|
|
19
|
+
type: "string",
|
|
20
|
+
extendedType: "hex(32)",
|
|
21
|
+
description: I18n.formatMessage("node.cli.commands.node-set-tenant.params.tenant-id.description"),
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "load-env",
|
|
26
|
+
type: "string",
|
|
27
|
+
description: I18n.formatMessage("node.cli.commands.node-set-tenant.params.load-env.description"),
|
|
28
|
+
required: false
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
action: async (engineCore, envVars, params) => nodeSetTenant(engineCore, envVars, params)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Command for setting a node tenant.
|
|
36
|
+
* @param engineCore The engine core.
|
|
37
|
+
* @param envVars The environment variables for the node.
|
|
38
|
+
* @param params The parameters for the command.
|
|
39
|
+
* @param params.tenantId The tenant id to set for the node.
|
|
40
|
+
*/
|
|
41
|
+
export async function nodeSetTenant(engineCore, envVars, params) {
|
|
42
|
+
Guards.stringHexLength("nodeSetTenant", "tenant-id", params.tenantId, 32);
|
|
43
|
+
const state = engineCore.getState();
|
|
44
|
+
state.nodeTenantId = params.tenantId;
|
|
45
|
+
engineCore.setStateDirty();
|
|
46
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-tenant.labels.stored"));
|
|
47
|
+
CLIDisplay.done();
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=nodeSetTenant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeSetTenant.js","sourceRoot":"","sources":["../../../src/commands/nodeSetTenant.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAO9C,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAAC,kBAEjD;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,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,gEAAgE,CAChE;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,aAAa,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC;KACzF,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,UAA4D,EAC5D,OAAkC,EAClC,MAEC;IAED,MAAM,CAAC,eAAe,CAAC,eAAe,EAAE,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAE1E,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC;IACrC,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 { Guards, I18n } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"node-set-tenant\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeSetTenant(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.node-set-tenant.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-set-tenant.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-tenant.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-tenant.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => nodeSetTenant(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting a node tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.tenantId The tenant id to set for the node.\n */\nexport async function nodeSetTenant(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"nodeSetTenant\", \"tenant-id\", params.tenantId, 32);\n\n\tconst state = engineCore.getState();\n\tstate.nodeTenantId = params.tenantId;\n\tengineCore.setStateDirty();\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-tenant.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { TenantIdHelper } from "@twin.org/api-tenant-processor";
|
|
4
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
5
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
6
|
+
const COMMAND_NAME = "tenant-create";
|
|
7
|
+
/**
|
|
8
|
+
* Get the command definition parameters.
|
|
9
|
+
* @param commandDefinitions The registered command definitions.
|
|
10
|
+
*/
|
|
11
|
+
export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
12
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
13
|
+
command: COMMAND_NAME,
|
|
14
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.description"),
|
|
15
|
+
example: I18n.formatMessage("node.cli.commands.tenant-create.example"),
|
|
16
|
+
requiresTenantId: false,
|
|
17
|
+
params: [
|
|
18
|
+
{
|
|
19
|
+
key: "tenant-id",
|
|
20
|
+
type: "string",
|
|
21
|
+
extendedType: "hex(32)",
|
|
22
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.tenant-id.description"),
|
|
23
|
+
required: false
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: "api-key",
|
|
27
|
+
type: "string",
|
|
28
|
+
extendedType: "hex(32)",
|
|
29
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.api-key.description"),
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "label",
|
|
34
|
+
type: "string",
|
|
35
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.label.description"),
|
|
36
|
+
required: false
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: "load-env",
|
|
40
|
+
type: "string",
|
|
41
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.load-env.description"),
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "output-json",
|
|
46
|
+
type: "string",
|
|
47
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-json.description"),
|
|
48
|
+
required: false
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: "output-env",
|
|
52
|
+
type: "string",
|
|
53
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-env.description"),
|
|
54
|
+
required: false
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: "output-env-prefix",
|
|
58
|
+
type: "string",
|
|
59
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-env-prefix.description"),
|
|
60
|
+
required: false
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
action: async (engineCore, envVars, params) => tenantCreate(engineCore, envVars, params)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Command for creating a tenant.
|
|
68
|
+
* @param engineCore The engine core.
|
|
69
|
+
* @param envVars The environment variables for the node.
|
|
70
|
+
* @param params The parameters for the command.
|
|
71
|
+
* @param params.apiKey The api key to add.
|
|
72
|
+
* @param params.tenantId The tenant ID to add the api key to.
|
|
73
|
+
* @param params.label The label for the api key.
|
|
74
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
75
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
76
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
77
|
+
* @returns The created tenant details.
|
|
78
|
+
*/
|
|
79
|
+
export async function tenantCreate(engineCore, envVars, params) {
|
|
80
|
+
if (Is.stringValue(params.tenantId)) {
|
|
81
|
+
Guards.stringHexLength("tenantCreate", "tenant-id", params.tenantId, 32);
|
|
82
|
+
}
|
|
83
|
+
if (Is.stringValue(params.apiKey)) {
|
|
84
|
+
Guards.stringHexLength("tenantCreate", "api-key", params.apiKey, 32);
|
|
85
|
+
}
|
|
86
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
87
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
88
|
+
throw new GeneralError("tenantCreate", "tenantAdminComponentNotRegistered");
|
|
89
|
+
}
|
|
90
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
91
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-create.labels.creating"));
|
|
92
|
+
const apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();
|
|
93
|
+
const tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();
|
|
94
|
+
const label = params.label ?? "";
|
|
95
|
+
await tenantAdminService.set({
|
|
96
|
+
id: tenantId,
|
|
97
|
+
apiKey,
|
|
98
|
+
dateCreated: new Date(Date.now()).toISOString(),
|
|
99
|
+
label
|
|
100
|
+
});
|
|
101
|
+
CLIDisplay.break();
|
|
102
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.tenantId"), tenantId);
|
|
103
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.apiKey"), apiKey);
|
|
104
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.label"), label);
|
|
105
|
+
CLIDisplay.break();
|
|
106
|
+
const json = { apiKey, tenantId, label };
|
|
107
|
+
if (Is.stringValue(params.outputJson)) {
|
|
108
|
+
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
109
|
+
}
|
|
110
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
111
|
+
await CLIUtils.writeEnvFile(params.outputEnv, [
|
|
112
|
+
`${params.outputEnvPrefix}API_KEY="${apiKey}"`,
|
|
113
|
+
`${params.outputEnvPrefix}TENANT_ID="${tenantId}"`,
|
|
114
|
+
`${params.outputEnvPrefix}LABEL="${label}"`
|
|
115
|
+
], false);
|
|
116
|
+
}
|
|
117
|
+
CLIDisplay.done();
|
|
118
|
+
return json;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=tenantCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantCreate.js","sourceRoot":"","sources":["../../../src/commands/tenantCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAA8B,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAKlF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC9E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC;QACtE,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,8DAA8D,CAC9D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,SAAS;gBACd,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,4DAA4D,CAC5D;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,OAAO;gBACZ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,I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AE,CAAC;IACzC,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;SAC3C,EACD,KAAK,CACL,CAAC;IACH,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { TenantIdHelper, type ITenantAdminComponent } from \"@twin.org/api-tenant-processor\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-create.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.api-key.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-create.params.label.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to add.\n * @param params.tenantId The tenant ID to add the api key to.\n * @param params.label The label for the api key.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created tenant details.\n */\nexport async function tenantCreate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<{ apiKey: string; tenantId: string; label: string }> {\n\tif (Is.stringValue(params.tenantId)) {\n\t\tGuards.stringHexLength(\"tenantCreate\", \"tenant-id\", params.tenantId, 32);\n\t}\n\n\tif (Is.stringValue(params.apiKey)) {\n\t\tGuards.stringHexLength(\"tenantCreate\", \"api-key\", params.apiKey, 32);\n\t}\n\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\tthrow new GeneralError(\"tenantCreate\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.creating\"));\n\n\tconst apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();\n\tconst tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();\n\tconst label = params.label ?? \"\";\n\n\tawait tenantAdminService.set({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\tlabel\n\t});\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.tenantId\"), tenantId);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.apiKey\"), apiKey);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.label\"), label);\n\tCLIDisplay.break();\n\n\tconst json = { apiKey, tenantId, label };\n\tif (Is.stringValue(params.outputJson)) {\n\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t}\n\n\tif (Is.stringValue(params.outputEnv)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\tparams.outputEnv,\n\t\t\t[\n\t\t\t\t`${params.outputEnvPrefix}API_KEY=\"${apiKey}\"`,\n\t\t\t\t`${params.outputEnvPrefix}TENANT_ID=\"${tenantId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}LABEL=\"${label}\"`\n\t\t\t],\n\t\t\tfalse\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-import";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-import.example"),
|
|
13
|
+
requiresTenantId: false,
|
|
14
|
+
params: [
|
|
15
|
+
{
|
|
16
|
+
key: "tenant-id",
|
|
17
|
+
type: "string",
|
|
18
|
+
extendedType: "hex(32)",
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.tenant-id.description"),
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "api-key",
|
|
24
|
+
type: "string",
|
|
25
|
+
extendedType: "hex(32)",
|
|
26
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.api-key.description"),
|
|
27
|
+
required: true
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: "label",
|
|
31
|
+
type: "string",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.label.description"),
|
|
33
|
+
required: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "load-env",
|
|
37
|
+
type: "string",
|
|
38
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.load-env.description"),
|
|
39
|
+
required: false
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
action: async (engineCore, envVars, params) => tenantImport(engineCore, envVars, params)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Command for importing a tenant.
|
|
47
|
+
* @param engineCore The engine core.
|
|
48
|
+
* @param envVars The environment variables for the node.
|
|
49
|
+
* @param params The parameters for the command.
|
|
50
|
+
* @param params.apiKey The api key to import.
|
|
51
|
+
* @param params.tenantId The tenant ID to import the api key to.
|
|
52
|
+
* @param params.label The label for the api key.
|
|
53
|
+
*/
|
|
54
|
+
export async function tenantImport(engineCore, envVars, params) {
|
|
55
|
+
Guards.stringHexLength("tenantImport", "tenant-id", params.tenantId, 32);
|
|
56
|
+
Guards.stringHexLength("tenantImport", "api-key", params.apiKey, 32);
|
|
57
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
58
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
59
|
+
throw new GeneralError("tenantImport", "tenantAdminComponentNotRegistered");
|
|
60
|
+
}
|
|
61
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
62
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.importing"));
|
|
63
|
+
CLIDisplay.spinnerStart();
|
|
64
|
+
const apiKey = params.apiKey;
|
|
65
|
+
const tenantId = params.tenantId;
|
|
66
|
+
const label = params.label ?? "";
|
|
67
|
+
await tenantAdminService.set({
|
|
68
|
+
id: tenantId,
|
|
69
|
+
apiKey,
|
|
70
|
+
dateCreated: new Date(Date.now()).toISOString(),
|
|
71
|
+
label
|
|
72
|
+
});
|
|
73
|
+
CLIDisplay.spinnerStop();
|
|
74
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.imported"));
|
|
75
|
+
CLIDisplay.break();
|
|
76
|
+
CLIDisplay.done();
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=tenantImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantImport.js","sourceRoot":"","sources":["../../../src/commands/tenantImport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAKlF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC9E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC;QACtE,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,WAAW;gBAChB,IAAI,EAAE,QAAQ;gBACd,YAAY,EAAE,SAAS;gBACvB,WAAW,EAAE,IAAI,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BAA+B,CAC/B,CAAC;IAEF,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,kDAAkD,CAAC,CAAC,CAAC;IACxF,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IAEjC,MAAM,kBAAkB,CAAC,GAAG,CAAC;QAC5B,EAAE,EAAE,QAAQ;QACZ,MAAM;QACN,WAAW,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;QAC/C,KAAK;KACL,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-tenant-processor\";\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 type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantImport(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-import.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.api-key.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-import.params.label.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to import.\n * @param params.tenantId The tenant ID to import the api key to.\n * @param params.label The label for the api key.\n */\nexport async function tenantImport(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"tenantImport\", \"tenant-id\", params.tenantId, 32);\n\tGuards.stringHexLength(\"tenantImport\", \"api-key\", params.apiKey, 32);\n\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\tthrow new GeneralError(\"tenantImport\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-import.labels.importing\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst apiKey = params.apiKey;\n\tconst tenantId = params.tenantId;\n\tconst label = params.label ?? \"\";\n\n\tawait tenantAdminService.set({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\tlabel\n\t});\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-import.labels.imported\"));\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { PasswordHelper } from "@twin.org/api-auth-entity-storage-service";
|
|
4
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
5
|
+
import { Converter, GeneralError, Guards, I18n, Is, RandomHelper } from "@twin.org/core";
|
|
6
|
+
import { PasswordGenerator } from "@twin.org/crypto";
|
|
7
|
+
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
8
|
+
import { Did, IdentityProfileConnectorFactory } from "@twin.org/identity-models";
|
|
9
|
+
const COMMAND_NAME = "user-create";
|
|
10
|
+
/**
|
|
11
|
+
* Get the command definition parameters.
|
|
12
|
+
* @param commandDefinitions The registered command definitions.
|
|
13
|
+
*/
|
|
14
|
+
export function getCommandDefinitionUserCreate(commandDefinitions) {
|
|
15
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
16
|
+
command: COMMAND_NAME,
|
|
17
|
+
description: I18n.formatMessage("node.cli.commands.user-create.description"),
|
|
18
|
+
example: I18n.formatMessage("node.cli.commands.user-create.example"),
|
|
19
|
+
params: [
|
|
20
|
+
{
|
|
21
|
+
key: "user-identity",
|
|
22
|
+
type: "string",
|
|
23
|
+
extendedType: "DID",
|
|
24
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.user-identity.description")
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
key: "organization-identity",
|
|
28
|
+
type: "string",
|
|
29
|
+
extendedType: "DID",
|
|
30
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.organization-identity.description")
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "email",
|
|
34
|
+
type: "string",
|
|
35
|
+
extendedType: "email",
|
|
36
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.email.description")
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: "password",
|
|
40
|
+
type: "string",
|
|
41
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.password.description"),
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "given-name",
|
|
46
|
+
type: "string",
|
|
47
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.given-name.description"),
|
|
48
|
+
required: false
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
key: "family-name",
|
|
52
|
+
type: "string",
|
|
53
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.family-name.description"),
|
|
54
|
+
required: false
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: "overwrite-mode",
|
|
58
|
+
type: "string",
|
|
59
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.overwrite-mode.description"),
|
|
60
|
+
options: ["skip", "overwrite", "error"],
|
|
61
|
+
defaultValue: "skip",
|
|
62
|
+
required: false
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: "load-env",
|
|
66
|
+
type: "string",
|
|
67
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.load-env.description"),
|
|
68
|
+
required: false
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: "output-json",
|
|
72
|
+
type: "string",
|
|
73
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.output-json.description"),
|
|
74
|
+
required: false
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "output-env",
|
|
78
|
+
type: "string",
|
|
79
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.output-env.description"),
|
|
80
|
+
required: false
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
key: "output-env-prefix",
|
|
84
|
+
type: "string",
|
|
85
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.output-env-prefix.description"),
|
|
86
|
+
required: false
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
action: async (engineCore, envVars, params) => userCreate(engineCore, envVars, params)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Command for creating a user.
|
|
94
|
+
* @param engineCore The engine core.
|
|
95
|
+
* @param envVars The environment variables for the node.
|
|
96
|
+
* @param params The parameters for the command.
|
|
97
|
+
* @param params.userIdentity The DID for the user.
|
|
98
|
+
* @param params.organizationIdentity The organization DID for the user.
|
|
99
|
+
* @param params.email The email for the user.
|
|
100
|
+
* @param params.password The password for the user.
|
|
101
|
+
* @param params.givenName The given name for the user.
|
|
102
|
+
* @param params.familyName The family name for the user.
|
|
103
|
+
* @param params.overwriteMode The mode to use when a user with the same identity already exists.
|
|
104
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
105
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
106
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
107
|
+
* @returns The created user details or undefined if skipped.
|
|
108
|
+
*/
|
|
109
|
+
export async function userCreate(engineCore, envVars, params) {
|
|
110
|
+
Did.guard("userCreate", "user-identity", params.userIdentity);
|
|
111
|
+
Did.guard("userCreate", "organization-identity", params.organizationIdentity);
|
|
112
|
+
Guards.email("userCreate", "email", params.email);
|
|
113
|
+
if (Is.stringValue(params.password) && params.password.length < 16) {
|
|
114
|
+
throw new GeneralError("userCreate", "passwordTooShort", { minLength: 16 });
|
|
115
|
+
}
|
|
116
|
+
const defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType("identityProfileConnector");
|
|
117
|
+
const identityProfileConnector = IdentityProfileConnectorFactory.get(defaultIdentityProfileConnectorType);
|
|
118
|
+
const authUserEntityStorage = EntityStorageConnectorFactory.get("authentication-user");
|
|
119
|
+
let createUser = true;
|
|
120
|
+
let existingUser;
|
|
121
|
+
try {
|
|
122
|
+
existingUser = await authUserEntityStorage.get(params.userIdentity, "identity");
|
|
123
|
+
}
|
|
124
|
+
catch { }
|
|
125
|
+
if (!Is.empty(existingUser)) {
|
|
126
|
+
if (params.overwriteMode === "error") {
|
|
127
|
+
throw new GeneralError("userCreate", "userAlreadyExists");
|
|
128
|
+
}
|
|
129
|
+
else if (params.overwriteMode === "skip") {
|
|
130
|
+
createUser = false;
|
|
131
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.skipping"));
|
|
132
|
+
}
|
|
133
|
+
else if (params.overwriteMode === "overwrite") {
|
|
134
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.overwriting"));
|
|
135
|
+
await authUserEntityStorage.remove(existingUser.email);
|
|
136
|
+
await identityProfileConnector.remove(existingUser.identity);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
let json;
|
|
140
|
+
if (createUser) {
|
|
141
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.creating"));
|
|
142
|
+
const generatedPassword = params.password ?? PasswordGenerator.generate(16);
|
|
143
|
+
const passwordBytes = Converter.utf8ToBytes(generatedPassword);
|
|
144
|
+
const saltBytes = RandomHelper.generate(16);
|
|
145
|
+
const hashedPassword = await PasswordHelper.hashPassword(passwordBytes, saltBytes);
|
|
146
|
+
const user = {
|
|
147
|
+
email: params.email,
|
|
148
|
+
password: hashedPassword,
|
|
149
|
+
salt: Converter.bytesToBase64(saltBytes),
|
|
150
|
+
identity: params.userIdentity,
|
|
151
|
+
organization: params.organizationIdentity
|
|
152
|
+
};
|
|
153
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.storingUser"));
|
|
154
|
+
await authUserEntityStorage.set(user);
|
|
155
|
+
const name = `${params.givenName ?? ""} ${params.familyName ?? ""}`.trim();
|
|
156
|
+
const publicProfile = {
|
|
157
|
+
"@context": "https://schema.org",
|
|
158
|
+
"@type": "Person",
|
|
159
|
+
name: name.length > 0 ? name : undefined
|
|
160
|
+
};
|
|
161
|
+
const privateProfile = {
|
|
162
|
+
"@context": "https://schema.org",
|
|
163
|
+
"@type": "Person",
|
|
164
|
+
givenName: params.givenName,
|
|
165
|
+
familyName: params.familyName,
|
|
166
|
+
email: params.email
|
|
167
|
+
};
|
|
168
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.storingProfile"));
|
|
169
|
+
await identityProfileConnector.create(params.userIdentity, publicProfile, privateProfile);
|
|
170
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.userCreated"));
|
|
171
|
+
CLIDisplay.break();
|
|
172
|
+
json = {
|
|
173
|
+
did: params.userIdentity,
|
|
174
|
+
organizationDid: params.organizationIdentity,
|
|
175
|
+
email: params.email,
|
|
176
|
+
password: generatedPassword,
|
|
177
|
+
givenName: params.givenName ?? "",
|
|
178
|
+
familyName: params.familyName ?? ""
|
|
179
|
+
};
|
|
180
|
+
if (Is.stringValue(params.outputJson)) {
|
|
181
|
+
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
182
|
+
}
|
|
183
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
184
|
+
await CLIUtils.writeEnvFile(params.outputEnv, [
|
|
185
|
+
`${params.outputEnvPrefix}DID="${params.userIdentity}"`,
|
|
186
|
+
`${params.outputEnvPrefix}ORGANIZATION_DID="${params.organizationIdentity}"`,
|
|
187
|
+
`${params.outputEnvPrefix}EMAIL="${params.email}"`,
|
|
188
|
+
`${params.outputEnvPrefix}PASSWORD="${generatedPassword}"`,
|
|
189
|
+
`${params.outputEnvPrefix}GIVEN_NAME="${params.givenName ?? ""}"`,
|
|
190
|
+
`${params.outputEnvPrefix}FAMILY_NAME="${params.familyName ?? ""}"`
|
|
191
|
+
], false);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
CLIDisplay.done();
|
|
195
|
+
return json;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=userCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userCreate.js","sourceRoot":"","sources":["../../../src/commands/userCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAA2B,cAAc,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAMjF,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,kBAE9C;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC;QAC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AM,CAAC,UAAU,IAAI,EAAE,GAAG;aACnE,EACD,KAAK,CACL,CAAC;QACH,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 { type AuthenticationUser, PasswordHelper } from \"@twin.org/api-auth-entity-storage-service\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, I18n, Is, RandomHelper } from \"@twin.org/core\";\nimport { PasswordGenerator } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { Did, IdentityProfileConnectorFactory } from \"@twin.org/identity-models\";\nimport { nameofKebabCase } from \"@twin.org/nameof\";\nimport type { Person, WithContext } from \"schema-dts\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"user-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionUserCreate(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.user-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.user-create.example\"),\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"user-identity\",\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.user-create.params.user-identity.description\"\n\t\t\t\t)\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"organization-identity\",\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.user-create.params.organization-identity.description\"\n\t\t\t\t)\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"email\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"email\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-create.params.email.description\")\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"password\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.password.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: \"given-name\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.given-name.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: \"family-name\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.family-name.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: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-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.user-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.user-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.user-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.user-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) => userCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a user.\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.userIdentity The DID for the user.\n * @param params.organizationIdentity The organization DID for the user.\n * @param params.email The email for the user.\n * @param params.password The password for the user.\n * @param params.givenName The given name for the user.\n * @param params.familyName The family name for the user.\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 user details or undefined if skipped.\n */\nexport async function userCreate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tuserIdentity?: string;\n\t\torganizationIdentity?: string;\n\t\temail?: string;\n\t\tpassword?: string;\n\t\tgivenName?: string;\n\t\tfamilyName?: 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\tdid: string;\n\t\t\torganizationDid: string;\n\t\t\temail: string;\n\t\t\tpassword: string;\n\t\t\tgivenName: string;\n\t\t\tfamilyName: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"userCreate\", \"user-identity\", params.userIdentity);\n\tDid.guard(\"userCreate\", \"organization-identity\", params.organizationIdentity);\n\tGuards.email(\"userCreate\", \"email\", params.email);\n\n\tif (Is.stringValue(params.password) && params.password.length < 16) {\n\t\tthrow new GeneralError(\"userCreate\", \"passwordTooShort\", { minLength: 16 });\n\t}\n\n\tconst defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityProfileConnector\"\n\t);\n\tconst identityProfileConnector = IdentityProfileConnectorFactory.get(\n\t\tdefaultIdentityProfileConnectorType\n\t);\n\n\tconst authUserEntityStorage =\n\t\tEntityStorageConnectorFactory.get<IEntityStorageConnector<AuthenticationUser>>(\n\t\t\tnameofKebabCase<AuthenticationUser>()\n\t\t);\n\n\tlet createUser = true;\n\n\tlet existingUser;\n\ttry {\n\t\texistingUser = await authUserEntityStorage.get(params.userIdentity, \"identity\");\n\t} catch {}\n\n\tif (!Is.empty(existingUser)) {\n\t\tif (params.overwriteMode === \"error\") {\n\t\t\tthrow new GeneralError(\"userCreate\", \"userAlreadyExists\");\n\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\tcreateUser = false;\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.skipping\"));\n\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.overwriting\"));\n\t\t\tawait authUserEntityStorage.remove(existingUser.email);\n\t\t\tawait identityProfileConnector.remove(existingUser.identity);\n\t\t}\n\t}\n\n\tlet json;\n\tif (createUser) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.creating\"));\n\n\t\tconst generatedPassword = params.password ?? PasswordGenerator.generate(16);\n\t\tconst passwordBytes = Converter.utf8ToBytes(generatedPassword);\n\t\tconst saltBytes = RandomHelper.generate(16);\n\t\tconst hashedPassword = await PasswordHelper.hashPassword(passwordBytes, saltBytes);\n\n\t\tconst user: AuthenticationUser = {\n\t\t\temail: params.email,\n\t\t\tpassword: hashedPassword,\n\t\t\tsalt: Converter.bytesToBase64(saltBytes),\n\t\t\tidentity: params.userIdentity,\n\t\t\torganization: params.organizationIdentity\n\t\t};\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.storingUser\"));\n\t\tawait authUserEntityStorage.set(user);\n\n\t\tconst name = `${params.givenName ?? \"\"} ${params.familyName ?? \"\"}`.trim();\n\t\tconst publicProfile: WithContext<Person> = {\n\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\"@type\": \"Person\",\n\t\t\tname: name.length > 0 ? name : undefined\n\t\t};\n\t\tconst privateProfile: WithContext<Person> = {\n\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\"@type\": \"Person\",\n\t\t\tgivenName: params.givenName,\n\t\t\tfamilyName: params.familyName,\n\t\t\temail: params.email\n\t\t};\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.storingProfile\"));\n\t\tawait identityProfileConnector.create(params.userIdentity, publicProfile, privateProfile);\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.userCreated\"));\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tdid: params.userIdentity,\n\t\t\torganizationDid: params.organizationIdentity,\n\t\t\temail: params.email,\n\t\t\tpassword: generatedPassword,\n\t\t\tgivenName: params.givenName ?? \"\",\n\t\t\tfamilyName: params.familyName ?? \"\"\n\t\t};\n\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\tawait CLIUtils.writeEnvFile(\n\t\t\t\tparams.outputEnv,\n\t\t\t\t[\n\t\t\t\t\t`${params.outputEnvPrefix}DID=\"${params.userIdentity}\"`,\n\t\t\t\t\t`${params.outputEnvPrefix}ORGANIZATION_DID=\"${params.organizationIdentity}\"`,\n\t\t\t\t\t`${params.outputEnvPrefix}EMAIL=\"${params.email}\"`,\n\t\t\t\t\t`${params.outputEnvPrefix}PASSWORD=\"${generatedPassword}\"`,\n\t\t\t\t\t`${params.outputEnvPrefix}GIVEN_NAME=\"${params.givenName ?? \"\"}\"`,\n\t\t\t\t\t`${params.outputEnvPrefix}FAMILY_NAME=\"${params.familyName ?? \"\"}\"`\n\t\t\t\t],\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|