@twin.org/engine 0.0.1-next.14

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.
@@ -0,0 +1,587 @@
1
+ import { EngineCore } from '@twin.org/engine-core';
2
+ import path from 'node:path';
3
+ import { Coerce, Is, StringHelper, ObjectHelper } from '@twin.org/core';
4
+ import { LoggingComponentType, BlobStorageComponentType, TelemetryComponentType, NftComponentType, IdentityComponentType, IdentityProfileComponentType, ImmutableProofComponentType, AttestationComponentType, AuditableItemGraphComponentType, AuditableItemStreamComponentType, EntityStorageConnectorType, BlobStorageConnectorType, LoggingConnectorType, VaultConnectorType, BackgroundTaskConnectorType, TelemetryConnectorType, FaucetConnectorType, WalletConnectorType, NftConnectorType, ImmutableStorageConnectorType, IdentityConnectorType, IdentityProfileConnectorType, AttestationConnectorType } from '@twin.org/engine-types';
5
+
6
+ // Copyright 2024 IOTA Stiftung.
7
+ // SPDX-License-Identifier: Apache-2.0.
8
+ /**
9
+ * The engine with built in types.
10
+ */
11
+ class Engine extends EngineCore {
12
+ /**
13
+ * Runtime name for the class.
14
+ */
15
+ CLASS_NAME = "Engine";
16
+ /**
17
+ * Create a new instance of Engine.
18
+ * @param options The options for the engine.
19
+ */
20
+ constructor(options) {
21
+ super(options);
22
+ this.addCoreTypeInitialisers(this, this._context);
23
+ }
24
+ /**
25
+ * Add the core type initializers.
26
+ * @internal
27
+ */
28
+ addCoreTypeInitialisers(engineCore, context) {
29
+ this.addTypeInitialiser("loggingConnector", context.config.types.loggingConnector, "@twin.org/engine-types", "initialiseLoggingConnector");
30
+ this.addTypeInitialiser("loggingComponent", context.config.types.loggingComponent, "@twin.org/engine-types", "initialiseLoggingComponent");
31
+ this.addTypeInitialiser("backgroundTaskConnector", context.config.types.backgroundTaskConnector, "@twin.org/engine-types", "initialiseBackgroundTaskConnector");
32
+ this.addTypeInitialiser("telemetryConnector", context.config.types.telemetryConnector, "@twin.org/engine-types", "initialiseTelemetryConnector");
33
+ this.addTypeInitialiser("telemetryComponent", context.config.types.telemetryComponent, "@twin.org/engine-types", "initialiseTelemetryComponent");
34
+ this.addTypeInitialiser("entityStorageComponent", context.config.types.entityStorageComponent, "@twin.org/engine-types", "initialiseEntityStorageComponent");
35
+ this.addTypeInitialiser("vaultConnector", context.config.types.vaultConnector, "@twin.org/engine-types", "initialiseVaultConnector");
36
+ this.addTypeInitialiser("blobStorageConnector", context.config.types.blobStorageConnector, "@twin.org/engine-types", "initialiseBlobStorageConnector");
37
+ this.addTypeInitialiser("blobStorageComponent", context.config.types.blobStorageComponent, "@twin.org/engine-types", "initialiseBlobStorageComponent");
38
+ this.addTypeInitialiser("immutableStorageConnector", context.config.types.immutableStorageConnector, "@twin.org/engine-types", "initialiseImmutableStorageConnector");
39
+ this.addTypeInitialiser("walletConnector", context.config.types.walletConnector, "@twin.org/engine-types", "initialiseWalletStorage");
40
+ this.addTypeInitialiser("faucetConnector", context.config.types.faucetConnector, "@twin.org/engine-types", "initialiseFaucetConnector");
41
+ this.addTypeInitialiser("walletConnector", context.config.types.walletConnector, "@twin.org/engine-types", "initialiseWalletConnector");
42
+ this.addTypeInitialiser("identityConnector", context.config.types.identityConnector, "@twin.org/engine-types", "initialiseIdentityConnector");
43
+ this.addTypeInitialiser("identityComponent", context.config.types.identityComponent, "@twin.org/engine-types", "initialiseIdentityComponent");
44
+ this.addTypeInitialiser("identityProfileConnector", context.config.types.identityProfileConnector, "@twin.org/engine-types", "initialiseIdentityProfileConnector");
45
+ this.addTypeInitialiser("identityProfileComponent", context.config.types.identityProfileComponent, "@twin.org/engine-types", "initialiseIdentityProfileComponent");
46
+ this.addTypeInitialiser("nftConnector", context.config.types.nftConnector, "@twin.org/engine-types", "initialiseNftConnector");
47
+ this.addTypeInitialiser("nftComponent", context.config.types.nftComponent, "@twin.org/engine-types", "initialiseNftComponent");
48
+ this.addTypeInitialiser("immutableProofComponent", context.config.types.immutableProofComponent, "@twin.org/engine-types", "initialiseImmutableProofComponent");
49
+ this.addTypeInitialiser("attestationConnector", context.config.types.attestationConnector, "@twin.org/engine-types", "initialiseAttestationConnector");
50
+ this.addTypeInitialiser("attestationComponent", context.config.types.attestationComponent, "@twin.org/engine-types", "initialiseAttestationComponent");
51
+ this.addTypeInitialiser("auditableItemGraphComponent", context.config.types.auditableItemGraphComponent, "@twin.org/engine-types", "initialiseAuditableItemGraphComponent");
52
+ this.addTypeInitialiser("auditableItemStreamComponent", context.config.types.auditableItemStreamComponent, "@twin.org/engine-types", "initialiseAuditableItemStreamComponent");
53
+ }
54
+ }
55
+
56
+ // Copyright 2024 IOTA Stiftung.
57
+ // SPDX-License-Identifier: Apache-2.0.
58
+ /**
59
+ * Build the engine core configuration from environment variables.
60
+ * @param envVars The environment variables.
61
+ * @returns The config for the core.
62
+ */
63
+ function buildEngineConfiguration(envVars) {
64
+ envVars.stateFilename ??= "engine-state.json";
65
+ envVars.storageFileRoot = path.resolve(envVars.storageFileRoot);
66
+ envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
67
+ envVars.attestationAssertionMethodId ??= "attestation-assertion";
68
+ envVars.immutableProofHashKeyId ??= "immutable-proof-hash";
69
+ envVars.immutableProofAssertionMethodId ??= "immutable-proof-assertion";
70
+ envVars.blobStorageEnableEncryption ??= "false";
71
+ envVars.blobStorageEncryptionKey ??= "blob-encryption";
72
+ const coreConfig = {
73
+ debug: Coerce.boolean(envVars.debug) ?? false,
74
+ types: {
75
+ loggingConnector: [],
76
+ loggingComponent: [{ type: LoggingComponentType.Service }],
77
+ entityStorageConnector: [],
78
+ blobStorageConnector: [],
79
+ blobStorageComponent: [
80
+ {
81
+ type: BlobStorageComponentType.Service,
82
+ options: {
83
+ config: {
84
+ vaultKeyId: envVars.blobStorageEncryptionKey
85
+ }
86
+ }
87
+ }
88
+ ],
89
+ backgroundTaskConnector: [],
90
+ telemetryConnector: [],
91
+ telemetryComponent: [{ type: TelemetryComponentType.Service }],
92
+ vaultConnector: [],
93
+ walletConnector: [],
94
+ faucetConnector: [],
95
+ immutableStorageConnector: [],
96
+ nftConnector: [],
97
+ nftComponent: [{ type: NftComponentType.Service }],
98
+ identityConnector: [],
99
+ identityComponent: [{ type: IdentityComponentType.Service }],
100
+ identityProfileConnector: [],
101
+ identityProfileComponent: [{ type: IdentityProfileComponentType.Service }],
102
+ immutableProofComponent: [
103
+ {
104
+ type: ImmutableProofComponentType.Service,
105
+ options: {
106
+ config: {
107
+ assertionMethodId: envVars.immutableProofAssertionMethodId,
108
+ proofHashKeyId: envVars.immutableProofHashKeyId
109
+ }
110
+ }
111
+ }
112
+ ],
113
+ attestationConnector: [],
114
+ attestationComponent: [
115
+ {
116
+ type: AttestationComponentType.Service
117
+ }
118
+ ],
119
+ auditableItemGraphComponent: [{ type: AuditableItemGraphComponentType.Service }],
120
+ auditableItemStreamComponent: [{ type: AuditableItemStreamComponentType.Service }]
121
+ }
122
+ };
123
+ configureEntityStorageConnectors(coreConfig, envVars);
124
+ configureBlobStorageConnectors(coreConfig, envVars);
125
+ configureVaultConnectors(coreConfig, envVars);
126
+ configureLogging(coreConfig, envVars);
127
+ configureBackgroundTaskConnectors(coreConfig, envVars);
128
+ configureTelemetryConnectors(coreConfig, envVars);
129
+ configureFaucetConnectors(coreConfig, envVars);
130
+ configureWalletConnectors(coreConfig, envVars);
131
+ configureNftConnectors(coreConfig, envVars);
132
+ configureImmutableStorageConnectors(coreConfig, envVars);
133
+ configureIdentityConnectors(coreConfig, envVars);
134
+ configureIdentityProfileConnectors(coreConfig, envVars);
135
+ configureAttestationConnectors(coreConfig, envVars);
136
+ return coreConfig;
137
+ }
138
+ /**
139
+ * Configures the entity storage connectors for the core.
140
+ * @param coreConfig The core config.
141
+ * @param envVars The environment variables.
142
+ */
143
+ function configureEntityStorageConnectors(coreConfig, envVars) {
144
+ coreConfig.types ??= {};
145
+ coreConfig.types.entityStorageConnector ??= [];
146
+ if ((Coerce.boolean(envVars.entityMemoryEnable) ?? false) ||
147
+ envVars.blobStorageConnectorType === EntityStorageConnectorType.Memory) {
148
+ coreConfig.types.entityStorageConnector.push({
149
+ type: EntityStorageConnectorType.Memory
150
+ });
151
+ }
152
+ if ((Coerce.boolean(envVars.entityFileEnable) ?? false) ||
153
+ envVars.entityStorageConnectorType === EntityStorageConnectorType.File) {
154
+ coreConfig.types.entityStorageConnector.push({
155
+ type: EntityStorageConnectorType.File,
156
+ options: {
157
+ config: { directory: envVars.storageFileRoot },
158
+ folderPrefix: envVars.entityStorageTablePrefix
159
+ }
160
+ });
161
+ }
162
+ if (Is.stringValue(envVars.awsDynamodbAccessKeyId)) {
163
+ coreConfig.types.entityStorageConnector.push({
164
+ type: EntityStorageConnectorType.AwsDynamoDb,
165
+ options: {
166
+ config: {
167
+ region: envVars.awsDynamodbRegion,
168
+ accessKeyId: envVars.awsDynamodbAccessKeyId,
169
+ secretAccessKey: envVars.awsDynamodbSecretAccessKey,
170
+ endpoint: envVars.awsDynamodbEndpoint
171
+ },
172
+ tablePrefix: envVars.entityStorageTablePrefix
173
+ }
174
+ });
175
+ }
176
+ if (Is.stringValue(envVars.azureCosmosdbKey)) {
177
+ coreConfig.types.entityStorageConnector.push({
178
+ type: EntityStorageConnectorType.AzureCosmosDb,
179
+ options: {
180
+ config: {
181
+ endpoint: envVars.azureCosmosdbEndpoint,
182
+ key: envVars.azureCosmosdbKey,
183
+ databaseId: envVars.azureCosmosdbDatabaseId,
184
+ containerId: envVars.azureCosmosdbContainerId
185
+ },
186
+ tablePrefix: envVars.entityStorageTablePrefix
187
+ }
188
+ });
189
+ }
190
+ if (Is.stringValue(envVars.gcpFirestoreCredentials)) {
191
+ coreConfig.types.entityStorageConnector.push({
192
+ type: EntityStorageConnectorType.GcpFirestoreDb,
193
+ options: {
194
+ config: {
195
+ projectId: envVars.gcpFirestoreProjectId,
196
+ credentials: envVars.gcpFirestoreCredentials,
197
+ databaseId: envVars.gcpFirestoreDatabaseId,
198
+ collectionName: envVars.gcpFirestoreCollectionName,
199
+ endpoint: envVars.gcpFirestoreApiEndpoint
200
+ },
201
+ tablePrefix: envVars.entityStorageTablePrefix
202
+ }
203
+ });
204
+ }
205
+ if (Is.stringValue(envVars.scylladbHosts)) {
206
+ coreConfig.types.entityStorageConnector.push({
207
+ type: EntityStorageConnectorType.ScyllaDb,
208
+ options: {
209
+ config: {
210
+ hosts: envVars.scylladbHosts.split(","),
211
+ localDataCenter: envVars.scylladbLocalDataCenter,
212
+ keyspace: envVars.scylladbKeyspace
213
+ },
214
+ tablePrefix: envVars.entityStorageTablePrefix
215
+ }
216
+ });
217
+ }
218
+ const defaultStorageConnector = envVars.entityStorageConnectorType;
219
+ if (Is.stringValue(defaultStorageConnector)) {
220
+ for (const config of coreConfig.types.entityStorageConnector) {
221
+ if (config.type === defaultStorageConnector) {
222
+ config.isDefault = true;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ /**
228
+ * Configures the blob storage connectors for the core.
229
+ * @param coreConfig The core config.
230
+ * @param envVars The environment variables.
231
+ */
232
+ function configureBlobStorageConnectors(coreConfig, envVars) {
233
+ coreConfig.types.blobStorageConnector ??= [];
234
+ if ((Coerce.boolean(envVars.blobMemoryEnable) ?? false) ||
235
+ envVars.blobStorageConnectorType === BlobStorageConnectorType.Memory) {
236
+ coreConfig.types.blobStorageConnector.push({
237
+ type: BlobStorageConnectorType.Memory
238
+ });
239
+ }
240
+ if ((Coerce.boolean(envVars.blobFileEnable) ?? false) ||
241
+ envVars.blobStorageConnectorType === BlobStorageConnectorType.File) {
242
+ coreConfig.types.blobStorageConnector.push({
243
+ type: BlobStorageConnectorType.File,
244
+ options: {
245
+ config: { directory: path.join(envVars.storageFileRoot, "blob-storage") },
246
+ storagePrefix: envVars.blobStoragePrefix
247
+ }
248
+ });
249
+ }
250
+ if (Is.stringValue(envVars.ipfsApiUrl)) {
251
+ coreConfig.types.blobStorageConnector.push({
252
+ type: BlobStorageConnectorType.Ipfs,
253
+ options: {
254
+ config: {
255
+ apiUrl: envVars.ipfsApiUrl,
256
+ bearerToken: envVars.ipfsBearerToken
257
+ }
258
+ }
259
+ });
260
+ }
261
+ if (Is.stringValue(envVars.awsS3AccessKeyId)) {
262
+ coreConfig.types.blobStorageConnector.push({
263
+ type: BlobStorageConnectorType.AwsS3,
264
+ options: {
265
+ config: {
266
+ region: envVars.awsS3Region,
267
+ bucketName: envVars.awsS3BucketName,
268
+ accessKeyId: envVars.awsS3AccessKeyId,
269
+ secretAccessKey: envVars.awsS3SecretAccessKey,
270
+ endpoint: envVars.awsS3Endpoint
271
+ },
272
+ storagePrefix: envVars.blobStoragePrefix
273
+ }
274
+ });
275
+ }
276
+ if (Is.stringValue(envVars.azureStorageAccountKey)) {
277
+ coreConfig.types.blobStorageConnector.push({
278
+ type: BlobStorageConnectorType.AzureStorage,
279
+ options: {
280
+ config: {
281
+ accountName: envVars.azureStorageAccountName,
282
+ accountKey: envVars.azureStorageAccountKey,
283
+ containerName: envVars.azureStorageContainerName,
284
+ endpoint: envVars.azureStorageEndpoint
285
+ },
286
+ storagePrefix: envVars.blobStoragePrefix
287
+ }
288
+ });
289
+ }
290
+ if (Is.stringValue(envVars.gcpStorageCredentials)) {
291
+ coreConfig.types.blobStorageConnector.push({
292
+ type: BlobStorageConnectorType.GcpStorage,
293
+ options: {
294
+ config: {
295
+ projectId: envVars.gcpStorageProjectId,
296
+ credentials: envVars.gcpStorageCredentials,
297
+ bucketName: envVars.gcpStorageBucketName,
298
+ apiEndpoint: envVars.gcpFirestoreApiEndpoint
299
+ },
300
+ storagePrefix: envVars.blobStoragePrefix
301
+ }
302
+ });
303
+ }
304
+ const defaultStorageConnectorType = envVars.blobStorageConnectorType;
305
+ if (Is.stringValue(defaultStorageConnectorType)) {
306
+ for (const config of coreConfig.types.blobStorageConnector) {
307
+ if (config.type === defaultStorageConnectorType) {
308
+ config.isDefault = true;
309
+ }
310
+ }
311
+ }
312
+ }
313
+ /**
314
+ * Configures the logging connectors for the core.
315
+ * @param coreConfig The core config.
316
+ * @param envVars The environment variables.
317
+ */
318
+ function configureLogging(coreConfig, envVars) {
319
+ const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
320
+ for (const loggingConnector of loggingConnectors) {
321
+ if (loggingConnector === LoggingConnectorType.Console) {
322
+ coreConfig.types.loggingConnector?.push({
323
+ type: LoggingConnectorType.Console,
324
+ options: {
325
+ config: {
326
+ translateMessages: true,
327
+ hideGroups: true
328
+ }
329
+ }
330
+ });
331
+ }
332
+ else if (loggingConnector === LoggingConnectorType.EntityStorage) {
333
+ coreConfig.types.loggingConnector?.push({
334
+ type: LoggingConnectorType.EntityStorage
335
+ });
336
+ }
337
+ }
338
+ if (loggingConnectors.length > 1) {
339
+ coreConfig.types.loggingConnector?.push({
340
+ type: LoggingConnectorType.Multi,
341
+ isDefault: true,
342
+ options: {
343
+ loggingConnectorTypes: loggingConnectors
344
+ }
345
+ });
346
+ }
347
+ }
348
+ /**
349
+ * Configures the vault connectors for the core.
350
+ * @param coreConfig The core config.
351
+ * @param envVars The environment variables.
352
+ */
353
+ function configureVaultConnectors(coreConfig, envVars) {
354
+ coreConfig.types.vaultConnector ??= [];
355
+ if (envVars.vaultConnector === VaultConnectorType.EntityStorage) {
356
+ coreConfig.types.vaultConnector.push({
357
+ type: VaultConnectorType.EntityStorage
358
+ });
359
+ }
360
+ else if (envVars.vaultConnector === VaultConnectorType.Hashicorp) {
361
+ coreConfig.types.vaultConnector.push({
362
+ type: VaultConnectorType.Hashicorp,
363
+ options: {
364
+ config: { endpoint: envVars.hashicorpVaultEndpoint, token: envVars.hashicorpVaultToken }
365
+ }
366
+ });
367
+ }
368
+ }
369
+ /**
370
+ * Configures the background task connectors for the core.
371
+ * @param coreConfig The core config.
372
+ * @param envVars The environment variables.
373
+ */
374
+ function configureBackgroundTaskConnectors(coreConfig, envVars) {
375
+ coreConfig.types.backgroundTaskConnector ??= [];
376
+ if (envVars.backgroundTaskConnector === BackgroundTaskConnectorType.EntityStorage) {
377
+ coreConfig.types.backgroundTaskConnector.push({
378
+ type: BackgroundTaskConnectorType.EntityStorage
379
+ });
380
+ }
381
+ }
382
+ /**
383
+ * Configures the telemetry connectors for the core.
384
+ * @param coreConfig The core config.
385
+ * @param envVars The environment variables.
386
+ */
387
+ function configureTelemetryConnectors(coreConfig, envVars) {
388
+ coreConfig.types.telemetryConnector ??= [];
389
+ if (envVars.telemetryConnector === TelemetryConnectorType.EntityStorage) {
390
+ coreConfig.types.telemetryConnector.push({
391
+ type: TelemetryConnectorType.EntityStorage
392
+ });
393
+ }
394
+ }
395
+ /**
396
+ * Configures the faucet connectors for the core.
397
+ * @param coreConfig The core config.
398
+ * @param envVars The environment variables.
399
+ */
400
+ function configureFaucetConnectors(coreConfig, envVars) {
401
+ coreConfig.types.faucetConnector ??= [];
402
+ if (envVars.faucetConnector === FaucetConnectorType.EntityStorage) {
403
+ coreConfig.types.faucetConnector.push({
404
+ type: FaucetConnectorType.EntityStorage
405
+ });
406
+ }
407
+ else if (envVars.faucetConnector === FaucetConnectorType.Iota) {
408
+ coreConfig.types.faucetConnector.push({
409
+ type: FaucetConnectorType.Iota,
410
+ options: {
411
+ config: {
412
+ endpoint: envVars.iotaFaucetEndpoint,
413
+ clientOptions: {
414
+ nodes: [envVars.iotaNodeEndpoint]
415
+ },
416
+ bech32Hrp: envVars.iotaBech32Hrp,
417
+ coinType: Coerce.number(envVars.iotaCoinType)
418
+ }
419
+ }
420
+ });
421
+ }
422
+ }
423
+ /**
424
+ * Configures the wallet connectors for the core.
425
+ * @param coreConfig The core config.
426
+ * @param envVars The environment variables.
427
+ */
428
+ function configureWalletConnectors(coreConfig, envVars) {
429
+ coreConfig.types.walletConnector ??= [];
430
+ if (envVars.walletConnector === WalletConnectorType.EntityStorage) {
431
+ coreConfig.types.walletConnector.push({
432
+ type: WalletConnectorType.EntityStorage
433
+ });
434
+ }
435
+ else if (envVars.walletConnector === WalletConnectorType.Iota) {
436
+ coreConfig.types.walletConnector.push({
437
+ type: WalletConnectorType.Iota,
438
+ options: {
439
+ config: {
440
+ clientOptions: {
441
+ nodes: [envVars.iotaNodeEndpoint]
442
+ },
443
+ bech32Hrp: envVars.iotaBech32Hrp,
444
+ coinType: Coerce.number(envVars.iotaCoinType)
445
+ }
446
+ }
447
+ });
448
+ }
449
+ }
450
+ /**
451
+ * Configures the NFT connectors for the core.
452
+ * @param coreConfig The core config.
453
+ * @param envVars The environment variables.
454
+ */
455
+ function configureNftConnectors(coreConfig, envVars) {
456
+ coreConfig.types.nftConnector ??= [];
457
+ if (envVars.nftConnector === NftConnectorType.EntityStorage) {
458
+ coreConfig.types.nftConnector.push({
459
+ type: NftConnectorType.EntityStorage
460
+ });
461
+ }
462
+ else if (envVars.nftConnector === NftConnectorType.Iota) {
463
+ coreConfig.types.nftConnector.push({
464
+ type: NftConnectorType.Iota,
465
+ options: {
466
+ config: {
467
+ clientOptions: {
468
+ nodes: [envVars.iotaNodeEndpoint]
469
+ },
470
+ bech32Hrp: envVars.iotaBech32Hrp,
471
+ coinType: Coerce.number(envVars.iotaCoinType)
472
+ }
473
+ }
474
+ });
475
+ }
476
+ }
477
+ /**
478
+ * Configures the immutable storage connectors for the core.
479
+ * @param coreConfig The core config.
480
+ * @param envVars The environment variables.
481
+ */
482
+ function configureImmutableStorageConnectors(coreConfig, envVars) {
483
+ coreConfig.types.immutableStorageConnector ??= [];
484
+ if (envVars.immutableStorageConnector === ImmutableStorageConnectorType.EntityStorage) {
485
+ coreConfig.types.immutableStorageConnector.push({
486
+ type: ImmutableStorageConnectorType.EntityStorage
487
+ });
488
+ }
489
+ else if (envVars.immutableStorageConnector === ImmutableStorageConnectorType.Iota) {
490
+ coreConfig.types.immutableStorageConnector.push({
491
+ type: ImmutableStorageConnectorType.Iota,
492
+ options: {
493
+ config: {
494
+ clientOptions: {
495
+ nodes: [envVars.iotaNodeEndpoint]
496
+ },
497
+ bech32Hrp: envVars.iotaBech32Hrp,
498
+ coinType: Coerce.number(envVars.iotaCoinType)
499
+ }
500
+ }
501
+ });
502
+ }
503
+ }
504
+ /**
505
+ * Configures the identity connectors for the core.
506
+ * @param coreConfig The core config.
507
+ * @param envVars The environment variables.
508
+ */
509
+ function configureIdentityConnectors(coreConfig, envVars) {
510
+ coreConfig.types.identityConnector ??= [];
511
+ if (envVars.identityConnector === IdentityConnectorType.EntityStorage) {
512
+ coreConfig.types.identityConnector.push({
513
+ type: IdentityConnectorType.EntityStorage
514
+ });
515
+ }
516
+ else if (envVars.identityConnector === IdentityConnectorType.Iota) {
517
+ coreConfig.types.identityConnector.push({
518
+ type: IdentityConnectorType.Iota,
519
+ options: {
520
+ config: {
521
+ clientOptions: {
522
+ nodes: [envVars.iotaNodeEndpoint]
523
+ },
524
+ bech32Hrp: envVars.iotaBech32Hrp,
525
+ coinType: Coerce.number(envVars.iotaCoinType)
526
+ }
527
+ }
528
+ });
529
+ }
530
+ }
531
+ /**
532
+ * Configures the identity profile connectors for the core.
533
+ * @param coreConfig The core config.
534
+ * @param envVars The environment variables.
535
+ */
536
+ function configureIdentityProfileConnectors(coreConfig, envVars) {
537
+ coreConfig.types.identityProfileConnector ??= [];
538
+ if (envVars.identityProfileConnector === IdentityConnectorType.EntityStorage) {
539
+ coreConfig.types.identityProfileConnector.push({
540
+ type: IdentityProfileConnectorType.EntityStorage
541
+ });
542
+ }
543
+ }
544
+ /**
545
+ * Configures the attestation connectors for the core.
546
+ * @param coreConfig The core config.
547
+ * @param envVars The environment variables.
548
+ */
549
+ function configureAttestationConnectors(coreConfig, envVars) {
550
+ coreConfig.types.attestationConnector ??= [];
551
+ if (envVars.attestationConnector === AttestationConnectorType.EntityStorage) {
552
+ coreConfig.types.attestationConnector.push({
553
+ type: AttestationConnectorType.EntityStorage
554
+ });
555
+ }
556
+ else if (envVars.attestationConnector === AttestationConnectorType.Iota) {
557
+ coreConfig.types.attestationConnector.push({
558
+ type: AttestationConnectorType.Iota
559
+ });
560
+ }
561
+ }
562
+
563
+ // Copyright 2024 IOTA Stiftung.
564
+ // SPDX-License-Identifier: Apache-2.0.
565
+ /**
566
+ * Environment variable helper.
567
+ */
568
+ class EnvHelper {
569
+ /**
570
+ * Get the environment variable as an object with camel cased names.
571
+ * @param envVars The environment variables.
572
+ * @param prefix The prefix of the environment variables.
573
+ * @returns The object with camel cased names.
574
+ */
575
+ static envToJson(envVars, prefix) {
576
+ const result = {};
577
+ for (const envVar in envVars) {
578
+ if (envVar.startsWith(prefix) && Is.stringValue(process.env[envVar])) {
579
+ const camelCaseName = StringHelper.camelCase(envVar.replace(prefix, "").toLowerCase());
580
+ ObjectHelper.propertySet(result, camelCaseName, process.env[envVar]);
581
+ }
582
+ }
583
+ return result;
584
+ }
585
+ }
586
+
587
+ export { Engine, EnvHelper, buildEngineConfiguration };
@@ -0,0 +1,17 @@
1
+ import { EngineCore, type IEngineCoreOptions } from "@twin.org/engine-core";
2
+ import type { IEngineState } from "@twin.org/engine-models";
3
+ import type { IEngineCoreTypesConfig } from "@twin.org/engine-types";
4
+ /**
5
+ * The engine with built in types.
6
+ */
7
+ export declare class Engine<C extends IEngineCoreTypesConfig = IEngineCoreTypesConfig, S extends IEngineState = IEngineState> extends EngineCore<C, S> {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of Engine.
14
+ * @param options The options for the engine.
15
+ */
16
+ constructor(options?: IEngineCoreOptions<C, S>);
17
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./engine";
2
+ export * from "./models/IEngineEnvironmentVariables";
3
+ export * from "./utils/engineEnvBuilder";
4
+ export * from "./utils/envHelper";