@twin.org/node-core 0.0.1-next.3 → 0.0.1-next.4

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.
package/README.md CHANGED
@@ -1,32 +1,20 @@
1
1
  # TWIN Node Core
2
2
 
3
- Core of a TWIN node for running the TWIN engine as a REST server.
3
+ TWIN Node Core for serving APIs using the specified configuration
4
4
 
5
- ## Building and running the application
6
-
7
- To install the dependencies, perform a full build and start the server.
8
-
9
- ```shell
10
- npm install
11
- npm run dist
12
- npm start
13
- ```
14
-
15
- ## Development mode
16
-
17
- Once you have performed a full build you can run the server in development mode, this will watch the TypeScript code, rebuild if there are any changes, and relaunch the server.
5
+ ## Installation
18
6
 
19
7
  ```shell
20
- npm run dev
8
+ npm install @twin.org/node-core
21
9
  ```
22
10
 
23
- ## Configuration
11
+ ## Examples
24
12
 
25
- There are various options you can set through configuration, these can be found in [docs/configuration.md](docs/configuration.md)
13
+ Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
26
14
 
27
- ## Deployment
15
+ ## Reference
28
16
 
29
- Examples of how to deploy the app can be found in [docs/deployment.md](docs/deployment.md)
17
+ Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
30
18
 
31
19
  ## Changelog
32
20
 
@@ -491,19 +491,22 @@ async function bootstrapAuth(engineCore, context, envVars, features) {
491
491
  /**
492
492
  * Start the engine server.
493
493
  * @param serverInfo The server information.
494
+ * @param envVarsPrefix The prefix for the environment variables.
494
495
  * @param envVars The environment variables.
495
496
  * @param openApiSpecFile Path to the OpenAPI spec file.
496
497
  * @param stateStorage The state storage.
497
498
  * @param customConfig Extends the engine configuration with any additional custom configuration.
498
499
  * @returns The engine server.
499
500
  */
500
- async function start(serverInfo, envVars, openApiSpecFile, stateStorage, customConfig) {
501
+ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateStorage, customConfig) {
501
502
  envVars.storageFileRoot ??= "";
502
503
  if ((envVars.entityStorageConnectorType === engineTypes.EntityStorageConnectorType.File ||
503
504
  envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.File ||
504
505
  core.Is.empty(stateStorage)) &&
505
506
  !core.Is.stringValue(envVars.storageFileRoot)) {
506
- throw new core.GeneralError("node", "storageFileRootNotSet");
507
+ throw new core.GeneralError("node", "storageFileRootNotSet", {
508
+ storageFileRoot: `${envVarsPrefix}_STORAGE_FILE_ROOT`
509
+ });
507
510
  }
508
511
  // Build the engine configuration from the environment variables.
509
512
  const engineConfig = engine.buildEngineConfiguration(envVars);
@@ -546,7 +549,7 @@ async function run(options) {
546
549
  try {
547
550
  const serverInfo = {
548
551
  name: options?.serverName ?? "TWIN Node Server",
549
- version: options?.serverVersion ?? "0.0.1-next.3" // x-release-please-version
552
+ version: options?.serverVersion ?? "0.0.1-next.4" // x-release-please-version
550
553
  };
551
554
  console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
552
555
  const executionDirectory = options?.executionDirectory ?? getExecutionDirectory();
@@ -572,8 +575,11 @@ async function run(options) {
572
575
  const envPrefix = options?.envPrefix ?? "TWIN_NODE_";
573
576
  console.info("Environment Prefix:", envPrefix);
574
577
  const envVars = core.EnvHelper.envToJson(process.env, envPrefix);
578
+ if (Object.keys(envVars).length === 0) {
579
+ throw new core.GeneralError("node", "noEnvVars", { prefix: envPrefix });
580
+ }
575
581
  console.info();
576
- const startResult = await start(serverInfo, envVars, options?.openApiSpecFile, options.stateStorage, options.customConfig);
582
+ const startResult = await start(serverInfo, envPrefix, envVars, options?.openApiSpecFile, options.stateStorage, options.customConfig);
577
583
  if (!core.Is.empty(startResult)) {
578
584
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
579
585
  process.on(signal, async () => {
@@ -470,19 +470,22 @@ async function bootstrapAuth(engineCore, context, envVars, features) {
470
470
  /**
471
471
  * Start the engine server.
472
472
  * @param serverInfo The server information.
473
+ * @param envVarsPrefix The prefix for the environment variables.
473
474
  * @param envVars The environment variables.
474
475
  * @param openApiSpecFile Path to the OpenAPI spec file.
475
476
  * @param stateStorage The state storage.
476
477
  * @param customConfig Extends the engine configuration with any additional custom configuration.
477
478
  * @returns The engine server.
478
479
  */
479
- async function start(serverInfo, envVars, openApiSpecFile, stateStorage, customConfig) {
480
+ async function start(serverInfo, envVarsPrefix, envVars, openApiSpecFile, stateStorage, customConfig) {
480
481
  envVars.storageFileRoot ??= "";
481
482
  if ((envVars.entityStorageConnectorType === EntityStorageConnectorType.File ||
482
483
  envVars.blobStorageConnectorType === BlobStorageConnectorType.File ||
483
484
  Is.empty(stateStorage)) &&
484
485
  !Is.stringValue(envVars.storageFileRoot)) {
485
- throw new GeneralError("node", "storageFileRootNotSet");
486
+ throw new GeneralError("node", "storageFileRootNotSet", {
487
+ storageFileRoot: `${envVarsPrefix}_STORAGE_FILE_ROOT`
488
+ });
486
489
  }
487
490
  // Build the engine configuration from the environment variables.
488
491
  const engineConfig = buildEngineConfiguration(envVars);
@@ -525,7 +528,7 @@ async function run(options) {
525
528
  try {
526
529
  const serverInfo = {
527
530
  name: options?.serverName ?? "TWIN Node Server",
528
- version: options?.serverVersion ?? "0.0.1-next.3" // x-release-please-version
531
+ version: options?.serverVersion ?? "0.0.1-next.4" // x-release-please-version
529
532
  };
530
533
  console.log(`\u001B[4m🌩️ ${serverInfo.name} v${serverInfo.version}\u001B[24m\n`);
531
534
  const executionDirectory = options?.executionDirectory ?? getExecutionDirectory();
@@ -551,8 +554,11 @@ async function run(options) {
551
554
  const envPrefix = options?.envPrefix ?? "TWIN_NODE_";
552
555
  console.info("Environment Prefix:", envPrefix);
553
556
  const envVars = EnvHelper.envToJson(process.env, envPrefix);
557
+ if (Object.keys(envVars).length === 0) {
558
+ throw new GeneralError("node", "noEnvVars", { prefix: envPrefix });
559
+ }
554
560
  console.info();
555
- const startResult = await start(serverInfo, envVars, options?.openApiSpecFile, options.stateStorage, options.customConfig);
561
+ const startResult = await start(serverInfo, envPrefix, envVars, options?.openApiSpecFile, options.stateStorage, options.customConfig);
556
562
  if (!Is.empty(startResult)) {
557
563
  for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"]) {
558
564
  process.on(signal, async () => {
@@ -9,13 +9,14 @@ import type { INodeVariables } from "./models/INodeVariables";
9
9
  /**
10
10
  * Start the engine server.
11
11
  * @param serverInfo The server information.
12
+ * @param envVarsPrefix The prefix for the environment variables.
12
13
  * @param envVars The environment variables.
13
14
  * @param openApiSpecFile Path to the OpenAPI spec file.
14
15
  * @param stateStorage The state storage.
15
16
  * @param customConfig Extends the engine configuration with any additional custom configuration.
16
17
  * @returns The engine server.
17
18
  */
18
- export declare function start(serverInfo: IServerInfo, envVars: INodeVariables, openApiSpecFile?: string, stateStorage?: IEngineStateStorage, customConfig?: (config: IEngineConfig) => Promise<void>): Promise<{
19
+ export declare function start(serverInfo: IServerInfo, envVarsPrefix: string, envVars: INodeVariables, openApiSpecFile?: string, stateStorage?: IEngineStateStorage, customConfig?: (config: IEngineConfig) => Promise<void>): Promise<{
19
20
  engine: Engine<IEngineServerConfig, INodeState>;
20
21
  server: EngineServer;
21
22
  } | undefined>;
package/docs/changelog.md CHANGED
@@ -1,12 +1,23 @@
1
- # Changelog
1
+ # @twin.org/node-core - Changelog
2
2
 
3
- ## [0.0.1-next.3](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.2...node-core-v0.0.1-next.3) (2025-05-27)
3
+ ## [0.0.1-next.4](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.3...node-core-v0.0.1-next.4) (2025-05-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * improve error reporting ([fcd39a1](https://github.com/twinfoundation/node/commit/fcd39a18da2a6ce33965a99ca5f2f36f4aba712f))
4
9
 
5
10
 
11
+ ### Bug Fixes
12
+
13
+ * broken docs ([61479fd](https://github.com/twinfoundation/node/commit/61479fd618f766d22c5aafec5277e1a89e22b453))
14
+
15
+ ## [0.0.1-next.3](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.2...node-core-v0.0.1-next.3) (2025-05-27)
16
+
6
17
  ### Features
7
18
 
8
- * additional run options ([c35e5bb](https://github.com/twinfoundation/node/commit/c35e5bbb8a80fe6a36628d41f64585b3723d9ad7))
9
- * node app use JavaScript ([14fe08c](https://github.com/twinfoundation/node/commit/14fe08cb760dd885a5dac9056a4d5dbc3d61df64))
19
+ - additional run options ([c35e5bb](https://github.com/twinfoundation/node/commit/c35e5bbb8a80fe6a36628d41f64585b3723d9ad7))
20
+ - node app use JavaScript ([14fe08c](https://github.com/twinfoundation/node/commit/14fe08cb760dd885a5dac9056a4d5dbc3d61df64))
10
21
 
11
22
  ## [0.0.1-next.2](https://github.com/twinfoundation/node/compare/node-core-v0.0.1-next.1...node-core-v0.0.1-next.2) (2025-05-27)
12
23
 
@@ -0,0 +1 @@
1
+ # @twin.org/node-core - Examples
@@ -1,6 +1,6 @@
1
1
  # Function: start()
2
2
 
3
- > **start**(`serverInfo`, `envVars`, `openApiSpecFile?`, `stateStorage?`, `customConfig?`): `Promise`\<`undefined` \| \{ `engine`: `Engine`\<`IEngineServerConfig`, [`INodeState`](../interfaces/INodeState.md)\>; `server`: `EngineServer`; \}\>
3
+ > **start**(`serverInfo`, `envVarsPrefix`, `envVars`, `openApiSpecFile?`, `stateStorage?`, `customConfig?`): `Promise`\<`undefined` \| \{ `engine`: `Engine`\<`IEngineServerConfig`, [`INodeState`](../interfaces/INodeState.md)\>; `server`: `EngineServer`; \}\>
4
4
 
5
5
  Start the engine server.
6
6
 
@@ -12,6 +12,12 @@ Start the engine server.
12
12
 
13
13
  The server information.
14
14
 
15
+ ### envVarsPrefix
16
+
17
+ `string`
18
+
19
+ The prefix for the environment variables.
20
+
15
21
  ### envVars
16
22
 
17
23
  [`INodeVariables`](../interfaces/INodeVariables.md)
package/locales/en.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "error": {
3
3
  "node": {
4
- "noEnvVars": "There are no environment variables starting TWIN_NODE_ the server will not start without them, please set them in the shell or create a .env file",
5
- "storageFileRootNotSet": "TWIN_NODE_STORAGE_FILE_ROOT is not set, the server will not start without it, please set it in the shell or create a .env file"
4
+ "noEnvVars": "There are no environment variables starting \"{prefix}\" the server will not start without them, please set them in the shell or create a .env file",
5
+ "storageFileRootNotSet": "{storageFileRoot} is not set, the server will not start without it, please set it in the shell or create a .env file"
6
6
  }
7
7
  },
8
8
  "node": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/node-core",
3
- "version": "0.0.1-next.3",
3
+ "version": "0.0.1-next.4",
4
4
  "description": "TWIN Node Core for serving APIs using the specified configuration",
5
5
  "repository": {
6
6
  "type": "git",