@twin.org/node-core 0.9.2-next.15 → 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 +118 -76
  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 +2 -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 +12 -2
  18. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
  19. package/docs/changelog.md +8 -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 +30 -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.
@@ -525,45 +525,71 @@ async function configureEventBus(coreConfig, envVars) {
525
525
  */
526
526
  async function configureTelemetry(coreConfig, envVars) {
527
527
  coreConfig.types.telemetryConnector ??= [];
528
- if (envVars.telemetryConnector === TelemetryConnectorType.EntityStorage) {
529
- coreConfig.types.telemetryConnector.push({
530
- type: TelemetryConnectorType.EntityStorage,
531
- options: {
532
- config: {
533
- batchSize: envCount(envVars, "telemetryBatchSize"),
534
- batchIntervalMs: envSecToMs(envVars, "telemetryBatchFlushInterval"),
535
- maxCacheSize: envCount(envVars, "telemetryMaxCacheSize"),
536
- 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
+ }
537
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
+ };
538
562
  }
539
- });
540
- }
541
- else if (envVars.telemetryConnector === TelemetryConnectorType.OpenTelemetry) {
542
- let readers;
543
- if (envVars.openTelemetryReader === OpenTelemetryReaderTypes.Prometheus) {
544
- readers = {
545
- prometheus: {
546
- type: OpenTelemetryReaderTypes.Prometheus,
547
- 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
+ }
548
571
  }
549
- };
572
+ });
573
+ additionalConnectorCount++;
550
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) {
551
579
  coreConfig.types.telemetryConnector.push({
552
- type: TelemetryConnectorType.OpenTelemetry,
580
+ type: TelemetryConnectorType.Multi,
553
581
  options: {
554
- config: {
555
- batchSize: envCount(envVars, "telemetryBatchSize"),
556
- batchIntervalMs: envSecToMs(envVars, "telemetryBatchFlushInterval"),
557
- maxCacheSize: envCount(envVars, "telemetryMaxCacheSize"),
558
- mutexTimeoutMs: envMs(envVars, "telemetryMutexTimeout"),
559
- meterName: envVars.openTelemetryMeterName,
560
- meterVersion: envVars.openTelemetryMeterVersion,
561
- readers
562
- }
563
- }
582
+ telemetryConnectorTypes
583
+ },
584
+ isDefault: true
564
585
  });
565
586
  }
566
- 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) {
567
593
  coreConfig.types.telemetryComponent ??= [];
568
594
  coreConfig.types.telemetryComponent.push({ type: TelemetryComponentType.Service });
569
595
  }
@@ -575,7 +601,7 @@ async function configureTelemetry(coreConfig, envVars) {
575
601
  * @returns A promise that resolves when the metrics collector configuration has been applied.
576
602
  */
577
603
  async function configureMetricsCollector(coreConfig, envVars) {
578
- if (isTelemetryRequired(envVars)) {
604
+ if (isTelemetryEnabled(envVars)) {
579
605
  coreConfig.types.metricsCollectorComponent ??= [];
580
606
  coreConfig.types.metricsCollectorComponent.push({
581
607
  type: MetricsCollectorComponentType.Service,
@@ -606,38 +632,66 @@ async function configureMetricsCollector(coreConfig, envVars) {
606
632
  */
607
633
  async function configureTracing(coreConfig, envVars) {
608
634
  coreConfig.types.tracingConnector ??= [];
609
- if (envVars.tracingConnector === TracingConnectorType.EntityStorage) {
610
- coreConfig.types.tracingConnector.push({
611
- type: TracingConnectorType.EntityStorage,
612
- options: {
613
- config: {
614
- 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
+ }
615
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
+ };
616
668
  }
617
- });
618
- }
619
- else if (envVars.tracingConnector === TracingConnectorType.OpenTelemetry) {
620
- const otelTracingConfig = {
621
- tracerName: envVars.openTelemetryTracingTracerName,
622
- tracerVersion: envVars.openTelemetryTracingTracerVersion
623
- };
624
- if (Is.stringValue(envVars.openTelemetryTracingEndpoint)) {
625
- otelTracingConfig.exporters = {
626
- otlp: {
627
- endpoint: envVars.openTelemetryTracingEndpoint,
628
- processor: envVars.openTelemetryTracingProcessor ??
629
- OpenTelemetryProcessorTypes.Batch
669
+ coreConfig.types.tracingConnector.push({
670
+ type: TracingConnectorType.OpenTelemetry,
671
+ options: {
672
+ config: otelTracingConfig
630
673
  }
631
- };
674
+ });
675
+ additionalConnectorCount++;
632
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) {
633
681
  coreConfig.types.tracingConnector.push({
634
- type: TracingConnectorType.OpenTelemetry,
682
+ type: TracingConnectorType.Multi,
635
683
  options: {
636
- config: otelTracingConfig
637
- }
684
+ tracingConnectorTypes
685
+ },
686
+ isDefault: true
638
687
  });
639
688
  }
640
- 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) {
641
695
  coreConfig.types.tracingComponent ??= [];
642
696
  coreConfig.types.tracingComponent.push({ type: TracingComponentType.Service });
643
697
  }
@@ -811,16 +865,6 @@ async function configureMessaging(coreConfig, envVars) {
811
865
  });
812
866
  }
813
867
  else if (envVars.messagingPushNotificationConnector === MessagingPushNotificationConnectorType.Aws) {
814
- let messagingApps;
815
- if (Is.stringValue(envVars.awsMessagingPushNotificationApplications)) {
816
- try {
817
- messagingApps = JSON.parse(envVars.awsMessagingPushNotificationApplications);
818
- }
819
- catch { }
820
- }
821
- else if (Is.array(envVars.awsMessagingPushNotificationApplications)) {
822
- messagingApps = envVars.awsMessagingPushNotificationApplications;
823
- }
824
868
  coreConfig.types.messagingPushNotificationConnector.push({
825
869
  type: MessagingPushNotificationConnectorType.Aws,
826
870
  options: {
@@ -830,7 +874,7 @@ async function configureMessaging(coreConfig, envVars) {
830
874
  accessKeyId: envVars.awsSesAccessKeyId,
831
875
  secretAccessKey: envVars.awsSesSecretAccessKey,
832
876
  endpoint: envVars.awsSesEndpoint,
833
- applicationsSettings: messagingApps ?? []
877
+ applicationsSettings: envArray(envVars, "awsMessagingPushNotificationApplications", [])
834
878
  }
835
879
  }
836
880
  });
@@ -1583,23 +1627,21 @@ export function isAutomationRequired(envVars) {
1583
1627
  return isRightsManagementRequired(envVars);
1584
1628
  }
1585
1629
  /**
1586
- * Checks if the telemetry subsystem is required.
1630
+ * Checks if the telemetry subsystem is enabled.
1587
1631
  * Returns true when any component that depends on the telemetry subsystem is enabled.
1588
1632
  * @param envVars The environment variables.
1589
1633
  * @returns True if telemetry is enabled.
1590
1634
  */
1591
- export function isTelemetryRequired(envVars) {
1592
- return (envVars.telemetryConnector === TelemetryConnectorType.EntityStorage ||
1593
- envVars.telemetryConnector === TelemetryConnectorType.OpenTelemetry);
1635
+ export function isTelemetryEnabled(envVars) {
1636
+ return commaSeparatedListToArray(envVars.telemetryConnector).some(t => t === TelemetryConnectorType.EntityStorage || t === TelemetryConnectorType.OpenTelemetry);
1594
1637
  }
1595
1638
  /**
1596
- * Checks if the tracing subsystem is required.
1639
+ * Checks if the tracing subsystem is enabled.
1597
1640
  * Returns true when any component that depends on the tracing subsystem is enabled.
1598
1641
  * @param envVars The environment variables.
1599
1642
  * @returns True if tracing is enabled.
1600
1643
  */
1601
- export function isTracingRequired(envVars) {
1602
- return (envVars.tracingConnector === TracingConnectorType.EntityStorage ||
1603
- envVars.tracingConnector === TracingConnectorType.OpenTelemetry);
1644
+ export function isTracingEnabled(envVars) {
1645
+ return commaSeparatedListToArray(envVars.tracingConnector).some(t => t === TracingConnectorType.EntityStorage || t === TracingConnectorType.OpenTelemetry);
1604
1646
  }
1605
1647
  //# sourceMappingURL=engineEnvBuilder.js.map