@twin.org/engine 0.0.1-next.83 → 0.0.1

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.
@@ -4,7 +4,6 @@ var engineCore = require('@twin.org/engine-core');
4
4
  var core = require('@twin.org/core');
5
5
  var engineTypes = require('@twin.org/engine-types');
6
6
  var entity = require('@twin.org/entity');
7
- var path = require('node:path');
8
7
 
9
8
  // Copyright 2024 IOTA Stiftung.
10
9
  // SPDX-License-Identifier: Apache-2.0.
@@ -109,888 +108,10 @@ class EngineConfigHelper {
109
108
  }
110
109
  },
111
110
  overrideInstanceType: core.StringHelper.kebabCase(entityTypeName),
112
- restPath
113
- });
114
- }
115
- }
116
-
117
- // Copyright 2024 IOTA Stiftung.
118
- // SPDX-License-Identifier: Apache-2.0.
119
- /**
120
- * Build the engine core configuration from environment variables.
121
- * @param envVars The environment variables.
122
- * @returns The config for the core.
123
- */
124
- function buildEngineConfiguration(envVars) {
125
- if (core.Is.stringValue(envVars.storageFileRoot)) {
126
- envVars.stateFilename ??= "engine-state.json";
127
- envVars.storageFileRoot = path.resolve(envVars.storageFileRoot);
128
- envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
129
- }
130
- envVars.attestationVerificationMethodId ??= "attestation-assertion";
131
- envVars.immutableProofVerificationMethodId ??= "immutable-proof-assertion";
132
- envVars.blobStorageEnableEncryption ??= "false";
133
- envVars.blobStorageEncryptionKey ??= "blob-encryption";
134
- const coreConfig = {
135
- debug: core.Coerce.boolean(envVars.debug) ?? false,
136
- types: {}
137
- };
138
- configureEntityStorage(coreConfig, envVars);
139
- configureBlobStorage(coreConfig, envVars);
140
- configureVault(coreConfig, envVars);
141
- configureDlt(coreConfig, envVars);
142
- configureLogging(coreConfig, envVars);
143
- configureBackgroundTask(coreConfig, envVars);
144
- configureEventBus(coreConfig, envVars);
145
- configureTelemetry(coreConfig, envVars);
146
- configureMessaging(coreConfig, envVars);
147
- configureFaucet(coreConfig, envVars);
148
- configureWallet(coreConfig, envVars);
149
- configureNft(coreConfig, envVars);
150
- configureVerifiableStorage(coreConfig, envVars);
151
- configureIdentity(coreConfig, envVars);
152
- configureIdentityResolver(coreConfig, envVars);
153
- configureIdentityProfile(coreConfig, envVars);
154
- configureAttestation(coreConfig, envVars);
155
- configureDataProcessing(coreConfig, envVars);
156
- configureAuditableItemGraph(coreConfig);
157
- configureAuditableItemStream(coreConfig);
158
- configureDocumentManagement(coreConfig);
159
- configureFederatedCatalogue(coreConfig, envVars);
160
- configureRightsManagement(coreConfig, envVars);
161
- configureTaskScheduler(coreConfig, envVars);
162
- return coreConfig;
163
- }
164
- /**
165
- * Helper function to get IOTA configuration from centralized dltConfig.
166
- * @param coreConfig The core config.
167
- * @returns The IOTA configuration if found, undefined otherwise.
168
- */
169
- function getIotaConfig(coreConfig) {
170
- const dltConfig = coreConfig.types.dltConfig?.find(config => config.type === engineTypes.DltConfigType.Iota && config.isDefault);
171
- return dltConfig?.options?.config;
172
- }
173
- /**
174
- * Configures the entity storage.
175
- * @param coreConfig The core config.
176
- * @param envVars The environment variables.
177
- */
178
- function configureEntityStorage(coreConfig, envVars) {
179
- coreConfig.types ??= {};
180
- coreConfig.types.entityStorageConnector ??= [];
181
- if ((core.Coerce.boolean(envVars.entityMemoryEnable) ?? false) ||
182
- envVars.entityStorageConnectorType === engineTypes.EntityStorageConnectorType.Memory) {
183
- coreConfig.types.entityStorageConnector.push({
184
- type: engineTypes.EntityStorageConnectorType.Memory
185
- });
186
- }
187
- if ((core.Coerce.boolean(envVars.entityFileEnable) ?? false) ||
188
- envVars.entityStorageConnectorType === engineTypes.EntityStorageConnectorType.File) {
189
- coreConfig.types.entityStorageConnector.push({
190
- type: engineTypes.EntityStorageConnectorType.File,
191
- options: {
192
- config: { directory: envVars.storageFileRoot ?? "" },
193
- folderPrefix: envVars.entityStorageTablePrefix
194
- }
195
- });
196
- }
197
- if (core.Is.stringValue(envVars.awsDynamodbAccessKeyId)) {
198
- coreConfig.types.entityStorageConnector.push({
199
- type: engineTypes.EntityStorageConnectorType.AwsDynamoDb,
200
- options: {
201
- config: {
202
- region: envVars.awsDynamodbRegion ?? "",
203
- accessKeyId: envVars.awsDynamodbAccessKeyId ?? "",
204
- secretAccessKey: envVars.awsDynamodbSecretAccessKey ?? "",
205
- endpoint: envVars.awsDynamodbEndpoint ?? ""
206
- },
207
- tablePrefix: envVars.entityStorageTablePrefix
208
- }
209
- });
210
- }
211
- if (core.Is.stringValue(envVars.azureCosmosdbKey)) {
212
- coreConfig.types.entityStorageConnector.push({
213
- type: engineTypes.EntityStorageConnectorType.AzureCosmosDb,
214
- options: {
215
- config: {
216
- endpoint: envVars.azureCosmosdbEndpoint ?? "",
217
- key: envVars.azureCosmosdbKey ?? "",
218
- databaseId: envVars.azureCosmosdbDatabaseId ?? "",
219
- containerId: envVars.azureCosmosdbContainerId ?? ""
220
- },
221
- tablePrefix: envVars.entityStorageTablePrefix
222
- }
223
- });
224
- }
225
- if (core.Is.stringValue(envVars.gcpFirestoreCredentials)) {
226
- coreConfig.types.entityStorageConnector.push({
227
- type: engineTypes.EntityStorageConnectorType.GcpFirestoreDb,
228
- options: {
229
- config: {
230
- projectId: envVars.gcpFirestoreProjectId ?? "",
231
- credentials: envVars.gcpFirestoreCredentials ?? "",
232
- databaseId: envVars.gcpFirestoreDatabaseId ?? "",
233
- collectionName: envVars.gcpFirestoreCollectionName ?? "",
234
- endpoint: envVars.gcpFirestoreApiEndpoint ?? ""
235
- },
236
- tablePrefix: envVars.entityStorageTablePrefix
237
- }
238
- });
239
- }
240
- if (core.Is.stringValue(envVars.scylladbHosts)) {
241
- coreConfig.types.entityStorageConnector.push({
242
- type: engineTypes.EntityStorageConnectorType.ScyllaDb,
243
- options: {
244
- config: {
245
- hosts: envVars.scylladbHosts.split(",") ?? "",
246
- localDataCenter: envVars.scylladbLocalDataCenter ?? "",
247
- keyspace: envVars.scylladbKeyspace ?? ""
248
- },
249
- tablePrefix: envVars.entityStorageTablePrefix
250
- }
251
- });
252
- }
253
- if (core.Is.stringValue(envVars.mySqlHost)) {
254
- coreConfig.types.entityStorageConnector.push({
255
- type: engineTypes.EntityStorageConnectorType.MySqlDb,
256
- options: {
257
- config: {
258
- host: envVars.mySqlHost,
259
- port: envVars.mySqlPort ?? 3306,
260
- user: envVars.mySqlUser ?? "",
261
- password: envVars.mySqlPassword ?? "",
262
- database: envVars.mySqlDatabase ?? ""
263
- },
264
- tablePrefix: envVars.entityStorageTablePrefix
265
- }
266
- });
267
- }
268
- if (core.Is.stringValue(envVars.mySqlHost)) {
269
- coreConfig.types.entityStorageConnector.push({
270
- type: engineTypes.EntityStorageConnectorType.MySqlDb,
271
- options: {
272
- config: {
273
- host: envVars.mySqlHost,
274
- port: envVars.mySqlPort ?? 3306,
275
- user: envVars.mySqlUser ?? "",
276
- password: envVars.mySqlPassword ?? "",
277
- database: envVars.mySqlDatabase ?? ""
278
- },
279
- tablePrefix: envVars.entityStorageTablePrefix
280
- }
281
- });
282
- }
283
- if (core.Is.stringValue(envVars.mongoDbHost)) {
284
- coreConfig.types.entityStorageConnector.push({
285
- type: engineTypes.EntityStorageConnectorType.MongoDb,
286
- options: {
287
- config: {
288
- host: envVars.mongoDbHost,
289
- port: envVars.mongoDbPort,
290
- user: envVars.mongoDbUser ?? "",
291
- password: envVars.mongoDbPassword ?? "",
292
- database: envVars.mongoDbDatabase ?? ""
293
- },
294
- tablePrefix: envVars.entityStorageTablePrefix
295
- }
296
- });
297
- }
298
- if (core.Is.stringValue(envVars.postgreSqlHost)) {
299
- coreConfig.types.entityStorageConnector.push({
300
- type: engineTypes.EntityStorageConnectorType.PostgreSql,
301
- options: {
302
- config: {
303
- host: envVars.postgreSqlHost,
304
- port: envVars.postgreSqlPort,
305
- user: envVars.postgreSqlUser ?? "",
306
- password: envVars.postgreSqlPassword ?? "",
307
- database: envVars.postgreSqlDatabase ?? ""
308
- },
309
- tablePrefix: envVars.entityStorageTablePrefix
310
- }
311
- });
312
- }
313
- const defaultStorageConnector = envVars.entityStorageConnectorType;
314
- if (core.Is.stringValue(defaultStorageConnector)) {
315
- for (const config of coreConfig.types.entityStorageConnector) {
316
- if (config.type === defaultStorageConnector) {
317
- config.isDefault = true;
318
- }
319
- }
320
- }
321
- }
322
- /**
323
- * Configures the blob storage.
324
- * @param coreConfig The core config.
325
- * @param envVars The environment variables.
326
- */
327
- function configureBlobStorage(coreConfig, envVars) {
328
- coreConfig.types.blobStorageConnector ??= [];
329
- if ((core.Coerce.boolean(envVars.blobMemoryEnable) ?? false) ||
330
- envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.Memory) {
331
- coreConfig.types.blobStorageConnector.push({
332
- type: engineTypes.BlobStorageConnectorType.Memory
333
- });
334
- }
335
- if ((core.Coerce.boolean(envVars.blobFileEnable) ?? false) ||
336
- envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.File) {
337
- coreConfig.types.blobStorageConnector.push({
338
- type: engineTypes.BlobStorageConnectorType.File,
339
- options: {
340
- config: {
341
- directory: core.Is.stringValue(envVars.storageFileRoot)
342
- ? path.join(envVars.storageFileRoot, "blob-storage")
343
- : ""
344
- },
345
- storagePrefix: envVars.blobStoragePrefix
346
- }
347
- });
348
- }
349
- if (core.Is.stringValue(envVars.ipfsApiUrl)) {
350
- coreConfig.types.blobStorageConnector.push({
351
- type: engineTypes.BlobStorageConnectorType.Ipfs,
352
- options: {
353
- config: {
354
- apiUrl: envVars.ipfsApiUrl,
355
- bearerToken: envVars.ipfsBearerToken
356
- }
357
- }
358
- });
359
- }
360
- if (core.Is.stringValue(envVars.awsS3AccessKeyId)) {
361
- coreConfig.types.blobStorageConnector.push({
362
- type: engineTypes.BlobStorageConnectorType.AwsS3,
363
- options: {
364
- config: {
365
- region: envVars.awsS3Region ?? "",
366
- bucketName: envVars.awsS3BucketName ?? "",
367
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
368
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
369
- endpoint: envVars.awsS3Endpoint ?? ""
370
- },
371
- storagePrefix: envVars.blobStoragePrefix
372
- }
373
- });
374
- }
375
- if (core.Is.stringValue(envVars.azureStorageAccountKey)) {
376
- coreConfig.types.blobStorageConnector.push({
377
- type: engineTypes.BlobStorageConnectorType.AzureStorage,
378
- options: {
379
- config: {
380
- accountName: envVars.azureStorageAccountName ?? "",
381
- accountKey: envVars.azureStorageAccountKey ?? "",
382
- containerName: envVars.azureStorageContainerName ?? "",
383
- endpoint: envVars.azureStorageEndpoint ?? ""
384
- },
385
- storagePrefix: envVars.blobStoragePrefix
386
- }
387
- });
388
- }
389
- if (core.Is.stringValue(envVars.gcpStorageCredentials)) {
390
- coreConfig.types.blobStorageConnector.push({
391
- type: engineTypes.BlobStorageConnectorType.GcpStorage,
392
- options: {
393
- config: {
394
- projectId: envVars.gcpStorageProjectId ?? "",
395
- credentials: envVars.gcpStorageCredentials ?? "",
396
- bucketName: envVars.gcpStorageBucketName ?? "",
397
- apiEndpoint: envVars.gcpFirestoreApiEndpoint
398
- },
399
- storagePrefix: envVars.blobStoragePrefix
400
- }
401
- });
402
- }
403
- const defaultStorageConnectorType = envVars.blobStorageConnectorType;
404
- if (core.Is.stringValue(defaultStorageConnectorType)) {
405
- for (const config of coreConfig.types.blobStorageConnector) {
406
- if (config.type === defaultStorageConnectorType) {
407
- config.isDefault = true;
408
- }
409
- }
410
- }
411
- if (coreConfig.types.blobStorageConnector.length > 0) {
412
- coreConfig.types.blobStorageComponent ??= [];
413
- coreConfig.types.blobStorageComponent.push({
414
- type: engineTypes.BlobStorageComponentType.Service,
415
- options: {
416
- config: {
417
- vaultKeyId: (envVars.blobStorageEnableEncryption ?? false)
418
- ? envVars.blobStorageEncryptionKey
419
- : undefined
420
- }
421
- }
422
- });
423
- }
424
- }
425
- /**
426
- * Configures the logging.
427
- * @param coreConfig The core config.
428
- * @param envVars The environment variables.
429
- */
430
- function configureLogging(coreConfig, envVars) {
431
- coreConfig.types.loggingConnector ??= [];
432
- const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
433
- for (const loggingConnector of loggingConnectors) {
434
- if (loggingConnector === engineTypes.LoggingConnectorType.Console) {
435
- coreConfig.types.loggingConnector?.push({
436
- type: engineTypes.LoggingConnectorType.Console,
437
- options: {
438
- config: {
439
- translateMessages: true,
440
- hideGroups: true
441
- }
442
- },
443
- isDefault: loggingConnectors.length === 1
444
- });
445
- }
446
- else if (loggingConnector === engineTypes.LoggingConnectorType.EntityStorage) {
447
- coreConfig.types.loggingConnector?.push({
448
- type: engineTypes.LoggingConnectorType.EntityStorage,
449
- isDefault: loggingConnectors.length === 1
450
- });
451
- }
452
- }
453
- if (loggingConnectors.length > 1) {
454
- coreConfig.types.loggingConnector?.push({
455
- type: engineTypes.LoggingConnectorType.Multi,
456
- isDefault: true,
457
- options: {
458
- loggingConnectorTypes: loggingConnectors
459
- }
460
- });
461
- }
462
- if (loggingConnectors.length > 0) {
463
- coreConfig.types.loggingComponent ??= [];
464
- coreConfig.types.loggingComponent.push({ type: engineTypes.LoggingComponentType.Service });
465
- }
466
- }
467
- /**
468
- * Configures the vault.
469
- * @param coreConfig The core config.
470
- * @param envVars The environment variables.
471
- */
472
- function configureVault(coreConfig, envVars) {
473
- coreConfig.types.vaultConnector ??= [];
474
- if (envVars.vaultConnector === engineTypes.VaultConnectorType.EntityStorage) {
475
- coreConfig.types.vaultConnector.push({
476
- type: engineTypes.VaultConnectorType.EntityStorage
477
- });
478
- }
479
- else if (envVars.vaultConnector === engineTypes.VaultConnectorType.Hashicorp) {
480
- coreConfig.types.vaultConnector.push({
481
- type: engineTypes.VaultConnectorType.Hashicorp,
482
- options: {
483
- config: {
484
- endpoint: envVars.hashicorpVaultEndpoint ?? "",
485
- token: envVars.hashicorpVaultToken ?? ""
486
- }
487
- }
488
- });
489
- }
490
- }
491
- /**
492
- * Configures the background task.
493
- * @param coreConfig The core config.
494
- * @param envVars The environment variables.
495
- */
496
- function configureBackgroundTask(coreConfig, envVars) {
497
- coreConfig.types.backgroundTaskConnector ??= [];
498
- if (envVars.backgroundTaskConnector === engineTypes.BackgroundTaskConnectorType.EntityStorage) {
499
- coreConfig.types.backgroundTaskConnector.push({
500
- type: engineTypes.BackgroundTaskConnectorType.EntityStorage
501
- });
502
- }
503
- }
504
- /**
505
- * Configures the event bud.
506
- * @param coreConfig The core config.
507
- * @param envVars The environment variables.
508
- */
509
- function configureEventBus(coreConfig, envVars) {
510
- coreConfig.types.eventBusConnector ??= [];
511
- if (envVars.eventBusConnector === engineTypes.EventBusConnectorType.Local) {
512
- coreConfig.types.eventBusConnector.push({
513
- type: engineTypes.EventBusConnectorType.Local
514
- });
515
- }
516
- if (coreConfig.types.eventBusConnector.length > 0) {
517
- coreConfig.types.eventBusComponent ??= [];
518
- coreConfig.types.eventBusComponent.push({ type: engineTypes.EventBusComponentType.Service });
519
- }
520
- }
521
- /**
522
- * Configures the telemetry.
523
- * @param coreConfig The core config.
524
- * @param envVars The environment variables.
525
- */
526
- function configureTelemetry(coreConfig, envVars) {
527
- coreConfig.types.telemetryConnector ??= [];
528
- if (envVars.telemetryConnector === engineTypes.TelemetryConnectorType.EntityStorage) {
529
- coreConfig.types.telemetryConnector.push({
530
- type: engineTypes.TelemetryConnectorType.EntityStorage
531
- });
532
- }
533
- if (coreConfig.types.telemetryConnector.length > 0) {
534
- coreConfig.types.telemetryComponent ??= [];
535
- coreConfig.types.telemetryComponent.push({ type: engineTypes.TelemetryComponentType.Service });
536
- }
537
- }
538
- /**
539
- * Configures the messaging.
540
- * @param coreConfig The core config.
541
- * @param envVars The environment variables.
542
- */
543
- function configureMessaging(coreConfig, envVars) {
544
- coreConfig.types.messagingEmailConnector ??= [];
545
- coreConfig.types.messagingSmsConnector ??= [];
546
- coreConfig.types.messagingPushNotificationConnector ??= [];
547
- if (envVars.messagingEmailConnector === engineTypes.MessagingEmailConnectorType.EntityStorage) {
548
- coreConfig.types.messagingEmailConnector.push({
549
- type: engineTypes.MessagingEmailConnectorType.EntityStorage
550
- });
551
- }
552
- else if (envVars.messagingEmailConnector === engineTypes.MessagingEmailConnectorType.Aws) {
553
- coreConfig.types.messagingEmailConnector.push({
554
- type: engineTypes.MessagingEmailConnectorType.Aws,
555
- options: {
556
- config: {
557
- region: envVars.awsS3Region ?? "",
558
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
559
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
560
- endpoint: envVars.awsS3Endpoint ?? ""
561
- }
562
- }
563
- });
564
- }
565
- if (envVars.messagingSmsConnector === engineTypes.MessagingSmsConnectorType.EntityStorage) {
566
- coreConfig.types.messagingSmsConnector.push({
567
- type: engineTypes.MessagingSmsConnectorType.EntityStorage
568
- });
569
- }
570
- else if (envVars.messagingSmsConnector === engineTypes.MessagingSmsConnectorType.Aws) {
571
- coreConfig.types.messagingSmsConnector.push({
572
- type: engineTypes.MessagingSmsConnectorType.Aws,
573
- options: {
574
- config: {
575
- region: envVars.awsS3Region ?? "",
576
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
577
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
578
- endpoint: envVars.awsS3Endpoint ?? ""
579
- }
580
- }
581
- });
582
- }
583
- if (envVars.messagingPushNotificationConnector ===
584
- engineTypes.MessagingPushNotificationConnectorType.EntityStorage) {
585
- coreConfig.types.messagingPushNotificationConnector.push({
586
- type: engineTypes.MessagingPushNotificationConnectorType.EntityStorage
587
- });
588
- }
589
- else if (envVars.messagingPushNotificationConnector === engineTypes.MessagingPushNotificationConnectorType.Aws) {
590
- coreConfig.types.messagingPushNotificationConnector.push({
591
- type: engineTypes.MessagingPushNotificationConnectorType.Aws,
592
- options: {
593
- config: {
594
- region: envVars.awsS3Region ?? "",
595
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
596
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
597
- endpoint: envVars.awsS3Endpoint ?? "",
598
- applicationsSettings: core.Is.json(envVars.awsMessagingPushNotificationApplications)
599
- ? JSON.parse(envVars.awsMessagingPushNotificationApplications)
600
- : []
601
- }
602
- }
603
- });
604
- }
605
- if (coreConfig.types.messagingEmailConnector.length > 0 ||
606
- coreConfig.types.messagingSmsConnector.length > 0 ||
607
- coreConfig.types.messagingPushNotificationConnector.length > 0) {
608
- coreConfig.types.messagingComponent ??= [];
609
- coreConfig.types.messagingComponent.push({ type: engineTypes.MessagingComponentType.Service });
610
- }
611
- }
612
- /**
613
- * Configures the faucet.
614
- * @param coreConfig The core config.
615
- * @param envVars The environment variables.
616
- */
617
- function configureFaucet(coreConfig, envVars) {
618
- coreConfig.types.faucetConnector ??= [];
619
- if (envVars.faucetConnector === engineTypes.FaucetConnectorType.EntityStorage) {
620
- coreConfig.types.faucetConnector.push({
621
- type: engineTypes.FaucetConnectorType.EntityStorage
622
- });
623
- }
624
- else if (envVars.faucetConnector === engineTypes.FaucetConnectorType.Iota) {
625
- const iotaConfig = getIotaConfig(coreConfig);
626
- coreConfig.types.faucetConnector.push({
627
- type: engineTypes.FaucetConnectorType.Iota,
628
- options: {
629
- config: {
630
- endpoint: envVars.iotaFaucetEndpoint ?? "",
631
- clientOptions: iotaConfig?.clientOptions ?? { url: "" },
632
- network: iotaConfig?.network ?? ""
633
- }
634
- }
635
- });
636
- }
637
- }
638
- /**
639
- * Configures the wallet.
640
- * @param coreConfig The core config.
641
- * @param envVars The environment variables.
642
- */
643
- function configureWallet(coreConfig, envVars) {
644
- coreConfig.types.walletConnector ??= [];
645
- if (envVars.walletConnector === engineTypes.WalletConnectorType.EntityStorage) {
646
- coreConfig.types.walletConnector.push({
647
- type: engineTypes.WalletConnectorType.EntityStorage
648
- });
649
- }
650
- else if (envVars.walletConnector === engineTypes.WalletConnectorType.Iota) {
651
- const iotaConfig = getIotaConfig(coreConfig);
652
- coreConfig.types.walletConnector.push({
653
- type: engineTypes.WalletConnectorType.Iota,
654
- options: {
655
- config: iotaConfig ?? {}
656
- }
657
- });
658
- }
659
- }
660
- /**
661
- * Configures the NFT.
662
- * @param coreConfig The core config.
663
- * @param envVars The environment variables.
664
- */
665
- function configureNft(coreConfig, envVars) {
666
- coreConfig.types.nftConnector ??= [];
667
- if (envVars.nftConnector === engineTypes.NftConnectorType.EntityStorage) {
668
- coreConfig.types.nftConnector.push({
669
- type: engineTypes.NftConnectorType.EntityStorage
670
- });
671
- }
672
- else if (envVars.nftConnector === engineTypes.NftConnectorType.Iota) {
673
- const iotaConfig = getIotaConfig(coreConfig);
674
- coreConfig.types.nftConnector.push({
675
- type: engineTypes.NftConnectorType.Iota,
676
- options: {
677
- config: iotaConfig ?? {}
678
- }
679
- });
680
- }
681
- if (coreConfig.types.nftConnector.length > 0) {
682
- coreConfig.types.nftComponent ??= [];
683
- coreConfig.types.nftComponent.push({ type: engineTypes.NftComponentType.Service });
684
- }
685
- }
686
- /**
687
- * Configures the verifiable storage.
688
- * @param coreConfig The core config.
689
- * @param envVars The environment variables.
690
- */
691
- function configureVerifiableStorage(coreConfig, envVars) {
692
- coreConfig.types.verifiableStorageConnector ??= [];
693
- if (envVars.verifiableStorageConnector === engineTypes.VerifiableStorageConnectorType.EntityStorage) {
694
- coreConfig.types.verifiableStorageConnector.push({
695
- type: engineTypes.VerifiableStorageConnectorType.EntityStorage
696
- });
697
- }
698
- else if (envVars.verifiableStorageConnector === engineTypes.VerifiableStorageConnectorType.Iota) {
699
- const iotaConfig = getIotaConfig(coreConfig);
700
- coreConfig.types.verifiableStorageConnector.push({
701
- type: engineTypes.VerifiableStorageConnectorType.Iota,
702
- options: {
703
- config: iotaConfig ?? {}
704
- }
705
- });
706
- }
707
- if (coreConfig.types.verifiableStorageConnector.length > 0) {
708
- coreConfig.types.verifiableStorageComponent ??= [];
709
- coreConfig.types.verifiableStorageComponent.push({
710
- type: engineTypes.VerifiableStorageComponentType.Service
711
- });
712
- coreConfig.types.immutableProofComponent ??= [];
713
- coreConfig.types.immutableProofComponent.push({
714
- type: engineTypes.ImmutableProofComponentType.Service,
715
- options: {
716
- config: {
717
- verificationMethodId: envVars.immutableProofVerificationMethodId
718
- }
719
- }
720
- });
721
- coreConfig.types.auditableItemGraphComponent ??= [];
722
- coreConfig.types.auditableItemGraphComponent.push({
723
- type: engineTypes.AuditableItemGraphComponentType.Service
724
- });
725
- coreConfig.types.auditableItemStreamComponent ??= [];
726
- coreConfig.types.auditableItemStreamComponent.push({
727
- type: engineTypes.AuditableItemStreamComponentType.Service
728
- });
729
- }
730
- }
731
- /**
732
- * Configures the identity.
733
- * @param coreConfig The core config.
734
- * @param envVars The environment variables.
735
- */
736
- function configureIdentity(coreConfig, envVars) {
737
- coreConfig.types.identityConnector ??= [];
738
- if (envVars.identityConnector === engineTypes.IdentityConnectorType.EntityStorage) {
739
- coreConfig.types.identityConnector.push({
740
- type: engineTypes.IdentityConnectorType.EntityStorage
741
- });
742
- }
743
- else if (envVars.identityConnector === engineTypes.IdentityConnectorType.Iota) {
744
- const iotaConfig = getIotaConfig(coreConfig);
745
- coreConfig.types.identityConnector.push({
746
- type: engineTypes.IdentityConnectorType.Iota,
747
- options: {
748
- config: iotaConfig ?? {}
749
- }
750
- });
751
- }
752
- if (coreConfig.types.identityConnector.length > 0) {
753
- coreConfig.types.identityComponent ??= [];
754
- coreConfig.types.identityComponent.push({ type: engineTypes.IdentityComponentType.Service });
755
- }
756
- }
757
- /**
758
- * Configures the identity resolver.
759
- * @param coreConfig The core config.
760
- * @param envVars The environment variables.
761
- */
762
- function configureIdentityResolver(coreConfig, envVars) {
763
- coreConfig.types.identityResolverConnector ??= [];
764
- if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.EntityStorage) {
765
- coreConfig.types.identityResolverConnector.push({
766
- type: engineTypes.IdentityResolverConnectorType.EntityStorage
767
- });
768
- }
769
- else if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.Iota) {
770
- const iotaConfig = getIotaConfig(coreConfig);
771
- coreConfig.types.identityResolverConnector.push({
772
- type: engineTypes.IdentityResolverConnectorType.Iota,
773
- options: {
774
- config: iotaConfig ?? {}
775
- }
776
- });
777
- }
778
- else if (envVars.identityResolverConnector === engineTypes.IdentityResolverConnectorType.Universal) {
779
- coreConfig.types.identityResolverConnector.push({
780
- type: engineTypes.IdentityResolverConnectorType.Universal,
781
- options: {
782
- config: {
783
- endpoint: envVars.universalResolverEndpoint ?? ""
784
- }
785
- }
786
- });
787
- }
788
- if (coreConfig.types.identityResolverConnector.length > 0) {
789
- coreConfig.types.identityResolverComponent ??= [];
790
- coreConfig.types.identityResolverComponent.push({
791
- type: engineTypes.IdentityResolverComponentType.Service
792
- });
793
- }
794
- }
795
- /**
796
- * Configures the identity profile.
797
- * @param coreConfig The core config.
798
- * @param envVars The environment variables.
799
- */
800
- function configureIdentityProfile(coreConfig, envVars) {
801
- coreConfig.types.identityProfileConnector ??= [];
802
- if (envVars.identityProfileConnector === engineTypes.IdentityConnectorType.EntityStorage) {
803
- coreConfig.types.identityProfileConnector.push({
804
- type: engineTypes.IdentityProfileConnectorType.EntityStorage
805
- });
806
- }
807
- if (coreConfig.types.identityProfileConnector.length > 0) {
808
- coreConfig.types.identityProfileComponent ??= [];
809
- coreConfig.types.identityProfileComponent.push({ type: engineTypes.IdentityProfileComponentType.Service });
810
- }
811
- }
812
- /**
813
- * Configures the attestation.
814
- * @param coreConfig The core config.
815
- * @param envVars The environment variables.
816
- */
817
- function configureAttestation(coreConfig, envVars) {
818
- coreConfig.types.attestationConnector ??= [];
819
- if (envVars.attestationConnector === engineTypes.AttestationConnectorType.Nft) {
820
- coreConfig.types.attestationConnector.push({
821
- type: engineTypes.AttestationConnectorType.Nft
822
- });
823
- }
824
- if (coreConfig.types.attestationConnector.length > 0) {
825
- coreConfig.types.attestationComponent ??= [];
826
- coreConfig.types.attestationComponent.push({
827
- type: engineTypes.AttestationComponentType.Service,
828
- options: {
829
- config: {
830
- verificationMethodId: envVars.attestationVerificationMethodId
831
- }
832
- }
833
- });
834
- }
835
- }
836
- /**
837
- * Configures the auditable item graph.
838
- * @param coreConfig The core config.
839
- * @param envVars The environment variables.
840
- */
841
- function configureAuditableItemGraph(coreConfig, envVars) {
842
- if (core.Is.arrayValue(coreConfig.types.verifiableStorageConnector)) {
843
- coreConfig.types.auditableItemGraphComponent ??= [];
844
- coreConfig.types.auditableItemGraphComponent.push({
845
- type: engineTypes.AuditableItemGraphComponentType.Service
846
- });
847
- }
848
- }
849
- /**
850
- * Configures the auditable item stream.
851
- * @param coreConfig The core config.
852
- * @param envVars The environment variables.
853
- */
854
- function configureAuditableItemStream(coreConfig, envVars) {
855
- if (core.Is.arrayValue(coreConfig.types.verifiableStorageConnector)) {
856
- coreConfig.types.auditableItemStreamComponent ??= [];
857
- coreConfig.types.auditableItemStreamComponent.push({
858
- type: engineTypes.AuditableItemStreamComponentType.Service
859
- });
860
- }
861
- }
862
- /**
863
- * Configures the data processing.
864
- * @param coreConfig The core config.
865
- * @param envVars The environment variables.
866
- */
867
- function configureDataProcessing(coreConfig, envVars) {
868
- coreConfig.types.dataConverterConnector ??= [];
869
- coreConfig.types.dataExtractorConnector ??= [];
870
- const converterConnectors = envVars.dataConverterConnectors?.split(",") ?? [];
871
- for (const converterConnector of converterConnectors) {
872
- if (converterConnector === engineTypes.DataConverterConnectorType.Json) {
873
- coreConfig.types.dataConverterConnector.push({
874
- type: engineTypes.DataConverterConnectorType.Json
875
- });
876
- }
877
- else if (converterConnector === engineTypes.DataConverterConnectorType.Xml) {
878
- coreConfig.types.dataConverterConnector.push({
879
- type: engineTypes.DataConverterConnectorType.Xml
880
- });
881
- }
882
- }
883
- const extractorConnectors = envVars.dataExtractorConnectors?.split(",") ?? [];
884
- for (const extractorConnector of extractorConnectors) {
885
- if (extractorConnector === engineTypes.DataExtractorConnectorType.JsonPath) {
886
- coreConfig.types.dataExtractorConnector.push({
887
- type: engineTypes.DataExtractorConnectorType.JsonPath
888
- });
889
- }
890
- }
891
- if (coreConfig.types.dataConverterConnector.length > 0 ||
892
- coreConfig.types.dataExtractorConnector.length > 0) {
893
- coreConfig.types.dataProcessingComponent ??= [];
894
- coreConfig.types.dataProcessingComponent.push({ type: engineTypes.DataProcessingComponentType.Service });
895
- }
896
- }
897
- /**
898
- * Configures the document management.
899
- * @param coreConfig The core config.
900
- * @param envVars The environment variables.
901
- */
902
- function configureDocumentManagement(coreConfig, envVars) {
903
- if (core.Is.arrayValue(coreConfig.types.auditableItemGraphComponent) &&
904
- core.Is.arrayValue(coreConfig.types.blobStorageComponent) &&
905
- core.Is.arrayValue(coreConfig.types.attestationComponent)) {
906
- coreConfig.types.documentManagementComponent ??= [];
907
- coreConfig.types.documentManagementComponent.push({
908
- type: engineTypes.DocumentManagementComponentType.Service
909
- });
910
- }
911
- }
912
- /**
913
- * Configures the federated catalogue.
914
- * @param coreConfig The core config.
915
- * @param envVars The environment variables.
916
- */
917
- function configureFederatedCatalogue(coreConfig, envVars) {
918
- if (core.Is.arrayValue(coreConfig.types.identityResolverComponent)) {
919
- coreConfig.types.federatedCatalogueComponent ??= [];
920
- coreConfig.types.federatedCatalogueComponent.push({
921
- type: engineTypes.FederatedCatalogueComponentType.Service,
922
- options: {
923
- config: {
924
- subResourceCacheTtlMs: core.Coerce.number(envVars.federatedCatalogueCacheTtlMs),
925
- clearingHouseApproverList: core.Coerce.object(envVars.federatedCatalogueClearingHouseApproverList) ?? []
926
- }
927
- }
928
- });
929
- }
930
- }
931
- /**
932
- * Configures the rights management.
933
- * @param coreConfig The core config.
934
- * @param envVars The environment variables.
935
- */
936
- function configureRightsManagement(coreConfig, envVars) {
937
- if (core.Coerce.boolean(envVars.rightsManagementEnabled) ?? false) {
938
- coreConfig.types.rightsManagementPapComponent ??= [];
939
- coreConfig.types.rightsManagementPapComponent.push({
940
- type: engineTypes.RightsManagementPapComponentType.Service
941
- });
942
- coreConfig.types.rightsManagementComponent ??= [];
943
- coreConfig.types.rightsManagementComponent.push({
944
- type: engineTypes.RightsManagementComponentType.Service
945
- });
946
- }
947
- }
948
- /**
949
- * Configures the task scheduler.
950
- * @param coreConfig The core config.
951
- * @param envVars The environment variables.
952
- */
953
- function configureTaskScheduler(coreConfig, envVars) {
954
- if (core.Coerce.boolean(envVars.taskSchedulerEnabled) ?? true) {
955
- coreConfig.types.taskSchedulerComponent ??= [];
956
- coreConfig.types.taskSchedulerComponent.push({
957
- type: engineTypes.TaskSchedulerComponentType.Default
958
- });
959
- }
960
- }
961
- /**
962
- * Configures the DLT.
963
- * @param coreConfig The core config.
964
- * @param envVars The environment variables.
965
- */
966
- function configureDlt(coreConfig, envVars) {
967
- // Create centralized DLT configuration for IOTA if essential IOTA variables are set
968
- if (core.Is.stringValue(envVars.iotaNodeEndpoint) && core.Is.stringValue(envVars.iotaNetwork)) {
969
- coreConfig.types.dltConfig ??= [];
970
- const gasStationConfig = core.Is.stringValue(envVars.iotaGasStationEndpoint) &&
971
- core.Is.stringValue(envVars.iotaGasStationAuthToken)
972
- ? {
973
- gasStationUrl: envVars.iotaGasStationEndpoint,
974
- gasStationAuthToken: envVars.iotaGasStationAuthToken
975
- }
976
- : undefined;
977
- coreConfig.types.dltConfig.push({
978
- type: engineTypes.DltConfigType.Iota,
979
- isDefault: true,
980
- options: {
981
- config: {
982
- clientOptions: {
983
- url: envVars.iotaNodeEndpoint ?? ""
984
- },
985
- network: envVars.iotaNetwork ?? "",
986
- coinType: core.Coerce.number(envVars.iotaCoinType),
987
- gasStation: gasStationConfig
988
- }
989
- }
111
+ restPath: core.Is.stringValue(restPath) ? restPath : undefined
990
112
  });
991
113
  }
992
114
  }
993
115
 
994
116
  exports.Engine = Engine;
995
117
  exports.EngineConfigHelper = EngineConfigHelper;
996
- exports.buildEngineConfiguration = buildEngineConfiguration;