@twin.org/node-core 0.0.3-next.2 → 0.0.3-next.21

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 (151) hide show
  1. package/dist/es/builders/engineEnvBuilder.js +168 -105
  2. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  3. package/dist/es/builders/engineServerEnvBuilder.js +49 -25
  4. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  5. package/dist/es/cli.js +247 -0
  6. package/dist/es/cli.js.map +1 -0
  7. package/dist/es/commands/bootstrapLegacy.js +183 -0
  8. package/dist/es/commands/bootstrapLegacy.js.map +1 -0
  9. package/dist/es/commands/help.js +85 -0
  10. package/dist/es/commands/help.js.map +1 -0
  11. package/dist/es/commands/identityCreate.js +316 -0
  12. package/dist/es/commands/identityCreate.js.map +1 -0
  13. package/dist/es/commands/identityImports.js +82 -0
  14. package/dist/es/commands/identityImports.js.map +1 -0
  15. package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
  16. package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
  17. package/dist/es/commands/identityVerificationMethodCreate.js +214 -0
  18. package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
  19. package/dist/es/commands/identityVerificationMethodImport.js +126 -0
  20. package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
  21. package/dist/es/commands/nodeSetIdentity.js +64 -0
  22. package/dist/es/commands/nodeSetIdentity.js.map +1 -0
  23. package/dist/es/commands/nodeSetTenant.js +68 -0
  24. package/dist/es/commands/nodeSetTenant.js.map +1 -0
  25. package/dist/es/commands/tenantCreate.js +139 -0
  26. package/dist/es/commands/tenantCreate.js.map +1 -0
  27. package/dist/es/commands/tenantImport.js +97 -0
  28. package/dist/es/commands/tenantImport.js.map +1 -0
  29. package/dist/es/commands/tenantUpdate.js +94 -0
  30. package/dist/es/commands/tenantUpdate.js.map +1 -0
  31. package/dist/es/commands/userCreate.js +212 -0
  32. package/dist/es/commands/userCreate.js.map +1 -0
  33. package/dist/es/commands/userUpdate.js +132 -0
  34. package/dist/es/commands/userUpdate.js.map +1 -0
  35. package/dist/es/commands/vaultKeyCreate.js +191 -0
  36. package/dist/es/commands/vaultKeyCreate.js.map +1 -0
  37. package/dist/es/commands/vaultKeyImport.js +104 -0
  38. package/dist/es/commands/vaultKeyImport.js.map +1 -0
  39. package/dist/es/defaults.js +19 -1
  40. package/dist/es/defaults.js.map +1 -1
  41. package/dist/es/index.js +7 -3
  42. package/dist/es/index.js.map +1 -1
  43. package/dist/es/models/ICliArgs.js +4 -0
  44. package/dist/es/models/ICliArgs.js.map +1 -0
  45. package/dist/es/models/ICliCommand.js +2 -0
  46. package/dist/es/models/ICliCommand.js.map +1 -0
  47. package/dist/es/models/ICliCommandDefinition.js +2 -0
  48. package/dist/es/models/ICliCommandDefinition.js.map +1 -0
  49. package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
  50. package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
  51. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  52. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  53. package/dist/es/models/INodeEngineState.js.map +1 -1
  54. package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
  55. package/dist/es/models/INodeOptions.js.map +1 -1
  56. package/dist/es/models/cliCommandParamType.js +4 -0
  57. package/dist/es/models/cliCommandParamType.js.map +1 -0
  58. package/dist/es/node.js +78 -41
  59. package/dist/es/node.js.map +1 -1
  60. package/dist/es/start.js +139 -0
  61. package/dist/es/start.js.map +1 -0
  62. package/dist/es/utils.js +11 -21
  63. package/dist/es/utils.js.map +1 -1
  64. package/dist/types/builders/engineEnvBuilder.d.ts +4 -1
  65. package/dist/types/builders/engineServerEnvBuilder.d.ts +5 -2
  66. package/dist/types/cli.d.ts +56 -0
  67. package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
  68. package/dist/types/commands/help.d.ts +23 -0
  69. package/dist/types/commands/identityCreate.d.ts +39 -0
  70. package/dist/types/commands/identityImports.d.ts +24 -0
  71. package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
  72. package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
  73. package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
  74. package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
  75. package/dist/types/commands/nodeSetTenant.d.ts +22 -0
  76. package/dist/types/commands/tenantCreate.d.ts +38 -0
  77. package/dist/types/commands/tenantImport.d.ts +26 -0
  78. package/dist/types/commands/tenantUpdate.d.ts +26 -0
  79. package/dist/types/commands/userCreate.d.ts +49 -0
  80. package/dist/types/commands/userUpdate.d.ts +38 -0
  81. package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
  82. package/dist/types/commands/vaultKeyImport.d.ts +28 -0
  83. package/dist/types/defaults.d.ts +11 -1
  84. package/dist/types/index.d.ts +7 -3
  85. package/dist/types/models/ICliArgs.d.ts +20 -0
  86. package/dist/types/models/ICliCommand.d.ts +17 -0
  87. package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
  88. package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
  89. package/dist/types/models/IEngineEnvironmentVariables.d.ts +62 -53
  90. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
  91. package/dist/types/models/INodeEngineState.d.ts +0 -8
  92. package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
  93. package/dist/types/models/INodeOptions.d.ts +6 -2
  94. package/dist/types/models/cliCommandParamType.d.ts +4 -0
  95. package/dist/types/node.d.ts +8 -4
  96. package/dist/types/{server.d.ts → start.d.ts} +7 -2
  97. package/dist/types/utils.d.ts +6 -8
  98. package/docs/changelog.md +136 -0
  99. package/docs/reference/functions/buildConfiguration.md +3 -3
  100. package/docs/reference/functions/buildEngineConfiguration.md +1 -1
  101. package/docs/reference/functions/buildEngineServerConfiguration.md +3 -3
  102. package/docs/reference/functions/constructCliCommand.md +27 -0
  103. package/docs/reference/functions/executeCommand.md +29 -0
  104. package/docs/reference/functions/getEnvDefaults.md +19 -0
  105. package/docs/reference/functions/getScriptDirectory.md +19 -0
  106. package/docs/reference/functions/parseCommandLineArgs.md +19 -0
  107. package/docs/reference/functions/processEnvOptions.md +27 -0
  108. package/docs/reference/functions/registerCommands.md +9 -0
  109. package/docs/reference/functions/run.md +8 -2
  110. package/docs/reference/functions/start.md +10 -4
  111. package/docs/reference/functions/substituteEnvOptions.md +25 -0
  112. package/docs/reference/index.md +16 -13
  113. package/docs/reference/interfaces/ICliArgs.md +35 -0
  114. package/docs/reference/interfaces/ICliCommand.md +23 -0
  115. package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
  116. package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
  117. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +110 -85
  118. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +166 -117
  119. package/docs/reference/interfaces/INodeEngineState.md +0 -16
  120. package/docs/reference/interfaces/INodeEnvironmentVariables.md +170 -201
  121. package/docs/reference/interfaces/INodeOptions.md +10 -2
  122. package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
  123. package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +3 -0
  124. package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +3 -0
  125. package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
  126. package/locales/en.json +589 -30
  127. package/package.json +3 -1
  128. package/dist/es/bootstrap.js +0 -374
  129. package/dist/es/bootstrap.js.map +0 -1
  130. package/dist/es/identity.js +0 -169
  131. package/dist/es/identity.js.map +0 -1
  132. package/dist/es/models/nodeFeatures.js +0 -21
  133. package/dist/es/models/nodeFeatures.js.map +0 -1
  134. package/dist/es/server.js +0 -78
  135. package/dist/es/server.js.map +0 -1
  136. package/dist/types/bootstrap.d.ts +0 -76
  137. package/dist/types/identity.d.ts +0 -14
  138. package/dist/types/models/nodeFeatures.d.ts +0 -21
  139. package/docs/reference/functions/bootstrap.md +0 -29
  140. package/docs/reference/functions/bootstrapAuth.md +0 -35
  141. package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
  142. package/docs/reference/functions/bootstrapContextIdHandlers.md +0 -35
  143. package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
  144. package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
  145. package/docs/reference/functions/bootstrapNodeId.md +0 -35
  146. package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
  147. package/docs/reference/functions/bootstrapTenantId.md +0 -35
  148. package/docs/reference/functions/getFeatures.md +0 -19
  149. package/docs/reference/type-aliases/NodeFeatures.md +0 -5
  150. package/docs/reference/variables/NodeFeatures.md +0 -25
  151. package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
@@ -1 +1 @@
1
- {"version":3,"file":"IEngineEnvironmentVariables.js","sourceRoot":"","sources":["../../../src/models/IEngineEnvironmentVariables.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The engine core environment variables.\n */\nexport interface IEngineEnvironmentVariables {\n\t/**\n\t * Start the engine in debug mode.\n\t */\n\tdebug?: string;\n\n\t/**\n\t * The root directory for storing items like state file.\n\t */\n\tstorageFileRoot?: string;\n\n\t/**\n\t * The name of the state file.\n\t */\n\tstateFilename?: string;\n\n\t/**\n\t * Is multi-tenant support enabled, defaults to false.\n\t */\n\ttenantEnabled?: string;\n\n\t/**\n\t * A tenant id to use as a default for the node.\n\t */\n\ttenantId?: string;\n\n\t/**\n\t * A tenant api key to use as a default for the node.\n\t */\n\ttenantApiKey?: string;\n\n\t/**\n\t * The type of the entity storage to create, comma separate for more than one connector.\n\t * values: file, memory, aws-dynamodb, azure-cosmosdb, gcp-firestoredb, scylladb, mysql, mongodb, postgresql\n\t */\n\tentityStorageConnectorType?: string;\n\n\t/**\n\t * The default entity storage connector to use, defaults to the first one in the list.\n\t */\n\tentityStorageConnectorDefault?: string;\n\n\t/**\n\t * A prefix for all the table in entity-storage, can be empty.\n\t */\n\tentityStorageTablePrefix?: string;\n\n\t/**\n\t * AWS DynamoDB auth mode, either credentials or pod.\n\t */\n\tawsDynamodbAuthMode?: string;\n\n\t/**\n\t * AWS Dynamo DB access key id.\n\t */\n\tawsDynamodbAccessKeyId?: string;\n\n\t/**\n\t * AWS Dynamo DB Endpoint if running local instance.\n\t */\n\tawsDynamodbEndpoint?: string;\n\n\t/**\n\t * AWS Dynamo DB region.\n\t */\n\tawsDynamodbRegion?: string;\n\n\t/**\n\t * AWS Dynamo DB secret access key.\n\t */\n\tawsDynamodbSecretAccessKey?: string;\n\n\t/**\n\t * Azure Cosmos DB key.\n\t */\n\tazureCosmosdbKey?: string;\n\n\t/**\n\t * Azure Cosmos DB container id.\n\t */\n\tazureCosmosdbContainerId?: string;\n\n\t/**\n\t * Azure Cosmos DB database id.\n\t */\n\tazureCosmosdbDatabaseId?: string;\n\n\t/**\n\t * Azure Cosmos DB endpoint.\n\t */\n\tazureCosmosdbEndpoint?: string;\n\n\t/**\n\t * GCP Firestore collection name.\n\t */\n\tgcpFirestoreCollectionName?: string;\n\n\t/**\n\t * GCP Firestore credentials.\n\t */\n\tgcpFirestoreCredentials?: string;\n\n\t/**\n\t * GCP Firestore database id.\n\t */\n\tgcpFirestoreDatabaseId?: string;\n\n\t/**\n\t * GCP Firestore endpoint.\n\t */\n\tgcpFirestoreApiEndpoint?: string;\n\n\t/**\n\t * GCP Firestore project id.\n\t */\n\tgcpFirestoreProjectId?: string;\n\n\t/**\n\t * ScyllaDB hosts as comma separated string.\n\t */\n\tscylladbHosts?: string;\n\n\t/**\n\t * ScyllaDB keyspace.\n\t */\n\tscylladbKeyspace?: string;\n\n\t/**\n\t * ScyllaDB local data center.\n\t */\n\tscylladbLocalDataCenter?: string;\n\n\t/**\n\t * ScyllaDB port.\n\t */\n\tscylladbPort?: string;\n\n\t/**\n\t * MySQL host.\n\t */\n\tmySqlHost?: string;\n\n\t/**\n\t * MySQL port.\n\t */\n\tmySqlPort?: number;\n\n\t/**\n\t * MySQL username.\n\t */\n\tmySqlUser?: string;\n\n\t/**\n\t * MySQL password.\n\t */\n\tmySqlPassword?: string;\n\n\t/**\n\t * MySQL Database.\n\t */\n\tmySqlDatabase?: string;\n\n\t/**\n\t * MongoDB host.\n\t */\n\tmongoDbHost?: string;\n\n\t/**\n\t * MongoDB port.\n\t */\n\tmongoDbPort?: number;\n\n\t/**\n\t * MongoDB username.\n\t */\n\tmongoDbUser?: string;\n\n\t/**\n\t * MongoDB password.\n\t */\n\tmongoDbPassword?: string;\n\n\t/**\n\t * MongoDB Database.\n\t */\n\tmongoDbDatabase?: string;\n\n\t/**\n\t * PostgreSQl host.\n\t */\n\tpostgreSqlHost?: string;\n\n\t/**\n\t * PostgreSQl port.\n\t */\n\tpostgreSqlPort?: number;\n\n\t/**\n\t * PostgreSQl username.\n\t */\n\tpostgreSqlUser?: string;\n\n\t/**\n\t * PostgreSQl password.\n\t */\n\tpostgreSqlPassword?: string;\n\n\t/**\n\t * PostgreSQl Database.\n\t */\n\tpostgreSqlDatabase?: string;\n\n\t/**\n\t * The security token for accessing IPFS API.\n\t */\n\tipfsBearerToken?: string;\n\n\t/**\n\t * The url for accessing IPFS API.\n\t */\n\tipfsApiUrl?: string;\n\n\t/**\n\t * The type of the entity storage to create, comma separate for more than one connector.\n\t * values: memory, file, ipfs, aws-s3, azure-storage, gcp-storage.\n\t */\n\tblobStorageConnectorType?: string;\n\n\t/**\n\t * The default blob storage connector to use, defaults to the first one in the list.\n\t */\n\tblobStorageConnectorDefault?: string;\n\n\t/**\n\t * Blog storage connector which has public access.\n\t */\n\tblobStorageConnectorPublic?: string;\n\n\t/**\n\t * Enable encryption for the blob storage.\n\t */\n\tblobStorageEnableEncryption?: string;\n\n\t/**\n\t * The id of the encryption key for the blob storage.\n\t */\n\tblobStorageEncryptionKeyId?: string;\n\n\t/**\n\t * A symmetric encryption key for the blob storage, should be ChaCha20Poly1305 in base64 format.\n\t * If encryption is enabled but a key is not provided one will be generated.\n\t */\n\tblobStorageSymmetricEncryptionKey?: string;\n\n\t/**\n\t * A prefix for all the blobs in blob-storage, can be empty.\n\t */\n\tblobStoragePrefix?: string;\n\n\t/**\n\t * AWS S3 region.\n\t */\n\tawsS3Region?: string;\n\n\t/**\n\t * AWS S3 bucket name.\n\t */\n\tawsS3BucketName?: string;\n\n\t/**\n\t * AWS S3 auth mode, either credentials or pod, defaults to credentials.\n\t */\n\tawsS3AuthMode?: string;\n\n\t/**\n\t * AWS S3 access key id.\n\t */\n\tawsS3AccessKeyId?: string;\n\n\t/**\n\t * AWS S3 secret access key.\n\t */\n\tawsS3SecretAccessKey?: string;\n\n\t/**\n\t * AWS S3 endpoint.\n\t */\n\tawsS3Endpoint?: string;\n\n\t/**\n\t * Azure Storage account key.\n\t */\n\tazureStorageAccountKey?: string;\n\n\t/**\n\t * Azure Storage account name.\n\t */\n\tazureStorageAccountName?: string;\n\n\t/**\n\t * Azure Storage container.\n\t */\n\tazureStorageContainerName?: string;\n\n\t/**\n\t * Azure Storage endpoint.\n\t */\n\tazureStorageEndpoint?: string;\n\n\t/**\n\t * GCP Storage bucket.\n\t */\n\tgcpStorageBucketName?: string;\n\n\t/**\n\t * GCP Storage credentials.\n\t */\n\tgcpStorageCredentials?: string;\n\n\t/**\n\t * GCP Storage endpoint.\n\t */\n\tgcpStorageEndpoint?: string;\n\n\t/**\n\t * GCP Storage project id.\n\t */\n\tgcpStorageProjectId?: string;\n\n\t/**\n\t * The type of the default vault connector: entity-storage, hashicorp.\n\t */\n\tvaultConnector?: string;\n\n\t/**\n\t * Hashicorp Vault token.\n\t */\n\thashicorpVaultToken?: string;\n\n\t/**\n\t * Hashicorp Vault endpoint.\n\t */\n\thashicorpVaultEndpoint?: string;\n\n\t/**\n\t * The type of logging task connector, can be a comma separated list: console, entity-storage.\n\t */\n\tloggingConnector?: string;\n\n\t/**\n\t * The type of background task connector: entity-storage.\n\t */\n\tbackgroundTaskConnector?: string;\n\n\t/**\n\t * The type of event bus connector: local.\n\t */\n\teventBusConnector?: string;\n\n\t/**\n\t * The type of event bus component: service.\n\t */\n\teventBusComponent?: string;\n\n\t/**\n\t * Are the messaging components enabled, defaults to false.\n\t */\n\tmessagingEnabled?: string;\n\n\t/**\n\t * AWS SES region.\n\t */\n\tawsSesRegion?: string;\n\n\t/**\n\t * AWS SES auth mode, either credentials or pod, defaults to credentials.\n\t */\n\tawsSesAuthMode?: string;\n\n\t/**\n\t * AWS SES secret access key.\n\t */\n\tawsSesSecretAccessKey?: string;\n\n\t/**\n\t * AWS SES access key id.\n\t */\n\tawsSesAccessKeyId?: string;\n\n\t/**\n\t * AWS SES endpoint.\n\t */\n\tawsSesEndpoint?: string;\n\n\t/**\n\t * The applications for the push notifications JSON stringified array of IAwsApplicationSettings.\n\t */\n\tawsMessagingPushNotificationApplications?: string;\n\n\t/**\n\t * The type of messaging email connector: entity-storage, aws.\n\t */\n\tmessagingEmailConnector?: string;\n\n\t/**\n\t * The type of messaging sms connector: entity-storage, aws.\n\t */\n\tmessagingSmsConnector?: string;\n\n\t/**\n\t * The type of messaging push notification connector: entity-storage, aws.\n\t */\n\tmessagingPushNotificationConnector?: string;\n\n\t/**\n\t * The type of telemetry connector: entity-storage.\n\t */\n\ttelemetryConnector?: string;\n\n\t/**\n\t * The type of faucet connector: entity-storage, iota.\n\t */\n\tfaucetConnector?: string;\n\n\t/**\n\t * The type of wallet connector: entity-storage, iota.\n\t */\n\twalletConnector?: string;\n\n\t/**\n\t * The type of NFT connector: entity-storage, iota.\n\t */\n\tnftConnector?: string;\n\n\t/**\n\t * The type of identity connector: entity-storage, iota.\n\t */\n\tidentityConnector?: string;\n\n\t/**\n\t * The type of identity resolver connector: entity-storage, iota.\n\t */\n\tidentityResolverConnector?: string;\n\n\t/**\n\t * The type of verifiable storage connector: entity-storage, iota.\n\t */\n\tverifiableStorageConnector?: string;\n\n\t/**\n\t * IOTA Faucet Endpoint.\n\t */\n\tiotaFaucetEndpoint?: string;\n\n\t/**\n\t * IOTA Node Endpoint.\n\t */\n\tiotaNodeEndpoint?: string;\n\n\t/**\n\t * IOTA network.\n\t */\n\tiotaNetwork?: string;\n\n\t/**\n\t * IOTA coin type.\n\t */\n\tiotaCoinType?: string;\n\n\t/**\n\t * IOTA Explorer Endpoint.\n\t */\n\tiotaExplorerEndpoint?: string;\n\n\t/**\n\t * IOTA Gas Station Endpoint.\n\t */\n\tiotaGasStationEndpoint?: string;\n\n\t/**\n\t * IOTA Gas Station Authentication Token.\n\t */\n\tiotaGasStationAuthToken?: string;\n\n\t/**\n\t * Universal Resolver Endpoint.\n\t */\n\tuniversalResolverEndpoint?: string;\n\n\t/**\n\t * The type of identity profile connector: entity-storage.\n\t */\n\tidentityProfileConnector?: string;\n\n\t/**\n\t * The identity verification method id to use with immutable proofs.\n\t */\n\timmutableProofVerificationMethodId?: string;\n\n\t/**\n\t * The type of attestation connector: entity-storage, iota.\n\t */\n\tattestationConnector?: string;\n\n\t/**\n\t * The identity verification method id to use with attestation.\n\t */\n\tattestationVerificationMethodId?: string;\n\n\t/**\n\t * Is the data processing enabled, defaults to false.\n\t */\n\tdataProcessingEnabled?: string;\n\n\t/**\n\t * The type of the default data converters, can be a comma separated list: json, xml.\n\t */\n\tdataConverterConnectors?: string;\n\n\t/**\n\t * The type of the default data extractor, can be a comma separated list: json-path.\n\t */\n\tdataExtractorConnectors?: string;\n\n\t/**\n\t * Is the auditable item graph enabled, defaults to false.\n\t */\n\tauditableItemGraphEnabled?: string;\n\n\t/**\n\t * Is the auditable item stream enabled, defaults to false.\n\t */\n\tauditableItemStreamEnabled?: string;\n\n\t/**\n\t * Is the document management enabled, defaults to false.\n\t */\n\tdocumentManagementEnabled?: string;\n\n\t/**\n\t * Is the synchronised storage enabled, defaults to false.\n\t */\n\tsynchronisedStorageEnabled?: string;\n\n\t/**\n\t * Url which points to the api for a trusted synchronised storage node, not required if this is a trusted node.\n\t */\n\tsynchronisedStorageTrustedUrl?: string;\n\n\t/**\n\t * The key for the smart contract which contains the verifiable storage pointer store for synchronised storage.\n\t * This only required if using a custom verifiable storage item, otherwise it will default to the network name.\n\t */\n\tsynchronisedStorageVerifiableStorageKeyId?: string;\n\n\t/**\n\t * The key from the vault which is used to encrypt the synchronised storage blobs.\n\t * Only required for trusted nodes, as regular nodes will request from the trusted nodes.\n\t * Defaults to synchronised-storage-blob-encryption\n\t */\n\tsynchronisedStorageBlobStorageEncryptionKeyId?: string;\n\n\t/**\n\t * The key used for blob encryption, should be ChaCha20Poly1305 encoded as base64.\n\t * Only required for trusted nodes, as regular nodes will not write encrypted data.\n\t */\n\tsynchronisedStorageBlobStorageKey?: string;\n\n\t/**\n\t * How often to check for entity updates in minutes.\n\t * @default 5\n\t */\n\tsynchronisedStorageEntityUpdateIntervalMinutes?: string;\n\n\t/**\n\t * Interval to perform consolidation of changesets, only used if this is a trusted node.\n\t * @default 60\n\t */\n\tsynchronisedStorageConsolidationIntervalMinutes?: string;\n\n\t/**\n\t * The number of entities to process in a single consolidation batch, only used if this is a trusted node.\n\t * @default 1000\n\t */\n\tsynchronisedStorageConsolidationBatchSize?: string;\n\n\t/**\n\t * The maximum number of consolidations to keep in storage, only used if this is a trusted node.\n\t * @default 5\n\t */\n\tsynchronisedStorageMaxConsolidations?: string;\n\n\t/**\n\t * Is the federated catalogue enabled, defaults to false.\n\t */\n\tfederatedCatalogueEnabled?: string;\n\n\t/**\n\t * Federated catalog TTL for the cache.\n\t */\n\tfederatedCatalogueCacheTtlMs?: number;\n\n\t/**\n\t * Federated catalog clearing house approver list, stringified array of DIDs.\n\t */\n\tfederatedCatalogueClearingHouseApproverList?: string;\n\n\t/**\n\t * Is the rights management enabled, defaults to false.\n\t */\n\trightsManagementEnabled?: string;\n\n\t/**\n\t * What is the base callback url for rights management negotiations e.g. https://my-node/rights-management.\n\t */\n\trightsManagementBaseCallbackUrl?: string;\n\n\t/**\n\t * The rights management configuration which includes the information sources modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementInformationSources?: string;\n\n\t/**\n\t * The rights management configuration which includes the negotiator modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementNegotiators?: string;\n\n\t/**\n\t * The rights management configuration which includes the requester modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementRequesters?: string;\n\n\t/**\n\t * The rights management configuration which includes the execution actions modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementExecutionActions?: string;\n\n\t/**\n\t * The rights management configuration which includes the enforcement processor modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementEnforcementProcessors?: string;\n\n\t/**\n\t * The rights management configuration which includes the arbiter modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementArbiters?: string;\n\n\t/**\n\t * The rights management configuration which includes the offer modules to load.\n\t * Use the @json: prefix to specify the path to the JSON configuration file.\n\t */\n\trightsManagementOffers?: string;\n\n\t/**\n\t * Is the task scheduler enabled, defaults to false.\n\t */\n\ttaskSchedulerEnabled?: string;\n\n\t/**\n\t * Is the data space connector enabled, defaults to false.\n\t */\n\tdataSpaceConnectorEnabled?: string;\n\n\t/**\n\t * The length of time to retain the activity logs for in minutes, set to -1 to keep forever.\n\t * @default 10\n\t */\n\tdataSpaceConnectorRetainActivityLogsFor?: string;\n\n\t/**\n\t * The interval for cleaning up the activity logs.\n\t * @default 60\n\t */\n\tdataSpaceConnectorActivityLogsCleanUpInterval?: string;\n\n\t/**\n\t * Enable verifiable credential authentication for the API.\n\t */\n\tvcAuthenticationEnabled?: string;\n\n\t/**\n\t * Verifiable credential assertion for node to node communication.\n\t * Defaults to node-authentication-assertion.\n\t */\n\tvcAuthenticationVerificationMethodId?: string;\n\n\t/**\n\t * A comma separated list of additional node extensions to load, the initialiseExtension method will be called for each extension.\n\t */\n\textensions?: string;\n}\n"]}
1
+ {"version":3,"file":"IEngineEnvironmentVariables.js","sourceRoot":"","sources":["../../../src/models/IEngineEnvironmentVariables.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The engine core environment variables.\n */\nexport interface IEngineEnvironmentVariables {\n\t/**\n\t * Start the engine in debug mode.\n\t */\n\tdebug?: string;\n\n\t/**\n\t * Start the engine in silent mode.\n\t */\n\tsilent?: string;\n\n\t/**\n\t * The root directory for storing items like state file.\n\t */\n\tstorageFileRoot?: string;\n\n\t/**\n\t * The name of the state file.\n\t */\n\tstateFilename?: string;\n\n\t/**\n\t * Does the node have a unique ID, defaults to true.\n\t */\n\tnodeIdentityEnabled?: string;\n\n\t/**\n\t * Is multi-tenant support enabled, defaults to false.\n\t */\n\ttenantEnabled?: string;\n\n\t/**\n\t * The type of the entity storage to create, comma separate for more than one connector.\n\t * values: file, memory, aws-dynamodb, azure-cosmosdb, gcp-firestoredb, scylladb, mysql, mongodb, postgresql\n\t */\n\tentityStorageConnectorType?: string;\n\n\t/**\n\t * The default entity storage connector to use, defaults to the first one in the list.\n\t */\n\tentityStorageConnectorDefault?: string;\n\n\t/**\n\t * A prefix for all the table in entity-storage, can be empty.\n\t */\n\tentityStorageTablePrefix?: string;\n\n\t/**\n\t * AWS DynamoDB auth mode, either credentials or pod.\n\t */\n\tawsDynamodbAuthMode?: string;\n\n\t/**\n\t * AWS Dynamo DB access key id.\n\t */\n\tawsDynamodbAccessKeyId?: string;\n\n\t/**\n\t * AWS Dynamo DB Endpoint if running local instance.\n\t */\n\tawsDynamodbEndpoint?: string;\n\n\t/**\n\t * AWS Dynamo DB region.\n\t */\n\tawsDynamodbRegion?: string;\n\n\t/**\n\t * AWS Dynamo DB secret access key.\n\t */\n\tawsDynamodbSecretAccessKey?: string;\n\n\t/**\n\t * AWS Dynamo DB connection timeout.\n\t */\n\tawsDynamodbConnectionTimeoutMs?: string;\n\n\t/**\n\t * Azure Cosmos DB key.\n\t */\n\tazureCosmosdbKey?: string;\n\n\t/**\n\t * Azure Cosmos DB container id.\n\t */\n\tazureCosmosdbContainerId?: string;\n\n\t/**\n\t * Azure Cosmos DB database id.\n\t */\n\tazureCosmosdbDatabaseId?: string;\n\n\t/**\n\t * Azure Cosmos DB endpoint.\n\t */\n\tazureCosmosdbEndpoint?: string;\n\n\t/**\n\t * GCP Firestore collection name.\n\t */\n\tgcpFirestoreCollectionName?: string;\n\n\t/**\n\t * GCP Firestore credentials.\n\t */\n\tgcpFirestoreCredentials?: string;\n\n\t/**\n\t * GCP Firestore database id.\n\t */\n\tgcpFirestoreDatabaseId?: string;\n\n\t/**\n\t * GCP Firestore endpoint.\n\t */\n\tgcpFirestoreApiEndpoint?: string;\n\n\t/**\n\t * GCP Firestore project id.\n\t */\n\tgcpFirestoreProjectId?: string;\n\n\t/**\n\t * ScyllaDB hosts as comma separated string.\n\t */\n\tscylladbHosts?: string;\n\n\t/**\n\t * ScyllaDB keyspace.\n\t */\n\tscylladbKeyspace?: string;\n\n\t/**\n\t * ScyllaDB local data center.\n\t */\n\tscylladbLocalDataCenter?: string;\n\n\t/**\n\t * ScyllaDB port.\n\t */\n\tscylladbPort?: string;\n\n\t/**\n\t * MySQL host.\n\t */\n\tmySqlHost?: string;\n\n\t/**\n\t * MySQL port.\n\t */\n\tmySqlPort?: number;\n\n\t/**\n\t * MySQL username.\n\t */\n\tmySqlUser?: string;\n\n\t/**\n\t * MySQL password.\n\t */\n\tmySqlPassword?: string;\n\n\t/**\n\t * MySQL Database.\n\t */\n\tmySqlDatabase?: string;\n\n\t/**\n\t * MongoDB host.\n\t */\n\tmongoDbHost?: string;\n\n\t/**\n\t * MongoDB port.\n\t */\n\tmongoDbPort?: number;\n\n\t/**\n\t * MongoDB username.\n\t */\n\tmongoDbUser?: string;\n\n\t/**\n\t * MongoDB password.\n\t */\n\tmongoDbPassword?: string;\n\n\t/**\n\t * MongoDB Database.\n\t */\n\tmongoDbDatabase?: string;\n\n\t/**\n\t * PostgreSQl host.\n\t */\n\tpostgreSqlHost?: string;\n\n\t/**\n\t * PostgreSQl port.\n\t */\n\tpostgreSqlPort?: number;\n\n\t/**\n\t * PostgreSQl username.\n\t */\n\tpostgreSqlUser?: string;\n\n\t/**\n\t * PostgreSQl password.\n\t */\n\tpostgreSqlPassword?: string;\n\n\t/**\n\t * PostgreSQl Database.\n\t */\n\tpostgreSqlDatabase?: string;\n\n\t/**\n\t * The security token for accessing IPFS API.\n\t */\n\tipfsBearerToken?: string;\n\n\t/**\n\t * The url for accessing IPFS API.\n\t */\n\tipfsApiUrl?: string;\n\n\t/**\n\t * The type of the entity storage to create, comma separate for more than one connector.\n\t * values: memory, file, ipfs, aws-s3, azure-storage, gcp-storage.\n\t */\n\tblobStorageConnectorType?: string;\n\n\t/**\n\t * The default blob storage connector to use, defaults to the first one in the list.\n\t */\n\tblobStorageConnectorDefault?: string;\n\n\t/**\n\t * Blog storage connector which has public access.\n\t */\n\tblobStorageConnectorPublic?: string;\n\n\t/**\n\t * Enable encryption for the blob storage.\n\t */\n\tblobStorageEnableEncryption?: string;\n\n\t/**\n\t * The id of the encryption key for the blob storage.\n\t */\n\tblobStorageEncryptionKeyId?: string;\n\n\t/**\n\t * A prefix for all the blobs in blob-storage, can be empty.\n\t */\n\tblobStoragePrefix?: string;\n\n\t/**\n\t * AWS S3 region.\n\t */\n\tawsS3Region?: string;\n\n\t/**\n\t * AWS S3 bucket name.\n\t */\n\tawsS3BucketName?: string;\n\n\t/**\n\t * AWS S3 auth mode, either credentials or pod, defaults to credentials.\n\t */\n\tawsS3AuthMode?: string;\n\n\t/**\n\t * AWS S3 access key id.\n\t */\n\tawsS3AccessKeyId?: string;\n\n\t/**\n\t * AWS S3 secret access key.\n\t */\n\tawsS3SecretAccessKey?: string;\n\n\t/**\n\t * AWS S3 endpoint.\n\t */\n\tawsS3Endpoint?: string;\n\n\t/**\n\t * Azure Storage account key.\n\t */\n\tazureStorageAccountKey?: string;\n\n\t/**\n\t * Azure Storage account name.\n\t */\n\tazureStorageAccountName?: string;\n\n\t/**\n\t * Azure Storage container.\n\t */\n\tazureStorageContainerName?: string;\n\n\t/**\n\t * Azure Storage endpoint.\n\t */\n\tazureStorageEndpoint?: string;\n\n\t/**\n\t * GCP Storage bucket.\n\t */\n\tgcpStorageBucketName?: string;\n\n\t/**\n\t * GCP Storage credentials.\n\t */\n\tgcpStorageCredentials?: string;\n\n\t/**\n\t * GCP Storage endpoint.\n\t */\n\tgcpStorageEndpoint?: string;\n\n\t/**\n\t * GCP Storage project id.\n\t */\n\tgcpStorageProjectId?: string;\n\n\t/**\n\t * The type of the default vault connector: entity-storage, hashicorp.\n\t */\n\tvaultConnector?: string;\n\n\t/**\n\t * Prefix to prepend to entries in the vault.\n\t */\n\tvaultPrefix?: string;\n\n\t/**\n\t * Hashicorp Vault token.\n\t */\n\thashicorpVaultToken?: string;\n\n\t/**\n\t * Hashicorp Vault endpoint.\n\t */\n\thashicorpVaultEndpoint?: string;\n\n\t/**\n\t * The type of logging task connector, can be a comma separated list: console, entity-storage.\n\t */\n\tloggingConnector?: string;\n\n\t/**\n\t * The type of event bus connector: local.\n\t */\n\teventBusConnector?: string;\n\n\t/**\n\t * The type of event bus component: service.\n\t */\n\teventBusComponent?: string;\n\n\t/**\n\t * Are the messaging components enabled, defaults to false.\n\t */\n\tmessagingEnabled?: string;\n\n\t/**\n\t * AWS SES region.\n\t */\n\tawsSesRegion?: string;\n\n\t/**\n\t * AWS SES auth mode, either credentials or pod, defaults to credentials.\n\t */\n\tawsSesAuthMode?: string;\n\n\t/**\n\t * AWS SES secret access key.\n\t */\n\tawsSesSecretAccessKey?: string;\n\n\t/**\n\t * AWS SES access key id.\n\t */\n\tawsSesAccessKeyId?: string;\n\n\t/**\n\t * AWS SES endpoint.\n\t */\n\tawsSesEndpoint?: string;\n\n\t/**\n\t * The applications for the push notifications JSON stringified array of IAwsApplicationSettings.\n\t */\n\tawsMessagingPushNotificationApplications?: string;\n\n\t/**\n\t * The type of messaging email connector: entity-storage, aws.\n\t */\n\tmessagingEmailConnector?: string;\n\n\t/**\n\t * The type of messaging sms connector: entity-storage, aws.\n\t */\n\tmessagingSmsConnector?: string;\n\n\t/**\n\t * The type of messaging push notification connector: entity-storage, aws.\n\t */\n\tmessagingPushNotificationConnector?: string;\n\n\t/**\n\t * The type of telemetry connector: entity-storage.\n\t */\n\ttelemetryConnector?: string;\n\n\t/**\n\t * The type of faucet connector: entity-storage, iota.\n\t */\n\tfaucetConnector?: string;\n\n\t/**\n\t * The type of wallet connector: entity-storage, iota.\n\t */\n\twalletConnector?: string;\n\n\t/**\n\t * The type of NFT connector: entity-storage, iota.\n\t */\n\tnftConnector?: string;\n\n\t/**\n\t * The type of identity connector: entity-storage, iota.\n\t */\n\tidentityConnector?: string;\n\n\t/**\n\t * The index of the wallet address to use, defaults to 0.\n\t */\n\tidentityWalletAddressIndex?: string;\n\n\t/**\n\t * The type of identity resolver connector: entity-storage, iota.\n\t */\n\tidentityResolverConnector?: string;\n\n\t/**\n\t * The type of verifiable storage connector: entity-storage, iota.\n\t */\n\tverifiableStorageConnector?: string;\n\n\t/**\n\t * IOTA Faucet Endpoint.\n\t */\n\tiotaFaucetEndpoint?: string;\n\n\t/**\n\t * IOTA Node Endpoint.\n\t */\n\tiotaNodeEndpoint?: string;\n\n\t/**\n\t * IOTA network.\n\t */\n\tiotaNetwork?: string;\n\n\t/**\n\t * IOTA coin type.\n\t */\n\tiotaCoinType?: string;\n\n\t/**\n\t * IOTA Explorer Endpoint.\n\t */\n\tiotaExplorerEndpoint?: string;\n\n\t/**\n\t * IOTA Gas Station Endpoint.\n\t */\n\tiotaGasStationEndpoint?: string;\n\n\t/**\n\t * IOTA Gas Station Authentication Token.\n\t */\n\tiotaGasStationAuthToken?: string;\n\n\t/**\n\t * Universal Resolver Endpoint.\n\t */\n\tuniversalResolverEndpoint?: string;\n\n\t/**\n\t * The type of identity profile connector: entity-storage.\n\t */\n\tidentityProfileConnector?: string;\n\n\t/**\n\t * The identity verification method id to use with immutable proofs.\n\t */\n\timmutableProofVerificationMethodId?: string;\n\n\t/**\n\t * The type of attestation connector: entity-storage, iota.\n\t */\n\tattestationConnector?: string;\n\n\t/**\n\t * The identity verification method id to use with attestation.\n\t */\n\tattestationVerificationMethodId?: string;\n\n\t/**\n\t * Is the data processing enabled, defaults to false.\n\t */\n\tdataProcessingEnabled?: string;\n\n\t/**\n\t * The type of the default data converters, can be a comma separated list: json, xml.\n\t */\n\tdataConverterConnectors?: string;\n\n\t/**\n\t * The type of the default data extractor, can be a comma separated list: json-path.\n\t */\n\tdataExtractorConnectors?: string;\n\n\t/**\n\t * Is the auditable item graph enabled, defaults to false.\n\t */\n\tauditableItemGraphEnabled?: string;\n\n\t/**\n\t * Is the auditable item stream enabled, defaults to false.\n\t */\n\tauditableItemStreamEnabled?: string;\n\n\t/**\n\t * Is the document management enabled, defaults to false.\n\t */\n\tdocumentManagementEnabled?: string;\n\n\t/**\n\t * Is the synchronised storage enabled, defaults to false.\n\t */\n\tsynchronisedStorageEnabled?: string;\n\n\t/**\n\t * Url which points to the api for a trusted synchronised storage node, not required if this is a trusted node.\n\t */\n\tsynchronisedStorageTrustedUrl?: string;\n\n\t/**\n\t * The key for the smart contract which contains the verifiable storage pointer store for synchronised storage.\n\t * This only required if using a custom verifiable storage item, otherwise it will default to the network name.\n\t */\n\tsynchronisedStorageVerifiableStorageKeyId?: string;\n\n\t/**\n\t * The key from the vault which is used to encrypt the synchronised storage blobs.\n\t * Only required for trusted nodes, as regular nodes will request from the trusted nodes.\n\t * Defaults to synchronised-storage-blob-encryption\n\t */\n\tsynchronisedStorageBlobStorageEncryptionKeyId?: string;\n\n\t/**\n\t * The key used for blob encryption, should be ChaCha20Poly1305 encoded as base64.\n\t * Only required for trusted nodes, as regular nodes will not write encrypted data.\n\t */\n\tsynchronisedStorageBlobStorageKey?: string;\n\n\t/**\n\t * How often to check for entity updates in minutes.\n\t * @default 5\n\t */\n\tsynchronisedStorageEntityUpdateIntervalMinutes?: string;\n\n\t/**\n\t * Interval to perform consolidation of changesets, only used if this is a trusted node.\n\t * @default 60\n\t */\n\tsynchronisedStorageConsolidationIntervalMinutes?: string;\n\n\t/**\n\t * The number of entities to process in a single consolidation batch, only used if this is a trusted node.\n\t * @default 1000\n\t */\n\tsynchronisedStorageConsolidationBatchSize?: string;\n\n\t/**\n\t * The maximum number of consolidations to keep in storage, only used if this is a trusted node.\n\t * @default 5\n\t */\n\tsynchronisedStorageMaxConsolidations?: string;\n\n\t/**\n\t * Is the federated catalogue enabled, defaults to false.\n\t */\n\tfederatedCatalogueEnabled?: string;\n\n\t/**\n\t * Federated catalog filters, command separated list of filters to add.\n\t */\n\tfederatedCatalogueFilters?: string;\n\n\t/**\n\t * Is the trust management enabled, defaults to false.\n\t */\n\ttrustEnabled?: string;\n\n\t/**\n\t * The trust generators to add to the factory, comma separated list.\n\t */\n\ttrustGenerators?: string;\n\n\t/**\n\t * The trust verifiers to add to the factory, comma separated list.\n\t */\n\ttrustVerifiers?: string;\n\n\t/**\n\t * The verification method to use for trust identities.\n\t * Defaults to trust-assertion.\n\t */\n\ttrustVerificationMethodId?: string;\n\n\t/**\n\t * The trust time to live for generating JWTs.\n\t * Defaults to undefined for never expiring.\n\t */\n\ttrustJwtTtlSeconds?: string;\n\n\t/**\n\t * Is the rights management enabled, defaults to false.\n\t */\n\trightsManagementEnabled?: string;\n\n\t/**\n\t * What is the callback path for rights management negotiations, will be combined with hosting public url e.g. /callback.\n\t */\n\trightsManagementCallbackPath?: string;\n\n\t/**\n\t * The rights management policy information sources to add to the factory.\n\t */\n\trightsManagementPolicyInformationSources?: string;\n\n\t/**\n\t * The rights management policy negotiators sources to add to the factory.\n\t */\n\trightsManagementPolicyNegotiators?: string;\n\n\t/**\n\t * The rights management policy requesters to add to the factory.\n\t */\n\trightsManagementPolicyRequesters?: string;\n\n\t/**\n\t * The rights management policy execution actions to add to the factory.\n\t */\n\trightsManagementPolicyExecutionActions?: string;\n\n\t/**\n\t * The rights management policy enforcement processors to add to the factory.\n\t */\n\trightsManagementPolicyEnforcementProcessors?: string;\n\n\t/**\n\t * The rights management policy arbiters to add to the factory.\n\t */\n\trightsManagementPolicyArbiters?: string;\n\n\t/**\n\t * The rights management policy obligation enforcers to add to the factory.\n\t */\n\trightsManagementPolicyObligationEnforcers?: string;\n\n\t/**\n\t * Are background tasks enabled, defaults to false.\n\t */\n\tbackgroundTasksEnabled?: string;\n\n\t/**\n\t * Is the task scheduler enabled, defaults to false.\n\t */\n\ttaskSchedulerEnabled?: string;\n\n\t/**\n\t * Is the data space connector enabled, defaults to false.\n\t */\n\tdataSpaceConnectorEnabled?: string;\n\n\t/**\n\t * The length of time to retain the activity logs for in minutes, set to -1 to keep forever.\n\t * @default 10\n\t */\n\tdataSpaceConnectorRetainActivityLogsFor?: string;\n\n\t/**\n\t * The interval for cleaning up the activity logs.\n\t * @default 60\n\t */\n\tdataSpaceConnectorActivityLogsCleanUpInterval?: string;\n\n\t/**\n\t * A comma separated list of additional node extensions to load, the initialiseExtension method will be called for each extension.\n\t */\n\textensions?: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IEngineServerEnvironmentVariables.js","sourceRoot":"","sources":["../../../src/models/IEngineServerEnvironmentVariables.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineEnvironmentVariables } from \"./IEngineEnvironmentVariables.js\";\n\n/**\n * The engine server environment variables.\n */\nexport interface IEngineServerEnvironmentVariables extends IEngineEnvironmentVariables {\n\t/**\n\t * The port to serve the API from.\n\t */\n\tport?: string;\n\n\t/**\n\t * The host to serve the API from.\n\t */\n\thost?: string;\n\n\t/**\n\t * The CORS origins to allow, defaults to *.\n\t */\n\tcorsOrigins?: string;\n\n\t/**\n\t * The CORS methods to allow, defaults to GET, POST, PUT, DELETE, OPTIONS.\n\t */\n\thttpMethods?: string;\n\n\t/**\n\t * The CORS headers to allow.\n\t */\n\thttpAllowedHeaders?: string;\n\n\t/**\n\t * The CORS headers to expose.\n\t */\n\thttpExposedHeaders?: string;\n\n\t/**\n\t * The type of auth admin processor to use on the API: entity-storage.\n\t */\n\tauthAdminProcessorType?: string;\n\n\t/**\n\t * The type of auth processor to use on the API: entity-storage.\n\t */\n\tauthProcessorType?: string;\n\n\t/**\n\t * The id of the key in the vault to use for signing in auth operations.\n\t */\n\tauthSigningKeyId?: string;\n\n\t/**\n\t * Additional MIME type processors to include, comma separated.\n\t */\n\tmimeTypeProcessors?: string;\n\n\t/**\n\t * Include the body in the REST logging output, useful for debugging.\n\t */\n\trouteLoggingIncludeBody?: string;\n\n\t/**\n\t * Include the full base 64 output in the REST logging output, useful for debugging.\n\t */\n\trouteLoggingFullBase64?: string;\n\n\t/**\n\t * List of properties to obfuscate in the REST logging output, comma separated.\n\t */\n\trouteLoggingObfuscateProperties?: string;\n}\n"]}
1
+ {"version":3,"file":"IEngineServerEnvironmentVariables.js","sourceRoot":"","sources":["../../../src/models/IEngineServerEnvironmentVariables.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineEnvironmentVariables } from \"./IEngineEnvironmentVariables.js\";\n\n/**\n * The engine server environment variables.\n */\nexport interface IEngineServerEnvironmentVariables extends IEngineEnvironmentVariables {\n\t/**\n\t * The port to serve the API from.\n\t */\n\tport?: string;\n\n\t/**\n\t * The host to serve the API from.\n\t */\n\thost?: string;\n\n\t/**\n\t * The CORS origins to allow, defaults to *.\n\t */\n\tcorsOrigins?: string;\n\n\t/**\n\t * The CORS methods to allow, defaults to GET, POST, PUT, DELETE, OPTIONS.\n\t */\n\thttpMethods?: string;\n\n\t/**\n\t * The CORS headers to allow.\n\t */\n\thttpAllowedHeaders?: string;\n\n\t/**\n\t * The CORS headers to expose.\n\t */\n\thttpExposedHeaders?: string;\n\n\t/**\n\t * The public origin URL for the API e.g. https://api.example.com:1234\n\t */\n\tpublicOrigin?: string;\n\n\t/**\n\t * The type of auth admin processor to use on the API: entity-storage.\n\t */\n\tauthAdminProcessorType?: string;\n\n\t/**\n\t * The type of auth processor to use on the API: entity-storage.\n\t */\n\tauthProcessorType?: string;\n\n\t/**\n\t * The id of the key in the vault to use for signing in auth operations.\n\t */\n\tauthSigningKeyId?: string;\n\n\t/**\n\t * Additional MIME type processors to include, comma separated.\n\t */\n\tmimeTypeProcessors?: string;\n\n\t/**\n\t * Include the body in the REST logging output, useful for debugging.\n\t */\n\trouteLoggingIncludeBody?: string;\n\n\t/**\n\t * Include the full base 64 output in the REST logging output, useful for debugging.\n\t */\n\trouteLoggingFullBase64?: string;\n\n\t/**\n\t * List of properties to obfuscate in the REST logging output, comma separated.\n\t */\n\trouteLoggingObfuscateProperties?: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"INodeEngineState.js","sourceRoot":"","sources":["../../../src/models/INodeEngineState.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineState } from \"@twin.org/engine-models\";\n\n/**\n * The engine state for the node.\n */\nexport interface INodeEngineState extends IEngineState {\n\t/**\n\t * The identity for the node.\n\t */\n\tnodeId?: string;\n\n\t/**\n\t * The tenant id for the node.\n\t */\n\tnodeTenantId?: string;\n\n\t/**\n\t * The identity for the organization.\n\t */\n\tnodeOrganizationId?: string;\n\n\t/**\n\t * The identity for the admin user.\n\t */\n\tnodeAdminUserId?: string;\n}\n"]}
1
+ {"version":3,"file":"INodeEngineState.js","sourceRoot":"","sources":["../../../src/models/INodeEngineState.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineState } from \"@twin.org/engine-models\";\n\n/**\n * The engine state for the node.\n */\nexport interface INodeEngineState extends IEngineState {\n\t/**\n\t * The identity for the node.\n\t */\n\tnodeId?: string;\n\n\t/**\n\t * The tenant id for the node.\n\t */\n\tnodeTenantId?: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"INodeEnvironmentVariables.js","sourceRoot":"","sources":["../../../src/models/INodeEnvironmentVariables.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineServerEnvironmentVariables } from \"./IEngineServerEnvironmentVariables.js\";\n\n/**\n * The environment variables for the node.\n */\nexport interface INodeEnvironmentVariables extends IEngineServerEnvironmentVariables {\n\t/**\n\t * The features that are enabled on the node.\n\t * @default []\n\t */\n\tfeatures?: string;\n\n\t/**\n\t * The identity of the node which, if empty and node-identity feature is enabled it will be generated.\n\t */\n\tnodeIdentity?: string;\n\n\t/**\n\t * The mnemonic for the identity, if empty and node-identity feature is enabled it will be randomly generated.\n\t */\n\tnodeMnemonic?: string;\n\n\t/**\n\t * If the node-admin-user feature is enabled, this will be the organization of the user, if one is not provided it will be generated\n\t */\n\torganizationIdentity?: string;\n\n\t/**\n\t * The mnemonic for the organization, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t */\n\torganizationMnemonic?: string;\n\n\t/**\n\t * If the node-admin-user feature is enabled, this will be the identity of the user, if one is not provided it will be generated\n\t */\n\tadminUserIdentity?: string;\n\n\t/**\n\t * The mnemonic for the admin user, if empty and node-admin-user feature is enabled it will be randomly generated.\n\t */\n\tadminUserMnemonic?: string;\n\n\t/**\n\t * If the node-admin-user feature is enabled, this will be the name of the user.\n\t * @default admin@node\n\t */\n\tadminUserName?: string;\n\n\t/**\n\t * If the node-admin-user feature is enabled, this will be the password of the user, if empty it will be randomly generated.\n\t */\n\tadminUserPassword?: string;\n\n\t/**\n\t * Maximum size in MB for HTTPS extensions downloads.\n\t * @default 10\n\t */\n\textensionsMaxSizeMb?: number;\n\n\t/**\n\t * Whether to clear the extensions cache on startup.\n\t * @default false\n\t */\n\textensionsClearCache?: boolean;\n\n\t/**\n\t * Custom directory for extensions cache storage.\n\t * @default \".tmp\"\n\t */\n\textensionsCacheDirectory?: string;\n\n\t/**\n\t * TTL in hours for HTTPS extensions cache.\n\t * @default 24\n\t */\n\textensionsCacheTtlHours?: number;\n\n\t/**\n\t * Force refresh of all cached extensions.\n\t * @default false\n\t */\n\textensionsForceRefresh?: boolean;\n}\n"]}
1
+ {"version":3,"file":"INodeEnvironmentVariables.js","sourceRoot":"","sources":["../../../src/models/INodeEnvironmentVariables.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineServerEnvironmentVariables } from \"./IEngineServerEnvironmentVariables.js\";\n\n/**\n * The environment variables for the node.\n */\nexport interface INodeEnvironmentVariables extends IEngineServerEnvironmentVariables {\n\t/**\n\t * Maximum size in MB for HTTPS extensions downloads.\n\t * @default 10\n\t */\n\textensionsMaxSizeMb?: number;\n\n\t/**\n\t * Whether to clear the extensions cache on startup.\n\t * @default false\n\t */\n\textensionsClearCache?: boolean;\n\n\t/**\n\t * Custom directory for extensions cache storage.\n\t * @default \".tmp\"\n\t */\n\textensionsCacheDirectory?: string;\n\n\t/**\n\t * TTL in hours for HTTPS extensions cache.\n\t * @default 24\n\t */\n\textensionsCacheTtlHours?: number;\n\n\t/**\n\t * Force refresh of all cached extensions.\n\t * @default false\n\t */\n\textensionsForceRefresh?: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"INodeOptions.js","sourceRoot":"","sources":["../../../src/models/INodeOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineCore, IEngineServer, IEngineStateStorage } from \"@twin.org/engine-models\";\nimport type { IEngineConfig } from \"@twin.org/engine-types\";\nimport type { INodeEngineConfig } from \"./INodeEngineConfig.js\";\nimport type { INodeEnvironmentVariables } from \"./INodeEnvironmentVariables.js\";\n\n/**\n * The options when running the node.\n */\nexport interface INodeOptions {\n\t/**\n\t * The name of the server, defaults to \"TWIN Node Server\".\n\t * @default \"TWIN Node Server\"\n\t */\n\tserverName?: string;\n\n\t/**\n\t * The version of the server, defaults to the current version.\n\t */\n\tserverVersion?: string;\n\n\t/**\n\t * Additional environment variables to set.\n\t */\n\tenvVars?: { [key: string]: string };\n\n\t/**\n\t * Additional environment variable filenames to load, defaults to .env.\n\t */\n\tenvFilenames?: string[];\n\n\t/**\n\t * The prefix for environment variables, defaults to \"TWIN_\".\n\t */\n\tenvPrefix?: string;\n\n\t/**\n\t * A list of JSON files to load as configuration files.\n\t * The files will be loaded in the order they are provided, and the last one will\n\t * override any previous values.\n\t */\n\tconfigFilenames?: string[];\n\n\t/**\n\t * Provides the ability to have some initial custom configuration for the engine.\n\t * This will be merged with any configuration loaded from the environment variables.\n\t */\n\tconfig?: IEngineConfig;\n\n\t/**\n\t * The directory to override the execution location, defaults to process directory.\n\t */\n\texecutionDirectory?: string;\n\n\t/**\n\t * The directory to override the locales directory, defaults to the locales directory.\n\t */\n\tlocalesDirectory?: string;\n\n\t/**\n\t * The path to the OpenAPI spec file, defaults to docs/open-api/spec.json.\n\t */\n\topenApiSpecFile?: string;\n\n\t/**\n\t * The path to the favicon, defaults to static/favicon.png.\n\t */\n\tfavIconFile?: string;\n\n\t/**\n\t * Method to extend the engine environment variables with any additional custom configuration.\n\t */\n\textendEnvVars?: (envVars: INodeEnvironmentVariables) => Promise<void>;\n\n\t/**\n\t * Method to extend the engine configuration with any additional custom configuration.\n\t */\n\textendConfig?: (envVars: INodeEnvironmentVariables, config: INodeEngineConfig) => Promise<void>;\n\n\t/**\n\t * Method to extend the engine with any additional options.\n\t */\n\textendEngine?: (engine: IEngineCore) => Promise<void>;\n\n\t/**\n\t * Method to extend the engine server with any additional options.\n\t */\n\textendEngineServer?: (engineServer: IEngineServer) => Promise<void>;\n\n\t/**\n\t * The state storage to use for the engine.\n\t * If not provided, a default file-based state storage will be used.\n\t */\n\tstateStorage?: IEngineStateStorage;\n\n\t/**\n\t * Disables process.exit calls on fatal errors and throws instead.\n\t */\n\tdisableProcessExitOnFailure?: boolean;\n}\n"]}
1
+ {"version":3,"file":"INodeOptions.js","sourceRoot":"","sources":["../../../src/models/INodeOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineCore, IEngineServer, IEngineStateStorage } from \"@twin.org/engine-models\";\nimport type { IEngineConfig } from \"@twin.org/engine-types\";\nimport type { INodeEngineConfig } from \"./INodeEngineConfig.js\";\nimport type { INodeEnvironmentVariables } from \"./INodeEnvironmentVariables.js\";\n\n/**\n * The options when running the node.\n */\nexport interface INodeOptions {\n\t/**\n\t * The name of the server, defaults to \"TWIN Node\".\n\t * @default \"TWIN Node\"\n\t */\n\tserverName?: string;\n\n\t/**\n\t * The version of the server, defaults to the current version.\n\t */\n\tserverVersion?: string;\n\n\t/**\n\t * Additional environment variables to set.\n\t */\n\tenvVars?: { [key: string]: string };\n\n\t/**\n\t * Additional environment variable filenames to load, defaults to .env.\n\t */\n\tenvFilenames?: string[];\n\n\t/**\n\t * The prefix for environment variables, defaults to \"TWIN_\".\n\t */\n\tenvPrefix?: string;\n\n\t/**\n\t * A list of JSON files to load as configuration files.\n\t * The files will be loaded in the order they are provided, and the last one will\n\t * override any previous values.\n\t */\n\tconfigFilenames?: string[];\n\n\t/**\n\t * Provides the ability to have some initial custom configuration for the engine.\n\t * This will be merged with any configuration loaded from the environment variables.\n\t */\n\tconfig?: IEngineConfig;\n\n\t/**\n\t * The directory to override the script location, defaults to location of index.js.\n\t */\n\tscriptDirectory?: string;\n\n\t/**\n\t * The directory to override the execution location, defaults to process directory.\n\t */\n\texecutionDirectory?: string;\n\n\t/**\n\t * The directory to override the locales directory, defaults to the locales directory.\n\t */\n\tlocalesDirectory?: string;\n\n\t/**\n\t * The path to the OpenAPI spec file, defaults to docs/open-api/spec.json.\n\t */\n\topenApiSpecFile?: string;\n\n\t/**\n\t * The path to the favicon, defaults to static/favicon.png.\n\t */\n\tfavIconFile?: string;\n\n\t/**\n\t * Method to extend the engine environment variables with any additional custom configuration.\n\t */\n\textendEnvVars?: (envVars: INodeEnvironmentVariables) => Promise<void>;\n\n\t/**\n\t * Method to extend the engine configuration with any additional custom configuration.\n\t */\n\textendConfig?: (envVars: INodeEnvironmentVariables, config: INodeEngineConfig) => Promise<void>;\n\n\t/**\n\t * Method to extend the engine with any additional options.\n\t */\n\textendEngine?: (engine: IEngineCore) => Promise<void>;\n\n\t/**\n\t * Method to extend the engine server with any additional options.\n\t */\n\textendEngineServer?: (engineServer: IEngineServer) => Promise<void>;\n\n\t/**\n\t * The state storage to use for the engine.\n\t * If not provided, a default file-based state storage will be used.\n\t */\n\tstateStorage?: IEngineStateStorage;\n\n\t/**\n\t * Disables process.exit calls on fatal errors and throws instead.\n\t */\n\tdisableProcessExitOnFailure?: boolean;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=cliCommandParamType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cliCommandParamType.js","sourceRoot":"","sources":["../../../src/models/cliCommandParamType.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Type for the properties in commands.\n */\nexport type CliCommandParamType = string | number | boolean;\n"]}
package/dist/es/node.js CHANGED
@@ -3,63 +3,54 @@
3
3
  import { execSync } from "node:child_process";
4
4
  import path from "node:path";
5
5
  import { CLIDisplay } from "@twin.org/cli-core";
6
- import { Coerce, EnvHelper, GeneralError, Is } from "@twin.org/core";
6
+ import { BaseError, Coerce, EnvHelper, GeneralError, Is, ObjectHelper } from "@twin.org/core";
7
7
  import { ModuleHelper } from "@twin.org/modules";
8
8
  import * as dotenv from "dotenv";
9
9
  import { buildEngineConfiguration } from "./builders/engineEnvBuilder.js";
10
10
  import { buildEngineServerConfiguration } from "./builders/engineServerEnvBuilder.js";
11
11
  import { extensionsConfiguration } from "./builders/extensionsBuilder.js";
12
+ import { constructCliCommand, parseCommandLineArgs, registerCommands } from "./cli.js";
13
+ import { getEnvDefaults } from "./defaults.js";
12
14
  import { ModuleProtocol } from "./models/moduleProtocol.js";
13
- import { start } from "./server.js";
14
- import { createModuleImportUrl, fileExists, getExecutionDirectory, getExtensionsCacheDir, handleHttpsProtocol, handleNpmProtocol, initialiseLocales, loadJsonFile, loadTextFile, parseModuleProtocol, resolvePackageEntryPoint } from "./utils.js";
15
+ import { start } from "./start.js";
16
+ import { createModuleImportUrl, fileExists, getExecutionDirectory, getExtensionsCacheDir, getScriptDirectory, handleHttpsProtocol, handleNpmProtocol, initialiseLocales, loadJsonFile, loadTextFile, parseModuleProtocol, resolvePackageEntryPoint } from "./utils.js";
15
17
  const moduleCache = {};
16
18
  /**
17
- * Run the TWIN Node server.
19
+ * Run the TWIN Node.
18
20
  * @param nodeOptions Optional configuration options for running the server.
21
+ * @param args Optional command line arguments.
19
22
  * @returns A promise that resolves when the server is started containing a shutdown method.
20
23
  */
21
- export async function run(nodeOptions) {
24
+ export async function run(nodeOptions, args) {
25
+ let showErrorDetails = true;
22
26
  try {
23
27
  nodeOptions ??= {};
24
28
  const serverInfo = {
25
- name: nodeOptions?.serverName ?? "TWIN Node Server",
26
- version: nodeOptions?.serverVersion ?? "0.0.3-next.0" // x-release-please-version
29
+ name: nodeOptions?.serverName ?? "TWIN Node",
30
+ version: nodeOptions?.serverVersion ?? "0.0.3-next.21" // x-release-please-version
27
31
  };
28
32
  CLIDisplay.header(serverInfo.name, serverInfo.version, "🌩️ ");
29
33
  if (!Is.stringValue(nodeOptions?.executionDirectory)) {
30
34
  nodeOptions.executionDirectory = getExecutionDirectory();
31
35
  }
32
36
  CLIDisplay.value("Execution Directory", nodeOptions.executionDirectory);
37
+ if (!Is.stringValue(nodeOptions?.scriptDirectory)) {
38
+ nodeOptions.scriptDirectory = getScriptDirectory(args);
39
+ }
40
+ CLIDisplay.value("Script Directory", nodeOptions.scriptDirectory);
33
41
  nodeOptions.localesDirectory =
34
42
  nodeOptions?.localesDirectory ??
35
- path.resolve(path.join(nodeOptions.executionDirectory, "dist", "locales"));
43
+ path.resolve(path.join(nodeOptions.scriptDirectory, "dist", "locales"));
36
44
  CLIDisplay.value("Locales Directory", nodeOptions.localesDirectory);
37
45
  await initialiseLocales(nodeOptions.localesDirectory);
38
- if (Is.empty(nodeOptions?.openApiSpecFile)) {
39
- const specFile = path.resolve(path.join(nodeOptions.executionDirectory ?? "", "docs", "open-api", "spec.json"));
40
- CLIDisplay.value("Default OpenAPI Spec File", specFile);
41
- if (await fileExists(specFile)) {
42
- nodeOptions ??= {};
43
- nodeOptions.openApiSpecFile = specFile;
44
- }
45
- }
46
- else {
47
- CLIDisplay.value("OpenAPI Spec File", nodeOptions.openApiSpecFile);
48
- }
49
- if (Is.empty(nodeOptions?.favIconFile)) {
50
- const favIconFile = path.resolve(path.join(nodeOptions.executionDirectory ?? "", "static", "favicon.png"));
51
- CLIDisplay.value("Default Favicon File", favIconFile);
52
- if (await fileExists(favIconFile)) {
53
- nodeOptions ??= {};
54
- nodeOptions.favIconFile = favIconFile;
55
- }
56
- }
57
- else {
58
- CLIDisplay.value("Favicon File", nodeOptions.favIconFile);
59
- }
60
46
  nodeOptions.envPrefix ??= "TWIN_";
61
- CLIDisplay.value("Environment Variable Prefix", nodeOptions.envPrefix);
62
47
  overrideModuleImport(nodeOptions.executionDirectory ?? "");
48
+ const commandLineArgs = parseCommandLineArgs(args);
49
+ const hasEnvPrefix = commandLineArgs.options?.find(option => option.key === "env-prefix");
50
+ if (hasEnvPrefix) {
51
+ nodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;
52
+ }
53
+ CLIDisplay.value("Environment Variable Prefix", nodeOptions.envPrefix);
63
54
  // This is the only location in the code base that should access process.env directly
64
55
  // So we can safely disable the linting rule here.
65
56
  let finalEnvVars =
@@ -71,14 +62,54 @@ export async function run(nodeOptions) {
71
62
  ...nodeOptions.envVars
72
63
  };
73
64
  }
74
- const { nodeEngineConfig, nodeEnvVars: envVars, contextIdKeys } = await buildConfiguration(finalEnvVars, nodeOptions, serverInfo);
65
+ finalEnvVars = {
66
+ ...getEnvDefaults(nodeOptions.envPrefix),
67
+ ...finalEnvVars
68
+ };
69
+ let cliCommand;
70
+ if (Is.arrayValue(commandLineArgs.options)) {
71
+ registerCommands();
72
+ cliCommand = constructCliCommand(finalEnvVars, commandLineArgs);
73
+ }
74
+ if (Is.object(cliCommand)) {
75
+ finalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= "true";
76
+ }
77
+ else {
78
+ if (Is.empty(nodeOptions?.openApiSpecFile)) {
79
+ const specFile = path.resolve(path.join(nodeOptions.scriptDirectory ?? "", "docs", "open-api", "spec.json"));
80
+ if (await fileExists(specFile)) {
81
+ nodeOptions ??= {};
82
+ nodeOptions.openApiSpecFile = specFile;
83
+ }
84
+ }
85
+ if (Is.stringValue(nodeOptions.openApiSpecFile)) {
86
+ CLIDisplay.value("OpenAPI Spec File", nodeOptions.openApiSpecFile);
87
+ }
88
+ if (Is.empty(nodeOptions?.favIconFile)) {
89
+ const favIconFile = path.resolve(path.join(nodeOptions.scriptDirectory ?? "", "static", "favicon.png"));
90
+ if (await fileExists(favIconFile)) {
91
+ nodeOptions ??= {};
92
+ nodeOptions.favIconFile = favIconFile;
93
+ }
94
+ }
95
+ if (Is.stringValue(nodeOptions.favIconFile)) {
96
+ CLIDisplay.value("Favicon File", nodeOptions.favIconFile);
97
+ }
98
+ }
99
+ const { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(finalEnvVars, nodeOptions, serverInfo);
75
100
  CLIDisplay.break();
76
- const startResult = await start(nodeOptions, nodeEngineConfig, envVars, contextIdKeys);
101
+ const startResult = await start(nodeOptions, nodeEngineConfig, nodeEnvVars, cliCommand, availableContextIdKeys);
77
102
  if (!Is.empty(startResult)) {
103
+ showErrorDetails = false;
104
+ let isShuttingDown = false;
78
105
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
79
106
  process.on(signal, async () => {
80
- CLIDisplay.value("Terminate Signal", signal);
81
- await startResult.shutdown();
107
+ if (!isShuttingDown) {
108
+ isShuttingDown = true;
109
+ CLIDisplay.value("Terminate Signal", signal);
110
+ await startResult.shutdown();
111
+ process.exit(0);
112
+ }
82
113
  });
83
114
  }
84
115
  }
@@ -88,13 +119,19 @@ export async function run(nodeOptions) {
88
119
  if (nodeOptions?.disableProcessExitOnFailure ?? false) {
89
120
  throw err;
90
121
  }
91
- CLIDisplay.error(err);
122
+ if (showErrorDetails) {
123
+ const baseError = BaseError.fromError(err);
124
+ if (baseError.source === "node") {
125
+ ObjectHelper.propertyDelete(err, "stack");
126
+ }
127
+ CLIDisplay.error(err);
128
+ }
92
129
  // eslint-disable-next-line unicorn/no-process-exit
93
130
  process.exit(1);
94
131
  }
95
132
  }
96
133
  /**
97
- * Build the configuration for the TWIN Node server.
134
+ * Build the configuration for the TWIN Node.
98
135
  * @param processEnv The environment variables from the process.
99
136
  * @param options The options for running the server.
100
137
  * @param serverInfo The server information.
@@ -102,7 +139,7 @@ export async function run(nodeOptions) {
102
139
  * and options.
103
140
  */
104
141
  export async function buildConfiguration(processEnv, options, serverInfo) {
105
- const contextIdKeys = [];
142
+ const availableContextIdKeys = [];
106
143
  let defaultEnvOnly = false;
107
144
  if (Is.empty(options?.envFilenames)) {
108
145
  const envFile = path.resolve(path.join(options.executionDirectory ?? "", ".env"));
@@ -149,8 +186,8 @@ export async function buildConfiguration(processEnv, options, serverInfo) {
149
186
  await options.extendEnvVars(envVars);
150
187
  }
151
188
  // Build the engine configuration from the environment variables.
152
- const coreConfig = await buildEngineConfiguration(envVars, contextIdKeys);
153
- const engineServerConfig = await buildEngineServerConfiguration(envVars, contextIdKeys, coreConfig, serverInfo, options?.openApiSpecFile, options?.favIconFile);
189
+ const coreConfig = await buildEngineConfiguration(envVars, availableContextIdKeys);
190
+ const engineServerConfig = await buildEngineServerConfiguration(envVars, availableContextIdKeys, coreConfig, serverInfo, options?.openApiSpecFile, options?.favIconFile);
154
191
  // Merge any custom configuration provided in the options.
155
192
  if (Is.arrayValue(options?.configFilenames)) {
156
193
  for (const configFile of options.configFilenames) {
@@ -170,7 +207,7 @@ export async function buildConfiguration(processEnv, options, serverInfo) {
170
207
  await options.extendConfig(envVars, engineServerConfig);
171
208
  }
172
209
  const nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);
173
- return { nodeEngineConfig, nodeEnvVars: envVars, contextIdKeys };
210
+ return { nodeEngineConfig, nodeEnvVars: envVars, availableContextIdKeys };
174
211
  }
175
212
  /**
176
213
  * Override module imports to support protocol-based loading (npm:, https:) and local files.
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAIrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC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Y,GAAG,IAAI,CAAC,OAAO,CAChC,qBAAqB,CAAC,kBAAkB,EAAE,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,EAC7E,cAAc,CACd,CAAC;oBAEF,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;oBAC3D,MAAM,QAAQ,GAAG,MAAM,wBAAwB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;oBACzE,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;oBACvD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;oBAC5C,IAAI,MAAM,EAAE,CAAC;wBACZ,YAAY,GAAG,UAAU,CAAC;oBAC3B,CAAC;gBACF,CAAC;gBAAC,MAAM,CAAC;oBACR,4CAA4C;gBAC7C,CAAC;gBACD,MAAM;YACP,CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACjC,OAAO;gBACN,MAAM;gBACN,UAAU,EAAE,KAAK;aACjB,CAAC;QACH,CAAC;QAED,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { IServerInfo } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { Coerce, EnvHelper, GeneralError, Is } from \"@twin.org/core\";\nimport type { Engine } from \"@twin.org/engine\";\nimport type { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport * as dotenv from \"dotenv\";\nimport { buildEngineConfiguration } from \"./builders/engineEnvBuilder.js\";\nimport { buildEngineServerConfiguration } from \"./builders/engineServerEnvBuilder.js\";\nimport { extensionsConfiguration } from \"./builders/extensionsBuilder.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\nimport { ModuleProtocol } from \"./models/moduleProtocol.js\";\nimport { start } from \"./server.js\";\nimport {\n\tcreateModuleImportUrl,\n\tfileExists,\n\tgetExecutionDirectory,\n\tgetExtensionsCacheDir,\n\thandleHttpsProtocol,\n\thandleNpmProtocol,\n\tinitialiseLocales,\n\tloadJsonFile,\n\tloadTextFile,\n\tparseModuleProtocol,\n\tresolvePackageEntryPoint\n} from \"./utils.js\";\n\nconst moduleCache: { [id: string]: unknown } = {};\n\n/**\n * Run the TWIN Node server.\n * @param nodeOptions Optional configuration options for running the server.\n * @returns A promise that resolves when the server is started containing a shutdown method.\n */\nexport async function run(nodeOptions?: INodeOptions): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\ttry {\n\t\tnodeOptions ??= {};\n\n\t\tconst serverInfo: IServerInfo = {\n\t\t\tname: nodeOptions?.serverName ?? \"TWIN Node Server\",\n\t\t\tversion: nodeOptions?.serverVersion ?? \"0.0.3-next.0\" // x-release-please-version\n\t\t};\n\n\t\tCLIDisplay.header(serverInfo.name, serverInfo.version, \"🌩️ \");\n\n\t\tif (!Is.stringValue(nodeOptions?.executionDirectory)) {\n\t\t\tnodeOptions.executionDirectory = getExecutionDirectory();\n\t\t}\n\t\tCLIDisplay.value(\"Execution Directory\", nodeOptions.executionDirectory);\n\n\t\tnodeOptions.localesDirectory =\n\t\t\tnodeOptions?.localesDirectory ??\n\t\t\tpath.resolve(path.join(nodeOptions.executionDirectory, \"dist\", \"locales\"));\n\t\tCLIDisplay.value(\"Locales Directory\", nodeOptions.localesDirectory);\n\n\t\tawait initialiseLocales(nodeOptions.localesDirectory);\n\n\t\tif (Is.empty(nodeOptions?.openApiSpecFile)) {\n\t\t\tconst specFile = path.resolve(\n\t\t\t\tpath.join(nodeOptions.executionDirectory ?? \"\", \"docs\", \"open-api\", \"spec.json\")\n\t\t\t);\n\t\t\tCLIDisplay.value(\"Default OpenAPI Spec File\", specFile);\n\t\t\tif (await fileExists(specFile)) {\n\t\t\t\tnodeOptions ??= {};\n\t\t\t\tnodeOptions.openApiSpecFile = specFile;\n\t\t\t}\n\t\t} else {\n\t\t\tCLIDisplay.value(\"OpenAPI Spec File\", nodeOptions.openApiSpecFile);\n\t\t}\n\n\t\tif (Is.empty(nodeOptions?.favIconFile)) {\n\t\t\tconst favIconFile = path.resolve(\n\t\t\t\tpath.join(nodeOptions.executionDirectory ?? \"\", \"static\", \"favicon.png\")\n\t\t\t);\n\t\t\tCLIDisplay.value(\"Default Favicon File\", favIconFile);\n\t\t\tif (await fileExists(favIconFile)) {\n\t\t\t\tnodeOptions ??= {};\n\t\t\t\tnodeOptions.favIconFile = favIconFile;\n\t\t\t}\n\t\t} else {\n\t\t\tCLIDisplay.value(\"Favicon File\", nodeOptions.favIconFile);\n\t\t}\n\n\t\tnodeOptions.envPrefix ??= \"TWIN_\";\n\t\tCLIDisplay.value(\"Environment Variable Prefix\", nodeOptions.envPrefix);\n\n\t\toverrideModuleImport(nodeOptions.executionDirectory ?? \"\");\n\n\t\t// This is the only location in the code base that should access process.env directly\n\t\t// So we can safely disable the linting rule here.\n\t\tlet finalEnvVars =\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tprocess.env as {\n\t\t\t\t[id: string]: string;\n\t\t\t};\n\n\t\tif (Is.objectValue(nodeOptions?.envVars)) {\n\t\t\tfinalEnvVars = {\n\t\t\t\t...finalEnvVars,\n\t\t\t\t...nodeOptions.envVars\n\t\t\t};\n\t\t}\n\n\t\tconst {\n\t\t\tnodeEngineConfig,\n\t\t\tnodeEnvVars: envVars,\n\t\t\tcontextIdKeys\n\t\t} = await buildConfiguration(finalEnvVars, nodeOptions, serverInfo);\n\n\t\tCLIDisplay.break();\n\t\tconst startResult = await start(nodeOptions, nodeEngineConfig, envVars, contextIdKeys);\n\n\t\tif (!Is.empty(startResult)) {\n\t\t\tfor (const signal of [\"SIGHUP\", \"SIGINT\", \"SIGTERM\"]) {\n\t\t\t\tprocess.on(signal, async () => {\n\t\t\t\t\tCLIDisplay.value(\"Terminate Signal\", signal);\n\t\t\t\t\tawait startResult.shutdown();\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn startResult;\n\t} catch (err) {\n\t\tif (nodeOptions?.disableProcessExitOnFailure ?? false) {\n\t\t\tthrow err;\n\t\t}\n\t\tCLIDisplay.error(err);\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Build the configuration for the TWIN Node server.\n * @param processEnv The environment variables from the process.\n * @param options The options for running the server.\n * @param serverInfo The server information.\n * @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,\n * and options.\n */\nexport async function buildConfiguration(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: INodeOptions,\n\tserverInfo: IServerInfo\n): Promise<{\n\tnodeEnvVars: INodeEnvironmentVariables & { [id: string]: string | unknown };\n\tnodeEngineConfig: INodeEngineConfig;\n\tcontextIdKeys: string[];\n}> {\n\tconst contextIdKeys: string[] = [];\n\n\tlet defaultEnvOnly = false;\n\tif (Is.empty(options?.envFilenames)) {\n\t\tconst envFile = path.resolve(path.join(options.executionDirectory ?? \"\", \".env\"));\n\t\tCLIDisplay.value(\"Default Environment File\", envFile);\n\t\toptions ??= {};\n\t\toptions.envFilenames = [envFile];\n\t\tdefaultEnvOnly = true;\n\t}\n\n\tif (Is.arrayValue(options?.envFilenames)) {\n\t\tconst output = dotenv.config({\n\t\t\tpath: options?.envFilenames,\n\t\t\tquiet: true\n\t\t});\n\n\t\t// We don't want to throw an error if the default environment file is not found.\n\t\t// Only if we have custom environment files.\n\t\tif (!defaultEnvOnly && output.error) {\n\t\t\tthrow output.error;\n\t\t}\n\n\t\tif (Is.objectValue(output.parsed)) {\n\t\t\tObject.assign(processEnv, output.parsed);\n\t\t}\n\t}\n\n\tconst envVars = EnvHelper.envToJson<{ [id: string]: string | unknown }>(\n\t\tprocessEnv,\n\t\toptions.envPrefix ?? \"\"\n\t);\n\n\t// Expand any environment variables that use the @file: syntax\n\tconst keys = Object.keys(envVars);\n\tfor (const key of keys) {\n\t\tif (\n\t\t\tIs.stringValue(envVars[key]) &&\n\t\t\t(envVars[key].startsWith(\"@text:\") || envVars[key].startsWith(\"@json:\"))\n\t\t) {\n\t\t\tconst filePath = envVars[key].slice(6).trim();\n\t\t\tconst embeddedFile = path.resolve(path.join(options.executionDirectory ?? \"\", filePath));\n\n\t\t\tif (envVars[key].startsWith(\"@text:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from text file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadTextFile(embeddedFile);\n\t\t\t} else if (envVars[key].startsWith(\"@json:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from JSON file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadJsonFile(embeddedFile);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extend the environment variables with any additional custom configuration.\n\tif (Is.function(options?.extendEnvVars)) {\n\t\tCLIDisplay.task(\"Extending Environment Variables\");\n\t\tawait options.extendEnvVars(envVars);\n\t}\n\n\t// Build the engine configuration from the environment variables.\n\tconst coreConfig = await buildEngineConfiguration(envVars, contextIdKeys);\n\tconst engineServerConfig = await buildEngineServerConfiguration(\n\t\tenvVars,\n\t\tcontextIdKeys,\n\t\tcoreConfig,\n\t\tserverInfo,\n\t\toptions?.openApiSpecFile,\n\t\toptions?.favIconFile\n\t);\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.arrayValue(options?.configFilenames)) {\n\t\tfor (const configFile of options.configFilenames) {\n\t\t\tCLIDisplay.value(\"Loading Configuration File\", configFile);\n\t\t\tconst configFilePath = path.resolve(path.join(options.executionDirectory ?? \"\", configFile));\n\t\t\tconst config = await loadJsonFile(configFilePath);\n\t\t\tObject.assign(engineServerConfig, config);\n\t\t}\n\t}\n\n\tif (Is.objectValue(options?.config)) {\n\t\tCLIDisplay.task(\"Merging Custom Configuration\");\n\t\tObject.assign(engineServerConfig, options.config);\n\t}\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.function(options?.extendConfig)) {\n\t\tCLIDisplay.task(\"Extending Configuration\");\n\t\tawait options.extendConfig(envVars, engineServerConfig);\n\t}\n\n\tconst nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);\n\n\treturn { nodeEngineConfig, nodeEnvVars: envVars, contextIdKeys };\n}\n\n/**\n * Override module imports to support protocol-based loading (npm:, https:) and local files.\n * @param executionDirectory The execution directory for resolving local module paths.\n * @param envVars The environment variables containing extension configuration (optional, uses defaults if not provided).\n */\nexport function overrideModuleImport(\n\texecutionDirectory: string,\n\tenvVars?: INodeEnvironmentVariables\n): void {\n\tconst maxSizeMb = Coerce.number(envVars?.extensionsMaxSizeMb) ?? 10;\n\tconst cacheDirectory = envVars?.extensionsCacheDirectory;\n\n\tModuleHelper.overrideImport(async moduleName => {\n\t\tif (moduleCache[moduleName]) {\n\t\t\treturn {\n\t\t\t\tmodule: moduleCache[moduleName],\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\tconst parsed = parseModuleProtocol(moduleName);\n\t\tlet resolvedPath: string | undefined;\n\n\t\tswitch (parsed.protocol) {\n\t\t\tcase ModuleProtocol.Npm: {\n\t\t\t\tconst result = await handleNpmProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tcacheDirectory\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Https: {\n\t\t\t\tconst result = await handleHttpsProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tmaxSizeMb,\n\t\t\t\t\tcacheDirectory,\n\t\t\t\t\tenvVars?.extensionsCacheTtlHours,\n\t\t\t\t\tenvVars?.extensionsForceRefresh\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Http: {\n\t\t\t\tthrow new GeneralError(\"node\", \"insecureProtocol\", { protocol: ModuleProtocol.Http });\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Local: {\n\t\t\t\tlet localFilename = path.resolve(moduleName);\n\n\t\t\t\tlet exists = await fileExists(localFilename);\n\t\t\t\tif (!exists) {\n\t\t\t\t\tlocalFilename = path.resolve(executionDirectory, moduleName);\n\t\t\t\t\texists = await fileExists(localFilename);\n\t\t\t\t}\n\n\t\t\t\tif (exists) {\n\t\t\t\t\tresolvedPath = localFilename;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Default: {\n\t\t\t\ttry {\n\t\t\t\t\tconst npmRoot = execSync(\"npm root\").toString().trim().replace(/\\\\/g, \"/\");\n\t\t\t\t\tconst packagePath = path.resolve(npmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Continue to fallback resolution\n\t\t\t\t}\n\n\t\t\t\t// Fallback: resolve from npm protocol cache directory (installed via handleNpmProtocol)\n\t\t\t\ttry {\n\t\t\t\t\tconst cacheNpmRoot = path.resolve(\n\t\t\t\t\t\tgetExtensionsCacheDir(executionDirectory, ModuleProtocol.Npm, cacheDirectory),\n\t\t\t\t\t\t\"node_modules\"\n\t\t\t\t\t);\n\n\t\t\t\t\tconst packagePath = path.resolve(cacheNpmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// No cached resolution either; fall through\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Common module loading and caching logic\n\t\tif (resolvedPath) {\n\t\t\tconst module = await import(createModuleImportUrl(resolvedPath));\n\t\t\tmoduleCache[moduleName] = module;\n\t\t\treturn {\n\t\t\t\tmodule,\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tmodule: undefined,\n\t\t\tuseDefault: true\n\t\t};\n\t});\n}\n"]}
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/node.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9F,OAAO,EAAE,YAA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CAAC;QACF,CAAC;QAED,0CAA0C;QAC1C,IAAI,YAAY,EAAE,CAAC;YAClB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAC;YACjE,WAAW,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;YACjC,OAAO;gBACN,MAAM;gBACN,UAAU,EAAE,KAAK;aACjB,CAAC;QACH,CAAC;QAED,OAAO;YACN,MAAM,EAAE,SAAS;YACjB,UAAU,EAAE,IAAI;SAChB,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { execSync } from \"node:child_process\";\nimport path from \"node:path\";\nimport type { IServerInfo } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { BaseError, Coerce, EnvHelper, GeneralError, Is, ObjectHelper } from \"@twin.org/core\";\nimport type { Engine } from \"@twin.org/engine\";\nimport type { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { ModuleHelper } from \"@twin.org/modules\";\nimport * as dotenv from \"dotenv\";\nimport { buildEngineConfiguration } from \"./builders/engineEnvBuilder.js\";\nimport { buildEngineServerConfiguration } from \"./builders/engineServerEnvBuilder.js\";\nimport { extensionsConfiguration } from \"./builders/extensionsBuilder.js\";\nimport { constructCliCommand, parseCommandLineArgs, registerCommands } from \"./cli.js\";\nimport { getEnvDefaults } from \"./defaults.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\nimport { ModuleProtocol } from \"./models/moduleProtocol.js\";\nimport { start } from \"./start.js\";\nimport {\n\tcreateModuleImportUrl,\n\tfileExists,\n\tgetExecutionDirectory,\n\tgetExtensionsCacheDir,\n\tgetScriptDirectory,\n\thandleHttpsProtocol,\n\thandleNpmProtocol,\n\tinitialiseLocales,\n\tloadJsonFile,\n\tloadTextFile,\n\tparseModuleProtocol,\n\tresolvePackageEntryPoint\n} from \"./utils.js\";\n\nconst moduleCache: { [id: string]: unknown } = {};\n\n/**\n * Run the TWIN Node.\n * @param nodeOptions Optional configuration options for running the server.\n * @param args Optional command line arguments.\n * @returns A promise that resolves when the server is started containing a shutdown method.\n */\nexport async function run(\n\tnodeOptions?: INodeOptions,\n\targs?: string[]\n): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\tlet showErrorDetails = true;\n\ttry {\n\t\tnodeOptions ??= {};\n\n\t\tconst serverInfo: IServerInfo = {\n\t\t\tname: nodeOptions?.serverName ?? \"TWIN Node\",\n\t\t\tversion: nodeOptions?.serverVersion ?? \"0.0.3-next.21\" // x-release-please-version\n\t\t};\n\n\t\tCLIDisplay.header(serverInfo.name, serverInfo.version, \"🌩️ \");\n\n\t\tif (!Is.stringValue(nodeOptions?.executionDirectory)) {\n\t\t\tnodeOptions.executionDirectory = getExecutionDirectory();\n\t\t}\n\t\tCLIDisplay.value(\"Execution Directory\", nodeOptions.executionDirectory);\n\n\t\tif (!Is.stringValue(nodeOptions?.scriptDirectory)) {\n\t\t\tnodeOptions.scriptDirectory = getScriptDirectory(args);\n\t\t}\n\t\tCLIDisplay.value(\"Script Directory\", nodeOptions.scriptDirectory);\n\n\t\tnodeOptions.localesDirectory =\n\t\t\tnodeOptions?.localesDirectory ??\n\t\t\tpath.resolve(path.join(nodeOptions.scriptDirectory, \"dist\", \"locales\"));\n\n\t\tCLIDisplay.value(\"Locales Directory\", nodeOptions.localesDirectory);\n\t\tawait initialiseLocales(nodeOptions.localesDirectory);\n\n\t\tnodeOptions.envPrefix ??= \"TWIN_\";\n\n\t\toverrideModuleImport(nodeOptions.executionDirectory ?? \"\");\n\n\t\tconst commandLineArgs = parseCommandLineArgs(args);\n\n\t\tconst hasEnvPrefix = commandLineArgs.options?.find(option => option.key === \"env-prefix\");\n\t\tif (hasEnvPrefix) {\n\t\t\tnodeOptions.envPrefix = Coerce.string(hasEnvPrefix.value) ?? nodeOptions.envPrefix;\n\t\t}\n\n\t\tCLIDisplay.value(\"Environment Variable Prefix\", nodeOptions.envPrefix);\n\n\t\t// This is the only location in the code base that should access process.env directly\n\t\t// So we can safely disable the linting rule here.\n\t\tlet finalEnvVars =\n\t\t\t// eslint-disable-next-line no-restricted-syntax\n\t\t\tprocess.env as {\n\t\t\t\t[id: string]: string;\n\t\t\t};\n\n\t\tif (Is.objectValue(nodeOptions?.envVars)) {\n\t\t\tfinalEnvVars = {\n\t\t\t\t...finalEnvVars,\n\t\t\t\t...nodeOptions.envVars\n\t\t\t};\n\t\t}\n\n\t\tfinalEnvVars = {\n\t\t\t...getEnvDefaults(nodeOptions.envPrefix),\n\t\t\t...finalEnvVars\n\t\t};\n\n\t\tlet cliCommand;\n\t\tif (Is.arrayValue(commandLineArgs.options)) {\n\t\t\tregisterCommands();\n\t\t\tcliCommand = constructCliCommand(finalEnvVars, commandLineArgs);\n\t\t}\n\n\t\tif (Is.object(cliCommand)) {\n\t\t\tfinalEnvVars[`${nodeOptions.envPrefix}SILENT`] ??= \"true\";\n\t\t} else {\n\t\t\tif (Is.empty(nodeOptions?.openApiSpecFile)) {\n\t\t\t\tconst specFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"docs\", \"open-api\", \"spec.json\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(specFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.openApiSpecFile = specFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.openApiSpecFile)) {\n\t\t\t\tCLIDisplay.value(\"OpenAPI Spec File\", nodeOptions.openApiSpecFile);\n\t\t\t}\n\n\t\t\tif (Is.empty(nodeOptions?.favIconFile)) {\n\t\t\t\tconst favIconFile = path.resolve(\n\t\t\t\t\tpath.join(nodeOptions.scriptDirectory ?? \"\", \"static\", \"favicon.png\")\n\t\t\t\t);\n\t\t\t\tif (await fileExists(favIconFile)) {\n\t\t\t\t\tnodeOptions ??= {};\n\t\t\t\t\tnodeOptions.favIconFile = favIconFile;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (Is.stringValue(nodeOptions.favIconFile)) {\n\t\t\t\tCLIDisplay.value(\"Favicon File\", nodeOptions.favIconFile);\n\t\t\t}\n\t\t}\n\n\t\tconst { nodeEngineConfig, nodeEnvVars, availableContextIdKeys } = await buildConfiguration(\n\t\t\tfinalEnvVars,\n\t\t\tnodeOptions,\n\t\t\tserverInfo\n\t\t);\n\n\t\tCLIDisplay.break();\n\n\t\tconst startResult = await start(\n\t\t\tnodeOptions,\n\t\t\tnodeEngineConfig,\n\t\t\tnodeEnvVars,\n\t\t\tcliCommand,\n\t\t\tavailableContextIdKeys\n\t\t);\n\n\t\tif (!Is.empty(startResult)) {\n\t\t\tshowErrorDetails = false;\n\n\t\t\tlet isShuttingDown = false;\n\t\t\tfor (const signal of [\"SIGHUP\", \"SIGINT\", \"SIGTERM\"]) {\n\t\t\t\tprocess.on(signal, async () => {\n\t\t\t\t\tif (!isShuttingDown) {\n\t\t\t\t\t\tisShuttingDown = true;\n\t\t\t\t\t\tCLIDisplay.value(\"Terminate Signal\", signal);\n\t\t\t\t\t\tawait startResult.shutdown();\n\t\t\t\t\t\tprocess.exit(0);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn startResult;\n\t} catch (err) {\n\t\tif (nodeOptions?.disableProcessExitOnFailure ?? false) {\n\t\t\tthrow err;\n\t\t}\n\n\t\tif (showErrorDetails) {\n\t\t\tconst baseError = BaseError.fromError(err);\n\t\t\tif (baseError.source === \"node\") {\n\t\t\t\tObjectHelper.propertyDelete(err, \"stack\");\n\t\t\t}\n\t\t\tCLIDisplay.error(err);\n\t\t}\n\n\t\t// eslint-disable-next-line unicorn/no-process-exit\n\t\tprocess.exit(1);\n\t}\n}\n\n/**\n * Build the configuration for the TWIN Node.\n * @param processEnv The environment variables from the process.\n * @param options The options for running the server.\n * @param serverInfo The server information.\n * @returns A promise that resolves to the engine server configuration, environment prefix, environment variables,\n * and options.\n */\nexport async function buildConfiguration(\n\tprocessEnv: {\n\t\t[id: string]: string;\n\t},\n\toptions: INodeOptions,\n\tserverInfo: IServerInfo\n): Promise<{\n\tnodeEnvVars: INodeEnvironmentVariables & { [id: string]: string | unknown };\n\tnodeEngineConfig: INodeEngineConfig;\n\tavailableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[];\n}> {\n\tconst availableContextIdKeys: { key: string; requiredHandlerFeatures: string[] }[] = [];\n\n\tlet defaultEnvOnly = false;\n\tif (Is.empty(options?.envFilenames)) {\n\t\tconst envFile = path.resolve(path.join(options.executionDirectory ?? \"\", \".env\"));\n\t\tCLIDisplay.value(\"Default Environment File\", envFile);\n\t\toptions ??= {};\n\t\toptions.envFilenames = [envFile];\n\t\tdefaultEnvOnly = true;\n\t}\n\n\tif (Is.arrayValue(options?.envFilenames)) {\n\t\tconst output = dotenv.config({\n\t\t\tpath: options?.envFilenames,\n\t\t\tquiet: true\n\t\t});\n\n\t\t// We don't want to throw an error if the default environment file is not found.\n\t\t// Only if we have custom environment files.\n\t\tif (!defaultEnvOnly && output.error) {\n\t\t\tthrow output.error;\n\t\t}\n\n\t\tif (Is.objectValue(output.parsed)) {\n\t\t\tObject.assign(processEnv, output.parsed);\n\t\t}\n\t}\n\n\tconst envVars = EnvHelper.envToJson<{ [id: string]: string | unknown }>(\n\t\tprocessEnv,\n\t\toptions.envPrefix ?? \"\"\n\t);\n\n\t// Expand any environment variables that use the @file: syntax\n\tconst keys = Object.keys(envVars);\n\tfor (const key of keys) {\n\t\tif (\n\t\t\tIs.stringValue(envVars[key]) &&\n\t\t\t(envVars[key].startsWith(\"@text:\") || envVars[key].startsWith(\"@json:\"))\n\t\t) {\n\t\t\tconst filePath = envVars[key].slice(6).trim();\n\t\t\tconst embeddedFile = path.resolve(path.join(options.executionDirectory ?? \"\", filePath));\n\n\t\t\tif (envVars[key].startsWith(\"@text:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from text file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadTextFile(embeddedFile);\n\t\t\t} else if (envVars[key].startsWith(\"@json:\")) {\n\t\t\t\tCLIDisplay.value(`Expanding Environment Variable: ${key} from JSON file`, embeddedFile);\n\t\t\t\tenvVars[key] = await loadJsonFile(embeddedFile);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Extend the environment variables with any additional custom configuration.\n\tif (Is.function(options?.extendEnvVars)) {\n\t\tCLIDisplay.task(\"Extending Environment Variables\");\n\t\tawait options.extendEnvVars(envVars);\n\t}\n\n\t// Build the engine configuration from the environment variables.\n\tconst coreConfig = await buildEngineConfiguration(envVars, availableContextIdKeys);\n\tconst engineServerConfig = await buildEngineServerConfiguration(\n\t\tenvVars,\n\t\tavailableContextIdKeys,\n\t\tcoreConfig,\n\t\tserverInfo,\n\t\toptions?.openApiSpecFile,\n\t\toptions?.favIconFile\n\t);\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.arrayValue(options?.configFilenames)) {\n\t\tfor (const configFile of options.configFilenames) {\n\t\t\tCLIDisplay.value(\"Loading Configuration File\", configFile);\n\t\t\tconst configFilePath = path.resolve(path.join(options.executionDirectory ?? \"\", configFile));\n\t\t\tconst config = await loadJsonFile(configFilePath);\n\t\t\tObject.assign(engineServerConfig, config);\n\t\t}\n\t}\n\n\tif (Is.objectValue(options?.config)) {\n\t\tCLIDisplay.task(\"Merging Custom Configuration\");\n\t\tObject.assign(engineServerConfig, options.config);\n\t}\n\n\t// Merge any custom configuration provided in the options.\n\tif (Is.function(options?.extendConfig)) {\n\t\tCLIDisplay.task(\"Extending Configuration\");\n\t\tawait options.extendConfig(envVars, engineServerConfig);\n\t}\n\n\tconst nodeEngineConfig = await extensionsConfiguration(envVars, engineServerConfig);\n\n\treturn { nodeEngineConfig, nodeEnvVars: envVars, availableContextIdKeys };\n}\n\n/**\n * Override module imports to support protocol-based loading (npm:, https:) and local files.\n * @param executionDirectory The execution directory for resolving local module paths.\n * @param envVars The environment variables containing extension configuration (optional, uses defaults if not provided).\n */\nexport function overrideModuleImport(\n\texecutionDirectory: string,\n\tenvVars?: INodeEnvironmentVariables\n): void {\n\tconst maxSizeMb = Coerce.number(envVars?.extensionsMaxSizeMb) ?? 10;\n\tconst cacheDirectory = envVars?.extensionsCacheDirectory;\n\n\tModuleHelper.overrideImport(async moduleName => {\n\t\tif (moduleCache[moduleName]) {\n\t\t\treturn {\n\t\t\t\tmodule: moduleCache[moduleName],\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\tconst parsed = parseModuleProtocol(moduleName);\n\t\tlet resolvedPath: string | undefined;\n\n\t\tswitch (parsed.protocol) {\n\t\t\tcase ModuleProtocol.Npm: {\n\t\t\t\tconst result = await handleNpmProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tcacheDirectory\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Https: {\n\t\t\t\tconst result = await handleHttpsProtocol(\n\t\t\t\t\tparsed.identifier,\n\t\t\t\t\texecutionDirectory,\n\t\t\t\t\tmaxSizeMb,\n\t\t\t\t\tcacheDirectory,\n\t\t\t\t\tenvVars?.extensionsCacheTtlHours,\n\t\t\t\t\tenvVars?.extensionsForceRefresh\n\t\t\t\t);\n\t\t\t\tresolvedPath = result.resolvedPath;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Http: {\n\t\t\t\tthrow new GeneralError(\"node\", \"insecureProtocol\", { protocol: ModuleProtocol.Http });\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Local: {\n\t\t\t\tlet localFilename = path.resolve(moduleName);\n\n\t\t\t\tlet exists = await fileExists(localFilename);\n\t\t\t\tif (!exists) {\n\t\t\t\t\tlocalFilename = path.resolve(executionDirectory, moduleName);\n\t\t\t\t\texists = await fileExists(localFilename);\n\t\t\t\t}\n\n\t\t\t\tif (exists) {\n\t\t\t\t\tresolvedPath = localFilename;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase ModuleProtocol.Default: {\n\t\t\t\ttry {\n\t\t\t\t\tconst npmRoot = execSync(\"npm root\").toString().trim().replace(/\\\\/g, \"/\");\n\t\t\t\t\tconst packagePath = path.resolve(npmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Continue to fallback resolution\n\t\t\t\t}\n\n\t\t\t\t// Fallback: resolve from npm protocol cache directory (installed via handleNpmProtocol)\n\t\t\t\ttry {\n\t\t\t\t\tconst cacheNpmRoot = path.resolve(\n\t\t\t\t\t\tgetExtensionsCacheDir(executionDirectory, ModuleProtocol.Npm, cacheDirectory),\n\t\t\t\t\t\t\"node_modules\"\n\t\t\t\t\t);\n\n\t\t\t\t\tconst packagePath = path.resolve(cacheNpmRoot, moduleName);\n\t\t\t\t\tconst mainFile = await resolvePackageEntryPoint(packagePath, moduleName);\n\t\t\t\t\tconst modulePath = path.resolve(packagePath, mainFile);\n\t\t\t\t\tconst exists = await fileExists(modulePath);\n\t\t\t\t\tif (exists) {\n\t\t\t\t\t\tresolvedPath = modulePath;\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// No cached resolution either; fall through\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t// Common module loading and caching logic\n\t\tif (resolvedPath) {\n\t\t\tconst module = await import(createModuleImportUrl(resolvedPath));\n\t\t\tmoduleCache[moduleName] = module;\n\t\t\treturn {\n\t\t\t\tmodule,\n\t\t\t\tuseDefault: false\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tmodule: undefined,\n\t\t\tuseDefault: true\n\t\t};\n\t});\n}\n"]}
@@ -0,0 +1,139 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { ContextIdKeys } from "@twin.org/context";
4
+ import { Coerce, GeneralError, I18n, Is } from "@twin.org/core";
5
+ import { Engine } from "@twin.org/engine";
6
+ import { FileStateStorage } from "@twin.org/engine-core";
7
+ import { EngineCoreFactory } from "@twin.org/engine-models";
8
+ import { EngineServer } from "@twin.org/engine-server";
9
+ import { BlobStorageConnectorType, EntityStorageConnectorType } from "@twin.org/engine-types";
10
+ import { extensionsInitialiseEngine, extensionsInitialiseEngineServer, shutdownExtensions } from "./builders/extensionsBuilder.js";
11
+ import { executeCommand } from "./cli.js";
12
+ /**
13
+ * Start the engine server.
14
+ * @param nodeOptions Optional run options for the engine server.
15
+ * @param nodeEngineConfig The configuration for the engine server.
16
+ * @param envVars The environment variables.
17
+ * @param cliCommand The constructed CLI command (optional).
18
+ * @param availableContextIdKeys The context ID keys available for operation.
19
+ * @returns The engine server.
20
+ */
21
+ export async function start(nodeOptions, nodeEngineConfig, envVars, cliCommand, availableContextIdKeys) {
22
+ const entityStorageConnectorType = envVars.entityStorageConnectorType?.split(",") ?? [];
23
+ const blobStorageConnectorType = envVars.blobStorageConnectorType?.split(",") ?? [];
24
+ const requiresEngineStarted = cliCommand?.definition?.requiresEngineStarted ?? true;
25
+ const requiresNodeIdentity = cliCommand?.definition?.requiresNodeIdentity ?? true;
26
+ const requiresTenantId = cliCommand?.definition?.requiresTenantId ?? true;
27
+ // If the blob storage or entity storage is configured with file connectors
28
+ // then we need to make sure the storageFileRoot is set
29
+ if ((entityStorageConnectorType.includes(EntityStorageConnectorType.File) ||
30
+ blobStorageConnectorType.includes(BlobStorageConnectorType.File) ||
31
+ Is.empty(nodeOptions?.stateStorage)) &&
32
+ !Is.stringValue(envVars.storageFileRoot) &&
33
+ requiresEngineStarted) {
34
+ throw new GeneralError("node", "storageFileRootNotSet", {
35
+ storageFileRoot: `${nodeOptions?.envPrefix ?? ""}STORAGE_FILE_ROOT`
36
+ });
37
+ }
38
+ // Create the engine instance using file state storage unless one is configured in options
39
+ const engine = new Engine({
40
+ config: nodeEngineConfig,
41
+ stateStorage: requiresEngineStarted
42
+ ? (nodeOptions?.stateStorage ?? new FileStateStorage(envVars.stateFilename ?? ""))
43
+ : undefined,
44
+ customBootstrap: async (engineCore, context) => {
45
+ configureContextIds(engineCore, envVars, requiresEngineStarted, requiresNodeIdentity, requiresTenantId);
46
+ }
47
+ });
48
+ configureContextIdKeys(engine, availableContextIdKeys);
49
+ // Construct the server with the engine.
50
+ const server = new EngineServer({ engineCore: engine });
51
+ // Extend the engine.
52
+ if (Is.function(nodeOptions?.extendEngine)) {
53
+ await engine.logInfo(I18n.formatMessage("node.extendingEngine"));
54
+ await nodeOptions.extendEngine(engine);
55
+ }
56
+ await extensionsInitialiseEngine(envVars, engine);
57
+ // Extend the engine server.
58
+ if (Is.function(nodeOptions?.extendEngineServer)) {
59
+ await engine.logInfo(I18n.formatMessage("node.extendingEngineServer"));
60
+ await nodeOptions?.extendEngineServer(server);
61
+ }
62
+ await extensionsInitialiseEngineServer(envVars, engine, server);
63
+ // Need to register the engine with the factory so that background tasks
64
+ // can clone it to spawn new instances.
65
+ EngineCoreFactory.register("engine", () => engine);
66
+ if (Is.objectValue(cliCommand)) {
67
+ await executeCommand(engine, envVars, cliCommand);
68
+ }
69
+ else {
70
+ try {
71
+ // Start the server, which also starts the engine.
72
+ await server.start();
73
+ return {
74
+ engine,
75
+ server,
76
+ shutdown: async () => {
77
+ await shutdownExtensions(envVars, engine);
78
+ await server.stop();
79
+ }
80
+ };
81
+ }
82
+ catch (err) {
83
+ await shutdownExtensions(envVars, engine);
84
+ throw err;
85
+ }
86
+ }
87
+ }
88
+ /**
89
+ * Configure the context IDs for the engine.
90
+ * @param engine The engine to configure.
91
+ * @param envVars The environment variables.
92
+ * @param requiresEngineStarted Whether the engine is required to be started.
93
+ * @param requiresNodeIdentity Whether the node identity is required.
94
+ * @param requiresTenantId Whether the tenant id is required.
95
+ * @throws GeneralError Throws if the node identity or tenant is required but not set.
96
+ */
97
+ function configureContextIds(engine, envVars, requiresEngineStarted, requiresNodeIdentity, requiresTenantId) {
98
+ const state = engine.getState();
99
+ if (requiresEngineStarted && requiresNodeIdentity) {
100
+ const nodeIdentityEnabled = Coerce.boolean(envVars.nodeIdentityEnabled) ?? true;
101
+ if (nodeIdentityEnabled) {
102
+ if (Is.stringValue(state.nodeId)) {
103
+ engine.addContextId(ContextIdKeys.Node, state.nodeId);
104
+ }
105
+ else {
106
+ throw new GeneralError("node", "nodeIdentityNotSet");
107
+ }
108
+ }
109
+ }
110
+ if (requiresEngineStarted && requiresTenantId) {
111
+ const tenantEnabled = Coerce.boolean(envVars.tenantEnabled) ?? false;
112
+ if (tenantEnabled) {
113
+ if (Is.stringValue(state.nodeTenantId)) {
114
+ engine.addContextId(ContextIdKeys.Tenant, state.nodeTenantId);
115
+ }
116
+ else {
117
+ throw new GeneralError("node", "nodeTenantNotSet");
118
+ }
119
+ }
120
+ }
121
+ }
122
+ /**
123
+ * Configure the context IDs for the engine.
124
+ * @param engine The engine to configure.
125
+ * @param availableContextIdKeys The available context ID keys.
126
+ * @throws GeneralError Throws if the node identity or tenant is required but not set.
127
+ */
128
+ function configureContextIdKeys(engine, availableContextIdKeys) {
129
+ if (Is.arrayValue(availableContextIdKeys)) {
130
+ const added = [];
131
+ for (const availableContextIdKey of availableContextIdKeys) {
132
+ if (!added.includes(availableContextIdKey.key)) {
133
+ engine.addContextIdKey(availableContextIdKey.key, availableContextIdKey.requiredHandlerFeatures);
134
+ added.push(availableContextIdKey.key);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ //# sourceMappingURL=start.js.map