@twin.org/node-core 0.0.3-next.16 â 0.0.3-next.18
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/cli.js +6 -16
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/bootstrapLegacy.js +9 -1
- package/dist/es/commands/bootstrapLegacy.js.map +1 -1
- package/dist/es/commands/identityCreate.js +6 -0
- package/dist/es/commands/identityCreate.js.map +1 -1
- package/dist/es/commands/identityImports.js +6 -0
- package/dist/es/commands/identityImports.js.map +1 -1
- package/dist/es/commands/identityVerifiableCredentialCreate.js +6 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodCreate.js +6 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodImport.js +6 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -1
- package/dist/es/commands/nodeSetIdentity.js +6 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -1
- package/dist/es/commands/nodeSetTenant.js +9 -6
- package/dist/es/commands/nodeSetTenant.js.map +1 -1
- package/dist/es/commands/tenantCreate.js +7 -2
- package/dist/es/commands/tenantCreate.js.map +1 -1
- package/dist/es/commands/tenantImport.js +7 -2
- package/dist/es/commands/tenantImport.js.map +1 -1
- package/dist/es/commands/tenantUpdate.js +12 -16
- package/dist/es/commands/tenantUpdate.js.map +1 -1
- package/dist/es/commands/userCreate.js +36 -21
- package/dist/es/commands/userCreate.js.map +1 -1
- package/dist/es/commands/userUpdate.js +132 -0
- package/dist/es/commands/userUpdate.js.map +1 -0
- package/dist/es/commands/vaultKeyCreate.js +6 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyImport.js +6 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -1
- package/dist/es/node.js +14 -6
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +11 -3
- package/dist/es/start.js.map +1 -1
- package/dist/types/cli.d.ts +0 -10
- package/dist/types/commands/userCreate.d.ts +3 -0
- package/dist/types/commands/userUpdate.d.ts +38 -0
- package/docs/changelog.md +14 -0
- package/docs/reference/index.md +0 -1
- package/locales/en.json +86 -5
- package/package.json +1 -1
- package/docs/reference/functions/initCli.md +0 -27
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
// Copyright 2026 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { PasswordHelper } from "@twin.org/api-auth-entity-storage-service";
|
|
4
1
|
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
5
|
-
import {
|
|
2
|
+
import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
6
3
|
import { PasswordGenerator } from "@twin.org/crypto";
|
|
7
|
-
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
8
4
|
import { Did, IdentityProfileConnectorFactory } from "@twin.org/identity-models";
|
|
9
5
|
const COMMAND_NAME = "user-create";
|
|
10
6
|
/**
|
|
@@ -17,6 +13,12 @@ export function getCommandDefinitionUserCreate(commandDefinitions) {
|
|
|
17
13
|
description: I18n.formatMessage("node.cli.commands.user-create.description"),
|
|
18
14
|
example: I18n.formatMessage("node.cli.commands.user-create.example"),
|
|
19
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
|
+
},
|
|
20
22
|
{
|
|
21
23
|
key: "user-identity",
|
|
22
24
|
type: "string",
|
|
@@ -41,6 +43,12 @@ export function getCommandDefinitionUserCreate(commandDefinitions) {
|
|
|
41
43
|
description: I18n.formatMessage("node.cli.commands.user-create.params.password.description"),
|
|
42
44
|
required: false
|
|
43
45
|
},
|
|
46
|
+
{
|
|
47
|
+
key: "scope",
|
|
48
|
+
type: "string",
|
|
49
|
+
description: I18n.formatMessage("node.cli.commands.user-create.params.scope.description"),
|
|
50
|
+
required: false
|
|
51
|
+
},
|
|
44
52
|
{
|
|
45
53
|
key: "given-name",
|
|
46
54
|
type: "string",
|
|
@@ -98,6 +106,7 @@ export function getCommandDefinitionUserCreate(commandDefinitions) {
|
|
|
98
106
|
* @param params.organizationIdentity The organization DID for the user.
|
|
99
107
|
* @param params.email The email for the user.
|
|
100
108
|
* @param params.password The password for the user.
|
|
109
|
+
* @param params.scope The scope for the user.
|
|
101
110
|
* @param params.givenName The given name for the user.
|
|
102
111
|
* @param params.familyName The family name for the user.
|
|
103
112
|
* @param params.overwriteMode The mode to use when a user with the same identity already exists.
|
|
@@ -107,19 +116,20 @@ export function getCommandDefinitionUserCreate(commandDefinitions) {
|
|
|
107
116
|
* @returns The created user details or undefined if skipped.
|
|
108
117
|
*/
|
|
109
118
|
export async function userCreate(engineCore, envVars, params) {
|
|
119
|
+
Guards.email("userCreate", "email", params.email);
|
|
110
120
|
Did.guard("userCreate", "user-identity", params.userIdentity);
|
|
111
121
|
Did.guard("userCreate", "organization-identity", params.organizationIdentity);
|
|
112
|
-
Guards.email("userCreate", "email", params.email);
|
|
113
122
|
if (Is.stringValue(params.password) && params.password.length < 16) {
|
|
114
123
|
throw new GeneralError("userCreate", "passwordTooShort", { minLength: 16 });
|
|
115
124
|
}
|
|
116
125
|
const defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType("identityProfileConnector");
|
|
117
126
|
const identityProfileConnector = IdentityProfileConnectorFactory.get(defaultIdentityProfileConnectorType);
|
|
118
|
-
const
|
|
127
|
+
const defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType("authenticationAdminComponent");
|
|
128
|
+
const authenticationAdminComponent = ComponentFactory.get(defaultAuthenticationAdminComponentType);
|
|
119
129
|
let createUser = true;
|
|
120
130
|
let existingUser;
|
|
121
131
|
try {
|
|
122
|
-
existingUser = await
|
|
132
|
+
existingUser = await authenticationAdminComponent.get(params.email);
|
|
123
133
|
}
|
|
124
134
|
catch { }
|
|
125
135
|
if (!Is.empty(existingUser)) {
|
|
@@ -132,26 +142,27 @@ export async function userCreate(engineCore, envVars, params) {
|
|
|
132
142
|
}
|
|
133
143
|
else if (params.overwriteMode === "overwrite") {
|
|
134
144
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.overwriting"));
|
|
135
|
-
await
|
|
136
|
-
await identityProfileConnector.remove(existingUser.
|
|
145
|
+
await authenticationAdminComponent.remove(existingUser.email);
|
|
146
|
+
await identityProfileConnector.remove(existingUser.userIdentity);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
let json;
|
|
140
150
|
if (createUser) {
|
|
141
151
|
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
152
|
const user = {
|
|
147
153
|
email: params.email,
|
|
148
|
-
password:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
password: params.password ?? PasswordGenerator.generate(16),
|
|
155
|
+
userIdentity: params.userIdentity,
|
|
156
|
+
organizationIdentity: params.organizationIdentity,
|
|
157
|
+
scope: params.scope?.split(",").map(s => s.trim()) ?? []
|
|
152
158
|
};
|
|
153
159
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.storingUser"));
|
|
154
|
-
|
|
160
|
+
if (existingUser) {
|
|
161
|
+
await authenticationAdminComponent.update(user);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
await authenticationAdminComponent.create(user);
|
|
165
|
+
}
|
|
155
166
|
const name = `${params.givenName ?? ""} ${params.familyName ?? ""}`.trim();
|
|
156
167
|
const publicProfile = {
|
|
157
168
|
"@context": "https://schema.org",
|
|
@@ -168,12 +179,15 @@ export async function userCreate(engineCore, envVars, params) {
|
|
|
168
179
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-create.labels.storingProfile"));
|
|
169
180
|
await identityProfileConnector.create(params.userIdentity, publicProfile, privateProfile);
|
|
170
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);
|
|
171
184
|
CLIDisplay.break();
|
|
172
185
|
json = {
|
|
173
186
|
did: params.userIdentity,
|
|
174
187
|
organizationDid: params.organizationIdentity,
|
|
175
188
|
email: params.email,
|
|
176
|
-
password:
|
|
189
|
+
password: user.password,
|
|
190
|
+
scope: params.scope?.split(",").map(s => s.trim()) ?? [],
|
|
177
191
|
givenName: params.givenName ?? "",
|
|
178
192
|
familyName: params.familyName ?? ""
|
|
179
193
|
};
|
|
@@ -185,7 +199,8 @@ export async function userCreate(engineCore, envVars, params) {
|
|
|
185
199
|
`${params.outputEnvPrefix}DID="${params.userIdentity}"`,
|
|
186
200
|
`${params.outputEnvPrefix}ORGANIZATION_DID="${params.organizationIdentity}"`,
|
|
187
201
|
`${params.outputEnvPrefix}EMAIL="${params.email}"`,
|
|
188
|
-
`${params.outputEnvPrefix}PASSWORD="${
|
|
202
|
+
`${params.outputEnvPrefix}PASSWORD="${user.password}"`,
|
|
203
|
+
`${params.outputEnvPrefix}SCOPE="${params.scope ?? ""}"`,
|
|
189
204
|
`${params.outputEnvPrefix}GIVEN_NAME="${params.givenName ?? ""}"`,
|
|
190
205
|
`${params.outputEnvPrefix}FAMILY_NAME="${params.familyName ?? ""}"`
|
|
191
206
|
], false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userCreate.js","sourceRoot":"","sources":["../../../src/commands/userCreate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AI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;YACvC,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;QAED,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,MAAM,QAAQ,CAAC,YAAY,CAC1B,MAAM,CAAC,SAAS,EAChB;gBACC,GAAG,MAAM,CAAC,eAAe,QAAQ,MAAM,CAAC,YAAY,GAAG;gBACvD,GAAG,MAAM,CAAC,eAAe,qBAAqB,MAAM,CAAC,oBAAoB,GAAG;gBAC5E,GAAG,MAAM,CAAC,eAAe,UAAU,MAAM,CAAC,KAAK,GAAG;gBAClD,GAAG,MAAM,CAAC,eAAe,aAAa,iBAAiB,GAAG;gBAC1D,GAAG,MAAM,CAAC,eAAe,eAAe,MAAM,CAAC,SAAS,IAAI,EAAE,GAAG;gBACjE,GAAG,MAAM,CAAC,eAAe,gBAAgB,MAAM,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"]}
|
|
1
|
+
{"version":3,"file":"userCreate.js","sourceRoot":"","sources":["../../../src/commands/userCreate.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;A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;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 {\n\tIAuthenticationAdminComponent,\n\tIAuthenticationUser\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"]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
2
|
+
import { ComponentFactory, Guards, I18n, Is } from "@twin.org/core";
|
|
3
|
+
import { Did, IdentityProfileConnectorFactory } from "@twin.org/identity-models";
|
|
4
|
+
const COMMAND_NAME = "user-update";
|
|
5
|
+
/**
|
|
6
|
+
* Get the command definition parameters.
|
|
7
|
+
* @param commandDefinitions The registered command definitions.
|
|
8
|
+
*/
|
|
9
|
+
export function getCommandDefinitionUserUpdate(commandDefinitions) {
|
|
10
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
11
|
+
command: COMMAND_NAME,
|
|
12
|
+
description: I18n.formatMessage("node.cli.commands.user-update.description"),
|
|
13
|
+
example: I18n.formatMessage("node.cli.commands.user-update.example"),
|
|
14
|
+
params: [
|
|
15
|
+
{
|
|
16
|
+
key: "env-prefix",
|
|
17
|
+
type: "string",
|
|
18
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.env-prefix.description"),
|
|
19
|
+
required: false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: "user-identity",
|
|
23
|
+
type: "string",
|
|
24
|
+
extendedType: "DID",
|
|
25
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.user-identity.description"),
|
|
26
|
+
required: false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "organization-identity",
|
|
30
|
+
type: "string",
|
|
31
|
+
extendedType: "DID",
|
|
32
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.organization-identity.description"),
|
|
33
|
+
required: false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: "email",
|
|
37
|
+
type: "string",
|
|
38
|
+
extendedType: "email",
|
|
39
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.email.description")
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: "scope",
|
|
43
|
+
type: "string",
|
|
44
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.scope.description"),
|
|
45
|
+
required: false
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "given-name",
|
|
49
|
+
type: "string",
|
|
50
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.given-name.description"),
|
|
51
|
+
required: false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: "family-name",
|
|
55
|
+
type: "string",
|
|
56
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.family-name.description"),
|
|
57
|
+
required: false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "load-env",
|
|
61
|
+
type: "string",
|
|
62
|
+
description: I18n.formatMessage("node.cli.commands.user-update.params.load-env.description"),
|
|
63
|
+
required: false
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
action: async (engineCore, envVars, params) => userUpdate(engineCore, envVars, params)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Command for creating a user.
|
|
71
|
+
* @param engineCore The engine core.
|
|
72
|
+
* @param envVars The environment variables for the node.
|
|
73
|
+
* @param params The parameters for the command.
|
|
74
|
+
* @param params.userIdentity The DID for the user.
|
|
75
|
+
* @param params.organizationIdentity The organization DID for the user.
|
|
76
|
+
* @param params.email The email for the user.
|
|
77
|
+
* @param params.scope The scope for the user.
|
|
78
|
+
* @param params.givenName The given name for the user.
|
|
79
|
+
* @param params.familyName The family name for the user.
|
|
80
|
+
* @returns The updated user details or undefined if skipped.
|
|
81
|
+
*/
|
|
82
|
+
export async function userUpdate(engineCore, envVars, params) {
|
|
83
|
+
Guards.email("userUpdate", "email", params.email);
|
|
84
|
+
if (Is.stringValue(params.userIdentity)) {
|
|
85
|
+
Did.guard("userUpdate", "user-identity", params.userIdentity);
|
|
86
|
+
}
|
|
87
|
+
if (Is.stringValue(params.organizationIdentity)) {
|
|
88
|
+
Did.guard("userUpdate", "organization-identity", params.organizationIdentity);
|
|
89
|
+
}
|
|
90
|
+
const defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType("identityProfileConnector");
|
|
91
|
+
const identityProfileConnector = IdentityProfileConnectorFactory.get(defaultIdentityProfileConnectorType);
|
|
92
|
+
const defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType("authenticationAdminComponent");
|
|
93
|
+
const authenticationAdminComponent = ComponentFactory.get(defaultAuthenticationAdminComponentType);
|
|
94
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.updating"));
|
|
95
|
+
const user = {
|
|
96
|
+
email: params.email,
|
|
97
|
+
userIdentity: params.userIdentity,
|
|
98
|
+
organizationIdentity: params.organizationIdentity,
|
|
99
|
+
scope: params.scope?.split(",").map(s => s.trim())
|
|
100
|
+
};
|
|
101
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.storingUser"));
|
|
102
|
+
const existingUser = await authenticationAdminComponent.get(params.email);
|
|
103
|
+
await authenticationAdminComponent.update(user);
|
|
104
|
+
const name = `${params.givenName ?? ""} ${params.familyName ?? ""}`.trim();
|
|
105
|
+
const publicProfile = {
|
|
106
|
+
"@context": "https://schema.org",
|
|
107
|
+
"@type": "Person",
|
|
108
|
+
name: name.length > 0 ? name : undefined
|
|
109
|
+
};
|
|
110
|
+
const privateProfile = {
|
|
111
|
+
"@context": "https://schema.org",
|
|
112
|
+
"@type": "Person",
|
|
113
|
+
givenName: params.givenName,
|
|
114
|
+
familyName: params.familyName,
|
|
115
|
+
email: params.email
|
|
116
|
+
};
|
|
117
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.storingProfile"));
|
|
118
|
+
await identityProfileConnector.update(existingUser.userIdentity, publicProfile, privateProfile);
|
|
119
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.userUpdated"));
|
|
120
|
+
CLIDisplay.break();
|
|
121
|
+
const json = {
|
|
122
|
+
did: params.userIdentity ?? existingUser.userIdentity,
|
|
123
|
+
organizationDid: params.organizationIdentity ?? existingUser.organizationIdentity,
|
|
124
|
+
email: params.email,
|
|
125
|
+
scope: params.scope?.split(",").map(s => s.trim()) ?? existingUser.scope,
|
|
126
|
+
givenName: params.givenName ?? "",
|
|
127
|
+
familyName: params.familyName ?? ""
|
|
128
|
+
};
|
|
129
|
+
CLIDisplay.done();
|
|
130
|
+
return json;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=userUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userUpdate.js","sourceRoot":"","sources":["../../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AAS,EAAE,MAAM,CAAC,SAAS;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;KACnB,CAAC;IAEF,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC,CAAC;IAC3F,MAAM,wBAAwB,CAAC,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;IAEhG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,kDAAkD,CAAC,CAAC,CAAC;IAExF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,MAAM,IAAI,GAAG;QACZ,GAAG,EAAE,MAAM,CAAC,YAAY,IAAI,YAAY,CAAC,YAAY;QACrD,eAAe,EAAE,MAAM,CAAC,oBAAoB,IAAI,YAAY,CAAC,oBAAoB;QACjF,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,YAAY,CAAC,KAAK;QACxE,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,EAAE;KACnC,CAAC;IAEF,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 {\n\tIAuthenticationAdminComponent,\n\tIAuthenticationUser\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, Guards, I18n, Is } from \"@twin.org/core\";\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-update\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionUserUpdate(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-update.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.user-update.example\"),\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-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: \"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-update.params.user-identity.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"organization-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-update.params.organization-identity.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: \"email\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"email\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-update.params.email.description\")\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-update.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-update.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-update.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: \"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-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) => userUpdate(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.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 * @returns The updated user details or undefined if skipped.\n */\nexport async function userUpdate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tuserIdentity?: string;\n\t\torganizationIdentity?: string;\n\t\temail?: string;\n\t\tscope?: string;\n\t\tgivenName?: string;\n\t\tfamilyName?: 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\tscope: string[];\n\t\t\tgivenName: string;\n\t\t\tfamilyName: string;\n\t }\n\t| undefined\n> {\n\tGuards.email(\"userUpdate\", \"email\", params.email);\n\n\tif (Is.stringValue(params.userIdentity)) {\n\t\tDid.guard(\"userUpdate\", \"user-identity\", params.userIdentity);\n\t}\n\tif (Is.stringValue(params.organizationIdentity)) {\n\t\tDid.guard(\"userUpdate\", \"organization-identity\", params.organizationIdentity);\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\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.updating\"));\n\n\tconst user: Partial<Omit<IAuthenticationUser, \"password\" | \"salt\">> = {\n\t\temail: params.email,\n\t\tuserIdentity: params.userIdentity,\n\t\torganizationIdentity: params.organizationIdentity,\n\t\tscope: params.scope?.split(\",\").map(s => s.trim())\n\t};\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.storingUser\"));\n\n\tconst existingUser = await authenticationAdminComponent.get(params.email);\n\n\tawait authenticationAdminComponent.update(user);\n\n\tconst name = `${params.givenName ?? \"\"} ${params.familyName ?? \"\"}`.trim();\n\tconst publicProfile: WithContext<Person> = {\n\t\t\"@context\": \"https://schema.org\",\n\t\t\"@type\": \"Person\",\n\t\tname: name.length > 0 ? name : undefined\n\t};\n\tconst privateProfile: WithContext<Person> = {\n\t\t\"@context\": \"https://schema.org\",\n\t\t\"@type\": \"Person\",\n\t\tgivenName: params.givenName,\n\t\tfamilyName: params.familyName,\n\t\temail: params.email\n\t};\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.storingProfile\"));\n\tawait identityProfileConnector.update(existingUser.userIdentity, publicProfile, privateProfile);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.userUpdated\"));\n\n\tCLIDisplay.break();\n\n\tconst json = {\n\t\tdid: params.userIdentity ?? existingUser.userIdentity,\n\t\torganizationDid: params.organizationIdentity ?? existingUser.organizationIdentity,\n\t\temail: params.email,\n\t\tscope: params.scope?.split(\",\").map(s => s.trim()) ?? existingUser.scope,\n\t\tgivenName: params.givenName ?? \"\",\n\t\tfamilyName: params.familyName ?? \"\"\n\t};\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -17,6 +17,12 @@ export function getCommandDefinitionVaultKeyCreate(commandDefinitions) {
|
|
|
17
17
|
requiresNodeIdentity: false,
|
|
18
18
|
requiresTenantId: false,
|
|
19
19
|
params: [
|
|
20
|
+
{
|
|
21
|
+
key: "env-prefix",
|
|
22
|
+
type: "string",
|
|
23
|
+
description: I18n.formatMessage("node.cli.commands.vault-key-create.params.env-prefix.description"),
|
|
24
|
+
required: false
|
|
25
|
+
},
|
|
20
26
|
{
|
|
21
27
|
key: "identity",
|
|
22
28
|
type: "string",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vaultKeyCreate.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM7E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE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,oBAAoB,aAAa,GAAG,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,mBAAmB,YAAY,GAAG,CAAC,CAAC;YAChF,CAAC;YACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"vault-key-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.vault-key-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\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.vault-key-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => vaultKeyCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a vault key.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.overwriteMode The mode to use when a user with the same identity already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created vault key details or undefined if skipped.\n */\nexport async function vaultKeyCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tidentity: string;\n\t\t\tkeyId: string;\n\t\t\tkeyType?: string;\n\t\t\tprivateKeyBase64?: string;\n\t\t\tpublicKeyBase64?: string;\n\t\t\tprivateKeyHex?: string;\n\t\t\tpublicKeyHex?: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"vaultKeyCreate\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyCreate\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyCreate\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createVaultKey = true;\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t} catch {}\n\n\tif (!Is.empty(existingKey)) {\n\t\tif (params.overwriteMode === \"error\") {\n\t\t\tthrow new GeneralError(\"vaultKeyCreate\", \"vaultKeyAlreadyExists\");\n\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\tcreateVaultKey = false;\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.skipping\"));\n\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.overwriting\"));\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t}\n\n\tlet json;\n\tif (createVaultKey) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.creating\"));\n\t\tCLIDisplay.spinnerStart();\n\n\t\tawait vaultConnector.createKey(\n\t\t\tfullKeyId,\n\t\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType]\n\t\t);\n\n\t\tconst key = await vaultConnector.getKey(fullKeyId);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.created\"));\n\n\t\tconst privateKeyBase64 = key.privateKey ? Converter.bytesToBase64(key.privateKey) : undefined;\n\t\tconst publicKeyBase64 = key.publicKey ? Converter.bytesToBase64(key.publicKey) : undefined;\n\t\tconst privateKeyHex = key.privateKey ? Converter.bytesToHex(key.privateKey, true) : undefined;\n\t\tconst publicKeyHex = key.publicKey ? Converter.bytesToHex(key.publicKey, true) : undefined;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyId\"),\n\t\t\tparams.keyId\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyType\"),\n\t\t\tparams.keyType\n\t\t);\n\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyBase64\"),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyBase64\"),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyHex\"),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyHex\"),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\t\t}\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tidentity: params.identity,\n\t\t\tkeyId: params.keyId,\n\t\t\tkeyType: params.keyType,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64,\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex\n\t\t};\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst outputParams = [\n\t\t\t\t`${params.outputEnvPrefix}IDENTITY=\"${params.identity}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_ID=\"${params.keyId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_TYPE=\"${params.keyType}\"`\n\t\t\t];\n\n\t\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_HEX=\"${privateKeyHex}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_HEX=\"${publicKeyHex}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, outputParams, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vaultKeyCreate.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM7E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAk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ACrC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,sBAAsB,eAAe,GAAG,CAAC,CAAC;YACtF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;gBACnC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,oBAAoB,aAAa,GAAG,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,mBAAmB,YAAY,GAAG,CAAC,CAAC;YAChF,CAAC;YACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"vault-key-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.vault-key-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\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.vault-key-create.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => vaultKeyCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a vault key.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.overwriteMode The mode to use when a user with the same identity already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created vault key details or undefined if skipped.\n */\nexport async function vaultKeyCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tidentity: string;\n\t\t\tkeyId: string;\n\t\t\tkeyType?: string;\n\t\t\tprivateKeyBase64?: string;\n\t\t\tpublicKeyBase64?: string;\n\t\t\tprivateKeyHex?: string;\n\t\t\tpublicKeyHex?: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"vaultKeyCreate\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyCreate\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyCreate\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createVaultKey = true;\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t} catch {}\n\n\tif (!Is.empty(existingKey)) {\n\t\tif (params.overwriteMode === \"error\") {\n\t\t\tthrow new GeneralError(\"vaultKeyCreate\", \"vaultKeyAlreadyExists\");\n\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\tcreateVaultKey = false;\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.skipping\"));\n\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.overwriting\"));\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t}\n\n\tlet json;\n\tif (createVaultKey) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.creating\"));\n\t\tCLIDisplay.spinnerStart();\n\n\t\tawait vaultConnector.createKey(\n\t\t\tfullKeyId,\n\t\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType]\n\t\t);\n\n\t\tconst key = await vaultConnector.getKey(fullKeyId);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.created\"));\n\n\t\tconst privateKeyBase64 = key.privateKey ? Converter.bytesToBase64(key.privateKey) : undefined;\n\t\tconst publicKeyBase64 = key.publicKey ? Converter.bytesToBase64(key.publicKey) : undefined;\n\t\tconst privateKeyHex = key.privateKey ? Converter.bytesToHex(key.privateKey, true) : undefined;\n\t\tconst publicKeyHex = key.publicKey ? Converter.bytesToHex(key.publicKey, true) : undefined;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyId\"),\n\t\t\tparams.keyId\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyType\"),\n\t\t\tparams.keyType\n\t\t);\n\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyBase64\"),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyBase64\"),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyHex\"),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyHex\"),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\t\t}\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tidentity: params.identity,\n\t\t\tkeyId: params.keyId,\n\t\t\tkeyType: params.keyType,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64,\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex\n\t\t};\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst outputParams = [\n\t\t\t\t`${params.outputEnvPrefix}IDENTITY=\"${params.identity}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_ID=\"${params.keyId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_TYPE=\"${params.keyType}\"`\n\t\t\t];\n\n\t\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_HEX=\"${privateKeyHex}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_HEX=\"${publicKeyHex}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, outputParams, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -18,6 +18,12 @@ export function getCommandDefinitionVaultKeyImport(commandDefinitions) {
|
|
|
18
18
|
requiresNodeIdentity: false,
|
|
19
19
|
requiresTenantId: false,
|
|
20
20
|
params: [
|
|
21
|
+
{
|
|
22
|
+
key: "env-prefix",
|
|
23
|
+
type: "string",
|
|
24
|
+
description: I18n.formatMessage("node.cli.commands.vault-key-import.params.env-prefix.description"),
|
|
25
|
+
required: false
|
|
26
|
+
},
|
|
21
27
|
{
|
|
22
28
|
key: "identity",
|
|
23
29
|
type: "string",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vaultKeyImport.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyImport.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM7E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;QACjF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;QACzE,oBAAoB,EAAE,KAAK;QAC3B,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,gEAAgE,CAChE;gBACD,YAAY,EAAE,KAAK;gBACnB,QAAQ,EAAE,IAAI;aACd;YACD;gBACC,GAAG,EAAE,QAAQ;gBACb,IAAI,EAAE,QA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AC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { Converter, Guards, HexHelper, I18n, Is } from \"@twin.org/core\";\nimport { Ed25519 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"vault-key-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyImport(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.vault-key-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-import.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.vault-key-import.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.key-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"private-key-hex\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.private-key-hex.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.vault-key-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) => vaultKeyImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing a vault key.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.privateKeyHex The private key in hexadecimal format.\n */\nexport async function vaultKeyImport(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\tprivateKeyHex?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"vaultKeyImport\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyImport\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyImport\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\tGuards.stringHex(\"vaultKeyImport\", \"private-key-hex\", params.privateKeyHex, true);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t\tif (!Is.empty(existingKey)) {\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t} catch {}\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-import.labels.importing\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst privateKeyBytes = Converter.hexToBytes(HexHelper.stripPrefix(params.privateKeyHex));\n\tconst publicKeyBytes =\n\t\tparams.keyType === \"Ed25519\" ? Ed25519.publicKeyFromPrivateKey(privateKeyBytes) : undefined;\n\n\tawait vaultConnector.addKey(\n\t\tfullKeyId,\n\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType],\n\t\tprivateKeyBytes,\n\t\tpublicKeyBytes\n\t);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-import.labels.imported\"));\n\n\tCLIDisplay.break();\n\tCLIDisplay.done();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vaultKeyImport.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyImport.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAw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C;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC,CAAC;IAC3F,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,eAAe,GAAG,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IAC1F,MAAM,cAAc,GACnB,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE7F,MAAM,cAAc,CAAC,MAAM,CAC1B,SAAS,EACT,YAAY,CAAC,MAAM,CAAC,OAAoC,CAAC,EACzD,eAAe,EACf,cAAc,CACd,CAAC;IAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,oDAAoD,CAAC,CAAC,CAAC;IAE1F,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,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 { Converter, Guards, HexHelper, I18n, Is } from \"@twin.org/core\";\nimport { Ed25519 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"vault-key-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyImport(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.vault-key-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-import.example\"),\n\t\trequiresNodeIdentity: false,\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.vault-key-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: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.key-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"private-key-hex\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.private-key-hex.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.vault-key-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) => vaultKeyImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing a vault key.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.privateKeyHex The private key in hexadecimal format.\n */\nexport async function vaultKeyImport(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\tprivateKeyHex?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"vaultKeyImport\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyImport\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyImport\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\tGuards.stringHex(\"vaultKeyImport\", \"private-key-hex\", params.privateKeyHex, true);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t\tif (!Is.empty(existingKey)) {\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t} catch {}\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-import.labels.importing\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst privateKeyBytes = Converter.hexToBytes(HexHelper.stripPrefix(params.privateKeyHex));\n\tconst publicKeyBytes =\n\t\tparams.keyType === \"Ed25519\" ? Ed25519.publicKeyFromPrivateKey(privateKeyBytes) : undefined;\n\n\tawait vaultConnector.addKey(\n\t\tfullKeyId,\n\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType],\n\t\tprivateKeyBytes,\n\t\tpublicKeyBytes\n\t);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-import.labels.imported\"));\n\n\tCLIDisplay.break();\n\tCLIDisplay.done();\n}\n"]}
|
package/dist/es/node.js
CHANGED
|
@@ -9,7 +9,7 @@ import * as dotenv from "dotenv";
|
|
|
9
9
|
import { buildEngineConfiguration } from "./builders/engineEnvBuilder.js";
|
|
10
10
|
import { buildEngineServerConfiguration } from "./builders/engineServerEnvBuilder.js";
|
|
11
11
|
import { extensionsConfiguration } from "./builders/extensionsBuilder.js";
|
|
12
|
-
import {
|
|
12
|
+
import { constructCliCommand, parseCommandLineArgs, registerCommands } from "./cli.js";
|
|
13
13
|
import { getEnvDefaults } from "./defaults.js";
|
|
14
14
|
import { ModuleProtocol } from "./models/moduleProtocol.js";
|
|
15
15
|
import { start } from "./start.js";
|
|
@@ -27,7 +27,7 @@ export async function run(nodeOptions, args) {
|
|
|
27
27
|
nodeOptions ??= {};
|
|
28
28
|
const serverInfo = {
|
|
29
29
|
name: nodeOptions?.serverName ?? "TWIN Node",
|
|
30
|
-
version: nodeOptions?.serverVersion ?? "0.0.3-next.
|
|
30
|
+
version: nodeOptions?.serverVersion ?? "0.0.3-next.18" // x-release-please-version
|
|
31
31
|
};
|
|
32
32
|
CLIDisplay.header(serverInfo.name, serverInfo.version, "đŠī¸ ");
|
|
33
33
|
if (!Is.stringValue(nodeOptions?.executionDirectory)) {
|
|
@@ -45,6 +45,12 @@ export async function run(nodeOptions, args) {
|
|
|
45
45
|
await initialiseLocales(nodeOptions.localesDirectory);
|
|
46
46
|
nodeOptions.envPrefix ??= "TWIN_";
|
|
47
47
|
overrideModuleImport(nodeOptions.executionDirectory ?? "");
|
|
48
|
+
const commandLineArgs = parseCommandLineArgs(args);
|
|
49
|
+
const hasEnvPrefix = commandLineArgs.options?.find(option => option.key === "env-prefix");
|
|
50
|
+
if (hasEnvPrefix) {
|
|
51
|
+
nodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;
|
|
52
|
+
}
|
|
53
|
+
CLIDisplay.value("Environment Variable Prefix", nodeOptions.envPrefix);
|
|
48
54
|
// This is the only location in the code base that should access process.env directly
|
|
49
55
|
// So we can safely disable the linting rule here.
|
|
50
56
|
let finalEnvVars =
|
|
@@ -60,8 +66,12 @@ export async function run(nodeOptions, args) {
|
|
|
60
66
|
...getEnvDefaults(nodeOptions.envPrefix),
|
|
61
67
|
...finalEnvVars
|
|
62
68
|
};
|
|
63
|
-
|
|
64
|
-
if (
|
|
69
|
+
let cliCommand;
|
|
70
|
+
if (Is.arrayValue(commandLineArgs.options)) {
|
|
71
|
+
registerCommands();
|
|
72
|
+
cliCommand = constructCliCommand(finalEnvVars, commandLineArgs);
|
|
73
|
+
}
|
|
74
|
+
if (Is.object(cliCommand)) {
|
|
65
75
|
finalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= "true";
|
|
66
76
|
}
|
|
67
77
|
else {
|
|
@@ -86,7 +96,6 @@ export async function run(nodeOptions, args) {
|
|
|
86
96
|
CLIDisplay.value("Favicon File", nodeOptions.favIconFile);
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
|
-
CLIDisplay.value("Environment Variable Prefix", nodeOptions.envPrefix);
|
|
90
99
|
const { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(finalEnvVars, nodeOptions, serverInfo);
|
|
91
100
|
CLIDisplay.break();
|
|
92
101
|
const startResult = await start(nodeOptions, nodeEngineConfig, nodeEnvVars, cliCommand, availableContextIdKeys);
|
|
@@ -96,7 +105,6 @@ export async function run(nodeOptions, args) {
|
|
|
96
105
|
process.on(signal, async () => {
|
|
97
106
|
CLIDisplay.value("Terminate Signal", signal);
|
|
98
107
|
await startResult.shutdown();
|
|
99
|
-
process.exit(0);
|
|
100
108
|
});
|
|
101
109
|
}
|
|
102
110
|
}
|