@twin.org/node-core 0.9.2-next.6 → 0.9.2-next.8

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.
@@ -1,13 +1,14 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import path from "node:path";
4
- import { Coerce, Is, Mutex } from "@twin.org/core";
4
+ import { Is, Mutex } from "@twin.org/core";
5
5
  import { AttestationComponentType, AttestationConnectorType, AuditableItemGraphComponentType, AuditableItemStreamComponentType, AutomationComponentType, BackgroundTaskComponentType, BlobStorageComponentType, BlobStorageConnectorType, ContextIdHandlerComponentType, DataProcessingComponentType, DataspaceControlPlaneComponentType, DataspaceDataPlaneComponentType, DltConfigType, DocumentManagementComponentType, EngineTypeHelper, EntityStorageConnectorType, EventBusComponentType, EventBusConnectorType, FaucetConnectorType, FederatedCatalogueComponentType, HealthComponentType, IdentityComponentType, IdentityConnectorType, IdentityProfileComponentType, IdentityProfileConnectorType, IdentityResolverComponentType, IdentityResolverConnectorType, ImmutableProofComponentType, LoggingComponentType, LoggingConnectorType, MessagingAdminComponentType, MessagingComponentType, MessagingEmailConnectorType, MessagingPushNotificationConnectorType, MessagingSmsConnectorType, MetricsCollectorComponentType, MetricsProducerComponentType, NftComponentType, NftConnectorType, NotarizationComponentType, NotarizationConnectorType, PlatformComponentType, RightsManagementPapComponentType, RightsManagementPdpComponentType, RightsManagementPepComponentType, RightsManagementPipComponentType, RightsManagementPmpComponentType, RightsManagementPnapComponentType, RightsManagementPnpComponentType, RightsManagementPxpComponentType, SchemaVersionMigrationComponentType, TaskSchedulerComponentType, TelemetryComponentType, TelemetryConnectorType, TenantAdminComponentType, TracingComponentType, TracingConnectorType, TrustComponentType, TrustVerifierComponentType, VaultConnectorType, WalletConnectorType } from "@twin.org/engine-types";
6
6
  import { OpenTelemetryExporterTypes } from "@twin.org/logging-connector-opentelemetry";
7
7
  import { OpenTelemetryReaderTypes } from "@twin.org/telemetry-connector-opentelemetry";
8
8
  import { OpenTelemetryProcessorTypes } from "@twin.org/tracing-connector-opentelemetry";
9
9
  import { CONTEXT_ID_HANDLER_FEATURE_DID, CONTEXT_ID_HANDLER_FEATURE_TENANT } from "../defaults.js";
10
10
  import { isAuthEntityStorageRequired } from "./engineServerEnvBuilder.js";
11
+ import { commaSeparatedListToArray, envBoolean, envCount, envDateTime, envInteger, envMinToMs, envMinutes, envMs, envSecToMs, envSeconds } from "./helper/envHelpers.js";
11
12
  /**
12
13
  * Build the engine core configuration from environment variables.
13
14
  * @param envVars The environment variables.
@@ -20,12 +21,12 @@ export async function buildEngineConfiguration(envVars) {
20
21
  envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
21
22
  }
22
23
  const coreConfig = {
23
- debug: Coerce.boolean(envVars.debug) ?? false,
24
- silent: Coerce.boolean(envVars.silent) ?? false,
24
+ debug: envBoolean(envVars, "debug", false),
25
+ silent: envBoolean(envVars, "silent", false),
25
26
  silentLoggers: commaSeparatedListToArray(envVars.loggingSilentComponents),
26
27
  types: {}
27
28
  };
28
- const mutexTimeoutMs = Coerce.integer(envVars.mutexTimeoutMsDefault);
29
+ const mutexTimeoutMs = envMs(envVars, "mutexTimeoutDefault");
29
30
  if (!Is.empty(mutexTimeoutMs)) {
30
31
  Mutex.setDefaultTimeoutMs(mutexTimeoutMs);
31
32
  }
@@ -81,7 +82,7 @@ async function configureEntityStorage(coreConfig, envVars) {
81
82
  type: EntityStorageConnectorType.Memory,
82
83
  options: {
83
84
  config: {
84
- mutexTimeoutMs: Coerce.integer(envVars.entityStorageMemoryMutexTimeout)
85
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
85
86
  }
86
87
  }
87
88
  });
@@ -92,7 +93,7 @@ async function configureEntityStorage(coreConfig, envVars) {
92
93
  options: {
93
94
  config: {
94
95
  directory: envVars.storageFileRoot ?? "",
95
- mutexTimeoutMs: Coerce.integer(envVars.entityStorageFileMutexTimeout)
96
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
96
97
  },
97
98
  folderPrefix: envVars.entityStorageTablePrefix
98
99
  }
@@ -108,7 +109,8 @@ async function configureEntityStorage(coreConfig, envVars) {
108
109
  accessKeyId: envVars.awsDynamodbAccessKeyId,
109
110
  secretAccessKey: envVars.awsDynamodbSecretAccessKey,
110
111
  endpoint: envVars.awsDynamodbEndpoint,
111
- connectionTimeoutMs: Coerce.integer(envVars.awsDynamodbConnectionTimeout)
112
+ connectionTimeoutMs: envMs(envVars, "awsDynamodbConnectionTimeout"),
113
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
112
114
  },
113
115
  tablePrefix: envVars.entityStorageTablePrefix
114
116
  }
@@ -122,7 +124,8 @@ async function configureEntityStorage(coreConfig, envVars) {
122
124
  endpoint: envVars.azureCosmosdbEndpoint ?? "",
123
125
  key: envVars.azureCosmosdbKey ?? "",
124
126
  databaseId: envVars.azureCosmosdbDatabaseId ?? "",
125
- containerId: envVars.azureCosmosdbContainerId ?? ""
127
+ containerId: envVars.azureCosmosdbContainerId ?? "",
128
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
126
129
  },
127
130
  tablePrefix: envVars.entityStorageTablePrefix
128
131
  }
@@ -137,7 +140,8 @@ async function configureEntityStorage(coreConfig, envVars) {
137
140
  credentials: envVars.gcpFirestoreCredentials ?? "",
138
141
  databaseId: envVars.gcpFirestoreDatabaseId ?? "",
139
142
  collectionName: envVars.gcpFirestoreCollectionName ?? "",
140
- endpoint: envVars.gcpFirestoreEndpoint ?? ""
143
+ endpoint: envVars.gcpFirestoreEndpoint ?? "",
144
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
141
145
  },
142
146
  tablePrefix: envVars.entityStorageTablePrefix
143
147
  }
@@ -151,7 +155,8 @@ async function configureEntityStorage(coreConfig, envVars) {
151
155
  hosts: commaSeparatedListToArray(envVars.scylladbHosts),
152
156
  localDataCenter: envVars.scylladbLocalDataCenter ?? "",
153
157
  keyspace: envVars.scylladbKeyspace ?? "",
154
- port: Coerce.integer(envVars.scylladbPort)
158
+ port: envInteger(envVars, "scylladbPort"),
159
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
155
160
  },
156
161
  tablePrefix: envVars.entityStorageTablePrefix
157
162
  }
@@ -163,10 +168,11 @@ async function configureEntityStorage(coreConfig, envVars) {
163
168
  options: {
164
169
  config: {
165
170
  host: envVars.mySqlHost ?? "",
166
- port: Coerce.integer(envVars.mySqlPort),
171
+ port: envInteger(envVars, "mySqlPort"),
167
172
  user: envVars.mySqlUser ?? "",
168
173
  password: envVars.mySqlPassword ?? "",
169
- database: envVars.mySqlDatabase ?? ""
174
+ database: envVars.mySqlDatabase ?? "",
175
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
170
176
  },
171
177
  tablePrefix: envVars.entityStorageTablePrefix
172
178
  }
@@ -178,10 +184,11 @@ async function configureEntityStorage(coreConfig, envVars) {
178
184
  options: {
179
185
  config: {
180
186
  host: envVars.mongoDbHost ?? "",
181
- port: Coerce.integer(envVars.mongoDbPort),
187
+ port: envInteger(envVars, "mongoDbPort"),
182
188
  user: envVars.mongoDbUser ?? "",
183
189
  password: envVars.mongoDbPassword ?? "",
184
- database: envVars.mongoDbDatabase ?? ""
190
+ database: envVars.mongoDbDatabase ?? "",
191
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
185
192
  },
186
193
  tablePrefix: envVars.entityStorageTablePrefix
187
194
  }
@@ -193,10 +200,11 @@ async function configureEntityStorage(coreConfig, envVars) {
193
200
  options: {
194
201
  config: {
195
202
  host: envVars.postgreSqlHost ?? "",
196
- port: Coerce.integer(envVars.postgreSqlPort),
203
+ port: envInteger(envVars, "postgreSqlPort"),
197
204
  user: envVars.postgreSqlUser ?? "",
198
205
  password: envVars.postgreSqlPassword ?? "",
199
- database: envVars.postgreSqlDatabase ?? ""
206
+ database: envVars.postgreSqlDatabase ?? "",
207
+ mutexTimeoutMs: envMs(envVars, "entityStorageMutexTimeout")
200
208
  },
201
209
  tablePrefix: envVars.entityStorageTablePrefix
202
210
  }
@@ -344,13 +352,13 @@ async function configureLogging(coreConfig, envVars) {
344
352
  type: LoggingConnectorType.EntityStorage,
345
353
  options: {
346
354
  config: {
347
- batchSize: Coerce.integer(envVars.loggingBatchSize),
348
- batchIntervalMs: (Coerce.integer(envVars.loggingBatchFlushInterval) ?? 5) * 1000,
349
- retainForMs: (Coerce.integer(envVars.loggingRetainFor) ?? 2880) * 60_000,
350
- maxEntries: Coerce.integer(envVars.loggingMaxEntries),
351
- retentionIntervalMs: (Coerce.integer(envVars.loggingRetentionInterval) ?? 5) * 60_000,
352
- retentionBatchSize: Coerce.integer(envVars.loggingRetentionBatchSize),
353
- mutexTimeoutMs: Coerce.integer(envVars.loggingMutexTimeout)
355
+ batchSize: envCount(envVars, "loggingBatchSize"),
356
+ batchIntervalMs: envSecToMs(envVars, "loggingBatchFlushInterval"),
357
+ retainForMs: envMinToMs(envVars, "loggingRetainFor"),
358
+ maxEntries: envCount(envVars, "loggingMaxEntries"),
359
+ retentionIntervalMs: envMinToMs(envVars, "loggingRetentionInterval"),
360
+ retentionBatchSize: envCount(envVars, "loggingRetentionBatchSize"),
361
+ mutexTimeoutMs: envMs(envVars, "loggingMutexTimeout")
354
362
  }
355
363
  }
356
364
  });
@@ -386,9 +394,9 @@ async function configureLogging(coreConfig, envVars) {
386
394
  config: {
387
395
  directory: envVars.loggingFileDirectory ?? envVars.storageFileRoot ?? "",
388
396
  filename: envVars.loggingFileFilename,
389
- maxFileSizeBytes: Coerce.integer(envVars.loggingFileMaxFileSizeBytes),
390
- maxRetainedFiles: Coerce.integer(envVars.loggingFileMaxRetainedFiles),
391
- mutexTimeoutMs: Coerce.integer(envVars.loggingMutexTimeout)
397
+ maxFileSizeBytes: envCount(envVars, "loggingFileMaxFileSizeBytes"),
398
+ maxRetainedFiles: envCount(envVars, "loggingFileMaxRetainedFiles"),
399
+ mutexTimeoutMs: envMs(envVars, "loggingMutexTimeout")
392
400
  }
393
401
  }
394
402
  });
@@ -494,7 +502,7 @@ async function configureTelemetry(coreConfig, envVars) {
494
502
  type: TelemetryConnectorType.EntityStorage,
495
503
  options: {
496
504
  config: {
497
- mutexTimeoutMs: Coerce.integer(envVars.telemetryMutexTimeout)
505
+ mutexTimeoutMs: envMs(envVars, "telemetryMutexTimeout")
498
506
  }
499
507
  }
500
508
  });
@@ -505,7 +513,7 @@ async function configureTelemetry(coreConfig, envVars) {
505
513
  readers = {
506
514
  prometheus: {
507
515
  type: OpenTelemetryReaderTypes.Prometheus,
508
- port: Coerce.integer(envVars.openTelemetryPrometheusPort)
516
+ port: envCount(envVars, "openTelemetryPrometheusPort")
509
517
  }
510
518
  };
511
519
  }
@@ -513,7 +521,7 @@ async function configureTelemetry(coreConfig, envVars) {
513
521
  type: TelemetryConnectorType.OpenTelemetry,
514
522
  options: {
515
523
  config: {
516
- mutexTimeoutMs: Coerce.integer(envVars.telemetryMutexTimeout),
524
+ mutexTimeoutMs: envMs(envVars, "telemetryMutexTimeout"),
517
525
  meterName: envVars.openTelemetryMeterName,
518
526
  meterVersion: envVars.openTelemetryMeterVersion,
519
527
  readers
@@ -534,21 +542,23 @@ async function configureTelemetry(coreConfig, envVars) {
534
542
  */
535
543
  async function configureMetricsCollector(coreConfig, envVars) {
536
544
  if (isTelemetryRequired(envVars)) {
537
- const intervalSec = Coerce.integer(envVars.telemetryMetricsCollectorInterval) ?? 60;
538
545
  coreConfig.types.metricsCollectorComponent ??= [];
539
546
  coreConfig.types.metricsCollectorComponent.push({
540
547
  type: MetricsCollectorComponentType.Service,
541
- options: { config: { intervalMs: intervalSec * 1000 } },
548
+ options: {
549
+ config: {
550
+ intervalMs: envSecToMs(envVars, "telemetryMetricsCollectorInterval")
551
+ }
552
+ },
542
553
  isCloneable: false
543
554
  });
544
- const maxHistory = Coerce.integer(envVars.telemetryMetricsProducerMaxHistory) ?? 1440;
545
555
  coreConfig.types.metricsProducerComponent ??= [];
546
556
  const metricsProducers = commaSeparatedListToArray(envVars.telemetryMetricsProducers ??
547
557
  [MetricsProducerComponentType.System, MetricsProducerComponentType.Process].join(","));
548
558
  for (const producerType of metricsProducers) {
549
559
  coreConfig.types.metricsProducerComponent.push({
550
560
  type: producerType,
551
- options: { maxHistory },
561
+ options: { maxHistory: envCount(envVars, "telemetryMetricsProducerMaxHistory") },
552
562
  isCloneable: false
553
563
  });
554
564
  }
@@ -567,7 +577,7 @@ async function configureTracing(coreConfig, envVars) {
567
577
  type: TracingConnectorType.EntityStorage,
568
578
  options: {
569
579
  config: {
570
- mutexTimeoutMs: Coerce.integer(envVars.tracingMutexTimeout)
580
+ mutexTimeoutMs: envMs(envVars, "tracingMutexTimeout")
571
581
  }
572
582
  }
573
583
  });
@@ -630,14 +640,14 @@ async function configureAutomation(coreConfig, envVars) {
630
640
  */
631
641
  async function configureHealth(coreConfig, envVars) {
632
642
  coreConfig.types.healthComponent ??= [];
633
- if (Coerce.boolean(envVars.healthEnabled) ?? false) {
643
+ if (envBoolean(envVars, "healthEnabled", false)) {
634
644
  coreConfig.types.healthComponent.push({
635
645
  type: HealthComponentType.Service,
636
646
  options: {
637
647
  config: {
638
- healthCheckInterval: (Coerce.integer(envVars.healthInterval) ?? 60) * 1000,
639
- healthCheckApplicationInterval: (Coerce.integer(envVars.healthApplicationInterval) ?? 300) * 1000,
640
- initialInterval: (Coerce.integer(envVars.healthStartupInterval) ?? 2) * 1000
648
+ healthCheckInterval: envSecToMs(envVars, "healthInterval"),
649
+ healthCheckApplicationInterval: envSecToMs(envVars, "healthApplicationInterval"),
650
+ initialInterval: envSecToMs(envVars, "healthStartupInterval")
641
651
  }
642
652
  },
643
653
  isCloneable: false
@@ -651,7 +661,7 @@ async function configureHealth(coreConfig, envVars) {
651
661
  * @returns A promise that resolves when the schema migration configuration has been applied.
652
662
  */
653
663
  async function configureSchemaMigration(coreConfig, envVars) {
654
- const isSchemaMigrationEnabled = Coerce.boolean(envVars.schemaMigrationEnabled) ?? true;
664
+ const isSchemaMigrationEnabled = envBoolean(envVars, "schemaMigrationEnabled", true);
655
665
  if (isSchemaMigrationEnabled) {
656
666
  coreConfig.types.schemaVersionMigrationComponent ??= [];
657
667
  coreConfig.types.schemaVersionMigrationComponent.push({
@@ -667,7 +677,7 @@ async function configureSchemaMigration(coreConfig, envVars) {
667
677
  * @returns A promise that resolves when the platform configuration has been applied.
668
678
  */
669
679
  async function configurePlatform(coreConfig, envVars) {
670
- const isTenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
680
+ const isTenantEnabled = envBoolean(envVars, "tenantEnabled", false);
671
681
  coreConfig.types.platformComponent ??= [];
672
682
  coreConfig.types.platformComponent.push({
673
683
  type: PlatformComponentType.Service,
@@ -685,7 +695,7 @@ async function configurePlatform(coreConfig, envVars) {
685
695
  * @returns A promise that resolves when the tenant configuration has been applied.
686
696
  */
687
697
  async function configureTenant(coreConfig, envVars) {
688
- const isTenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
698
+ const isTenantEnabled = envBoolean(envVars, "tenantEnabled", false);
689
699
  if (isTenantEnabled) {
690
700
  coreConfig.types.tenantAdminComponent ??= [];
691
701
  coreConfig.types.tenantAdminComponent.push({
@@ -705,7 +715,7 @@ async function configureContextIdHandlers(coreConfig, envVars) {
705
715
  type: ContextIdHandlerComponentType.Did,
706
716
  features: [CONTEXT_ID_HANDLER_FEATURE_DID]
707
717
  });
708
- if (Coerce.boolean(envVars.tenantEnabled) ?? false) {
718
+ if (envBoolean(envVars, "tenantEnabled", false)) {
709
719
  coreConfig.types.contextIdHandlerComponent.push({
710
720
  type: ContextIdHandlerComponentType.Tenant,
711
721
  features: [CONTEXT_ID_HANDLER_FEATURE_TENANT]
@@ -719,7 +729,7 @@ async function configureContextIdHandlers(coreConfig, envVars) {
719
729
  * @returns A promise that resolves when the messaging configuration has been applied.
720
730
  */
721
731
  async function configureMessaging(coreConfig, envVars) {
722
- if (Coerce.boolean(envVars.messagingEnabled) ?? false) {
732
+ if (envBoolean(envVars, "messagingEnabled", false)) {
723
733
  coreConfig.types.messagingEmailConnector ??= [];
724
734
  coreConfig.types.messagingSmsConnector ??= [];
725
735
  coreConfig.types.messagingPushNotificationConnector ??= [];
@@ -923,9 +933,15 @@ async function configureImmutableProof(coreConfig, envVars) {
923
933
  options: {
924
934
  config: {
925
935
  verificationMethodId: envVars.immutableProofVerificationMethodId,
926
- taskRetryCount: Coerce.integer(envVars.immutableProofTaskRetryCount),
927
- taskRetryInterval: (Coerce.integer(envVars.immutableProofTaskRetryInterval) ?? 5) * 1000,
928
- taskFailureRetainFor: (Coerce.integer(envVars.immutableProofTaskFailureRetainFor) ?? 10080) * 60_000
936
+ taskRetryCount: envCount(envVars, "immutableProofTaskRetryCount"),
937
+ taskRetryInterval: envSecToMs(envVars, "immutableProofTaskRetryInterval"),
938
+ taskFailureRetainFor: envMinToMs(envVars, "immutableProofTaskFailureRetainFor"),
939
+ sweepIntervalMinutes: envMinutes(envVars, "immutableProofSweepInterval"),
940
+ sweepStaleThresholdMs: envMinToMs(envVars, "immutableProofSweepStaleThreshold"),
941
+ sweepMaxAttempts: envCount(envVars, "immutableProofSweepMaxAttempts"),
942
+ sweepBatchLimit: envCount(envVars, "immutableProofSweepBatchLimit"),
943
+ sweepBackoffMs: envMinToMs(envVars, "immutableProofSweepBackoff"),
944
+ sweepAssumeRetryableBefore: envDateTime(envVars, "immutableProofSweepAssumeRetryableBefore")
929
945
  }
930
946
  }
931
947
  });
@@ -954,8 +970,10 @@ async function configureIdentity(coreConfig, envVars) {
954
970
  identityPkgId: Is.stringValue(envVars.iotaIdentityPackageId)
955
971
  ? envVars.iotaIdentityPackageId
956
972
  : undefined,
957
- walletAddressIndex: Coerce.integer(envVars.identityWalletAddressIndex) ?? 0,
958
- didResolutionCacheTtlMs: Coerce.integer(envVars.identityDidResolutionCacheTtlMs)
973
+ walletAddressIndex: envCount(envVars, "identityWalletAddressIndex") ?? 0,
974
+ didResolutionCacheTtlMs: envMs(envVars, "identityDidResolutionCacheTtl"),
975
+ didResolutionCacheCapacity: envCount(envVars, "identityDidResolutionCacheCapacity"),
976
+ didResolutionCacheMutexTimeoutMs: envMs(envVars, "identityDidResolutionCacheMutexTimeout")
959
977
  }
960
978
  }
961
979
  });
@@ -1059,13 +1077,13 @@ async function configureAttestation(coreConfig, envVars) {
1059
1077
  * @returns A promise that resolves when the auditable item graph configuration has been applied.
1060
1078
  */
1061
1079
  async function configureAuditableItemGraph(coreConfig, envVars) {
1062
- if (Coerce.boolean(envVars.auditableItemGraphEnabled) ?? false) {
1080
+ if (envBoolean(envVars, "auditableItemGraphEnabled", false)) {
1063
1081
  coreConfig.types.auditableItemGraphComponent ??= [];
1064
1082
  coreConfig.types.auditableItemGraphComponent.push({
1065
1083
  type: AuditableItemGraphComponentType.Service,
1066
1084
  options: {
1067
1085
  config: {
1068
- mutexTimeoutMs: Coerce.integer(envVars.auditableItemGraphMutexTimeout)
1086
+ mutexTimeoutMs: envMs(envVars, "auditableItemGraphMutexTimeout")
1069
1087
  }
1070
1088
  }
1071
1089
  });
@@ -1078,13 +1096,13 @@ async function configureAuditableItemGraph(coreConfig, envVars) {
1078
1096
  * @returns A promise that resolves when the auditable item stream configuration has been applied.
1079
1097
  */
1080
1098
  async function configureAuditableItemStream(coreConfig, envVars) {
1081
- if (Coerce.boolean(envVars.auditableItemStreamEnabled) ?? false) {
1099
+ if (envBoolean(envVars, "auditableItemStreamEnabled", false)) {
1082
1100
  coreConfig.types.auditableItemStreamComponent ??= [];
1083
1101
  coreConfig.types.auditableItemStreamComponent.push({
1084
1102
  type: AuditableItemStreamComponentType.Service,
1085
1103
  options: {
1086
1104
  config: {
1087
- mutexTimeoutMs: Coerce.integer(envVars.auditableItemStreamMutexTimeout)
1105
+ mutexTimeoutMs: envMs(envVars, "auditableItemStreamMutexTimeout")
1088
1106
  }
1089
1107
  }
1090
1108
  });
@@ -1097,7 +1115,7 @@ async function configureAuditableItemStream(coreConfig, envVars) {
1097
1115
  * @returns A promise that resolves when the data processing configuration has been applied.
1098
1116
  */
1099
1117
  async function configureDataProcessing(coreConfig, envVars) {
1100
- if (Coerce.boolean(envVars.dataProcessingEnabled) ?? false) {
1118
+ if (envBoolean(envVars, "dataProcessingEnabled", false)) {
1101
1119
  coreConfig.types.dataProcessingComponent ??= [];
1102
1120
  coreConfig.types.dataProcessingComponent.push({ type: DataProcessingComponentType.Service });
1103
1121
  coreConfig.types.dataConverterConnector ??= [];
@@ -1123,13 +1141,13 @@ async function configureDataProcessing(coreConfig, envVars) {
1123
1141
  * @returns A promise that resolves when the document management configuration has been applied.
1124
1142
  */
1125
1143
  async function configureDocumentManagement(coreConfig, envVars) {
1126
- if (Coerce.boolean(envVars.documentManagementEnabled) ?? false) {
1144
+ if (envBoolean(envVars, "documentManagementEnabled", false)) {
1127
1145
  coreConfig.types.documentManagementComponent ??= [];
1128
1146
  coreConfig.types.documentManagementComponent.push({
1129
1147
  type: DocumentManagementComponentType.Service,
1130
1148
  options: {
1131
1149
  config: {
1132
- mutexTimeoutMs: Coerce.integer(envVars.documentManagementMutexTimeout)
1150
+ mutexTimeoutMs: envMs(envVars, "documentManagementMutexTimeout")
1133
1151
  }
1134
1152
  }
1135
1153
  });
@@ -1155,7 +1173,7 @@ async function configureTrust(coreConfig, envVars) {
1155
1173
  options: {
1156
1174
  config: {
1157
1175
  verificationMethodId: envVars.trustVerificationMethodId ?? "",
1158
- tokenTtlInSeconds: Coerce.integer(envVars.trustJwtTtl)
1176
+ tokenTtlInSeconds: envCount(envVars, "trustJwtTtl")
1159
1177
  }
1160
1178
  }
1161
1179
  });
@@ -1240,7 +1258,7 @@ async function configureRightsManagement(coreConfig, envVars) {
1240
1258
  config: {
1241
1259
  callbackPath: rightsManagementPath,
1242
1260
  includeErrorDetails: coreConfig.debug ?? false,
1243
- mutexTimeoutMs: Coerce.integer(envVars.rightsManagementMutexTimeout)
1261
+ mutexTimeoutMs: envMs(envVars, "rightsManagementMutexTimeout")
1244
1262
  }
1245
1263
  },
1246
1264
  isDefault: true
@@ -1250,7 +1268,7 @@ async function configureRightsManagement(coreConfig, envVars) {
1250
1268
  type: RightsManagementPnapComponentType.Service,
1251
1269
  options: {
1252
1270
  config: {
1253
- mutexTimeoutMs: Coerce.integer(envVars.rightsManagementMutexTimeout)
1271
+ mutexTimeoutMs: envMs(envVars, "rightsManagementMutexTimeout")
1254
1272
  }
1255
1273
  }
1256
1274
  });
@@ -1342,7 +1360,7 @@ async function configureFederatedCatalogue(coreConfig, envVars) {
1342
1360
  type: FederatedCatalogueComponentType.Service,
1343
1361
  options: {
1344
1362
  config: {
1345
- mutexTimeoutMs: Coerce.integer(envVars.federatedCatalogueMutexTimeout)
1363
+ mutexTimeoutMs: envMs(envVars, "federatedCatalogueMutexTimeout")
1346
1364
  }
1347
1365
  }
1348
1366
  });
@@ -1364,7 +1382,7 @@ async function configureFederatedCatalogue(coreConfig, envVars) {
1364
1382
  * @returns A promise that resolves when the dataspace configuration has been applied.
1365
1383
  */
1366
1384
  async function configureDataspace(coreConfig, envVars) {
1367
- if (Coerce.boolean(envVars.dataspaceEnabled) ?? false) {
1385
+ if (envBoolean(envVars, "dataspaceEnabled", false)) {
1368
1386
  coreConfig.types.dataspaceControlPlaneComponent ??= [];
1369
1387
  // We add a multi instance REST client for remote/consumer-initiated transfers.
1370
1388
  coreConfig.types.dataspaceControlPlaneComponent.push({
@@ -1375,8 +1393,6 @@ async function configureDataspace(coreConfig, envVars) {
1375
1393
  isMultiInstance: true,
1376
1394
  features: ["remote"]
1377
1395
  });
1378
- const stalledNegotiationTimeout = Coerce.integer(envVars.dataspaceStalledNegotiationTimeout);
1379
- const stalledTransferTimeout = Coerce.integer(envVars.dataspaceStalledTransferTimeout);
1380
1396
  coreConfig.types.dataspaceControlPlaneComponent.push({
1381
1397
  type: DataspaceControlPlaneComponentType.Service,
1382
1398
  options: {
@@ -1387,30 +1403,29 @@ async function configureDataspace(coreConfig, envVars) {
1387
1403
  // Base mount path of the data plane only; the transfer handlers append the
1388
1404
  // sub-paths themselves (`/entities` for PULL, `/inbox` for PUSH).
1389
1405
  dataPlanePath: envVars.dataspaceDataPlanePath,
1390
- autoStartTransfers: Coerce.boolean(envVars.dataspaceAutoStartTransfers),
1391
- stalledNegotiationTimeoutMs: !Is.empty(stalledNegotiationTimeout)
1392
- ? stalledNegotiationTimeout * 1000
1393
- : undefined,
1394
- stalledTransferTimeoutMs: !Is.empty(stalledTransferTimeout)
1395
- ? stalledTransferTimeout * 1000
1396
- : undefined
1406
+ autoStartTransfers: envBoolean(envVars, "dataspaceAutoStartTransfers", false),
1407
+ stalledNegotiationTimeoutMs: envSecToMs(envVars, "dataspaceStalledNegotiationTimeout"),
1408
+ stalledTransferTimeoutMs: envSecToMs(envVars, "dataspaceStalledTransferTimeout"),
1409
+ providerTransferIdleTimeoutMs: envSecToMs(envVars, "dataspaceProviderTransferIdleTimeout"),
1410
+ providerTransferPolicySweepIntervalMs: envSecToMs(envVars, "dataspaceProviderTransferPolicySweepInterval")
1397
1411
  }
1398
1412
  },
1399
1413
  isDefault: true
1400
1414
  });
1401
- const retainActivityLogsFor = Coerce.integer(envVars.dataspaceRetainActivityLogsFor);
1402
- const activityLogsCleanUpInterval = Coerce.integer(envVars.dataspaceActivityLogsCleanupInterval);
1403
1415
  coreConfig.types.dataspaceDataPlaneComponent ??= [];
1404
1416
  coreConfig.types.dataspaceDataPlaneComponent.push({
1405
1417
  type: DataspaceDataPlaneComponentType.Service,
1406
1418
  options: {
1407
1419
  config: {
1408
- retainActivityLogsForMs: !Is.empty(retainActivityLogsFor)
1409
- ? retainActivityLogsFor * 1000
1410
- : undefined,
1411
- activityLogsCleanUpIntervalMs: !Is.empty(activityLogsCleanUpInterval)
1412
- ? activityLogsCleanUpInterval * 1000
1413
- : undefined
1420
+ retainActivityLogsForMs: envSecToMs(envVars, "dataspaceRetainActivityLogsFor"),
1421
+ activityLogsCleanUpIntervalMs: envSecToMs(envVars, "dataspaceActivityLogsCleanupInterval"),
1422
+ retryCount: envCount(envVars, "dataspaceRetryCount"),
1423
+ pushRetryCount: envCount(envVars, "dataspacePushRetryCount"),
1424
+ pushRetryBaseDelayMs: envMs(envVars, "dataspacePushRetryBaseDelay"),
1425
+ pushTimeoutMs: envMs(envVars, "dataspacePushTimeout"),
1426
+ pushSubscriptionCleanupIntervalMs: envMs(envVars, "dataspacePushSubscriptionCleanupInterval"),
1427
+ agreementCacheTtlMs: envMs(envVars, "dataspaceAgreementCacheTtl"),
1428
+ agreementCacheMutexTimeoutMs: envMs(envVars, "dataspaceAgreementCacheMutexTimeout")
1414
1429
  }
1415
1430
  }
1416
1431
  });
@@ -1442,26 +1457,15 @@ async function configureDlt(coreConfig, envVars) {
1442
1457
  url: envVars.iotaNodeEndpoint ?? ""
1443
1458
  },
1444
1459
  network: envVars.iotaNetwork ?? "",
1445
- coinType: Coerce.integer(envVars.iotaCoinType),
1460
+ coinType: envCount(envVars, "iotaCoinType"),
1446
1461
  gasStation: gasStationConfig,
1447
- gasBudget: Coerce.integer(envVars.iotaGasBudget),
1448
- gasReservationDuration: Coerce.integer(envVars.iotaGasReservationDuration)
1462
+ gasBudget: envCount(envVars, "iotaGasBudget"),
1463
+ gasReservationDuration: envSeconds(envVars, "iotaGasReservationDuration")
1449
1464
  }
1450
1465
  }
1451
1466
  });
1452
1467
  }
1453
1468
  }
1454
- /**
1455
- * Converts a comma separated list to an array.
1456
- * @param value The comma separated list.
1457
- * @returns The array.
1458
- */
1459
- function commaSeparatedListToArray(value) {
1460
- return (value ?? "")
1461
- .split(",")
1462
- .map(item => item.trim())
1463
- .filter(item => item.length > 0);
1464
- }
1465
1469
  /**
1466
1470
  * Checks if the trust subsystem is required.
1467
1471
  * Returns true when any component that depends on the trust subsystem is enabled.
@@ -1470,7 +1474,7 @@ function commaSeparatedListToArray(value) {
1470
1474
  */
1471
1475
  export function isTrustRequired(envVars) {
1472
1476
  return (isRightsManagementRequired(envVars) ||
1473
- (Coerce.boolean(envVars.dataspaceEnabled) ?? false) ||
1477
+ envBoolean(envVars, "dataspaceEnabled", false) ||
1474
1478
  isFederatedCatalogueRequired(envVars));
1475
1479
  }
1476
1480
  /**
@@ -1480,7 +1484,7 @@ export function isTrustRequired(envVars) {
1480
1484
  * @returns True if dataspace or verifiable storage is enabled.
1481
1485
  */
1482
1486
  export function isBackgroundTasksRequired(envVars) {
1483
- return (Coerce.boolean(envVars.dataspaceEnabled) ?? false) || isImmutableProofRequired(envVars);
1487
+ return envBoolean(envVars, "dataspaceEnabled", false) || isImmutableProofRequired(envVars);
1484
1488
  }
1485
1489
  /**
1486
1490
  * Checks if the immutable proof subsystem is required.
@@ -1489,9 +1493,9 @@ export function isBackgroundTasksRequired(envVars) {
1489
1493
  * @returns True if verifiable storage is enabled.
1490
1494
  */
1491
1495
  export function isImmutableProofRequired(envVars) {
1492
- return ((Coerce.boolean(envVars.auditableItemGraphEnabled) ?? false) ||
1493
- (Coerce.boolean(envVars.auditableItemStreamEnabled) ?? false) ||
1494
- (Coerce.boolean(envVars.documentManagementEnabled) ?? false));
1496
+ return (envBoolean(envVars, "auditableItemGraphEnabled", false) ||
1497
+ envBoolean(envVars, "auditableItemStreamEnabled", false) ||
1498
+ envBoolean(envVars, "documentManagementEnabled", false));
1495
1499
  }
1496
1500
  /**
1497
1501
  * Checks if the federated catalogue subsystem is required.
@@ -1500,10 +1504,10 @@ export function isImmutableProofRequired(envVars) {
1500
1504
  * @returns True if the federated catalogue is required.
1501
1505
  */
1502
1506
  export function isFederatedCatalogueRequired(envVars) {
1503
- return ((Coerce.boolean(envVars.federatedCatalogueEnabled) ?? false) ||
1507
+ return (envBoolean(envVars, "federatedCatalogueEnabled", false) ||
1504
1508
  Is.stringValue(envVars.federatedCatalogueRemoteEndpoint) ||
1505
1509
  Is.stringValue(envVars.federatedCatalogueFilters) ||
1506
- (Coerce.boolean(envVars.dataspaceEnabled) ?? false));
1510
+ envBoolean(envVars, "dataspaceEnabled", false));
1507
1511
  }
1508
1512
  /**
1509
1513
  * Checks if the rights management subsystem is required.
@@ -1515,7 +1519,7 @@ export function isFederatedCatalogueRequired(envVars) {
1515
1519
  * @returns True if rights management is enabled.
1516
1520
  */
1517
1521
  export function isRightsManagementRequired(envVars) {
1518
- return Coerce.boolean(envVars.dataspaceEnabled) ?? false;
1522
+ return envBoolean(envVars, "dataspaceEnabled", false);
1519
1523
  }
1520
1524
  /**
1521
1525
  * Checks if the task scheduler subsystem is required.
@@ -1524,8 +1528,8 @@ export function isRightsManagementRequired(envVars) {
1524
1528
  * @returns True if task scheduler is enabled.
1525
1529
  */
1526
1530
  export function isTaskSchedulerRequired(envVars) {
1527
- return ((Coerce.boolean(envVars.taskSchedulerEnabled) ?? false) ||
1528
- (Coerce.boolean(envVars.dataspaceEnabled) ?? false) ||
1531
+ return (envBoolean(envVars, "taskSchedulerEnabled", false) ||
1532
+ envBoolean(envVars, "dataspaceEnabled", false) ||
1529
1533
  isRightsManagementRequired(envVars) ||
1530
1534
  isAuthEntityStorageRequired(envVars) ||
1531
1535
  isImmutableProofRequired(envVars));