@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
package/dist/es/cli.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { ContextIdStore } from "@twin.org/context";
|
|
5
|
+
import { Coerce, GeneralError, I18n, Is, StringHelper } from "@twin.org/core";
|
|
6
|
+
import * as dotenv from "dotenv";
|
|
7
|
+
import { getCommandDefinitionBootstrapLegacy } from "./commands/bootstrapLegacy.js";
|
|
8
|
+
import { getCommandDefinitionHelp } from "./commands/help.js";
|
|
9
|
+
import { getCommandDefinitionIdentityCreate } from "./commands/identityCreate.js";
|
|
10
|
+
import { getCommandDefinitionIdentityImport } from "./commands/identityImports.js";
|
|
11
|
+
import { getCommandDefinitionIdentityVerifiableCredentialCreate } from "./commands/identityVerifiableCredentialCreate.js";
|
|
12
|
+
import { getCommandDefinitionIdentityVerificationMethodCreate } from "./commands/identityVerificationMethodCreate.js";
|
|
13
|
+
import { getCommandDefinitionIdentityVerificationMethodImport } from "./commands/identityVerificationMethodImport.js";
|
|
14
|
+
import { getCommandDefinitionNodeSetIdentity } from "./commands/nodeSetIdentity.js";
|
|
15
|
+
import { getCommandDefinitionNodeSetTenant } from "./commands/nodeSetTenant.js";
|
|
16
|
+
import { getCommandDefinitionTenantCreate } from "./commands/tenantCreate.js";
|
|
17
|
+
import { getCommandDefinitionTenantImport } from "./commands/tenantImport.js";
|
|
18
|
+
import { getCommandDefinitionTenantUpdate } from "./commands/tenantUpdate.js";
|
|
19
|
+
import { getCommandDefinitionUserCreate } from "./commands/userCreate.js";
|
|
20
|
+
import { getCommandDefinitionUserUpdate } from "./commands/userUpdate.js";
|
|
21
|
+
import { getCommandDefinitionVaultKeyCreate } from "./commands/vaultKeyCreate.js";
|
|
22
|
+
import { getCommandDefinitionVaultKeyImport } from "./commands/vaultKeyImport.js";
|
|
23
|
+
const commandDefinitions = {};
|
|
24
|
+
/**
|
|
25
|
+
* Parse command line arguments.
|
|
26
|
+
* @param args The command line arguments.
|
|
27
|
+
* @returns The parsed command line arguments.
|
|
28
|
+
*/
|
|
29
|
+
export function parseCommandLineArgs(args) {
|
|
30
|
+
let nodePath;
|
|
31
|
+
let scriptPath;
|
|
32
|
+
let options;
|
|
33
|
+
if (Is.arrayValue(args)) {
|
|
34
|
+
if (args.length > 0) {
|
|
35
|
+
nodePath = args[0];
|
|
36
|
+
}
|
|
37
|
+
if (args.length > 1) {
|
|
38
|
+
scriptPath = args[1];
|
|
39
|
+
}
|
|
40
|
+
if (args.length > 2) {
|
|
41
|
+
options = [];
|
|
42
|
+
for (let i = 2; i < args.length; i++) {
|
|
43
|
+
const arg = args[i];
|
|
44
|
+
const equalIndex = arg.indexOf("=");
|
|
45
|
+
if (equalIndex > 0) {
|
|
46
|
+
const key = arg.slice(0, equalIndex).trim();
|
|
47
|
+
const value = arg.slice(equalIndex + 1).trim();
|
|
48
|
+
if (key.startsWith("--")) {
|
|
49
|
+
options.push({ key: key.slice(2), value });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
options.push({ key: arg, value: "" });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
nodePath,
|
|
60
|
+
scriptPath,
|
|
61
|
+
options
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Construct the CLI command from the parsed arguments.
|
|
66
|
+
* @param processEnv The environment variables from the process.
|
|
67
|
+
* @param cliArgs The parsed CLI arguments.
|
|
68
|
+
* @returns The constructed CLI command.
|
|
69
|
+
* @throws GeneralError if the command is missing.
|
|
70
|
+
*/
|
|
71
|
+
export function constructCliCommand(processEnv, cliArgs) {
|
|
72
|
+
if (Is.arrayValue(cliArgs.options)) {
|
|
73
|
+
const command = cliArgs.options[0];
|
|
74
|
+
// If the first option is --help, we can display help for all commands
|
|
75
|
+
if (command.key === "--help") {
|
|
76
|
+
return {
|
|
77
|
+
definition: commandDefinitions.help,
|
|
78
|
+
params: {}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// In cases where no command but env-prefix is provided, we just return
|
|
82
|
+
if (command.key === "env-prefix") {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (!commandDefinitions[command.key]) {
|
|
86
|
+
throw new GeneralError("node", "cliCommandMissing", { command: command.key });
|
|
87
|
+
}
|
|
88
|
+
// We have a valid command, check for --help for that command
|
|
89
|
+
const hasHelp = cliArgs.options.find(option => option.key === "--help");
|
|
90
|
+
if (hasHelp) {
|
|
91
|
+
return {
|
|
92
|
+
definition: commandDefinitions.help,
|
|
93
|
+
params: {
|
|
94
|
+
command: command.key
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
processEnvOptions(processEnv, cliArgs.options);
|
|
99
|
+
const cliParams = {};
|
|
100
|
+
const allParamKeys = cliArgs.options
|
|
101
|
+
.map(option => option.key)
|
|
102
|
+
.filter(key => key !== command.key);
|
|
103
|
+
for (const commandDefParam of commandDefinitions[command.key].params) {
|
|
104
|
+
const foundParamIndex = cliArgs.options?.findIndex(option => option.key === commandDefParam.key) ?? -1;
|
|
105
|
+
const foundParam = foundParamIndex >= 0 ? cliArgs.options?.[foundParamIndex] : undefined;
|
|
106
|
+
let paramValue;
|
|
107
|
+
if (commandDefParam.type === "number") {
|
|
108
|
+
paramValue = Coerce.number(foundParam?.value ?? commandDefParam.defaultValue);
|
|
109
|
+
}
|
|
110
|
+
else if (commandDefParam.type === "boolean") {
|
|
111
|
+
paramValue = Coerce.boolean(foundParam?.value ?? commandDefParam.defaultValue);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
paramValue = Coerce.string(foundParam?.value ?? commandDefParam.defaultValue);
|
|
115
|
+
}
|
|
116
|
+
const required = commandDefParam.required ?? true;
|
|
117
|
+
if (Is.empty(paramValue) && required) {
|
|
118
|
+
throw new GeneralError("node", "cliCommandParamMissing", {
|
|
119
|
+
command: command.key,
|
|
120
|
+
param: commandDefParam.key
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (!Is.empty(paramValue)) {
|
|
124
|
+
cliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;
|
|
125
|
+
}
|
|
126
|
+
if (foundParamIndex >= 0) {
|
|
127
|
+
allParamKeys.splice(allParamKeys.indexOf(commandDefParam.key), 1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (allParamKeys.length > 0) {
|
|
131
|
+
throw new GeneralError("node", "cliCommandParamExtra", {
|
|
132
|
+
command: command.key,
|
|
133
|
+
params: allParamKeys.join(", ")
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (commandDefinitions[command.key].params.find(param => param.key === "output-env-prefix")) {
|
|
137
|
+
cliParams.outputEnvPrefix = (Coerce.string(cliParams.outputEnvPrefix) ?? "").toUpperCase();
|
|
138
|
+
cliParams.outputEnvPrefix =
|
|
139
|
+
cliParams.outputEnvPrefix.length > 0 && !cliParams.outputEnvPrefix.endsWith("_")
|
|
140
|
+
? `${cliParams.outputEnvPrefix}_`
|
|
141
|
+
: cliParams.outputEnvPrefix;
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
definition: commandDefinitions[command.key],
|
|
145
|
+
params: cliParams
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Execute the CLI command.
|
|
151
|
+
* @param engineCore The engine core.
|
|
152
|
+
* @param envVars The environment variables for the node.
|
|
153
|
+
* @param cliCommand The CLI command to execute.
|
|
154
|
+
*/
|
|
155
|
+
export async function executeCommand(engineCore, envVars, cliCommand) {
|
|
156
|
+
const requiresEngineStarted = cliCommand.definition.requiresEngineStarted ?? true;
|
|
157
|
+
try {
|
|
158
|
+
if (requiresEngineStarted) {
|
|
159
|
+
await engineCore.start(true);
|
|
160
|
+
}
|
|
161
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.command"), cliCommand.definition.command);
|
|
162
|
+
for (const paramKey in cliCommand.params) {
|
|
163
|
+
CLIDisplay.value(paramKey, Coerce.string(cliCommand.params[paramKey]), 1);
|
|
164
|
+
}
|
|
165
|
+
CLIDisplay.break();
|
|
166
|
+
await ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {
|
|
167
|
+
await cliCommand.definition.action(engineCore, envVars, cliCommand.params);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
CLIDisplay.spinnerStop();
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
if (requiresEngineStarted) {
|
|
176
|
+
CLIDisplay.break();
|
|
177
|
+
await engineCore.stop();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Load the env files and process the options.
|
|
183
|
+
* @param processEnv The environment variables from the process.
|
|
184
|
+
* @param options The options.
|
|
185
|
+
* @returns The processed parameters.
|
|
186
|
+
* @throws GeneralError if an env file has errors.
|
|
187
|
+
*/
|
|
188
|
+
export function processEnvOptions(processEnv, options) {
|
|
189
|
+
const inputEnv = options.find(option => option.key === "load-env")?.value;
|
|
190
|
+
if (Is.stringValue(inputEnv)) {
|
|
191
|
+
const envFiles = inputEnv.split(",").map(f => f.trim());
|
|
192
|
+
for (const envFile of envFiles) {
|
|
193
|
+
const output = dotenv.config({
|
|
194
|
+
path: envFile,
|
|
195
|
+
quiet: true
|
|
196
|
+
});
|
|
197
|
+
if (output.error) {
|
|
198
|
+
throw output.error;
|
|
199
|
+
}
|
|
200
|
+
if (Is.objectValue(output.parsed)) {
|
|
201
|
+
for (const key in output.parsed) {
|
|
202
|
+
processEnv[key] = output.parsed[key];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return substituteEnvOptions(processEnv, options);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Process options and replace any env variables with their values.
|
|
211
|
+
* @param processEnv The environment variables from the process.
|
|
212
|
+
* @param options The options.
|
|
213
|
+
* @throws GeneralError if an env variable is missing.
|
|
214
|
+
*/
|
|
215
|
+
export function substituteEnvOptions(processEnv, options) {
|
|
216
|
+
for (const option of options) {
|
|
217
|
+
if (option.value.startsWith("!")) {
|
|
218
|
+
const envVar = processEnv[option.value.slice(1)];
|
|
219
|
+
if (!Is.stringValue(envVar)) {
|
|
220
|
+
throw new GeneralError("node", "cliEnvVarMissing", { envVar: option.value.slice(1) });
|
|
221
|
+
}
|
|
222
|
+
option.value = envVar;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Register available CLI commands.
|
|
228
|
+
*/
|
|
229
|
+
export function registerCommands() {
|
|
230
|
+
getCommandDefinitionHelp(commandDefinitions);
|
|
231
|
+
getCommandDefinitionBootstrapLegacy(commandDefinitions);
|
|
232
|
+
getCommandDefinitionIdentityCreate(commandDefinitions);
|
|
233
|
+
getCommandDefinitionIdentityImport(commandDefinitions);
|
|
234
|
+
getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);
|
|
235
|
+
getCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);
|
|
236
|
+
getCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);
|
|
237
|
+
getCommandDefinitionNodeSetIdentity(commandDefinitions);
|
|
238
|
+
getCommandDefinitionNodeSetTenant(commandDefinitions);
|
|
239
|
+
getCommandDefinitionTenantCreate(commandDefinitions);
|
|
240
|
+
getCommandDefinitionTenantImport(commandDefinitions);
|
|
241
|
+
getCommandDefinitionTenantUpdate(commandDefinitions);
|
|
242
|
+
getCommandDefinitionUserCreate(commandDefinitions);
|
|
243
|
+
getCommandDefinitionUserUpdate(commandDefinitions);
|
|
244
|
+
getCommandDefinitionVaultKeyCreate(commandDefinitions);
|
|
245
|
+
getCommandDefinitionVaultKeyImport(commandDefinitions);
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9E,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,mCAAmC,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,sDAAsD,EAAE,MAAM,kDAAkD,CAAC;AAC1H,OAAO,EAAE,oDAAoD,EAAE,MAAM,gDAAgD,CAAC;AACtH,OAAO,EAAE,oDAAoD,EAAE,MAAM,gDAAgD,CAAC;AACtH,OAAO,EAAE,mCAAmC,EAAE,MAAM,+BAA+B,CAAC;AACpF,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,gCAAgC,EAAE,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,CAAC;IACnD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;AACxD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, GeneralError, I18n, Is, StringHelper } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport * as dotenv from \"dotenv\";\nimport { getCommandDefinitionBootstrapLegacy } from \"./commands/bootstrapLegacy.js\";\nimport { getCommandDefinitionHelp } from \"./commands/help.js\";\nimport { getCommandDefinitionIdentityCreate } from \"./commands/identityCreate.js\";\nimport { getCommandDefinitionIdentityImport } from \"./commands/identityImports.js\";\nimport { getCommandDefinitionIdentityVerifiableCredentialCreate } from \"./commands/identityVerifiableCredentialCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodCreate } from \"./commands/identityVerificationMethodCreate.js\";\nimport { getCommandDefinitionIdentityVerificationMethodImport } from \"./commands/identityVerificationMethodImport.js\";\nimport { getCommandDefinitionNodeSetIdentity } from \"./commands/nodeSetIdentity.js\";\nimport { getCommandDefinitionNodeSetTenant } from \"./commands/nodeSetTenant.js\";\nimport { getCommandDefinitionTenantCreate } from \"./commands/tenantCreate.js\";\nimport { getCommandDefinitionTenantImport } from \"./commands/tenantImport.js\";\nimport { getCommandDefinitionTenantUpdate } from \"./commands/tenantUpdate.js\";\nimport { getCommandDefinitionUserCreate } from \"./commands/userCreate.js\";\nimport { getCommandDefinitionUserUpdate } from \"./commands/userUpdate.js\";\nimport { getCommandDefinitionVaultKeyCreate } from \"./commands/vaultKeyCreate.js\";\nimport { getCommandDefinitionVaultKeyImport } from \"./commands/vaultKeyImport.js\";\nimport type { CliCommandParamType } from \"./models/cliCommandParamType.js\";\nimport type { ICliArgs } from \"./models/ICliArgs.js\";\nimport type { ICliCommand } from \"./models/ICliCommand.js\";\nimport type { ICliCommandDefinition } from \"./models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\n\nconst commandDefinitions: { [id: string]: ICliCommandDefinition } = {};\n\n/**\n * Parse command line arguments.\n * @param args The command line arguments.\n * @returns The parsed command line arguments.\n */\nexport function parseCommandLineArgs(args?: string[]): ICliArgs {\n\tlet nodePath;\n\tlet scriptPath;\n\tlet options:\n\t\t| {\n\t\t\t\tkey: string;\n\t\t\t\tvalue: string;\n\t\t }[]\n\t\t| undefined;\n\n\tif (Is.arrayValue(args)) {\n\t\tif (args.length > 0) {\n\t\t\tnodePath = args[0];\n\t\t}\n\t\tif (args.length > 1) {\n\t\t\tscriptPath = args[1];\n\t\t}\n\t\tif (args.length > 2) {\n\t\t\toptions = [];\n\n\t\t\tfor (let i = 2; i < args.length; i++) {\n\t\t\t\tconst arg = args[i];\n\t\t\t\tconst equalIndex = arg.indexOf(\"=\");\n\t\t\t\tif (equalIndex > 0) {\n\t\t\t\t\tconst key = arg.slice(0, equalIndex).trim();\n\t\t\t\t\tconst value = arg.slice(equalIndex + 1).trim();\n\t\t\t\t\tif (key.startsWith(\"--\")) {\n\t\t\t\t\t\toptions.push({ key: key.slice(2), value });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\toptions.push({ key: arg, value: \"\" });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tnodePath,\n\t\tscriptPath,\n\t\toptions\n\t};\n}\n\n/**\n * Construct the CLI command from the parsed arguments.\n * @param processEnv The environment variables from the process.\n * @param cliArgs The parsed CLI arguments.\n * @returns The constructed CLI command.\n * @throws GeneralError if the command is missing.\n */\nexport function constructCliCommand(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\tcliArgs: ICliArgs\n): ICliCommand | undefined {\n\tif (Is.arrayValue(cliArgs.options)) {\n\t\tconst command = cliArgs.options[0];\n\n\t\t// If the first option is --help, we can display help for all commands\n\t\tif (command.key === \"--help\") {\n\t\t\treturn {\n\t\t\t\tdefinition: commandDefinitions.help,\n\t\t\t\tparams: {}\n\t\t\t};\n\t\t}\n\n\t\t// In cases where no command but env-prefix is provided, we just return\n\t\tif (command.key === \"env-prefix\") {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (!commandDefinitions[command.key]) {\n\t\t\tthrow new GeneralError(\"node\", \"cliCommandMissing\", { command: command.key });\n\t\t}\n\n\t\t// We have a valid command, check for --help for that command\n\t\tconst hasHelp = cliArgs.options.find(option => option.key === \"--help\");\n\t\tif (hasHelp) {\n\t\t\treturn {\n\t\t\t\tdefinition: commandDefinitions.help,\n\t\t\t\tparams: {\n\t\t\t\t\tcommand: command.key\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tprocessEnvOptions(processEnv, cliArgs.options);\n\n\t\tconst cliParams: { [id: string]: CliCommandParamType } = {};\n\t\tconst allParamKeys = cliArgs.options\n\t\t\t.map(option => option.key)\n\t\t\t.filter(key => key !== command.key);\n\n\t\tfor (const commandDefParam of commandDefinitions[command.key].params) {\n\t\t\tconst foundParamIndex =\n\t\t\t\tcliArgs.options?.findIndex(option => option.key === commandDefParam.key) ?? -1;\n\t\t\tconst foundParam = foundParamIndex >= 0 ? cliArgs.options?.[foundParamIndex] : undefined;\n\n\t\t\tlet paramValue;\n\t\t\tif (commandDefParam.type === \"number\") {\n\t\t\t\tparamValue = Coerce.number(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t} else if (commandDefParam.type === \"boolean\") {\n\t\t\t\tparamValue = Coerce.boolean(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t} else {\n\t\t\t\tparamValue = Coerce.string(foundParam?.value ?? commandDefParam.defaultValue);\n\t\t\t}\n\n\t\t\tconst required = commandDefParam.required ?? true;\n\t\t\tif (Is.empty(paramValue) && required) {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliCommandParamMissing\", {\n\t\t\t\t\tcommand: command.key,\n\t\t\t\t\tparam: commandDefParam.key\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!Is.empty(paramValue)) {\n\t\t\t\tcliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;\n\t\t\t}\n\n\t\t\tif (foundParamIndex >= 0) {\n\t\t\t\tallParamKeys.splice(allParamKeys.indexOf(commandDefParam.key), 1);\n\t\t\t}\n\t\t}\n\n\t\tif (allParamKeys.length > 0) {\n\t\t\tthrow new GeneralError(\"node\", \"cliCommandParamExtra\", {\n\t\t\t\tcommand: command.key,\n\t\t\t\tparams: allParamKeys.join(\", \")\n\t\t\t});\n\t\t}\n\n\t\tif (commandDefinitions[command.key].params.find(param => param.key === \"output-env-prefix\")) {\n\t\t\tcliParams.outputEnvPrefix = (Coerce.string(cliParams.outputEnvPrefix) ?? \"\").toUpperCase();\n\t\t\tcliParams.outputEnvPrefix =\n\t\t\t\tcliParams.outputEnvPrefix.length > 0 && !cliParams.outputEnvPrefix.endsWith(\"_\")\n\t\t\t\t\t? `${cliParams.outputEnvPrefix}_`\n\t\t\t\t\t: cliParams.outputEnvPrefix;\n\t\t}\n\n\t\treturn {\n\t\t\tdefinition: commandDefinitions[command.key],\n\t\t\tparams: cliParams\n\t\t};\n\t}\n}\n\n/**\n * Execute the CLI command.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param cliCommand The CLI command to execute.\n */\nexport async function executeCommand(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tcliCommand: ICliCommand\n): Promise<void> {\n\tconst requiresEngineStarted = cliCommand.definition.requiresEngineStarted ?? true;\n\n\ttry {\n\t\tif (requiresEngineStarted) {\n\t\t\tawait engineCore.start(true);\n\t\t}\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.command\"),\n\t\t\tcliCommand.definition.command\n\t\t);\n\t\tfor (const paramKey in cliCommand.params) {\n\t\t\tCLIDisplay.value(paramKey, Coerce.string(cliCommand.params[paramKey]), 1);\n\t\t}\n\t\tCLIDisplay.break();\n\n\t\tawait ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {\n\t\t\tawait cliCommand.definition.action(engineCore, envVars, cliCommand.params);\n\t\t});\n\t} catch (error) {\n\t\tCLIDisplay.spinnerStop();\n\n\t\tthrow error;\n\t} finally {\n\t\tif (requiresEngineStarted) {\n\t\t\tCLIDisplay.break();\n\t\t\tawait engineCore.stop();\n\t\t}\n\t}\n}\n\n/**\n * Load the env files and process the options.\n * @param processEnv The environment variables from the process.\n * @param options The options.\n * @returns The processed parameters.\n * @throws GeneralError if an env file has errors.\n */\nexport function processEnvOptions(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: {\n\t\tkey: string;\n\t\tvalue: string;\n\t}[]\n): void {\n\tconst inputEnv = options.find(option => option.key === \"load-env\")?.value;\n\n\tif (Is.stringValue(inputEnv)) {\n\t\tconst envFiles = inputEnv.split(\",\").map(f => f.trim());\n\t\tfor (const envFile of envFiles) {\n\t\t\tconst output = dotenv.config({\n\t\t\t\tpath: envFile,\n\t\t\t\tquiet: true\n\t\t\t});\n\n\t\t\tif (output.error) {\n\t\t\t\tthrow output.error;\n\t\t\t}\n\n\t\t\tif (Is.objectValue(output.parsed)) {\n\t\t\t\tfor (const key in output.parsed) {\n\t\t\t\t\tprocessEnv[key] = output.parsed[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn substituteEnvOptions(processEnv, options);\n}\n\n/**\n * Process options and replace any env variables with their values.\n * @param processEnv The environment variables from the process.\n * @param options The options.\n * @throws GeneralError if an env variable is missing.\n */\nexport function substituteEnvOptions(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: {\n\t\tkey: string;\n\t\tvalue: string;\n\t}[]\n): void {\n\tfor (const option of options) {\n\t\tif (option.value.startsWith(\"!\")) {\n\t\t\tconst envVar = processEnv[option.value.slice(1)];\n\t\t\tif (!Is.stringValue(envVar)) {\n\t\t\t\tthrow new GeneralError(\"node\", \"cliEnvVarMissing\", { envVar: option.value.slice(1) });\n\t\t\t}\n\t\t\toption.value = envVar;\n\t\t}\n\t}\n}\n\n/**\n * Register available CLI commands.\n */\nexport function registerCommands(): void {\n\tgetCommandDefinitionHelp(commandDefinitions);\n\tgetCommandDefinitionBootstrapLegacy(commandDefinitions);\n\tgetCommandDefinitionIdentityCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityImport(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);\n\tgetCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);\n\tgetCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);\n\tgetCommandDefinitionNodeSetIdentity(commandDefinitions);\n\tgetCommandDefinitionNodeSetTenant(commandDefinitions);\n\tgetCommandDefinitionTenantCreate(commandDefinitions);\n\tgetCommandDefinitionTenantImport(commandDefinitions);\n\tgetCommandDefinitionTenantUpdate(commandDefinitions);\n\tgetCommandDefinitionUserCreate(commandDefinitions);\n\tgetCommandDefinitionUserUpdate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyCreate(commandDefinitions);\n\tgetCommandDefinitionVaultKeyImport(commandDefinitions);\n}\n"]}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
5
|
+
import { Coerce, Converter, GeneralError, I18n, Is } from "@twin.org/core";
|
|
6
|
+
import { identityCreate } from "./identityCreate.js";
|
|
7
|
+
import { identityVerificationMethodCreate } from "./identityVerificationMethodCreate.js";
|
|
8
|
+
import { nodeSetIdentity } from "./nodeSetIdentity.js";
|
|
9
|
+
import { nodeSetTenant } from "./nodeSetTenant.js";
|
|
10
|
+
import { tenantCreate } from "./tenantCreate.js";
|
|
11
|
+
import { userCreate } from "./userCreate.js";
|
|
12
|
+
import { vaultKeyCreate } from "./vaultKeyCreate.js";
|
|
13
|
+
import { vaultKeyImport } from "./vaultKeyImport.js";
|
|
14
|
+
const COMMAND_NAME = "bootstrap-legacy";
|
|
15
|
+
/**
|
|
16
|
+
* Get the command definition parameters.
|
|
17
|
+
* @param commandDefinitions The registered command definitions.
|
|
18
|
+
*/
|
|
19
|
+
export function getCommandDefinitionBootstrapLegacy(commandDefinitions) {
|
|
20
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
21
|
+
command: COMMAND_NAME,
|
|
22
|
+
description: I18n.formatMessage("node.cli.commands.bootstrap-legacy.description"),
|
|
23
|
+
example: I18n.formatMessage("node.cli.commands.bootstrap-legacy.example"),
|
|
24
|
+
requiresNodeIdentity: false,
|
|
25
|
+
requiresTenantId: false,
|
|
26
|
+
params: [
|
|
27
|
+
{
|
|
28
|
+
key: "env-prefix",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: I18n.formatMessage("node.cli.commands.bootstrap-legacy.params.env-prefix.description"),
|
|
31
|
+
required: false
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: "load-env",
|
|
35
|
+
type: "string",
|
|
36
|
+
description: I18n.formatMessage("node.cli.commands.bootstrap-legacy.params.load-env.description"),
|
|
37
|
+
required: false
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
action: async (engineCore, envVars, params) => bootstrapLegacy(engineCore, envVars, params)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Command for legacy bootstrap.
|
|
45
|
+
* @param engineCore The engine core.
|
|
46
|
+
* @param envVars The environment variables for the node.
|
|
47
|
+
* @param params The parameters for the command.
|
|
48
|
+
*/
|
|
49
|
+
export async function bootstrapLegacy(engineCore, envVars, params) {
|
|
50
|
+
const features = (envVars.features ?? "")
|
|
51
|
+
.split(",")
|
|
52
|
+
.map(f => f.trim())
|
|
53
|
+
.filter(f => f.length > 0);
|
|
54
|
+
const state = engineCore.getState();
|
|
55
|
+
const requireWallet = features.includes("node-wallet");
|
|
56
|
+
let tenantId = state.nodeTenantId;
|
|
57
|
+
let nodeId = state.nodeId;
|
|
58
|
+
if (features.length === 0) {
|
|
59
|
+
throw new GeneralError("bootstrapLegacy", "noFeaturesEnabled");
|
|
60
|
+
}
|
|
61
|
+
if (features.includes("node-identity") && Is.empty(nodeId)) {
|
|
62
|
+
CLIDisplay.break();
|
|
63
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeIdentityCreate"));
|
|
64
|
+
const nodeIdentity = await identityCreate(engineCore, envVars, {
|
|
65
|
+
identity: envVars.nodeIdentity,
|
|
66
|
+
mnemonic: envVars.nodeMnemonic,
|
|
67
|
+
fundWallet: requireWallet
|
|
68
|
+
});
|
|
69
|
+
nodeId = nodeIdentity.did;
|
|
70
|
+
CLIDisplay.break();
|
|
71
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeAuthKeyCreate"));
|
|
72
|
+
await vaultKeyCreate(engineCore, envVars, {
|
|
73
|
+
identity: nodeIdentity.did,
|
|
74
|
+
keyType: "Ed25519",
|
|
75
|
+
keyId: envVars.authSigningKeyId
|
|
76
|
+
});
|
|
77
|
+
if (Coerce.boolean(envVars.trustEnabled) ?? false) {
|
|
78
|
+
CLIDisplay.break();
|
|
79
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.trustVerificationMethodCreate"));
|
|
80
|
+
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
81
|
+
identity: nodeIdentity.did,
|
|
82
|
+
verificationMethodType: "assertionMethod",
|
|
83
|
+
verificationMethodId: envVars.trustVerificationMethodId,
|
|
84
|
+
overwriteMode: "skip"
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if ((Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) &&
|
|
88
|
+
Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {
|
|
89
|
+
CLIDisplay.break();
|
|
90
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.synchronisedStorageKeyAdd"));
|
|
91
|
+
await vaultKeyImport(engineCore, envVars, {
|
|
92
|
+
identity: nodeIdentity.did,
|
|
93
|
+
keyType: "ChaCha20Poly1305",
|
|
94
|
+
keyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,
|
|
95
|
+
privateKeyHex: Converter.bytesToHex(Converter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey))
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
CLIDisplay.break();
|
|
99
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeIdentitySet"));
|
|
100
|
+
await nodeSetIdentity(engineCore, envVars, {
|
|
101
|
+
identity: nodeId
|
|
102
|
+
});
|
|
103
|
+
const tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
|
|
104
|
+
if (tenantEnabled && Is.empty(tenantId)) {
|
|
105
|
+
await ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {
|
|
106
|
+
CLIDisplay.break();
|
|
107
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeTenantCreate"));
|
|
108
|
+
const tenantDetails = await tenantCreate(engineCore, envVars, {
|
|
109
|
+
tenantId: envVars.tenantId,
|
|
110
|
+
apiKey: envVars.tenantApiKey,
|
|
111
|
+
label: "Node"
|
|
112
|
+
});
|
|
113
|
+
CLIDisplay.break();
|
|
114
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.nodeTenantSet"));
|
|
115
|
+
await nodeSetTenant(engineCore, envVars, {
|
|
116
|
+
tenantId: tenantDetails.tenantId
|
|
117
|
+
});
|
|
118
|
+
tenantId = tenantDetails.tenantId;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (features.includes("node-admin-user")) {
|
|
123
|
+
await ContextIdStore.run({ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenantId }, async () => {
|
|
124
|
+
CLIDisplay.break();
|
|
125
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.organisationCreate"));
|
|
126
|
+
const organisation = await identityCreate(engineCore, envVars, {
|
|
127
|
+
identity: envVars.organizationIdentity,
|
|
128
|
+
mnemonic: envVars.organizationMnemonic,
|
|
129
|
+
fundWallet: requireWallet
|
|
130
|
+
});
|
|
131
|
+
if (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {
|
|
132
|
+
CLIDisplay.break();
|
|
133
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.blobStorageKeyCreate"));
|
|
134
|
+
await vaultKeyCreate(engineCore, envVars, {
|
|
135
|
+
identity: organisation.did,
|
|
136
|
+
keyType: "ChaCha20Poly1305",
|
|
137
|
+
keyId: envVars.blobStorageEncryptionKeyId
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const defaultAttestationConnectorType = engineCore.getRegisteredInstanceTypeOptional("attestationConnector");
|
|
141
|
+
if (!Is.empty(defaultAttestationConnectorType)) {
|
|
142
|
+
CLIDisplay.break();
|
|
143
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.attestationMethodCreate"));
|
|
144
|
+
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
145
|
+
identity: organisation.did,
|
|
146
|
+
verificationMethodType: "assertionMethod",
|
|
147
|
+
verificationMethodId: envVars.attestationVerificationMethodId,
|
|
148
|
+
overwriteMode: "skip"
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const defaultImmutableProofComponentType = engineCore.getRegisteredInstanceTypeOptional("immutableProofComponent");
|
|
152
|
+
if (!Is.empty(defaultImmutableProofComponentType)) {
|
|
153
|
+
CLIDisplay.break();
|
|
154
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.immutableProofMethodCreate"));
|
|
155
|
+
await identityVerificationMethodCreate(engineCore, envVars, {
|
|
156
|
+
identity: organisation.did,
|
|
157
|
+
verificationMethodType: "assertionMethod",
|
|
158
|
+
verificationMethodId: envVars.immutableProofVerificationMethodId,
|
|
159
|
+
overwriteMode: "skip"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
CLIDisplay.break();
|
|
163
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.adminIdentityCreate"));
|
|
164
|
+
const adminUserIdentity = await identityCreate(engineCore, envVars, {
|
|
165
|
+
identity: envVars.adminUserIdentity,
|
|
166
|
+
mnemonic: envVars.adminUserMnemonic,
|
|
167
|
+
controller: organisation.did
|
|
168
|
+
});
|
|
169
|
+
CLIDisplay.break();
|
|
170
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.bootstrap-legacy.labels.adminUserCreate"));
|
|
171
|
+
await userCreate(engineCore, envVars, {
|
|
172
|
+
userIdentity: adminUserIdentity.did,
|
|
173
|
+
organizationIdentity: organisation.did,
|
|
174
|
+
email: envVars.adminUserName ?? "admin@node",
|
|
175
|
+
password: envVars.adminUserPassword,
|
|
176
|
+
scope: "tenant-admin",
|
|
177
|
+
givenName: "Node",
|
|
178
|
+
familyName: "Admin"
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=bootstrapLegacy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrapLegacy.js","sourceRoot":"","sources":["../../../src/commands/bootstrapLegacy.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,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CAAC,CAAC;QACJ,CAAC,CACD,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, Converter, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { identityCreate } from \"./identityCreate.js\";\nimport { identityVerificationMethodCreate } from \"./identityVerificationMethodCreate.js\";\nimport { nodeSetIdentity } from \"./nodeSetIdentity.js\";\nimport { nodeSetTenant } from \"./nodeSetTenant.js\";\nimport { tenantCreate } from \"./tenantCreate.js\";\nimport { userCreate } from \"./userCreate.js\";\nimport { vaultKeyCreate } from \"./vaultKeyCreate.js\";\nimport { vaultKeyImport } from \"./vaultKeyImport.js\";\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 = \"bootstrap-legacy\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionBootstrapLegacy(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.bootstrap-legacy.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.bootstrap-legacy.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.bootstrap-legacy.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: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.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) => bootstrapLegacy(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for legacy bootstrap.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n */\nexport async function bootstrapLegacy(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables & {\n\t\t/**\n\t\t * The features that are enabled on the node.\n\t\t * @default []\n\t\t */\n\t\tfeatures?: string;\n\n\t\t/**\n\t\t * The identity of the node which, if empty and node-identity feature is enabled it will be generated.\n\t\t */\n\t\tnodeIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the identity, if empty and node-identity feature is enabled it will be randomly generated.\n\t\t */\n\t\tnodeMnemonic?: string;\n\n\t\t/**\n\t\t * A tenant id to use as a default for the node.\n\t\t */\n\t\ttenantId?: string;\n\n\t\t/**\n\t\t * A tenant api key to use as a default for the node.\n\t\t */\n\t\ttenantApiKey?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the organization of the user, if one is not provided it will be generated\n\t\t */\n\t\torganizationIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the organization, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\torganizationMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the identity of the user, if one is not provided it will be generated\n\t\t */\n\t\tadminUserIdentity?: string;\n\n\t\t/**\n\t\t * The mnemonic for the admin user, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t\t */\n\t\tadminUserMnemonic?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the name of the user.\n\t\t * @default admin@node\n\t\t */\n\t\tadminUserName?: string;\n\n\t\t/**\n\t\t * If the node-admin-user feature is enabled, this will be the password of the user, if empty it will be randomly generated.\n\t\t */\n\t\tadminUserPassword?: string;\n\t},\n\tparams: {}\n): Promise<void> {\n\tconst features = (envVars.features ?? \"\")\n\t\t.split(\",\")\n\t\t.map(f => f.trim())\n\t\t.filter(f => f.length > 0);\n\n\tconst state = engineCore.getState();\n\tconst requireWallet = features.includes(\"node-wallet\");\n\tlet tenantId = state.nodeTenantId;\n\tlet nodeId = state.nodeId;\n\n\tif (features.length === 0) {\n\t\tthrow new GeneralError(\"bootstrapLegacy\", \"noFeaturesEnabled\");\n\t}\n\n\tif (features.includes(\"node-identity\") && Is.empty(nodeId)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentityCreate\")\n\t\t);\n\n\t\tconst nodeIdentity = await identityCreate(engineCore, envVars, {\n\t\t\tidentity: envVars.nodeIdentity,\n\t\t\tmnemonic: envVars.nodeMnemonic,\n\t\t\tfundWallet: requireWallet\n\t\t});\n\n\t\tnodeId = nodeIdentity.did;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeAuthKeyCreate\")\n\t\t);\n\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\tidentity: nodeIdentity.did,\n\t\t\tkeyType: \"Ed25519\",\n\t\t\tkeyId: envVars.authSigningKeyId\n\t\t});\n\n\t\tif (Coerce.boolean(envVars.trustEnabled) ?? false) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.trustVerificationMethodCreate\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\tverificationMethodId: envVars.trustVerificationMethodId,\n\t\t\t\toverwriteMode: \"skip\"\n\t\t\t});\n\t\t}\n\n\t\tif (\n\t\t\t(Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) &&\n\t\t\tIs.stringBase64(envVars.synchronisedStorageBlobStorageKey)\n\t\t) {\n\t\t\tCLIDisplay.break();\n\t\t\tCLIDisplay.section(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.synchronisedStorageKeyAdd\")\n\t\t\t);\n\t\t\tawait vaultKeyImport(engineCore, envVars, {\n\t\t\t\tidentity: nodeIdentity.did,\n\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\tkeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,\n\t\t\t\tprivateKeyHex: Converter.bytesToHex(\n\t\t\t\t\tConverter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey)\n\t\t\t\t)\n\t\t\t});\n\t\t}\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeIdentitySet\")\n\t\t);\n\t\tawait nodeSetIdentity(engineCore, envVars, {\n\t\t\tidentity: nodeId\n\t\t});\n\n\t\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\t\tif (tenantEnabled && Is.empty(tenantId)) {\n\t\t\tawait ContextIdStore.run({ [ContextIdKeys.Node]: nodeId }, async () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeTenantCreate\")\n\t\t\t\t);\n\t\t\t\tconst tenantDetails = await tenantCreate(engineCore, envVars, {\n\t\t\t\t\ttenantId: envVars.tenantId,\n\t\t\t\t\tapiKey: envVars.tenantApiKey,\n\t\t\t\t\tlabel: \"Node\"\n\t\t\t\t});\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.nodeTenantSet\")\n\t\t\t\t);\n\t\t\t\tawait nodeSetTenant(engineCore, envVars, {\n\t\t\t\t\ttenantId: tenantDetails.tenantId\n\t\t\t\t});\n\n\t\t\t\ttenantId = tenantDetails.tenantId;\n\t\t\t});\n\t\t}\n\t}\n\n\tif (features.includes(\"node-admin-user\")) {\n\t\tawait ContextIdStore.run(\n\t\t\t{ [ContextIdKeys.Node]: nodeId, [ContextIdKeys.Tenant]: tenantId },\n\t\t\tasync () => {\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.organisationCreate\")\n\t\t\t\t);\n\t\t\t\tconst organisation = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.organizationIdentity,\n\t\t\t\t\tmnemonic: envVars.organizationMnemonic,\n\t\t\t\t\tfundWallet: requireWallet\n\t\t\t\t});\n\n\t\t\t\tif (Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.blobStorageKeyCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait vaultKeyCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tkeyType: \"ChaCha20Poly1305\",\n\t\t\t\t\t\tkeyId: envVars.blobStorageEncryptionKeyId\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultAttestationConnectorType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\t\t\tif (!Is.empty(defaultAttestationConnectorType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.attestationMethodCreate\")\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.attestationVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tconst defaultImmutableProofComponentType =\n\t\t\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\t\t\tif (!Is.empty(defaultImmutableProofComponentType)) {\n\t\t\t\t\tCLIDisplay.break();\n\t\t\t\t\tCLIDisplay.section(\n\t\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\t\"node.cli.commands.bootstrap-legacy.labels.immutableProofMethodCreate\"\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t\tawait identityVerificationMethodCreate(engineCore, envVars, {\n\t\t\t\t\t\tidentity: organisation.did,\n\t\t\t\t\t\tverificationMethodType: \"assertionMethod\",\n\t\t\t\t\t\tverificationMethodId: envVars.immutableProofVerificationMethodId,\n\t\t\t\t\t\toverwriteMode: \"skip\"\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.adminIdentityCreate\")\n\t\t\t\t);\n\t\t\t\tconst adminUserIdentity = await identityCreate(engineCore, envVars, {\n\t\t\t\t\tidentity: envVars.adminUserIdentity,\n\t\t\t\t\tmnemonic: envVars.adminUserMnemonic,\n\t\t\t\t\tcontroller: organisation.did\n\t\t\t\t});\n\n\t\t\t\tCLIDisplay.break();\n\t\t\t\tCLIDisplay.section(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.bootstrap-legacy.labels.adminUserCreate\")\n\t\t\t\t);\n\t\t\t\tawait userCreate(engineCore, envVars, {\n\t\t\t\t\tuserIdentity: adminUserIdentity.did,\n\t\t\t\t\torganizationIdentity: organisation.did,\n\t\t\t\t\temail: envVars.adminUserName ?? \"admin@node\",\n\t\t\t\t\tpassword: envVars.adminUserPassword,\n\t\t\t\t\tscope: \"tenant-admin\",\n\t\t\t\t\tgivenName: \"Node\",\n\t\t\t\t\tfamilyName: \"Admin\"\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { I18n, Is } from "@twin.org/core";
|
|
5
|
+
const COMMAND_NAME = "help";
|
|
6
|
+
/**
|
|
7
|
+
* Get the command definition parameters.
|
|
8
|
+
* @param commandDefinitions The registered command definitions.
|
|
9
|
+
*/
|
|
10
|
+
export function getCommandDefinitionHelp(commandDefinitions) {
|
|
11
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
12
|
+
command: COMMAND_NAME,
|
|
13
|
+
description: I18n.formatMessage("node.cli.commands.help.description"),
|
|
14
|
+
example: "",
|
|
15
|
+
params: [],
|
|
16
|
+
action: async (engineCore, envVars, params) => help(engineCore, envVars, params, commandDefinitions),
|
|
17
|
+
requiresEngineStarted: false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Command for displaying help information.
|
|
22
|
+
* @param engineCore The engine core.
|
|
23
|
+
* @param envVars The environment variables for the node.
|
|
24
|
+
* @param params The command parameters.
|
|
25
|
+
* @param params.command The command to display help for.
|
|
26
|
+
* @param commandDefinitions The registered command definitions.
|
|
27
|
+
*/
|
|
28
|
+
export async function help(engineCore, envVars, params, commandDefinitions) {
|
|
29
|
+
if (Is.stringValue(params.command)) {
|
|
30
|
+
const commandDefinition = commandDefinitions[params.command];
|
|
31
|
+
if (commandDefinition) {
|
|
32
|
+
displayCommandHelp(commandDefinition);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
CLIDisplay.value("", I18n.formatMessage("node.cli.commands.help.labels.commands"));
|
|
37
|
+
CLIDisplay.break();
|
|
38
|
+
for (const commandId in commandDefinitions) {
|
|
39
|
+
const commandDef = commandDefinitions[commandId];
|
|
40
|
+
if (commandId !== "help") {
|
|
41
|
+
CLIDisplay.value(commandDef.command, I18n.formatMessage(`node.cli.commands.${commandDef.command}.description`));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Display help for a specific command.
|
|
48
|
+
* @param commandDefinition The command definition.
|
|
49
|
+
*/
|
|
50
|
+
function displayCommandHelp(commandDefinition) {
|
|
51
|
+
CLIDisplay.value(commandDefinition.command, commandDefinition.description);
|
|
52
|
+
CLIDisplay.break();
|
|
53
|
+
const defaultLabel = I18n.formatMessage("node.cli.commands.help.labels.default");
|
|
54
|
+
const optionsLabel = I18n.formatMessage("node.cli.commands.help.labels.options");
|
|
55
|
+
const requiredLabel = I18n.formatMessage("node.cli.commands.help.labels.required");
|
|
56
|
+
const optionalLabel = I18n.formatMessage("node.cli.commands.help.labels.optional");
|
|
57
|
+
if (commandDefinition.params.length > 0) {
|
|
58
|
+
for (const param of commandDefinition.params) {
|
|
59
|
+
const typeParts = [param.type];
|
|
60
|
+
if (Is.stringValue(param.extendedType)) {
|
|
61
|
+
typeParts.push(param.extendedType);
|
|
62
|
+
}
|
|
63
|
+
if (!Is.empty(param.defaultValue)) {
|
|
64
|
+
typeParts.push(`${defaultLabel}: '${param.defaultValue}'`);
|
|
65
|
+
}
|
|
66
|
+
if (param.required) {
|
|
67
|
+
typeParts.push(requiredLabel);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
typeParts.push(optionalLabel);
|
|
71
|
+
}
|
|
72
|
+
if (Is.arrayValue(param.options)) {
|
|
73
|
+
typeParts.push(`${optionsLabel}: [${param.options.join(", ")}]`);
|
|
74
|
+
}
|
|
75
|
+
CLIDisplay.value(param.key, `(${typeParts.join(", ")})`, 1);
|
|
76
|
+
CLIDisplay.value("", param.description, 1);
|
|
77
|
+
CLIDisplay.break();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (Is.stringValue(commandDefinition.example)) {
|
|
81
|
+
CLIDisplay.break();
|
|
82
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.help.labels.example"), commandDefinition.example);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../../src/commands/help.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAK1C,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,kBAExC;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,oCAAoC,CAAC;QACrE,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7C,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB,CAAC;QACtD,qBAAqB,EAAE,KAAK;KAC5B,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACzB,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K,EAAE,CAAC;QACnB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,uCAAuC,CAAC,EAC3D,iBAAiB,CAAC,OAAO,CACzB,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"help\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionHelp(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.help.description\"),\n\t\texample: \"\",\n\t\tparams: [],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\thelp(engineCore, envVars, params, commandDefinitions),\n\t\trequiresEngineStarted: false\n\t};\n}\n\n/**\n * Command for displaying help information.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The command parameters.\n * @param params.command The command to display help for.\n * @param commandDefinitions The registered command definitions.\n */\nexport async function help(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: { command?: string },\n\tcommandDefinitions: { [id: string]: ICliCommandDefinition }\n): Promise<void> {\n\tif (Is.stringValue(params.command)) {\n\t\tconst commandDefinition = commandDefinitions[params.command];\n\t\tif (commandDefinition) {\n\t\t\tdisplayCommandHelp(commandDefinition);\n\t\t}\n\t} else {\n\t\tCLIDisplay.value(\"\", I18n.formatMessage(\"node.cli.commands.help.labels.commands\"));\n\t\tCLIDisplay.break();\n\n\t\tfor (const commandId in commandDefinitions) {\n\t\t\tconst commandDef = commandDefinitions[commandId];\n\t\t\tif (commandId !== \"help\") {\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tcommandDef.command,\n\t\t\t\t\tI18n.formatMessage(`node.cli.commands.${commandDef.command}.description`)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Display help for a specific command.\n * @param commandDefinition The command definition.\n */\nfunction displayCommandHelp(commandDefinition: ICliCommandDefinition): void {\n\tCLIDisplay.value(commandDefinition.command, commandDefinition.description);\n\tCLIDisplay.break();\n\n\tconst defaultLabel = I18n.formatMessage(\"node.cli.commands.help.labels.default\");\n\tconst optionsLabel = I18n.formatMessage(\"node.cli.commands.help.labels.options\");\n\tconst requiredLabel = I18n.formatMessage(\"node.cli.commands.help.labels.required\");\n\tconst optionalLabel = I18n.formatMessage(\"node.cli.commands.help.labels.optional\");\n\n\tif (commandDefinition.params.length > 0) {\n\t\tfor (const param of commandDefinition.params) {\n\t\t\tconst typeParts: string[] = [param.type];\n\t\t\tif (Is.stringValue(param.extendedType)) {\n\t\t\t\ttypeParts.push(param.extendedType);\n\t\t\t}\n\t\t\tif (!Is.empty(param.defaultValue)) {\n\t\t\t\ttypeParts.push(`${defaultLabel}: '${param.defaultValue}'`);\n\t\t\t}\n\t\t\tif (param.required) {\n\t\t\t\ttypeParts.push(requiredLabel);\n\t\t\t} else {\n\t\t\t\ttypeParts.push(optionalLabel);\n\t\t\t}\n\n\t\t\tif (Is.arrayValue(param.options)) {\n\t\t\t\ttypeParts.push(`${optionsLabel}: [${param.options.join(\", \")}]`);\n\t\t\t}\n\n\t\t\tCLIDisplay.value(param.key, `(${typeParts.join(\", \")})`, 1);\n\n\t\t\tCLIDisplay.value(\"\", param.description, 1);\n\n\t\t\tCLIDisplay.break();\n\t\t}\n\t}\n\n\tif (Is.stringValue(commandDefinition.example)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.help.labels.example\"),\n\t\t\tcommandDefinition.example\n\t\t);\n\t}\n}\n"]}
|