@twin.org/engine-server 0.0.1-next.83 → 0.0.1-next.84
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 +27 -149
- package/dist/esm/index.mjs +30 -151
- package/dist/types/index.d.ts +1 -2
- package/dist/types/utils/engineServerConfigHelper.d.ts +11 -0
- package/docs/changelog.md +18 -0
- package/docs/reference/index.md +0 -5
- package/package.json +4 -4
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +0 -45
- package/dist/types/utils/engineServerEnvBuilder.d.ts +0 -23
- package/docs/reference/functions/buildEngineServerConfiguration.md +0 -37
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +0 -83
package/dist/cjs/index.cjs
CHANGED
|
@@ -240,7 +240,14 @@ class EngineServer {
|
|
|
240
240
|
if (core.Is.string(restPath)) {
|
|
241
241
|
const serviceType = typeConfig[i].overrideInstanceType ?? defaultEngineTypes[typeKey];
|
|
242
242
|
if (core.Is.stringValue(serviceType)) {
|
|
243
|
-
|
|
243
|
+
const generatedRoutes = generateRoutes(restPath, serviceType);
|
|
244
|
+
for (const route of generatedRoutes) {
|
|
245
|
+
// Don't strip trailing slashes from the root path.
|
|
246
|
+
if (core.Is.stringValue(route.path) && route.path.length > 1) {
|
|
247
|
+
route.path = core.StringHelper.trimTrailingSlashes(route.path);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
routes.push(...generatedRoutes);
|
|
244
251
|
}
|
|
245
252
|
}
|
|
246
253
|
}
|
|
@@ -318,136 +325,8 @@ class EngineServer {
|
|
|
318
325
|
}
|
|
319
326
|
}
|
|
320
327
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
* @param envVars The environment variables.
|
|
324
|
-
* @param coreEngineConfig The core engine config.
|
|
325
|
-
* @param serverInfo The server information.
|
|
326
|
-
* @param openApiSpecPath The path to the open api spec.
|
|
327
|
-
* @returns The the config for the core and the server.
|
|
328
|
-
*/
|
|
329
|
-
function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo, openApiSpecPath) {
|
|
330
|
-
envVars.authSigningKeyId ??= "auth-signing";
|
|
331
|
-
const webServerOptions = {
|
|
332
|
-
port: core.Coerce.number(envVars.port),
|
|
333
|
-
host: core.Coerce.string(envVars.host),
|
|
334
|
-
methods: core.Is.stringValue(envVars.httpMethods)
|
|
335
|
-
? envVars.httpMethods.split(",")
|
|
336
|
-
: undefined,
|
|
337
|
-
allowedHeaders: core.Is.stringValue(envVars.httpAllowedHeaders)
|
|
338
|
-
? envVars.httpAllowedHeaders.split(",")
|
|
339
|
-
: undefined,
|
|
340
|
-
exposedHeaders: core.Is.stringValue(envVars.httpExposedHeaders)
|
|
341
|
-
? envVars.httpExposedHeaders.split(",")
|
|
342
|
-
: undefined,
|
|
343
|
-
corsOrigins: core.Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(",") : undefined
|
|
344
|
-
};
|
|
345
|
-
const authProcessorType = envVars.authProcessorType;
|
|
346
|
-
const serverConfig = {
|
|
347
|
-
...coreEngineConfig,
|
|
348
|
-
web: webServerOptions,
|
|
349
|
-
types: {
|
|
350
|
-
...coreEngineConfig.types,
|
|
351
|
-
informationComponent: [
|
|
352
|
-
{
|
|
353
|
-
type: engineServerTypes.InformationComponentType.Service,
|
|
354
|
-
options: {
|
|
355
|
-
config: {
|
|
356
|
-
serverInfo,
|
|
357
|
-
openApiSpecPath
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
]
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
if (core.Is.stringValue(envVars.mimeTypeProcessors)) {
|
|
365
|
-
const mimeTypeProcessors = envVars.mimeTypeProcessors.split(",");
|
|
366
|
-
if (core.Is.arrayValue(mimeTypeProcessors)) {
|
|
367
|
-
serverConfig.types.mimeTypeProcessor ??= [];
|
|
368
|
-
for (const mimeTypeProcessor of mimeTypeProcessors) {
|
|
369
|
-
serverConfig.types.mimeTypeProcessor.push({
|
|
370
|
-
type: mimeTypeProcessor
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
serverConfig.types.restRouteProcessor ??= [];
|
|
376
|
-
serverConfig.types.socketRouteProcessor ??= [];
|
|
377
|
-
const disableNodeIdentity = core.Coerce.boolean(envVars.disableNodeIdentity);
|
|
378
|
-
if (!disableNodeIdentity) {
|
|
379
|
-
serverConfig.types.restRouteProcessor.push({
|
|
380
|
-
type: engineServerTypes.RestRouteProcessorType.NodeIdentity
|
|
381
|
-
});
|
|
382
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
383
|
-
type: engineServerTypes.SocketRouteProcessorType.NodeIdentity
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
if (!coreEngineConfig.silent) {
|
|
387
|
-
serverConfig.types.restRouteProcessor.push({
|
|
388
|
-
type: engineServerTypes.RestRouteProcessorType.Logging,
|
|
389
|
-
options: {
|
|
390
|
-
config: {
|
|
391
|
-
includeBody: coreEngineConfig.debug
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
396
|
-
type: engineServerTypes.SocketRouteProcessorType.Logging,
|
|
397
|
-
options: {
|
|
398
|
-
config: {
|
|
399
|
-
includeBody: coreEngineConfig.debug
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
serverConfig.types.restRouteProcessor.push({
|
|
405
|
-
type: engineServerTypes.RestRouteProcessorType.RestRoute,
|
|
406
|
-
options: {
|
|
407
|
-
config: {
|
|
408
|
-
includeErrorStack: coreEngineConfig.debug
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
413
|
-
type: engineServerTypes.SocketRouteProcessorType.SocketRoute,
|
|
414
|
-
options: {
|
|
415
|
-
config: {
|
|
416
|
-
includeErrorStack: coreEngineConfig.debug
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
if (authProcessorType === engineServerTypes.AuthenticationComponentType.EntityStorage) {
|
|
421
|
-
serverConfig.types.authenticationComponent ??= [];
|
|
422
|
-
serverConfig.types.authenticationComponent.push({
|
|
423
|
-
type: engineServerTypes.AuthenticationComponentType.EntityStorage,
|
|
424
|
-
options: {
|
|
425
|
-
config: {
|
|
426
|
-
signingKeyName: envVars.authSigningKeyId
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
serverConfig.types.restRouteProcessor.push({
|
|
431
|
-
type: engineServerTypes.RestRouteProcessorType.AuthHeader,
|
|
432
|
-
options: {
|
|
433
|
-
config: {
|
|
434
|
-
signingKeyName: envVars.authSigningKeyId
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
439
|
-
type: engineServerTypes.SocketRouteProcessorType.AuthHeader,
|
|
440
|
-
options: {
|
|
441
|
-
config: {
|
|
442
|
-
signingKeyName: envVars.authSigningKeyId
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
addDefaultRestPaths(serverConfig);
|
|
448
|
-
addDefaultSocketPaths(serverConfig);
|
|
449
|
-
return serverConfig;
|
|
450
|
-
}
|
|
328
|
+
// Copyright 2024 IOTA Stiftung.
|
|
329
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
451
330
|
/**
|
|
452
331
|
* Adds the rest paths to the server config.
|
|
453
332
|
* @param serverConfig The server config.
|
|
@@ -458,71 +337,71 @@ function addDefaultRestPaths(serverConfig) {
|
|
|
458
337
|
}
|
|
459
338
|
if (core.Is.arrayValue(serverConfig.types.authenticationComponent) &&
|
|
460
339
|
!core.Is.stringValue(serverConfig.types.authenticationComponent[0].restPath)) {
|
|
461
|
-
serverConfig.types.authenticationComponent[0].restPath = "authentication";
|
|
340
|
+
serverConfig.types.authenticationComponent[0].restPath = "/authentication";
|
|
462
341
|
}
|
|
463
342
|
if (core.Is.arrayValue(serverConfig.types.blobStorageComponent) &&
|
|
464
343
|
!core.Is.stringValue(serverConfig.types.blobStorageComponent[0].restPath)) {
|
|
465
|
-
serverConfig.types.blobStorageComponent[0].restPath = "blob";
|
|
344
|
+
serverConfig.types.blobStorageComponent[0].restPath = "/blob";
|
|
466
345
|
}
|
|
467
346
|
if (core.Is.arrayValue(serverConfig.types.loggingComponent) &&
|
|
468
347
|
!core.Is.stringValue(serverConfig.types.loggingComponent[0].restPath)) {
|
|
469
|
-
serverConfig.types.loggingComponent[0].restPath = "logging";
|
|
348
|
+
serverConfig.types.loggingComponent[0].restPath = "/logging";
|
|
470
349
|
}
|
|
471
350
|
if (core.Is.arrayValue(serverConfig.types.telemetryComponent) &&
|
|
472
351
|
!core.Is.stringValue(serverConfig.types.telemetryComponent[0].restPath)) {
|
|
473
|
-
serverConfig.types.telemetryComponent[0].restPath = "telemetry";
|
|
352
|
+
serverConfig.types.telemetryComponent[0].restPath = "/telemetry";
|
|
474
353
|
}
|
|
475
354
|
if (core.Is.arrayValue(serverConfig.types.identityComponent) &&
|
|
476
355
|
!core.Is.stringValue(serverConfig.types.identityComponent[0].restPath)) {
|
|
477
|
-
serverConfig.types.identityComponent[0].restPath = "identity";
|
|
356
|
+
serverConfig.types.identityComponent[0].restPath = "/identity";
|
|
478
357
|
}
|
|
479
358
|
if (core.Is.arrayValue(serverConfig.types.identityResolverComponent) &&
|
|
480
359
|
!core.Is.stringValue(serverConfig.types.identityResolverComponent[0].restPath)) {
|
|
481
|
-
serverConfig.types.identityResolverComponent[0].restPath = "identity";
|
|
360
|
+
serverConfig.types.identityResolverComponent[0].restPath = "/identity";
|
|
482
361
|
}
|
|
483
362
|
if (core.Is.arrayValue(serverConfig.types.identityProfileComponent) &&
|
|
484
363
|
!core.Is.stringValue(serverConfig.types.identityProfileComponent[0].restPath)) {
|
|
485
|
-
serverConfig.types.identityProfileComponent[0].restPath = "identity/profile";
|
|
364
|
+
serverConfig.types.identityProfileComponent[0].restPath = "/identity/profile";
|
|
486
365
|
}
|
|
487
366
|
if (core.Is.arrayValue(serverConfig.types.nftComponent) &&
|
|
488
367
|
!core.Is.stringValue(serverConfig.types.nftComponent[0].restPath)) {
|
|
489
|
-
serverConfig.types.nftComponent[0].restPath = "nft";
|
|
368
|
+
serverConfig.types.nftComponent[0].restPath = "/nft";
|
|
490
369
|
}
|
|
491
370
|
if (core.Is.arrayValue(serverConfig.types.verifiableStorageComponent) &&
|
|
492
371
|
!core.Is.stringValue(serverConfig.types.verifiableStorageComponent[0].restPath)) {
|
|
493
|
-
serverConfig.types.verifiableStorageComponent[0].restPath = "verifiable";
|
|
372
|
+
serverConfig.types.verifiableStorageComponent[0].restPath = "/verifiable";
|
|
494
373
|
}
|
|
495
374
|
if (core.Is.arrayValue(serverConfig.types.immutableProofComponent) &&
|
|
496
375
|
!core.Is.stringValue(serverConfig.types.immutableProofComponent[0].restPath)) {
|
|
497
|
-
serverConfig.types.immutableProofComponent[0].restPath = "immutable-proof";
|
|
376
|
+
serverConfig.types.immutableProofComponent[0].restPath = "/immutable-proof";
|
|
498
377
|
}
|
|
499
378
|
if (core.Is.arrayValue(serverConfig.types.attestationComponent) &&
|
|
500
379
|
!core.Is.stringValue(serverConfig.types.attestationComponent[0].restPath)) {
|
|
501
|
-
serverConfig.types.attestationComponent[0].restPath = "attestation";
|
|
380
|
+
serverConfig.types.attestationComponent[0].restPath = "/attestation";
|
|
502
381
|
}
|
|
503
382
|
if (core.Is.arrayValue(serverConfig.types.auditableItemGraphComponent) &&
|
|
504
383
|
!core.Is.stringValue(serverConfig.types.auditableItemGraphComponent[0].restPath)) {
|
|
505
|
-
serverConfig.types.auditableItemGraphComponent[0].restPath = "aig";
|
|
384
|
+
serverConfig.types.auditableItemGraphComponent[0].restPath = "/aig";
|
|
506
385
|
}
|
|
507
386
|
if (core.Is.arrayValue(serverConfig.types.auditableItemStreamComponent) &&
|
|
508
387
|
!core.Is.stringValue(serverConfig.types.auditableItemStreamComponent[0].restPath)) {
|
|
509
|
-
serverConfig.types.auditableItemStreamComponent[0].restPath = "ais";
|
|
388
|
+
serverConfig.types.auditableItemStreamComponent[0].restPath = "/ais";
|
|
510
389
|
}
|
|
511
390
|
if (core.Is.arrayValue(serverConfig.types.dataProcessingComponent) &&
|
|
512
391
|
!core.Is.stringValue(serverConfig.types.dataProcessingComponent[0].restPath)) {
|
|
513
|
-
serverConfig.types.dataProcessingComponent[0].restPath = "data-processing";
|
|
392
|
+
serverConfig.types.dataProcessingComponent[0].restPath = "/data-processing";
|
|
514
393
|
}
|
|
515
394
|
if (core.Is.arrayValue(serverConfig.types.documentManagementComponent) &&
|
|
516
395
|
!core.Is.stringValue(serverConfig.types.documentManagementComponent[0].restPath)) {
|
|
517
|
-
serverConfig.types.documentManagementComponent[0].restPath = "documents";
|
|
396
|
+
serverConfig.types.documentManagementComponent[0].restPath = "/documents";
|
|
518
397
|
}
|
|
519
398
|
if (core.Is.arrayValue(serverConfig.types.federatedCatalogueComponent) &&
|
|
520
399
|
!core.Is.stringValue(serverConfig.types.federatedCatalogueComponent[0].restPath)) {
|
|
521
|
-
serverConfig.types.federatedCatalogueComponent[0].restPath = "federated-catalogue";
|
|
400
|
+
serverConfig.types.federatedCatalogueComponent[0].restPath = "/federated-catalogue";
|
|
522
401
|
}
|
|
523
402
|
if (core.Is.arrayValue(serverConfig.types.rightsManagementComponent) &&
|
|
524
403
|
!core.Is.stringValue(serverConfig.types.rightsManagementComponent[0].restPath)) {
|
|
525
|
-
serverConfig.types.rightsManagementComponent[0].restPath = "rights-management";
|
|
404
|
+
serverConfig.types.rightsManagementComponent[0].restPath = "/rights-management";
|
|
526
405
|
}
|
|
527
406
|
}
|
|
528
407
|
/**
|
|
@@ -539,4 +418,3 @@ function addDefaultSocketPaths(serverConfig) {
|
|
|
539
418
|
exports.EngineServer = EngineServer;
|
|
540
419
|
exports.addDefaultRestPaths = addDefaultRestPaths;
|
|
541
420
|
exports.addDefaultSocketPaths = addDefaultSocketPaths;
|
|
542
|
-
exports.buildEngineServerConfiguration = buildEngineServerConfiguration;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RestRouteProcessorFactory, SocketRouteProcessorFactory, MimeTypeProcessorFactory } from '@twin.org/api-models';
|
|
2
2
|
import { FastifyWebServer } from '@twin.org/api-server-fastify';
|
|
3
|
-
import { Guards, Is,
|
|
4
|
-
import { RestRouteProcessorType, SocketRouteProcessorType
|
|
3
|
+
import { Guards, Is, StringHelper } from '@twin.org/core';
|
|
4
|
+
import { RestRouteProcessorType, SocketRouteProcessorType } from '@twin.org/engine-server-types';
|
|
5
5
|
import { ModuleHelper } from '@twin.org/modules';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -238,7 +238,14 @@ class EngineServer {
|
|
|
238
238
|
if (Is.string(restPath)) {
|
|
239
239
|
const serviceType = typeConfig[i].overrideInstanceType ?? defaultEngineTypes[typeKey];
|
|
240
240
|
if (Is.stringValue(serviceType)) {
|
|
241
|
-
|
|
241
|
+
const generatedRoutes = generateRoutes(restPath, serviceType);
|
|
242
|
+
for (const route of generatedRoutes) {
|
|
243
|
+
// Don't strip trailing slashes from the root path.
|
|
244
|
+
if (Is.stringValue(route.path) && route.path.length > 1) {
|
|
245
|
+
route.path = StringHelper.trimTrailingSlashes(route.path);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
routes.push(...generatedRoutes);
|
|
242
249
|
}
|
|
243
250
|
}
|
|
244
251
|
}
|
|
@@ -316,136 +323,8 @@ class EngineServer {
|
|
|
316
323
|
}
|
|
317
324
|
}
|
|
318
325
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
* @param envVars The environment variables.
|
|
322
|
-
* @param coreEngineConfig The core engine config.
|
|
323
|
-
* @param serverInfo The server information.
|
|
324
|
-
* @param openApiSpecPath The path to the open api spec.
|
|
325
|
-
* @returns The the config for the core and the server.
|
|
326
|
-
*/
|
|
327
|
-
function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo, openApiSpecPath) {
|
|
328
|
-
envVars.authSigningKeyId ??= "auth-signing";
|
|
329
|
-
const webServerOptions = {
|
|
330
|
-
port: Coerce.number(envVars.port),
|
|
331
|
-
host: Coerce.string(envVars.host),
|
|
332
|
-
methods: Is.stringValue(envVars.httpMethods)
|
|
333
|
-
? envVars.httpMethods.split(",")
|
|
334
|
-
: undefined,
|
|
335
|
-
allowedHeaders: Is.stringValue(envVars.httpAllowedHeaders)
|
|
336
|
-
? envVars.httpAllowedHeaders.split(",")
|
|
337
|
-
: undefined,
|
|
338
|
-
exposedHeaders: Is.stringValue(envVars.httpExposedHeaders)
|
|
339
|
-
? envVars.httpExposedHeaders.split(",")
|
|
340
|
-
: undefined,
|
|
341
|
-
corsOrigins: Is.stringValue(envVars.corsOrigins) ? envVars.corsOrigins.split(",") : undefined
|
|
342
|
-
};
|
|
343
|
-
const authProcessorType = envVars.authProcessorType;
|
|
344
|
-
const serverConfig = {
|
|
345
|
-
...coreEngineConfig,
|
|
346
|
-
web: webServerOptions,
|
|
347
|
-
types: {
|
|
348
|
-
...coreEngineConfig.types,
|
|
349
|
-
informationComponent: [
|
|
350
|
-
{
|
|
351
|
-
type: InformationComponentType.Service,
|
|
352
|
-
options: {
|
|
353
|
-
config: {
|
|
354
|
-
serverInfo,
|
|
355
|
-
openApiSpecPath
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
]
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
if (Is.stringValue(envVars.mimeTypeProcessors)) {
|
|
363
|
-
const mimeTypeProcessors = envVars.mimeTypeProcessors.split(",");
|
|
364
|
-
if (Is.arrayValue(mimeTypeProcessors)) {
|
|
365
|
-
serverConfig.types.mimeTypeProcessor ??= [];
|
|
366
|
-
for (const mimeTypeProcessor of mimeTypeProcessors) {
|
|
367
|
-
serverConfig.types.mimeTypeProcessor.push({
|
|
368
|
-
type: mimeTypeProcessor
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
serverConfig.types.restRouteProcessor ??= [];
|
|
374
|
-
serverConfig.types.socketRouteProcessor ??= [];
|
|
375
|
-
const disableNodeIdentity = Coerce.boolean(envVars.disableNodeIdentity);
|
|
376
|
-
if (!disableNodeIdentity) {
|
|
377
|
-
serverConfig.types.restRouteProcessor.push({
|
|
378
|
-
type: RestRouteProcessorType.NodeIdentity
|
|
379
|
-
});
|
|
380
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
381
|
-
type: SocketRouteProcessorType.NodeIdentity
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
if (!coreEngineConfig.silent) {
|
|
385
|
-
serverConfig.types.restRouteProcessor.push({
|
|
386
|
-
type: RestRouteProcessorType.Logging,
|
|
387
|
-
options: {
|
|
388
|
-
config: {
|
|
389
|
-
includeBody: coreEngineConfig.debug
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
394
|
-
type: SocketRouteProcessorType.Logging,
|
|
395
|
-
options: {
|
|
396
|
-
config: {
|
|
397
|
-
includeBody: coreEngineConfig.debug
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
serverConfig.types.restRouteProcessor.push({
|
|
403
|
-
type: RestRouteProcessorType.RestRoute,
|
|
404
|
-
options: {
|
|
405
|
-
config: {
|
|
406
|
-
includeErrorStack: coreEngineConfig.debug
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
411
|
-
type: SocketRouteProcessorType.SocketRoute,
|
|
412
|
-
options: {
|
|
413
|
-
config: {
|
|
414
|
-
includeErrorStack: coreEngineConfig.debug
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
if (authProcessorType === AuthenticationComponentType.EntityStorage) {
|
|
419
|
-
serverConfig.types.authenticationComponent ??= [];
|
|
420
|
-
serverConfig.types.authenticationComponent.push({
|
|
421
|
-
type: AuthenticationComponentType.EntityStorage,
|
|
422
|
-
options: {
|
|
423
|
-
config: {
|
|
424
|
-
signingKeyName: envVars.authSigningKeyId
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
serverConfig.types.restRouteProcessor.push({
|
|
429
|
-
type: RestRouteProcessorType.AuthHeader,
|
|
430
|
-
options: {
|
|
431
|
-
config: {
|
|
432
|
-
signingKeyName: envVars.authSigningKeyId
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
});
|
|
436
|
-
serverConfig.types.socketRouteProcessor.push({
|
|
437
|
-
type: SocketRouteProcessorType.AuthHeader,
|
|
438
|
-
options: {
|
|
439
|
-
config: {
|
|
440
|
-
signingKeyName: envVars.authSigningKeyId
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
addDefaultRestPaths(serverConfig);
|
|
446
|
-
addDefaultSocketPaths(serverConfig);
|
|
447
|
-
return serverConfig;
|
|
448
|
-
}
|
|
326
|
+
// Copyright 2024 IOTA Stiftung.
|
|
327
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
449
328
|
/**
|
|
450
329
|
* Adds the rest paths to the server config.
|
|
451
330
|
* @param serverConfig The server config.
|
|
@@ -456,71 +335,71 @@ function addDefaultRestPaths(serverConfig) {
|
|
|
456
335
|
}
|
|
457
336
|
if (Is.arrayValue(serverConfig.types.authenticationComponent) &&
|
|
458
337
|
!Is.stringValue(serverConfig.types.authenticationComponent[0].restPath)) {
|
|
459
|
-
serverConfig.types.authenticationComponent[0].restPath = "authentication";
|
|
338
|
+
serverConfig.types.authenticationComponent[0].restPath = "/authentication";
|
|
460
339
|
}
|
|
461
340
|
if (Is.arrayValue(serverConfig.types.blobStorageComponent) &&
|
|
462
341
|
!Is.stringValue(serverConfig.types.blobStorageComponent[0].restPath)) {
|
|
463
|
-
serverConfig.types.blobStorageComponent[0].restPath = "blob";
|
|
342
|
+
serverConfig.types.blobStorageComponent[0].restPath = "/blob";
|
|
464
343
|
}
|
|
465
344
|
if (Is.arrayValue(serverConfig.types.loggingComponent) &&
|
|
466
345
|
!Is.stringValue(serverConfig.types.loggingComponent[0].restPath)) {
|
|
467
|
-
serverConfig.types.loggingComponent[0].restPath = "logging";
|
|
346
|
+
serverConfig.types.loggingComponent[0].restPath = "/logging";
|
|
468
347
|
}
|
|
469
348
|
if (Is.arrayValue(serverConfig.types.telemetryComponent) &&
|
|
470
349
|
!Is.stringValue(serverConfig.types.telemetryComponent[0].restPath)) {
|
|
471
|
-
serverConfig.types.telemetryComponent[0].restPath = "telemetry";
|
|
350
|
+
serverConfig.types.telemetryComponent[0].restPath = "/telemetry";
|
|
472
351
|
}
|
|
473
352
|
if (Is.arrayValue(serverConfig.types.identityComponent) &&
|
|
474
353
|
!Is.stringValue(serverConfig.types.identityComponent[0].restPath)) {
|
|
475
|
-
serverConfig.types.identityComponent[0].restPath = "identity";
|
|
354
|
+
serverConfig.types.identityComponent[0].restPath = "/identity";
|
|
476
355
|
}
|
|
477
356
|
if (Is.arrayValue(serverConfig.types.identityResolverComponent) &&
|
|
478
357
|
!Is.stringValue(serverConfig.types.identityResolverComponent[0].restPath)) {
|
|
479
|
-
serverConfig.types.identityResolverComponent[0].restPath = "identity";
|
|
358
|
+
serverConfig.types.identityResolverComponent[0].restPath = "/identity";
|
|
480
359
|
}
|
|
481
360
|
if (Is.arrayValue(serverConfig.types.identityProfileComponent) &&
|
|
482
361
|
!Is.stringValue(serverConfig.types.identityProfileComponent[0].restPath)) {
|
|
483
|
-
serverConfig.types.identityProfileComponent[0].restPath = "identity/profile";
|
|
362
|
+
serverConfig.types.identityProfileComponent[0].restPath = "/identity/profile";
|
|
484
363
|
}
|
|
485
364
|
if (Is.arrayValue(serverConfig.types.nftComponent) &&
|
|
486
365
|
!Is.stringValue(serverConfig.types.nftComponent[0].restPath)) {
|
|
487
|
-
serverConfig.types.nftComponent[0].restPath = "nft";
|
|
366
|
+
serverConfig.types.nftComponent[0].restPath = "/nft";
|
|
488
367
|
}
|
|
489
368
|
if (Is.arrayValue(serverConfig.types.verifiableStorageComponent) &&
|
|
490
369
|
!Is.stringValue(serverConfig.types.verifiableStorageComponent[0].restPath)) {
|
|
491
|
-
serverConfig.types.verifiableStorageComponent[0].restPath = "verifiable";
|
|
370
|
+
serverConfig.types.verifiableStorageComponent[0].restPath = "/verifiable";
|
|
492
371
|
}
|
|
493
372
|
if (Is.arrayValue(serverConfig.types.immutableProofComponent) &&
|
|
494
373
|
!Is.stringValue(serverConfig.types.immutableProofComponent[0].restPath)) {
|
|
495
|
-
serverConfig.types.immutableProofComponent[0].restPath = "immutable-proof";
|
|
374
|
+
serverConfig.types.immutableProofComponent[0].restPath = "/immutable-proof";
|
|
496
375
|
}
|
|
497
376
|
if (Is.arrayValue(serverConfig.types.attestationComponent) &&
|
|
498
377
|
!Is.stringValue(serverConfig.types.attestationComponent[0].restPath)) {
|
|
499
|
-
serverConfig.types.attestationComponent[0].restPath = "attestation";
|
|
378
|
+
serverConfig.types.attestationComponent[0].restPath = "/attestation";
|
|
500
379
|
}
|
|
501
380
|
if (Is.arrayValue(serverConfig.types.auditableItemGraphComponent) &&
|
|
502
381
|
!Is.stringValue(serverConfig.types.auditableItemGraphComponent[0].restPath)) {
|
|
503
|
-
serverConfig.types.auditableItemGraphComponent[0].restPath = "aig";
|
|
382
|
+
serverConfig.types.auditableItemGraphComponent[0].restPath = "/aig";
|
|
504
383
|
}
|
|
505
384
|
if (Is.arrayValue(serverConfig.types.auditableItemStreamComponent) &&
|
|
506
385
|
!Is.stringValue(serverConfig.types.auditableItemStreamComponent[0].restPath)) {
|
|
507
|
-
serverConfig.types.auditableItemStreamComponent[0].restPath = "ais";
|
|
386
|
+
serverConfig.types.auditableItemStreamComponent[0].restPath = "/ais";
|
|
508
387
|
}
|
|
509
388
|
if (Is.arrayValue(serverConfig.types.dataProcessingComponent) &&
|
|
510
389
|
!Is.stringValue(serverConfig.types.dataProcessingComponent[0].restPath)) {
|
|
511
|
-
serverConfig.types.dataProcessingComponent[0].restPath = "data-processing";
|
|
390
|
+
serverConfig.types.dataProcessingComponent[0].restPath = "/data-processing";
|
|
512
391
|
}
|
|
513
392
|
if (Is.arrayValue(serverConfig.types.documentManagementComponent) &&
|
|
514
393
|
!Is.stringValue(serverConfig.types.documentManagementComponent[0].restPath)) {
|
|
515
|
-
serverConfig.types.documentManagementComponent[0].restPath = "documents";
|
|
394
|
+
serverConfig.types.documentManagementComponent[0].restPath = "/documents";
|
|
516
395
|
}
|
|
517
396
|
if (Is.arrayValue(serverConfig.types.federatedCatalogueComponent) &&
|
|
518
397
|
!Is.stringValue(serverConfig.types.federatedCatalogueComponent[0].restPath)) {
|
|
519
|
-
serverConfig.types.federatedCatalogueComponent[0].restPath = "federated-catalogue";
|
|
398
|
+
serverConfig.types.federatedCatalogueComponent[0].restPath = "/federated-catalogue";
|
|
520
399
|
}
|
|
521
400
|
if (Is.arrayValue(serverConfig.types.rightsManagementComponent) &&
|
|
522
401
|
!Is.stringValue(serverConfig.types.rightsManagementComponent[0].restPath)) {
|
|
523
|
-
serverConfig.types.rightsManagementComponent[0].restPath = "rights-management";
|
|
402
|
+
serverConfig.types.rightsManagementComponent[0].restPath = "/rights-management";
|
|
524
403
|
}
|
|
525
404
|
}
|
|
526
405
|
/**
|
|
@@ -534,4 +413,4 @@ function addDefaultSocketPaths(serverConfig) {
|
|
|
534
413
|
}
|
|
535
414
|
}
|
|
536
415
|
|
|
537
|
-
export { EngineServer, addDefaultRestPaths, addDefaultSocketPaths
|
|
416
|
+
export { EngineServer, addDefaultRestPaths, addDefaultSocketPaths };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IEngineServerConfig } from "@twin.org/engine-server-types";
|
|
2
|
+
/**
|
|
3
|
+
* Adds the rest paths to the server config.
|
|
4
|
+
* @param serverConfig The server config.
|
|
5
|
+
*/
|
|
6
|
+
export declare function addDefaultRestPaths(serverConfig: IEngineServerConfig): void;
|
|
7
|
+
/**
|
|
8
|
+
* Adds the socket paths to the server config.
|
|
9
|
+
* @param serverConfig The server config.
|
|
10
|
+
*/
|
|
11
|
+
export declare function addDefaultSocketPaths(serverConfig: IEngineServerConfig): void;
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @twin.org/engine-server - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.1-next.84](https://github.com/twinfoundation/engine/compare/engine-server-v0.0.1-next.83...engine-server-v0.0.1-next.84) (2025-07-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* move environment variable processing to node level ([2223c12](https://github.com/twinfoundation/engine/commit/2223c12f49f3d34051ecec9687351aa5dd094e54))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/engine-core bumped from 0.0.1-next.83 to 0.0.1-next.84
|
|
16
|
+
* @twin.org/engine-models bumped from 0.0.1-next.83 to 0.0.1-next.84
|
|
17
|
+
* @twin.org/engine-server-types bumped from 0.0.1-next.83 to 0.0.1-next.84
|
|
18
|
+
* devDependencies
|
|
19
|
+
* @twin.org/engine bumped from 0.0.1-next.83 to 0.0.1-next.84
|
|
20
|
+
|
|
3
21
|
## [0.0.1-next.83](https://github.com/twinfoundation/engine/compare/engine-server-v0.0.1-next.82...engine-server-v0.0.1-next.83) (2025-07-10)
|
|
4
22
|
|
|
5
23
|
|
package/docs/reference/index.md
CHANGED
|
@@ -4,12 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- [EngineServer](classes/EngineServer.md)
|
|
6
6
|
|
|
7
|
-
## Interfaces
|
|
8
|
-
|
|
9
|
-
- [IEngineServerEnvironmentVariables](interfaces/IEngineServerEnvironmentVariables.md)
|
|
10
|
-
|
|
11
7
|
## Functions
|
|
12
8
|
|
|
13
|
-
- [buildEngineServerConfiguration](functions/buildEngineServerConfiguration.md)
|
|
14
9
|
- [addDefaultRestPaths](functions/addDefaultRestPaths.md)
|
|
15
10
|
- [addDefaultSocketPaths](functions/addDefaultSocketPaths.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/engine-server",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.84",
|
|
4
4
|
"description": "Engine implementation for a server.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"@twin.org/api-models": "next",
|
|
18
18
|
"@twin.org/api-server-fastify": "next",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
|
-
"@twin.org/engine-core": "0.0.1-next.
|
|
21
|
-
"@twin.org/engine-models": "0.0.1-next.
|
|
22
|
-
"@twin.org/engine-server-types": "0.0.1-next.
|
|
20
|
+
"@twin.org/engine-core": "0.0.1-next.84",
|
|
21
|
+
"@twin.org/engine-models": "0.0.1-next.84",
|
|
22
|
+
"@twin.org/engine-server-types": "0.0.1-next.84",
|
|
23
23
|
"@twin.org/modules": "next",
|
|
24
24
|
"@twin.org/nameof": "next"
|
|
25
25
|
},
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The engine server environment variables.
|
|
3
|
-
*/
|
|
4
|
-
export interface IEngineServerEnvironmentVariables {
|
|
5
|
-
/**
|
|
6
|
-
* The port to serve the API from.
|
|
7
|
-
*/
|
|
8
|
-
port?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The host to serve the API from.
|
|
11
|
-
*/
|
|
12
|
-
host?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The CORS origins to allow, defaults to *.
|
|
15
|
-
*/
|
|
16
|
-
corsOrigins?: string;
|
|
17
|
-
/**
|
|
18
|
-
* The CORS methods to allow, defaults to GET, POST, PUT, DELETE, OPTIONS.
|
|
19
|
-
*/
|
|
20
|
-
httpMethods?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The CORS headers to allow.
|
|
23
|
-
*/
|
|
24
|
-
httpAllowedHeaders?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The CORS headers to expose.
|
|
27
|
-
*/
|
|
28
|
-
httpExposedHeaders?: string;
|
|
29
|
-
/**
|
|
30
|
-
* The type of auth processor to use on the API: entity-storage.
|
|
31
|
-
*/
|
|
32
|
-
authProcessorType?: string;
|
|
33
|
-
/**
|
|
34
|
-
* The id of the key in the vault to use for signing in auth operations.
|
|
35
|
-
*/
|
|
36
|
-
authSigningKeyId?: string;
|
|
37
|
-
/**
|
|
38
|
-
* Additional MIME type processors to include, comma separated.
|
|
39
|
-
*/
|
|
40
|
-
mimeTypeProcessors?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Disable Node Identity route processors.
|
|
43
|
-
*/
|
|
44
|
-
disableNodeIdentity?: string;
|
|
45
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { IServerInfo } from "@twin.org/api-models";
|
|
2
|
-
import type { IEngineCoreConfig } from "@twin.org/engine-models";
|
|
3
|
-
import { type IEngineServerConfig } from "@twin.org/engine-server-types";
|
|
4
|
-
import type { IEngineServerEnvironmentVariables } from "../models/IEngineServerEnvironmentVariables";
|
|
5
|
-
/**
|
|
6
|
-
* Handles the configuration of the server.
|
|
7
|
-
* @param envVars The environment variables.
|
|
8
|
-
* @param coreEngineConfig The core engine config.
|
|
9
|
-
* @param serverInfo The server information.
|
|
10
|
-
* @param openApiSpecPath The path to the open api spec.
|
|
11
|
-
* @returns The the config for the core and the server.
|
|
12
|
-
*/
|
|
13
|
-
export declare function buildEngineServerConfiguration(envVars: IEngineServerEnvironmentVariables, coreEngineConfig: IEngineCoreConfig, serverInfo: IServerInfo, openApiSpecPath?: string): IEngineServerConfig;
|
|
14
|
-
/**
|
|
15
|
-
* Adds the rest paths to the server config.
|
|
16
|
-
* @param serverConfig The server config.
|
|
17
|
-
*/
|
|
18
|
-
export declare function addDefaultRestPaths(serverConfig: IEngineServerConfig): void;
|
|
19
|
-
/**
|
|
20
|
-
* Adds the socket paths to the server config.
|
|
21
|
-
* @param serverConfig The server config.
|
|
22
|
-
*/
|
|
23
|
-
export declare function addDefaultSocketPaths(serverConfig: IEngineServerConfig): void;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Function: buildEngineServerConfiguration()
|
|
2
|
-
|
|
3
|
-
> **buildEngineServerConfiguration**(`envVars`, `coreEngineConfig`, `serverInfo`, `openApiSpecPath?`): `IEngineServerConfig`
|
|
4
|
-
|
|
5
|
-
Handles the configuration of the server.
|
|
6
|
-
|
|
7
|
-
## Parameters
|
|
8
|
-
|
|
9
|
-
### envVars
|
|
10
|
-
|
|
11
|
-
[`IEngineServerEnvironmentVariables`](../interfaces/IEngineServerEnvironmentVariables.md)
|
|
12
|
-
|
|
13
|
-
The environment variables.
|
|
14
|
-
|
|
15
|
-
### coreEngineConfig
|
|
16
|
-
|
|
17
|
-
`IEngineCoreConfig`
|
|
18
|
-
|
|
19
|
-
The core engine config.
|
|
20
|
-
|
|
21
|
-
### serverInfo
|
|
22
|
-
|
|
23
|
-
`IServerInfo`
|
|
24
|
-
|
|
25
|
-
The server information.
|
|
26
|
-
|
|
27
|
-
### openApiSpecPath?
|
|
28
|
-
|
|
29
|
-
`string`
|
|
30
|
-
|
|
31
|
-
The path to the open api spec.
|
|
32
|
-
|
|
33
|
-
## Returns
|
|
34
|
-
|
|
35
|
-
`IEngineServerConfig`
|
|
36
|
-
|
|
37
|
-
The the config for the core and the server.
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# Interface: IEngineServerEnvironmentVariables
|
|
2
|
-
|
|
3
|
-
The engine server environment variables.
|
|
4
|
-
|
|
5
|
-
## Properties
|
|
6
|
-
|
|
7
|
-
### port?
|
|
8
|
-
|
|
9
|
-
> `optional` **port**: `string`
|
|
10
|
-
|
|
11
|
-
The port to serve the API from.
|
|
12
|
-
|
|
13
|
-
***
|
|
14
|
-
|
|
15
|
-
### host?
|
|
16
|
-
|
|
17
|
-
> `optional` **host**: `string`
|
|
18
|
-
|
|
19
|
-
The host to serve the API from.
|
|
20
|
-
|
|
21
|
-
***
|
|
22
|
-
|
|
23
|
-
### corsOrigins?
|
|
24
|
-
|
|
25
|
-
> `optional` **corsOrigins**: `string`
|
|
26
|
-
|
|
27
|
-
The CORS origins to allow, defaults to *.
|
|
28
|
-
|
|
29
|
-
***
|
|
30
|
-
|
|
31
|
-
### httpMethods?
|
|
32
|
-
|
|
33
|
-
> `optional` **httpMethods**: `string`
|
|
34
|
-
|
|
35
|
-
The CORS methods to allow, defaults to GET, POST, PUT, DELETE, OPTIONS.
|
|
36
|
-
|
|
37
|
-
***
|
|
38
|
-
|
|
39
|
-
### httpAllowedHeaders?
|
|
40
|
-
|
|
41
|
-
> `optional` **httpAllowedHeaders**: `string`
|
|
42
|
-
|
|
43
|
-
The CORS headers to allow.
|
|
44
|
-
|
|
45
|
-
***
|
|
46
|
-
|
|
47
|
-
### httpExposedHeaders?
|
|
48
|
-
|
|
49
|
-
> `optional` **httpExposedHeaders**: `string`
|
|
50
|
-
|
|
51
|
-
The CORS headers to expose.
|
|
52
|
-
|
|
53
|
-
***
|
|
54
|
-
|
|
55
|
-
### authProcessorType?
|
|
56
|
-
|
|
57
|
-
> `optional` **authProcessorType**: `string`
|
|
58
|
-
|
|
59
|
-
The type of auth processor to use on the API: entity-storage.
|
|
60
|
-
|
|
61
|
-
***
|
|
62
|
-
|
|
63
|
-
### authSigningKeyId?
|
|
64
|
-
|
|
65
|
-
> `optional` **authSigningKeyId**: `string`
|
|
66
|
-
|
|
67
|
-
The id of the key in the vault to use for signing in auth operations.
|
|
68
|
-
|
|
69
|
-
***
|
|
70
|
-
|
|
71
|
-
### mimeTypeProcessors?
|
|
72
|
-
|
|
73
|
-
> `optional` **mimeTypeProcessors**: `string`
|
|
74
|
-
|
|
75
|
-
Additional MIME type processors to include, comma separated.
|
|
76
|
-
|
|
77
|
-
***
|
|
78
|
-
|
|
79
|
-
### disableNodeIdentity?
|
|
80
|
-
|
|
81
|
-
> `optional` **disableNodeIdentity**: `string`
|
|
82
|
-
|
|
83
|
-
Disable Node Identity route processors.
|