@twin.org/node-core 0.0.2-next.16 → 0.0.2-next.17

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 (36) hide show
  1. package/dist/cjs/index.cjs +182 -53
  2. package/dist/esm/index.mjs +173 -54
  3. package/dist/types/builders/engineServerEnvBuilder.d.ts +1 -1
  4. package/dist/types/builders/extensionsBuilder.d.ts +31 -0
  5. package/dist/types/defaults.d.ts +6 -0
  6. package/dist/types/index.d.ts +4 -0
  7. package/dist/types/models/IEngineEnvironmentVariables.d.ts +35 -14
  8. package/dist/types/models/INodeEngineConfig.d.ts +6 -0
  9. package/dist/types/models/INodeOptions.d.ts +2 -1
  10. package/dist/types/models/nodeExtensionMethods.d.ts +22 -0
  11. package/dist/types/node.d.ts +2 -2
  12. package/dist/types/server.d.ts +4 -2
  13. package/docs/changelog.md +8 -0
  14. package/docs/reference/functions/buildConfiguration.md +2 -2
  15. package/docs/reference/functions/buildEngineServerConfiguration.md +1 -1
  16. package/docs/reference/functions/extensionsConfiguration.md +25 -0
  17. package/docs/reference/functions/extensionsInitialiseEngine.md +25 -0
  18. package/docs/reference/functions/extensionsInitialiseEngineServer.md +31 -0
  19. package/docs/reference/functions/shutdownExtensions.md +19 -0
  20. package/docs/reference/functions/start.md +4 -4
  21. package/docs/reference/index.md +14 -0
  22. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +73 -22
  23. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +101 -30
  24. package/docs/reference/interfaces/INodeEngineConfig.md +7 -0
  25. package/docs/reference/interfaces/INodeEnvironmentVariables.md +101 -30
  26. package/docs/reference/interfaces/INodeOptions.md +6 -2
  27. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +18 -0
  28. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +24 -0
  29. package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +23 -0
  30. package/docs/reference/variables/ATTESTATION_VERIFICATION_METHOD_ID.md +3 -0
  31. package/docs/reference/variables/AUTH_SIGNING_KEY_ID.md +3 -0
  32. package/docs/reference/variables/BLOB_STORAGE_ENCRYPTION_KEY_ID.md +3 -0
  33. package/docs/reference/variables/IMMUTABLE_PROOF_VERIFICATION_METHOD_ID.md +3 -0
  34. package/docs/reference/variables/SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID.md +3 -0
  35. package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +3 -0
  36. package/package.json +12 -1
@@ -38,6 +38,15 @@ function _interopNamespaceDefault(e) {
38
38
 
39
39
  var dotenv__namespace = /*#__PURE__*/_interopNamespaceDefault(dotenv);
40
40
 
41
+ // Copyright 2024 IOTA Stiftung.
42
+ // SPDX-License-Identifier: Apache-2.0.
43
+ const ATTESTATION_VERIFICATION_METHOD_ID = "attestation-assertion";
44
+ const IMMUTABLE_PROOF_VERIFICATION_METHOD_ID = "immutable-proof-assertion";
45
+ const BLOB_STORAGE_ENCRYPTION_KEY_ID = "blob-encryption";
46
+ const SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID = "synchronised-storage-blob-encryption";
47
+ const VC_AUTHENTICATION_VERIFICATION_METHOD_ID = "node-authentication-assertion";
48
+ const AUTH_SIGNING_KEY_ID = "auth-signing";
49
+
41
50
  // Copyright 2024 IOTA Stiftung.
42
51
  // SPDX-License-Identifier: Apache-2.0.
43
52
  /**
@@ -209,10 +218,16 @@ async function bootstrap(engineCore, context, envVars) {
209
218
  await bootstrapNodeUser(engineCore, context, envVars, features);
210
219
  await bootstrapAuth(engineCore, context, envVars);
211
220
  await bootstrapBlobEncryption(engineCore, context, envVars);
212
- await addVerificationMethod(engineCore, context, "attestation", envVars.attestationVerificationMethodId);
213
- await addVerificationMethod(engineCore, context, "immutable proof", envVars.immutableProofVerificationMethodId);
221
+ const defaultAttestationConnectorType = engineCore.getRegisteredInstanceTypeOptional("attestationConnector");
222
+ if (!core.Is.empty(defaultAttestationConnectorType)) {
223
+ await addVerificationMethod(engineCore, context, "attestation", envVars.attestationVerificationMethodId ?? ATTESTATION_VERIFICATION_METHOD_ID);
224
+ }
225
+ const defaultImmutableProofComponentType = engineCore.getRegisteredInstanceTypeOptional("immutableProofComponent");
226
+ if (!core.Is.empty(defaultImmutableProofComponentType)) {
227
+ await addVerificationMethod(engineCore, context, "immutable proof", envVars.immutableProofVerificationMethodId ?? IMMUTABLE_PROOF_VERIFICATION_METHOD_ID);
228
+ }
214
229
  if (core.Coerce.boolean(envVars.vcAuthenticationEnabled) ?? false) {
215
- await addVerificationMethod(engineCore, context, "verifiable credential authentication", envVars.vcAuthenticationVerificationMethodId);
230
+ await addVerificationMethod(engineCore, context, "verifiable credential authentication", envVars.vcAuthenticationVerificationMethodId ?? VC_AUTHENTICATION_VERIFICATION_METHOD_ID);
216
231
  }
217
232
  await bootstrapSynchronisedStorage(engineCore, context, envVars);
218
233
  }
@@ -488,7 +503,7 @@ async function bootstrapBlobEncryption(engineCore, context, envVars, features) {
488
503
  // Create a new key for encrypting blobs
489
504
  const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
490
505
  const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
491
- const keyName = `${context.state.nodeIdentity}/${envVars.blobStorageEncryptionKeyId}`;
506
+ const keyName = `${context.state.nodeIdentity}/${envVars.blobStorageEncryptionKeyId ?? BLOB_STORAGE_ENCRYPTION_KEY_ID}`;
492
507
  let existingKey;
493
508
  try {
494
509
  existingKey = await vaultConnector.getKey(keyName);
@@ -528,7 +543,7 @@ async function bootstrapAuth(engineCore, context, envVars, features) {
528
543
  // Create a new JWT signing key and a user login for the node
529
544
  const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
530
545
  const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
531
- const keyName = `${context.state.nodeIdentity}/${envVars.authSigningKeyId}`;
546
+ const keyName = `${context.state.nodeIdentity}/${envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID}`;
532
547
  let existingKey;
533
548
  try {
534
549
  existingKey = await vaultConnector.getKey(keyName);
@@ -553,11 +568,11 @@ async function bootstrapAuth(engineCore, context, envVars, features) {
553
568
  async function bootstrapSynchronisedStorage(engineCore, context, envVars, features) {
554
569
  if (core.Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) {
555
570
  // If this is a trusted node we need to add the blob encryption key pair
556
- if (core.Is.stringValue(envVars.synchronisedStorageBlobStorageEncryptionKeyId) &&
557
- core.Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {
571
+ if (core.Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {
558
572
  const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
559
573
  const vaultConnector = vaultModels.VaultConnectorFactory.get(defaultVaultConnectorType);
560
- const keyName = envVars.synchronisedStorageBlobStorageEncryptionKeyId;
574
+ const keyName = envVars.synchronisedStorageBlobStorageEncryptionKeyId ??
575
+ SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID;
561
576
  let existingKey;
562
577
  try {
563
578
  existingKey = await vaultConnector.getKey(keyName);
@@ -625,12 +640,6 @@ async function buildEngineConfiguration(envVars) {
625
640
  envVars.storageFileRoot = path.resolve(envVars.storageFileRoot);
626
641
  envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
627
642
  }
628
- envVars.attestationVerificationMethodId ??= "attestation-assertion";
629
- envVars.immutableProofVerificationMethodId ??= "immutable-proof-assertion";
630
- envVars.blobStorageEnableEncryption ??= "false";
631
- envVars.blobStorageEncryptionKeyId ??= "blob-encryption";
632
- envVars.synchronisedStorageBlobStorageEncryptionKeyId ??= "synchronised-storage-blob-encryption";
633
- envVars.vcAuthenticationVerificationMethodId ??= "node-authentication-assertion";
634
643
  const coreConfig = {
635
644
  debug: core.Coerce.boolean(envVars.debug) ?? false,
636
645
  types: {}
@@ -693,9 +702,10 @@ async function configureEntityStorage(coreConfig, envVars) {
693
702
  options: {
694
703
  config: {
695
704
  region: envVars.awsDynamodbRegion ?? "",
696
- accessKeyId: envVars.awsDynamodbAccessKeyId ?? "",
697
- secretAccessKey: envVars.awsDynamodbSecretAccessKey ?? "",
698
- endpoint: envVars.awsDynamodbEndpoint ?? ""
705
+ authMode: envVars.awsDynamodbAuthMode,
706
+ accessKeyId: envVars.awsDynamodbAccessKeyId,
707
+ secretAccessKey: envVars.awsDynamodbSecretAccessKey,
708
+ endpoint: envVars.awsDynamodbEndpoint
699
709
  },
700
710
  tablePrefix: envVars.entityStorageTablePrefix
701
711
  }
@@ -852,9 +862,10 @@ async function configureBlobStorage(coreConfig, envVars) {
852
862
  config: {
853
863
  region: envVars.awsS3Region ?? "",
854
864
  bucketName: envVars.awsS3BucketName ?? "",
855
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
856
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
857
- endpoint: envVars.awsS3Endpoint ?? ""
865
+ authMode: envVars.awsS3AuthMode,
866
+ accessKeyId: envVars.awsS3AccessKeyId,
867
+ secretAccessKey: envVars.awsS3SecretAccessKey,
868
+ endpoint: envVars.awsS3Endpoint
858
869
  },
859
870
  storagePrefix: envVars.blobStoragePrefix
860
871
  }
@@ -911,7 +922,7 @@ async function configureBlobStorage(coreConfig, envVars) {
911
922
  options: {
912
923
  config: {
913
924
  vaultKeyId: (envVars.blobStorageEnableEncryption ?? false)
914
- ? envVars.blobStorageEncryptionKeyId
925
+ ? (envVars.blobStorageEncryptionKeyId ?? BLOB_STORAGE_ENCRYPTION_KEY_ID)
915
926
  : undefined
916
927
  }
917
928
  }
@@ -1051,10 +1062,11 @@ async function configureMessaging(coreConfig, envVars) {
1051
1062
  type: engineTypes.MessagingEmailConnectorType.Aws,
1052
1063
  options: {
1053
1064
  config: {
1054
- region: envVars.awsS3Region ?? "",
1055
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
1056
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
1057
- endpoint: envVars.awsS3Endpoint ?? ""
1065
+ region: envVars.awsSesRegion ?? "",
1066
+ authMode: envVars.awsSesAuthMode,
1067
+ accessKeyId: envVars.awsSesAccessKeyId,
1068
+ secretAccessKey: envVars.awsSesSecretAccessKey,
1069
+ endpoint: envVars.awsSesEndpoint
1058
1070
  }
1059
1071
  }
1060
1072
  });
@@ -1069,10 +1081,11 @@ async function configureMessaging(coreConfig, envVars) {
1069
1081
  type: engineTypes.MessagingSmsConnectorType.Aws,
1070
1082
  options: {
1071
1083
  config: {
1072
- region: envVars.awsS3Region ?? "",
1073
- accessKeyId: envVars.awsS3AccessKeyId ?? "",
1074
- secretAccessKey: envVars.awsS3SecretAccessKey ?? "",
1075
- endpoint: envVars.awsS3Endpoint ?? ""
1084
+ region: envVars.awsSesRegion ?? "",
1085
+ authMode: envVars.awsSesAuthMode,
1086
+ accessKeyId: envVars.awsSesAccessKeyId,
1087
+ secretAccessKey: envVars.awsSesSecretAccessKey,
1088
+ endpoint: envVars.awsSesEndpoint
1076
1089
  }
1077
1090
  }
1078
1091
  });
@@ -1089,8 +1102,9 @@ async function configureMessaging(coreConfig, envVars) {
1089
1102
  options: {
1090
1103
  config: {
1091
1104
  region: envVars.awsSesRegion ?? "",
1092
- accessKeyId: envVars.awsSesAccessKeyId ?? "",
1093
- secretAccessKey: envVars.awsSesSecretAccessKey ?? "",
1105
+ authMode: envVars.awsSesAuthMode,
1106
+ accessKeyId: envVars.awsSesAccessKeyId,
1107
+ secretAccessKey: envVars.awsSesSecretAccessKey,
1094
1108
  endpoint: envVars.awsSesEndpoint,
1095
1109
  applicationsSettings: core.Is.json(envVars.awsMessagingPushNotificationApplications)
1096
1110
  ? JSON.parse(envVars.awsMessagingPushNotificationApplications)
@@ -1220,7 +1234,7 @@ async function configureVerifiableStorage(coreConfig, envVars) {
1220
1234
  type: engineTypes.ImmutableProofComponentType.Service,
1221
1235
  options: {
1222
1236
  config: {
1223
- verificationMethodId: envVars.immutableProofVerificationMethodId
1237
+ verificationMethodId: envVars.immutableProofVerificationMethodId ?? IMMUTABLE_PROOF_VERIFICATION_METHOD_ID
1224
1238
  }
1225
1239
  }
1226
1240
  });
@@ -1325,7 +1339,7 @@ async function configureAttestation(coreConfig, envVars) {
1325
1339
  type: engineTypes.AttestationComponentType.Service,
1326
1340
  options: {
1327
1341
  config: {
1328
- verificationMethodId: envVars.attestationVerificationMethodId
1342
+ verificationMethodId: envVars.attestationVerificationMethodId ?? ATTESTATION_VERIFICATION_METHOD_ID
1329
1343
  }
1330
1344
  }
1331
1345
  });
@@ -1416,7 +1430,9 @@ async function configureVerifiableCredentialAuthentication(coreConfig, envVars)
1416
1430
  coreConfig.types.authenticationGeneratorComponent.push({
1417
1431
  type: engineTypes.AuthenticationGeneratorComponentType.VerifiableCredential,
1418
1432
  options: {
1419
- config: { verificationMethodId: envVars.vcAuthenticationVerificationMethodId ?? "" }
1433
+ config: {
1434
+ verificationMethodId: envVars.vcAuthenticationVerificationMethodId ?? VC_AUTHENTICATION_VERIFICATION_METHOD_ID
1435
+ }
1420
1436
  },
1421
1437
  features: ["verifiable-credential"]
1422
1438
  });
@@ -1544,7 +1560,8 @@ async function configureSynchronisedStorage(coreConfig, envVars) {
1544
1560
  options: {
1545
1561
  config: {
1546
1562
  verifiableStorageKeyId: verifiableStorageKeyId ?? "",
1547
- blobStorageEncryptionKeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId,
1563
+ blobStorageEncryptionKeyId: envVars.synchronisedStorageBlobStorageEncryptionKeyId ??
1564
+ SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID,
1548
1565
  entityUpdateIntervalMinutes: core.Coerce.number(envVars.synchronisedStorageEntityUpdateIntervalMinutes),
1549
1566
  consolidationIntervalMinutes: core.Coerce.number(envVars.synchronisedStorageConsolidationIntervalMinutes),
1550
1567
  consolidationBatchSize: core.Coerce.number(envVars.synchronisedStorageConsolidationBatchSize),
@@ -1597,9 +1614,8 @@ async function configureDataSpaceConnector(coreConfig, envVars) {
1597
1614
  type: engineTypes.DataSpaceConnectorComponentType.Service,
1598
1615
  options: {
1599
1616
  config: {
1600
- dataSpaceConnectorAppDescriptors: core.Is.arrayValue(envVars.dataSpaceConnectorApps)
1601
- ? envVars.dataSpaceConnectorApps
1602
- : undefined
1617
+ retainActivityLogsFor: core.Coerce.number(envVars.dataSpaceConnectorRetainActivityLogsFor),
1618
+ activityLogsCleanUpInterval: core.Coerce.number(envVars.dataSpaceConnectorActivityLogsCleanUpInterval)
1603
1619
  }
1604
1620
  }
1605
1621
  });
@@ -1645,10 +1661,9 @@ async function configureDlt(coreConfig, envVars) {
1645
1661
  * @param serverInfo The server information.
1646
1662
  * @param openApiSpecPath The path to the open api spec.
1647
1663
  * @param favIconPath The path to the favicon.
1648
- * @returns The the config for the core and the server.
1664
+ * @returns The config for the core and the server.
1649
1665
  */
1650
1666
  async function buildEngineServerConfiguration(envVars, coreEngineConfig, serverInfo, openApiSpecPath, favIconPath) {
1651
- envVars.authSigningKeyId ??= "auth-signing";
1652
1667
  const webServerOptions = {
1653
1668
  port: core.Coerce.number(envVars.port),
1654
1669
  host: core.Coerce.string(envVars.host),
@@ -1764,7 +1779,7 @@ async function buildEngineServerConfiguration(envVars, coreEngineConfig, serverI
1764
1779
  type: engineServerTypes.AuthenticationComponentType.EntityStorage,
1765
1780
  options: {
1766
1781
  config: {
1767
- signingKeyName: envVars.authSigningKeyId
1782
+ signingKeyName: envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID
1768
1783
  }
1769
1784
  }
1770
1785
  });
@@ -1772,7 +1787,7 @@ async function buildEngineServerConfiguration(envVars, coreEngineConfig, serverI
1772
1787
  type: engineServerTypes.RestRouteProcessorType.AuthHeader,
1773
1788
  options: {
1774
1789
  config: {
1775
- signingKeyName: envVars.authSigningKeyId
1790
+ signingKeyName: envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID
1776
1791
  }
1777
1792
  }
1778
1793
  });
@@ -1780,7 +1795,7 @@ async function buildEngineServerConfiguration(envVars, coreEngineConfig, serverI
1780
1795
  type: engineServerTypes.SocketRouteProcessorType.AuthHeader,
1781
1796
  options: {
1782
1797
  config: {
1783
- signingKeyName: envVars.authSigningKeyId
1798
+ signingKeyName: envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID
1784
1799
  }
1785
1800
  }
1786
1801
  });
@@ -1798,17 +1813,111 @@ async function buildEngineServerConfiguration(envVars, coreEngineConfig, serverI
1798
1813
  return serverConfig;
1799
1814
  }
1800
1815
 
1816
+ // Copyright 2024 IOTA Stiftung.
1817
+ // SPDX-License-Identifier: Apache-2.0.
1818
+ /* eslint-disable no-console */
1819
+ /**
1820
+ * Handles the configuration of the extensions.
1821
+ * @param envVars The environment variables for the node.
1822
+ * @param nodeEngineConfig The node engine config.
1823
+ * @returns The config for the core and the server.
1824
+ */
1825
+ async function extensionsConfiguration(envVars, nodeEngineConfig) {
1826
+ if (core.Is.stringValue(envVars.extensions)) {
1827
+ const extensions = envVars.extensions.split(",");
1828
+ for (const extension of extensions) {
1829
+ let initialiseConfigMethod;
1830
+ try {
1831
+ console.info(`Loading extension "${extension}"`);
1832
+ initialiseConfigMethod = await modules.ModuleHelper.getModuleMethod(extension, "extensionInitialise");
1833
+ }
1834
+ catch (err) {
1835
+ console.error(`Failed to load extension "${extension}":`, err);
1836
+ }
1837
+ if (core.Is.function(initialiseConfigMethod)) {
1838
+ await initialiseConfigMethod(envVars, nodeEngineConfig);
1839
+ }
1840
+ }
1841
+ }
1842
+ return nodeEngineConfig;
1843
+ }
1844
+ /**
1845
+ * Handles the initialisation of the extensions when the engine has been constructed.
1846
+ * @param envVars The environment variables for the node.
1847
+ * @param engineCore The engine core instance.
1848
+ * @returns Nothing.
1849
+ */
1850
+ async function extensionsInitialiseEngine(envVars, engineCore) {
1851
+ if (core.Is.stringValue(envVars.extensions)) {
1852
+ const extensions = envVars.extensions.split(",");
1853
+ for (const extension of extensions) {
1854
+ let initialiseEngineMethod;
1855
+ try {
1856
+ initialiseEngineMethod =
1857
+ await modules.ModuleHelper.getModuleMethod(extension, "extensionInitialiseEngine");
1858
+ }
1859
+ catch { }
1860
+ if (core.Is.function(initialiseEngineMethod)) {
1861
+ await initialiseEngineMethod(engineCore);
1862
+ }
1863
+ }
1864
+ }
1865
+ }
1866
+ /**
1867
+ * Handles the initialisation of the extensions when the engine server has been constructed.
1868
+ * @param envVars The environment variables for the node.
1869
+ * @param engineCore The engine core instance.
1870
+ * @param engineServer The engine server instance.
1871
+ * @returns Nothing.
1872
+ */
1873
+ async function extensionsInitialiseEngineServer(envVars, engineCore, engineServer) {
1874
+ if (core.Is.stringValue(envVars.extensions)) {
1875
+ const extensions = envVars.extensions.split(",");
1876
+ for (const extension of extensions) {
1877
+ let initialiseEngineServerMethod;
1878
+ try {
1879
+ initialiseEngineServerMethod =
1880
+ await modules.ModuleHelper.getModuleMethod(extension, "extensionInitialiseEngineServer");
1881
+ }
1882
+ catch { }
1883
+ if (core.Is.function(initialiseEngineServerMethod)) {
1884
+ await initialiseEngineServerMethod(engineCore, engineServer);
1885
+ }
1886
+ }
1887
+ }
1888
+ }
1889
+ /**
1890
+ * Handles the shutdown of the extensions.
1891
+ * @param envVars The environment variables for the node.
1892
+ * @returns Nothing.
1893
+ */
1894
+ async function shutdownExtensions(envVars) {
1895
+ if (core.Is.stringValue(envVars.extensions)) {
1896
+ const extensions = envVars.extensions.split(",");
1897
+ for (const extension of extensions) {
1898
+ let shutdownMethod;
1899
+ try {
1900
+ shutdownMethod = await modules.ModuleHelper.getModuleMethod(extension, "extensionShutdown");
1901
+ }
1902
+ catch { }
1903
+ if (core.Is.function(shutdownMethod)) {
1904
+ await shutdownMethod();
1905
+ }
1906
+ }
1907
+ }
1908
+ }
1909
+
1801
1910
  // Copyright 2024 IOTA Stiftung.
1802
1911
  // SPDX-License-Identifier: Apache-2.0.
1803
1912
  /* eslint-disable no-console */
1804
1913
  /**
1805
1914
  * Start the engine server.
1806
1915
  * @param nodeOptions Optional run options for the engine server.
1807
- * @param engineServerConfig The configuration for the engine server.
1916
+ * @param nodeEngineConfig The configuration for the engine server.
1808
1917
  * @param envVars The environment variables.
1809
1918
  * @returns The engine server.
1810
1919
  */
1811
- async function start(nodeOptions, engineServerConfig, envVars) {
1920
+ async function start(nodeOptions, nodeEngineConfig, envVars) {
1812
1921
  const entityStorageConnectorType = envVars.entityStorageConnectorType?.split(",") ?? [];
1813
1922
  const blobStorageConnectorType = envVars.blobStorageConnectorType?.split(",") ?? [];
1814
1923
  // If the blob storage or entity storage is configured with file connectors
@@ -1823,7 +1932,7 @@ async function start(nodeOptions, engineServerConfig, envVars) {
1823
1932
  }
1824
1933
  // Create the engine instance using file state storage unless one is configured in options
1825
1934
  const engine$1 = new engine.Engine({
1826
- config: engineServerConfig,
1935
+ config: nodeEngineConfig,
1827
1936
  stateStorage: nodeOptions?.stateStorage ?? new engineCore.FileStateStorage(envVars.stateFilename ?? ""),
1828
1937
  customBootstrap: async (core, engineContext) => bootstrap(core, engineContext, envVars)
1829
1938
  });
@@ -1834,11 +1943,13 @@ async function start(nodeOptions, engineServerConfig, envVars) {
1834
1943
  console.info("Extending Engine");
1835
1944
  await nodeOptions.extendEngine(engine$1);
1836
1945
  }
1946
+ await extensionsInitialiseEngine(envVars, engine$1);
1837
1947
  // Extend the engine server.
1838
1948
  if (core.Is.function(nodeOptions?.extendEngineServer)) {
1839
1949
  console.info("Extending Engine Server");
1840
1950
  await nodeOptions?.extendEngineServer(server);
1841
1951
  }
1952
+ await extensionsInitialiseEngineServer(envVars, engine$1, server);
1842
1953
  // Need to register the engine with the factory so that background tasks
1843
1954
  // can clone it to spawn new instances.
1844
1955
  engineModels.EngineCoreFactory.register("engine", () => engine$1);
@@ -1847,7 +1958,11 @@ async function start(nodeOptions, engineServerConfig, envVars) {
1847
1958
  if (canContinue) {
1848
1959
  return {
1849
1960
  engine: engine$1,
1850
- server
1961
+ server,
1962
+ shutdown: async () => {
1963
+ await server.stop();
1964
+ await shutdownExtensions(envVars);
1965
+ }
1851
1966
  };
1852
1967
  }
1853
1968
  }
@@ -1865,7 +1980,7 @@ async function run(nodeOptions) {
1865
1980
  nodeOptions ??= {};
1866
1981
  const serverInfo = {
1867
1982
  name: nodeOptions?.serverName ?? "TWIN Node Server",
1868
- version: nodeOptions?.serverVersion ?? "0.0.2-next.16" // x-release-please-version
1983
+ version: nodeOptions?.serverVersion ?? "0.0.2-next.17" // x-release-please-version
1869
1984
  };
1870
1985
  console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
1871
1986
  if (!core.Is.stringValue(nodeOptions?.executionDirectory)) {
@@ -1896,13 +2011,16 @@ async function run(nodeOptions) {
1896
2011
  nodeOptions.envPrefix ??= "TWIN_NODE_";
1897
2012
  console.info("Environment Prefix:", nodeOptions.envPrefix);
1898
2013
  overrideModuleImport(nodeOptions.executionDirectory ?? "");
1899
- const { engineServerConfig, nodeEnvVars: envVars } = await buildConfiguration(process.env, nodeOptions, serverInfo);
2014
+ const { nodeEngineConfig, nodeEnvVars: envVars } = await buildConfiguration(
2015
+ // This is the only location in the code base that should access process.env directly
2016
+ // eslint-disable-next-line no-restricted-syntax
2017
+ process.env, nodeOptions, serverInfo);
1900
2018
  console.info();
1901
- const startResult = await start(nodeOptions, engineServerConfig, envVars);
2019
+ const startResult = await start(nodeOptions, nodeEngineConfig, envVars);
1902
2020
  if (!core.Is.empty(startResult)) {
1903
2021
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
1904
2022
  process.on(signal, async () => {
1905
- await startResult.server.stop();
2023
+ await startResult.shutdown();
1906
2024
  });
1907
2025
  }
1908
2026
  }
@@ -1986,9 +2104,10 @@ async function buildConfiguration(processEnv, options, serverInfo) {
1986
2104
  // Merge any custom configuration provided in the options.
1987
2105
  if (core.Is.function(options?.extendConfig)) {
1988
2106
  console.info("Extending Configuration");
1989
- await options.extendConfig(engineServerConfig);
2107
+ await options.extendConfig(envVars, engineServerConfig);
1990
2108
  }
1991
- return { engineServerConfig, nodeEnvVars: envVars };
2109
+ const nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);
2110
+ return { nodeEngineConfig, nodeEnvVars: envVars };
1992
2111
  }
1993
2112
  /**
1994
2113
  * Override module imports to use local files where possible.
@@ -2025,7 +2144,13 @@ function overrideModuleImport(executionDirectory) {
2025
2144
  });
2026
2145
  }
2027
2146
 
2147
+ exports.ATTESTATION_VERIFICATION_METHOD_ID = ATTESTATION_VERIFICATION_METHOD_ID;
2148
+ exports.AUTH_SIGNING_KEY_ID = AUTH_SIGNING_KEY_ID;
2149
+ exports.BLOB_STORAGE_ENCRYPTION_KEY_ID = BLOB_STORAGE_ENCRYPTION_KEY_ID;
2150
+ exports.IMMUTABLE_PROOF_VERIFICATION_METHOD_ID = IMMUTABLE_PROOF_VERIFICATION_METHOD_ID;
2028
2151
  exports.NodeFeatures = NodeFeatures;
2152
+ exports.SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID = SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID;
2153
+ exports.VC_AUTHENTICATION_VERIFICATION_METHOD_ID = VC_AUTHENTICATION_VERIFICATION_METHOD_ID;
2029
2154
  exports.bootstrap = bootstrap;
2030
2155
  exports.bootstrapAuth = bootstrapAuth;
2031
2156
  exports.bootstrapBlobEncryption = bootstrapBlobEncryption;
@@ -2037,6 +2162,9 @@ exports.buildConfiguration = buildConfiguration;
2037
2162
  exports.buildEngineConfiguration = buildEngineConfiguration;
2038
2163
  exports.buildEngineServerConfiguration = buildEngineServerConfiguration;
2039
2164
  exports.directoryExists = directoryExists;
2165
+ exports.extensionsConfiguration = extensionsConfiguration;
2166
+ exports.extensionsInitialiseEngine = extensionsInitialiseEngine;
2167
+ exports.extensionsInitialiseEngineServer = extensionsInitialiseEngineServer;
2040
2168
  exports.fileExists = fileExists;
2041
2169
  exports.getExecutionDirectory = getExecutionDirectory;
2042
2170
  exports.getFeatures = getFeatures;
@@ -2047,4 +2175,5 @@ exports.loadJsonFile = loadJsonFile;
2047
2175
  exports.loadTextFile = loadTextFile;
2048
2176
  exports.overrideModuleImport = overrideModuleImport;
2049
2177
  exports.run = run;
2178
+ exports.shutdownExtensions = shutdownExtensions;
2050
2179
  exports.start = start;