@twin.org/api-service 0.0.3-next.9 → 0.9.0-next.1

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 (52) hide show
  1. package/README.md +1 -1
  2. package/dist/es/healthRoutes.js +107 -0
  3. package/dist/es/healthRoutes.js.map +1 -0
  4. package/dist/es/healthService.js +155 -0
  5. package/dist/es/healthService.js.map +1 -0
  6. package/dist/es/index.js +7 -0
  7. package/dist/es/index.js.map +1 -1
  8. package/dist/es/informationRoutes.js +35 -67
  9. package/dist/es/informationRoutes.js.map +1 -1
  10. package/dist/es/informationService.js +11 -87
  11. package/dist/es/informationService.js.map +1 -1
  12. package/dist/es/models/IHealthServiceConfig.js +4 -0
  13. package/dist/es/models/IHealthServiceConfig.js.map +1 -0
  14. package/dist/es/models/IHealthServiceConstructorOptions.js +2 -0
  15. package/dist/es/models/IHealthServiceConstructorOptions.js.map +1 -0
  16. package/dist/es/models/IPlatformServiceConfig.js +4 -0
  17. package/dist/es/models/IPlatformServiceConfig.js.map +1 -0
  18. package/dist/es/models/IPlatformServiceConstructorOptions.js +2 -0
  19. package/dist/es/models/IPlatformServiceConstructorOptions.js.map +1 -0
  20. package/dist/es/platformService.js +155 -0
  21. package/dist/es/platformService.js.map +1 -0
  22. package/dist/es/restEntryPoints.js +10 -0
  23. package/dist/es/restEntryPoints.js.map +1 -1
  24. package/dist/types/healthRoutes.d.ts +20 -0
  25. package/dist/types/healthService.d.ts +42 -0
  26. package/dist/types/index.d.ts +7 -0
  27. package/dist/types/informationRoutes.d.ts +3 -3
  28. package/dist/types/informationService.d.ts +11 -23
  29. package/dist/types/models/IHealthServiceConfig.d.ts +16 -0
  30. package/dist/types/models/IHealthServiceConstructorOptions.d.ts +10 -0
  31. package/dist/types/models/IPlatformServiceConfig.d.ts +10 -0
  32. package/dist/types/models/IPlatformServiceConstructorOptions.d.ts +15 -0
  33. package/dist/types/platformService.d.ts +39 -0
  34. package/dist/types/restEntryPoints.d.ts +3 -0
  35. package/docs/changelog.md +740 -70
  36. package/docs/examples.md +74 -1
  37. package/docs/reference/classes/HealthService.md +123 -0
  38. package/docs/reference/classes/InformationService.md +18 -94
  39. package/docs/reference/classes/PlatformService.md +123 -0
  40. package/docs/reference/functions/generateRestRoutesHealth.md +25 -0
  41. package/docs/reference/functions/serverReadyz.md +31 -0
  42. package/docs/reference/index.md +10 -1
  43. package/docs/reference/interfaces/IHealthServiceConfig.md +32 -0
  44. package/docs/reference/interfaces/IHealthServiceConstructorOptions.md +11 -0
  45. package/docs/reference/interfaces/IInformationServiceConfig.md +5 -5
  46. package/docs/reference/interfaces/IInformationServiceConstructorOptions.md +1 -1
  47. package/docs/reference/interfaces/IPlatformServiceConfig.md +17 -0
  48. package/docs/reference/interfaces/IPlatformServiceConstructorOptions.md +25 -0
  49. package/docs/reference/variables/restEntryPoints.md +2 -0
  50. package/docs/reference/variables/tagsHealth.md +5 -0
  51. package/locales/en.json +7 -1
  52. package/package.json +13 -9
package/docs/examples.md CHANGED
@@ -1 +1,74 @@
1
- # @twin.org/api-service - Examples
1
+ # Service Examples
2
+
3
+ These snippets demonstrate how to configure service-level URL generation and expose operational information for monitoring.
4
+
5
+ ## InformationService
6
+
7
+ ```typescript
8
+ import { InformationService } from '@twin.org/api-service';
9
+
10
+ const infoService = new InformationService({
11
+ config: {
12
+ serverInfo: {
13
+ name: 'Twin API',
14
+ version: '1.2.0'
15
+ }
16
+ }
17
+ });
18
+
19
+ await infoService.start();
20
+ console.log(infoService.className()); // InformationService
21
+
22
+ const root = await infoService.root();
23
+ const info = await infoService.info();
24
+ const favicon = await infoService.favicon();
25
+
26
+ console.log(root); // Twin API - 1.2.0
27
+ console.log(info.version); // 1.2.0
28
+ console.log((favicon?.byteLength ?? 0) > 0); // true
29
+ ```
30
+
31
+ ```typescript
32
+ import { InformationService } from '@twin.org/api-service';
33
+
34
+ const infoService = new InformationService({
35
+ config: {
36
+ serverInfo: {
37
+ name: 'Twin API',
38
+ version: '1.2.0'
39
+ }
40
+ }
41
+ });
42
+
43
+ const spec = await infoService.spec();
44
+ const live = await infoService.livez();
45
+ const health = await infoService.health();
46
+
47
+ await infoService.setComponentHealth('queue', 'ok');
48
+ await infoService.removeComponentHealth('queue');
49
+
50
+ console.log(typeof spec); // undefined
51
+ console.log(live); // true
52
+ console.log(health.status); // ok
53
+ ```
54
+
55
+ ## HostingService
56
+
57
+ ```typescript
58
+ import { HostingService } from '@twin.org/api-service';
59
+
60
+ const hostingService = new HostingService({
61
+ config: {
62
+ localOrigin: 'http://localhost:3000',
63
+ publicOrigin: 'https://api.example.org'
64
+ }
65
+ });
66
+
67
+ console.log(hostingService.className()); // HostingService
68
+
69
+ const publicOrigin = await hostingService.getPublicOrigin('http://localhost:3000/users');
70
+ const usersUrl = await hostingService.buildPublicUrl('http://localhost:3000/users');
71
+
72
+ console.log(publicOrigin); // https://api.example.org
73
+ console.log(usersUrl); // https://api.example.org/users
74
+ ```
@@ -0,0 +1,123 @@
1
+ # Class: HealthService
2
+
3
+ The health service for the server.
4
+
5
+ ## Implements
6
+
7
+ - `IHealthComponent`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new HealthService**(`options?`): `HealthService`
14
+
15
+ Create a new instance of HealthService.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`IHealthServiceConstructorOptions`](../interfaces/IHealthServiceConstructorOptions.md)
22
+
23
+ The constructor options.
24
+
25
+ #### Returns
26
+
27
+ `HealthService`
28
+
29
+ ## Properties
30
+
31
+ ### CLASS\_NAME {#class_name}
32
+
33
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
+
35
+ Runtime name for the class.
36
+
37
+ ## Methods
38
+
39
+ ### className() {#classname}
40
+
41
+ > **className**(): `string`
42
+
43
+ Returns the class name of the component.
44
+
45
+ #### Returns
46
+
47
+ `string`
48
+
49
+ The class name of the component.
50
+
51
+ #### Implementation of
52
+
53
+ `IHealthComponent.className`
54
+
55
+ ***
56
+
57
+ ### start() {#start}
58
+
59
+ > **start**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
60
+
61
+ The component needs to be started when the node is initialized.
62
+
63
+ #### Parameters
64
+
65
+ ##### nodeLoggingComponentType?
66
+
67
+ `string`
68
+
69
+ The node logging component type.
70
+
71
+ #### Returns
72
+
73
+ `Promise`\<`void`\>
74
+
75
+ A promise that resolves when the initial health check timer has been scheduled.
76
+
77
+ #### Implementation of
78
+
79
+ `IHealthComponent.start`
80
+
81
+ ***
82
+
83
+ ### stop() {#stop}
84
+
85
+ > **stop**(`nodeLoggingComponentType?`): `Promise`\<`void`\>
86
+
87
+ The component needs to be stopped when the node is closed.
88
+
89
+ #### Parameters
90
+
91
+ ##### nodeLoggingComponentType?
92
+
93
+ `string`
94
+
95
+ The node logging component type.
96
+
97
+ #### Returns
98
+
99
+ `Promise`\<`void`\>
100
+
101
+ A promise that resolves when the health check timer has been cancelled.
102
+
103
+ #### Implementation of
104
+
105
+ `IHealthComponent.stop`
106
+
107
+ ***
108
+
109
+ ### healthStatus() {#healthstatus}
110
+
111
+ > **healthStatus**(): `Promise`\<\{ `status`: `HealthStatus`; `components`: `IHealth`[]; \}\>
112
+
113
+ Get the server health.
114
+
115
+ #### Returns
116
+
117
+ `Promise`\<\{ `status`: `HealthStatus`; `components`: `IHealth`[]; \}\>
118
+
119
+ The service health.
120
+
121
+ #### Implementation of
122
+
123
+ `IHealthComponent.healthStatus`
@@ -28,7 +28,7 @@ The options to create the service.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ## Methods
38
38
 
39
- ### className()
39
+ ### className() {#classname}
40
40
 
41
41
  > **className**(): `string`
42
42
 
@@ -54,7 +54,7 @@ The class name of the component.
54
54
 
55
55
  ***
56
56
 
57
- ### start()
57
+ ### start() {#start}
58
58
 
59
59
  > **start**(): `Promise`\<`void`\>
60
60
 
@@ -64,7 +64,7 @@ The service needs to be started when the application is initialized.
64
64
 
65
65
  `Promise`\<`void`\>
66
66
 
67
- Nothing.
67
+ A promise that resolves when the OpenAPI spec and favicon have been loaded from disk.
68
68
 
69
69
  #### Implementation of
70
70
 
@@ -72,7 +72,7 @@ Nothing.
72
72
 
73
73
  ***
74
74
 
75
- ### root()
75
+ ### root() {#root}
76
76
 
77
77
  > **root**(): `Promise`\<`string`\>
78
78
 
@@ -90,7 +90,7 @@ The root information.
90
90
 
91
91
  ***
92
92
 
93
- ### info()
93
+ ### info() {#info}
94
94
 
95
95
  > **info**(): `Promise`\<`IServerInfo`\>
96
96
 
@@ -108,7 +108,7 @@ The service information.
108
108
 
109
109
  ***
110
110
 
111
- ### favicon()
111
+ ### favicon() {#favicon}
112
112
 
113
113
  > **favicon**(): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
114
114
 
@@ -126,7 +126,7 @@ The favicon.
126
126
 
127
127
  ***
128
128
 
129
- ### spec()
129
+ ### spec() {#spec}
130
130
 
131
131
  > **spec**(): `Promise`\<`unknown`\>
132
132
 
@@ -144,17 +144,17 @@ The OpenAPI spec.
144
144
 
145
145
  ***
146
146
 
147
- ### livez()
147
+ ### livez() {#livez}
148
148
 
149
- > **livez**(): `Promise`\<`boolean`\>
149
+ > **livez**(): `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
150
150
 
151
151
  Is the server live.
152
152
 
153
153
  #### Returns
154
154
 
155
- `Promise`\<`boolean`\>
155
+ `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
156
156
 
157
- True if the server is live.
157
+ The liveness status of the server.
158
158
 
159
159
  #### Implementation of
160
160
 
@@ -162,94 +162,18 @@ True if the server is live.
162
162
 
163
163
  ***
164
164
 
165
- ### health()
165
+ ### readyz() {#readyz}
166
166
 
167
- > **health**(): `Promise`\<`IHealthInfo`\>
167
+ > **readyz**(): `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
168
168
 
169
- Get the server health.
169
+ Is the server ready.
170
170
 
171
171
  #### Returns
172
172
 
173
- `Promise`\<`IHealthInfo`\>
173
+ `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
174
174
 
175
- The service health.
175
+ The readyz status of the server.
176
176
 
177
177
  #### Implementation of
178
178
 
179
- `IInformationComponent.health`
180
-
181
- ***
182
-
183
- ### setComponentHealth()
184
-
185
- > **setComponentHealth**(`name`, `status`, `details?`, `tenantId?`): `Promise`\<`void`\>
186
-
187
- Set the status of a component.
188
-
189
- #### Parameters
190
-
191
- ##### name
192
-
193
- `string`
194
-
195
- The component name.
196
-
197
- ##### status
198
-
199
- `HealthStatus`
200
-
201
- The status of the component.
202
-
203
- ##### details?
204
-
205
- `string`
206
-
207
- The details for the status.
208
-
209
- ##### tenantId?
210
-
211
- `string`
212
-
213
- The tenant id, optional if the health status is not tenant specific.
214
-
215
- #### Returns
216
-
217
- `Promise`\<`void`\>
218
-
219
- Nothing.
220
-
221
- #### Implementation of
222
-
223
- `IInformationComponent.setComponentHealth`
224
-
225
- ***
226
-
227
- ### removeComponentHealth()
228
-
229
- > **removeComponentHealth**(`name`, `tenantId?`): `Promise`\<`void`\>
230
-
231
- Remove the status of a component.
232
-
233
- #### Parameters
234
-
235
- ##### name
236
-
237
- `string`
238
-
239
- The component name.
240
-
241
- ##### tenantId?
242
-
243
- `string`
244
-
245
- The tenant id, optional if the health status is not tenant specific.
246
-
247
- #### Returns
248
-
249
- `Promise`\<`void`\>
250
-
251
- Nothing.
252
-
253
- #### Implementation of
254
-
255
- `IInformationComponent.removeComponentHealth`
179
+ `IInformationComponent.readyz`
@@ -0,0 +1,123 @@
1
+ # Class: PlatformService
2
+
3
+ Service for performing platform operations.
4
+
5
+ ## Implements
6
+
7
+ - `IPlatformComponent`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new PlatformService**(`options?`): `PlatformService`
14
+
15
+ Create a new instance of PlatformService.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`IPlatformServiceConstructorOptions`](../interfaces/IPlatformServiceConstructorOptions.md)
22
+
23
+ The options for the connector.
24
+
25
+ #### Returns
26
+
27
+ `PlatformService`
28
+
29
+ ## Properties
30
+
31
+ ### CLASS\_NAME {#class_name}
32
+
33
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
+
35
+ Runtime name for the class.
36
+
37
+ ## Methods
38
+
39
+ ### className() {#classname}
40
+
41
+ > **className**(): `string`
42
+
43
+ Returns the class name of the component.
44
+
45
+ #### Returns
46
+
47
+ `string`
48
+
49
+ The class name of the component.
50
+
51
+ #### Implementation of
52
+
53
+ `IPlatformComponent.className`
54
+
55
+ ***
56
+
57
+ ### isMultiTenant() {#ismultitenant}
58
+
59
+ > **isMultiTenant**(): `boolean`
60
+
61
+ Indicates whether the component is running in a multi-tenant environment.
62
+
63
+ #### Returns
64
+
65
+ `boolean`
66
+
67
+ True if the component is running in a multi-tenant environment, false otherwise.
68
+
69
+ #### Implementation of
70
+
71
+ `IPlatformComponent.isMultiTenant`
72
+
73
+ ***
74
+
75
+ ### execute() {#execute}
76
+
77
+ > **execute**(`method`): `Promise`\<`void`\>
78
+
79
+ Execute a method, if single tenant will run once, if multi-tenant will run for each tenant.
80
+
81
+ #### Parameters
82
+
83
+ ##### method
84
+
85
+ () => `Promise`\<`void`\>
86
+
87
+ The method to run for each tenant.
88
+
89
+ #### Returns
90
+
91
+ `Promise`\<`void`\>
92
+
93
+ A promise that resolves when the method has been executed for all applicable tenants.
94
+
95
+ #### Implementation of
96
+
97
+ `IPlatformComponent.execute`
98
+
99
+ ***
100
+
101
+ ### getLocalOriginContext() {#getlocalorigincontext}
102
+
103
+ > **getLocalOriginContext**(`url`): `Promise`\<`IContextIds` \| `undefined`\>
104
+
105
+ Get the local origin context IDs for the given URL.
106
+
107
+ #### Parameters
108
+
109
+ ##### url
110
+
111
+ `string`
112
+
113
+ The URL to check.
114
+
115
+ #### Returns
116
+
117
+ `Promise`\<`IContextIds` \| `undefined`\>
118
+
119
+ A promise that resolves to the context IDs if the URL is a local origin, undefined otherwise.
120
+
121
+ #### Implementation of
122
+
123
+ `IPlatformComponent.getLocalOriginContext`
@@ -0,0 +1,25 @@
1
+ # Function: generateRestRoutesHealth()
2
+
3
+ > **generateRestRoutesHealth**(`baseRouteName`, `componentName`): `IRestRoute`\<`any`, `any`\>[]
4
+
5
+ The REST routes for server health.
6
+
7
+ ## Parameters
8
+
9
+ ### baseRouteName
10
+
11
+ `string`
12
+
13
+ Prefix to prepend to the paths.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes stored in the ComponentFactory.
20
+
21
+ ## Returns
22
+
23
+ `IRestRoute`\<`any`, `any`\>[]
24
+
25
+ The generated routes.
@@ -0,0 +1,31 @@
1
+ # Function: serverReadyz()
2
+
3
+ > **serverReadyz**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`IServerReadyzResponse`\>
4
+
5
+ Get the readyz for the server.
6
+
7
+ ## Parameters
8
+
9
+ ### httpRequestContext
10
+
11
+ `IHttpRequestContext`
12
+
13
+ The request context for the API.
14
+
15
+ ### componentName
16
+
17
+ `string`
18
+
19
+ The name of the component to use in the routes.
20
+
21
+ ### request
22
+
23
+ `INoContentRequest`
24
+
25
+ The request.
26
+
27
+ ## Returns
28
+
29
+ `Promise`\<`IServerReadyzResponse`\>
30
+
31
+ The response object with additional http response properties.
@@ -2,24 +2,33 @@
2
2
 
3
3
  ## Classes
4
4
 
5
+ - [HealthService](classes/HealthService.md)
5
6
  - [InformationService](classes/InformationService.md)
7
+ - [PlatformService](classes/PlatformService.md)
6
8
 
7
9
  ## Interfaces
8
10
 
11
+ - [IHealthServiceConfig](interfaces/IHealthServiceConfig.md)
12
+ - [IHealthServiceConstructorOptions](interfaces/IHealthServiceConstructorOptions.md)
9
13
  - [IInformationServiceConfig](interfaces/IInformationServiceConfig.md)
10
14
  - [IInformationServiceConstructorOptions](interfaces/IInformationServiceConstructorOptions.md)
15
+ - [IPlatformServiceConfig](interfaces/IPlatformServiceConfig.md)
16
+ - [IPlatformServiceConstructorOptions](interfaces/IPlatformServiceConstructorOptions.md)
11
17
 
12
18
  ## Variables
13
19
 
20
+ - [tagsHealth](variables/tagsHealth.md)
14
21
  - [tagsInformation](variables/tagsInformation.md)
15
22
  - [restEntryPoints](variables/restEntryPoints.md)
16
23
 
17
24
  ## Functions
18
25
 
26
+ - [generateRestRoutesHealth](functions/generateRestRoutesHealth.md)
27
+ - [serverHealth](functions/serverHealth.md)
19
28
  - [generateRestRoutesInformation](functions/generateRestRoutesInformation.md)
20
29
  - [serverRoot](functions/serverRoot.md)
21
30
  - [serverInfo](functions/serverInfo.md)
22
31
  - [serverLivez](functions/serverLivez.md)
23
- - [serverHealth](functions/serverHealth.md)
32
+ - [serverReadyz](functions/serverReadyz.md)
24
33
  - [serverFavIcon](functions/serverFavIcon.md)
25
34
  - [serverSpec](functions/serverSpec.md)
@@ -0,0 +1,32 @@
1
+ # Interface: IHealthServiceConfig
2
+
3
+ Configuration for the health service.
4
+
5
+ ## Properties
6
+
7
+ ### healthCheckInterval? {#healthcheckinterval}
8
+
9
+ > `optional` **healthCheckInterval?**: `number`
10
+
11
+ The interval for checking the health of the components and setting it in the health service.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ 60000
17
+ ```
18
+
19
+ ***
20
+
21
+ ### initialInterval? {#initialinterval}
22
+
23
+ > `optional` **initialInterval?**: `number`
24
+
25
+ The initial interval for checking the health of the components and setting it in the health service.
26
+ This is used to check the health of the components immediately after the service is started.
27
+
28
+ #### Default
29
+
30
+ ```ts
31
+ 2000
32
+ ```
@@ -0,0 +1,11 @@
1
+ # Interface: IHealthServiceConstructorOptions
2
+
3
+ Options for the HealthService constructor.
4
+
5
+ ## Properties
6
+
7
+ ### config? {#config}
8
+
9
+ > `optional` **config?**: [`IHealthServiceConfig`](IHealthServiceConfig.md)
10
+
11
+ The configuration for the service.
@@ -4,7 +4,7 @@ Configuration for the information service.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### serverInfo
7
+ ### serverInfo {#serverinfo}
8
8
 
9
9
  > **serverInfo**: `IServerInfo`
10
10
 
@@ -12,16 +12,16 @@ The server information.
12
12
 
13
13
  ***
14
14
 
15
- ### openApiSpecPath?
15
+ ### openApiSpecPath? {#openapispecpath}
16
16
 
17
- > `optional` **openApiSpecPath**: `string`
17
+ > `optional` **openApiSpecPath?**: `string`
18
18
 
19
19
  The path to the OpenAPI Spec.
20
20
 
21
21
  ***
22
22
 
23
- ### favIconPath?
23
+ ### favIconPath? {#faviconpath}
24
24
 
25
- > `optional` **favIconPath**: `string`
25
+ > `optional` **favIconPath?**: `string`
26
26
 
27
27
  The path to the favicon.
@@ -4,7 +4,7 @@ Options for the InformationService constructor.
4
4
 
5
5
  ## Properties
6
6
 
7
- ### config
7
+ ### config {#config}
8
8
 
9
9
  > **config**: [`IInformationServiceConfig`](IInformationServiceConfig.md)
10
10
 
@@ -0,0 +1,17 @@
1
+ # Interface: IPlatformServiceConfig
2
+
3
+ Configuration for the platform service
4
+
5
+ ## Properties
6
+
7
+ ### isMultiTenant? {#ismultitenant}
8
+
9
+ > `optional` **isMultiTenant?**: `boolean`
10
+
11
+ Indicates whether the service is running in a multi-tenant environment.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ false
17
+ ```