@twin.org/node-core 0.0.3-next.4 → 0.0.3-next.40
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/README.md +3 -1
- package/dist/es/builders/engineEnvBuilder.js +443 -126
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +89 -32
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/extensionsBuilder.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 +199 -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 +327 -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 +228 -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 +239 -0
- package/dist/es/commands/userCreate.js.map +1 -0
- package/dist/es/commands/userUpdate.js +154 -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 +11 -4
- 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/models/nodeExtensionInitialiseEngineMethod.js +2 -0
- package/dist/es/models/nodeExtensionInitialiseEngineMethod.js.map +1 -0
- package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js +2 -0
- package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js.map +1 -0
- package/dist/es/models/nodeExtensionInitialiseMethod.js +2 -0
- package/dist/es/models/nodeExtensionInitialiseMethod.js.map +1 -0
- package/dist/es/models/nodeExtensionShutdownMethod.js +4 -0
- package/dist/es/models/nodeExtensionShutdownMethod.js.map +1 -0
- package/dist/es/node.js +86 -39
- 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 +12 -22
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +64 -1
- package/dist/types/builders/engineServerEnvBuilder.d.ts +11 -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 +51 -0
- package/dist/types/commands/userUpdate.d.ts +40 -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 +10 -1
- package/dist/types/index.d.ts +11 -4
- 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 +117 -60
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +8 -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/models/nodeExtensionInitialiseEngineMethod.d.ts +7 -0
- package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +8 -0
- package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +8 -0
- package/dist/types/models/nodeExtensionShutdownMethod.d.ts +5 -0
- package/dist/types/node.d.ts +5 -4
- package/dist/types/{server.d.ts → start.d.ts} +4 -2
- package/dist/types/utils.d.ts +6 -8
- package/docs/changelog.md +532 -176
- package/docs/examples.md +99 -1
- package/docs/reference/functions/buildConfiguration.md +1 -1
- package/docs/reference/functions/buildEngineServerConfiguration.md +1 -1
- 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/isAuthEntityStorageRequired.md +20 -0
- package/docs/reference/functions/isAutomationRequired.md +20 -0
- package/docs/reference/functions/isBackgroundTasksRequired.md +20 -0
- package/docs/reference/functions/isFederatedCatalogueRequired.md +20 -0
- package/docs/reference/functions/isImmutableProofRequired.md +20 -0
- package/docs/reference/functions/isRightsManagementRequired.md +20 -0
- package/docs/reference/functions/isTaskSchedulerRequired.md +20 -0
- package/docs/reference/functions/isTelemetryRequired.md +20 -0
- package/docs/reference/functions/isTrustRequired.md +20 -0
- package/docs/reference/functions/isUrlTransformerRequired.md +20 -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/resolvePackageEntryPoint.md +2 -2
- package/docs/reference/functions/run.md +8 -2
- package/docs/reference/functions/start.md +9 -3
- package/docs/reference/functions/substituteEnvOptions.md +25 -0
- package/docs/reference/index.md +26 -13
- package/docs/reference/interfaces/ICacheMetadata.md +3 -3
- 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 +420 -311
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +545 -368
- package/docs/reference/interfaces/IModuleProtocol.md +3 -3
- package/docs/reference/interfaces/INodeEngineState.md +4 -20
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +551 -450
- package/docs/reference/interfaces/INodeOptions.md +44 -36
- package/docs/reference/interfaces/IProtocolHandlerResult.md +2 -2
- package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +1 -1
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +1 -1
- package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +1 -1
- package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +1 -1
- package/docs/reference/variables/ModuleProtocol.md +5 -5
- package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
- package/docs/reference/variables/URL_TRANSFORMER_ENCRYPTION_KEY_ID.md +3 -0
- package/locales/en.json +600 -30
- package/package.json +10 -6
- package/dist/es/bootstrap.js +0 -366
- package/dist/es/bootstrap.js.map +0 -1
- package/dist/es/identity.js +0 -182
- package/dist/es/identity.js.map +0 -1
- package/dist/es/models/nodeExtensionMethods.js +0 -2
- package/dist/es/models/nodeExtensionMethods.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 -81
- package/dist/es/server.js.map +0 -1
- package/dist/types/bootstrap.d.ts +0 -68
- package/dist/types/identity.d.ts +0 -14
- package/dist/types/models/nodeExtensionMethods.d.ts +0 -27
- package/dist/types/models/nodeFeatures.d.ts +0 -21
- package/docs/detailed-guide.md +0 -129
- 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/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
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ContextIdKeys } from "@twin.org/context";
|
|
2
|
-
import { Coerce, Is } from "@twin.org/core";
|
|
2
|
+
import { Coerce, GeneralError, Is, StringHelper, Url } from "@twin.org/core";
|
|
3
3
|
import { addDefaultRestPaths, addDefaultSocketPaths } from "@twin.org/engine-server";
|
|
4
|
-
import { AuthenticationAdminComponentType, AuthenticationComponentType, InformationComponentType, RestRouteProcessorType, SocketRouteProcessorType } from "@twin.org/engine-server-types";
|
|
5
|
-
import {
|
|
6
|
-
import { NodeFeatures } from "../models/nodeFeatures.js";
|
|
7
|
-
import { getFeatures } from "../utils.js";
|
|
4
|
+
import { AuthenticationAdminComponentType, AuthenticationAuditComponentType, AuthenticationComponentType, AuthenticationRateComponentType, HostingComponentType, InformationComponentType, RestRouteProcessorType, SocketRouteProcessorType } from "@twin.org/engine-server-types";
|
|
5
|
+
import { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from "../defaults.js";
|
|
8
6
|
/**
|
|
9
7
|
* Handles the configuration of the server.
|
|
10
8
|
* @param envVars The environment variables for the engine server.
|
|
@@ -30,6 +28,19 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
30
28
|
: undefined,
|
|
31
29
|
corsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(",") : undefined
|
|
32
30
|
};
|
|
31
|
+
const localOrigin = `http://${webServerOptions.host ?? "localhost"}:${webServerOptions.port ?? 3000}`;
|
|
32
|
+
let publicOrigin;
|
|
33
|
+
if (Is.stringValue(envVars.publicOrigin)) {
|
|
34
|
+
const publicUrl = Url.tryParseExact(envVars.publicOrigin);
|
|
35
|
+
if (!Is.empty(publicUrl)) {
|
|
36
|
+
const urlParts = publicUrl.parts();
|
|
37
|
+
publicOrigin = `${urlParts.schema}://${urlParts.host}${Is.integer(urlParts.port) ? `:${urlParts.port}` : ""}`;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new GeneralError("node", "invalidPublicOrigin", { publicOrigin: envVars.publicOrigin });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const nodeIdentityEnabled = Coerce.boolean(envVars.nodeIdentityEnabled) ?? true;
|
|
33
44
|
const tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
|
|
34
45
|
if (tenantEnabled) {
|
|
35
46
|
webServerOptions.allowedHeaders ??= [];
|
|
@@ -53,6 +64,17 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
53
64
|
}
|
|
54
65
|
}
|
|
55
66
|
}
|
|
67
|
+
],
|
|
68
|
+
hostingComponent: [
|
|
69
|
+
{
|
|
70
|
+
type: HostingComponentType.Service,
|
|
71
|
+
options: {
|
|
72
|
+
config: {
|
|
73
|
+
localOrigin,
|
|
74
|
+
publicOrigin
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
56
78
|
]
|
|
57
79
|
}
|
|
58
80
|
};
|
|
@@ -69,12 +91,10 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
69
91
|
}
|
|
70
92
|
serverConfig.types.restRouteProcessor ??= [];
|
|
71
93
|
serverConfig.types.socketRouteProcessor ??= [];
|
|
72
|
-
|
|
73
|
-
const hasNodeId = features.includes(NodeFeatures.NodeId);
|
|
74
|
-
if (hasNodeId) {
|
|
94
|
+
if (nodeIdentityEnabled) {
|
|
75
95
|
availableContextIdKeys.push({
|
|
76
96
|
key: ContextIdKeys.Node,
|
|
77
|
-
|
|
97
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
78
98
|
});
|
|
79
99
|
serverConfig.types.restRouteProcessor.push({
|
|
80
100
|
type: RestRouteProcessorType.ContextId,
|
|
@@ -96,13 +116,19 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
96
116
|
if (tenantEnabled) {
|
|
97
117
|
availableContextIdKeys.push({
|
|
98
118
|
key: ContextIdKeys.Tenant,
|
|
99
|
-
|
|
119
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]
|
|
100
120
|
});
|
|
101
121
|
serverConfig.types.restRouteProcessor.push({
|
|
102
|
-
type: RestRouteProcessorType.Tenant
|
|
122
|
+
type: RestRouteProcessorType.Tenant,
|
|
123
|
+
options: {
|
|
124
|
+
config: {}
|
|
125
|
+
}
|
|
103
126
|
});
|
|
104
127
|
serverConfig.types.socketRouteProcessor.push({
|
|
105
|
-
type: SocketRouteProcessorType.Tenant
|
|
128
|
+
type: SocketRouteProcessorType.Tenant,
|
|
129
|
+
options: {
|
|
130
|
+
config: {}
|
|
131
|
+
}
|
|
106
132
|
});
|
|
107
133
|
}
|
|
108
134
|
if (!coreEngineConfig.silent) {
|
|
@@ -149,6 +175,18 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
149
175
|
}
|
|
150
176
|
});
|
|
151
177
|
const authAdminProcessorType = envVars.authAdminProcessorType;
|
|
178
|
+
const authProcessorType = envVars.authProcessorType;
|
|
179
|
+
if (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||
|
|
180
|
+
authProcessorType === AuthenticationComponentType.EntityStorage) {
|
|
181
|
+
serverConfig.types.authenticationRateComponent ??= [];
|
|
182
|
+
serverConfig.types.authenticationRateComponent.push({
|
|
183
|
+
type: AuthenticationRateComponentType.EntityStorage
|
|
184
|
+
});
|
|
185
|
+
serverConfig.types.authenticationAuditComponent ??= [];
|
|
186
|
+
serverConfig.types.authenticationAuditComponent.push({
|
|
187
|
+
type: AuthenticationAuditComponentType.EntityStorage
|
|
188
|
+
});
|
|
189
|
+
}
|
|
152
190
|
if (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage) {
|
|
153
191
|
serverConfig.types.authenticationAdminComponent ??= [];
|
|
154
192
|
serverConfig.types.authenticationAdminComponent.push({
|
|
@@ -158,22 +196,23 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
158
196
|
}
|
|
159
197
|
});
|
|
160
198
|
}
|
|
161
|
-
const authProcessorType = envVars.authProcessorType;
|
|
162
199
|
if (authProcessorType === AuthenticationComponentType.EntityStorage) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
200
|
+
if (nodeIdentityEnabled) {
|
|
201
|
+
availableContextIdKeys.push({
|
|
202
|
+
key: ContextIdKeys.Organization,
|
|
203
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
204
|
+
});
|
|
205
|
+
availableContextIdKeys.push({
|
|
206
|
+
key: ContextIdKeys.User,
|
|
207
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
208
|
+
});
|
|
209
|
+
}
|
|
171
210
|
serverConfig.types.authenticationComponent ??= [];
|
|
172
211
|
serverConfig.types.authenticationComponent.push({
|
|
173
212
|
type: AuthenticationComponentType.EntityStorage,
|
|
174
213
|
options: {
|
|
175
214
|
config: {
|
|
176
|
-
signingKeyName: envVars.authSigningKeyId
|
|
215
|
+
signingKeyName: envVars.authSigningKeyId
|
|
177
216
|
}
|
|
178
217
|
}
|
|
179
218
|
});
|
|
@@ -181,7 +220,7 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
181
220
|
type: RestRouteProcessorType.AuthHeader,
|
|
182
221
|
options: {
|
|
183
222
|
config: {
|
|
184
|
-
signingKeyName: envVars.authSigningKeyId
|
|
223
|
+
signingKeyName: envVars.authSigningKeyId
|
|
185
224
|
}
|
|
186
225
|
}
|
|
187
226
|
});
|
|
@@ -189,21 +228,39 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
189
228
|
type: SocketRouteProcessorType.AuthHeader,
|
|
190
229
|
options: {
|
|
191
230
|
config: {
|
|
192
|
-
signingKeyName: envVars.authSigningKeyId
|
|
231
|
+
signingKeyName: envVars.authSigningKeyId
|
|
193
232
|
}
|
|
194
233
|
}
|
|
195
234
|
});
|
|
196
235
|
}
|
|
197
|
-
if (Coerce.boolean(envVars.vcAuthenticationEnabled) ?? false) {
|
|
198
|
-
serverConfig.types.restRouteProcessor.push({
|
|
199
|
-
type: RestRouteProcessorType.AuthVerifiableCredential
|
|
200
|
-
});
|
|
201
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
202
|
-
type: SocketRouteProcessorType.AuthVerifiableCredential
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
236
|
addDefaultRestPaths(serverConfig);
|
|
206
237
|
addDefaultSocketPaths(serverConfig);
|
|
238
|
+
// See if any of the rest paths should be overridden by environment variables and update the config accordingly
|
|
239
|
+
for (const componentType in serverConfig.types) {
|
|
240
|
+
const types = serverConfig.types[componentType];
|
|
241
|
+
if (Is.arrayValue(types)) {
|
|
242
|
+
for (const typeConfig of types) {
|
|
243
|
+
if (Is.stringValue(typeConfig.restPath)) {
|
|
244
|
+
const envVarName = `restPath${StringHelper.pascalCase(componentType.replace("Component", ""))}`;
|
|
245
|
+
const overrideRestPath = envVars[envVarName];
|
|
246
|
+
if (Is.stringValue(overrideRestPath)) {
|
|
247
|
+
typeConfig.restPath = overrideRestPath;
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
207
254
|
return serverConfig;
|
|
208
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Checks if the authentication entity storage subsystem is required.
|
|
258
|
+
* Returns true when any component that depends on the authentication entity storage subsystem is enabled.
|
|
259
|
+
* @param envVars The environment variables.
|
|
260
|
+
* @returns True if authentication entity storage is enabled.
|
|
261
|
+
*/
|
|
262
|
+
export function isAuthEntityStorageRequired(envVars) {
|
|
263
|
+
return (envVars.authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||
|
|
264
|
+
envVars.authProcessorType === AuthenticationComponentType.EntityStorage);
|
|
265
|
+
}
|
|
209
266
|
//# sourceMappingURL=engineServerEnvBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineServerEnvBuilder.js","sourceRoot":"","sources":["../../../src/builders/engineServerEnvBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACN,gCAAgC,EAChC,2BAA2B,EAE3B,wBAAwB,EAExB,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACN,mBAAmB,EACnB,8BAA8B,EAC9B,iCAAiC,EACjC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CACnD,OAA0C,EAC1C,sBAAsE,EACtE,gBAAmC,EACnC,UAAuB,EACvB,eAAwB,EACxB,WAAoB;IAEpB,MAAM,gBAAgB,GAAsB;QAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACjC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACjC,OAAO,EAAE,EAAE,CAAC,WAAW,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C;QAClD,YAAY,CAAC,KAAK,CAAC,uBAAuB,CAAC,IAAI,CAAC;YAC/C,IAAI,EAAE,2BAA2B,CAAC,aAAa;YAC/C,OAAO,EAAE;gBACR,MAAM,EAAE;oBACP,cAAc,EAAE,OAAO,CAAC,gBAAgB,IAAI,mBAAmB;iBAC/D;aACD;SACD,CAAC,CAAC;QACH,YAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC;YAC1C,IAAI,EAAE,sBAAsB,CAAC,UAAU;YACvC,OAAO,EAAE;gBACR,MAAM,EAAE;oBACP,cAAc,EAAE,OAAO,CAAC,gBAAgB,IAAI,mBAAmB;iBAC/D;aACD;SACD,CAAC,CAAC;QACH,YAAY,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC;YAC5C,IAAI,EAAE,wBAAwB,CAAC,UAAU;YACzC,OAAO,EAAE;gBACR,MAAM,EAAE;oBACP,cAAc,EAAE,OAAO,CAAC,gBAAgB,IAAI,mBAAmB;iBAC/D;aACD;SACD,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,IAAI,KAAK,EAAE,CAAC;QAC9D,YAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC;YAC1C,IAAI,EAAE,sBAAsB,CAAC,wBAAwB;SACrD,CAAC,CAAC;QACH,YAAY,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC;YAC5C,IAAI,EAAE,wBAAwB,CAAC,wBAAwB;SACvD,CAAC,CAAC;IACJ,CAAC;IAED,mBAAmB,CAAC,YAAY,CAAC,CAAC;IAClC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAEpC,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IServerInfo, IWebServerOptions } from \"@twin.org/api-models\";\nimport { ContextIdKeys } from \"@twin.org/context\";\nimport { Coerce, Is } from \"@twin.org/core\";\nimport type { IEngineCoreConfig } from \"@twin.org/engine-models\";\nimport { addDefaultRestPaths, addDefaultSocketPaths } from \"@twin.org/engine-server\";\nimport {\n\tAuthenticationAdminComponentType,\n\tAuthenticationComponentType,\n\ttype IEngineServerConfig,\n\tInformationComponentType,\n\ttype MimeTypeProcessorType,\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType\n} from \"@twin.org/engine-server-types\";\nimport type { HttpMethod } from \"@twin.org/web\";\nimport {\n\tAUTH_SIGNING_KEY_ID,\n\tCONTEXT_ID_HANDLER_FEATURE_DID,\n\tCONTEXT_ID_HANDLER_FEATURE_TENANT\n} from \"../defaults.js\";\nimport type { IEngineServerEnvironmentVariables } from \"../models/IEngineServerEnvironmentVariables.js\";\nimport { NodeFeatures } from \"../models/nodeFeatures.js\";\nimport { getFeatures } from \"../utils.js\";\n\n/**\n * Handles the configuration of the server.\n * @param envVars The environment variables for the engine server.\n * @param availableContextIdKeys The context ID keys.\n * @param coreEngineConfig The core engine config.\n * @param serverInfo The server information.\n * @param openApiSpecPath The path to the open api spec.\n * @param favIconPath The path to the favicon.\n * @returns The config for the core and the server.\n */\nexport async function buildEngineServerConfiguration(\n\tenvVars: IEngineServerEnvironmentVariables,\n\tavailableContextIdKeys: { key: string; componentFeatures: string[] }[],\n\tcoreEngineConfig: IEngineCoreConfig,\n\tserverInfo: IServerInfo,\n\topenApiSpecPath?: string,\n\tfavIconPath?: string\n): Promise<IEngineServerConfig> {\n\tconst webServerOptions: IWebServerOptions = {\n\t\tport: Coerce.number(envVars.port),\n\t\thost: Coerce.string(envVars.host),\n\t\tmethods: Is.stringValue(envVars.httpMethods)\n\t\t\t? (envVars.httpMethods.split(\",\") as HttpMethod[])\n\t\t\t: undefined,\n\t\tallowedHeaders: Is.stringValue(envVars.httpAllowedHeaders)\n\t\t\t? envVars.httpAllowedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\texposedHeaders: Is.stringValue(envVars.httpExposedHeaders)\n\t\t\t? envVars.httpExposedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\tcorsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(\",\") : undefined\n\t};\n\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(\"x-api-key\")) {\n\t\t\twebServerOptions.allowedHeaders.push(\"x-api-key\");\n\t\t}\n\t}\n\n\tconst serverConfig: IEngineServerConfig = {\n\t\t...coreEngineConfig,\n\t\tweb: webServerOptions,\n\t\ttypes: {\n\t\t\t...coreEngineConfig.types,\n\t\t\tinformationComponent: [\n\t\t\t\t{\n\t\t\t\t\ttype: InformationComponentType.Service,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tserverInfo,\n\t\t\t\t\t\t\topenApiSpecPath,\n\t\t\t\t\t\t\tfavIconPath\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t};\n\n\tif (Is.stringValue(envVars.mimeTypeProcessors)) {\n\t\tconst mimeTypeProcessors = envVars.mimeTypeProcessors.split(\",\");\n\n\t\tif (Is.arrayValue(mimeTypeProcessors)) {\n\t\t\tserverConfig.types.mimeTypeProcessor ??= [];\n\t\t\tfor (const mimeTypeProcessor of mimeTypeProcessors) {\n\t\t\t\tserverConfig.types.mimeTypeProcessor.push({\n\t\t\t\t\ttype: mimeTypeProcessor as MimeTypeProcessorType\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tserverConfig.types.restRouteProcessor ??= [];\n\tserverConfig.types.socketRouteProcessor ??= [];\n\n\tconst features = getFeatures(envVars);\n\tconst hasNodeId = features.includes(NodeFeatures.NodeId);\n\n\tif (hasNodeId) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Node,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (tenantEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Tenant,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tenant\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Tenant\n\t\t});\n\t}\n\n\tif (!coreEngineConfig.silent) {\n\t\tconst includeBody = Coerce.boolean(envVars.routeLoggingIncludeBody) ?? coreEngineConfig.debug;\n\t\tconst fullBase64 = Coerce.boolean(envVars.routeLoggingFullBase64) ?? false;\n\t\tconst obfuscateProperties = Is.stringValue(envVars.routeLoggingObfuscateProperties)\n\t\t\t? envVars.routeLoggingObfuscateProperties.split(\",\")\n\t\t\t: undefined;\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.RestRoute,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.SocketRoute,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\n\tconst authAdminProcessorType = envVars.authAdminProcessorType;\n\tif (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage) {\n\t\tserverConfig.types.authenticationAdminComponent ??= [];\n\t\tserverConfig.types.authenticationAdminComponent.push({\n\t\t\ttype: AuthenticationAdminComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {}\n\t\t\t}\n\t\t});\n\t}\n\n\tconst authProcessorType = envVars.authProcessorType;\n\tif (authProcessorType === AuthenticationComponentType.EntityStorage) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.User,\n\t\t\tcomponentFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.authenticationComponent ??= [];\n\t\tserverConfig.types.authenticationComponent.push({\n\t\t\ttype: AuthenticationComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (Coerce.boolean(envVars.vcAuthenticationEnabled) ?? false) {\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.AuthVerifiableCredential\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.AuthVerifiableCredential\n\t\t});\n\t}\n\n\taddDefaultRestPaths(serverConfig);\n\taddDefaultSocketPaths(serverConfig);\n\n\treturn serverConfig;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"engineServerEnvBuilder.js","sourceRoot":"","sources":["../../../src/builders/engineServerEnvBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,2BAA2B,EAC3B,+BAA+B,EAC/B,oBAAoB,EAEpB,wBAAwB,EAExB,sBAAsB,EACtB,wBAAwB,EACxB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,8BAA8B,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAGnG;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CACnD,OAA+E,EAC/E,sBA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,aAAa,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAEhD,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,KAAK,MAAM,UAAU,IAAI,KAAK,EAAE,CAAC;gBAChC,IAAI,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACzC,MAAM,UAAU,GAAG,WAAW,YAAY,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC;oBAChG,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;oBAC7C,IAAI,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;wBACtC,UAAU,CAAC,QAAQ,GAAG,gBAAgB,CAAC;oBACxC,CAAC;oBACD,MAAM;gBACP,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,YAAY,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA0C;IACrF,OAAO,CACN,OAAO,CAAC,sBAAsB,KAAK,gCAAgC,CAAC,aAAa;QACjF,OAAO,CAAC,iBAAiB,KAAK,2BAA2B,CAAC,aAAa,CACvE,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IServerInfo, IWebServerOptions } from \"@twin.org/api-models\";\nimport { ContextIdKeys } from \"@twin.org/context\";\nimport { Coerce, GeneralError, Is, StringHelper, Url } from \"@twin.org/core\";\nimport type { IEngineCoreConfig } from \"@twin.org/engine-models\";\nimport { addDefaultRestPaths, addDefaultSocketPaths } from \"@twin.org/engine-server\";\nimport {\n\tAuthenticationAdminComponentType,\n\tAuthenticationAuditComponentType,\n\tAuthenticationComponentType,\n\tAuthenticationRateComponentType,\n\tHostingComponentType,\n\ttype IEngineServerConfig,\n\tInformationComponentType,\n\ttype MimeTypeProcessorType,\n\tRestRouteProcessorType,\n\tSocketRouteProcessorType\n} from \"@twin.org/engine-server-types\";\nimport type { HttpMethod } from \"@twin.org/web\";\nimport { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from \"../defaults.js\";\nimport type { IEngineServerEnvironmentVariables } from \"../models/IEngineServerEnvironmentVariables.js\";\n\n/**\n * Handles the configuration of the server.\n * @param envVars The environment variables for the engine server.\n * @param availableContextIdKeys The context ID keys.\n * @param coreEngineConfig The core engine config.\n * @param serverInfo The server information.\n * @param openApiSpecPath The path to the open api spec.\n * @param favIconPath The path to the favicon.\n * @returns The config for the core and the server.\n */\nexport async function buildEngineServerConfiguration(\n\tenvVars: IEngineServerEnvironmentVariables & { [id: string]: string | unknown },\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[],\n\tcoreEngineConfig: IEngineCoreConfig,\n\tserverInfo: IServerInfo,\n\topenApiSpecPath?: string,\n\tfavIconPath?: string\n): Promise<IEngineServerConfig> {\n\tconst webServerOptions: IWebServerOptions = {\n\t\tport: Coerce.number(envVars.port),\n\t\thost: Coerce.string(envVars.host),\n\t\tmethods: Is.stringValue(envVars.httpMethods)\n\t\t\t? (envVars.httpMethods.split(\",\") as HttpMethod[])\n\t\t\t: undefined,\n\t\tallowedHeaders: Is.stringValue(envVars.httpAllowedHeaders)\n\t\t\t? envVars.httpAllowedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\texposedHeaders: Is.stringValue(envVars.httpExposedHeaders)\n\t\t\t? envVars.httpExposedHeaders.split(\",\")\n\t\t\t: undefined,\n\t\tcorsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(\",\") : undefined\n\t};\n\n\tconst localOrigin = `http://${webServerOptions.host ?? \"localhost\"}:${webServerOptions.port ?? 3000}`;\n\n\tlet publicOrigin;\n\tif (Is.stringValue(envVars.publicOrigin)) {\n\t\tconst publicUrl = Url.tryParseExact(envVars.publicOrigin);\n\t\tif (!Is.empty(publicUrl)) {\n\t\t\tconst urlParts = publicUrl.parts();\n\t\t\tpublicOrigin = `${urlParts.schema}://${urlParts.host}${Is.integer(urlParts.port) ? `:${urlParts.port}` : \"\"}`;\n\t\t} else {\n\t\t\tthrow new GeneralError(\"node\", \"invalidPublicOrigin\", { publicOrigin: envVars.publicOrigin });\n\t\t}\n\t}\n\n\tconst nodeIdentityEnabled = Coerce.boolean(envVars.nodeIdentityEnabled) ?? true;\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(\"x-api-key\")) {\n\t\t\twebServerOptions.allowedHeaders.push(\"x-api-key\");\n\t\t}\n\t}\n\n\tconst serverConfig: IEngineServerConfig = {\n\t\t...coreEngineConfig,\n\t\tweb: webServerOptions,\n\t\ttypes: {\n\t\t\t...coreEngineConfig.types,\n\t\t\tinformationComponent: [\n\t\t\t\t{\n\t\t\t\t\ttype: InformationComponentType.Service,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tserverInfo,\n\t\t\t\t\t\t\topenApiSpecPath,\n\t\t\t\t\t\t\tfavIconPath\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t],\n\t\t\thostingComponent: [\n\t\t\t\t{\n\t\t\t\t\ttype: HostingComponentType.Service,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tlocalOrigin,\n\t\t\t\t\t\t\tpublicOrigin\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t};\n\n\tif (Is.stringValue(envVars.mimeTypeProcessors)) {\n\t\tconst mimeTypeProcessors = envVars.mimeTypeProcessors.split(\",\");\n\n\t\tif (Is.arrayValue(mimeTypeProcessors)) {\n\t\t\tserverConfig.types.mimeTypeProcessor ??= [];\n\t\t\tfor (const mimeTypeProcessor of mimeTypeProcessors) {\n\t\t\t\tserverConfig.types.mimeTypeProcessor.push({\n\t\t\t\t\ttype: mimeTypeProcessor as MimeTypeProcessorType\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tserverConfig.types.restRouteProcessor ??= [];\n\tserverConfig.types.socketRouteProcessor ??= [];\n\n\tif (nodeIdentityEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Node,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.ContextId,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (tenantEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Tenant,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Tenant,\n\t\t\toptions: {\n\t\t\t\tconfig: {}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Tenant,\n\t\t\toptions: {\n\t\t\t\tconfig: {}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (!coreEngineConfig.silent) {\n\t\tconst includeBody = Coerce.boolean(envVars.routeLoggingIncludeBody) ?? coreEngineConfig.debug;\n\t\tconst fullBase64 = Coerce.boolean(envVars.routeLoggingFullBase64) ?? false;\n\t\tconst obfuscateProperties = Is.stringValue(envVars.routeLoggingObfuscateProperties)\n\t\t\t? envVars.routeLoggingObfuscateProperties.split(\",\")\n\t\t\t: undefined;\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.Logging,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tincludeBody,\n\t\t\t\t\tfullBase64,\n\t\t\t\t\tobfuscateProperties\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.RestRoute,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.SocketRoute,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tincludeErrorStack: coreEngineConfig.debug\n\t\t\t}\n\t\t}\n\t});\n\n\tconst authAdminProcessorType = envVars.authAdminProcessorType;\n\tconst authProcessorType = envVars.authProcessorType;\n\n\tif (\n\t\tauthAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||\n\t\tauthProcessorType === AuthenticationComponentType.EntityStorage\n\t) {\n\t\tserverConfig.types.authenticationRateComponent ??= [];\n\t\tserverConfig.types.authenticationRateComponent.push({\n\t\t\ttype: AuthenticationRateComponentType.EntityStorage\n\t\t});\n\n\t\tserverConfig.types.authenticationAuditComponent ??= [];\n\t\tserverConfig.types.authenticationAuditComponent.push({\n\t\t\ttype: AuthenticationAuditComponentType.EntityStorage\n\t\t});\n\t}\n\n\tif (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage) {\n\t\tserverConfig.types.authenticationAdminComponent ??= [];\n\t\tserverConfig.types.authenticationAdminComponent.push({\n\t\t\ttype: AuthenticationAdminComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {}\n\t\t\t}\n\t\t});\n\t}\n\n\tif (authProcessorType === AuthenticationComponentType.EntityStorage) {\n\t\tif (nodeIdentityEnabled) {\n\t\t\tavailableContextIdKeys.push({\n\t\t\t\tkey: ContextIdKeys.Organization,\n\t\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t\t});\n\t\t\tavailableContextIdKeys.push({\n\t\t\t\tkey: ContextIdKeys.User,\n\t\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t\t});\n\t\t}\n\n\t\tserverConfig.types.authenticationComponent ??= [];\n\t\tserverConfig.types.authenticationComponent.push({\n\t\t\ttype: AuthenticationComponentType.EntityStorage,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.AuthHeader,\n\t\t\toptions: {\n\t\t\t\tconfig: {\n\t\t\t\t\tsigningKeyName: envVars.authSigningKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\taddDefaultRestPaths(serverConfig);\n\taddDefaultSocketPaths(serverConfig);\n\n\t// See if any of the rest paths should be overridden by environment variables and update the config accordingly\n\tfor (const componentType in serverConfig.types) {\n\t\tconst types = serverConfig.types[componentType];\n\n\t\tif (Is.arrayValue(types)) {\n\t\t\tfor (const typeConfig of types) {\n\t\t\t\tif (Is.stringValue(typeConfig.restPath)) {\n\t\t\t\t\tconst envVarName = `restPath${StringHelper.pascalCase(componentType.replace(\"Component\", \"\"))}`;\n\t\t\t\t\tconst overrideRestPath = envVars[envVarName];\n\t\t\t\t\tif (Is.stringValue(overrideRestPath)) {\n\t\t\t\t\t\ttypeConfig.restPath = overrideRestPath;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn serverConfig;\n}\n\n/**\n * Checks if the authentication entity storage subsystem is required.\n * Returns true when any component that depends on the authentication entity storage subsystem is enabled.\n * @param envVars The environment variables.\n * @returns True if authentication entity storage is enabled.\n */\nexport function isAuthEntityStorageRequired(envVars: IEngineServerEnvironmentVariables): boolean {\n\treturn (\n\t\tenvVars.authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||\n\t\tenvVars.authProcessorType === AuthenticationComponentType.EntityStorage\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensionsBuilder.js","sourceRoot":"","sources":["../../../src/builders/extensionsBuilder.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"extensionsBuilder.js","sourceRoot":"","sources":["../../../src/builders/extensionsBuilder.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAA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,CAAC,CAAA,CAAC;YAEV,IAAI,EAAE,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,CAAC;gBAC/C,MAAM,4BAA4B,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YAC9D,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,OAAkC,EAClC,UAAuB;IAEvB,IAAI,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACxC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACpC,cAAc,CAAC,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;YAErD,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;gBAC3C,cAAc,CAAC,SAAS,CAAC,CAAC,WAAW,GAAG,KAAK,CAAC;gBAC9C,IAAI,cAAuD,CAAC;gBAC5D,IAAI,CAAC;oBACJ,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,wBAAwB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;oBAChF,cAAc,GAAG,MAAM,YAAY,CAAC,eAAe,CAClD,SAAS,EACT,mBAAmB,CACnB,CAAC;gBACH,CAAC;gBAAC,MAAM,CAAC,CAAA,CAAC;gBAEV,IAAI,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;oBACjC,MAAM,cAAc,EAAE,CAAC;gBACxB,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore, IEngineServer } from \"@twin.org/engine-models\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\nimport type { NodeExtensionInitialiseEngineMethod } from \"../models/nodeExtensionInitialiseEngineMethod.js\";\nimport type { NodeExtensionInitialiseEngineServerMethod } from \"../models/nodeExtensionInitialiseEngineServerMethod.js\";\nimport type { NodeExtensionInitialiseMethod } from \"../models/nodeExtensionInitialiseMethod.js\";\nimport type { NodeExtensionShutdownMethod } from \"../models/nodeExtensionShutdownMethod.js\";\n\nconst extensionState: { [id: string]: { initialised: boolean } } = {};\n\n/**\n * Handles the configuration of the extensions.\n * @param envVars The environment variables for the node.\n * @param nodeEngineConfig The node engine config.\n * @returns The config for the core and the server.\n */\nexport async function extensionsConfiguration(\n\tenvVars: INodeEnvironmentVariables,\n\tnodeEngineConfig: INodeEngineConfig\n): Promise<INodeEngineConfig> {\n\tif (Is.stringValue(envVars.extensions)) {\n\t\tconst extensions = envVars.extensions.split(\",\");\n\n\t\tfor (const extension of extensions) {\n\t\t\tlet initialiseConfigMethod: NodeExtensionInitialiseMethod | undefined;\n\t\t\ttry {\n\t\t\t\tCLIDisplay.value(I18n.formatMessage(\"node.extensionLoading\"), extension);\n\n\t\t\t\tinitialiseConfigMethod = await ModuleHelper.getModuleMethod<NodeExtensionInitialiseMethod>(\n\t\t\t\t\textension,\n\t\t\t\t\t\"extensionInitialise\"\n\t\t\t\t);\n\t\t\t} catch (err) {\n\t\t\t\tthrow new GeneralError(\"node\", \"extensionLoadingError\", { extension }, err);\n\t\t\t}\n\n\t\t\tif (Is.function(initialiseConfigMethod)) {\n\t\t\t\tawait initialiseConfigMethod(envVars, nodeEngineConfig);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodeEngineConfig;\n}\n\n/**\n * Handles the initialisation of the extensions when the engine has been constructed.\n * @param envVars The environment variables for the node.\n * @param engineCore The engine core instance.\n * @returns Nothing.\n */\nexport async function extensionsInitialiseEngine(\n\tenvVars: INodeEnvironmentVariables,\n\tengineCore: IEngineCore\n): Promise<void> {\n\tif (Is.stringValue(envVars.extensions)) {\n\t\tconst extensions = envVars.extensions.split(\",\");\n\n\t\tfor (const extension of extensions) {\n\t\t\textensionState[extension] ??= { initialised: false };\n\n\t\t\tif (!extensionState[extension].initialised) {\n\t\t\t\textensionState[extension].initialised = true;\n\n\t\t\t\tlet initialiseEngineMethod: NodeExtensionInitialiseEngineMethod | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.extensionInitialisingEngine\", { extension }));\n\t\t\t\t\tinitialiseEngineMethod =\n\t\t\t\t\t\tawait ModuleHelper.getModuleMethod<NodeExtensionInitialiseEngineMethod>(\n\t\t\t\t\t\t\textension,\n\t\t\t\t\t\t\t\"extensionInitialiseEngine\"\n\t\t\t\t\t\t);\n\t\t\t\t} catch {}\n\n\t\t\t\tif (Is.function(initialiseEngineMethod)) {\n\t\t\t\t\tawait initialiseEngineMethod(engineCore);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Handles the initialisation of the extensions when the engine server has been constructed.\n * @param envVars The environment variables for the node.\n * @param engineCore The engine core instance.\n * @param engineServer The engine server instance.\n * @returns Nothing.\n */\nexport async function extensionsInitialiseEngineServer(\n\tenvVars: INodeEnvironmentVariables,\n\tengineCore: IEngineCore,\n\tengineServer: IEngineServer\n): Promise<void> {\n\tif (Is.stringValue(envVars.extensions)) {\n\t\tconst extensions = envVars.extensions.split(\",\");\n\n\t\tfor (const extension of extensions) {\n\t\t\tlet initialiseEngineServerMethod: NodeExtensionInitialiseEngineServerMethod | undefined;\n\t\t\ttry {\n\t\t\t\tengineCore.logInfo(\n\t\t\t\t\tI18n.formatMessage(\"node.extensionInitialisingEngineServer\", { extension })\n\t\t\t\t);\n\t\t\t\tinitialiseEngineServerMethod =\n\t\t\t\t\tawait ModuleHelper.getModuleMethod<NodeExtensionInitialiseEngineServerMethod>(\n\t\t\t\t\t\textension,\n\t\t\t\t\t\t\"extensionInitialiseEngineServer\"\n\t\t\t\t\t);\n\t\t\t} catch {}\n\n\t\t\tif (Is.function(initialiseEngineServerMethod)) {\n\t\t\t\tawait initialiseEngineServerMethod(engineCore, engineServer);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Handles the shutdown of the extensions.\n * @param envVars The environment variables for the node.\n * @param engineCore The engine core instance.\n * @returns Nothing.\n */\nexport async function shutdownExtensions(\n\tenvVars: INodeEnvironmentVariables,\n\tengineCore: IEngineCore\n): Promise<void> {\n\tif (Is.stringValue(envVars.extensions)) {\n\t\tconst extensions = envVars.extensions.split(\",\");\n\n\t\tfor (const extension of extensions) {\n\t\t\textensionState[extension] ??= { initialised: false };\n\n\t\t\tif (extensionState[extension].initialised) {\n\t\t\t\textensionState[extension].initialised = false;\n\t\t\t\tlet shutdownMethod: NodeExtensionShutdownMethod | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.extensionShutdown\", { extension }));\n\t\t\t\t\tshutdownMethod = await ModuleHelper.getModuleMethod<NodeExtensionShutdownMethod>(\n\t\t\t\t\t\textension,\n\t\t\t\t\t\t\"extensionShutdown\"\n\t\t\t\t\t);\n\t\t\t\t} catch {}\n\n\t\t\t\tif (Is.function(shutdownMethod)) {\n\t\t\t\t\tawait shutdownMethod();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
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,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AE,kBAAkB,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACvF,CAAC;YACD,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC;QACvB,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC/B,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;IAC7C,mCAAmC,CAAC,kBAAkB,CAAC,CAAC;IACxD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,kCAAkC,CAAC,kBAAkB,CAAC,CAAC;IACvD,oDAAoD,CAAC,kBAAkB,CAAC,CAAC;IACzE,oDAAoD,CAAC,kBAAkB,CAAC,CAAC;IACzE,sDAAsD,CAAC,kBAAkB,CAAC,CAAC;IAC3E,mCAAmC,CAAC,kBAAkB,CAAC,CAAC;IACxD,iCAAiC,CAAC,kBAAkB,CAAC,CAAC;IACtD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,gCAAgC,CAAC,kBAAkB,CAAC,CAAC;IACrD,8BAA8B,CAAC,kBAAkB,CAAC,CAAC;IACnD,8BAA8B,CAAC,kBAAkB,CAAC,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"]}
|