@twin.org/node-core 0.9.2-next.14 → 0.9.2-next.16

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.
Files changed (26) hide show
  1. package/dist/es/builders/engineEnvBuilder.js +126 -78
  2. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  3. package/dist/es/builders/engineServerEnvBuilder.js +6 -5
  4. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  5. package/dist/es/builders/helper/envHelpers.js +57 -72
  6. package/dist/es/builders/helper/envHelpers.js.map +1 -1
  7. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  8. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  9. package/dist/es/models/engineEnvironmentVariableKeys.js +4 -0
  10. package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -1
  11. package/dist/es/models/engineServerEnvironmentVariableKeys.js +1 -0
  12. package/dist/es/models/engineServerEnvironmentVariableKeys.js.map +1 -1
  13. package/dist/es/node.js +1 -1
  14. package/dist/es/node.js.map +1 -1
  15. package/dist/types/builders/engineEnvBuilder.d.ts +4 -4
  16. package/dist/types/builders/helper/envHelpers.d.ts +79 -20
  17. package/dist/types/models/IEngineEnvironmentVariables.d.ts +20 -2
  18. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
  19. package/docs/changelog.md +15 -0
  20. package/docs/reference/functions/{isTelemetryRequired.md → isTelemetryEnabled.md} +3 -3
  21. package/docs/reference/functions/{isTracingRequired.md → isTracingEnabled.md} +3 -3
  22. package/docs/reference/index.md +2 -2
  23. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +46 -2
  24. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +8 -0
  25. package/locales/en.json +1 -0
  26. package/package.json +1 -1
@@ -8,7 +8,7 @@ import { OpenTelemetryReaderTypes } from "@twin.org/telemetry-connector-opentele
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
+ import { commaSeparatedListToArray, envArray, envBoolean, envCount, envDateTime, envInteger, envMinToMs, envMinutes, envMs, envSecToMs, envSeconds } from "./helper/envHelpers.js";
12
12
  /**
13
13
  * Build the engine core configuration from environment variables.
14
14
  * @param envVars The environment variables.
@@ -23,7 +23,11 @@ export async function buildEngineConfiguration(envVars) {
23
23
  const coreConfig = {
24
24
  debug: envBoolean(envVars, "debug", false),
25
25
  silent: envBoolean(envVars, "silent", false),
26
- silentLoggers: commaSeparatedListToArray(envVars.loggingSilentComponents),
26
+ silentComponents: {
27
+ logging: commaSeparatedListToArray(envVars.loggingSilentComponents),
28
+ telemetry: commaSeparatedListToArray(envVars.telemetrySilentComponents),
29
+ tracing: commaSeparatedListToArray(envVars.tracingSilentComponents)
30
+ },
27
31
  types: {}
28
32
  };
29
33
  const mutexTimeoutMs = envMs(envVars, "mutexTimeoutDefault");
@@ -521,45 +525,71 @@ async function configureEventBus(coreConfig, envVars) {
521
525
  */
522
526
  async function configureTelemetry(coreConfig, envVars) {
523
527
  coreConfig.types.telemetryConnector ??= [];
524
- if (envVars.telemetryConnector === TelemetryConnectorType.EntityStorage) {
525
- coreConfig.types.telemetryConnector.push({
526
- type: TelemetryConnectorType.EntityStorage,
527
- options: {
528
- config: {
529
- batchSize: envCount(envVars, "telemetryBatchSize"),
530
- batchIntervalMs: envSecToMs(envVars, "telemetryBatchFlushInterval"),
531
- maxCacheSize: envCount(envVars, "telemetryMaxCacheSize"),
532
- mutexTimeoutMs: envMs(envVars, "telemetryMutexTimeout")
528
+ const telemetryConnectorTypes = commaSeparatedListToArray(envVars.telemetryConnector);
529
+ let additionalConnectorCount = 0;
530
+ for (const telemetryConnector of telemetryConnectorTypes) {
531
+ if (telemetryConnector === TelemetryConnectorType.Silent) {
532
+ coreConfig.types.telemetryConnector.push({
533
+ type: TelemetryConnectorType.Silent
534
+ });
535
+ additionalConnectorCount++;
536
+ }
537
+ else if (telemetryConnector === TelemetryConnectorType.EntityStorage) {
538
+ coreConfig.types.telemetryConnector.push({
539
+ type: TelemetryConnectorType.EntityStorage,
540
+ options: {
541
+ config: {
542
+ batchSize: envCount(envVars, "telemetryBatchSize"),
543
+ batchIntervalMs: envSecToMs(envVars, "telemetryBatchFlushInterval"),
544
+ maxCacheSize: envCount(envVars, "telemetryMaxCacheSize"),
545
+ mutexTimeoutMs: envMs(envVars, "telemetryMutexTimeout"),
546
+ metricDefinitionCacheCapacity: envCount(envVars, "telemetryMetricDefinitionCacheCapacity"),
547
+ metricDefinitionCacheTtiMs: envMs(envVars, "telemetryMetricDefinitionCacheTtiMs")
548
+ }
533
549
  }
550
+ });
551
+ additionalConnectorCount++;
552
+ }
553
+ else if (telemetryConnector === TelemetryConnectorType.OpenTelemetry) {
554
+ let readers;
555
+ if (envVars.openTelemetryReader === OpenTelemetryReaderTypes.Prometheus) {
556
+ readers = {
557
+ prometheus: {
558
+ type: OpenTelemetryReaderTypes.Prometheus,
559
+ port: envCount(envVars, "openTelemetryPrometheusPort")
560
+ }
561
+ };
534
562
  }
535
- });
536
- }
537
- else if (envVars.telemetryConnector === TelemetryConnectorType.OpenTelemetry) {
538
- let readers;
539
- if (envVars.openTelemetryReader === OpenTelemetryReaderTypes.Prometheus) {
540
- readers = {
541
- prometheus: {
542
- type: OpenTelemetryReaderTypes.Prometheus,
543
- port: envCount(envVars, "openTelemetryPrometheusPort")
563
+ coreConfig.types.telemetryConnector.push({
564
+ type: TelemetryConnectorType.OpenTelemetry,
565
+ options: {
566
+ config: {
567
+ meterName: envVars.openTelemetryMeterName,
568
+ meterVersion: envVars.openTelemetryMeterVersion,
569
+ readers
570
+ }
544
571
  }
545
- };
572
+ });
573
+ additionalConnectorCount++;
546
574
  }
575
+ }
576
+ // If more than one telemetry connector, then we need to add a multi connector
577
+ // and set it as the default one
578
+ if (additionalConnectorCount > 1) {
547
579
  coreConfig.types.telemetryConnector.push({
548
- type: TelemetryConnectorType.OpenTelemetry,
580
+ type: TelemetryConnectorType.Multi,
549
581
  options: {
550
- config: {
551
- batchSize: envCount(envVars, "telemetryBatchSize"),
552
- batchIntervalMs: envSecToMs(envVars, "telemetryBatchFlushInterval"),
553
- maxCacheSize: envCount(envVars, "telemetryMaxCacheSize"),
554
- mutexTimeoutMs: envMs(envVars, "telemetryMutexTimeout"),
555
- meterName: envVars.openTelemetryMeterName,
556
- meterVersion: envVars.openTelemetryMeterVersion,
557
- readers
558
- }
559
- }
582
+ telemetryConnectorTypes
583
+ },
584
+ isDefault: true
560
585
  });
561
586
  }
562
- if (coreConfig.types.telemetryConnector.length > 0) {
587
+ else if (additionalConnectorCount > 0) {
588
+ // If only one connector, then we set it as the default one
589
+ coreConfig.types.telemetryConnector[coreConfig.types.telemetryConnector.length - 1].isDefault =
590
+ true;
591
+ }
592
+ if (additionalConnectorCount > 0) {
563
593
  coreConfig.types.telemetryComponent ??= [];
564
594
  coreConfig.types.telemetryComponent.push({ type: TelemetryComponentType.Service });
565
595
  }
@@ -571,7 +601,7 @@ async function configureTelemetry(coreConfig, envVars) {
571
601
  * @returns A promise that resolves when the metrics collector configuration has been applied.
572
602
  */
573
603
  async function configureMetricsCollector(coreConfig, envVars) {
574
- if (isTelemetryRequired(envVars)) {
604
+ if (isTelemetryEnabled(envVars)) {
575
605
  coreConfig.types.metricsCollectorComponent ??= [];
576
606
  coreConfig.types.metricsCollectorComponent.push({
577
607
  type: MetricsCollectorComponentType.Service,
@@ -602,38 +632,66 @@ async function configureMetricsCollector(coreConfig, envVars) {
602
632
  */
603
633
  async function configureTracing(coreConfig, envVars) {
604
634
  coreConfig.types.tracingConnector ??= [];
605
- if (envVars.tracingConnector === TracingConnectorType.EntityStorage) {
606
- coreConfig.types.tracingConnector.push({
607
- type: TracingConnectorType.EntityStorage,
608
- options: {
609
- config: {
610
- mutexTimeoutMs: envMs(envVars, "tracingMutexTimeout")
635
+ const tracingConnectorTypes = commaSeparatedListToArray(envVars.tracingConnector);
636
+ let additionalConnectorCount = 0;
637
+ for (const tracingConnector of tracingConnectorTypes) {
638
+ if (tracingConnector === TracingConnectorType.Silent) {
639
+ coreConfig.types.tracingConnector.push({
640
+ type: TracingConnectorType.Silent
641
+ });
642
+ additionalConnectorCount++;
643
+ }
644
+ else if (tracingConnector === TracingConnectorType.EntityStorage) {
645
+ coreConfig.types.tracingConnector.push({
646
+ type: TracingConnectorType.EntityStorage,
647
+ options: {
648
+ config: {
649
+ mutexTimeoutMs: envMs(envVars, "tracingMutexTimeout")
650
+ }
611
651
  }
652
+ });
653
+ additionalConnectorCount++;
654
+ }
655
+ else if (tracingConnector === TracingConnectorType.OpenTelemetry) {
656
+ const otelTracingConfig = {
657
+ tracerName: envVars.openTelemetryTracingTracerName,
658
+ tracerVersion: envVars.openTelemetryTracingTracerVersion
659
+ };
660
+ if (Is.stringValue(envVars.openTelemetryTracingEndpoint)) {
661
+ otelTracingConfig.exporters = {
662
+ otlp: {
663
+ endpoint: envVars.openTelemetryTracingEndpoint,
664
+ processor: envVars.openTelemetryTracingProcessor ??
665
+ OpenTelemetryProcessorTypes.Batch
666
+ }
667
+ };
612
668
  }
613
- });
614
- }
615
- else if (envVars.tracingConnector === TracingConnectorType.OpenTelemetry) {
616
- const otelTracingConfig = {
617
- tracerName: envVars.openTelemetryTracingTracerName,
618
- tracerVersion: envVars.openTelemetryTracingTracerVersion
619
- };
620
- if (Is.stringValue(envVars.openTelemetryTracingEndpoint)) {
621
- otelTracingConfig.exporters = {
622
- otlp: {
623
- endpoint: envVars.openTelemetryTracingEndpoint,
624
- processor: envVars.openTelemetryTracingProcessor ??
625
- OpenTelemetryProcessorTypes.Batch
669
+ coreConfig.types.tracingConnector.push({
670
+ type: TracingConnectorType.OpenTelemetry,
671
+ options: {
672
+ config: otelTracingConfig
626
673
  }
627
- };
674
+ });
675
+ additionalConnectorCount++;
628
676
  }
677
+ }
678
+ // If more than one tracing connector, then we need to add a multi connector
679
+ // and set it as the default one
680
+ if (additionalConnectorCount > 1) {
629
681
  coreConfig.types.tracingConnector.push({
630
- type: TracingConnectorType.OpenTelemetry,
682
+ type: TracingConnectorType.Multi,
631
683
  options: {
632
- config: otelTracingConfig
633
- }
684
+ tracingConnectorTypes
685
+ },
686
+ isDefault: true
634
687
  });
635
688
  }
636
- if (coreConfig.types.tracingConnector.length > 0) {
689
+ else if (additionalConnectorCount > 0) {
690
+ // If only one connector, then we set it as the default one
691
+ coreConfig.types.tracingConnector[coreConfig.types.tracingConnector.length - 1].isDefault =
692
+ true;
693
+ }
694
+ if (additionalConnectorCount > 0) {
637
695
  coreConfig.types.tracingComponent ??= [];
638
696
  coreConfig.types.tracingComponent.push({ type: TracingComponentType.Service });
639
697
  }
@@ -807,16 +865,6 @@ async function configureMessaging(coreConfig, envVars) {
807
865
  });
808
866
  }
809
867
  else if (envVars.messagingPushNotificationConnector === MessagingPushNotificationConnectorType.Aws) {
810
- let messagingApps;
811
- if (Is.stringValue(envVars.awsMessagingPushNotificationApplications)) {
812
- try {
813
- messagingApps = JSON.parse(envVars.awsMessagingPushNotificationApplications);
814
- }
815
- catch { }
816
- }
817
- else if (Is.array(envVars.awsMessagingPushNotificationApplications)) {
818
- messagingApps = envVars.awsMessagingPushNotificationApplications;
819
- }
820
868
  coreConfig.types.messagingPushNotificationConnector.push({
821
869
  type: MessagingPushNotificationConnectorType.Aws,
822
870
  options: {
@@ -826,7 +874,7 @@ async function configureMessaging(coreConfig, envVars) {
826
874
  accessKeyId: envVars.awsSesAccessKeyId,
827
875
  secretAccessKey: envVars.awsSesSecretAccessKey,
828
876
  endpoint: envVars.awsSesEndpoint,
829
- applicationsSettings: messagingApps ?? []
877
+ applicationsSettings: envArray(envVars, "awsMessagingPushNotificationApplications", [])
830
878
  }
831
879
  }
832
880
  });
@@ -1517,7 +1565,9 @@ export function isTrustRequired(envVars) {
1517
1565
  * @returns True if dataspace or verifiable storage is enabled.
1518
1566
  */
1519
1567
  export function isBackgroundTasksRequired(envVars) {
1520
- return envBoolean(envVars, "dataspaceEnabled", false) || isImmutableProofRequired(envVars);
1568
+ return (envBoolean(envVars, "dataspaceEnabled", false) ||
1569
+ isImmutableProofRequired(envVars) ||
1570
+ envBoolean(envVars, "healthEnabled", false));
1521
1571
  }
1522
1572
  /**
1523
1573
  * Checks if the immutable proof subsystem is required.
@@ -1577,23 +1627,21 @@ export function isAutomationRequired(envVars) {
1577
1627
  return isRightsManagementRequired(envVars);
1578
1628
  }
1579
1629
  /**
1580
- * Checks if the telemetry subsystem is required.
1630
+ * Checks if the telemetry subsystem is enabled.
1581
1631
  * Returns true when any component that depends on the telemetry subsystem is enabled.
1582
1632
  * @param envVars The environment variables.
1583
1633
  * @returns True if telemetry is enabled.
1584
1634
  */
1585
- export function isTelemetryRequired(envVars) {
1586
- return (envVars.telemetryConnector === TelemetryConnectorType.EntityStorage ||
1587
- envVars.telemetryConnector === TelemetryConnectorType.OpenTelemetry);
1635
+ export function isTelemetryEnabled(envVars) {
1636
+ return commaSeparatedListToArray(envVars.telemetryConnector).some(t => t === TelemetryConnectorType.EntityStorage || t === TelemetryConnectorType.OpenTelemetry);
1588
1637
  }
1589
1638
  /**
1590
- * Checks if the tracing subsystem is required.
1639
+ * Checks if the tracing subsystem is enabled.
1591
1640
  * Returns true when any component that depends on the tracing subsystem is enabled.
1592
1641
  * @param envVars The environment variables.
1593
1642
  * @returns True if tracing is enabled.
1594
1643
  */
1595
- export function isTracingRequired(envVars) {
1596
- return (envVars.tracingConnector === TracingConnectorType.EntityStorage ||
1597
- envVars.tracingConnector === TracingConnectorType.OpenTelemetry);
1644
+ export function isTracingEnabled(envVars) {
1645
+ return commaSeparatedListToArray(envVars.tracingConnector).some(t => t === TracingConnectorType.EntityStorage || t === TracingConnectorType.OpenTelemetry);
1598
1646
  }
1599
1647
  //# sourceMappingURL=engineEnvBuilder.js.map