@twin.org/api-models 0.0.3-next.2 → 0.0.3-next.21

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 (82) hide show
  1. package/README.md +1 -1
  2. package/dist/es/helpers/httpErrorHelper.js +28 -19
  3. package/dist/es/helpers/httpErrorHelper.js.map +1 -1
  4. package/dist/es/helpers/httpUrlHelper.js +92 -0
  5. package/dist/es/helpers/httpUrlHelper.js.map +1 -0
  6. package/dist/es/index.js +6 -2
  7. package/dist/es/index.js.map +1 -1
  8. package/dist/es/models/api/IServerLivezResponse.js +2 -0
  9. package/dist/es/models/api/IServerLivezResponse.js.map +1 -0
  10. package/dist/es/models/api/IServerRootResponse.js +0 -2
  11. package/dist/es/models/api/IServerRootResponse.js.map +1 -1
  12. package/dist/es/models/protocol/IHttpRequestContext.js.map +1 -1
  13. package/dist/es/models/protocol/IHttpRequestPathParams.js.map +1 -1
  14. package/dist/es/models/protocol/IHttpRequestQuery.js.map +1 -1
  15. package/dist/es/models/protocol/IHttpServerRequest.js.map +1 -1
  16. package/dist/es/models/routes/IBaseRoute.js.map +1 -1
  17. package/dist/es/models/server/IBaseRouteProcessor.js.map +1 -1
  18. package/dist/es/models/server/IRestRouteProcessor.js.map +1 -1
  19. package/dist/es/models/server/ISocketRouteProcessor.js.map +1 -1
  20. package/dist/es/models/services/IHealthComponentInfo.js +2 -0
  21. package/dist/es/models/services/IHealthComponentInfo.js.map +1 -0
  22. package/dist/es/models/services/IHealthInfo.js.map +1 -1
  23. package/dist/es/models/services/IHostingComponent.js +2 -0
  24. package/dist/es/models/services/IHostingComponent.js.map +1 -0
  25. package/dist/es/models/services/IInformationComponent.js.map +1 -1
  26. package/dist/es/models/services/ITenant.js +4 -0
  27. package/dist/es/models/services/ITenant.js.map +1 -0
  28. package/dist/es/models/services/ITenantAdminComponent.js +2 -0
  29. package/dist/es/models/services/ITenantAdminComponent.js.map +1 -0
  30. package/dist/types/helpers/httpErrorHelper.d.ts +6 -0
  31. package/dist/types/helpers/httpUrlHelper.d.ts +46 -0
  32. package/dist/types/index.d.ts +6 -2
  33. package/dist/types/models/api/IServerLivezResponse.d.ts +16 -0
  34. package/dist/types/models/api/IServerRootResponse.d.ts +7 -0
  35. package/dist/types/models/protocol/IHttpRequestContext.d.ts +4 -0
  36. package/dist/types/models/protocol/IHttpRequestPathParams.d.ts +1 -1
  37. package/dist/types/models/protocol/IHttpRequestQuery.d.ts +1 -1
  38. package/dist/types/models/protocol/IHttpServerRequest.d.ts +4 -4
  39. package/dist/types/models/routes/IBaseRoute.d.ts +9 -1
  40. package/dist/types/models/server/IBaseRouteProcessor.d.ts +14 -4
  41. package/dist/types/models/server/IRestRouteProcessor.d.ts +7 -2
  42. package/dist/types/models/services/IHealthComponentInfo.d.ts +18 -0
  43. package/dist/types/models/services/IHealthInfo.d.ts +2 -14
  44. package/dist/types/models/services/IHostingComponent.d.ts +24 -0
  45. package/dist/types/models/services/IInformationComponent.d.ts +9 -2
  46. package/dist/types/models/services/ITenant.d.ts +33 -0
  47. package/dist/types/models/services/ITenantAdminComponent.d.ts +63 -0
  48. package/docs/changelog.md +165 -1
  49. package/docs/examples.md +63 -1
  50. package/docs/reference/classes/HttpErrorHelper.md +12 -0
  51. package/docs/reference/classes/HttpUrlHelper.md +169 -0
  52. package/docs/reference/index.md +6 -2
  53. package/docs/reference/interfaces/IBaseRoute.md +17 -1
  54. package/docs/reference/interfaces/IBaseRouteProcessor.md +26 -6
  55. package/docs/reference/interfaces/IHealthComponentInfo.md +27 -0
  56. package/docs/reference/interfaces/IHealthInfo.md +1 -19
  57. package/docs/reference/interfaces/IHostingComponent.md +73 -0
  58. package/docs/reference/interfaces/IHttpRequestContext.md +8 -0
  59. package/docs/reference/interfaces/IHttpRequestPathParams.md +1 -1
  60. package/docs/reference/interfaces/IHttpRequestQuery.md +1 -1
  61. package/docs/reference/interfaces/IHttpServerRequest.md +6 -6
  62. package/docs/reference/interfaces/IInformationComponent.md +28 -2
  63. package/docs/reference/interfaces/IRestRoute.md +25 -1
  64. package/docs/reference/interfaces/IRestRouteProcessor.md +39 -9
  65. package/docs/reference/interfaces/IServerLivezResponse.md +23 -0
  66. package/docs/reference/interfaces/IServerRootResponse.md +12 -0
  67. package/docs/reference/interfaces/ISocketRequestContext.md +12 -0
  68. package/docs/reference/interfaces/ISocketRoute.md +25 -1
  69. package/docs/reference/interfaces/ISocketRouteProcessor.md +26 -6
  70. package/docs/reference/interfaces/ISocketServerRequest.md +8 -8
  71. package/docs/reference/interfaces/ITenant.md +59 -0
  72. package/docs/reference/interfaces/ITenantAdminComponent.md +193 -0
  73. package/docs/reference/interfaces/IWebServerOptions.md +0 -24
  74. package/package.json +2 -2
  75. package/dist/es/factories/authenticationGeneratorFactory.js +0 -9
  76. package/dist/es/factories/authenticationGeneratorFactory.js.map +0 -1
  77. package/dist/es/models/client/IAuthenticationGenerator.js +0 -2
  78. package/dist/es/models/client/IAuthenticationGenerator.js.map +0 -1
  79. package/dist/types/factories/authenticationGeneratorFactory.d.ts +0 -6
  80. package/dist/types/models/client/IAuthenticationGenerator.d.ts +0 -14
  81. package/docs/reference/interfaces/IAuthenticationGenerator.md +0 -35
  82. package/docs/reference/variables/AuthenticationGeneratorFactory.md +0 -5
@@ -4,6 +4,18 @@ The root text for the server.
4
4
 
5
5
  ## Properties
6
6
 
7
+ ### headers
8
+
9
+ > **headers**: `object`
10
+
11
+ The headers for the response.
12
+
13
+ #### content-type
14
+
15
+ > **content-type**: `"text/plain"`
16
+
17
+ ***
18
+
7
19
  ### body
8
20
 
9
21
  > **body**: `string`
@@ -48,6 +48,18 @@ Logging component type for the request.
48
48
 
49
49
  ***
50
50
 
51
+ ### hostingComponentType?
52
+
53
+ > `optional` **hostingComponentType**: `string`
54
+
55
+ Hosting component type for the request.
56
+
57
+ #### Inherited from
58
+
59
+ [`IHttpRequestContext`](IHttpRequestContext.md).[`hostingComponentType`](IHttpRequestContext.md#hostingcomponenttype)
60
+
61
+ ***
62
+
51
63
  ### socketId
52
64
 
53
65
  > **socketId**: `string`
@@ -46,7 +46,7 @@ The path to use for routing.
46
46
 
47
47
  > `optional` **skipAuth**: `boolean`
48
48
 
49
- Skips the authentication for this route.
49
+ Skips the authentication requirement for this route.
50
50
 
51
51
  #### Inherited from
52
52
 
@@ -54,6 +54,30 @@ Skips the authentication for this route.
54
54
 
55
55
  ***
56
56
 
57
+ ### skipTenant?
58
+
59
+ > `optional` **skipTenant**: `boolean`
60
+
61
+ Skips the tenant requirement for this route.
62
+
63
+ #### Inherited from
64
+
65
+ [`IBaseRoute`](IBaseRoute.md).[`skipTenant`](IBaseRoute.md#skiptenant)
66
+
67
+ ***
68
+
69
+ ### requiredScope?
70
+
71
+ > `optional` **requiredScope**: `string`[]
72
+
73
+ The user must have one of the specified scopes to access the route.
74
+
75
+ #### Inherited from
76
+
77
+ [`IBaseRoute`](IBaseRoute.md).[`requiredScope`](IBaseRoute.md#requiredscope)
78
+
79
+ ***
80
+
57
81
  ### processorFeatures?
58
82
 
59
83
  > `optional` **processorFeatures**: `string`[]
@@ -30,7 +30,7 @@ The features supported by this processor.
30
30
 
31
31
  ### pre()?
32
32
 
33
- > `optional` **pre**(`request`, `response`, `route`, `contextIds`, `processorState`, `loggingComponentType?`): `Promise`\<`void`\>
33
+ > `optional` **pre**(`request`, `response`, `route`, `contextIds`, `processorState`, `componentTypes?`): `Promise`\<`void`\>
34
34
 
35
35
  Pre process the REST request for the specified route.
36
36
 
@@ -64,11 +64,21 @@ The context IDs of the request.
64
64
 
65
65
  The state handed through the processors.
66
66
 
67
- ##### loggingComponentType?
67
+ ##### componentTypes?
68
+
69
+ The component types for the request.
70
+
71
+ ###### loggingComponentType?
68
72
 
69
73
  `string`
70
74
 
71
- The logging component type for the request.
75
+ The logging component type.
76
+
77
+ ###### hostingComponentType?
78
+
79
+ `string`
80
+
81
+ The hosting component type.
72
82
 
73
83
  #### Returns
74
84
 
@@ -84,7 +94,7 @@ Promise that resolves when the request is processed.
84
94
 
85
95
  ### post()?
86
96
 
87
- > `optional` **post**(`request`, `response`, `route`, `contextIds`, `processorState`, `loggingComponentType?`): `Promise`\<`void`\>
97
+ > `optional` **post**(`request`, `response`, `route`, `contextIds`, `processorState`, `componentTypes?`): `Promise`\<`void`\>
88
98
 
89
99
  Post process the REST request for the specified route.
90
100
 
@@ -118,11 +128,21 @@ The context IDs of the request.
118
128
 
119
129
  The state handed through the processors.
120
130
 
121
- ##### loggingComponentType?
131
+ ##### componentTypes?
132
+
133
+ The component types for the request.
134
+
135
+ ###### loggingComponentType?
122
136
 
123
137
  `string`
124
138
 
125
- The logging component type for the request.
139
+ The logging component type.
140
+
141
+ ###### hostingComponentType?
142
+
143
+ `string`
144
+
145
+ The hosting component type.
126
146
 
127
147
  #### Returns
128
148
 
@@ -62,27 +62,27 @@ Data to return send as the body.
62
62
 
63
63
  ***
64
64
 
65
- ### method?
65
+ ### url
66
66
 
67
- > `optional` **method**: `HttpMethod`
67
+ > **url**: `string`
68
68
 
69
- The request method.
69
+ The request url.
70
70
 
71
71
  #### Inherited from
72
72
 
73
- [`IHttpServerRequest`](IHttpServerRequest.md).[`method`](IHttpServerRequest.md#method)
73
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`url`](IHttpServerRequest.md#url)
74
74
 
75
75
  ***
76
76
 
77
- ### url?
77
+ ### method?
78
78
 
79
- > `optional` **url**: `string`
79
+ > `optional` **method**: `HttpMethod`
80
80
 
81
- The request url.
81
+ The request method.
82
82
 
83
83
  #### Inherited from
84
84
 
85
- [`IHttpServerRequest`](IHttpServerRequest.md).[`url`](IHttpServerRequest.md#url)
85
+ [`IHttpServerRequest`](IHttpServerRequest.md).[`method`](IHttpServerRequest.md#method)
86
86
 
87
87
  ***
88
88
 
@@ -0,0 +1,59 @@
1
+ # Interface: ITenant
2
+
3
+ Model defining the tenant.
4
+
5
+ ## Properties
6
+
7
+ ### id
8
+
9
+ > **id**: `string`
10
+
11
+ The unique identifier for the tenant.
12
+
13
+ ***
14
+
15
+ ### apiKey
16
+
17
+ > **apiKey**: `string`
18
+
19
+ The api key for the tenant.
20
+
21
+ ***
22
+
23
+ ### label
24
+
25
+ > **label**: `string`
26
+
27
+ The label of the tenant.
28
+
29
+ ***
30
+
31
+ ### dateCreated
32
+
33
+ > **dateCreated**: `string`
34
+
35
+ The date the tenant was created.
36
+
37
+ ***
38
+
39
+ ### dateModified
40
+
41
+ > **dateModified**: `string`
42
+
43
+ The date the tenant was modified.
44
+
45
+ ***
46
+
47
+ ### publicOrigin?
48
+
49
+ > `optional` **publicOrigin**: `string`
50
+
51
+ The public origin available to the public for accessing the API.
52
+
53
+ ***
54
+
55
+ ### isNodeTenant
56
+
57
+ > **isNodeTenant**: `boolean`
58
+
59
+ Indicates whether the tenant is the node tenant.
@@ -0,0 +1,193 @@
1
+ # Interface: ITenantAdminComponent
2
+
3
+ Configuration for the tenant admin component
4
+
5
+ ## Extends
6
+
7
+ - `IComponent`
8
+
9
+ ## Methods
10
+
11
+ ### create()
12
+
13
+ > **create**(`tenant`): `Promise`\<`string`\>
14
+
15
+ Create a tenant.
16
+
17
+ #### Parameters
18
+
19
+ ##### tenant
20
+
21
+ `Omit`\<[`ITenant`](ITenant.md), `"id"` \| `"dateCreated"` \| `"dateModified"`\> & `object`
22
+
23
+ The tenant to store.
24
+
25
+ #### Returns
26
+
27
+ `Promise`\<`string`\>
28
+
29
+ The tenant id.
30
+
31
+ ***
32
+
33
+ ### update()
34
+
35
+ > **update**(`tenant`): `Promise`\<`void`\>
36
+
37
+ Update a tenant.
38
+
39
+ #### Parameters
40
+
41
+ ##### tenant
42
+
43
+ `Partial`\<`Omit`\<[`ITenant`](ITenant.md), `"dateCreated"` \| `"dateModified"`\>\>
44
+
45
+ The tenant to update.
46
+
47
+ #### Returns
48
+
49
+ `Promise`\<`void`\>
50
+
51
+ Nothing.
52
+
53
+ ***
54
+
55
+ ### get()
56
+
57
+ > **get**(`tenantId`): `Promise`\<[`ITenant`](ITenant.md)\>
58
+
59
+ Get a tenant by its id.
60
+
61
+ #### Parameters
62
+
63
+ ##### tenantId
64
+
65
+ `string`
66
+
67
+ The id of the tenant.
68
+
69
+ #### Returns
70
+
71
+ `Promise`\<[`ITenant`](ITenant.md)\>
72
+
73
+ The tenant.
74
+
75
+ #### Throws
76
+
77
+ Error if the tenant is not found.
78
+
79
+ ***
80
+
81
+ ### getByApiKey()
82
+
83
+ > **getByApiKey**(`apiKey`): `Promise`\<[`ITenant`](ITenant.md)\>
84
+
85
+ Get a tenant by its api key.
86
+
87
+ #### Parameters
88
+
89
+ ##### apiKey
90
+
91
+ `string`
92
+
93
+ The api key of the tenant.
94
+
95
+ #### Returns
96
+
97
+ `Promise`\<[`ITenant`](ITenant.md)\>
98
+
99
+ The tenant.
100
+
101
+ #### Throws
102
+
103
+ Error if the tenant is not found.
104
+
105
+ ***
106
+
107
+ ### getByPublicOrigin()
108
+
109
+ > **getByPublicOrigin**(`publicOrigin`): `Promise`\<[`ITenant`](ITenant.md)\>
110
+
111
+ Get a tenant by its public origin.
112
+
113
+ #### Parameters
114
+
115
+ ##### publicOrigin
116
+
117
+ `string`
118
+
119
+ The origin of the tenant.
120
+
121
+ #### Returns
122
+
123
+ `Promise`\<[`ITenant`](ITenant.md)\>
124
+
125
+ The tenant.
126
+
127
+ #### Throws
128
+
129
+ Error if the tenant is not found.
130
+
131
+ ***
132
+
133
+ ### remove()
134
+
135
+ > **remove**(`tenantId`): `Promise`\<`void`\>
136
+
137
+ Remove a tenant by its id.
138
+
139
+ #### Parameters
140
+
141
+ ##### tenantId
142
+
143
+ `string`
144
+
145
+ The id of the tenant.
146
+
147
+ #### Returns
148
+
149
+ `Promise`\<`void`\>
150
+
151
+ Nothing.
152
+
153
+ #### Throws
154
+
155
+ Error if the tenant is not found.
156
+
157
+ ***
158
+
159
+ ### query()
160
+
161
+ > **query**(`options?`, `cursor?`, `limit?`): `Promise`\<\{ `tenants`: [`ITenant`](ITenant.md)[]; `cursor?`: `string`; \}\>
162
+
163
+ Query tenants with pagination.
164
+
165
+ #### Parameters
166
+
167
+ ##### options?
168
+
169
+ Optional query options.
170
+
171
+ ###### isNodeTenant?
172
+
173
+ `boolean`
174
+
175
+ Whether to filter for node admin tenants.
176
+
177
+ ##### cursor?
178
+
179
+ `string`
180
+
181
+ The cursor to start from.
182
+
183
+ ##### limit?
184
+
185
+ `number`
186
+
187
+ The maximum number of tenants to return.
188
+
189
+ #### Returns
190
+
191
+ `Promise`\<\{ `tenants`: [`ITenant`](ITenant.md)[]; `cursor?`: `string`; \}\>
192
+
193
+ The tenants and the next cursor if more tenants are available.
@@ -10,12 +10,6 @@ Options for the web server.
10
10
 
11
11
  The port to bind the web server to.
12
12
 
13
- #### Default
14
-
15
- ```ts
16
- 3000
17
- ```
18
-
19
13
  ***
20
14
 
21
15
  ### host?
@@ -24,12 +18,6 @@ The port to bind the web server to.
24
18
 
25
19
  The address to bind the web server to.
26
20
 
27
- #### Default
28
-
29
- ```ts
30
- localhost
31
- ```
32
-
33
21
  ***
34
22
 
35
23
  ### methods?
@@ -38,12 +26,6 @@ localhost
38
26
 
39
27
  The methods that the server accepts.
40
28
 
41
- #### Default
42
-
43
- ```ts
44
- ["GET", "PUT", "POST", "DELETE", "OPTIONS"]
45
- ```
46
-
47
29
  ***
48
30
 
49
31
  ### allowedHeaders?
@@ -67,9 +49,3 @@ And additional exposed headers.
67
49
  > `optional` **corsOrigins**: `string` \| `string`[]
68
50
 
69
51
  The allowed CORS domains.
70
-
71
- #### Default
72
-
73
- ```ts
74
- ["*"]
75
- ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/api-models",
3
- "version": "0.0.3-next.2",
4
- "description": "Contains models and classes for use with APIs",
3
+ "version": "0.0.3-next.21",
4
+ "description": "Shared API contracts, route types, and response models used across services and clients.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/api.git",
@@ -1,9 +0,0 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
- import { Factory } from "@twin.org/core";
4
- /**
5
- * Factory for creating implementation of authentication generator types.
6
- */
7
- // eslint-disable-next-line @typescript-eslint/naming-convention
8
- export const AuthenticationGeneratorFactory = Factory.createFactory("authentication-generator");
9
- //# sourceMappingURL=authenticationGeneratorFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authenticationGeneratorFactory.js","sourceRoot":"","sources":["../../../src/factories/authenticationGeneratorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,8BAA8B,GAAG,OAAO,CAAC,aAAa,CAClE,0BAA0B,CAC1B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@twin.org/core\";\nimport type { IAuthenticationGenerator } from \"../models/client/IAuthenticationGenerator.js\";\n\n/**\n * Factory for creating implementation of authentication generator types.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const AuthenticationGeneratorFactory = Factory.createFactory<IAuthenticationGenerator>(\n\t\"authentication-generator\"\n);\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IAuthenticationGenerator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IAuthenticationGenerator.js","sourceRoot":"","sources":["../../../../src/models/client/IAuthenticationGenerator.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\nimport type { IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * Definition for the authentication generator component.\n */\nexport interface IAuthenticationGenerator extends IComponent {\n\t/**\n\t * Adds authentication information to the request headers.\n\t * @param requestHeaders The request headers to add authentication information to.\n\t * @param authData Optional authentication data passed from the request.\n\t * @returns A promise that resolves when the authentication information has been added.\n\t */\n\taddAuthentication(requestHeaders: IHttpHeaders, authData?: unknown): Promise<void>;\n}\n"]}
@@ -1,6 +0,0 @@
1
- import { Factory } from "@twin.org/core";
2
- import type { IAuthenticationGenerator } from "../models/client/IAuthenticationGenerator.js";
3
- /**
4
- * Factory for creating implementation of authentication generator types.
5
- */
6
- export declare const AuthenticationGeneratorFactory: Factory<IAuthenticationGenerator>;
@@ -1,14 +0,0 @@
1
- import type { IComponent } from "@twin.org/core";
2
- import type { IHttpHeaders } from "@twin.org/web";
3
- /**
4
- * Definition for the authentication generator component.
5
- */
6
- export interface IAuthenticationGenerator extends IComponent {
7
- /**
8
- * Adds authentication information to the request headers.
9
- * @param requestHeaders The request headers to add authentication information to.
10
- * @param authData Optional authentication data passed from the request.
11
- * @returns A promise that resolves when the authentication information has been added.
12
- */
13
- addAuthentication(requestHeaders: IHttpHeaders, authData?: unknown): Promise<void>;
14
- }
@@ -1,35 +0,0 @@
1
- # Interface: IAuthenticationGenerator
2
-
3
- Definition for the authentication generator component.
4
-
5
- ## Extends
6
-
7
- - `IComponent`
8
-
9
- ## Methods
10
-
11
- ### addAuthentication()
12
-
13
- > **addAuthentication**(`requestHeaders`, `authData?`): `Promise`\<`void`\>
14
-
15
- Adds authentication information to the request headers.
16
-
17
- #### Parameters
18
-
19
- ##### requestHeaders
20
-
21
- `IHttpHeaders`
22
-
23
- The request headers to add authentication information to.
24
-
25
- ##### authData?
26
-
27
- `unknown`
28
-
29
- Optional authentication data passed from the request.
30
-
31
- #### Returns
32
-
33
- `Promise`\<`void`\>
34
-
35
- A promise that resolves when the authentication information has been added.
@@ -1,5 +0,0 @@
1
- # Variable: AuthenticationGeneratorFactory
2
-
3
- > `const` **AuthenticationGeneratorFactory**: `Factory`\<[`IAuthenticationGenerator`](../interfaces/IAuthenticationGenerator.md)\>
4
-
5
- Factory for creating implementation of authentication generator types.