@twin.org/api-rest-client 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.
package/docs/examples.md CHANGED
@@ -1 +1,64 @@
1
- # @twin.org/api-rest-client - Examples
1
+ # Rest Client Examples
2
+
3
+ Use these snippets to call health, metadata, and specification endpoints from operational tools and integration tests.
4
+
5
+ ## InformationRestClient
6
+
7
+ ```typescript
8
+ import { InformationRestClient } from '@twin.org/api-rest-client';
9
+
10
+ const client = new InformationRestClient({
11
+ endpoint: 'https://api.example.org',
12
+ pathPrefix: 'v1'
13
+ });
14
+
15
+ console.log(client.className()); // InformationRestClient
16
+
17
+ const root = await client.root();
18
+ const info = await client.info();
19
+ const icon = await client.favicon();
20
+
21
+ console.log(root); // twin-api - 1.2.0
22
+ console.log(info.version); // 1.2.0
23
+ console.log((icon?.byteLength ?? 0) > 0); // true
24
+ ```
25
+
26
+ ```typescript
27
+ import { InformationRestClient } from '@twin.org/api-rest-client';
28
+
29
+ const client = new InformationRestClient({
30
+ endpoint: 'https://api.example.org',
31
+ pathPrefix: 'v1'
32
+ });
33
+
34
+ const openApi = await client.spec();
35
+ const live = await client.livez();
36
+ const health = await client.health();
37
+
38
+ console.log(typeof openApi); // object
39
+ console.log(live); // true
40
+ console.log(health.status); // ok
41
+ ```
42
+
43
+ ```typescript
44
+ import { InformationRestClient } from '@twin.org/api-rest-client';
45
+
46
+ const client = new InformationRestClient({
47
+ endpoint: 'https://api.example.org',
48
+ pathPrefix: 'v1'
49
+ });
50
+
51
+ try {
52
+ await client.setComponentHealth('database', 'ok');
53
+ } catch (err) {
54
+ const errorName = err instanceof Error ? err.name : 'Error';
55
+ console.log(errorName); // NotSupportedError
56
+ }
57
+
58
+ try {
59
+ await client.removeComponentHealth('database');
60
+ } catch (err) {
61
+ const errorName = err instanceof Error ? err.name : 'Error';
62
+ console.log(errorName); // NotSupportedError
63
+ }
64
+ ```
@@ -0,0 +1,145 @@
1
+ # Class: HealthRestClient
2
+
3
+ The client to connect to the health service.
4
+
5
+ ## Extends
6
+
7
+ - `BaseRestClient`
8
+
9
+ ## Implements
10
+
11
+ - `IHealthComponent`
12
+
13
+ ## Constructors
14
+
15
+ ### Constructor
16
+
17
+ > **new HealthRestClient**(`config`): `HealthRestClient`
18
+
19
+ Create a new instance of HealthRestClient.
20
+
21
+ #### Parameters
22
+
23
+ ##### config
24
+
25
+ `IBaseRestClientConfig`
26
+
27
+ The configuration for the client.
28
+
29
+ #### Returns
30
+
31
+ `HealthRestClient`
32
+
33
+ #### Overrides
34
+
35
+ `BaseRestClient.constructor`
36
+
37
+ ## Properties
38
+
39
+ ### CLASS\_NAME {#class_name}
40
+
41
+ > `readonly` `static` **CLASS\_NAME**: `string`
42
+
43
+ Runtime name for the class.
44
+
45
+ ## Methods
46
+
47
+ ### getEndpointWithPrefix() {#getendpointwithprefix}
48
+
49
+ > **getEndpointWithPrefix**(): `string`
50
+
51
+ Get the endpoint with the prefix for the namespace.
52
+
53
+ #### Returns
54
+
55
+ `string`
56
+
57
+ The endpoint with namespace prefix attached.
58
+
59
+ #### Inherited from
60
+
61
+ `BaseRestClient.getEndpointWithPrefix`
62
+
63
+ ***
64
+
65
+ ### fetch() {#fetch}
66
+
67
+ > **fetch**\<`T`, `U`\>(`route`, `method`, `request?`): `Promise`\<`U`\>
68
+
69
+ Perform a request in json format.
70
+
71
+ #### Type Parameters
72
+
73
+ ##### T
74
+
75
+ `T` *extends* `IHttpRequest`\<`any`\>
76
+
77
+ ##### U
78
+
79
+ `U` *extends* `IHttpResponse`\<`any`\>
80
+
81
+ #### Parameters
82
+
83
+ ##### route
84
+
85
+ `string`
86
+
87
+ The route of the request.
88
+
89
+ ##### method
90
+
91
+ `HttpMethod`
92
+
93
+ The http method.
94
+
95
+ ##### request?
96
+
97
+ `T`
98
+
99
+ Request to send to the endpoint.
100
+
101
+ #### Returns
102
+
103
+ `Promise`\<`U`\>
104
+
105
+ The response.
106
+
107
+ #### Inherited from
108
+
109
+ `BaseRestClient.fetch`
110
+
111
+ ***
112
+
113
+ ### className() {#classname}
114
+
115
+ > **className**(): `string`
116
+
117
+ Returns the class name of the component.
118
+
119
+ #### Returns
120
+
121
+ `string`
122
+
123
+ The class name of the component.
124
+
125
+ #### Implementation of
126
+
127
+ `IHealthComponent.className`
128
+
129
+ ***
130
+
131
+ ### healthStatus() {#healthstatus}
132
+
133
+ > **healthStatus**(): `Promise`\<\{ `status`: `HealthStatus`; `components`: `IHealth`[]; \}\>
134
+
135
+ Get the server health.
136
+
137
+ #### Returns
138
+
139
+ `Promise`\<\{ `status`: `HealthStatus`; `components`: `IHealth`[]; \}\>
140
+
141
+ The service health.
142
+
143
+ #### Implementation of
144
+
145
+ `IHealthComponent.healthStatus`
@@ -36,7 +36,7 @@ The configuration for the client.
36
36
 
37
37
  ## Properties
38
38
 
39
- ### CLASS\_NAME
39
+ ### CLASS\_NAME {#class_name}
40
40
 
41
41
  > `readonly` `static` **CLASS\_NAME**: `string`
42
42
 
@@ -44,190 +44,192 @@ Runtime name for the class.
44
44
 
45
45
  ## Methods
46
46
 
47
- ### className()
47
+ ### getEndpointWithPrefix() {#getendpointwithprefix}
48
48
 
49
- > **className**(): `string`
49
+ > **getEndpointWithPrefix**(): `string`
50
50
 
51
- Returns the class name of the component.
51
+ Get the endpoint with the prefix for the namespace.
52
52
 
53
53
  #### Returns
54
54
 
55
55
  `string`
56
56
 
57
- The class name of the component.
57
+ The endpoint with namespace prefix attached.
58
58
 
59
- #### Implementation of
59
+ #### Inherited from
60
60
 
61
- `IInformationComponent.className`
61
+ `BaseRestClient.getEndpointWithPrefix`
62
62
 
63
63
  ***
64
64
 
65
- ### root()
65
+ ### fetch() {#fetch}
66
66
 
67
- > **root**(): `Promise`\<`string`\>
67
+ > **fetch**\<`T`, `U`\>(`route`, `method`, `request?`): `Promise`\<`U`\>
68
68
 
69
- Get the server root.
69
+ Perform a request in json format.
70
70
 
71
- #### Returns
71
+ #### Type Parameters
72
72
 
73
- `Promise`\<`string`\>
73
+ ##### T
74
74
 
75
- The root root.
75
+ `T` *extends* `IHttpRequest`\<`any`\>
76
76
 
77
- #### Implementation of
77
+ ##### U
78
78
 
79
- `IInformationComponent.root`
79
+ `U` *extends* `IHttpResponse`\<`any`\>
80
80
 
81
- ***
81
+ #### Parameters
82
82
 
83
- ### info()
83
+ ##### route
84
84
 
85
- > **info**(): `Promise`\<`IServerInfo`\>
85
+ `string`
86
86
 
87
- Get the server information.
87
+ The route of the request.
88
+
89
+ ##### method
90
+
91
+ `HttpMethod`
92
+
93
+ The http method.
94
+
95
+ ##### request?
96
+
97
+ `T`
98
+
99
+ Request to send to the endpoint.
88
100
 
89
101
  #### Returns
90
102
 
91
- `Promise`\<`IServerInfo`\>
103
+ `Promise`\<`U`\>
92
104
 
93
- The service information.
105
+ The response.
94
106
 
95
- #### Implementation of
107
+ #### Inherited from
96
108
 
97
- `IInformationComponent.info`
109
+ `BaseRestClient.fetch`
98
110
 
99
111
  ***
100
112
 
101
- ### favicon()
113
+ ### className() {#classname}
102
114
 
103
- > **favicon**(): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
115
+ > **className**(): `string`
104
116
 
105
- Get the favicon.
117
+ Returns the class name of the component.
106
118
 
107
119
  #### Returns
108
120
 
109
- `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
121
+ `string`
110
122
 
111
- The favicon.
123
+ The class name of the component.
112
124
 
113
125
  #### Implementation of
114
126
 
115
- `IInformationComponent.favicon`
127
+ `IInformationComponent.className`
116
128
 
117
129
  ***
118
130
 
119
- ### spec()
131
+ ### root() {#root}
120
132
 
121
- > **spec**(): `Promise`\<`unknown`\>
133
+ > **root**(): `Promise`\<`string`\>
122
134
 
123
- Get the OpenAPI spec.
135
+ Get the server root.
124
136
 
125
137
  #### Returns
126
138
 
127
- `Promise`\<`unknown`\>
139
+ `Promise`\<`string`\>
128
140
 
129
- The OpenAPI spec.
141
+ The root text page content.
130
142
 
131
143
  #### Implementation of
132
144
 
133
- `IInformationComponent.spec`
145
+ `IInformationComponent.root`
134
146
 
135
147
  ***
136
148
 
137
- ### livez()
149
+ ### info() {#info}
138
150
 
139
- > **livez**(): `Promise`\<`boolean`\>
151
+ > **info**(): `Promise`\<`IServerInfo`\>
140
152
 
141
- Is the server live.
153
+ Get the server information.
142
154
 
143
155
  #### Returns
144
156
 
145
- `Promise`\<`boolean`\>
157
+ `Promise`\<`IServerInfo`\>
146
158
 
147
- True if the server is live.
159
+ The service information.
148
160
 
149
161
  #### Implementation of
150
162
 
151
- `IInformationComponent.livez`
163
+ `IInformationComponent.info`
152
164
 
153
165
  ***
154
166
 
155
- ### health()
167
+ ### favicon() {#favicon}
156
168
 
157
- > **health**(): `Promise`\<`IHealthInfo`\>
169
+ > **favicon**(): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
158
170
 
159
- Get the server health.
171
+ Get the favicon.
160
172
 
161
173
  #### Returns
162
174
 
163
- `Promise`\<`IHealthInfo`\>
175
+ `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
164
176
 
165
- The service health.
177
+ The favicon.
166
178
 
167
179
  #### Implementation of
168
180
 
169
- `IInformationComponent.health`
181
+ `IInformationComponent.favicon`
170
182
 
171
183
  ***
172
184
 
173
- ### setComponentHealth()
174
-
175
- > **setComponentHealth**(`name`, `status`, `details?`): `Promise`\<`void`\>
185
+ ### spec() {#spec}
176
186
 
177
- Set the status of a component.
187
+ > **spec**(): `Promise`\<`unknown`\>
178
188
 
179
- #### Parameters
189
+ Get the OpenAPI spec.
180
190
 
181
- ##### name
191
+ #### Returns
182
192
 
183
- `string`
193
+ `Promise`\<`unknown`\>
184
194
 
185
- The component name.
195
+ The OpenAPI spec.
186
196
 
187
- ##### status
197
+ #### Implementation of
188
198
 
189
- `HealthStatus`
199
+ `IInformationComponent.spec`
190
200
 
191
- The status of the component.
201
+ ***
192
202
 
193
- ##### details?
203
+ ### livez() {#livez}
194
204
 
195
- `string`
205
+ > **livez**(): `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
196
206
 
197
- The details for the status.
207
+ Is the server live.
198
208
 
199
209
  #### Returns
200
210
 
201
- `Promise`\<`void`\>
211
+ `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
202
212
 
203
- Nothing.
213
+ The liveness status of the server.
204
214
 
205
215
  #### Implementation of
206
216
 
207
- `IInformationComponent.setComponentHealth`
217
+ `IInformationComponent.livez`
208
218
 
209
219
  ***
210
220
 
211
- ### removeComponentHealth()
212
-
213
- > **removeComponentHealth**(`name`): `Promise`\<`void`\>
214
-
215
- Remove the status of a component.
221
+ ### readyz() {#readyz}
216
222
 
217
- #### Parameters
218
-
219
- ##### name
220
-
221
- `string`
223
+ > **readyz**(): `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
222
224
 
223
- The component name.
225
+ Is the server ready.
224
226
 
225
227
  #### Returns
226
228
 
227
- `Promise`\<`void`\>
229
+ `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
228
230
 
229
- Nothing.
231
+ The readiness status of the server.
230
232
 
231
233
  #### Implementation of
232
234
 
233
- `IInformationComponent.removeComponentHealth`
235
+ `IInformationComponent.readyz`
@@ -2,4 +2,5 @@
2
2
 
3
3
  ## Classes
4
4
 
5
+ - [HealthRestClient](classes/HealthRestClient.md)
5
6
  - [InformationRestClient](classes/InformationRestClient.md)
package/locales/en.json CHANGED
@@ -1,7 +1 @@
1
- {
2
- "error": {
3
- "informationRestClient": {
4
- "notSupportedOnClient": "The method \"{methodName}\" is not supported on the REST client, it can only be used on a server side component"
5
- }
6
- }
7
- }
1
+ {}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/api-rest-client",
3
- "version": "0.0.3-next.9",
4
- "description": "Information contract implementation which can connect to REST endpoints",
3
+ "version": "0.9.0-next.1",
4
+ "description": "REST client implementation for consuming information and hosting endpoints.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/api.git",
7
+ "url": "git+https://github.com/iotaledger/twin-api.git",
8
8
  "directory": "packages/api-rest-client"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -14,11 +14,11 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-core": "0.0.3-next.9",
18
- "@twin.org/api-models": "0.0.3-next.9",
19
- "@twin.org/core": "next",
20
- "@twin.org/nameof": "next",
21
- "@twin.org/web": "next"
17
+ "@twin.org/api-core": "0.9.0-next.1",
18
+ "@twin.org/api-models": "0.9.0-next.1",
19
+ "@twin.org/core": "0.9.0-next.1",
20
+ "@twin.org/nameof": "0.9.0-next.1",
21
+ "@twin.org/web": "0.9.0-next.1"
22
22
  },
23
23
  "main": "./dist/es/index.js",
24
24
  "types": "./dist/types/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "api"
45
45
  ],
46
46
  "bugs": {
47
- "url": "git+https://github.com/twinfoundation/api/issues"
47
+ "url": "git+https://github.com/iotaledger/twin-api/issues"
48
48
  },
49
49
  "homepage": "https://twindev.org"
50
50
  }