@twin.org/engine-server 0.0.1-next.13 → 0.0.1-next.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +108 -354
- package/dist/esm/index.mjs +98 -344
- package/dist/types/engineServer.d.ts +10 -13
- package/dist/types/utils/engineServerEnvBuilder.d.ts +2 -1
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/EngineServer.md +22 -22
- package/package.json +6 -66
- package/dist/types/components/authentication.d.ts +0 -11
- package/dist/types/components/information.d.ts +0 -11
- package/dist/types/components/mimeTypeProcessor.d.ts +0 -11
- package/dist/types/components/restRouteProcessor.d.ts +0 -11
- package/dist/types/components/socketRouteProcessor.d.ts +0 -11
package/dist/esm/index.mjs
CHANGED
|
@@ -1,261 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MimeTypeProcessorFactory, RestRouteProcessorFactory, SocketRouteProcessorFactory } from '@twin.org/api-models';
|
|
1
|
+
import { RestRouteProcessorFactory, SocketRouteProcessorFactory, MimeTypeProcessorFactory } from '@twin.org/api-models';
|
|
3
2
|
import { FastifyWebServer } from '@twin.org/api-server-fastify';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { generateRestRoutesAuditableItemStream } from '@twin.org/auditable-item-stream-service';
|
|
8
|
-
import { generateRestRoutesBlobStorage } from '@twin.org/blob-storage-service';
|
|
9
|
-
import { I18n, GeneralError, ComponentFactory, Guards, Is, Coerce } from '@twin.org/core';
|
|
10
|
-
import { AuthenticationComponentType, InformationComponentType, MimeTypeProcessorType, RestRouteProcessorType, SocketRouteProcessorType } from '@twin.org/engine-models';
|
|
11
|
-
import { generateRestRoutesEntityStorage } from '@twin.org/entity-storage-service';
|
|
12
|
-
import { generateRestRoutesIdentity, generateRestRoutesIdentityProfile } from '@twin.org/identity-service';
|
|
13
|
-
import { generateRestRoutesLogging } from '@twin.org/logging-service';
|
|
14
|
-
import { generateRestRoutesNft } from '@twin.org/nft-service';
|
|
15
|
-
import { generateRestRoutesTelemetry } from '@twin.org/telemetry-service';
|
|
16
|
-
import { initialiseEntityStorageConnector } from '@twin.org/engine-core';
|
|
17
|
-
import { JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, StaticUserIdentityProcessor, RestRouteProcessor, SocketRouteProcessor } from '@twin.org/api-processors';
|
|
3
|
+
import { Guards, Is, Coerce } from '@twin.org/core';
|
|
4
|
+
import { RestRouteProcessorType, InformationComponentType, SocketRouteProcessorType, AuthenticationComponentType } from '@twin.org/engine-server-types';
|
|
5
|
+
import { ModuleHelper } from '@twin.org/modules';
|
|
18
6
|
|
|
19
|
-
/**
|
|
20
|
-
* Initialise the authentication.
|
|
21
|
-
* @param engineCore The engine core.
|
|
22
|
-
* @param context The context for the engine.
|
|
23
|
-
* @param instanceConfig The instance config.
|
|
24
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
25
|
-
* @returns The name of the instance created.
|
|
26
|
-
* @throws GeneralError if the component type is unknown.
|
|
27
|
-
*/
|
|
28
|
-
function initialiseAuthenticationComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
29
|
-
engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
|
|
30
|
-
element: `Authentication Component: ${instanceConfig.type}`
|
|
31
|
-
}));
|
|
32
|
-
const type = instanceConfig.type;
|
|
33
|
-
let component;
|
|
34
|
-
let instanceType;
|
|
35
|
-
if (type === AuthenticationComponentType.EntityStorage) {
|
|
36
|
-
initSchema();
|
|
37
|
-
initialiseEntityStorageConnector(engineCore, context, instanceConfig.options?.userEntityStorageType, "AuthenticationUser");
|
|
38
|
-
component = new EntityStorageAuthenticationService({
|
|
39
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
40
|
-
...instanceConfig.options
|
|
41
|
-
});
|
|
42
|
-
instanceType = EntityStorageAuthenticationService.NAMESPACE;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw new GeneralError("engineCore", "componentUnknownType", {
|
|
46
|
-
type,
|
|
47
|
-
componentType: "authenticationComponent"
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
51
|
-
context.componentInstances.push({
|
|
52
|
-
instanceType: finalInstanceType,
|
|
53
|
-
component
|
|
54
|
-
});
|
|
55
|
-
ComponentFactory.register(finalInstanceType, () => component);
|
|
56
|
-
return finalInstanceType;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Initialise the information component.
|
|
61
|
-
* @param engineCore The engine core.
|
|
62
|
-
* @param context The context for the engine.
|
|
63
|
-
* @param instanceConfig The instance config.
|
|
64
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
65
|
-
* @returns The name of the instance created.
|
|
66
|
-
* @throws GeneralError if the component type is unknown.
|
|
67
|
-
*/
|
|
68
|
-
function initialiseInformationComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
69
|
-
engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
|
|
70
|
-
element: `Information Component: ${instanceConfig.type}`
|
|
71
|
-
}));
|
|
72
|
-
const type = instanceConfig.type;
|
|
73
|
-
let component;
|
|
74
|
-
let instanceType;
|
|
75
|
-
if (type === InformationComponentType.Service) {
|
|
76
|
-
component = new InformationService(instanceConfig.options);
|
|
77
|
-
instanceType = InformationService.NAMESPACE;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
throw new GeneralError("engineCore", "componentUnknownType", {
|
|
81
|
-
type,
|
|
82
|
-
componentType: "informationComponent"
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
86
|
-
context.componentInstances.push({
|
|
87
|
-
instanceType: finalInstanceType,
|
|
88
|
-
component
|
|
89
|
-
});
|
|
90
|
-
ComponentFactory.register(finalInstanceType, () => component);
|
|
91
|
-
return finalInstanceType;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Copyright 2024 IOTA Stiftung.
|
|
95
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
96
|
-
/**
|
|
97
|
-
* Initialise the mime type processor.
|
|
98
|
-
* @param engineCore The engine core.
|
|
99
|
-
* @param context The context for the engine.
|
|
100
|
-
* @param instanceConfig The instance config.
|
|
101
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
102
|
-
* @returns The name of the instance created.
|
|
103
|
-
* @throws GeneralError if the component type is unknown.
|
|
104
|
-
*/
|
|
105
|
-
function initialiseMimeTypeProcessorComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
106
|
-
engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
|
|
107
|
-
element: `Mime Type Processor: ${instanceConfig.type}`
|
|
108
|
-
}));
|
|
109
|
-
const type = instanceConfig.type;
|
|
110
|
-
let component;
|
|
111
|
-
let instanceType;
|
|
112
|
-
if (type === MimeTypeProcessorType.Jwt) {
|
|
113
|
-
component = new JwtMimeTypeProcessor();
|
|
114
|
-
instanceType = JwtMimeTypeProcessor.NAMESPACE;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
throw new GeneralError("engineCore", "componentUnknownType", {
|
|
118
|
-
type,
|
|
119
|
-
componentType: "mimeTypeProcessorComponent"
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
123
|
-
context.componentInstances.push({
|
|
124
|
-
instanceType: finalInstanceType,
|
|
125
|
-
component
|
|
126
|
-
});
|
|
127
|
-
MimeTypeProcessorFactory.register(finalInstanceType, () => component);
|
|
128
|
-
return finalInstanceType;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Copyright 2024 IOTA Stiftung.
|
|
132
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
133
|
-
/**
|
|
134
|
-
* Initialise the rest route processor.
|
|
135
|
-
* @param engineCore The engine core.
|
|
136
|
-
* @param context The context for the engine.
|
|
137
|
-
* @param instanceConfig The instance config.
|
|
138
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
139
|
-
* @returns The name of the instance created.
|
|
140
|
-
* @throws GeneralError if the component type is unknown.
|
|
141
|
-
*/
|
|
142
|
-
function initialiseRestRouteProcessorComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
143
|
-
engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
|
|
144
|
-
element: `REST Route Processor: ${instanceConfig.type}`
|
|
145
|
-
}));
|
|
146
|
-
const type = instanceConfig.type;
|
|
147
|
-
let component;
|
|
148
|
-
let instanceType;
|
|
149
|
-
if (type === RestRouteProcessorType.AuthHeader) {
|
|
150
|
-
component = new AuthHeaderProcessor({
|
|
151
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
152
|
-
config: {
|
|
153
|
-
...instanceConfig.options?.config
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
instanceType = AuthHeaderProcessor.NAMESPACE;
|
|
157
|
-
}
|
|
158
|
-
else if (type === RestRouteProcessorType.Logging) {
|
|
159
|
-
component = new LoggingProcessor({
|
|
160
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
161
|
-
config: {
|
|
162
|
-
...instanceConfig.options?.config
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
instanceType = LoggingProcessor.NAMESPACE;
|
|
166
|
-
}
|
|
167
|
-
else if (type === RestRouteProcessorType.NodeIdentity) {
|
|
168
|
-
component = new NodeIdentityProcessor();
|
|
169
|
-
instanceType = NodeIdentityProcessor.NAMESPACE;
|
|
170
|
-
}
|
|
171
|
-
else if (type === RestRouteProcessorType.StaticUserIdentity) {
|
|
172
|
-
component = new StaticUserIdentityProcessor(instanceConfig.options);
|
|
173
|
-
instanceType = StaticUserIdentityProcessor.NAMESPACE;
|
|
174
|
-
}
|
|
175
|
-
else if (type === RestRouteProcessorType.RestRoute) {
|
|
176
|
-
component = new RestRouteProcessor(instanceConfig.options);
|
|
177
|
-
instanceType = RestRouteProcessor.NAMESPACE;
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
throw new GeneralError("engineCore", "componentUnknownType", {
|
|
181
|
-
type,
|
|
182
|
-
componentType: "restRouteProcessorComponent"
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
186
|
-
context.componentInstances.push({
|
|
187
|
-
instanceType: finalInstanceType,
|
|
188
|
-
component
|
|
189
|
-
});
|
|
190
|
-
RestRouteProcessorFactory.register(finalInstanceType, () => component);
|
|
191
|
-
return finalInstanceType;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Copyright 2024 IOTA Stiftung.
|
|
195
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
196
|
-
/**
|
|
197
|
-
* Initialise the socket route processor.
|
|
198
|
-
* @param engineCore The engine core.
|
|
199
|
-
* @param context The context for the engine.
|
|
200
|
-
* @param instanceConfig The instance config.
|
|
201
|
-
* @param overrideInstanceType The instance type to override the default.
|
|
202
|
-
* @returns The name of the instance created.
|
|
203
|
-
* @throws GeneralError if the component type is unknown.
|
|
204
|
-
*/
|
|
205
|
-
function initialiseSocketRouteProcessorComponent(engineCore, context, instanceConfig, overrideInstanceType) {
|
|
206
|
-
engineCore.logInfo(I18n.formatMessage("engineCore.configuring", {
|
|
207
|
-
element: `Socket Route Processor: ${instanceConfig.type}`
|
|
208
|
-
}));
|
|
209
|
-
const type = instanceConfig.type;
|
|
210
|
-
let component;
|
|
211
|
-
let instanceType;
|
|
212
|
-
if (type === SocketRouteProcessorType.AuthHeader) {
|
|
213
|
-
component = new AuthHeaderProcessor({
|
|
214
|
-
vaultConnectorType: context.defaultTypes.vaultConnector,
|
|
215
|
-
config: {
|
|
216
|
-
...instanceConfig.options?.config
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
instanceType = AuthHeaderProcessor.NAMESPACE;
|
|
220
|
-
}
|
|
221
|
-
else if (type === SocketRouteProcessorType.Logging) {
|
|
222
|
-
component = new LoggingProcessor({
|
|
223
|
-
loggingConnectorType: context.defaultTypes.loggingConnector,
|
|
224
|
-
config: {
|
|
225
|
-
...instanceConfig.options?.config
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
instanceType = LoggingProcessor.NAMESPACE;
|
|
229
|
-
}
|
|
230
|
-
else if (type === SocketRouteProcessorType.NodeIdentity) {
|
|
231
|
-
component = new NodeIdentityProcessor();
|
|
232
|
-
instanceType = NodeIdentityProcessor.NAMESPACE;
|
|
233
|
-
}
|
|
234
|
-
else if (type === SocketRouteProcessorType.StaticUserIdentity) {
|
|
235
|
-
component = new StaticUserIdentityProcessor(instanceConfig.options);
|
|
236
|
-
instanceType = StaticUserIdentityProcessor.NAMESPACE;
|
|
237
|
-
}
|
|
238
|
-
else if (type === SocketRouteProcessorType.SocketRoute) {
|
|
239
|
-
component = new SocketRouteProcessor(instanceConfig.options);
|
|
240
|
-
instanceType = SocketRouteProcessor.NAMESPACE;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
throw new GeneralError("engineCore", "componentUnknownType", {
|
|
244
|
-
type,
|
|
245
|
-
componentType: "socketRouteProcessorComponent"
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
const finalInstanceType = overrideInstanceType ?? instanceType;
|
|
249
|
-
context.componentInstances.push({
|
|
250
|
-
instanceType: finalInstanceType,
|
|
251
|
-
component
|
|
252
|
-
});
|
|
253
|
-
SocketRouteProcessorFactory.register(finalInstanceType, () => component);
|
|
254
|
-
return finalInstanceType;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Copyright 2024 IOTA Stiftung.
|
|
258
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
259
7
|
/**
|
|
260
8
|
* Server for the engine.
|
|
261
9
|
*/
|
|
@@ -264,10 +12,6 @@ class EngineServer {
|
|
|
264
12
|
* Runtime name for the class.
|
|
265
13
|
*/
|
|
266
14
|
CLASS_NAME = "EngineServer";
|
|
267
|
-
/**
|
|
268
|
-
* The server config.
|
|
269
|
-
*/
|
|
270
|
-
_config;
|
|
271
15
|
/**
|
|
272
16
|
* The engine.
|
|
273
17
|
* @internal
|
|
@@ -296,21 +40,19 @@ class EngineServer {
|
|
|
296
40
|
/**
|
|
297
41
|
* Create a new instance of EngineServer.
|
|
298
42
|
* @param options The options for the engine.
|
|
299
|
-
* @param options.server The server options for the engine.
|
|
300
43
|
* @param options.engineCore The engine core to serve from.
|
|
301
44
|
*/
|
|
302
45
|
constructor(options) {
|
|
303
46
|
Guards.object(this.CLASS_NAME, "options", options);
|
|
304
47
|
Guards.object(this.CLASS_NAME, "options.engineCore", options.engineCore);
|
|
305
|
-
this._config = options?.server ?? {};
|
|
306
48
|
this._engineCore = options.engineCore;
|
|
307
49
|
this._restRouteGenerators = [];
|
|
308
50
|
this._socketRouteGenerators = [];
|
|
309
51
|
const coreConfig = this._engineCore.getConfig();
|
|
310
|
-
if (!Is.arrayValue(
|
|
311
|
-
|
|
52
|
+
if (!Is.arrayValue(coreConfig.types.restRouteProcessor)) {
|
|
53
|
+
coreConfig.types.restRouteProcessor = [];
|
|
312
54
|
if (!coreConfig.silent) {
|
|
313
|
-
|
|
55
|
+
coreConfig.types.restRouteProcessor.push({
|
|
314
56
|
type: RestRouteProcessorType.Logging,
|
|
315
57
|
options: {
|
|
316
58
|
config: {
|
|
@@ -319,7 +61,7 @@ class EngineServer {
|
|
|
319
61
|
}
|
|
320
62
|
});
|
|
321
63
|
}
|
|
322
|
-
|
|
64
|
+
coreConfig.types.restRouteProcessor.push({
|
|
323
65
|
type: RestRouteProcessorType.RestRoute,
|
|
324
66
|
options: {
|
|
325
67
|
config: {
|
|
@@ -336,14 +78,16 @@ class EngineServer {
|
|
|
336
78
|
* Add a REST route generator.
|
|
337
79
|
* @param type The type to add the generator for.
|
|
338
80
|
* @param typeConfig The type config.
|
|
339
|
-
* @param
|
|
81
|
+
* @param module The module containing the generator.
|
|
82
|
+
* @param method The method to call on the module.
|
|
340
83
|
*/
|
|
341
|
-
addRestRouteGenerator(type, typeConfig,
|
|
84
|
+
addRestRouteGenerator(type, typeConfig, module, method) {
|
|
342
85
|
if (!Is.empty(typeConfig)) {
|
|
343
86
|
this._restRouteGenerators.push({
|
|
344
87
|
type,
|
|
345
88
|
typeConfig,
|
|
346
|
-
|
|
89
|
+
module,
|
|
90
|
+
method
|
|
347
91
|
});
|
|
348
92
|
}
|
|
349
93
|
}
|
|
@@ -351,14 +95,16 @@ class EngineServer {
|
|
|
351
95
|
* Add a socket route generator.
|
|
352
96
|
* @param type The type to add the generator for.
|
|
353
97
|
* @param typeConfig The type config.
|
|
354
|
-
* @param
|
|
98
|
+
* @param module The module containing the generator.
|
|
99
|
+
* @param method The method to call on the module.
|
|
355
100
|
*/
|
|
356
|
-
addSocketRouteGenerator(type, typeConfig,
|
|
101
|
+
addSocketRouteGenerator(type, typeConfig, module, method) {
|
|
357
102
|
if (!Is.empty(typeConfig)) {
|
|
358
103
|
this._socketRouteGenerators.push({
|
|
359
104
|
type,
|
|
360
105
|
typeConfig,
|
|
361
|
-
|
|
106
|
+
module,
|
|
107
|
+
method
|
|
362
108
|
});
|
|
363
109
|
}
|
|
364
110
|
}
|
|
@@ -389,8 +135,8 @@ class EngineServer {
|
|
|
389
135
|
* @internal
|
|
390
136
|
*/
|
|
391
137
|
async startWebServer() {
|
|
392
|
-
const restRoutes = this.buildRestRoutes();
|
|
393
|
-
const socketRoutes = this.buildSocketRoutes();
|
|
138
|
+
const restRoutes = await this.buildRestRoutes();
|
|
139
|
+
const socketRoutes = await this.buildSocketRoutes();
|
|
394
140
|
const restRouteProcessors = RestRouteProcessorFactory.names().map(n => RestRouteProcessorFactory.get(n));
|
|
395
141
|
const socketRouteProcessors = SocketRouteProcessorFactory.names().map(n => SocketRouteProcessorFactory.get(n));
|
|
396
142
|
const mimeTypeProcessors = MimeTypeProcessorFactory.names().map(n => MimeTypeProcessorFactory.get(n));
|
|
@@ -401,7 +147,7 @@ class EngineServer {
|
|
|
401
147
|
loggingConnectorType: this._loggingConnectorType,
|
|
402
148
|
mimeTypeProcessors
|
|
403
149
|
});
|
|
404
|
-
await this._webServer.build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes,
|
|
150
|
+
await this._webServer.build(restRouteProcessors, restRoutes, socketRouteProcessors, socketRoutes, coreConfig.web);
|
|
405
151
|
await this._webServer.start();
|
|
406
152
|
}
|
|
407
153
|
/**
|
|
@@ -409,10 +155,10 @@ class EngineServer {
|
|
|
409
155
|
* @returns The REST routes for the application.
|
|
410
156
|
* @internal
|
|
411
157
|
*/
|
|
412
|
-
buildRestRoutes() {
|
|
158
|
+
async buildRestRoutes() {
|
|
413
159
|
const routes = [];
|
|
414
|
-
for (const { type, typeConfig,
|
|
415
|
-
this.initialiseRestTypeRoute(routes, type, typeConfig,
|
|
160
|
+
for (const { type, typeConfig, module, method } of this._restRouteGenerators) {
|
|
161
|
+
await this.initialiseRestTypeRoute(routes, type, typeConfig, module, method);
|
|
416
162
|
}
|
|
417
163
|
return routes;
|
|
418
164
|
}
|
|
@@ -421,10 +167,10 @@ class EngineServer {
|
|
|
421
167
|
* @returns The socket routes for the application.
|
|
422
168
|
* @internal
|
|
423
169
|
*/
|
|
424
|
-
buildSocketRoutes() {
|
|
170
|
+
async buildSocketRoutes() {
|
|
425
171
|
const routes = [];
|
|
426
|
-
for (const { type, typeConfig,
|
|
427
|
-
this.initialiseSocketTypeRoute(routes, type, typeConfig,
|
|
172
|
+
for (const { type, typeConfig, module, method } of this._socketRouteGenerators) {
|
|
173
|
+
await this.initialiseSocketTypeRoute(routes, type, typeConfig, module, method);
|
|
428
174
|
}
|
|
429
175
|
return routes;
|
|
430
176
|
}
|
|
@@ -436,9 +182,10 @@ class EngineServer {
|
|
|
436
182
|
* @param generateRoutes The function to generate the routes.
|
|
437
183
|
* @internal
|
|
438
184
|
*/
|
|
439
|
-
initialiseRestTypeRoute(routes, typeKey, typeConfig,
|
|
185
|
+
async initialiseRestTypeRoute(routes, typeKey, typeConfig, module, method) {
|
|
440
186
|
if (Is.arrayValue(typeConfig)) {
|
|
441
187
|
const defaultEngineTypes = this._engineCore.getDefaultTypes();
|
|
188
|
+
const generateRoutes = await ModuleHelper.getModuleEntry(module, method);
|
|
442
189
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
443
190
|
const restPath = typeConfig[i].restPath;
|
|
444
191
|
if (Is.string(restPath)) {
|
|
@@ -455,12 +202,14 @@ class EngineServer {
|
|
|
455
202
|
* @param routes The routes to add to.
|
|
456
203
|
* @param typeKey The key for the default types.
|
|
457
204
|
* @param typeConfig The type config.
|
|
458
|
-
* @param
|
|
205
|
+
* @param module The module containing the generator.
|
|
206
|
+
* @param method The method to call on the module.
|
|
459
207
|
* @internal
|
|
460
208
|
*/
|
|
461
|
-
initialiseSocketTypeRoute(routes, typeKey, typeConfig,
|
|
209
|
+
async initialiseSocketTypeRoute(routes, typeKey, typeConfig, module, method) {
|
|
462
210
|
if (Is.arrayValue(typeConfig)) {
|
|
463
211
|
const defaultEngineTypes = this._engineCore.getDefaultTypes();
|
|
212
|
+
const generateRoutes = await ModuleHelper.getModuleEntry(module, method);
|
|
464
213
|
for (let i = 0; i < typeConfig.length; i++) {
|
|
465
214
|
const socketPath = typeConfig[i].socketPath;
|
|
466
215
|
if (Is.string(socketPath)) {
|
|
@@ -477,30 +226,31 @@ class EngineServer {
|
|
|
477
226
|
* @internal
|
|
478
227
|
*/
|
|
479
228
|
addServerTypeInitialisers() {
|
|
480
|
-
this._engineCore.
|
|
481
|
-
this._engineCore.addTypeInitialiser("
|
|
482
|
-
this._engineCore.addTypeInitialiser("
|
|
483
|
-
this._engineCore.addTypeInitialiser("
|
|
484
|
-
this._engineCore.addTypeInitialiser("
|
|
229
|
+
const coreConfig = this._engineCore.getConfig();
|
|
230
|
+
this._engineCore.addTypeInitialiser("authenticationComponent", coreConfig.types.authenticationComponent, "@twin.org/engine-server-types", "initialiseAuthenticationComponent");
|
|
231
|
+
this._engineCore.addTypeInitialiser("informationComponent", coreConfig.types.informationComponent, "@twin.org/engine-server-types", "initialiseInformationComponent");
|
|
232
|
+
this._engineCore.addTypeInitialiser("restRouteProcessor", coreConfig.types.restRouteProcessor, "@twin.org/engine-server-types", "initialiseRestRouteProcessorComponent");
|
|
233
|
+
this._engineCore.addTypeInitialiser("socketRouteProcessor", coreConfig.types.socketRouteProcessor, "@twin.org/engine-server-types", "initialiseSocketRouteProcessorComponent");
|
|
234
|
+
this._engineCore.addTypeInitialiser("mimeTypeProcessor", coreConfig.types.mimeTypeProcessor, "@twin.org/engine-server-types", "initialiseMimeTypeProcessorComponent");
|
|
485
235
|
}
|
|
486
236
|
/**
|
|
487
237
|
* Add the server REST route generators.
|
|
488
238
|
* @internal
|
|
489
239
|
*/
|
|
490
240
|
addServerRestRouteGenerators() {
|
|
491
|
-
this.addRestRouteGenerator("informationComponent", this._config.informationComponent, generateRestRoutesInformation);
|
|
492
|
-
this.addRestRouteGenerator("authenticationComponent", this._config.authenticationComponent, generateRestRoutesAuthentication);
|
|
493
241
|
const coreConfig = this._engineCore.getConfig();
|
|
494
|
-
this.addRestRouteGenerator("
|
|
495
|
-
this.addRestRouteGenerator("
|
|
496
|
-
this.addRestRouteGenerator("
|
|
497
|
-
this.addRestRouteGenerator("
|
|
498
|
-
this.addRestRouteGenerator("
|
|
499
|
-
this.addRestRouteGenerator("
|
|
500
|
-
this.addRestRouteGenerator("
|
|
501
|
-
this.addRestRouteGenerator("
|
|
502
|
-
this.addRestRouteGenerator("
|
|
503
|
-
this.addRestRouteGenerator("
|
|
242
|
+
this.addRestRouteGenerator("informationComponent", coreConfig.types.informationComponent, "@twin.org/api-service", "generateRestRoutesInformation");
|
|
243
|
+
this.addRestRouteGenerator("authenticationComponent", coreConfig.types.authenticationComponent, "@twin.org/api-auth-entity-storage-service", "generateRestRoutesAuthentication");
|
|
244
|
+
this.addRestRouteGenerator("loggingComponent", coreConfig.types.loggingComponent, "@twin.org/logging-service", "generateRestRoutesLogging");
|
|
245
|
+
this.addRestRouteGenerator("telemetryComponent", coreConfig.types.telemetryComponent, "@twin.org/telemetry-service", "generateRestRoutesTelemetry");
|
|
246
|
+
this.addRestRouteGenerator("blobStorageComponent", coreConfig.types.blobStorageComponent, "@twin.org/blob-storage-service", "generateRestRoutesBlobStorage");
|
|
247
|
+
this.addRestRouteGenerator("identityComponent", coreConfig.types.identityComponent, "@twin.org/identity-service", "generateRestRoutesIdentity");
|
|
248
|
+
this.addRestRouteGenerator("identityProfileComponent", coreConfig.types.identityProfileComponent, "@twin.org/identity-service", "generateRestRoutesIdentityProfile");
|
|
249
|
+
this.addRestRouteGenerator("nftComponent", coreConfig.types.nftComponent, "@twin.org/nft-service", "generateRestRoutesNft");
|
|
250
|
+
this.addRestRouteGenerator("attestationComponent", coreConfig.types.attestationComponent, "@twin.org/attestation-service", "generateRestRoutesAttestation");
|
|
251
|
+
this.addRestRouteGenerator("auditableItemGraphComponent", coreConfig.types.auditableItemGraphComponent, "@twin.org/auditable-item-graph-service", "generateRestRoutesAuditableItemGraph");
|
|
252
|
+
this.addRestRouteGenerator("auditableItemStreamComponent", coreConfig.types.auditableItemStreamComponent, "@twin.org/auditable-item-stream-service", "generateRestRoutesAuditableItemStream");
|
|
253
|
+
this.addRestRouteGenerator("entityStorageComponent", coreConfig.types.entityStorageComponent, "@twin.org/entity-storage-service", "generateRestRoutesEntityStorage");
|
|
504
254
|
}
|
|
505
255
|
/**
|
|
506
256
|
* Add the server socket route generators.
|
|
@@ -538,29 +288,33 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
538
288
|
};
|
|
539
289
|
const authProcessorType = envVars.authProcessorType;
|
|
540
290
|
const serverConfig = {
|
|
291
|
+
...coreEngineConfig,
|
|
541
292
|
web: webServerOptions,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
293
|
+
types: {
|
|
294
|
+
...coreEngineConfig.types,
|
|
295
|
+
informationComponent: [
|
|
296
|
+
{
|
|
297
|
+
type: InformationComponentType.Service,
|
|
298
|
+
options: {
|
|
299
|
+
config: {
|
|
300
|
+
serverInfo
|
|
301
|
+
}
|
|
548
302
|
}
|
|
549
303
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
304
|
+
],
|
|
305
|
+
restRouteProcessor: []
|
|
306
|
+
}
|
|
553
307
|
};
|
|
554
|
-
serverConfig.restRouteProcessor ??= [];
|
|
555
|
-
serverConfig.socketRouteProcessor ??= [];
|
|
556
|
-
serverConfig.restRouteProcessor.push({
|
|
308
|
+
serverConfig.types.restRouteProcessor ??= [];
|
|
309
|
+
serverConfig.types.socketRouteProcessor ??= [];
|
|
310
|
+
serverConfig.types.restRouteProcessor.push({
|
|
557
311
|
type: RestRouteProcessorType.NodeIdentity
|
|
558
312
|
});
|
|
559
|
-
serverConfig.socketRouteProcessor.push({
|
|
313
|
+
serverConfig.types.socketRouteProcessor.push({
|
|
560
314
|
type: SocketRouteProcessorType.NodeIdentity
|
|
561
315
|
});
|
|
562
316
|
if (!coreEngineConfig.silent) {
|
|
563
|
-
serverConfig.restRouteProcessor.push({
|
|
317
|
+
serverConfig.types.restRouteProcessor.push({
|
|
564
318
|
type: RestRouteProcessorType.Logging,
|
|
565
319
|
options: {
|
|
566
320
|
config: {
|
|
@@ -568,7 +322,7 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
568
322
|
}
|
|
569
323
|
}
|
|
570
324
|
});
|
|
571
|
-
serverConfig.socketRouteProcessor.push({
|
|
325
|
+
serverConfig.types.socketRouteProcessor.push({
|
|
572
326
|
type: SocketRouteProcessorType.Logging,
|
|
573
327
|
options: {
|
|
574
328
|
config: {
|
|
@@ -577,7 +331,7 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
577
331
|
}
|
|
578
332
|
});
|
|
579
333
|
}
|
|
580
|
-
serverConfig.restRouteProcessor.push({
|
|
334
|
+
serverConfig.types.restRouteProcessor.push({
|
|
581
335
|
type: RestRouteProcessorType.RestRoute,
|
|
582
336
|
options: {
|
|
583
337
|
config: {
|
|
@@ -585,7 +339,7 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
585
339
|
}
|
|
586
340
|
}
|
|
587
341
|
});
|
|
588
|
-
serverConfig.socketRouteProcessor.push({
|
|
342
|
+
serverConfig.types.socketRouteProcessor.push({
|
|
589
343
|
type: SocketRouteProcessorType.SocketRoute,
|
|
590
344
|
options: {
|
|
591
345
|
config: {
|
|
@@ -594,8 +348,8 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
594
348
|
}
|
|
595
349
|
});
|
|
596
350
|
if (authProcessorType === AuthenticationComponentType.EntityStorage) {
|
|
597
|
-
serverConfig.authenticationComponent ??= [];
|
|
598
|
-
serverConfig.authenticationComponent.push({
|
|
351
|
+
serverConfig.types.authenticationComponent ??= [];
|
|
352
|
+
serverConfig.types.authenticationComponent.push({
|
|
599
353
|
type: AuthenticationComponentType.EntityStorage,
|
|
600
354
|
options: {
|
|
601
355
|
config: {
|
|
@@ -603,7 +357,7 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
603
357
|
}
|
|
604
358
|
}
|
|
605
359
|
});
|
|
606
|
-
serverConfig.restRouteProcessor.push({
|
|
360
|
+
serverConfig.types.restRouteProcessor.push({
|
|
607
361
|
type: RestRouteProcessorType.AuthHeader,
|
|
608
362
|
options: {
|
|
609
363
|
config: {
|
|
@@ -611,7 +365,7 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
611
365
|
}
|
|
612
366
|
}
|
|
613
367
|
});
|
|
614
|
-
serverConfig.socketRouteProcessor.push({
|
|
368
|
+
serverConfig.types.socketRouteProcessor.push({
|
|
615
369
|
type: SocketRouteProcessorType.AuthHeader,
|
|
616
370
|
options: {
|
|
617
371
|
config: {
|
|
@@ -629,38 +383,38 @@ function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo) {
|
|
|
629
383
|
* @param serverConfig The server config.
|
|
630
384
|
*/
|
|
631
385
|
function addRestPaths(coreEngineConfig, serverConfig) {
|
|
632
|
-
if (Is.arrayValue(serverConfig.informationComponent)) {
|
|
633
|
-
serverConfig.informationComponent[0].restPath = "";
|
|
386
|
+
if (Is.arrayValue(serverConfig.types.informationComponent)) {
|
|
387
|
+
serverConfig.types.informationComponent[0].restPath = "";
|
|
634
388
|
}
|
|
635
|
-
if (Is.arrayValue(serverConfig.authenticationComponent)) {
|
|
636
|
-
serverConfig.authenticationComponent[0].restPath = "authentication";
|
|
389
|
+
if (Is.arrayValue(serverConfig.types.authenticationComponent)) {
|
|
390
|
+
serverConfig.types.authenticationComponent[0].restPath = "authentication";
|
|
637
391
|
}
|
|
638
|
-
if (Is.arrayValue(coreEngineConfig.blobStorageComponent)) {
|
|
639
|
-
coreEngineConfig.blobStorageComponent[0].restPath = "blob";
|
|
392
|
+
if (Is.arrayValue(coreEngineConfig.types.blobStorageComponent)) {
|
|
393
|
+
coreEngineConfig.types.blobStorageComponent[0].restPath = "blob";
|
|
640
394
|
}
|
|
641
|
-
if (Is.arrayValue(coreEngineConfig.loggingComponent)) {
|
|
642
|
-
coreEngineConfig.loggingComponent[0].restPath = "logging";
|
|
395
|
+
if (Is.arrayValue(coreEngineConfig.types.loggingComponent)) {
|
|
396
|
+
coreEngineConfig.types.loggingComponent[0].restPath = "logging";
|
|
643
397
|
}
|
|
644
|
-
if (Is.arrayValue(coreEngineConfig.telemetryComponent)) {
|
|
645
|
-
coreEngineConfig.telemetryComponent[0].restPath = "telemetry";
|
|
398
|
+
if (Is.arrayValue(coreEngineConfig.types.telemetryComponent)) {
|
|
399
|
+
coreEngineConfig.types.telemetryComponent[0].restPath = "telemetry";
|
|
646
400
|
}
|
|
647
|
-
if (Is.arrayValue(coreEngineConfig.identityComponent)) {
|
|
648
|
-
coreEngineConfig.identityComponent[0].restPath = "identity";
|
|
401
|
+
if (Is.arrayValue(coreEngineConfig.types.identityComponent)) {
|
|
402
|
+
coreEngineConfig.types.identityComponent[0].restPath = "identity";
|
|
649
403
|
}
|
|
650
|
-
if (Is.arrayValue(coreEngineConfig.identityProfileComponent)) {
|
|
651
|
-
coreEngineConfig.identityProfileComponent[0].restPath = "identity/profile";
|
|
404
|
+
if (Is.arrayValue(coreEngineConfig.types.identityProfileComponent)) {
|
|
405
|
+
coreEngineConfig.types.identityProfileComponent[0].restPath = "identity/profile";
|
|
652
406
|
}
|
|
653
|
-
if (Is.arrayValue(coreEngineConfig.nftComponent)) {
|
|
654
|
-
coreEngineConfig.nftComponent[0].restPath = "nft";
|
|
407
|
+
if (Is.arrayValue(coreEngineConfig.types.nftComponent)) {
|
|
408
|
+
coreEngineConfig.types.nftComponent[0].restPath = "nft";
|
|
655
409
|
}
|
|
656
|
-
if (Is.arrayValue(coreEngineConfig.attestationComponent)) {
|
|
657
|
-
coreEngineConfig.attestationComponent[0].restPath = "attestation";
|
|
410
|
+
if (Is.arrayValue(coreEngineConfig.types.attestationComponent)) {
|
|
411
|
+
coreEngineConfig.types.attestationComponent[0].restPath = "attestation";
|
|
658
412
|
}
|
|
659
|
-
if (Is.arrayValue(coreEngineConfig.auditableItemGraphComponent)) {
|
|
660
|
-
coreEngineConfig.auditableItemGraphComponent[0].restPath = "aig";
|
|
413
|
+
if (Is.arrayValue(coreEngineConfig.types.auditableItemGraphComponent)) {
|
|
414
|
+
coreEngineConfig.types.auditableItemGraphComponent[0].restPath = "aig";
|
|
661
415
|
}
|
|
662
|
-
if (Is.arrayValue(coreEngineConfig.auditableItemStreamComponent)) {
|
|
663
|
-
coreEngineConfig.auditableItemStreamComponent[0].restPath = "ais";
|
|
416
|
+
if (Is.arrayValue(coreEngineConfig.types.auditableItemStreamComponent)) {
|
|
417
|
+
coreEngineConfig.types.auditableItemStreamComponent[0].restPath = "ais";
|
|
664
418
|
}
|
|
665
419
|
}
|
|
666
420
|
|