@twin.org/api-service 0.0.3-next.4 → 0.0.3-next.40

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 (63) 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 +156 -0
  5. package/dist/es/healthService.js.map +1 -0
  6. package/dist/es/hostingService.js +89 -0
  7. package/dist/es/hostingService.js.map +1 -0
  8. package/dist/es/index.js +10 -0
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/informationRoutes.js +92 -62
  11. package/dist/es/informationRoutes.js.map +1 -1
  12. package/dist/es/informationService.js +12 -58
  13. package/dist/es/informationService.js.map +1 -1
  14. package/dist/es/models/IHealthServiceConfig.js +4 -0
  15. package/dist/es/models/IHealthServiceConfig.js.map +1 -0
  16. package/dist/es/models/IHealthServiceConstructorOptions.js +2 -0
  17. package/dist/es/models/IHealthServiceConstructorOptions.js.map +1 -0
  18. package/dist/es/models/IHostingServiceConfig.js +4 -0
  19. package/dist/es/models/IHostingServiceConfig.js.map +1 -0
  20. package/dist/es/models/IHostingServiceConstructorOptions.js +2 -0
  21. package/dist/es/models/IHostingServiceConstructorOptions.js.map +1 -0
  22. package/dist/es/models/IUrlTransformerServiceConfig.js +4 -0
  23. package/dist/es/models/IUrlTransformerServiceConfig.js.map +1 -0
  24. package/dist/es/models/IUrlTransformerServiceConstructorOptions.js +2 -0
  25. package/dist/es/models/IUrlTransformerServiceConstructorOptions.js.map +1 -0
  26. package/dist/es/restEntryPoints.js +7 -0
  27. package/dist/es/restEntryPoints.js.map +1 -1
  28. package/dist/es/urlTransformerService.js +256 -0
  29. package/dist/es/urlTransformerService.js.map +1 -0
  30. package/dist/types/healthRoutes.d.ts +20 -0
  31. package/dist/types/healthService.d.ts +42 -0
  32. package/dist/types/hostingService.d.ts +39 -0
  33. package/dist/types/index.d.ts +10 -0
  34. package/dist/types/informationRoutes.d.ts +11 -3
  35. package/dist/types/informationService.d.ts +11 -16
  36. package/dist/types/models/IHealthServiceConfig.d.ts +16 -0
  37. package/dist/types/models/IHealthServiceConstructorOptions.d.ts +10 -0
  38. package/dist/types/models/IHostingServiceConfig.d.ts +13 -0
  39. package/dist/types/models/IHostingServiceConstructorOptions.d.ts +15 -0
  40. package/dist/types/models/IUrlTransformerServiceConfig.d.ts +19 -0
  41. package/dist/types/models/IUrlTransformerServiceConstructorOptions.d.ts +15 -0
  42. package/dist/types/urlTransformerService.d.ts +94 -0
  43. package/docs/changelog.md +574 -55
  44. package/docs/examples.md +74 -1
  45. package/docs/reference/classes/HealthService.md +123 -0
  46. package/docs/reference/classes/HostingService.md +131 -0
  47. package/docs/reference/classes/InformationService.md +19 -65
  48. package/docs/reference/classes/UrlTransformerService.md +379 -0
  49. package/docs/reference/functions/generateRestRoutesHealth.md +25 -0
  50. package/docs/reference/functions/serverLivez.md +31 -0
  51. package/docs/reference/functions/serverReadyz.md +31 -0
  52. package/docs/reference/index.md +14 -1
  53. package/docs/reference/interfaces/IHealthServiceConfig.md +32 -0
  54. package/docs/reference/interfaces/IHealthServiceConstructorOptions.md +11 -0
  55. package/docs/reference/interfaces/IHostingServiceConfig.md +19 -0
  56. package/docs/reference/interfaces/IHostingServiceConstructorOptions.md +25 -0
  57. package/docs/reference/interfaces/IInformationServiceConfig.md +5 -5
  58. package/docs/reference/interfaces/IInformationServiceConstructorOptions.md +1 -1
  59. package/docs/reference/interfaces/IUrlTransformerServiceConfig.md +32 -0
  60. package/docs/reference/interfaces/IUrlTransformerServiceConstructorOptions.md +25 -0
  61. package/docs/reference/variables/tagsHealth.md +5 -0
  62. package/locales/en.json +13 -1
  63. package/package.json +9 -5
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
+ Nothing.
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
+ Nothing.
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`
@@ -0,0 +1,131 @@
1
+ # Class: HostingService
2
+
3
+ The hosting service for the server.
4
+
5
+ ## Implements
6
+
7
+ - `IHostingComponent`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new HostingService**(`options`): `HostingService`
14
+
15
+ Create a new instance of HostingService.
16
+
17
+ #### Parameters
18
+
19
+ ##### options
20
+
21
+ [`IHostingServiceConstructorOptions`](../interfaces/IHostingServiceConstructorOptions.md)
22
+
23
+ The options to create the service.
24
+
25
+ #### Returns
26
+
27
+ `HostingService`
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
+ `IHostingComponent.className`
54
+
55
+ ***
56
+
57
+ ### getPublicOrigin() {#getpublicorigin}
58
+
59
+ > **getPublicOrigin**(`serverRequestUrl?`): `Promise`\<`string`\>
60
+
61
+ Get the public origin for the hosting.
62
+
63
+ #### Parameters
64
+
65
+ ##### serverRequestUrl?
66
+
67
+ `string`
68
+
69
+ The url of the current server request if there is one.
70
+
71
+ #### Returns
72
+
73
+ `Promise`\<`string`\>
74
+
75
+ The public origin.
76
+
77
+ #### Implementation of
78
+
79
+ `IHostingComponent.getPublicOrigin`
80
+
81
+ ***
82
+
83
+ ### getTenantOrigin() {#gettenantorigin}
84
+
85
+ > **getTenantOrigin**(`tenantId`): `Promise`\<`string` \| `undefined`\>
86
+
87
+ Get the public origin for the tenant if one exists.
88
+
89
+ #### Parameters
90
+
91
+ ##### tenantId
92
+
93
+ `string`
94
+
95
+ The tenant identifier.
96
+
97
+ #### Returns
98
+
99
+ `Promise`\<`string` \| `undefined`\>
100
+
101
+ The public origin for the tenant.
102
+
103
+ #### Implementation of
104
+
105
+ `IHostingComponent.getTenantOrigin`
106
+
107
+ ***
108
+
109
+ ### buildPublicUrl() {#buildpublicurl}
110
+
111
+ > **buildPublicUrl**(`url`): `Promise`\<`string`\>
112
+
113
+ Build a public url based on the public origin and the url provided.
114
+
115
+ #### Parameters
116
+
117
+ ##### url
118
+
119
+ `string`
120
+
121
+ The url to build upon the public origin.
122
+
123
+ #### Returns
124
+
125
+ `Promise`\<`string`\>
126
+
127
+ The full url based on the public origin.
128
+
129
+ #### Implementation of
130
+
131
+ `IHostingComponent.buildPublicUrl`
@@ -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
 
@@ -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,82 +144,36 @@ The OpenAPI spec.
144
144
 
145
145
  ***
146
146
 
147
- ### health()
147
+ ### livez() {#livez}
148
148
 
149
- > **health**(): `Promise`\<`IHealthInfo`\>
149
+ > **livez**(): `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
150
150
 
151
- Get the server health.
151
+ Is the server live.
152
152
 
153
153
  #### Returns
154
154
 
155
- `Promise`\<`IHealthInfo`\>
155
+ `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
156
156
 
157
- The service health.
157
+ True if the server is live.
158
158
 
159
159
  #### Implementation of
160
160
 
161
- `IInformationComponent.health`
161
+ `IInformationComponent.livez`
162
162
 
163
163
  ***
164
164
 
165
- ### setComponentHealth()
165
+ ### readyz() {#readyz}
166
166
 
167
- > **setComponentHealth**(`name`, `status`, `details?`): `Promise`\<`void`\>
167
+ > **readyz**(): `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
168
168
 
169
- Set the status of a component.
170
-
171
- #### Parameters
172
-
173
- ##### name
174
-
175
- `string`
176
-
177
- The component name.
178
-
179
- ##### status
180
-
181
- `HealthStatus`
182
-
183
- The status of the component.
184
-
185
- ##### details?
186
-
187
- `string`
188
-
189
- The details for the status.
169
+ Is the server ready.
190
170
 
191
171
  #### Returns
192
172
 
193
- `Promise`\<`void`\>
194
-
195
- Nothing.
196
-
197
- #### Implementation of
173
+ `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
198
174
 
199
- `IInformationComponent.setComponentHealth`
200
-
201
- ***
202
-
203
- ### removeComponentHealth()
204
-
205
- > **removeComponentHealth**(`name`): `Promise`\<`void`\>
206
-
207
- Remove the status of a component.
208
-
209
- #### Parameters
210
-
211
- ##### name
212
-
213
- `string`
214
-
215
- The component name.
216
-
217
- #### Returns
218
-
219
- `Promise`\<`void`\>
220
-
221
- Nothing.
175
+ The readyz status of the server.
222
176
 
223
177
  #### Implementation of
224
178
 
225
- `IInformationComponent.removeComponentHealth`
179
+ `IInformationComponent.readyz`