@twin.org/node-core 0.0.3-next.2 → 0.0.3-next.21
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 +168 -105
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +49 -25
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/cli.js +247 -0
- package/dist/es/cli.js.map +1 -0
- package/dist/es/commands/bootstrapLegacy.js +183 -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 +316 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityImports.js +82 -0
- package/dist/es/commands/identityImports.js.map +1 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodCreate.js +214 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js +126 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
- package/dist/es/commands/nodeSetIdentity.js +64 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -0
- package/dist/es/commands/nodeSetTenant.js +68 -0
- package/dist/es/commands/nodeSetTenant.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +139 -0
- package/dist/es/commands/tenantCreate.js.map +1 -0
- package/dist/es/commands/tenantImport.js +97 -0
- package/dist/es/commands/tenantImport.js.map +1 -0
- package/dist/es/commands/tenantUpdate.js +94 -0
- package/dist/es/commands/tenantUpdate.js.map +1 -0
- package/dist/es/commands/userCreate.js +212 -0
- package/dist/es/commands/userCreate.js.map +1 -0
- package/dist/es/commands/userUpdate.js +132 -0
- package/dist/es/commands/userUpdate.js.map +1 -0
- package/dist/es/commands/vaultKeyCreate.js +191 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -0
- package/dist/es/commands/vaultKeyImport.js +104 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -0
- package/dist/es/defaults.js +19 -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/IEngineServerEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeEngineState.js.map +1 -1
- package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeOptions.js.map +1 -1
- package/dist/es/models/cliCommandParamType.js +4 -0
- package/dist/es/models/cliCommandParamType.js.map +1 -0
- package/dist/es/node.js +78 -41
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +139 -0
- package/dist/es/start.js.map +1 -0
- package/dist/es/utils.js +11 -21
- 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 +56 -0
- package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
- package/dist/types/commands/help.d.ts +23 -0
- package/dist/types/commands/identityCreate.d.ts +39 -0
- package/dist/types/commands/identityImports.d.ts +24 -0
- package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
- package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
- package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
- package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
- package/dist/types/commands/nodeSetTenant.d.ts +22 -0
- package/dist/types/commands/tenantCreate.d.ts +38 -0
- package/dist/types/commands/tenantImport.d.ts +26 -0
- package/dist/types/commands/tenantUpdate.d.ts +26 -0
- package/dist/types/commands/userCreate.d.ts +49 -0
- package/dist/types/commands/userUpdate.d.ts +38 -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 +62 -53
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
- package/dist/types/models/INodeEngineState.d.ts +0 -8
- package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
- package/dist/types/models/INodeOptions.d.ts +6 -2
- package/dist/types/models/cliCommandParamType.d.ts +4 -0
- package/dist/types/node.d.ts +8 -4
- package/dist/types/{server.d.ts → start.d.ts} +7 -2
- package/dist/types/utils.d.ts +6 -8
- package/docs/changelog.md +136 -0
- package/docs/reference/functions/buildConfiguration.md +3 -3
- 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/getScriptDirectory.md +19 -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 +8 -2
- package/docs/reference/functions/start.md +10 -4
- package/docs/reference/functions/substituteEnvOptions.md +25 -0
- package/docs/reference/index.md +16 -13
- 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 +110 -85
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +166 -117
- package/docs/reference/interfaces/INodeEngineState.md +0 -16
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +170 -201
- package/docs/reference/interfaces/INodeOptions.md +10 -2
- 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/TRUST_VERIFICATION_METHOD_ID.md +3 -0
- package/locales/en.json +589 -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 -78
- 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
- package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { TenantIdHelper } from "@twin.org/api-tenant-processor";
|
|
2
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
3
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
4
|
+
const COMMAND_NAME = "tenant-create";
|
|
5
|
+
/**
|
|
6
|
+
* Get the command definition parameters.
|
|
7
|
+
* @param commandDefinitions The registered command definitions.
|
|
8
|
+
*/
|
|
9
|
+
export function getCommandDefinitionTenantCreate(commandDefinitions) {
|
|
10
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
11
|
+
command: COMMAND_NAME,
|
|
12
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.description"),
|
|
13
|
+
example: I18n.formatMessage("node.cli.commands.tenant-create.example"),
|
|
14
|
+
requiresTenantId: false,
|
|
15
|
+
params: [
|
|
16
|
+
{
|
|
17
|
+
key: "env-prefix",
|
|
18
|
+
type: "string",
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.env-prefix.description"),
|
|
20
|
+
required: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "tenant-id",
|
|
24
|
+
type: "string",
|
|
25
|
+
extendedType: "hex(32)",
|
|
26
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.tenant-id.description"),
|
|
27
|
+
required: false
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: "api-key",
|
|
31
|
+
type: "string",
|
|
32
|
+
extendedType: "hex(32)",
|
|
33
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.api-key.description"),
|
|
34
|
+
required: false
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: "public-origin",
|
|
38
|
+
type: "string",
|
|
39
|
+
extendedType: "url",
|
|
40
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.public-origin.description"),
|
|
41
|
+
required: false
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: "label",
|
|
45
|
+
type: "string",
|
|
46
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.label.description"),
|
|
47
|
+
required: false
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: "load-env",
|
|
51
|
+
type: "string",
|
|
52
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.load-env.description"),
|
|
53
|
+
required: false
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key: "output-json",
|
|
57
|
+
type: "string",
|
|
58
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-json.description"),
|
|
59
|
+
required: false
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
key: "output-env",
|
|
63
|
+
type: "string",
|
|
64
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-env.description"),
|
|
65
|
+
required: false
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "output-env-prefix",
|
|
69
|
+
type: "string",
|
|
70
|
+
description: I18n.formatMessage("node.cli.commands.tenant-create.params.output-env-prefix.description"),
|
|
71
|
+
required: false
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
action: async (engineCore, envVars, params) => tenantCreate(engineCore, envVars, params)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Command for creating a tenant.
|
|
79
|
+
* @param engineCore The engine core.
|
|
80
|
+
* @param envVars The environment variables for the node.
|
|
81
|
+
* @param params The parameters for the command.
|
|
82
|
+
* @param params.apiKey The api key to add.
|
|
83
|
+
* @param params.tenantId The tenant ID to add the api key to.
|
|
84
|
+
* @param params.label The label for the api key.
|
|
85
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
86
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
87
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
88
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
89
|
+
* @returns The created tenant details.
|
|
90
|
+
*/
|
|
91
|
+
export async function tenantCreate(engineCore, envVars, params) {
|
|
92
|
+
if (Is.stringValue(params.tenantId)) {
|
|
93
|
+
Guards.stringHexLength("tenantCreate", "tenant-id", params.tenantId, 32);
|
|
94
|
+
}
|
|
95
|
+
if (Is.stringValue(params.apiKey)) {
|
|
96
|
+
Guards.stringHexLength("tenantCreate", "api-key", params.apiKey, 32);
|
|
97
|
+
}
|
|
98
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
99
|
+
Url.guard("tenantCreate", "public-origin", params.publicOrigin);
|
|
100
|
+
}
|
|
101
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
102
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
103
|
+
throw new GeneralError("tenantCreate", "tenantAdminComponentNotRegistered");
|
|
104
|
+
}
|
|
105
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
106
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-create.labels.creating"));
|
|
107
|
+
const apiKey = params.apiKey ?? TenantIdHelper.generateApiKey();
|
|
108
|
+
const tenantId = params.tenantId ?? TenantIdHelper.generateTenantId();
|
|
109
|
+
const label = params.label ?? "";
|
|
110
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
111
|
+
await tenantAdminService.create({
|
|
112
|
+
id: tenantId,
|
|
113
|
+
apiKey,
|
|
114
|
+
label,
|
|
115
|
+
publicOrigin,
|
|
116
|
+
isNodeTenant: false
|
|
117
|
+
});
|
|
118
|
+
CLIDisplay.break();
|
|
119
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.tenantId"), tenantId);
|
|
120
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.apiKey"), apiKey);
|
|
121
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.label"), label);
|
|
122
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.tenant-create.labels.publicOrigin"), publicOrigin);
|
|
123
|
+
CLIDisplay.break();
|
|
124
|
+
const json = { apiKey, tenantId, label, publicOrigin };
|
|
125
|
+
if (Is.stringValue(params.outputJson)) {
|
|
126
|
+
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
127
|
+
}
|
|
128
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
129
|
+
await CLIUtils.writeEnvFile(params.outputEnv, [
|
|
130
|
+
`${params.outputEnvPrefix}API_KEY="${apiKey}"`,
|
|
131
|
+
`${params.outputEnvPrefix}TENANT_ID="${tenantId}"`,
|
|
132
|
+
`${params.outputEnvPrefix}LABEL="${label}"`,
|
|
133
|
+
`${params.outputEnvPrefix}PUBLIC_ORIGIN="${publicOrigin}"`
|
|
134
|
+
], false);
|
|
135
|
+
}
|
|
136
|
+
CLIDisplay.done();
|
|
137
|
+
return json;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=tenantCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantCreate.js","sourceRoot":"","sources":["../../../src/commands/tenantCreate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAKvF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;Q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C,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\trequiresTenantId: 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.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\tisNodeTenant: false\n\t});\n\n\tCLIDisplay.break();\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.tenantId\"), tenantId);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.apiKey\"), apiKey);\n\tCLIDisplay.value(I18n.formatMessage(\"node.cli.commands.tenant-create.labels.label\"), label);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.tenant-create.labels.publicOrigin\"),\n\t\tpublicOrigin\n\t);\n\tCLIDisplay.break();\n\n\tconst json = { apiKey, tenantId, label, publicOrigin };\n\tif (Is.stringValue(params.outputJson)) {\n\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t}\n\n\tif (Is.stringValue(params.outputEnv)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\tparams.outputEnv,\n\t\t\t[\n\t\t\t\t`${params.outputEnvPrefix}API_KEY=\"${apiKey}\"`,\n\t\t\t\t`${params.outputEnvPrefix}TENANT_ID=\"${tenantId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}LABEL=\"${label}\"`,\n\t\t\t\t`${params.outputEnvPrefix}PUBLIC_ORIGIN=\"${publicOrigin}\"`\n\t\t\t],\n\t\t\tfalse\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-import";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantImport(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-import.example"),
|
|
13
|
+
requiresTenantId: false,
|
|
14
|
+
params: [
|
|
15
|
+
{
|
|
16
|
+
key: "env-prefix",
|
|
17
|
+
type: "string",
|
|
18
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.env-prefix.description"),
|
|
19
|
+
required: false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: "tenant-id",
|
|
23
|
+
type: "string",
|
|
24
|
+
extendedType: "hex(32)",
|
|
25
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.tenant-id.description"),
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "api-key",
|
|
30
|
+
type: "string",
|
|
31
|
+
extendedType: "hex(32)",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.api-key.description"),
|
|
33
|
+
required: true
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "label",
|
|
37
|
+
type: "string",
|
|
38
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.label.description"),
|
|
39
|
+
required: false
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: "public-origin",
|
|
43
|
+
type: "string",
|
|
44
|
+
extendedType: "url",
|
|
45
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.public-origin.description"),
|
|
46
|
+
required: false
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "load-env",
|
|
50
|
+
type: "string",
|
|
51
|
+
description: I18n.formatMessage("node.cli.commands.tenant-import.params.load-env.description"),
|
|
52
|
+
required: false
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
action: async (engineCore, envVars, params) => tenantImport(engineCore, envVars, params)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Command for importing a tenant.
|
|
60
|
+
* @param engineCore The engine core.
|
|
61
|
+
* @param envVars The environment variables for the node.
|
|
62
|
+
* @param params The parameters for the command.
|
|
63
|
+
* @param params.apiKey The api key to import.
|
|
64
|
+
* @param params.tenantId The tenant ID to import the api key to.
|
|
65
|
+
* @param params.label The label for the api key.
|
|
66
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
67
|
+
*/
|
|
68
|
+
export async function tenantImport(engineCore, envVars, params) {
|
|
69
|
+
Guards.stringHexLength("tenantImport", "tenant-id", params.tenantId, 32);
|
|
70
|
+
Guards.stringHexLength("tenantImport", "api-key", params.apiKey, 32);
|
|
71
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
72
|
+
Url.guard("tenantImport", "public-origin", params.publicOrigin);
|
|
73
|
+
}
|
|
74
|
+
const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceTypeOptional("tenantAdminComponent");
|
|
75
|
+
if (!Is.stringValue(tenantAdminServiceComponentType)) {
|
|
76
|
+
throw new GeneralError("tenantImport", "tenantAdminComponentNotRegistered");
|
|
77
|
+
}
|
|
78
|
+
const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
|
|
79
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.importing"));
|
|
80
|
+
CLIDisplay.spinnerStart();
|
|
81
|
+
const apiKey = params.apiKey;
|
|
82
|
+
const tenantId = params.tenantId;
|
|
83
|
+
const label = params.label ?? "";
|
|
84
|
+
const publicOrigin = params.publicOrigin ?? "";
|
|
85
|
+
await tenantAdminService.create({
|
|
86
|
+
id: tenantId,
|
|
87
|
+
apiKey,
|
|
88
|
+
label,
|
|
89
|
+
publicOrigin,
|
|
90
|
+
isNodeTenant: false
|
|
91
|
+
});
|
|
92
|
+
CLIDisplay.spinnerStop();
|
|
93
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-import.labels.imported"));
|
|
94
|
+
CLIDisplay.break();
|
|
95
|
+
CLIDisplay.done();
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=tenantImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantImport.js","sourceRoot":"","sources":["../../../src/commands/tenantImport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAKvF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC;QAC9E,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,yCAAyC,CAAC;QACtE,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAA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 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantImport(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-import.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.api-key.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-import.params.label.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"public-origin\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"url\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.public-origin.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-import.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to import.\n * @param params.tenantId The tenant ID to import the api key to.\n * @param params.label The label for the api key.\n * @param params.publicOrigin The public URL origin for the tenant.\n */\nexport async function tenantImport(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\tpublicOrigin?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"tenantImport\", \"tenant-id\", params.tenantId, 32);\n\tGuards.stringHexLength(\"tenantImport\", \"api-key\", params.apiKey, 32);\n\n\tif (Is.stringValue(params.publicOrigin)) {\n\t\tUrl.guard(\"tenantImport\", \"public-origin\", params.publicOrigin);\n\t}\n\n\tconst tenantAdminServiceComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(tenantAdminServiceComponentType)) {\n\t\tthrow new GeneralError(\"tenantImport\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\ttenantAdminServiceComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-import.labels.importing\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst apiKey = params.apiKey;\n\tconst tenantId = params.tenantId;\n\tconst label = params.label ?? \"\";\n\tconst publicOrigin = params.publicOrigin ?? \"\";\n\tawait tenantAdminService.create({\n\t\tid: tenantId,\n\t\tapiKey,\n\t\tlabel,\n\t\tpublicOrigin,\n\t\tisNodeTenant: false\n\t});\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-import.labels.imported\"));\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from "@twin.org/core";
|
|
3
|
+
const COMMAND_NAME = "tenant-update";
|
|
4
|
+
/**
|
|
5
|
+
* Get the command definition parameters.
|
|
6
|
+
* @param commandDefinitions The registered command definitions.
|
|
7
|
+
*/
|
|
8
|
+
export function getCommandDefinitionTenantUpdate(commandDefinitions) {
|
|
9
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
10
|
+
command: COMMAND_NAME,
|
|
11
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.description"),
|
|
12
|
+
example: I18n.formatMessage("node.cli.commands.tenant-update.example"),
|
|
13
|
+
requiresTenantId: false,
|
|
14
|
+
params: [
|
|
15
|
+
{
|
|
16
|
+
key: "env-prefix",
|
|
17
|
+
type: "string",
|
|
18
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.env-prefix.description"),
|
|
19
|
+
required: false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: "tenant-id",
|
|
23
|
+
type: "string",
|
|
24
|
+
extendedType: "hex(32)",
|
|
25
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.tenant-id.description"),
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "api-key",
|
|
30
|
+
type: "string",
|
|
31
|
+
extendedType: "hex(32)",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.api-key.description"),
|
|
33
|
+
required: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "label",
|
|
37
|
+
type: "string",
|
|
38
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.label.description"),
|
|
39
|
+
required: false
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: "public-origin",
|
|
43
|
+
type: "string",
|
|
44
|
+
extendedType: "url",
|
|
45
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.public-origin.description"),
|
|
46
|
+
required: false
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "load-env",
|
|
50
|
+
type: "string",
|
|
51
|
+
description: I18n.formatMessage("node.cli.commands.tenant-update.params.load-env.description"),
|
|
52
|
+
required: false
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
action: async (engineCore, envVars, params) => tenantUpdate(engineCore, envVars, params)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Command for updating a tenant.
|
|
60
|
+
* @param engineCore The engine core.
|
|
61
|
+
* @param envVars The environment variables for the node.
|
|
62
|
+
* @param params The parameters for the command.
|
|
63
|
+
* @param params.apiKey The api key to update.
|
|
64
|
+
* @param params.tenantId The tenant ID to update the api key to.
|
|
65
|
+
* @param params.label The label for the api key.
|
|
66
|
+
* @param params.publicOrigin The public URL origin for the tenant.
|
|
67
|
+
*/
|
|
68
|
+
export async function tenantUpdate(engineCore, envVars, params) {
|
|
69
|
+
Guards.stringHexLength("tenantUpdate", "tenant-id", params.tenantId, 32);
|
|
70
|
+
if (Is.stringValue(params.apiKey)) {
|
|
71
|
+
Guards.stringHexLength("tenantUpdate", "api-key", params.apiKey, 32);
|
|
72
|
+
}
|
|
73
|
+
if (Is.stringValue(params.publicOrigin)) {
|
|
74
|
+
Url.guard("tenantUpdate", "public-origin", params.publicOrigin);
|
|
75
|
+
}
|
|
76
|
+
const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceType("tenantAdminComponent");
|
|
77
|
+
if (!Is.stringValue(defaultTenantAdminComponentType)) {
|
|
78
|
+
throw new GeneralError("tenantUpdate", "tenantAdminComponentNotRegistered");
|
|
79
|
+
}
|
|
80
|
+
const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
|
|
81
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updating"));
|
|
82
|
+
CLIDisplay.spinnerStart();
|
|
83
|
+
await tenantAdminComponent.update({
|
|
84
|
+
id: params.tenantId,
|
|
85
|
+
apiKey: params.apiKey,
|
|
86
|
+
label: params.label,
|
|
87
|
+
publicOrigin: params.publicOrigin
|
|
88
|
+
});
|
|
89
|
+
CLIDisplay.spinnerStop();
|
|
90
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.tenant-update.labels.updated"));
|
|
91
|
+
CLIDisplay.break();
|
|
92
|
+
CLIDisplay.done();
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=tenantUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenantUpdate.js","sourceRoot":"","sources":["../../../src/commands/tenantUpdate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAKvF,MAAM,YAAY,GAAG,eAAe,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAAC,kBAEhD;IACA,kBAAkB,CAAC,YAAY,CAA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C;IACzB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC,CAAC,CAAC;IAEtF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is, Url } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"tenant-update\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionTenantUpdate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-update.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.tenant-update.example\"),\n\t\trequiresTenantId: 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.tenant-update.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"api-key\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.api-key.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"label\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.tenant-update.params.label.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"public-origin\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"url\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.public-origin.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.tenant-update.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => tenantUpdate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for updating a tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.apiKey The api key to update.\n * @param params.tenantId The tenant ID to update the api key to.\n * @param params.label The label for the api key.\n * @param params.publicOrigin The public URL origin for the tenant.\n */\nexport async function tenantUpdate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tapiKey?: string;\n\t\ttenantId?: string;\n\t\tlabel?: string;\n\t\tpublicOrigin?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"tenantUpdate\", \"tenant-id\", params.tenantId, 32);\n\n\tif (Is.stringValue(params.apiKey)) {\n\t\tGuards.stringHexLength(\"tenantUpdate\", \"api-key\", params.apiKey, 32);\n\t}\n\n\tif (Is.stringValue(params.publicOrigin)) {\n\t\tUrl.guard(\"tenantUpdate\", \"public-origin\", params.publicOrigin);\n\t}\n\n\tconst defaultTenantAdminComponentType =\n\t\tengineCore.getRegisteredInstanceType(\"tenantAdminComponent\");\n\n\tif (!Is.stringValue(defaultTenantAdminComponentType)) {\n\t\tthrow new GeneralError(\"tenantUpdate\", \"tenantAdminComponentNotRegistered\");\n\t}\n\n\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(\n\t\tdefaultTenantAdminComponentType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-update.labels.updating\"));\n\tCLIDisplay.spinnerStart();\n\n\tawait tenantAdminComponent.update({\n\t\tid: params.tenantId,\n\t\tapiKey: params.apiKey,\n\t\tlabel: params.label,\n\t\tpublicOrigin: params.publicOrigin\n\t});\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.tenant-update.labels.updated\"));\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { PasswordGenerator } from "@twin.org/crypto";
|
|
4
|
+
import { Did, IdentityProfileConnectorFactory } from "@twin.org/identity-models";
|
|
5
|
+
const COMMAND_NAME = "user-create";
|
|
6
|
+
/**
|
|
7
|
+
* Get the command definition parameters.
|
|
8
|
+
* @param commandDefinitions The registered command definitions.
|
|
9
|
+
*/
|
|
10
|
+
export function getCommandDefinitionUserCreate(commandDefinitions) {
|
|
11
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
12
|
+
command: COMMAND_NAME,
|
|
13
|
+
description: I18n.formatMessage("node.cli.commands.user-create.description"),
|
|
14
|
+
example: I18n.formatMessage("node.cli.commands.user-create.example"),
|
|
15
|
+
params: [
|
|
16
|
+
{
|
|
17
|
+
key: "env-prefix",
|
|
18
|
+
type: "string",
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.env-prefix.description"),
|
|
20
|
+
required: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "user-identity",
|
|
24
|
+
type: "string",
|
|
25
|
+
extendedType: "DID",
|
|
26
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.user-identity.description")
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "organization-identity",
|
|
30
|
+
type: "string",
|
|
31
|
+
extendedType: "DID",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.organization-identity.description")
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "email",
|
|
36
|
+
type: "string",
|
|
37
|
+
extendedType: "email",
|
|
38
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.email.description")
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "password",
|
|
42
|
+
type: "string",
|
|
43
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.password.description"),
|
|
44
|
+
required: false
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
key: "scope",
|
|
48
|
+
type: "string",
|
|
49
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.scope.description"),
|
|
50
|
+
required: false
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: "given-name",
|
|
54
|
+
type: "string",
|
|
55
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.given-name.description"),
|
|
56
|
+
required: false
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "family-name",
|
|
60
|
+
type: "string",
|
|
61
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.family-name.description"),
|
|
62
|
+
required: false
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: "overwrite-mode",
|
|
66
|
+
type: "string",
|
|
67
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.overwrite-mode.description"),
|
|
68
|
+
options: ["skip", "overwrite", "error"],
|
|
69
|
+
defaultValue: "skip",
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "load-env",
|
|
74
|
+
type: "string",
|
|
75
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.load-env.description"),
|
|
76
|
+
required: false
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "output-json",
|
|
80
|
+
type: "string",
|
|
81
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.output-json.description"),
|
|
82
|
+
required: false
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "output-env",
|
|
86
|
+
type: "string",
|
|
87
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.output-env.description"),
|
|
88
|
+
required: false
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
key: "output-env-prefix",
|
|
92
|
+
type: "string",
|
|
93
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.output-env-prefix.description"),
|
|
94
|
+
required: false
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
action: async (engineCore, envVars, params) => userCreate(engineCore, envVars, params)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Command for creating a user.
|
|
102
|
+
* @param engineCore The engine core.
|
|
103
|
+
* @param envVars The environment variables for the node.
|
|
104
|
+
* @param params The parameters for the command.
|
|
105
|
+
* @param params.userIdentity The DID for the user.
|
|
106
|
+
* @param params.organizationIdentity The organization DID for the user.
|
|
107
|
+
* @param params.email The email for the user.
|
|
108
|
+
* @param params.password The password for the user.
|
|
109
|
+
* @param params.scope The scope for the user.
|
|
110
|
+
* @param params.givenName The given name for the user.
|
|
111
|
+
* @param params.familyName The family name for the user.
|
|
112
|
+
* @param params.overwriteMode The mode to use when a user with the same identity already exists.
|
|
113
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
114
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
115
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
116
|
+
* @returns The created user details or undefined if skipped.
|
|
117
|
+
*/
|
|
118
|
+
export async function userCreate(engineCore, envVars, params) {
|
|
119
|
+
Guards.email("userCreate", "email", params.email);
|
|
120
|
+
Did.guard("userCreate", "user-identity", params.userIdentity);
|
|
121
|
+
Did.guard("userCreate", "organization-identity", params.organizationIdentity);
|
|
122
|
+
if (Is.stringValue(params.password) && params.password.length < 16) {
|
|
123
|
+
throw new GeneralError("userCreate", "passwordTooShort", { minLength: 16 });
|
|
124
|
+
}
|
|
125
|
+
const defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType("identityProfileConnector");
|
|
126
|
+
const identityProfileConnector = IdentityProfileConnectorFactory.get(defaultIdentityProfileConnectorType);
|
|
127
|
+
const defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType("authenticationAdminComponent");
|
|
128
|
+
const authenticationAdminComponent = ComponentFactory.get(defaultAuthenticationAdminComponentType);
|
|
129
|
+
let createUser = true;
|
|
130
|
+
let existingUser;
|
|
131
|
+
try {
|
|
132
|
+
existingUser = await authenticationAdminComponent.get(params.email);
|
|
133
|
+
}
|
|
134
|
+
catch { }
|
|
135
|
+
if (!Is.empty(existingUser)) {
|
|
136
|
+
if (params.overwriteMode === "error") {
|
|
137
|
+
throw new GeneralError("userCreate", "userAlreadyExists");
|
|
138
|
+
}
|
|
139
|
+
else if (params.overwriteMode === "skip") {
|
|
140
|
+
createUser = false;
|
|
141
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.skipping"));
|
|
142
|
+
}
|
|
143
|
+
else if (params.overwriteMode === "overwrite") {
|
|
144
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.overwriting"));
|
|
145
|
+
await authenticationAdminComponent.remove(existingUser.email);
|
|
146
|
+
await identityProfileConnector.remove(existingUser.userIdentity);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
let json;
|
|
150
|
+
if (createUser) {
|
|
151
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.creating"));
|
|
152
|
+
const user = {
|
|
153
|
+
email: params.email,
|
|
154
|
+
password: params.password ?? PasswordGenerator.generate(16),
|
|
155
|
+
userIdentity: params.userIdentity,
|
|
156
|
+
organizationIdentity: params.organizationIdentity,
|
|
157
|
+
scope: params.scope?.split(",").map(s => s.trim()) ?? []
|
|
158
|
+
};
|
|
159
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.storingUser"));
|
|
160
|
+
if (existingUser) {
|
|
161
|
+
await authenticationAdminComponent.update(user);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
await authenticationAdminComponent.create(user);
|
|
165
|
+
}
|
|
166
|
+
const name = `${params.givenName ?? ""} ${params.familyName ?? ""}`.trim();
|
|
167
|
+
const publicProfile = {
|
|
168
|
+
"@context": "https://schema.org",
|
|
169
|
+
"@type": "Person",
|
|
170
|
+
name: name.length > 0 ? name : undefined
|
|
171
|
+
};
|
|
172
|
+
const privateProfile = {
|
|
173
|
+
"@context": "https://schema.org",
|
|
174
|
+
"@type": "Person",
|
|
175
|
+
givenName: params.givenName,
|
|
176
|
+
familyName: params.familyName,
|
|
177
|
+
email: params.email
|
|
178
|
+
};
|
|
179
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.storingProfile"));
|
|
180
|
+
await identityProfileConnector.create(params.userIdentity, publicProfile, privateProfile);
|
|
181
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.userCreated"));
|
|
182
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.user-create.labels.email"), user.email);
|
|
183
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.user-create.labels.password"), user.password);
|
|
184
|
+
CLIDisplay.break();
|
|
185
|
+
json = {
|
|
186
|
+
did: params.userIdentity,
|
|
187
|
+
organizationDid: params.organizationIdentity,
|
|
188
|
+
email: params.email,
|
|
189
|
+
password: user.password,
|
|
190
|
+
scope: params.scope?.split(",").map(s => s.trim()) ?? [],
|
|
191
|
+
givenName: params.givenName ?? "",
|
|
192
|
+
familyName: params.familyName ?? ""
|
|
193
|
+
};
|
|
194
|
+
if (Is.stringValue(params.outputJson)) {
|
|
195
|
+
await CLIUtils.writeJsonFile(params.outputJson, json, false);
|
|
196
|
+
}
|
|
197
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
198
|
+
await CLIUtils.writeEnvFile(params.outputEnv, [
|
|
199
|
+
`${params.outputEnvPrefix}DID="${params.userIdentity}"`,
|
|
200
|
+
`${params.outputEnvPrefix}ORGANIZATION_DID="${params.organizationIdentity}"`,
|
|
201
|
+
`${params.outputEnvPrefix}EMAIL="${params.email}"`,
|
|
202
|
+
`${params.outputEnvPrefix}PASSWORD="${user.password}"`,
|
|
203
|
+
`${params.outputEnvPrefix}SCOPE="${params.scope ?? ""}"`,
|
|
204
|
+
`${params.outputEnvPrefix}GIVEN_NAME="${params.givenName ?? ""}"`,
|
|
205
|
+
`${params.outputEnvPrefix}FAMILY_NAME="${params.familyName ?? ""}"`
|
|
206
|
+
], false);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
CLIDisplay.done();
|
|
210
|
+
return json;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=userCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userCreate.js","sourceRoot":"","sources":["../../../src/commands/userCreate.ts"],"names":[],"mappings":"AAMA,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;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,GAAG,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAK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User\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport { PasswordGenerator } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityProfileConnectorFactory } from \"@twin.org/identity-models\";\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: \"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.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: \"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: \"scope\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-create.params.scope.description\"),\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.scope The scope 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\tscope?: 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\tscope: string[];\n\t\t\tgivenName: string;\n\t\t\tfamilyName: string;\n\t }\n\t| undefined\n> {\n\tGuards.email(\"userCreate\", \"email\", params.email);\n\tDid.guard(\"userCreate\", \"user-identity\", params.userIdentity);\n\tDid.guard(\"userCreate\", \"organization-identity\", params.organizationIdentity);\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 defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"authenticationAdminComponent\"\n\t);\n\tconst authenticationAdminComponent = ComponentFactory.get<IAuthenticationAdminComponent>(\n\t\tdefaultAuthenticationAdminComponentType\n\t);\n\n\tlet createUser = true;\n\n\tlet existingUser;\n\ttry {\n\t\texistingUser = await authenticationAdminComponent.get(params.email);\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 authenticationAdminComponent.remove(existingUser.email);\n\t\t\tawait identityProfileConnector.remove(existingUser.userIdentity);\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 user: Omit<IAuthenticationUser, \"salt\"> = {\n\t\t\temail: params.email,\n\t\t\tpassword: params.password ?? PasswordGenerator.generate(16),\n\t\t\tuserIdentity: params.userIdentity,\n\t\t\torganizationIdentity: params.organizationIdentity,\n\t\t\tscope: params.scope?.split(\",\").map(s => s.trim()) ?? []\n\t\t};\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.storingUser\"));\n\n\t\tif (existingUser) {\n\t\t\tawait authenticationAdminComponent.update(user);\n\t\t} else {\n\t\t\tawait authenticationAdminComponent.create(user);\n\t\t}\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.value(I18n.formatMessage(\"node.cli.commands.user-create.labels.email\"), user.email);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.user-create.labels.password\"),\n\t\t\tuser.password\n\t\t);\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: user.password,\n\t\t\tscope: params.scope?.split(\",\").map(s => s.trim()) ?? [],\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=\"${user.password}\"`,\n\t\t\t\t\t`${params.outputEnvPrefix}SCOPE=\"${params.scope ?? \"\"}\"`,\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"]}
|