@twin.org/node-core 0.0.2-next.9 → 0.0.3-next.2
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 +1 -1
- package/dist/es/bootstrap.js +374 -0
- package/dist/es/bootstrap.js.map +1 -0
- package/dist/es/builders/engineEnvBuilder.js +1051 -0
- package/dist/es/builders/engineEnvBuilder.js.map +1 -0
- package/dist/es/builders/engineServerEnvBuilder.js +197 -0
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -0
- package/dist/es/builders/extensionsBuilder.js +109 -0
- package/dist/es/builders/extensionsBuilder.js.map +1 -0
- package/dist/es/defaults.js +9 -0
- package/dist/es/defaults.js.map +1 -0
- package/dist/es/identity.js +169 -0
- package/dist/es/identity.js.map +1 -0
- package/dist/es/index.js +23 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/ICacheMetadata.js +4 -0
- package/dist/es/models/ICacheMetadata.js.map +1 -0
- package/dist/es/models/IEngineEnvironmentVariables.js +4 -0
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -0
- package/dist/es/models/IEngineServerEnvironmentVariables.js +2 -0
- package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -0
- package/dist/es/models/IModuleProtocol.js +2 -0
- package/dist/es/models/IModuleProtocol.js.map +1 -0
- package/dist/es/models/INodeEngineConfig.js +2 -0
- package/dist/es/models/INodeEngineConfig.js.map +1 -0
- package/dist/es/models/INodeEngineState.js +2 -0
- package/dist/es/models/INodeEngineState.js.map +1 -0
- package/dist/es/models/INodeEnvironmentVariables.js +2 -0
- package/dist/es/models/INodeEnvironmentVariables.js.map +1 -0
- package/dist/es/models/INodeOptions.js +2 -0
- package/dist/es/models/INodeOptions.js.map +1 -0
- package/dist/es/models/IProtocolHandlerResult.js +4 -0
- package/dist/es/models/IProtocolHandlerResult.js.map +1 -0
- package/dist/es/models/moduleProtocol.js +29 -0
- package/dist/es/models/moduleProtocol.js.map +1 -0
- package/dist/es/models/nodeExtensionMethods.js +2 -0
- package/dist/es/models/nodeExtensionMethods.js.map +1 -0
- package/dist/es/models/nodeFeatures.js +21 -0
- package/dist/es/models/nodeFeatures.js.map +1 -0
- package/dist/es/node.js +265 -0
- package/dist/es/node.js.map +1 -0
- package/dist/es/server.js +78 -0
- package/dist/es/server.js.map +1 -0
- package/dist/es/utils.js +418 -0
- package/dist/es/utils.js.map +1 -0
- package/dist/types/bootstrap.d.ts +27 -10
- package/dist/types/builders/engineEnvBuilder.d.ts +3 -2
- package/dist/types/builders/engineServerEnvBuilder.d.ts +4 -3
- package/dist/types/builders/extensionsBuilder.d.ts +32 -0
- package/dist/types/defaults.d.ts +6 -0
- package/dist/types/identity.d.ts +14 -0
- package/dist/types/index.d.ts +20 -11
- package/dist/types/models/ICacheMetadata.d.ts +17 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +132 -24
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +12 -3
- package/dist/types/models/IModuleProtocol.d.ts +18 -0
- package/dist/types/models/INodeEngineConfig.d.ts +6 -0
- package/dist/types/models/INodeEngineState.d.ts +22 -0
- package/dist/types/models/INodeEnvironmentVariables.d.ts +50 -10
- package/dist/types/models/INodeOptions.d.ts +14 -3
- package/dist/types/models/IProtocolHandlerResult.d.ts +13 -0
- package/dist/types/models/moduleProtocol.d.ts +29 -0
- package/dist/types/models/nodeExtensionMethods.d.ts +27 -0
- package/dist/types/models/nodeFeatures.d.ts +5 -5
- package/dist/types/node.d.ts +17 -7
- package/dist/types/server.d.ts +9 -6
- package/dist/types/utils.d.ts +87 -2
- package/docs/changelog.md +185 -0
- package/docs/detailed-guide.md +129 -0
- package/docs/reference/functions/bootstrap.md +1 -1
- package/docs/reference/functions/bootstrapAuth.md +1 -1
- package/docs/reference/functions/bootstrapBlobEncryption.md +1 -1
- package/docs/reference/functions/bootstrapContextIdHandlers.md +35 -0
- package/docs/reference/functions/bootstrapImmutableProofMethod.md +1 -1
- package/docs/reference/functions/{bootstrapNodeUser.md → bootstrapNodeAdminUser.md} +3 -3
- package/docs/reference/functions/{bootstrapNodeIdentity.md → bootstrapNodeId.md} +3 -3
- package/docs/reference/functions/bootstrapSynchronisedStorage.md +1 -1
- package/docs/reference/functions/bootstrapTenantId.md +35 -0
- package/docs/reference/functions/buildConfiguration.md +2 -2
- package/docs/reference/functions/buildEngineConfiguration.md +8 -2
- package/docs/reference/functions/buildEngineServerConfiguration.md +9 -3
- package/docs/reference/functions/createModuleImportUrl.md +21 -0
- package/docs/reference/functions/directoryExists.md +19 -0
- package/docs/reference/functions/extensionsConfiguration.md +25 -0
- package/docs/reference/functions/extensionsInitialiseEngine.md +25 -0
- package/docs/reference/functions/extensionsInitialiseEngineServer.md +31 -0
- package/docs/reference/functions/getExtensionsCacheDir.md +31 -0
- package/docs/reference/functions/getFiles.md +19 -0
- package/docs/reference/functions/getSubFolders.md +19 -0
- package/docs/reference/functions/handleHttpsProtocol.md +49 -0
- package/docs/reference/functions/handleNpmProtocol.md +31 -0
- package/docs/reference/functions/hashUrl.md +19 -0
- package/docs/reference/functions/isCacheExpired.md +31 -0
- package/docs/reference/functions/overrideModuleImport.md +8 -2
- package/docs/reference/functions/parseModuleProtocol.md +19 -0
- package/docs/reference/functions/resolvePackageEntryPoint.md +32 -0
- package/docs/reference/functions/run.md +3 -3
- package/docs/reference/functions/shutdownExtensions.md +25 -0
- package/docs/reference/functions/start.md +11 -5
- package/docs/reference/index.md +36 -2
- package/docs/reference/interfaces/ICacheMetadata.md +27 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +255 -37
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +1696 -5
- package/docs/reference/interfaces/IModuleProtocol.md +27 -0
- package/docs/reference/interfaces/INodeEngineConfig.md +7 -0
- package/docs/reference/interfaces/INodeEngineState.md +39 -0
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +609 -165
- package/docs/reference/interfaces/INodeOptions.md +27 -3
- package/docs/reference/interfaces/IProtocolHandlerResult.md +19 -0
- package/docs/reference/type-aliases/ModuleProtocol.md +5 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +18 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +24 -0
- package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +23 -0
- package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +10 -0
- package/docs/reference/variables/ATTESTATION_VERIFICATION_METHOD_ID.md +3 -0
- package/docs/reference/variables/AUTH_SIGNING_KEY_ID.md +3 -0
- package/docs/reference/variables/BLOB_STORAGE_ENCRYPTION_KEY_ID.md +3 -0
- package/docs/reference/variables/IMMUTABLE_PROOF_VERIFICATION_METHOD_ID.md +3 -0
- package/docs/reference/variables/ModuleProtocol.md +37 -0
- package/docs/reference/variables/NodeFeatures.md +7 -7
- package/docs/reference/variables/SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID.md +3 -0
- package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +3 -0
- package/locales/en.json +27 -9
- package/package.json +27 -9
- package/dist/cjs/index.cjs +0 -1910
- package/dist/esm/index.mjs +0 -1870
package/dist/cjs/index.cjs
DELETED
|
@@ -1,1910 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var apiAuthEntityStorageService = require('@twin.org/api-auth-entity-storage-service');
|
|
4
|
-
var core = require('@twin.org/core');
|
|
5
|
-
var crypto = require('@twin.org/crypto');
|
|
6
|
-
var engineServerTypes = require('@twin.org/engine-server-types');
|
|
7
|
-
var engineTypes = require('@twin.org/engine-types');
|
|
8
|
-
var entityStorageModels = require('@twin.org/entity-storage-models');
|
|
9
|
-
var identityModels = require('@twin.org/identity-models');
|
|
10
|
-
var vaultModels = require('@twin.org/vault-models');
|
|
11
|
-
var walletModels = require('@twin.org/wallet-models');
|
|
12
|
-
var promises = require('node:fs/promises');
|
|
13
|
-
var path = require('node:path');
|
|
14
|
-
var engineServer = require('@twin.org/engine-server');
|
|
15
|
-
var modules = require('@twin.org/modules');
|
|
16
|
-
var dotenv = require('dotenv');
|
|
17
|
-
var engine = require('@twin.org/engine');
|
|
18
|
-
var engineCore = require('@twin.org/engine-core');
|
|
19
|
-
var engineModels = require('@twin.org/engine-models');
|
|
20
|
-
|
|
21
|
-
function _interopNamespaceDefault(e) {
|
|
22
|
-
var n = Object.create(null);
|
|
23
|
-
if (e) {
|
|
24
|
-
Object.keys(e).forEach(function (k) {
|
|
25
|
-
if (k !== 'default') {
|
|
26
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function () { return e[k]; }
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
n.default = e;
|
|
35
|
-
return Object.freeze(n);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var dotenv__namespace = /*#__PURE__*/_interopNamespaceDefault(dotenv);
|
|
39
|
-
|
|
40
|
-
// Copyright 2024 IOTA Stiftung.
|
|
41
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
42
|
-
/**
|
|
43
|
-
* The features that can be enabled on the node.
|
|
44
|
-
*/
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
46
|
-
const NodeFeatures = {
|
|
47
|
-
/**
|
|
48
|
-
* NodeIdentity - generates an identity for the node if not provided in config.
|
|
49
|
-
*/
|
|
50
|
-
NodeIdentity: "node-identity",
|
|
51
|
-
/**
|
|
52
|
-
* NodeUser - generates a user for the node if not provided in config.
|
|
53
|
-
*/
|
|
54
|
-
NodeUser: "node-user",
|
|
55
|
-
/**
|
|
56
|
-
* NodeWallet - generates a wallet for the node and funds it when there is a faucet available.
|
|
57
|
-
*/
|
|
58
|
-
NodeWallet: "node-wallet"
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Copyright 2024 IOTA Stiftung.
|
|
62
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
63
|
-
/* eslint-disable no-console */
|
|
64
|
-
/**
|
|
65
|
-
* Initialise the locales for the application.
|
|
66
|
-
* @param localesDirectory The directory containing the locales.
|
|
67
|
-
*/
|
|
68
|
-
async function initialiseLocales(localesDirectory) {
|
|
69
|
-
const localesFile = path.resolve(path.join(localesDirectory, "en.json"));
|
|
70
|
-
console.info("Locales File:", localesFile);
|
|
71
|
-
if (await fileExists(localesFile)) {
|
|
72
|
-
const enLangContent = await promises.readFile(localesFile, "utf8");
|
|
73
|
-
core.I18n.addDictionary("en", JSON.parse(enLangContent));
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
console.warn(`Locales file not found: ${localesFile}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get the directory where the application is being executed.
|
|
81
|
-
* @returns The execution directory.
|
|
82
|
-
*/
|
|
83
|
-
function getExecutionDirectory() {
|
|
84
|
-
return process.cwd();
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Does the specified file exist.
|
|
88
|
-
* @param filename The filename to check for existence.
|
|
89
|
-
* @returns True if the file exists.
|
|
90
|
-
*/
|
|
91
|
-
async function fileExists(filename) {
|
|
92
|
-
try {
|
|
93
|
-
const stats = await promises.stat(filename);
|
|
94
|
-
return stats.isFile();
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Load the text file.
|
|
102
|
-
* @param filename The filename of the text file to load.
|
|
103
|
-
* @returns The contents of the text file if it could not be loaded.
|
|
104
|
-
*/
|
|
105
|
-
async function loadTextFile(filename) {
|
|
106
|
-
return promises.readFile(filename, "utf8");
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Load the JSON file.
|
|
110
|
-
* @param filename The filename of the JSON file to load.
|
|
111
|
-
* @returns The contents of the JSON file or null if it could not be loaded.
|
|
112
|
-
*/
|
|
113
|
-
async function loadJsonFile(filename) {
|
|
114
|
-
const content = await loadTextFile(filename);
|
|
115
|
-
return JSON.parse(content);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Get the features that are enabled on the node.
|
|
119
|
-
* @param env The environment variables for the node.
|
|
120
|
-
* @returns The features that are enabled on the node.
|
|
121
|
-
*/
|
|
122
|
-
function getFeatures(env) {
|
|
123
|
-
if (core.Is.empty(env.features)) {
|
|
124
|
-
return [];
|
|
125
|
-
}
|
|
126
|
-
const features = [];
|
|
127
|
-
const allFeatures = Object.values(NodeFeatures);
|
|
128
|
-
const splitFeatures = env.features.split(",");
|
|
129
|
-
for (const feature of splitFeatures) {
|
|
130
|
-
const featureTrimmed = feature.trim();
|
|
131
|
-
if (allFeatures.includes(featureTrimmed)) {
|
|
132
|
-
features.push(featureTrimmed);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return features;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Copyright 2024 IOTA Stiftung.
|
|
139
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
140
|
-
const DEFAULT_NODE_USERNAME = "admin@node";
|
|
141
|
-
/**
|
|
142
|
-
* Bootstrap the application.
|
|
143
|
-
* @param engineCore The engine core for the node.
|
|
144
|
-
* @param context The context for the node.
|
|
145
|
-
* @param envVars The environment variables for the node.
|
|
146
|
-
*/
|
|
147
|
-
async function bootstrap(engineCore, context, envVars) {
|
|
148
|
-
const features = getFeatures(envVars);
|
|
149
|
-
await bootstrapNodeIdentity(engineCore, context, envVars, features);
|
|
150
|
-
await bootstrapNodeUser(engineCore, context, envVars, features);
|
|
151
|
-
await bootstrapAuth(engineCore, context, envVars);
|
|
152
|
-
await bootstrapBlobEncryption(engineCore, context, envVars);
|
|
153
|
-
await addVerificationMethod(engineCore, context, "attestation", envVars.attestationVerificationMethodId);
|
|
154
|
-
await addVerificationMethod(engineCore, context, "immutable proof", envVars.immutableProofVerificationMethodId);
|
|
155
|
-
await bootstrapSynchronisedStorage(engineCore, context, envVars);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Bootstrap the node creating any necessary resources.
|
|
159
|
-
* @param engineCore The engine core for the node.
|
|
160
|
-
* @param context The context for the node.
|
|
161
|
-
* @param envVars The environment variables for the node.
|
|
162
|
-
* @param features The features that are enabled on the node. The features that are enabled on the node.
|
|
163
|
-
*/
|
|
164
|
-
async function bootstrapNodeIdentity(engineCore, context, envVars, features) {
|
|
165
|
-
if (features.includes(NodeFeatures.NodeIdentity)) {
|
|
166
|
-
// When we bootstrap the node we need to generate an identity for it,
|
|
167
|
-
// But we have a chicken and egg problem in that we can't create the identity
|
|
168
|
-
// to store the mnemonic in the vault without an identity. We use a temporary identity
|
|
169
|
-
// and then replace it with the new identity later in the process.
|
|
170
|
-
const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
|
|
171
|
-
const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
|
|
172
|
-
const workingIdentity = envVars.identity ??
|
|
173
|
-
context.state.nodeIdentity ??
|
|
174
|
-
`bootstrap-temp-${core.Converter.bytesToHex(core.RandomHelper.generate(16))}`;
|
|
175
|
-
await bootstrapMnemonic(engineCore, envVars, features, vaultConnector, workingIdentity);
|
|
176
|
-
const addresses = await bootstrapWallet(engineCore, envVars, features, workingIdentity);
|
|
177
|
-
const finalIdentity = await bootstrapIdentity(engineCore, envVars, features, workingIdentity);
|
|
178
|
-
await finaliseWallet(engineCore, envVars, features, finalIdentity, addresses);
|
|
179
|
-
await finaliseMnemonic(vaultConnector, workingIdentity, finalIdentity);
|
|
180
|
-
context.state.nodeIdentity = finalIdentity;
|
|
181
|
-
context.stateDirty = true;
|
|
182
|
-
engineCore.logInfo(core.I18n.formatMessage("node.nodeIdentity", {
|
|
183
|
-
identity: context.state.nodeIdentity
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Bootstrap the identity for the node.
|
|
189
|
-
* @param engineCore The engine core for the node.
|
|
190
|
-
* @param envVars The environment variables for the node.
|
|
191
|
-
* @param features The features that are enabled on the node. The features that are enabled on the node.
|
|
192
|
-
* @param nodeIdentity The identity of the node.
|
|
193
|
-
* @returns The addresses for the wallet.
|
|
194
|
-
*/
|
|
195
|
-
async function bootstrapIdentity(engineCore, envVars, features, nodeIdentity) {
|
|
196
|
-
const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
|
|
197
|
-
// Now create an identity for the node controlled by the address we just funded
|
|
198
|
-
const identityConnector = identityModels.IdentityConnectorFactory.get(defaultIdentityConnectorType);
|
|
199
|
-
let identityDocument;
|
|
200
|
-
try {
|
|
201
|
-
const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
|
|
202
|
-
const identityResolverConnector = identityModels.IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
|
|
203
|
-
identityDocument = await identityResolverConnector.resolveDocument(nodeIdentity);
|
|
204
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingNodeIdentity", { identity: nodeIdentity }));
|
|
205
|
-
}
|
|
206
|
-
catch { }
|
|
207
|
-
if (core.Is.empty(identityDocument)) {
|
|
208
|
-
engineCore.logInfo(core.I18n.formatMessage("node.generatingNodeIdentity"));
|
|
209
|
-
identityDocument = await identityConnector.createDocument(nodeIdentity);
|
|
210
|
-
engineCore.logInfo(core.I18n.formatMessage("node.createdNodeIdentity", { identity: identityDocument.id }));
|
|
211
|
-
}
|
|
212
|
-
if (defaultIdentityConnectorType.startsWith(engineTypes.IdentityConnectorType.Iota)) {
|
|
213
|
-
const didUrn = core.Urn.fromValidString(identityDocument.id);
|
|
214
|
-
const didParts = didUrn.parts();
|
|
215
|
-
const objectId = didParts[3];
|
|
216
|
-
engineCore.logInfo(core.I18n.formatMessage("node.identityExplorer", {
|
|
217
|
-
url: `${envVars.iotaExplorerEndpoint}object/${objectId}?network=${envVars.iotaNetwork}`
|
|
218
|
-
}));
|
|
219
|
-
}
|
|
220
|
-
return identityDocument.id;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Bootstrap the wallet for the node.
|
|
224
|
-
* @param engineCore The engine core for the node.
|
|
225
|
-
* @param envVars The environment variables for the node.
|
|
226
|
-
* @param features The features that are enabled on the node.
|
|
227
|
-
* @param nodeIdentity The identity of the node.
|
|
228
|
-
* @returns The addresses for the wallet.
|
|
229
|
-
*/
|
|
230
|
-
async function bootstrapWallet(engineCore, envVars, features, nodeIdentity) {
|
|
231
|
-
if (features.includes(NodeFeatures.NodeWallet)) {
|
|
232
|
-
const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
|
|
233
|
-
const walletConnector = walletModels.WalletConnectorFactory.get(defaultWalletConnectorType);
|
|
234
|
-
const addresses = await walletConnector.getAddresses(nodeIdentity, 0, 0, 5);
|
|
235
|
-
const balance = await walletConnector.getBalance(nodeIdentity, addresses[0]);
|
|
236
|
-
if (balance === 0n) {
|
|
237
|
-
let address0 = addresses[0];
|
|
238
|
-
if (defaultWalletConnectorType.startsWith(engineTypes.WalletConnectorType.Iota)) {
|
|
239
|
-
address0 = `${envVars.iotaExplorerEndpoint}address/${address0}?network=${envVars.iotaNetwork}`;
|
|
240
|
-
}
|
|
241
|
-
engineCore.logInfo(core.I18n.formatMessage("node.fundingWallet", { address: address0 }));
|
|
242
|
-
// Add some funds to the wallet from the faucet
|
|
243
|
-
await walletConnector.ensureBalance(nodeIdentity, addresses[0], 1000000000n);
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
engineCore.logInfo(core.I18n.formatMessage("node.fundedWallet"));
|
|
247
|
-
}
|
|
248
|
-
return addresses;
|
|
249
|
-
}
|
|
250
|
-
return [];
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Bootstrap the identity for the node.
|
|
254
|
-
* @param engineCore The engine core for the node.
|
|
255
|
-
* @param envVars The environment variables for the node.
|
|
256
|
-
* @param features The features that are enabled on the node.
|
|
257
|
-
* @param finalIdentity The identity of the node.
|
|
258
|
-
* @param addresses The addresses for the wallet.
|
|
259
|
-
*/
|
|
260
|
-
async function finaliseWallet(engineCore, envVars, features, finalIdentity, addresses) {
|
|
261
|
-
if (features.includes(NodeFeatures.NodeWallet)) {
|
|
262
|
-
const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
|
|
263
|
-
// If we are using entity storage for wallet the identity associated with the
|
|
264
|
-
// address will be wrong, so fix it
|
|
265
|
-
if (defaultWalletConnectorType.startsWith(engineTypes.WalletConnectorType.EntityStorage)) {
|
|
266
|
-
const walletAddress = entityStorageModels.EntityStorageConnectorFactory.get(core.StringHelper.kebabCase("WalletAddress"));
|
|
267
|
-
const addr = await walletAddress.get(addresses[0]);
|
|
268
|
-
if (!core.Is.empty(addr)) {
|
|
269
|
-
addr.identity = finalIdentity;
|
|
270
|
-
await walletAddress.set(addr);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Generate a mnemonic for the node identity.
|
|
277
|
-
* @param engineCore The engine core for the node.
|
|
278
|
-
* @param envVars The environment variables for the node.
|
|
279
|
-
* @param features The features that are enabled on the node.
|
|
280
|
-
* @param vaultConnector The vault connector to use.
|
|
281
|
-
* @param nodeIdentity The identity of the node.
|
|
282
|
-
*/
|
|
283
|
-
async function bootstrapMnemonic(engineCore, envVars, features, vaultConnector, nodeIdentity) {
|
|
284
|
-
let mnemonic = envVars.mnemonic;
|
|
285
|
-
let storeMnemonic = false;
|
|
286
|
-
try {
|
|
287
|
-
const storedMnemonic = await vaultConnector.getSecret(`${nodeIdentity}/mnemonic`);
|
|
288
|
-
storeMnemonic = storedMnemonic !== mnemonic;
|
|
289
|
-
mnemonic = storedMnemonic;
|
|
290
|
-
}
|
|
291
|
-
catch {
|
|
292
|
-
storeMnemonic = true;
|
|
293
|
-
}
|
|
294
|
-
// If there is no mnemonic then we need to generate one
|
|
295
|
-
if (core.Is.empty(mnemonic)) {
|
|
296
|
-
mnemonic = crypto.Bip39.randomMnemonic();
|
|
297
|
-
storeMnemonic = true;
|
|
298
|
-
engineCore.logInfo(core.I18n.formatMessage("node.generatingMnemonic", { mnemonic }));
|
|
299
|
-
}
|
|
300
|
-
// If there is no mnemonic stored in the vault then we need to store it
|
|
301
|
-
if (storeMnemonic) {
|
|
302
|
-
engineCore.logInfo(core.I18n.formatMessage("node.storingMnemonic"));
|
|
303
|
-
await vaultConnector.setSecret(`${nodeIdentity}/mnemonic`, mnemonic);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingMnemonic"));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Finalise the mnemonic for the node identity.
|
|
311
|
-
* @param vaultConnector The vault connector to use.
|
|
312
|
-
* @param workingIdentity The identity of the node.
|
|
313
|
-
* @param finalIdentity The final identity for the node.
|
|
314
|
-
*/
|
|
315
|
-
async function finaliseMnemonic(vaultConnector, workingIdentity, finalIdentity) {
|
|
316
|
-
// Now that we have an identity we can remove the temporary one
|
|
317
|
-
// and store the mnemonic with the new identity
|
|
318
|
-
if (workingIdentity.startsWith("bootstrap-temp-") && workingIdentity !== finalIdentity) {
|
|
319
|
-
const mnemonic = await vaultConnector.getSecret(`${workingIdentity}/mnemonic`);
|
|
320
|
-
await vaultConnector.setSecret(`${finalIdentity}/mnemonic`, mnemonic);
|
|
321
|
-
await vaultConnector.removeSecret(`${workingIdentity}/mnemonic`);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Bootstrap the user.
|
|
326
|
-
* @param engineCore The engine core for the node.
|
|
327
|
-
* @param context The context for the node.
|
|
328
|
-
* @param envVars The environment variables for the node.
|
|
329
|
-
* @param features The features that are enabled on the node.
|
|
330
|
-
*/
|
|
331
|
-
async function bootstrapNodeUser(engineCore, context, envVars, features) {
|
|
332
|
-
if (features.includes(NodeFeatures.NodeUser)) {
|
|
333
|
-
const defaultAuthenticationComponentType = engineCore.getRegisteredInstanceType("authenticationComponent");
|
|
334
|
-
if (defaultAuthenticationComponentType.startsWith(engineServerTypes.AuthenticationComponentType.EntityStorage) &&
|
|
335
|
-
core.Is.stringValue(context.state.nodeIdentity)) {
|
|
336
|
-
const authUserEntityStorage = entityStorageModels.EntityStorageConnectorFactory.get(core.StringHelper.kebabCase("AuthenticationUser"));
|
|
337
|
-
const email = envVars.username ?? DEFAULT_NODE_USERNAME;
|
|
338
|
-
let nodeAdminUser = await authUserEntityStorage.get(email);
|
|
339
|
-
if (core.Is.empty(nodeAdminUser)) {
|
|
340
|
-
engineCore.logInfo(core.I18n.formatMessage("node.creatingNodeUser", { email }));
|
|
341
|
-
const generatedPassword = envVars.password ?? crypto.PasswordGenerator.generate(16);
|
|
342
|
-
const passwordBytes = core.Converter.utf8ToBytes(generatedPassword);
|
|
343
|
-
const saltBytes = core.RandomHelper.generate(16);
|
|
344
|
-
const hashedPassword = await apiAuthEntityStorageService.PasswordHelper.hashPassword(passwordBytes, saltBytes);
|
|
345
|
-
nodeAdminUser = {
|
|
346
|
-
email,
|
|
347
|
-
password: hashedPassword,
|
|
348
|
-
salt: core.Converter.bytesToBase64(saltBytes),
|
|
349
|
-
identity: context.state.nodeIdentity
|
|
350
|
-
};
|
|
351
|
-
engineCore.logInfo(core.I18n.formatMessage("node.nodeAdminUserEmail", { email: nodeAdminUser.email }));
|
|
352
|
-
engineCore.logInfo(core.I18n.formatMessage("node.nodeAdminUserPassword", { password: generatedPassword }));
|
|
353
|
-
await authUserEntityStorage.set(nodeAdminUser);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingNodeUser", { email }));
|
|
357
|
-
// The user already exists, so double check the other details match
|
|
358
|
-
let needsUpdate = false;
|
|
359
|
-
if (nodeAdminUser.identity !== context.state.nodeIdentity) {
|
|
360
|
-
nodeAdminUser.identity = context.state.nodeIdentity;
|
|
361
|
-
needsUpdate = true;
|
|
362
|
-
}
|
|
363
|
-
if (core.Is.stringValue(envVars.password)) {
|
|
364
|
-
const passwordBytes = core.Converter.utf8ToBytes(envVars.password);
|
|
365
|
-
const saltBytes = core.Converter.base64ToBytes(nodeAdminUser.salt);
|
|
366
|
-
const hashedPassword = await apiAuthEntityStorageService.PasswordHelper.hashPassword(passwordBytes, saltBytes);
|
|
367
|
-
if (nodeAdminUser.password !== hashedPassword) {
|
|
368
|
-
nodeAdminUser.password = hashedPassword;
|
|
369
|
-
needsUpdate = true;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (needsUpdate) {
|
|
373
|
-
await authUserEntityStorage.set(nodeAdminUser);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
// We have create a node user, now we need to create a profile for the user
|
|
377
|
-
const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
|
|
378
|
-
const identityProfileConnector = identityModels.IdentityProfileConnectorFactory.get(defaultIdentityConnectorType);
|
|
379
|
-
if (identityProfileConnector) {
|
|
380
|
-
let userProfile;
|
|
381
|
-
try {
|
|
382
|
-
userProfile = await identityProfileConnector.get(context.state.nodeIdentity);
|
|
383
|
-
}
|
|
384
|
-
catch { }
|
|
385
|
-
if (core.Is.empty(userProfile)) {
|
|
386
|
-
engineCore.logInfo(core.I18n.formatMessage("node.creatingUserProfile", { identity: context.state.nodeIdentity }));
|
|
387
|
-
const publicProfile = {
|
|
388
|
-
"@context": "https://schema.org",
|
|
389
|
-
"@type": "Person",
|
|
390
|
-
name: "Node Administrator"
|
|
391
|
-
};
|
|
392
|
-
const privateProfile = {
|
|
393
|
-
"@context": "https://schema.org",
|
|
394
|
-
"@type": "Person",
|
|
395
|
-
givenName: "Node",
|
|
396
|
-
familyName: "Administrator",
|
|
397
|
-
email
|
|
398
|
-
};
|
|
399
|
-
await identityProfileConnector.create(context.state.nodeIdentity, publicProfile, privateProfile);
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingUserProfile", { identity: context.state.nodeIdentity }));
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* Bootstrap the immutable proof verification methods.
|
|
410
|
-
* @param engineCore The engine core for the node.
|
|
411
|
-
* @param context The context for the node.
|
|
412
|
-
* @param envVars The environment variables for the node.
|
|
413
|
-
* @param features The features that are enabled on the node.
|
|
414
|
-
*/
|
|
415
|
-
async function bootstrapImmutableProofMethod(engineCore, context, envVars, features) { }
|
|
416
|
-
/**
|
|
417
|
-
* Bootstrap the keys for blob encryption.
|
|
418
|
-
* @param engineCore The engine core for the node.
|
|
419
|
-
* @param context The context for the node.
|
|
420
|
-
* @param envVars The environment variables for the node.
|
|
421
|
-
* @param features The features that are enabled on the node.
|
|
422
|
-
*/
|
|
423
|
-
async function bootstrapBlobEncryption(engineCore, context, envVars, features) {
|
|
424
|
-
if ((core.Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) &&
|
|
425
|
-
core.Is.stringValue(context.state.nodeIdentity)) {
|
|
426
|
-
// Create a new key for encrypting blobs
|
|
427
|
-
const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
|
|
428
|
-
const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
|
|
429
|
-
const keyName = `${context.state.nodeIdentity}/${envVars.blobStorageEncryptionKeyId}`;
|
|
430
|
-
let existingKey;
|
|
431
|
-
try {
|
|
432
|
-
existingKey = await vaultConnector.getKey(keyName);
|
|
433
|
-
}
|
|
434
|
-
catch { }
|
|
435
|
-
if (core.Is.empty(existingKey)) {
|
|
436
|
-
if (core.Is.stringBase64(envVars.blobStorageSymmetricEncryptionKey)) {
|
|
437
|
-
engineCore.logInfo(core.I18n.formatMessage("node.addingBlobEncryptionKey", { keyName }));
|
|
438
|
-
await vaultConnector.addKey(keyName, vaultModels.VaultKeyType.ChaCha20Poly1305, core.Converter.base64ToBytes(envVars.blobStorageSymmetricEncryptionKey));
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
engineCore.logInfo(core.I18n.formatMessage("node.creatingBlobEncryptionKey", { keyName }));
|
|
442
|
-
const key = await vaultConnector.createKey(keyName, vaultModels.VaultKeyType.ChaCha20Poly1305);
|
|
443
|
-
engineCore.logInfo(core.I18n.formatMessage("node.createdBlobEncryptionKey", {
|
|
444
|
-
keyName,
|
|
445
|
-
keyValue: core.Converter.bytesToBase64(key)
|
|
446
|
-
}));
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingBlobEncryptionKey", { keyName }));
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Bootstrap the JWT signing key.
|
|
456
|
-
* @param engineCore The engine core for the node.
|
|
457
|
-
* @param context The context for the node.
|
|
458
|
-
* @param envVars The environment variables for the node.
|
|
459
|
-
* @param features The features that are enabled on the node.
|
|
460
|
-
*/
|
|
461
|
-
async function bootstrapAuth(engineCore, context, envVars, features) {
|
|
462
|
-
const defaultAuthenticationComponentType = engineCore.getRegisteredInstanceTypeOptional("authenticationComponent");
|
|
463
|
-
if (core.Is.stringValue(defaultAuthenticationComponentType) &&
|
|
464
|
-
defaultAuthenticationComponentType.startsWith(engineServerTypes.AuthenticationComponentType.EntityStorage) &&
|
|
465
|
-
core.Is.stringValue(context.state.nodeIdentity)) {
|
|
466
|
-
// Create a new JWT signing key and a user login for the node
|
|
467
|
-
const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
|
|
468
|
-
const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
|
|
469
|
-
const keyName = `${context.state.nodeIdentity}/${envVars.authSigningKeyId}`;
|
|
470
|
-
let existingKey;
|
|
471
|
-
try {
|
|
472
|
-
existingKey = await vaultConnector.getKey(keyName);
|
|
473
|
-
}
|
|
474
|
-
catch { }
|
|
475
|
-
if (core.Is.empty(existingKey)) {
|
|
476
|
-
engineCore.logInfo(core.I18n.formatMessage("node.creatingAuthKey", { keyName }));
|
|
477
|
-
await vaultConnector.createKey(keyName, vaultModels.VaultKeyType.Ed25519);
|
|
478
|
-
}
|
|
479
|
-
else {
|
|
480
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingAuthKey", { keyName }));
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Bootstrap the synchronised storage blob encryption and verification methods.
|
|
486
|
-
* @param engineCore The engine core for the node.
|
|
487
|
-
* @param context The context for the node.
|
|
488
|
-
* @param envVars The environment variables for the node.
|
|
489
|
-
* @param features The features that are enabled on the node.
|
|
490
|
-
*/
|
|
491
|
-
async function bootstrapSynchronisedStorage(engineCore, context, envVars, features) {
|
|
492
|
-
if (core.Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) {
|
|
493
|
-
// Add the verification method to the identity if it doesn't exist
|
|
494
|
-
await addVerificationMethod(engineCore, context, "synchronised storage", envVars.synchronisedStorageVerificationMethodId);
|
|
495
|
-
// If this is a trusted node we need to add the blob encryption key pair
|
|
496
|
-
if (core.Is.stringValue(envVars.synchronisedStorageBlobStorageEncryptionKeyId) &&
|
|
497
|
-
core.Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {
|
|
498
|
-
const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
|
|
499
|
-
const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
|
|
500
|
-
const keyName = envVars.synchronisedStorageBlobStorageEncryptionKeyId;
|
|
501
|
-
let existingKey;
|
|
502
|
-
try {
|
|
503
|
-
existingKey = await vaultConnector.getKey(keyName);
|
|
504
|
-
}
|
|
505
|
-
catch { }
|
|
506
|
-
if (core.Is.empty(existingKey)) {
|
|
507
|
-
engineCore.logInfo(core.I18n.formatMessage("node.addingSynchronisedStorageBlobEncryptionKey", { keyName }));
|
|
508
|
-
await vaultConnector.addKey(keyName, vaultModels.VaultKeyType.ChaCha20Poly1305, core.Converter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey));
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingSynchronisedStorageBlobEncryptionKey", { keyName }));
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Add a verification method if it doesn't exist.
|
|
518
|
-
* @param engineCore The engine core for the node.
|
|
519
|
-
* @param context The context for the node.
|
|
520
|
-
* @param verificationMethodTitle The verification method title.
|
|
521
|
-
* @param verificationMethodId The verification method ID.
|
|
522
|
-
*/
|
|
523
|
-
async function addVerificationMethod(engineCore, context, verificationMethodTitle, verificationMethodId) {
|
|
524
|
-
if (core.Is.stringValue(context.state.nodeIdentity) &&
|
|
525
|
-
core.Is.arrayValue(context.config.types.identityConnector) &&
|
|
526
|
-
core.Is.stringValue(verificationMethodId)) {
|
|
527
|
-
const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
|
|
528
|
-
const identityConnector = identityModels.IdentityConnectorFactory.get(defaultIdentityConnectorType);
|
|
529
|
-
const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
|
|
530
|
-
const identityResolverConnector = identityModels.IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
|
|
531
|
-
const identityDocument = await identityResolverConnector.resolveDocument(context.state.nodeIdentity);
|
|
532
|
-
const fullMethodId = `${identityDocument.id}#${verificationMethodId}`;
|
|
533
|
-
let exists = false;
|
|
534
|
-
try {
|
|
535
|
-
identityModels.DocumentHelper.getVerificationMethod(identityDocument, fullMethodId, "assertionMethod");
|
|
536
|
-
exists = true;
|
|
537
|
-
}
|
|
538
|
-
catch { }
|
|
539
|
-
if (!exists) {
|
|
540
|
-
engineCore.logInfo(core.I18n.formatMessage("node.addingVerificationMethod", {
|
|
541
|
-
title: verificationMethodTitle,
|
|
542
|
-
methodId: fullMethodId
|
|
543
|
-
}));
|
|
544
|
-
await identityConnector.addVerificationMethod(context.state.nodeIdentity, context.state.nodeIdentity, "assertionMethod", verificationMethodId);
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
engineCore.logInfo(core.I18n.formatMessage("node.existingVerificationMethod", {
|
|
548
|
-
title: verificationMethodTitle,
|
|
549
|
-
methodId: fullMethodId
|
|
550
|
-
}));
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// Copyright 2024 IOTA Stiftung.
|
|
556
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
557
|
-
/**
|
|
558
|
-
* Build the engine core configuration from environment variables.
|
|
559
|
-
* @param envVars The environment variables.
|
|
560
|
-
* @returns The config for the core.
|
|
561
|
-
*/
|
|
562
|
-
function buildEngineConfiguration(envVars) {
|
|
563
|
-
if (core.Is.stringValue(envVars.storageFileRoot)) {
|
|
564
|
-
envVars.stateFilename ??= "engine-state.json";
|
|
565
|
-
envVars.storageFileRoot = path.resolve(envVars.storageFileRoot);
|
|
566
|
-
envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
|
|
567
|
-
}
|
|
568
|
-
envVars.attestationVerificationMethodId ??= "attestation-assertion";
|
|
569
|
-
envVars.immutableProofVerificationMethodId ??= "immutable-proof-assertion";
|
|
570
|
-
envVars.blobStorageEnableEncryption ??= "false";
|
|
571
|
-
envVars.blobStorageEncryptionKeyId ??= "blob-encryption";
|
|
572
|
-
envVars.synchronisedStorageBlobStorageEncryptionKeyId ??= "synchronised-storage-blob-encryption";
|
|
573
|
-
envVars.synchronisedStorageVerificationMethodId ??= "synchronised-storage-assertion";
|
|
574
|
-
const coreConfig = {
|
|
575
|
-
debug: core.Coerce.boolean(envVars.debug) ?? false,
|
|
576
|
-
types: {}
|
|
577
|
-
};
|
|
578
|
-
configureEntityStorage(coreConfig, envVars);
|
|
579
|
-
configureBlobStorage(coreConfig, envVars);
|
|
580
|
-
configureVault(coreConfig, envVars);
|
|
581
|
-
configureDlt(coreConfig, envVars);
|
|
582
|
-
configureLogging(coreConfig, envVars);
|
|
583
|
-
configureBackgroundTask(coreConfig, envVars);
|
|
584
|
-
configureEventBus(coreConfig, envVars);
|
|
585
|
-
configureTelemetry(coreConfig, envVars);
|
|
586
|
-
configureMessaging(coreConfig, envVars);
|
|
587
|
-
configureFaucet(coreConfig, envVars);
|
|
588
|
-
configureWallet(coreConfig, envVars);
|
|
589
|
-
configureNft(coreConfig, envVars);
|
|
590
|
-
configureVerifiableStorage(coreConfig, envVars);
|
|
591
|
-
configureIdentity(coreConfig, envVars);
|
|
592
|
-
configureIdentityResolver(coreConfig, envVars);
|
|
593
|
-
configureIdentityProfile(coreConfig, envVars);
|
|
594
|
-
configureAttestation(coreConfig, envVars);
|
|
595
|
-
configureDataProcessing(coreConfig, envVars);
|
|
596
|
-
configureAuditableItemGraph(coreConfig);
|
|
597
|
-
configureAuditableItemStream(coreConfig);
|
|
598
|
-
configureDocumentManagement(coreConfig);
|
|
599
|
-
configureRightsManagement(coreConfig, envVars);
|
|
600
|
-
configureTaskScheduler(coreConfig, envVars);
|
|
601
|
-
configureSynchronisedStorage(coreConfig, envVars);
|
|
602
|
-
configureFederatedCatalogue(coreConfig, envVars);
|
|
603
|
-
configureDataSpaceConnector(coreConfig, envVars);
|
|
604
|
-
return coreConfig;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Helper function to get IOTA configuration from centralized dltConfig.
|
|
608
|
-
* @param coreConfig The core config.
|
|
609
|
-
* @returns The IOTA configuration if found, undefined otherwise.
|
|
610
|
-
*/
|
|
611
|
-
function getIotaConfig(coreConfig) {
|
|
612
|
-
const dltConfig = coreConfig.types.dltConfig?.find(config => config.type === engineTypes.DltConfigType.Iota && config.isDefault);
|
|
613
|
-
return dltConfig?.options?.config;
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Configures the entity storage.
|
|
617
|
-
* @param coreConfig The core config.
|
|
618
|
-
* @param envVars The environment variables.
|
|
619
|
-
*/
|
|
620
|
-
function configureEntityStorage(coreConfig, envVars) {
|
|
621
|
-
coreConfig.types ??= {};
|
|
622
|
-
coreConfig.types.entityStorageConnector ??= [];
|
|
623
|
-
const entityStorageConnectorTypes = envVars.entityStorageConnectorType?.split(",") ?? [];
|
|
624
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.Memory)) {
|
|
625
|
-
coreConfig.types.entityStorageConnector.push({
|
|
626
|
-
type: engineTypes.EntityStorageConnectorType.Memory
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.File)) {
|
|
630
|
-
coreConfig.types.entityStorageConnector.push({
|
|
631
|
-
type: engineTypes.EntityStorageConnectorType.File,
|
|
632
|
-
options: {
|
|
633
|
-
config: { directory: envVars.storageFileRoot ?? "" },
|
|
634
|
-
folderPrefix: envVars.entityStorageTablePrefix
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.AwsDynamoDb)) {
|
|
639
|
-
coreConfig.types.entityStorageConnector.push({
|
|
640
|
-
type: engineTypes.EntityStorageConnectorType.AwsDynamoDb,
|
|
641
|
-
options: {
|
|
642
|
-
config: {
|
|
643
|
-
region: envVars.awsDynamodbRegion ?? "",
|
|
644
|
-
accessKeyId: envVars.awsDynamodbAccessKeyId ?? "",
|
|
645
|
-
secretAccessKey: envVars.awsDynamodbSecretAccessKey ?? "",
|
|
646
|
-
endpoint: envVars.awsDynamodbEndpoint ?? ""
|
|
647
|
-
},
|
|
648
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
649
|
-
}
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.AzureCosmosDb)) {
|
|
653
|
-
coreConfig.types.entityStorageConnector.push({
|
|
654
|
-
type: engineTypes.EntityStorageConnectorType.AzureCosmosDb,
|
|
655
|
-
options: {
|
|
656
|
-
config: {
|
|
657
|
-
endpoint: envVars.azureCosmosdbEndpoint ?? "",
|
|
658
|
-
key: envVars.azureCosmosdbKey ?? "",
|
|
659
|
-
databaseId: envVars.azureCosmosdbDatabaseId ?? "",
|
|
660
|
-
containerId: envVars.azureCosmosdbContainerId ?? ""
|
|
661
|
-
},
|
|
662
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.GcpFirestoreDb)) {
|
|
667
|
-
coreConfig.types.entityStorageConnector.push({
|
|
668
|
-
type: engineTypes.EntityStorageConnectorType.GcpFirestoreDb,
|
|
669
|
-
options: {
|
|
670
|
-
config: {
|
|
671
|
-
projectId: envVars.gcpFirestoreProjectId ?? "",
|
|
672
|
-
credentials: envVars.gcpFirestoreCredentials ?? "",
|
|
673
|
-
databaseId: envVars.gcpFirestoreDatabaseId ?? "",
|
|
674
|
-
collectionName: envVars.gcpFirestoreCollectionName ?? "",
|
|
675
|
-
endpoint: envVars.gcpFirestoreApiEndpoint ?? ""
|
|
676
|
-
},
|
|
677
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.ScyllaDb)) {
|
|
682
|
-
coreConfig.types.entityStorageConnector.push({
|
|
683
|
-
type: engineTypes.EntityStorageConnectorType.ScyllaDb,
|
|
684
|
-
options: {
|
|
685
|
-
config: {
|
|
686
|
-
hosts: envVars.scylladbHosts?.split(",") ?? [],
|
|
687
|
-
localDataCenter: envVars.scylladbLocalDataCenter ?? "",
|
|
688
|
-
keyspace: envVars.scylladbKeyspace ?? "",
|
|
689
|
-
port: core.Coerce.integer(envVars.scylladbPort)
|
|
690
|
-
},
|
|
691
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
}
|
|
695
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.MySqlDb)) {
|
|
696
|
-
coreConfig.types.entityStorageConnector.push({
|
|
697
|
-
type: engineTypes.EntityStorageConnectorType.MySqlDb,
|
|
698
|
-
options: {
|
|
699
|
-
config: {
|
|
700
|
-
host: envVars.mySqlHost ?? "",
|
|
701
|
-
port: core.Coerce.integer(envVars.mySqlPort),
|
|
702
|
-
user: envVars.mySqlUser ?? "",
|
|
703
|
-
password: envVars.mySqlPassword ?? "",
|
|
704
|
-
database: envVars.mySqlDatabase ?? ""
|
|
705
|
-
},
|
|
706
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.MongoDb)) {
|
|
711
|
-
coreConfig.types.entityStorageConnector.push({
|
|
712
|
-
type: engineTypes.EntityStorageConnectorType.MongoDb,
|
|
713
|
-
options: {
|
|
714
|
-
config: {
|
|
715
|
-
host: envVars.mongoDbHost ?? "",
|
|
716
|
-
port: core.Coerce.integer(envVars.mongoDbPort),
|
|
717
|
-
user: envVars.mongoDbUser ?? "",
|
|
718
|
-
password: envVars.mongoDbPassword ?? "",
|
|
719
|
-
database: envVars.mongoDbDatabase ?? ""
|
|
720
|
-
},
|
|
721
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.PostgreSql)) {
|
|
726
|
-
coreConfig.types.entityStorageConnector.push({
|
|
727
|
-
type: engineTypes.EntityStorageConnectorType.PostgreSql,
|
|
728
|
-
options: {
|
|
729
|
-
config: {
|
|
730
|
-
host: envVars.postgreSqlHost ?? "",
|
|
731
|
-
port: core.Coerce.integer(envVars.postgreSqlPort),
|
|
732
|
-
user: envVars.postgreSqlUser ?? "",
|
|
733
|
-
password: envVars.postgreSqlPassword ?? "",
|
|
734
|
-
database: envVars.postgreSqlDatabase ?? ""
|
|
735
|
-
},
|
|
736
|
-
tablePrefix: envVars.entityStorageTablePrefix
|
|
737
|
-
}
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
const defaultEntityStorageConnectorType = envVars.entityStorageConnectorDefault ?? entityStorageConnectorTypes[0];
|
|
741
|
-
if (entityStorageConnectorTypes.includes(engineTypes.EntityStorageConnectorType.Synchronised)) {
|
|
742
|
-
// For synchronised storage we use the default connector as the one we wrap for real DB operations
|
|
743
|
-
coreConfig.types.entityStorageConnector.push({
|
|
744
|
-
type: engineTypes.EntityStorageConnectorType.Synchronised,
|
|
745
|
-
options: {
|
|
746
|
-
entityStorageConnectorType: defaultEntityStorageConnectorType
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
}
|
|
750
|
-
if (core.Is.arrayValue(entityStorageConnectorTypes)) {
|
|
751
|
-
for (const config of coreConfig.types.entityStorageConnector) {
|
|
752
|
-
if (config.type === defaultEntityStorageConnectorType) {
|
|
753
|
-
config.isDefault = true;
|
|
754
|
-
break;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
/**
|
|
760
|
-
* Configures the blob storage.
|
|
761
|
-
* @param coreConfig The core config.
|
|
762
|
-
* @param envVars The environment variables.
|
|
763
|
-
*/
|
|
764
|
-
function configureBlobStorage(coreConfig, envVars) {
|
|
765
|
-
coreConfig.types.blobStorageConnector ??= [];
|
|
766
|
-
const blobStorageConnectorTypes = envVars.blobStorageConnectorType?.split(",") ?? [];
|
|
767
|
-
if (blobStorageConnectorTypes.includes(engineTypes.BlobStorageConnectorType.Memory)) {
|
|
768
|
-
coreConfig.types.blobStorageConnector.push({
|
|
769
|
-
type: engineTypes.BlobStorageConnectorType.Memory
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
if (blobStorageConnectorTypes.includes(engineTypes.BlobStorageConnectorType.File)) {
|
|
773
|
-
coreConfig.types.blobStorageConnector.push({
|
|
774
|
-
type: engineTypes.BlobStorageConnectorType.File,
|
|
775
|
-
options: {
|
|
776
|
-
config: {
|
|
777
|
-
directory: core.Is.stringValue(envVars.storageFileRoot)
|
|
778
|
-
? path.join(envVars.storageFileRoot, "blob-storage")
|
|
779
|
-
: ""
|
|
780
|
-
},
|
|
781
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
if (blobStorageConnectorTypes.includes(engineTypes.BlobStorageConnectorType.Ipfs)) {
|
|
786
|
-
coreConfig.types.blobStorageConnector.push({
|
|
787
|
-
type: engineTypes.BlobStorageConnectorType.Ipfs,
|
|
788
|
-
options: {
|
|
789
|
-
config: {
|
|
790
|
-
apiUrl: envVars.ipfsApiUrl ?? "",
|
|
791
|
-
bearerToken: envVars.ipfsBearerToken
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
if (blobStorageConnectorTypes.includes(engineTypes.BlobStorageConnectorType.AwsS3)) {
|
|
797
|
-
coreConfig.types.blobStorageConnector.push({
|
|
798
|
-
type: engineTypes.BlobStorageConnectorType.AwsS3,
|
|
799
|
-
options: {
|
|
800
|
-
config: {
|
|
801
|
-
region: envVars.awsS3Region ?? "",
|
|
802
|
-
bucketName: envVars.awsS3BucketName ?? "",
|
|
803
|
-
accessKeyId: envVars.awsS3AccessKeyId ?? "",
|
|
804
|
-
secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
|
|
805
|
-
endpoint: envVars.awsS3Endpoint ?? ""
|
|
806
|
-
},
|
|
807
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
if (blobStorageConnectorTypes.includes(engineTypes.BlobStorageConnectorType.AzureStorage)) {
|
|
812
|
-
coreConfig.types.blobStorageConnector.push({
|
|
813
|
-
type: engineTypes.BlobStorageConnectorType.AzureStorage,
|
|
814
|
-
options: {
|
|
815
|
-
config: {
|
|
816
|
-
accountName: envVars.azureStorageAccountName ?? "",
|
|
817
|
-
accountKey: envVars.azureStorageAccountKey ?? "",
|
|
818
|
-
containerName: envVars.azureStorageContainerName ?? "",
|
|
819
|
-
endpoint: envVars.azureStorageEndpoint ?? ""
|
|
820
|
-
},
|
|
821
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
822
|
-
}
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
if (blobStorageConnectorTypes.includes(engineTypes.BlobStorageConnectorType.GcpStorage)) {
|
|
826
|
-
coreConfig.types.blobStorageConnector.push({
|
|
827
|
-
type: engineTypes.BlobStorageConnectorType.GcpStorage,
|
|
828
|
-
options: {
|
|
829
|
-
config: {
|
|
830
|
-
projectId: envVars.gcpStorageProjectId ?? "",
|
|
831
|
-
credentials: envVars.gcpStorageCredentials ?? "",
|
|
832
|
-
bucketName: envVars.gcpStorageBucketName ?? "",
|
|
833
|
-
apiEndpoint: envVars.gcpFirestoreApiEndpoint
|
|
834
|
-
},
|
|
835
|
-
storagePrefix: envVars.blobStoragePrefix
|
|
836
|
-
}
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
if (core.Is.arrayValue(blobStorageConnectorTypes)) {
|
|
840
|
-
const defaultStorageConnectorType = envVars.blobStorageConnectorDefault ?? blobStorageConnectorTypes[0];
|
|
841
|
-
for (const config of coreConfig.types.blobStorageConnector) {
|
|
842
|
-
if (config.type === defaultStorageConnectorType) {
|
|
843
|
-
config.isDefault = true;
|
|
844
|
-
}
|
|
845
|
-
// If this blob storage connector is the one to use for public access
|
|
846
|
-
// then add it as a feature
|
|
847
|
-
if (core.Is.stringValue(envVars.blobStorageConnectorPublic) &&
|
|
848
|
-
config.type === envVars.blobStorageConnectorPublic) {
|
|
849
|
-
config.features ??= [];
|
|
850
|
-
config.features.push("public");
|
|
851
|
-
break;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
if (coreConfig.types.blobStorageConnector.length > 0) {
|
|
856
|
-
coreConfig.types.blobStorageComponent ??= [];
|
|
857
|
-
coreConfig.types.blobStorageComponent.push({
|
|
858
|
-
type: engineTypes.BlobStorageComponentType.Service,
|
|
859
|
-
options: {
|
|
860
|
-
config: {
|
|
861
|
-
vaultKeyId: (envVars.blobStorageEnableEncryption ?? false)
|
|
862
|
-
? envVars.blobStorageEncryptionKeyId
|
|
863
|
-
: undefined
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Configures the logging.
|
|
871
|
-
* @param coreConfig The core config.
|
|
872
|
-
* @param envVars The environment variables.
|
|
873
|
-
*/
|
|
874
|
-
function configureLogging(coreConfig, envVars) {
|
|
875
|
-
coreConfig.types.loggingConnector ??= [];
|
|
876
|
-
const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
|
|
877
|
-
for (const loggingConnector of loggingConnectors) {
|
|
878
|
-
if (loggingConnector === engineTypes.LoggingConnectorType.Console) {
|
|
879
|
-
coreConfig.types.loggingConnector?.push({
|
|
880
|
-
type: engineTypes.LoggingConnectorType.Console,
|
|
881
|
-
options: {
|
|
882
|
-
config: {
|
|
883
|
-
translateMessages: true,
|
|
884
|
-
hideGroups: true
|
|
885
|
-
}
|
|
886
|
-
},
|
|
887
|
-
isDefault: loggingConnectors.length === 1
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
else if (loggingConnector === engineTypes.LoggingConnectorType.EntityStorage) {
|
|
891
|
-
coreConfig.types.loggingConnector?.push({
|
|
892
|
-
type: engineTypes.LoggingConnectorType.EntityStorage,
|
|
893
|
-
isDefault: loggingConnectors.length === 1
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
if (loggingConnectors.length > 1) {
|
|
898
|
-
coreConfig.types.loggingConnector?.push({
|
|
899
|
-
type: engineTypes.LoggingConnectorType.Multi,
|
|
900
|
-
isDefault: true,
|
|
901
|
-
options: {
|
|
902
|
-
loggingConnectorTypes: loggingConnectors
|
|
903
|
-
}
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
if (loggingConnectors.length > 0) {
|
|
907
|
-
coreConfig.types.loggingComponent ??= [];
|
|
908
|
-
coreConfig.types.loggingComponent.push({ type: engineTypes.LoggingComponentType.Service });
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* Configures the vault.
|
|
913
|
-
* @param coreConfig The core config.
|
|
914
|
-
* @param envVars The environment variables.
|
|
915
|
-
*/
|
|
916
|
-
function configureVault(coreConfig, envVars) {
|
|
917
|
-
coreConfig.types.vaultConnector ??= [];
|
|
918
|
-
if (envVars.vaultConnector === engineTypes.VaultConnectorType.EntityStorage) {
|
|
919
|
-
coreConfig.types.vaultConnector.push({
|
|
920
|
-
type: engineTypes.VaultConnectorType.EntityStorage
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
else if (envVars.vaultConnector === engineTypes.VaultConnectorType.Hashicorp) {
|
|
924
|
-
coreConfig.types.vaultConnector.push({
|
|
925
|
-
type: engineTypes.VaultConnectorType.Hashicorp,
|
|
926
|
-
options: {
|
|
927
|
-
config: {
|
|
928
|
-
endpoint: envVars.hashicorpVaultEndpoint ?? "",
|
|
929
|
-
token: envVars.hashicorpVaultToken ?? ""
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* Configures the background task.
|
|
937
|
-
* @param coreConfig The core config.
|
|
938
|
-
* @param envVars The environment variables.
|
|
939
|
-
*/
|
|
940
|
-
function configureBackgroundTask(coreConfig, envVars) {
|
|
941
|
-
coreConfig.types.backgroundTaskConnector ??= [];
|
|
942
|
-
if (envVars.backgroundTaskConnector === engineTypes.BackgroundTaskConnectorType.EntityStorage) {
|
|
943
|
-
coreConfig.types.backgroundTaskConnector.push({
|
|
944
|
-
type: engineTypes.BackgroundTaskConnectorType.EntityStorage
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Configures the event bud.
|
|
950
|
-
* @param coreConfig The core config.
|
|
951
|
-
* @param envVars The environment variables.
|
|
952
|
-
*/
|
|
953
|
-
function configureEventBus(coreConfig, envVars) {
|
|
954
|
-
coreConfig.types.eventBusConnector ??= [];
|
|
955
|
-
if (envVars.eventBusConnector === engineTypes.EventBusConnectorType.Local) {
|
|
956
|
-
coreConfig.types.eventBusConnector.push({
|
|
957
|
-
type: engineTypes.EventBusConnectorType.Local
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
if (coreConfig.types.eventBusConnector.length > 0) {
|
|
961
|
-
coreConfig.types.eventBusComponent ??= [];
|
|
962
|
-
coreConfig.types.eventBusComponent.push({ type: engineTypes.EventBusComponentType.Service });
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* Configures the telemetry.
|
|
967
|
-
* @param coreConfig The core config.
|
|
968
|
-
* @param envVars The environment variables.
|
|
969
|
-
*/
|
|
970
|
-
function configureTelemetry(coreConfig, envVars) {
|
|
971
|
-
coreConfig.types.telemetryConnector ??= [];
|
|
972
|
-
if (envVars.telemetryConnector === engineTypes.TelemetryConnectorType.EntityStorage) {
|
|
973
|
-
coreConfig.types.telemetryConnector.push({
|
|
974
|
-
type: engineTypes.TelemetryConnectorType.EntityStorage
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
|
-
if (coreConfig.types.telemetryConnector.length > 0) {
|
|
978
|
-
coreConfig.types.telemetryComponent ??= [];
|
|
979
|
-
coreConfig.types.telemetryComponent.push({ type: engineTypes.TelemetryComponentType.Service });
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Configures the messaging.
|
|
984
|
-
* @param coreConfig The core config.
|
|
985
|
-
* @param envVars The environment variables.
|
|
986
|
-
*/
|
|
987
|
-
function configureMessaging(coreConfig, envVars) {
|
|
988
|
-
coreConfig.types.messagingEmailConnector ??= [];
|
|
989
|
-
coreConfig.types.messagingSmsConnector ??= [];
|
|
990
|
-
coreConfig.types.messagingPushNotificationConnector ??= [];
|
|
991
|
-
if (envVars.messagingEmailConnector === engineTypes.MessagingEmailConnectorType.EntityStorage) {
|
|
992
|
-
coreConfig.types.messagingEmailConnector.push({
|
|
993
|
-
type: engineTypes.MessagingEmailConnectorType.EntityStorage
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
else if (envVars.messagingEmailConnector === engineTypes.MessagingEmailConnectorType.Aws) {
|
|
997
|
-
coreConfig.types.messagingEmailConnector.push({
|
|
998
|
-
type: engineTypes.MessagingEmailConnectorType.Aws,
|
|
999
|
-
options: {
|
|
1000
|
-
config: {
|
|
1001
|
-
region: envVars.awsS3Region ?? "",
|
|
1002
|
-
accessKeyId: envVars.awsS3AccessKeyId ?? "",
|
|
1003
|
-
secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
|
|
1004
|
-
endpoint: envVars.awsS3Endpoint ?? ""
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
if (envVars.messagingSmsConnector === engineTypes.MessagingSmsConnectorType.EntityStorage) {
|
|
1010
|
-
coreConfig.types.messagingSmsConnector.push({
|
|
1011
|
-
type: engineTypes.MessagingSmsConnectorType.EntityStorage
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
else if (envVars.messagingSmsConnector === engineTypes.MessagingSmsConnectorType.Aws) {
|
|
1015
|
-
coreConfig.types.messagingSmsConnector.push({
|
|
1016
|
-
type: engineTypes.MessagingSmsConnectorType.Aws,
|
|
1017
|
-
options: {
|
|
1018
|
-
config: {
|
|
1019
|
-
region: envVars.awsS3Region ?? "",
|
|
1020
|
-
accessKeyId: envVars.awsS3AccessKeyId ?? "",
|
|
1021
|
-
secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
|
|
1022
|
-
endpoint: envVars.awsS3Endpoint ?? ""
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
if (envVars.messagingPushNotificationConnector ===
|
|
1028
|
-
engineTypes.MessagingPushNotificationConnectorType.EntityStorage) {
|
|
1029
|
-
coreConfig.types.messagingPushNotificationConnector.push({
|
|
1030
|
-
type: engineTypes.MessagingPushNotificationConnectorType.EntityStorage
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
else if (envVars.messagingPushNotificationConnector === engineTypes.MessagingPushNotificationConnectorType.Aws) {
|
|
1034
|
-
coreConfig.types.messagingPushNotificationConnector.push({
|
|
1035
|
-
type: engineTypes.MessagingPushNotificationConnectorType.Aws,
|
|
1036
|
-
options: {
|
|
1037
|
-
config: {
|
|
1038
|
-
region: envVars.awsS3Region ?? "",
|
|
1039
|
-
accessKeyId: envVars.awsS3AccessKeyId ?? "",
|
|
1040
|
-
secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
|
|
1041
|
-
endpoint: envVars.awsS3Endpoint ?? "",
|
|
1042
|
-
applicationsSettings: core.Is.json(envVars.awsMessagingPushNotificationApplications)
|
|
1043
|
-
? JSON.parse(envVars.awsMessagingPushNotificationApplications)
|
|
1044
|
-
: []
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
if (coreConfig.types.messagingEmailConnector.length > 0 ||
|
|
1050
|
-
coreConfig.types.messagingSmsConnector.length > 0 ||
|
|
1051
|
-
coreConfig.types.messagingPushNotificationConnector.length > 0) {
|
|
1052
|
-
coreConfig.types.messagingComponent ??= [];
|
|
1053
|
-
coreConfig.types.messagingComponent.push({ type: engineTypes.MessagingComponentType.Service });
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
/**
|
|
1057
|
-
* Configures the faucet.
|
|
1058
|
-
* @param coreConfig The core config.
|
|
1059
|
-
* @param envVars The environment variables.
|
|
1060
|
-
*/
|
|
1061
|
-
function configureFaucet(coreConfig, envVars) {
|
|
1062
|
-
coreConfig.types.faucetConnector ??= [];
|
|
1063
|
-
if (envVars.faucetConnector === engineTypes.FaucetConnectorType.EntityStorage) {
|
|
1064
|
-
coreConfig.types.faucetConnector.push({
|
|
1065
|
-
type: engineTypes.FaucetConnectorType.EntityStorage
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
|
-
else if (envVars.faucetConnector === engineTypes.FaucetConnectorType.Iota) {
|
|
1069
|
-
const iotaConfig = getIotaConfig(coreConfig);
|
|
1070
|
-
coreConfig.types.faucetConnector.push({
|
|
1071
|
-
type: engineTypes.FaucetConnectorType.Iota,
|
|
1072
|
-
options: {
|
|
1073
|
-
config: {
|
|
1074
|
-
endpoint: envVars.iotaFaucetEndpoint ?? "",
|
|
1075
|
-
clientOptions: iotaConfig?.clientOptions ?? { url: "" },
|
|
1076
|
-
network: iotaConfig?.network ?? ""
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
/**
|
|
1083
|
-
* Configures the wallet.
|
|
1084
|
-
* @param coreConfig The core config.
|
|
1085
|
-
* @param envVars The environment variables.
|
|
1086
|
-
*/
|
|
1087
|
-
function configureWallet(coreConfig, envVars) {
|
|
1088
|
-
coreConfig.types.walletConnector ??= [];
|
|
1089
|
-
if (envVars.walletConnector === engineTypes.WalletConnectorType.EntityStorage) {
|
|
1090
|
-
coreConfig.types.walletConnector.push({
|
|
1091
|
-
type: engineTypes.WalletConnectorType.EntityStorage
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
else if (envVars.walletConnector === engineTypes.WalletConnectorType.Iota) {
|
|
1095
|
-
const iotaConfig = getIotaConfig(coreConfig);
|
|
1096
|
-
coreConfig.types.walletConnector.push({
|
|
1097
|
-
type: engineTypes.WalletConnectorType.Iota,
|
|
1098
|
-
options: {
|
|
1099
|
-
config: iotaConfig ?? {}
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Configures the NFT.
|
|
1106
|
-
* @param coreConfig The core config.
|
|
1107
|
-
* @param envVars The environment variables.
|
|
1108
|
-
*/
|
|
1109
|
-
function configureNft(coreConfig, envVars) {
|
|
1110
|
-
coreConfig.types.nftConnector ??= [];
|
|
1111
|
-
if (envVars.nftConnector === engineTypes.NftConnectorType.EntityStorage) {
|
|
1112
|
-
coreConfig.types.nftConnector.push({
|
|
1113
|
-
type: engineTypes.NftConnectorType.EntityStorage
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
else if (envVars.nftConnector === engineTypes.NftConnectorType.Iota) {
|
|
1117
|
-
const iotaConfig = getIotaConfig(coreConfig);
|
|
1118
|
-
coreConfig.types.nftConnector.push({
|
|
1119
|
-
type: engineTypes.NftConnectorType.Iota,
|
|
1120
|
-
options: {
|
|
1121
|
-
config: iotaConfig ?? {}
|
|
1122
|
-
}
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
|
-
if (coreConfig.types.nftConnector.length > 0) {
|
|
1126
|
-
coreConfig.types.nftComponent ??= [];
|
|
1127
|
-
coreConfig.types.nftComponent.push({ type: engineTypes.NftComponentType.Service });
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
/**
|
|
1131
|
-
* Configures the verifiable storage.
|
|
1132
|
-
* @param coreConfig The core config.
|
|
1133
|
-
* @param envVars The environment variables.
|
|
1134
|
-
*/
|
|
1135
|
-
function configureVerifiableStorage(coreConfig, envVars) {
|
|
1136
|
-
coreConfig.types.verifiableStorageConnector ??= [];
|
|
1137
|
-
if (envVars.verifiableStorageConnector === engineTypes.VerifiableStorageConnectorType.EntityStorage) {
|
|
1138
|
-
coreConfig.types.verifiableStorageConnector.push({
|
|
1139
|
-
type: engineTypes.VerifiableStorageConnectorType.EntityStorage
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
else if (envVars.verifiableStorageConnector === engineTypes.VerifiableStorageConnectorType.Iota) {
|
|
1143
|
-
const iotaConfig = getIotaConfig(coreConfig);
|
|
1144
|
-
coreConfig.types.verifiableStorageConnector.push({
|
|
1145
|
-
type: engineTypes.VerifiableStorageConnectorType.Iota,
|
|
1146
|
-
options: {
|
|
1147
|
-
config: iotaConfig ?? {}
|
|
1148
|
-
}
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
if (coreConfig.types.verifiableStorageConnector.length > 0) {
|
|
1152
|
-
coreConfig.types.verifiableStorageComponent ??= [];
|
|
1153
|
-
coreConfig.types.verifiableStorageComponent.push({
|
|
1154
|
-
type: engineTypes.VerifiableStorageComponentType.Service
|
|
1155
|
-
});
|
|
1156
|
-
coreConfig.types.immutableProofComponent ??= [];
|
|
1157
|
-
coreConfig.types.immutableProofComponent.push({
|
|
1158
|
-
type: engineTypes.ImmutableProofComponentType.Service,
|
|
1159
|
-
options: {
|
|
1160
|
-
config: {
|
|
1161
|
-
verificationMethodId: envVars.immutableProofVerificationMethodId
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
coreConfig.types.auditableItemGraphComponent ??= [];
|
|
1166
|
-
coreConfig.types.auditableItemGraphComponent.push({
|
|
1167
|
-
type: engineTypes.AuditableItemGraphComponentType.Service
|
|
1168
|
-
});
|
|
1169
|
-
coreConfig.types.auditableItemStreamComponent ??= [];
|
|
1170
|
-
coreConfig.types.auditableItemStreamComponent.push({
|
|
1171
|
-
type: engineTypes.AuditableItemStreamComponentType.Service
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
1176
|
-
* Configures the identity.
|
|
1177
|
-
* @param coreConfig The core config.
|
|
1178
|
-
* @param envVars The environment variables.
|
|
1179
|
-
*/
|
|
1180
|
-
function configureIdentity(coreConfig, envVars) {
|
|
1181
|
-
coreConfig.types.identityConnector ??= [];
|
|
1182
|
-
if (envVars.identityConnector === engineTypes.IdentityConnectorType.EntityStorage) {
|
|
1183
|
-
coreConfig.types.identityConnector.push({
|
|
1184
|
-
type: engineTypes.IdentityConnectorType.EntityStorage
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
else if (envVars.identityConnector === engineTypes.IdentityConnectorType.Iota) {
|
|
1188
|
-
const iotaConfig = getIotaConfig(coreConfig);
|
|
1189
|
-
coreConfig.types.identityConnector.push({
|
|
1190
|
-
type: engineTypes.IdentityConnectorType.Iota,
|
|
1191
|
-
options: {
|
|
1192
|
-
config: iotaConfig ?? {}
|
|
1193
|
-
}
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
if (coreConfig.types.identityConnector.length > 0) {
|
|
1197
|
-
coreConfig.types.identityComponent ??= [];
|
|
1198
|
-
coreConfig.types.identityComponent.push({ type: engineTypes.IdentityComponentType.Service });
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Configures the identity resolver.
|
|
1203
|
-
* @param coreConfig The core config.
|
|
1204
|
-
* @param envVars The environment variables.
|
|
1205
|
-
*/
|
|
1206
|
-
function configureIdentityResolver(coreConfig, envVars) {
|
|
1207
|
-
coreConfig.types.identityResolverConnector ??= [];
|
|
1208
|
-
if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.EntityStorage) {
|
|
1209
|
-
coreConfig.types.identityResolverConnector.push({
|
|
1210
|
-
type: engineTypes.IdentityResolverConnectorType.EntityStorage
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
else if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.Iota) {
|
|
1214
|
-
const iotaConfig = getIotaConfig(coreConfig);
|
|
1215
|
-
coreConfig.types.identityResolverConnector.push({
|
|
1216
|
-
type: engineTypes.IdentityResolverConnectorType.Iota,
|
|
1217
|
-
options: {
|
|
1218
|
-
config: iotaConfig ?? {}
|
|
1219
|
-
}
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
else if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.Universal) {
|
|
1223
|
-
coreConfig.types.identityResolverConnector.push({
|
|
1224
|
-
type: engineTypes.IdentityResolverConnectorType.Universal,
|
|
1225
|
-
options: {
|
|
1226
|
-
config: {
|
|
1227
|
-
endpoint: envVars.universalResolverEndpoint ?? ""
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
if (coreConfig.types.identityResolverConnector.length > 0) {
|
|
1233
|
-
coreConfig.types.identityResolverComponent ??= [];
|
|
1234
|
-
coreConfig.types.identityResolverComponent.push({
|
|
1235
|
-
type: engineTypes.IdentityResolverComponentType.Service
|
|
1236
|
-
});
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Configures the identity profile.
|
|
1241
|
-
* @param coreConfig The core config.
|
|
1242
|
-
* @param envVars The environment variables.
|
|
1243
|
-
*/
|
|
1244
|
-
function configureIdentityProfile(coreConfig, envVars) {
|
|
1245
|
-
coreConfig.types.identityProfileConnector ??= [];
|
|
1246
|
-
if (envVars.identityProfileConnector === engineTypes.IdentityConnectorType.EntityStorage) {
|
|
1247
|
-
coreConfig.types.identityProfileConnector.push({
|
|
1248
|
-
type: engineTypes.IdentityProfileConnectorType.EntityStorage
|
|
1249
|
-
});
|
|
1250
|
-
}
|
|
1251
|
-
if (coreConfig.types.identityProfileConnector.length > 0) {
|
|
1252
|
-
coreConfig.types.identityProfileComponent ??= [];
|
|
1253
|
-
coreConfig.types.identityProfileComponent.push({ type: engineTypes.IdentityProfileComponentType.Service });
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
/**
|
|
1257
|
-
* Configures the attestation.
|
|
1258
|
-
* @param coreConfig The core config.
|
|
1259
|
-
* @param envVars The environment variables.
|
|
1260
|
-
*/
|
|
1261
|
-
function configureAttestation(coreConfig, envVars) {
|
|
1262
|
-
coreConfig.types.attestationConnector ??= [];
|
|
1263
|
-
if (envVars.attestationConnector === engineTypes.AttestationConnectorType.Nft) {
|
|
1264
|
-
coreConfig.types.attestationConnector.push({
|
|
1265
|
-
type: engineTypes.AttestationConnectorType.Nft
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
if (coreConfig.types.attestationConnector.length > 0) {
|
|
1269
|
-
coreConfig.types.attestationComponent ??= [];
|
|
1270
|
-
coreConfig.types.attestationComponent.push({
|
|
1271
|
-
type: engineTypes.AttestationComponentType.Service,
|
|
1272
|
-
options: {
|
|
1273
|
-
config: {
|
|
1274
|
-
verificationMethodId: envVars.attestationVerificationMethodId
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
/**
|
|
1281
|
-
* Configures the auditable item graph.
|
|
1282
|
-
* @param coreConfig The core config.
|
|
1283
|
-
* @param envVars The environment variables.
|
|
1284
|
-
*/
|
|
1285
|
-
function configureAuditableItemGraph(coreConfig, envVars) {
|
|
1286
|
-
if (core.Is.arrayValue(coreConfig.types.verifiableStorageConnector)) {
|
|
1287
|
-
coreConfig.types.auditableItemGraphComponent ??= [];
|
|
1288
|
-
coreConfig.types.auditableItemGraphComponent.push({
|
|
1289
|
-
type: engineTypes.AuditableItemGraphComponentType.Service
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
/**
|
|
1294
|
-
* Configures the auditable item stream.
|
|
1295
|
-
* @param coreConfig The core config.
|
|
1296
|
-
* @param envVars The environment variables.
|
|
1297
|
-
*/
|
|
1298
|
-
function configureAuditableItemStream(coreConfig, envVars) {
|
|
1299
|
-
if (core.Is.arrayValue(coreConfig.types.verifiableStorageConnector)) {
|
|
1300
|
-
coreConfig.types.auditableItemStreamComponent ??= [];
|
|
1301
|
-
coreConfig.types.auditableItemStreamComponent.push({
|
|
1302
|
-
type: engineTypes.AuditableItemStreamComponentType.Service
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
/**
|
|
1307
|
-
* Configures the data processing.
|
|
1308
|
-
* @param coreConfig The core config.
|
|
1309
|
-
* @param envVars The environment variables.
|
|
1310
|
-
*/
|
|
1311
|
-
function configureDataProcessing(coreConfig, envVars) {
|
|
1312
|
-
coreConfig.types.dataConverterConnector ??= [];
|
|
1313
|
-
coreConfig.types.dataExtractorConnector ??= [];
|
|
1314
|
-
const converterConnectors = envVars.dataConverterConnectors?.split(",") ?? [];
|
|
1315
|
-
for (const converterConnector of converterConnectors) {
|
|
1316
|
-
if (converterConnector === engineTypes.DataConverterConnectorType.Json) {
|
|
1317
|
-
coreConfig.types.dataConverterConnector.push({
|
|
1318
|
-
type: engineTypes.DataConverterConnectorType.Json
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
else if (converterConnector === engineTypes.DataConverterConnectorType.Xml) {
|
|
1322
|
-
coreConfig.types.dataConverterConnector.push({
|
|
1323
|
-
type: engineTypes.DataConverterConnectorType.Xml
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
const extractorConnectors = envVars.dataExtractorConnectors?.split(",") ?? [];
|
|
1328
|
-
for (const extractorConnector of extractorConnectors) {
|
|
1329
|
-
if (extractorConnector === engineTypes.DataExtractorConnectorType.JsonPath) {
|
|
1330
|
-
coreConfig.types.dataExtractorConnector.push({
|
|
1331
|
-
type: engineTypes.DataExtractorConnectorType.JsonPath
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
if (coreConfig.types.dataConverterConnector.length > 0 ||
|
|
1336
|
-
coreConfig.types.dataExtractorConnector.length > 0) {
|
|
1337
|
-
coreConfig.types.dataProcessingComponent ??= [];
|
|
1338
|
-
coreConfig.types.dataProcessingComponent.push({ type: engineTypes.DataProcessingComponentType.Service });
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Configures the document management.
|
|
1343
|
-
* @param coreConfig The core config.
|
|
1344
|
-
* @param envVars The environment variables.
|
|
1345
|
-
*/
|
|
1346
|
-
function configureDocumentManagement(coreConfig, envVars) {
|
|
1347
|
-
if (core.Is.arrayValue(coreConfig.types.auditableItemGraphComponent) &&
|
|
1348
|
-
core.Is.arrayValue(coreConfig.types.blobStorageComponent) &&
|
|
1349
|
-
core.Is.arrayValue(coreConfig.types.attestationComponent)) {
|
|
1350
|
-
coreConfig.types.documentManagementComponent ??= [];
|
|
1351
|
-
coreConfig.types.documentManagementComponent.push({
|
|
1352
|
-
type: engineTypes.DocumentManagementComponentType.Service
|
|
1353
|
-
});
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* Configures the rights management.
|
|
1358
|
-
* @param coreConfig The core config.
|
|
1359
|
-
* @param envVars The environment variables.
|
|
1360
|
-
*/
|
|
1361
|
-
function configureRightsManagement(coreConfig, envVars) {
|
|
1362
|
-
if (core.Coerce.boolean(envVars.rightsManagementEnabled) ?? false) {
|
|
1363
|
-
coreConfig.types.rightsManagementPapComponent ??= [];
|
|
1364
|
-
coreConfig.types.rightsManagementPapComponent.push({
|
|
1365
|
-
type: engineTypes.RightsManagementPapComponentType.Service
|
|
1366
|
-
});
|
|
1367
|
-
coreConfig.types.rightsManagementPmpComponent ??= [];
|
|
1368
|
-
coreConfig.types.rightsManagementPmpComponent.push({
|
|
1369
|
-
type: engineTypes.RightsManagementPmpComponentType.Service
|
|
1370
|
-
});
|
|
1371
|
-
coreConfig.types.rightsManagementPipComponent ??= [];
|
|
1372
|
-
coreConfig.types.rightsManagementPipComponent.push({
|
|
1373
|
-
type: engineTypes.RightsManagementPipComponentType.Service
|
|
1374
|
-
});
|
|
1375
|
-
coreConfig.types.rightsManagementPxpComponent ??= [];
|
|
1376
|
-
coreConfig.types.rightsManagementPxpComponent.push({
|
|
1377
|
-
type: engineTypes.RightsManagementPxpComponentType.Service
|
|
1378
|
-
});
|
|
1379
|
-
coreConfig.types.rightsManagementPdpComponent ??= [];
|
|
1380
|
-
coreConfig.types.rightsManagementPdpComponent.push({
|
|
1381
|
-
type: engineTypes.RightsManagementPdpComponentType.Service
|
|
1382
|
-
});
|
|
1383
|
-
coreConfig.types.rightsManagementPepComponent ??= [];
|
|
1384
|
-
coreConfig.types.rightsManagementPepComponent.push({
|
|
1385
|
-
type: engineTypes.RightsManagementPepComponentType.Service
|
|
1386
|
-
});
|
|
1387
|
-
coreConfig.types.rightsManagementComponent ??= [];
|
|
1388
|
-
coreConfig.types.rightsManagementComponent.push({
|
|
1389
|
-
type: engineTypes.RightsManagementComponentType.Service
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Configures the task scheduler.
|
|
1395
|
-
* @param coreConfig The core config.
|
|
1396
|
-
* @param envVars The environment variables.
|
|
1397
|
-
*/
|
|
1398
|
-
function configureTaskScheduler(coreConfig, envVars) {
|
|
1399
|
-
if (core.Coerce.boolean(envVars.taskSchedulerEnabled) ?? false) {
|
|
1400
|
-
coreConfig.types.taskSchedulerComponent ??= [];
|
|
1401
|
-
coreConfig.types.taskSchedulerComponent.push({
|
|
1402
|
-
type: engineTypes.TaskSchedulerComponentType.Service
|
|
1403
|
-
});
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Configures the synchronised storage.
|
|
1408
|
-
* @param coreConfig The core config.
|
|
1409
|
-
* @param envVars The environment variables.
|
|
1410
|
-
*/
|
|
1411
|
-
function configureSynchronisedStorage(coreConfig, envVars) {
|
|
1412
|
-
if (core.Is.arrayValue(coreConfig.types.identityResolverComponent) &&
|
|
1413
|
-
(core.Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false)) {
|
|
1414
|
-
// Check if the config provides a custom verifiable storage key id
|
|
1415
|
-
let verifiableStorageKeyId = core.Coerce.string(envVars.synchronisedStorageVerifiableStorageKeyId);
|
|
1416
|
-
if (!core.Is.stringValue(verifiableStorageKeyId)) {
|
|
1417
|
-
// No custom key so default to the network setting
|
|
1418
|
-
verifiableStorageKeyId = envVars.iotaNetwork;
|
|
1419
|
-
}
|
|
1420
|
-
coreConfig.types.synchronisedStorageComponent ??= [];
|
|
1421
|
-
coreConfig.types.synchronisedStorageComponent.push({
|
|
1422
|
-
type: engineTypes.SynchronisedStorageComponentType.Service,
|
|
1423
|
-
options: {
|
|
1424
|
-
config: {
|
|
1425
|
-
verifiableStorageKeyId: verifiableStorageKeyId ?? "",
|
|
1426
|
-
synchronisedStorageMethodId: envVars.synchronisedStorageVerificationMethodId,
|
|
1427
|
-
blobStorageEncryptionKeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,
|
|
1428
|
-
entityUpdateIntervalMinutes: core.Coerce.number(envVars.synchronisedStorageEntityUpdateIntervalMinutes),
|
|
1429
|
-
consolidationIntervalMinutes: core.Coerce.number(envVars.synchronisedStorageConsolidationIntervalMinutes),
|
|
1430
|
-
consolidationBatchSize: core.Coerce.number(envVars.synchronisedStorageConsolidationBatchSize),
|
|
1431
|
-
maxConsolidations: core.Coerce.number(envVars.synchronisedStorageMaxConsolidations)
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
});
|
|
1435
|
-
// If there is a trusted url set, we need to add a client
|
|
1436
|
-
// and give it a feature of trusted so that when the synchronised
|
|
1437
|
-
// storage is created it can pickup the correct component
|
|
1438
|
-
if (core.Is.stringValue(envVars.synchronisedStorageTrustedUrl)) {
|
|
1439
|
-
coreConfig.types.synchronisedStorageComponent.push({
|
|
1440
|
-
type: engineTypes.SynchronisedStorageComponentType.RestClient,
|
|
1441
|
-
options: {
|
|
1442
|
-
endpoint: envVars.synchronisedStorageTrustedUrl
|
|
1443
|
-
},
|
|
1444
|
-
features: ["trusted"]
|
|
1445
|
-
});
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
/**
|
|
1450
|
-
* Configures the federated catalogue.
|
|
1451
|
-
* @param coreConfig The core config.
|
|
1452
|
-
* @param envVars The environment variables.
|
|
1453
|
-
*/
|
|
1454
|
-
function configureFederatedCatalogue(coreConfig, envVars) {
|
|
1455
|
-
if (core.Coerce.boolean(envVars.federatedCatalogueEnabled) ?? false) {
|
|
1456
|
-
coreConfig.types.federatedCatalogueComponent ??= [];
|
|
1457
|
-
coreConfig.types.federatedCatalogueComponent.push({
|
|
1458
|
-
type: engineTypes.FederatedCatalogueComponentType.Service,
|
|
1459
|
-
options: {
|
|
1460
|
-
config: {
|
|
1461
|
-
subResourceCacheTtlMs: core.Coerce.number(envVars.federatedCatalogueCacheTtlMs),
|
|
1462
|
-
clearingHouseApproverList: core.Coerce.object(envVars.federatedCatalogueClearingHouseApproverList) ?? []
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
* Configures the data space connector.
|
|
1470
|
-
* @param coreConfig The core config.
|
|
1471
|
-
* @param envVars The environment variables.
|
|
1472
|
-
*/
|
|
1473
|
-
function configureDataSpaceConnector(coreConfig, envVars) {
|
|
1474
|
-
if (core.Coerce.boolean(envVars.dataSpaceConnectorEnabled) ?? false) {
|
|
1475
|
-
coreConfig.types.dataSpaceConnectorComponent ??= [];
|
|
1476
|
-
coreConfig.types.dataSpaceConnectorComponent.push({
|
|
1477
|
-
type: engineTypes.DataSpaceConnectorComponentType.Service,
|
|
1478
|
-
options: {
|
|
1479
|
-
config: {
|
|
1480
|
-
dataSpaceConnectorAppDescriptors: core.Is.arrayValue(envVars.dataSpaceConnectorApps)
|
|
1481
|
-
? envVars.dataSpaceConnectorApps
|
|
1482
|
-
: undefined
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Configures the DLT.
|
|
1490
|
-
* @param coreConfig The core config.
|
|
1491
|
-
* @param envVars The environment variables.
|
|
1492
|
-
*/
|
|
1493
|
-
function configureDlt(coreConfig, envVars) {
|
|
1494
|
-
// Create centralized DLT configuration for IOTA if essential IOTA variables are set
|
|
1495
|
-
if (core.Is.stringValue(envVars.iotaNodeEndpoint) && core.Is.stringValue(envVars.iotaNetwork)) {
|
|
1496
|
-
coreConfig.types.dltConfig ??= [];
|
|
1497
|
-
const gasStationConfig = core.Is.stringValue(envVars.iotaGasStationEndpoint) &&
|
|
1498
|
-
core.Is.stringValue(envVars.iotaGasStationAuthToken)
|
|
1499
|
-
? {
|
|
1500
|
-
gasStationUrl: envVars.iotaGasStationEndpoint,
|
|
1501
|
-
gasStationAuthToken: envVars.iotaGasStationAuthToken
|
|
1502
|
-
}
|
|
1503
|
-
: undefined;
|
|
1504
|
-
coreConfig.types.dltConfig.push({
|
|
1505
|
-
type: engineTypes.DltConfigType.Iota,
|
|
1506
|
-
isDefault: true,
|
|
1507
|
-
options: {
|
|
1508
|
-
config: {
|
|
1509
|
-
clientOptions: {
|
|
1510
|
-
url: envVars.iotaNodeEndpoint ?? ""
|
|
1511
|
-
},
|
|
1512
|
-
network: envVars.iotaNetwork ?? "",
|
|
1513
|
-
coinType: core.Coerce.number(envVars.iotaCoinType),
|
|
1514
|
-
gasStation: gasStationConfig
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
/**
|
|
1522
|
-
* Handles the configuration of the server.
|
|
1523
|
-
* @param envVars The environment variables for the engine server.
|
|
1524
|
-
* @param coreEngineConfig The core engine config.
|
|
1525
|
-
* @param serverInfo The server information.
|
|
1526
|
-
* @param openApiSpecPath The path to the open api spec.
|
|
1527
|
-
* @param favIconPath The path to the favicon.
|
|
1528
|
-
* @returns The the config for the core and the server.
|
|
1529
|
-
*/
|
|
1530
|
-
function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo, openApiSpecPath, favIconPath) {
|
|
1531
|
-
envVars.authSigningKeyId ??= "auth-signing";
|
|
1532
|
-
const webServerOptions = {
|
|
1533
|
-
port: core.Coerce.number(envVars.port),
|
|
1534
|
-
host: core.Coerce.string(envVars.host),
|
|
1535
|
-
methods: core.Is.stringValue(envVars.httpMethods)
|
|
1536
|
-
? envVars.httpMethods.split(",")
|
|
1537
|
-
: undefined,
|
|
1538
|
-
allowedHeaders: core.Is.stringValue(envVars.httpAllowedHeaders)
|
|
1539
|
-
? envVars.httpAllowedHeaders.split(",")
|
|
1540
|
-
: undefined,
|
|
1541
|
-
exposedHeaders: core.Is.stringValue(envVars.httpExposedHeaders)
|
|
1542
|
-
? envVars.httpExposedHeaders.split(",")
|
|
1543
|
-
: undefined,
|
|
1544
|
-
corsOrigins: core.Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(",") : undefined
|
|
1545
|
-
};
|
|
1546
|
-
const serverConfig = {
|
|
1547
|
-
...coreEngineConfig,
|
|
1548
|
-
web: webServerOptions,
|
|
1549
|
-
types: {
|
|
1550
|
-
...coreEngineConfig.types,
|
|
1551
|
-
informationComponent: [
|
|
1552
|
-
{
|
|
1553
|
-
type: engineServerTypes.InformationComponentType.Service,
|
|
1554
|
-
options: {
|
|
1555
|
-
config: {
|
|
1556
|
-
serverInfo,
|
|
1557
|
-
openApiSpecPath,
|
|
1558
|
-
favIconPath
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
]
|
|
1563
|
-
}
|
|
1564
|
-
};
|
|
1565
|
-
if (core.Is.stringValue(envVars.mimeTypeProcessors)) {
|
|
1566
|
-
const mimeTypeProcessors = envVars.mimeTypeProcessors.split(",");
|
|
1567
|
-
if (core.Is.arrayValue(mimeTypeProcessors)) {
|
|
1568
|
-
serverConfig.types.mimeTypeProcessor ??= [];
|
|
1569
|
-
for (const mimeTypeProcessor of mimeTypeProcessors) {
|
|
1570
|
-
serverConfig.types.mimeTypeProcessor.push({
|
|
1571
|
-
type: mimeTypeProcessor
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
serverConfig.types.restRouteProcessor ??= [];
|
|
1577
|
-
serverConfig.types.socketRouteProcessor ??= [];
|
|
1578
|
-
const disableNodeIdentity = core.Coerce.boolean(envVars.disableNodeIdentity);
|
|
1579
|
-
if (!disableNodeIdentity) {
|
|
1580
|
-
serverConfig.types.restRouteProcessor.push({
|
|
1581
|
-
type: engineServerTypes.RestRouteProcessorType.NodeIdentity
|
|
1582
|
-
});
|
|
1583
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
1584
|
-
type: engineServerTypes.SocketRouteProcessorType.NodeIdentity
|
|
1585
|
-
});
|
|
1586
|
-
}
|
|
1587
|
-
if (!coreEngineConfig.silent) {
|
|
1588
|
-
serverConfig.types.restRouteProcessor.push({
|
|
1589
|
-
type: engineServerTypes.RestRouteProcessorType.Logging,
|
|
1590
|
-
options: {
|
|
1591
|
-
config: {
|
|
1592
|
-
includeBody: coreEngineConfig.debug
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
1596
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
1597
|
-
type: engineServerTypes.SocketRouteProcessorType.Logging,
|
|
1598
|
-
options: {
|
|
1599
|
-
config: {
|
|
1600
|
-
includeBody: coreEngineConfig.debug
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
});
|
|
1604
|
-
}
|
|
1605
|
-
serverConfig.types.restRouteProcessor.push({
|
|
1606
|
-
type: engineServerTypes.RestRouteProcessorType.RestRoute,
|
|
1607
|
-
options: {
|
|
1608
|
-
config: {
|
|
1609
|
-
includeErrorStack: coreEngineConfig.debug
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
});
|
|
1613
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
1614
|
-
type: engineServerTypes.SocketRouteProcessorType.SocketRoute,
|
|
1615
|
-
options: {
|
|
1616
|
-
config: {
|
|
1617
|
-
includeErrorStack: coreEngineConfig.debug
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
});
|
|
1621
|
-
const authAdminProcessorType = envVars.authAdminProcessorType;
|
|
1622
|
-
if (authAdminProcessorType === engineServerTypes.AuthenticationAdminComponentType.EntityStorage) {
|
|
1623
|
-
serverConfig.types.authenticationAdminComponent ??= [];
|
|
1624
|
-
serverConfig.types.authenticationAdminComponent.push({
|
|
1625
|
-
type: engineServerTypes.AuthenticationAdminComponentType.EntityStorage,
|
|
1626
|
-
options: {
|
|
1627
|
-
config: {}
|
|
1628
|
-
}
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
const authProcessorType = envVars.authProcessorType;
|
|
1632
|
-
if (authProcessorType === engineServerTypes.AuthenticationComponentType.EntityStorage) {
|
|
1633
|
-
serverConfig.types.authenticationComponent ??= [];
|
|
1634
|
-
serverConfig.types.authenticationComponent.push({
|
|
1635
|
-
type: engineServerTypes.AuthenticationComponentType.EntityStorage,
|
|
1636
|
-
options: {
|
|
1637
|
-
config: {
|
|
1638
|
-
signingKeyName: envVars.authSigningKeyId
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
serverConfig.types.restRouteProcessor.push({
|
|
1643
|
-
type: engineServerTypes.RestRouteProcessorType.AuthHeader,
|
|
1644
|
-
options: {
|
|
1645
|
-
config: {
|
|
1646
|
-
signingKeyName: envVars.authSigningKeyId
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
1651
|
-
type: engineServerTypes.SocketRouteProcessorType.AuthHeader,
|
|
1652
|
-
options: {
|
|
1653
|
-
config: {
|
|
1654
|
-
signingKeyName: envVars.authSigningKeyId
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
});
|
|
1658
|
-
}
|
|
1659
|
-
engineServer.addDefaultRestPaths(serverConfig);
|
|
1660
|
-
engineServer.addDefaultSocketPaths(serverConfig);
|
|
1661
|
-
return serverConfig;
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1665
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1666
|
-
/* eslint-disable no-console */
|
|
1667
|
-
/**
|
|
1668
|
-
* Start the engine server.
|
|
1669
|
-
* @param nodeOptions Optional run options for the engine server.
|
|
1670
|
-
* @param engineServerConfig The configuration for the engine server.
|
|
1671
|
-
* @param envVars The environment variables.
|
|
1672
|
-
* @returns The engine server.
|
|
1673
|
-
*/
|
|
1674
|
-
async function start(nodeOptions, engineServerConfig, envVars) {
|
|
1675
|
-
const entityStorageConnectorType = envVars.entityStorageConnectorType?.split(",") ?? [];
|
|
1676
|
-
const blobStorageConnectorType = envVars.blobStorageConnectorType?.split(",") ?? [];
|
|
1677
|
-
// If the blob storage or entity storage is configured with file connectors
|
|
1678
|
-
// then we need to make sure the storageFileRoot is set
|
|
1679
|
-
if ((entityStorageConnectorType.includes(engineTypes.EntityStorageConnectorType.File) ||
|
|
1680
|
-
blobStorageConnectorType.includes(engineTypes.BlobStorageConnectorType.File) ||
|
|
1681
|
-
core.Is.empty(nodeOptions?.stateStorage)) &&
|
|
1682
|
-
!core.Is.stringValue(envVars.storageFileRoot)) {
|
|
1683
|
-
throw new core.GeneralError("node", "storageFileRootNotSet", {
|
|
1684
|
-
storageFileRoot: `${nodeOptions?.envPrefix ?? ""}_STORAGE_FILE_ROOT`
|
|
1685
|
-
});
|
|
1686
|
-
}
|
|
1687
|
-
// Create the engine instance using file state storage unless one is configured in options
|
|
1688
|
-
const engine$1 = new engine.Engine({
|
|
1689
|
-
config: engineServerConfig,
|
|
1690
|
-
stateStorage: nodeOptions?.stateStorage ?? new engineCore.FileStateStorage(envVars.stateFilename ?? ""),
|
|
1691
|
-
customBootstrap: async (core, engineContext) => bootstrap(core, engineContext, envVars)
|
|
1692
|
-
});
|
|
1693
|
-
// Extend the engine.
|
|
1694
|
-
if (core.Is.function(nodeOptions?.extendEngine)) {
|
|
1695
|
-
console.info("Extending Engine");
|
|
1696
|
-
await nodeOptions.extendEngine(engine$1);
|
|
1697
|
-
}
|
|
1698
|
-
// Construct the server with the engine.
|
|
1699
|
-
const server = new engineServer.EngineServer({ engineCore: engine$1 });
|
|
1700
|
-
// Extend the engine server.
|
|
1701
|
-
if (core.Is.function(nodeOptions?.extendEngineServer)) {
|
|
1702
|
-
console.info("Extending Engine Server");
|
|
1703
|
-
await nodeOptions?.extendEngineServer(server);
|
|
1704
|
-
}
|
|
1705
|
-
// Need to register the engine with the factory so that background tasks
|
|
1706
|
-
// can clone it to spawn new instances.
|
|
1707
|
-
engineModels.EngineCoreFactory.register("engine", () => engine$1);
|
|
1708
|
-
// Start the server, which also starts the engine.
|
|
1709
|
-
const canContinue = await server.start();
|
|
1710
|
-
if (canContinue) {
|
|
1711
|
-
return {
|
|
1712
|
-
engine: engine$1,
|
|
1713
|
-
server
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
// Copyright 2024 IOTA Stiftung.
|
|
1719
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
1720
|
-
/* eslint-disable no-console */
|
|
1721
|
-
/**
|
|
1722
|
-
* Run the TWIN Node server.
|
|
1723
|
-
* @param nodeOptions Optional configuration options for running the server.
|
|
1724
|
-
* @returns A promise that resolves when the server is started.
|
|
1725
|
-
*/
|
|
1726
|
-
async function run(nodeOptions) {
|
|
1727
|
-
try {
|
|
1728
|
-
nodeOptions ??= {};
|
|
1729
|
-
const serverInfo = {
|
|
1730
|
-
name: nodeOptions?.serverName ?? "TWIN Node Server",
|
|
1731
|
-
version: nodeOptions?.serverVersion ?? "0.0.2-next.9" // x-release-please-version
|
|
1732
|
-
};
|
|
1733
|
-
console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
|
|
1734
|
-
if (!core.Is.stringValue(nodeOptions?.executionDirectory)) {
|
|
1735
|
-
nodeOptions.executionDirectory = getExecutionDirectory();
|
|
1736
|
-
}
|
|
1737
|
-
console.info("Execution Directory:", nodeOptions.executionDirectory);
|
|
1738
|
-
nodeOptions.localesDirectory =
|
|
1739
|
-
nodeOptions?.localesDirectory ??
|
|
1740
|
-
path.resolve(path.join(nodeOptions.executionDirectory, "dist", "locales"));
|
|
1741
|
-
console.info("Locales Directory:", nodeOptions.localesDirectory);
|
|
1742
|
-
await initialiseLocales(nodeOptions.localesDirectory);
|
|
1743
|
-
if (core.Is.empty(nodeOptions?.openApiSpecFile)) {
|
|
1744
|
-
const specFile = path.resolve(path.join(nodeOptions.executionDirectory ?? "", "docs", "open-api", "spec.json"));
|
|
1745
|
-
console.info("Default OpenAPI Spec File:", specFile);
|
|
1746
|
-
if (await fileExists(specFile)) {
|
|
1747
|
-
nodeOptions ??= {};
|
|
1748
|
-
nodeOptions.openApiSpecFile = specFile;
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
if (core.Is.empty(nodeOptions?.favIconFile)) {
|
|
1752
|
-
const favIconFile = path.resolve(path.join(nodeOptions.executionDirectory ?? "", "static", "favicon.png"));
|
|
1753
|
-
console.info("Default Favicon File:", favIconFile);
|
|
1754
|
-
if (await fileExists(favIconFile)) {
|
|
1755
|
-
nodeOptions ??= {};
|
|
1756
|
-
nodeOptions.favIconFile = favIconFile;
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
nodeOptions.envPrefix ??= "TWIN_NODE_";
|
|
1760
|
-
console.info("Environment Prefix:", nodeOptions.envPrefix);
|
|
1761
|
-
overrideModuleImport(nodeOptions.executionDirectory ?? "");
|
|
1762
|
-
const { engineServerConfig, nodeEnvVars: envVars } = await buildConfiguration(process.env, nodeOptions, serverInfo);
|
|
1763
|
-
console.info();
|
|
1764
|
-
const startResult = await start(nodeOptions, engineServerConfig, envVars);
|
|
1765
|
-
if (!core.Is.empty(startResult)) {
|
|
1766
|
-
for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
|
|
1767
|
-
process.on(signal, async () => {
|
|
1768
|
-
await startResult.server.stop();
|
|
1769
|
-
});
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
catch (err) {
|
|
1774
|
-
console.error(core.ErrorHelper.formatErrors(err).join("\n"));
|
|
1775
|
-
// eslint-disable-next-line unicorn/no-process-exit
|
|
1776
|
-
process.exit(1);
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Build the configuration for the TWIN Node server.
|
|
1781
|
-
* @param processEnv The environment variables from the process.
|
|
1782
|
-
* @param options The options for running the server.
|
|
1783
|
-
* @param serverInfo The server information.
|
|
1784
|
-
* @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,
|
|
1785
|
-
* and options.
|
|
1786
|
-
*/
|
|
1787
|
-
async function buildConfiguration(processEnv, options, serverInfo) {
|
|
1788
|
-
let defaultEnvOnly = false;
|
|
1789
|
-
if (core.Is.empty(options?.envFilenames)) {
|
|
1790
|
-
const envFile = path.resolve(path.join(options.executionDirectory ?? "", ".env"));
|
|
1791
|
-
console.info("Default Environment File:", envFile);
|
|
1792
|
-
options ??= {};
|
|
1793
|
-
options.envFilenames = [envFile];
|
|
1794
|
-
defaultEnvOnly = true;
|
|
1795
|
-
}
|
|
1796
|
-
if (core.Is.arrayValue(options?.envFilenames)) {
|
|
1797
|
-
const output = dotenv__namespace.config({
|
|
1798
|
-
path: options?.envFilenames,
|
|
1799
|
-
quiet: true
|
|
1800
|
-
});
|
|
1801
|
-
// We don't want to throw an error if the default environment file is not found.
|
|
1802
|
-
// Only if we have custom environment files.
|
|
1803
|
-
if (!defaultEnvOnly && output.error) {
|
|
1804
|
-
throw output.error;
|
|
1805
|
-
}
|
|
1806
|
-
if (core.Is.objectValue(output.parsed)) {
|
|
1807
|
-
Object.assign(processEnv, output.parsed);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
const envVars = core.EnvHelper.envToJson(processEnv, options.envPrefix ?? "");
|
|
1811
|
-
// Expand any environment variables that use the @file: syntax
|
|
1812
|
-
const keys = Object.keys(envVars);
|
|
1813
|
-
for (const key of keys) {
|
|
1814
|
-
if (core.Is.stringValue(envVars[key]) &&
|
|
1815
|
-
(envVars[key].startsWith("@text:") || envVars[key].startsWith("@json:"))) {
|
|
1816
|
-
const filePath = envVars[key].slice(6).trim();
|
|
1817
|
-
const embeddedFile = path.resolve(path.join(options.executionDirectory ?? "", filePath));
|
|
1818
|
-
if (envVars[key].startsWith("@text:")) {
|
|
1819
|
-
console.info(`Expanding Environment Variable: ${key} from text file: ${embeddedFile}`);
|
|
1820
|
-
envVars[key] = await loadTextFile(embeddedFile);
|
|
1821
|
-
}
|
|
1822
|
-
else if (envVars[key].startsWith("@json:")) {
|
|
1823
|
-
console.info(`Expanding Environment Variable: ${key} from JSON file: ${embeddedFile}`);
|
|
1824
|
-
envVars[key] = await loadJsonFile(embeddedFile);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
// Extend the environment variables with any additional custom configuration.
|
|
1829
|
-
if (core.Is.function(options?.extendEnvVars)) {
|
|
1830
|
-
console.info("Extending Environment Variables");
|
|
1831
|
-
await options.extendEnvVars(envVars);
|
|
1832
|
-
}
|
|
1833
|
-
// Build the engine configuration from the environment variables.
|
|
1834
|
-
const coreConfig = buildEngineConfiguration(envVars);
|
|
1835
|
-
const engineServerConfig = buildEngineServerConfiguration(envVars, coreConfig, serverInfo, options?.openApiSpecFile, options?.favIconFile);
|
|
1836
|
-
// Merge any custom configuration provided in the options.
|
|
1837
|
-
if (core.Is.arrayValue(options?.configFilenames)) {
|
|
1838
|
-
for (const configFile of options.configFilenames) {
|
|
1839
|
-
console.info("Loading Configuration File:", configFile);
|
|
1840
|
-
const configFilePath = path.resolve(path.join(options.executionDirectory ?? "", configFile));
|
|
1841
|
-
const config = await loadJsonFile(configFilePath);
|
|
1842
|
-
Object.assign(engineServerConfig, config);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
if (core.Is.objectValue(options?.config)) {
|
|
1846
|
-
console.info("Merging Custom Configuration");
|
|
1847
|
-
Object.assign(engineServerConfig, options.config);
|
|
1848
|
-
}
|
|
1849
|
-
// Merge any custom configuration provided in the options.
|
|
1850
|
-
if (core.Is.function(options?.extendConfig)) {
|
|
1851
|
-
console.info("Extending Configuration");
|
|
1852
|
-
await options.extendConfig(engineServerConfig);
|
|
1853
|
-
}
|
|
1854
|
-
return { engineServerConfig, nodeEnvVars: envVars };
|
|
1855
|
-
}
|
|
1856
|
-
/**
|
|
1857
|
-
* Override module imports to use local files where possible.
|
|
1858
|
-
* @param executionDirectory The execution directory for resolving local module paths.
|
|
1859
|
-
*/
|
|
1860
|
-
function overrideModuleImport(executionDirectory) {
|
|
1861
|
-
modules.ModuleHelper.overrideImport(async (moduleName) => {
|
|
1862
|
-
// If the module path for example when dynamically loading
|
|
1863
|
-
// modules looks like a local file then we try to resolve
|
|
1864
|
-
// using the local file system
|
|
1865
|
-
const isLocal = modules.ModuleHelper.isLocalModule(moduleName);
|
|
1866
|
-
if (isLocal) {
|
|
1867
|
-
// See if we can just resolve the filename locally
|
|
1868
|
-
let localFilename = path.resolve(moduleName);
|
|
1869
|
-
let exists = await fileExists(localFilename);
|
|
1870
|
-
if (!exists) {
|
|
1871
|
-
// Doesn't exist in the current directory, try the execution directory
|
|
1872
|
-
localFilename = path.resolve(executionDirectory, moduleName);
|
|
1873
|
-
exists = await fileExists(localFilename);
|
|
1874
|
-
}
|
|
1875
|
-
if (exists) {
|
|
1876
|
-
// If the module exists then we can load it, otherwise
|
|
1877
|
-
// we fallback to regular handling to see if that can import it
|
|
1878
|
-
return {
|
|
1879
|
-
module: await import(process.platform === "win32" ? `file://${localFilename}` : localFilename),
|
|
1880
|
-
useDefault: false
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
// The filename doesn't look like a local module, so just use default handling
|
|
1885
|
-
return {
|
|
1886
|
-
useDefault: true
|
|
1887
|
-
};
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
exports.NodeFeatures = NodeFeatures;
|
|
1892
|
-
exports.bootstrap = bootstrap;
|
|
1893
|
-
exports.bootstrapAuth = bootstrapAuth;
|
|
1894
|
-
exports.bootstrapBlobEncryption = bootstrapBlobEncryption;
|
|
1895
|
-
exports.bootstrapImmutableProofMethod = bootstrapImmutableProofMethod;
|
|
1896
|
-
exports.bootstrapNodeIdentity = bootstrapNodeIdentity;
|
|
1897
|
-
exports.bootstrapNodeUser = bootstrapNodeUser;
|
|
1898
|
-
exports.bootstrapSynchronisedStorage = bootstrapSynchronisedStorage;
|
|
1899
|
-
exports.buildConfiguration = buildConfiguration;
|
|
1900
|
-
exports.buildEngineConfiguration = buildEngineConfiguration;
|
|
1901
|
-
exports.buildEngineServerConfiguration = buildEngineServerConfiguration;
|
|
1902
|
-
exports.fileExists = fileExists;
|
|
1903
|
-
exports.getExecutionDirectory = getExecutionDirectory;
|
|
1904
|
-
exports.getFeatures = getFeatures;
|
|
1905
|
-
exports.initialiseLocales = initialiseLocales;
|
|
1906
|
-
exports.loadJsonFile = loadJsonFile;
|
|
1907
|
-
exports.loadTextFile = loadTextFile;
|
|
1908
|
-
exports.overrideModuleImport = overrideModuleImport;
|
|
1909
|
-
exports.run = run;
|
|
1910
|
-
exports.start = start;
|