@twin.org/node-core 0.0.3-next.28 → 0.0.3-next.29

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.
@@ -4,25 +4,31 @@ The options when running the node.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### serverName?
7
+ ### serverName? {#servername}
8
8
 
9
- > `optional` **serverName**: `string`
9
+ > `optional` **serverName?**: `string`
10
10
 
11
11
  The name of the server, defaults to "TWIN Node".
12
12
 
13
+ #### Default
14
+
15
+ ```ts
16
+ "TWIN Node"
17
+ ```
18
+
13
19
  ***
14
20
 
15
- ### serverVersion?
21
+ ### serverVersion? {#serverversion}
16
22
 
17
- > `optional` **serverVersion**: `string`
23
+ > `optional` **serverVersion?**: `string`
18
24
 
19
25
  The version of the server, defaults to the current version.
20
26
 
21
27
  ***
22
28
 
23
- ### envVars?
29
+ ### envVars? {#envvars}
24
30
 
25
- > `optional` **envVars**: `object`
31
+ > `optional` **envVars?**: `object`
26
32
 
27
33
  Additional environment variables to set.
28
34
 
@@ -32,25 +38,25 @@ Additional environment variables to set.
32
38
 
33
39
  ***
34
40
 
35
- ### envFilenames?
41
+ ### envFilenames? {#envfilenames}
36
42
 
37
- > `optional` **envFilenames**: `string`[]
43
+ > `optional` **envFilenames?**: `string`[]
38
44
 
39
45
  Additional environment variable filenames to load, defaults to .env.
40
46
 
41
47
  ***
42
48
 
43
- ### envPrefix?
49
+ ### envPrefix? {#envprefix}
44
50
 
45
- > `optional` **envPrefix**: `string`
51
+ > `optional` **envPrefix?**: `string`
46
52
 
47
53
  The prefix for environment variables, defaults to "TWIN_".
48
54
 
49
55
  ***
50
56
 
51
- ### configFilenames?
57
+ ### configFilenames? {#configfilenames}
52
58
 
53
- > `optional` **configFilenames**: `string`[]
59
+ > `optional` **configFilenames?**: `string`[]
54
60
 
55
61
  A list of JSON files to load as configuration files.
56
62
  The files will be loaded in the order they are provided, and the last one will
@@ -58,58 +64,58 @@ override any previous values.
58
64
 
59
65
  ***
60
66
 
61
- ### config?
67
+ ### config? {#config}
62
68
 
63
- > `optional` **config**: `IEngineConfig`
69
+ > `optional` **config?**: `IEngineConfig`
64
70
 
65
71
  Provides the ability to have some initial custom configuration for the engine.
66
72
  This will be merged with any configuration loaded from the environment variables.
67
73
 
68
74
  ***
69
75
 
70
- ### scriptDirectory?
76
+ ### scriptDirectory? {#scriptdirectory}
71
77
 
72
- > `optional` **scriptDirectory**: `string`
78
+ > `optional` **scriptDirectory?**: `string`
73
79
 
74
80
  The directory to override the script location, defaults to location of index.js.
75
81
 
76
82
  ***
77
83
 
78
- ### executionDirectory?
84
+ ### executionDirectory? {#executiondirectory}
79
85
 
80
- > `optional` **executionDirectory**: `string`
86
+ > `optional` **executionDirectory?**: `string`
81
87
 
82
88
  The directory to override the execution location, defaults to process directory.
83
89
 
84
90
  ***
85
91
 
86
- ### localesDirectory?
92
+ ### localesDirectory? {#localesdirectory}
87
93
 
88
- > `optional` **localesDirectory**: `string`
94
+ > `optional` **localesDirectory?**: `string`
89
95
 
90
96
  The directory to override the locales directory, defaults to the locales directory.
91
97
 
92
98
  ***
93
99
 
94
- ### openApiSpecFile?
100
+ ### openApiSpecFile? {#openapispecfile}
95
101
 
96
- > `optional` **openApiSpecFile**: `string`
102
+ > `optional` **openApiSpecFile?**: `string`
97
103
 
98
104
  The path to the OpenAPI spec file, defaults to docs/open-api/spec.json.
99
105
 
100
106
  ***
101
107
 
102
- ### favIconFile?
108
+ ### favIconFile? {#faviconfile}
103
109
 
104
- > `optional` **favIconFile**: `string`
110
+ > `optional` **favIconFile?**: `string`
105
111
 
106
112
  The path to the favicon, defaults to static/favicon.png.
107
113
 
108
114
  ***
109
115
 
110
- ### extendEnvVars()?
116
+ ### extendEnvVars? {#extendenvvars}
111
117
 
112
- > `optional` **extendEnvVars**: (`envVars`) => `Promise`\<`void`\>
118
+ > `optional` **extendEnvVars?**: (`envVars`) => `Promise`\<`void`\>
113
119
 
114
120
  Method to extend the engine environment variables with any additional custom configuration.
115
121
 
@@ -125,9 +131,9 @@ Method to extend the engine environment variables with any additional custom con
125
131
 
126
132
  ***
127
133
 
128
- ### extendConfig()?
134
+ ### extendConfig? {#extendconfig}
129
135
 
130
- > `optional` **extendConfig**: (`envVars`, `config`) => `Promise`\<`void`\>
136
+ > `optional` **extendConfig?**: (`envVars`, `config`) => `Promise`\<`void`\>
131
137
 
132
138
  Method to extend the engine configuration with any additional custom configuration.
133
139
 
@@ -147,9 +153,9 @@ Method to extend the engine configuration with any additional custom configurati
147
153
 
148
154
  ***
149
155
 
150
- ### extendEngine()?
156
+ ### extendEngine? {#extendengine}
151
157
 
152
- > `optional` **extendEngine**: (`engine`) => `Promise`\<`void`\>
158
+ > `optional` **extendEngine?**: (`engine`) => `Promise`\<`void`\>
153
159
 
154
160
  Method to extend the engine with any additional options.
155
161
 
@@ -165,9 +171,9 @@ Method to extend the engine with any additional options.
165
171
 
166
172
  ***
167
173
 
168
- ### extendEngineServer()?
174
+ ### extendEngineServer? {#extendengineserver}
169
175
 
170
- > `optional` **extendEngineServer**: (`engineServer`) => `Promise`\<`void`\>
176
+ > `optional` **extendEngineServer?**: (`engineServer`) => `Promise`\<`void`\>
171
177
 
172
178
  Method to extend the engine server with any additional options.
173
179
 
@@ -183,17 +189,17 @@ Method to extend the engine server with any additional options.
183
189
 
184
190
  ***
185
191
 
186
- ### stateStorage?
192
+ ### stateStorage? {#statestorage}
187
193
 
188
- > `optional` **stateStorage**: `IEngineStateStorage`\<`IEngineState`\>
194
+ > `optional` **stateStorage?**: `IEngineStateStorage`\<`IEngineState`\>
189
195
 
190
196
  The state storage to use for the engine.
191
197
  If not provided, a default file-based state storage will be used.
192
198
 
193
199
  ***
194
200
 
195
- ### disableProcessExitOnFailure?
201
+ ### disableProcessExitOnFailure? {#disableprocessexitonfailure}
196
202
 
197
- > `optional` **disableProcessExitOnFailure**: `boolean`
203
+ > `optional` **disableProcessExitOnFailure?**: `boolean`
198
204
 
199
205
  Disables process.exit calls on fatal errors and throws instead.
@@ -4,7 +4,7 @@ The result from a protocol handler.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### resolvedPath
7
+ ### resolvedPath {#resolvedpath}
8
8
 
9
9
  > **resolvedPath**: `string`
10
10
 
@@ -12,7 +12,7 @@ The resolved path to the module file.
12
12
 
13
13
  ***
14
14
 
15
- ### cached
15
+ ### cached {#cached}
16
16
 
17
17
  > **cached**: `boolean`
18
18
 
@@ -1,4 +1,4 @@
1
- # Type Alias: NodeExtensionInitialiseEngineMethod()
1
+ # Type Alias: NodeExtensionInitialiseEngineMethod
2
2
 
3
3
  > **NodeExtensionInitialiseEngineMethod** = (`engineCore`) => `Promise`\<`void`\>
4
4
 
@@ -1,4 +1,4 @@
1
- # Type Alias: NodeExtensionInitialiseEngineServerMethod()
1
+ # Type Alias: NodeExtensionInitialiseEngineServerMethod
2
2
 
3
3
  > **NodeExtensionInitialiseEngineServerMethod** = (`engineCore`, `engineServer`) => `Promise`\<`void`\>
4
4
 
@@ -1,4 +1,4 @@
1
- # Type Alias: NodeExtensionInitialiseMethod()
1
+ # Type Alias: NodeExtensionInitialiseMethod
2
2
 
3
3
  > **NodeExtensionInitialiseMethod** = (`envVars`, `nodeEngineConfig`) => `Promise`\<`void`\>
4
4
 
@@ -1,4 +1,4 @@
1
- # Type Alias: NodeExtensionShutdownMethod()
1
+ # Type Alias: NodeExtensionShutdownMethod
2
2
 
3
3
  > **NodeExtensionShutdownMethod** = () => `Promise`\<`void`\>
4
4
 
@@ -6,31 +6,31 @@ The protocol types for modules.
6
6
 
7
7
  ## Type Declaration
8
8
 
9
- ### Local
9
+ ### Local {#local}
10
10
 
11
11
  > `readonly` **Local**: `"local"` = `"local"`
12
12
 
13
13
  Local module (starts with . or / or file://).
14
14
 
15
- ### Npm
15
+ ### Npm {#npm}
16
16
 
17
17
  > `readonly` **Npm**: `"npm"` = `"npm"`
18
18
 
19
19
  NPM package (starts with npm:).
20
20
 
21
- ### Https
21
+ ### Https {#https}
22
22
 
23
23
  > `readonly` **Https**: `"https"` = `"https"`
24
24
 
25
25
  HTTPS URL (starts with https://).
26
26
 
27
- ### Http
27
+ ### Http {#http}
28
28
 
29
29
  > `readonly` **Http**: `"http"` = `"http"`
30
30
 
31
31
  HTTP URL (starts with http://).
32
32
 
33
- ### Default
33
+ ### Default {#default}
34
34
 
35
35
  > `readonly` **Default**: `"default"` = `"default"`
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/node-core",
3
- "version": "0.0.3-next.28",
3
+ "version": "0.0.3-next.29",
4
4
  "description": "TWIN Node Core for serving APIs using the specified configuration",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,129 +0,0 @@
1
- # TWIN Node - Detailed Documentation
2
-
3
- ## Overview
4
-
5
- TWIN Node provides the foundational components for running TWIN nodes, including dynamic extension loading, protocol-based module resolution, and lifecycle management.
6
-
7
- ## Protocol-Based Extension Loading
8
-
9
- The TWIN Node supports dynamic extension loading from multiple sources:
10
-
11
- ### Local Files
12
-
13
- Load extensions from your filesystem:
14
-
15
- ```bash
16
- TWIN_EXTENSIONS="./my-extension.mjs"
17
- ```
18
-
19
- ### NPM Packages
20
-
21
- Automatically install and load npm packages:
22
-
23
- ```bash
24
- TWIN_EXTENSIONS="npm:@twin.org/package"
25
- ```
26
-
27
- ### HTTPS URLs
28
-
29
- Download and cache remote extensions:
30
-
31
- ```bash
32
- TWIN_EXTENSIONS="https://example.com/extension.mjs"
33
- ```
34
-
35
- ## Extension Lifecycle Hooks
36
-
37
- Extensions can implement lifecycle hooks to customize node behavior at different stages:
38
-
39
- - **`extensionInitialise`** - Called before engine initialization
40
- - **`extensionInitialiseEngine`** - Called during engine initialization
41
- - **`extensionInitialiseEngineServer`** - Called during server initialization
42
- - **`extensionShutdown`** - Called during graceful shutdown
43
-
44
- ### Example Extension
45
-
46
- ```javascript
47
- // my-extension.mjs
48
- export function extensionInitialise() {
49
- console.log('Extension initializing...');
50
- }
51
-
52
- export function extensionInitialiseEngine(engine) {
53
- console.log('Configuring engine...');
54
- // Add custom components, routes, etc.
55
- }
56
-
57
- export function extensionInitialiseEngineServer(server) {
58
- console.log('Configuring server...');
59
- // Add middleware, routes, etc.
60
- }
61
-
62
- export function extensionShutdown() {
63
- console.log('Extension shutting down...');
64
- // Cleanup resources
65
- }
66
- ```
67
-
68
- ## Configuration Options
69
-
70
- ### Cache Management
71
-
72
- - `TWIN_EXTENSIONS_CACHE_TTL_HOURS` - TTL for HTTPS extensions cache (default: 24)
73
- - `TWIN_EXTENSIONS_FORCE_REFRESH` - Force refresh all cached extensions (default: false)
74
- - `TWIN_EXTENSIONS_CACHE_DIRECTORY` - Custom cache directory (default: ".tmp")
75
-
76
- ### Security
77
-
78
- - `TWIN_EXTENSIONS_MAX_SIZE_MB` - Maximum size for HTTPS downloads (default: 10)
79
- - `TWIN_EXTENSIONS_CLEAR_CACHE` - Clear cache on startup (default: false)
80
-
81
- ## API Reference
82
-
83
- ### Core Functions
84
-
85
- #### `overrideModuleImport(executionDirectory, envVars)`
86
-
87
- Sets up protocol-based module resolution for extensions.
88
-
89
- #### `buildConfiguration(options)`
90
-
91
- Builds node configuration from environment variables and options.
92
-
93
- #### `start(options)`
94
-
95
- Starts the TWIN node with the specified configuration.
96
-
97
- ### Utility Functions
98
-
99
- #### `parseModuleProtocol(moduleName)`
100
-
101
- Parses module name to determine protocol type (npm, https, local, etc.).
102
-
103
- #### `handleNpmProtocol(packageName, executionDirectory, cacheDirectory)`
104
-
105
- Handles installation and resolution of npm packages.
106
-
107
- #### `handleHttpsProtocol(url, executionDirectory, maxSizeMb, cacheDirectory, ttlHours, forceRefresh)`
108
-
109
- Handles download and caching of HTTPS extensions.
110
-
111
- ## Security Considerations
112
-
113
- - **HTTPS Only**: Remote extensions must use HTTPS protocol
114
- - **Size Limits**: Downloads are limited by `TWIN_EXTENSIONS_MAX_SIZE_MB`
115
- - **Cache TTL**: Extensions are automatically refreshed based on TTL
116
- - **Security Warnings**: Warnings are displayed when loading remote extensions
117
-
118
- ## Troubleshooting
119
-
120
- ### Common Issues
121
-
122
- 1. **Extension not found**: Check that the path/URL is correct and accessible
123
- 2. **Cache issues**: Use `TWIN_EXTENSIONS_FORCE_REFRESH=true` to force refresh
124
- 3. **Size limit exceeded**: Increase `TWIN_EXTENSIONS_MAX_SIZE_MB` if needed
125
- 4. **Network issues**: Ensure HTTPS URLs are accessible and not blocked by firewall
126
-
127
- ### Debug Mode
128
-
129
- Set `NODE_ENV=development` for additional debug output during extension loading.