@twin.org/node-core 0.0.3-next.6 → 0.0.3-next.60
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 +538 -213
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +86 -39
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/extensionsBuilder.js +3 -3
- package/dist/es/builders/extensionsBuilder.js.map +1 -1
- package/dist/es/cli.js +254 -0
- package/dist/es/cli.js.map +1 -0
- package/dist/es/commands/bootstrapLegacy.js +311 -0
- package/dist/es/commands/bootstrapLegacy.js.map +1 -0
- package/dist/es/commands/help.js +86 -0
- package/dist/es/commands/help.js.map +1 -0
- package/dist/es/commands/identityCreate.js +377 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityImports.js +83 -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 +230 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js +127 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
- package/dist/es/commands/nodeSetIdentity.js +69 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -0
- package/dist/es/commands/removeTenantOrgAlias.js +83 -0
- package/dist/es/commands/removeTenantOrgAlias.js.map +1 -0
- package/dist/es/commands/setNodeOrgId.js +62 -0
- package/dist/es/commands/setNodeOrgId.js.map +1 -0
- package/dist/es/commands/setTenantOrgId.js +99 -0
- package/dist/es/commands/setTenantOrgId.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +165 -0
- package/dist/es/commands/tenantCreate.js.map +1 -0
- package/dist/es/commands/tenantImport.js +108 -0
- package/dist/es/commands/tenantImport.js.map +1 -0
- package/dist/es/commands/tenantUpdate.js +108 -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 +105 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -0
- package/dist/es/defaults.js +37 -2
- 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 +87 -40
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +189 -0
- package/dist/es/start.js.map +1 -0
- package/dist/es/utils.js +24 -27
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +60 -5
- package/dist/types/builders/engineServerEnvBuilder.d.ts +11 -2
- package/dist/types/builders/extensionsBuilder.d.ts +3 -3
- package/dist/types/cli.d.ts +56 -0
- package/dist/types/commands/bootstrapLegacy.d.ts +67 -0
- package/dist/types/commands/help.d.ts +24 -0
- package/dist/types/commands/identityCreate.d.ts +45 -0
- package/dist/types/commands/identityImports.d.ts +25 -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 +32 -0
- package/dist/types/commands/nodeSetIdentity.d.ts +23 -0
- package/dist/types/commands/removeTenantOrgAlias.d.ts +24 -0
- package/dist/types/commands/setNodeOrgId.d.ts +24 -0
- package/dist/types/commands/setTenantOrgId.d.ts +38 -0
- package/dist/types/commands/tenantCreate.d.ts +41 -0
- package/dist/types/commands/tenantImport.d.ts +29 -0
- package/dist/types/commands/tenantUpdate.d.ts +29 -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 +29 -0
- package/dist/types/defaults.d.ts +30 -2
- 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 +168 -95
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +8 -0
- package/dist/types/models/INodeEngineState.d.ts +2 -9
- 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 +8 -0
- package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +9 -0
- package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +9 -0
- package/dist/types/models/nodeExtensionShutdownMethod.d.ts +6 -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 +9 -10
- package/docs/changelog.md +675 -180
- package/docs/examples.md +99 -1
- package/docs/reference/functions/buildConfiguration.md +1 -1
- package/docs/reference/functions/buildEngineConfiguration.md +1 -7
- 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/extensionsInitialiseEngine.md +1 -1
- package/docs/reference/functions/extensionsInitialiseEngineServer.md +1 -1
- package/docs/reference/functions/getEnvDefaults.md +19 -0
- package/docs/reference/functions/getScriptDirectory.md +19 -0
- package/docs/reference/functions/initialiseLocales.md +2 -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 +23 -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/loadJsonFile.md +1 -1
- package/docs/reference/functions/loadTextFile.md +1 -1
- 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/shutdownExtensions.md +1 -1
- package/docs/reference/functions/start.md +9 -3
- package/docs/reference/functions/substituteEnvOptions.md +25 -0
- package/docs/reference/index.md +24 -14
- 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 +488 -359
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +652 -431
- package/docs/reference/interfaces/IModuleProtocol.md +3 -3
- package/docs/reference/interfaces/INodeEngineState.md +6 -21
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +661 -516
- 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 +3 -1
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +3 -1
- package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +3 -1
- package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +3 -1
- package/docs/reference/variables/ATTESTATION_VERIFICATION_METHOD_ID.md +2 -0
- package/docs/reference/variables/AUTH_SIGNING_KEY_ID.md +2 -0
- package/docs/reference/variables/BLOB_STORAGE_ENCRYPTION_KEY_ID.md +2 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +2 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +2 -0
- package/docs/reference/variables/IMMUTABLE_PROOF_VERIFICATION_METHOD_ID.md +2 -0
- package/docs/reference/variables/ModuleProtocol.md +5 -5
- package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +5 -0
- package/locales/en.json +674 -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/SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID.md +0 -3
- 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, Is, StringHelper } 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, 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.
|
|
@@ -28,13 +26,15 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
28
26
|
exposedHeaders: Is.stringValue(envVars.httpExposedHeaders)
|
|
29
27
|
? envVars.httpExposedHeaders.split(",")
|
|
30
28
|
: undefined,
|
|
31
|
-
corsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(",") : undefined
|
|
29
|
+
corsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(",") : undefined,
|
|
30
|
+
publicOrigin: Coerce.string(envVars.publicOrigin)
|
|
32
31
|
};
|
|
33
32
|
const tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
|
|
33
|
+
const apiKeyHeader = envVars.authApiKeyHeader ?? "x-api-key";
|
|
34
34
|
if (tenantEnabled) {
|
|
35
35
|
webServerOptions.allowedHeaders ??= [];
|
|
36
|
-
if (!webServerOptions.allowedHeaders.includes(
|
|
37
|
-
webServerOptions.allowedHeaders.push(
|
|
36
|
+
if (!webServerOptions.allowedHeaders.includes(apiKeyHeader)) {
|
|
37
|
+
webServerOptions.allowedHeaders.push(apiKeyHeader);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
const serverConfig = {
|
|
@@ -69,40 +69,62 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
69
69
|
}
|
|
70
70
|
serverConfig.types.restRouteProcessor ??= [];
|
|
71
71
|
serverConfig.types.socketRouteProcessor ??= [];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
availableContextIdKeys.push({
|
|
73
|
+
key: ContextIdKeys.Node,
|
|
74
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
75
|
+
});
|
|
76
|
+
serverConfig.types.restRouteProcessor.push({
|
|
77
|
+
type: RestRouteProcessorType.ContextId,
|
|
78
|
+
options: {
|
|
79
|
+
config: {
|
|
80
|
+
key: ContextIdKeys.Node
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
serverConfig.types.socketRouteProcessor.push({
|
|
85
|
+
type: SocketRouteProcessorType.ContextId,
|
|
86
|
+
options: {
|
|
87
|
+
config: {
|
|
88
|
+
key: ContextIdKeys.Node
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
if (tenantEnabled) {
|
|
93
|
+
availableContextIdKeys.push({
|
|
94
|
+
key: ContextIdKeys.Organization,
|
|
95
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
96
|
+
});
|
|
75
97
|
availableContextIdKeys.push({
|
|
76
|
-
key: ContextIdKeys.
|
|
77
|
-
|
|
98
|
+
key: ContextIdKeys.Tenant,
|
|
99
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_TENANT]
|
|
78
100
|
});
|
|
79
101
|
serverConfig.types.restRouteProcessor.push({
|
|
80
|
-
type: RestRouteProcessorType.
|
|
102
|
+
type: RestRouteProcessorType.Tenant,
|
|
81
103
|
options: {
|
|
82
104
|
config: {
|
|
83
|
-
|
|
105
|
+
apiKeyName: apiKeyHeader
|
|
84
106
|
}
|
|
85
107
|
}
|
|
86
108
|
});
|
|
87
109
|
serverConfig.types.socketRouteProcessor.push({
|
|
88
|
-
type: SocketRouteProcessorType.
|
|
110
|
+
type: SocketRouteProcessorType.Tenant,
|
|
89
111
|
options: {
|
|
90
112
|
config: {
|
|
91
|
-
|
|
113
|
+
apiKeyName: apiKeyHeader
|
|
92
114
|
}
|
|
93
115
|
}
|
|
94
116
|
});
|
|
95
117
|
}
|
|
96
|
-
|
|
118
|
+
else {
|
|
97
119
|
availableContextIdKeys.push({
|
|
98
|
-
key: ContextIdKeys.
|
|
99
|
-
|
|
120
|
+
key: ContextIdKeys.Organization,
|
|
121
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
100
122
|
});
|
|
101
123
|
serverConfig.types.restRouteProcessor.push({
|
|
102
|
-
type: RestRouteProcessorType.
|
|
124
|
+
type: RestRouteProcessorType.SingleTenant
|
|
103
125
|
});
|
|
104
126
|
serverConfig.types.socketRouteProcessor.push({
|
|
105
|
-
type: SocketRouteProcessorType.
|
|
127
|
+
type: SocketRouteProcessorType.SingleTenant
|
|
106
128
|
});
|
|
107
129
|
}
|
|
108
130
|
if (!coreEngineConfig.silent) {
|
|
@@ -149,6 +171,18 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
149
171
|
}
|
|
150
172
|
});
|
|
151
173
|
const authAdminProcessorType = envVars.authAdminProcessorType;
|
|
174
|
+
const authProcessorType = envVars.authProcessorType;
|
|
175
|
+
if (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||
|
|
176
|
+
authProcessorType === AuthenticationComponentType.EntityStorage) {
|
|
177
|
+
serverConfig.types.authenticationRateComponent ??= [];
|
|
178
|
+
serverConfig.types.authenticationRateComponent.push({
|
|
179
|
+
type: AuthenticationRateComponentType.EntityStorage
|
|
180
|
+
});
|
|
181
|
+
serverConfig.types.authenticationAuditComponent ??= [];
|
|
182
|
+
serverConfig.types.authenticationAuditComponent.push({
|
|
183
|
+
type: AuthenticationAuditComponentType.EntityStorage
|
|
184
|
+
});
|
|
185
|
+
}
|
|
152
186
|
if (authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage) {
|
|
153
187
|
serverConfig.types.authenticationAdminComponent ??= [];
|
|
154
188
|
serverConfig.types.authenticationAdminComponent.push({
|
|
@@ -158,22 +192,17 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
158
192
|
}
|
|
159
193
|
});
|
|
160
194
|
}
|
|
161
|
-
const authProcessorType = envVars.authProcessorType;
|
|
162
195
|
if (authProcessorType === AuthenticationComponentType.EntityStorage) {
|
|
163
|
-
availableContextIdKeys.push({
|
|
164
|
-
key: ContextIdKeys.Organization,
|
|
165
|
-
componentFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
166
|
-
});
|
|
167
196
|
availableContextIdKeys.push({
|
|
168
197
|
key: ContextIdKeys.User,
|
|
169
|
-
|
|
198
|
+
requiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]
|
|
170
199
|
});
|
|
171
200
|
serverConfig.types.authenticationComponent ??= [];
|
|
172
201
|
serverConfig.types.authenticationComponent.push({
|
|
173
202
|
type: AuthenticationComponentType.EntityStorage,
|
|
174
203
|
options: {
|
|
175
204
|
config: {
|
|
176
|
-
signingKeyName: envVars.authSigningKeyId
|
|
205
|
+
signingKeyName: envVars.authSigningKeyId
|
|
177
206
|
}
|
|
178
207
|
}
|
|
179
208
|
});
|
|
@@ -181,7 +210,7 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
181
210
|
type: RestRouteProcessorType.AuthHeader,
|
|
182
211
|
options: {
|
|
183
212
|
config: {
|
|
184
|
-
signingKeyName: envVars.authSigningKeyId
|
|
213
|
+
signingKeyName: envVars.authSigningKeyId
|
|
185
214
|
}
|
|
186
215
|
}
|
|
187
216
|
});
|
|
@@ -189,21 +218,39 @@ export async function buildEngineServerConfiguration(envVars, availableContextId
|
|
|
189
218
|
type: SocketRouteProcessorType.AuthHeader,
|
|
190
219
|
options: {
|
|
191
220
|
config: {
|
|
192
|
-
signingKeyName: envVars.authSigningKeyId
|
|
221
|
+
signingKeyName: envVars.authSigningKeyId
|
|
193
222
|
}
|
|
194
223
|
}
|
|
195
224
|
});
|
|
196
225
|
}
|
|
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
226
|
addDefaultRestPaths(serverConfig);
|
|
206
227
|
addDefaultSocketPaths(serverConfig);
|
|
228
|
+
// See if any of the rest paths should be overridden by environment variables and update the config accordingly
|
|
229
|
+
for (const componentType in serverConfig.types) {
|
|
230
|
+
const types = serverConfig.types[componentType];
|
|
231
|
+
if (Is.arrayValue(types)) {
|
|
232
|
+
for (const typeConfig of types) {
|
|
233
|
+
if (Is.stringValue(typeConfig.restPath)) {
|
|
234
|
+
const envVarName = `restPath${StringHelper.pascalCase(componentType.replace("Component", ""))}`;
|
|
235
|
+
const overrideRestPath = envVars[envVarName];
|
|
236
|
+
if (Is.stringValue(overrideRestPath)) {
|
|
237
|
+
typeConfig.restPath = overrideRestPath;
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
207
244
|
return serverConfig;
|
|
208
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Checks if the authentication entity storage subsystem is required.
|
|
248
|
+
* Returns true when any component that depends on the authentication entity storage subsystem is enabled.
|
|
249
|
+
* @param envVars The environment variables.
|
|
250
|
+
* @returns True if authentication entity storage is enabled.
|
|
251
|
+
*/
|
|
252
|
+
export function isAuthEntityStorageRequired(envVars) {
|
|
253
|
+
return (envVars.authAdminProcessorType === AuthenticationAdminComponentType.EntityStorage ||
|
|
254
|
+
envVars.authProcessorType === AuthenticationComponentType.EntityStorage);
|
|
255
|
+
}
|
|
209
256
|
//# 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,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3C,CAAC,CAAE,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAk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a;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,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,2BAA2B,EAC3B,+BAA+B,EAE/B,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,sBAA4E,EAC5E,gBAAmC,EACnC,UAAuB,EACvB,eAAwB,EACxB,WAAoB;IAEpB,MAAM,gBAAgB,GAAsB;QAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAA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;;;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, Is, StringHelper } 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\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\tpublicOrigin: Coerce.string(envVars.publicOrigin)\n\t};\n\n\tconst tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;\n\tconst apiKeyHeader = envVars.authApiKeyHeader ?? \"x-api-key\";\n\tif (tenantEnabled) {\n\t\twebServerOptions.allowedHeaders ??= [];\n\t\tif (!webServerOptions.allowedHeaders.includes(apiKeyHeader)) {\n\t\t\twebServerOptions.allowedHeaders.push(apiKeyHeader);\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\tavailableContextIdKeys.push({\n\t\tkey: ContextIdKeys.Node,\n\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t});\n\n\tserverConfig.types.restRouteProcessor.push({\n\t\ttype: RestRouteProcessorType.ContextId,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t}\n\t\t}\n\t});\n\tserverConfig.types.socketRouteProcessor.push({\n\t\ttype: SocketRouteProcessorType.ContextId,\n\t\toptions: {\n\t\t\tconfig: {\n\t\t\t\tkey: ContextIdKeys.Node\n\t\t\t}\n\t\t}\n\t});\n\n\tif (tenantEnabled) {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\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\t\tapiKeyName: apiKeyHeader\n\t\t\t\t}\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\t\tapiKeyName: apiKeyHeader\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t} else {\n\t\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.Organization,\n\t\t\trequiredHandlerFeatures: [CONTEXT_ID_HANDLER_FEATURE_DID]\n\t\t});\n\n\t\tserverConfig.types.restRouteProcessor.push({\n\t\t\ttype: RestRouteProcessorType.SingleTenant\n\t\t});\n\t\tserverConfig.types.socketRouteProcessor.push({\n\t\t\ttype: SocketRouteProcessorType.SingleTenant\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\tavailableContextIdKeys.push({\n\t\t\tkey: ContextIdKeys.User,\n\t\t\trequiredHandlerFeatures: [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\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"]}
|
|
@@ -33,7 +33,7 @@ export async function extensionsConfiguration(envVars, nodeEngineConfig) {
|
|
|
33
33
|
* Handles the initialisation of the extensions when the engine has been constructed.
|
|
34
34
|
* @param envVars The environment variables for the node.
|
|
35
35
|
* @param engineCore The engine core instance.
|
|
36
|
-
* @returns
|
|
36
|
+
* @returns A promise that resolves when all extension engine initialisation methods have completed.
|
|
37
37
|
*/
|
|
38
38
|
export async function extensionsInitialiseEngine(envVars, engineCore) {
|
|
39
39
|
if (Is.stringValue(envVars.extensions)) {
|
|
@@ -61,7 +61,7 @@ export async function extensionsInitialiseEngine(envVars, engineCore) {
|
|
|
61
61
|
* @param envVars The environment variables for the node.
|
|
62
62
|
* @param engineCore The engine core instance.
|
|
63
63
|
* @param engineServer The engine server instance.
|
|
64
|
-
* @returns
|
|
64
|
+
* @returns A promise that resolves when all extension engine-server initialisation methods have completed.
|
|
65
65
|
*/
|
|
66
66
|
export async function extensionsInitialiseEngineServer(envVars, engineCore, engineServer) {
|
|
67
67
|
if (Is.stringValue(envVars.extensions)) {
|
|
@@ -84,7 +84,7 @@ export async function extensionsInitialiseEngineServer(envVars, engineCore, engi
|
|
|
84
84
|
* Handles the shutdown of the extensions.
|
|
85
85
|
* @param envVars The environment variables for the node.
|
|
86
86
|
* @param engineCore The engine core instance.
|
|
87
|
-
* @returns
|
|
87
|
+
* @returns A promise that resolves when all extension shutdown methods have completed.
|
|
88
88
|
*/
|
|
89
89
|
export async function shutdownExtensions(envVars, engineCore) {
|
|
90
90
|
if (Is.stringValue(envVars.extensions)) {
|
|
@@ -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,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD,MAAM,cAAc,GAA+C,EAAE,CA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AU,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 A promise that resolves when all extension engine initialisation methods have completed.\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 A promise that resolves when all extension engine-server initialisation methods have completed.\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 A promise that resolves when all extension shutdown methods have completed.\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,254 @@
|
|
|
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 { getCommandDefinitionRemoveTenantOrgAlias } from "./commands/removeTenantOrgAlias.js";
|
|
16
|
+
import { getCommandDefinitionSetNodeOrgId } from "./commands/setNodeOrgId.js";
|
|
17
|
+
import { getCommandDefinitionSetTenantOrgId } from "./commands/setTenantOrgId.js";
|
|
18
|
+
import { getCommandDefinitionTenantCreate } from "./commands/tenantCreate.js";
|
|
19
|
+
import { getCommandDefinitionTenantImport } from "./commands/tenantImport.js";
|
|
20
|
+
import { getCommandDefinitionTenantUpdate } from "./commands/tenantUpdate.js";
|
|
21
|
+
import { getCommandDefinitionUserCreate } from "./commands/userCreate.js";
|
|
22
|
+
import { getCommandDefinitionUserUpdate } from "./commands/userUpdate.js";
|
|
23
|
+
import { getCommandDefinitionVaultKeyCreate } from "./commands/vaultKeyCreate.js";
|
|
24
|
+
import { getCommandDefinitionVaultKeyImport } from "./commands/vaultKeyImport.js";
|
|
25
|
+
const commandDefinitions = {};
|
|
26
|
+
/**
|
|
27
|
+
* Parse command line arguments.
|
|
28
|
+
* @param args The command line arguments.
|
|
29
|
+
* @returns The parsed command line arguments.
|
|
30
|
+
*/
|
|
31
|
+
export function parseCommandLineArgs(args) {
|
|
32
|
+
let nodePath;
|
|
33
|
+
let scriptPath;
|
|
34
|
+
let options;
|
|
35
|
+
if (Is.arrayValue(args)) {
|
|
36
|
+
if (args.length > 0) {
|
|
37
|
+
nodePath = args[0];
|
|
38
|
+
}
|
|
39
|
+
if (args.length > 1) {
|
|
40
|
+
scriptPath = args[1];
|
|
41
|
+
}
|
|
42
|
+
if (args.length > 2) {
|
|
43
|
+
options = [];
|
|
44
|
+
for (let i = 2; i < args.length; i++) {
|
|
45
|
+
const arg = args[i];
|
|
46
|
+
const equalIndex = arg.indexOf("=");
|
|
47
|
+
if (equalIndex > 0) {
|
|
48
|
+
const key = arg.slice(0, equalIndex).trim();
|
|
49
|
+
const value = arg.slice(equalIndex + 1).trim();
|
|
50
|
+
if (key.startsWith("--")) {
|
|
51
|
+
options.push({ key: key.slice(2), value });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
options.push({ key: arg, value: "" });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
nodePath,
|
|
62
|
+
scriptPath,
|
|
63
|
+
options
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Construct the CLI command from the parsed arguments.
|
|
68
|
+
* @param processEnv The environment variables from the process.
|
|
69
|
+
* @param cliArgs The parsed CLI arguments.
|
|
70
|
+
* @returns The constructed CLI command.
|
|
71
|
+
* @throws GeneralError if the command is missing.
|
|
72
|
+
*/
|
|
73
|
+
export function constructCliCommand(processEnv, cliArgs) {
|
|
74
|
+
if (Is.arrayValue(cliArgs.options)) {
|
|
75
|
+
const command = cliArgs.options[0];
|
|
76
|
+
// If the first option is --help, we can display help for all commands
|
|
77
|
+
if (command.key === "--help") {
|
|
78
|
+
return {
|
|
79
|
+
definition: commandDefinitions.help,
|
|
80
|
+
params: {}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// In cases where no command but env-prefix is provided, we just return
|
|
84
|
+
if (command.key === "env-prefix") {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
if (!commandDefinitions[command.key]) {
|
|
88
|
+
throw new GeneralError("node", "cliCommandMissing", { command: command.key });
|
|
89
|
+
}
|
|
90
|
+
// We have a valid command, check for --help for that command
|
|
91
|
+
const hasHelp = cliArgs.options.find(option => option.key === "--help");
|
|
92
|
+
if (hasHelp) {
|
|
93
|
+
return {
|
|
94
|
+
definition: commandDefinitions.help,
|
|
95
|
+
params: {
|
|
96
|
+
command: command.key
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
processEnvOptions(processEnv, cliArgs.options);
|
|
101
|
+
const cliParams = {};
|
|
102
|
+
const allParamKeys = cliArgs.options
|
|
103
|
+
.map(option => option.key)
|
|
104
|
+
.filter(key => key !== command.key);
|
|
105
|
+
for (const commandDefParam of commandDefinitions[command.key].params) {
|
|
106
|
+
const foundParamIndex = cliArgs.options?.findIndex(option => option.key === commandDefParam.key) ?? -1;
|
|
107
|
+
const foundParam = foundParamIndex >= 0 ? cliArgs.options?.[foundParamIndex] : undefined;
|
|
108
|
+
let paramValue;
|
|
109
|
+
if (commandDefParam.type === "number") {
|
|
110
|
+
paramValue = Coerce.number(foundParam?.value ?? commandDefParam.defaultValue);
|
|
111
|
+
}
|
|
112
|
+
else if (commandDefParam.type === "boolean") {
|
|
113
|
+
paramValue = Coerce.boolean(foundParam?.value ?? commandDefParam.defaultValue);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
paramValue = Coerce.string(foundParam?.value ?? commandDefParam.defaultValue);
|
|
117
|
+
}
|
|
118
|
+
const required = commandDefParam.required ?? true;
|
|
119
|
+
if (Is.empty(paramValue) && required) {
|
|
120
|
+
throw new GeneralError("node", "cliCommandParamMissing", {
|
|
121
|
+
command: command.key,
|
|
122
|
+
param: commandDefParam.key
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (!Is.empty(paramValue)) {
|
|
126
|
+
cliParams[StringHelper.camelCase(commandDefParam.key)] = paramValue;
|
|
127
|
+
}
|
|
128
|
+
if (foundParamIndex >= 0) {
|
|
129
|
+
const paramIndex = allParamKeys.indexOf(commandDefParam.key);
|
|
130
|
+
if (paramIndex >= 0) {
|
|
131
|
+
allParamKeys.splice(paramIndex, 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (allParamKeys.length > 0) {
|
|
136
|
+
throw new GeneralError("node", "cliCommandParamExtra", {
|
|
137
|
+
command: command.key,
|
|
138
|
+
params: allParamKeys.join(", ")
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (commandDefinitions[command.key].params.find(param => param.key === "output-env-prefix")) {
|
|
142
|
+
cliParams.outputEnvPrefix = (Coerce.string(cliParams.outputEnvPrefix) ?? "").toUpperCase();
|
|
143
|
+
cliParams.outputEnvPrefix =
|
|
144
|
+
cliParams.outputEnvPrefix.length > 0 && !cliParams.outputEnvPrefix.endsWith("_")
|
|
145
|
+
? `${cliParams.outputEnvPrefix}_`
|
|
146
|
+
: cliParams.outputEnvPrefix;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
definition: commandDefinitions[command.key],
|
|
150
|
+
params: cliParams
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Execute the CLI command.
|
|
156
|
+
* @param engineCore The engine core.
|
|
157
|
+
* @param envVars The environment variables for the node.
|
|
158
|
+
* @param cliCommand The CLI command to execute.
|
|
159
|
+
*/
|
|
160
|
+
export async function executeCommand(engineCore, envVars, cliCommand) {
|
|
161
|
+
const requiresEngineStarted = cliCommand.definition.requiresEngineStarted ?? true;
|
|
162
|
+
try {
|
|
163
|
+
if (requiresEngineStarted) {
|
|
164
|
+
await engineCore.start(true);
|
|
165
|
+
}
|
|
166
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.command"), cliCommand.definition.command);
|
|
167
|
+
for (const paramKey in cliCommand.params) {
|
|
168
|
+
CLIDisplay.value(paramKey, Coerce.string(cliCommand.params[paramKey]), 1);
|
|
169
|
+
}
|
|
170
|
+
CLIDisplay.break();
|
|
171
|
+
await ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {
|
|
172
|
+
await cliCommand.definition.action(engineCore, envVars, cliCommand.params);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
CLIDisplay.spinnerStop();
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
if (requiresEngineStarted) {
|
|
181
|
+
CLIDisplay.break();
|
|
182
|
+
await engineCore.stop();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Load the env files and process the options.
|
|
188
|
+
* @param processEnv The environment variables from the process.
|
|
189
|
+
* @param options The options.
|
|
190
|
+
* @returns The substituted options, mutated in place with env variable values resolved.
|
|
191
|
+
* @throws GeneralError if an env file has errors.
|
|
192
|
+
*/
|
|
193
|
+
export function processEnvOptions(processEnv, options) {
|
|
194
|
+
const inputEnv = options.find(option => option.key === "load-env")?.value;
|
|
195
|
+
if (Is.stringValue(inputEnv)) {
|
|
196
|
+
const envFiles = inputEnv.split(",").map(f => f.trim());
|
|
197
|
+
for (const envFile of envFiles) {
|
|
198
|
+
const output = dotenv.config({
|
|
199
|
+
path: envFile,
|
|
200
|
+
quiet: true
|
|
201
|
+
});
|
|
202
|
+
if (output.error) {
|
|
203
|
+
throw output.error;
|
|
204
|
+
}
|
|
205
|
+
if (Is.objectValue(output.parsed)) {
|
|
206
|
+
for (const key in output.parsed) {
|
|
207
|
+
processEnv[key] = output.parsed[key];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return substituteEnvOptions(processEnv, options);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Process options and replace any env variables with their values.
|
|
216
|
+
* @param processEnv The environment variables from the process.
|
|
217
|
+
* @param options The options.
|
|
218
|
+
* @throws GeneralError if an env variable is missing.
|
|
219
|
+
*/
|
|
220
|
+
export function substituteEnvOptions(processEnv, options) {
|
|
221
|
+
for (const option of options) {
|
|
222
|
+
if (option.value.startsWith("!")) {
|
|
223
|
+
const envVar = processEnv[option.value.slice(1)];
|
|
224
|
+
if (!Is.stringValue(envVar)) {
|
|
225
|
+
throw new GeneralError("node", "cliEnvVarMissing", { envVar: option.value.slice(1) });
|
|
226
|
+
}
|
|
227
|
+
option.value = envVar;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Register all built-in CLI command definitions into the shared command map.
|
|
233
|
+
*/
|
|
234
|
+
export function registerCommands() {
|
|
235
|
+
getCommandDefinitionHelp(commandDefinitions);
|
|
236
|
+
getCommandDefinitionBootstrapLegacy(commandDefinitions);
|
|
237
|
+
getCommandDefinitionIdentityCreate(commandDefinitions);
|
|
238
|
+
getCommandDefinitionIdentityImport(commandDefinitions);
|
|
239
|
+
getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions);
|
|
240
|
+
getCommandDefinitionIdentityVerificationMethodImport(commandDefinitions);
|
|
241
|
+
getCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions);
|
|
242
|
+
getCommandDefinitionNodeSetIdentity(commandDefinitions);
|
|
243
|
+
getCommandDefinitionSetNodeOrgId(commandDefinitions);
|
|
244
|
+
getCommandDefinitionSetTenantOrgId(commandDefinitions);
|
|
245
|
+
getCommandDefinitionRemoveTenantOrgAlias(commandDefinitions);
|
|
246
|
+
getCommandDefinitionTenantCreate(commandDefinitions);
|
|
247
|
+
getCommandDefinitionTenantImport(commandDefinitions);
|
|
248
|
+
getCommandDefinitionTenantUpdate(commandDefinitions);
|
|
249
|
+
getCommandDefinitionUserCreate(commandDefinitions);
|
|
250
|
+
getCommandDefinitionUserUpdate(commandDefinitions);
|
|
251
|
+
getCommandDefinitionVaultKeyCreate(commandDefinitions);
|
|
252
|
+
getCommandDefinitionVaultKeyImport(commandDefinitions);
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=cli.js.map
|