@twin.org/api-models 0.0.2-next.9 → 0.0.3-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/dist/es/factories/authenticationGeneratorFactory.js +9 -0
- package/dist/es/factories/authenticationGeneratorFactory.js.map +1 -0
- package/dist/es/factories/mimeTypeProcessorFactory.js +9 -0
- package/dist/es/factories/mimeTypeProcessorFactory.js.map +1 -0
- package/dist/es/factories/restRouteProcessorFactory.js +9 -0
- package/dist/es/factories/restRouteProcessorFactory.js.map +1 -0
- package/dist/es/factories/socketRouteProcessorFactory.js +9 -0
- package/dist/es/factories/socketRouteProcessorFactory.js.map +1 -0
- package/dist/es/helpers/httpErrorHelper.js +60 -0
- package/dist/es/helpers/httpErrorHelper.js.map +1 -0
- package/dist/es/helpers/httpParameterHelper.js +41 -0
- package/dist/es/helpers/httpParameterHelper.js.map +1 -0
- package/dist/es/index.js +59 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/api/IServerFavIconResponse.js +2 -0
- package/dist/es/models/api/IServerFavIconResponse.js.map +1 -0
- package/dist/es/models/api/IServerHealthResponse.js +2 -0
- package/dist/es/models/api/IServerHealthResponse.js.map +1 -0
- package/dist/es/models/api/IServerInfoResponse.js +2 -0
- package/dist/es/models/api/IServerInfoResponse.js.map +1 -0
- package/dist/es/models/api/IServerRootResponse.js +4 -0
- package/dist/es/models/api/IServerRootResponse.js.map +1 -0
- package/dist/es/models/api/IServerSpecResponse.js +2 -0
- package/dist/es/models/api/IServerSpecResponse.js.map +1 -0
- package/dist/es/models/client/IAuthenticationGenerator.js +2 -0
- package/dist/es/models/client/IAuthenticationGenerator.js.map +1 -0
- package/dist/es/models/config/IBaseRestClientConfig.js +2 -0
- package/dist/es/models/config/IBaseRestClientConfig.js.map +1 -0
- package/dist/es/models/config/IBaseSocketClientConfig.js +2 -0
- package/dist/es/models/config/IBaseSocketClientConfig.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequest.js +2 -0
- package/dist/es/models/protocol/IHttpRequest.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestContext.js +2 -0
- package/dist/es/models/protocol/IHttpRequestContext.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestPathParams.js +4 -0
- package/dist/es/models/protocol/IHttpRequestPathParams.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestQuery.js +4 -0
- package/dist/es/models/protocol/IHttpRequestQuery.js.map +1 -0
- package/dist/es/models/protocol/IHttpResponse.js +2 -0
- package/dist/es/models/protocol/IHttpResponse.js.map +1 -0
- package/dist/es/models/protocol/IHttpServerRequest.js +2 -0
- package/dist/es/models/protocol/IHttpServerRequest.js.map +1 -0
- package/dist/es/models/protocol/ISocketRequestContext.js +2 -0
- package/dist/es/models/protocol/ISocketRequestContext.js.map +1 -0
- package/dist/es/models/protocol/ISocketServerRequest.js +2 -0
- package/dist/es/models/protocol/ISocketServerRequest.js.map +1 -0
- package/dist/es/models/requests/INoContentRequest.js +2 -0
- package/dist/es/models/requests/INoContentRequest.js.map +1 -0
- package/dist/es/models/responses/errors/IBadRequestResponse.js +2 -0
- package/dist/es/models/responses/errors/IBadRequestResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IConflictResponse.js +2 -0
- package/dist/es/models/responses/errors/IConflictResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IForbiddenResponse.js +2 -0
- package/dist/es/models/responses/errors/IForbiddenResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IInternalServerErrorResponse.js +2 -0
- package/dist/es/models/responses/errors/IInternalServerErrorResponse.js.map +1 -0
- package/dist/es/models/responses/errors/INotFoundResponse.js +2 -0
- package/dist/es/models/responses/errors/INotFoundResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IUnauthorizedResponse.js +2 -0
- package/dist/es/models/responses/errors/IUnauthorizedResponse.js.map +1 -0
- package/dist/es/models/responses/errors/IUnprocessableEntityResponse.js +2 -0
- package/dist/es/models/responses/errors/IUnprocessableEntityResponse.js.map +1 -0
- package/dist/es/models/responses/success/IAcceptedResponse.js +2 -0
- package/dist/es/models/responses/success/IAcceptedResponse.js.map +1 -0
- package/dist/es/models/responses/success/ICreatedResponse.js +2 -0
- package/dist/es/models/responses/success/ICreatedResponse.js.map +1 -0
- package/dist/es/models/responses/success/INoContentResponse.js +2 -0
- package/dist/es/models/responses/success/INoContentResponse.js.map +1 -0
- package/dist/es/models/responses/success/IOkResponse.js +2 -0
- package/dist/es/models/responses/success/IOkResponse.js.map +1 -0
- package/dist/es/models/routes/IBaseRoute.js +4 -0
- package/dist/es/models/routes/IBaseRoute.js.map +1 -0
- package/dist/es/models/routes/IBaseRouteEntryPoint.js +2 -0
- package/dist/es/models/routes/IBaseRouteEntryPoint.js.map +1 -0
- package/dist/es/models/routes/IRestRoute.js +2 -0
- package/dist/es/models/routes/IRestRoute.js.map +1 -0
- package/dist/es/models/routes/IRestRouteEntryPoint.js +2 -0
- package/dist/es/models/routes/IRestRouteEntryPoint.js.map +1 -0
- package/dist/es/models/routes/IRestRouteExample.js +4 -0
- package/dist/es/models/routes/IRestRouteExample.js.map +1 -0
- package/dist/es/models/routes/IRestRouteRequestExample.js +2 -0
- package/dist/es/models/routes/IRestRouteRequestExample.js.map +1 -0
- package/dist/es/models/routes/IRestRouteResponseAttachmentOptions.js +4 -0
- package/dist/es/models/routes/IRestRouteResponseAttachmentOptions.js.map +1 -0
- package/dist/es/models/routes/IRestRouteResponseExample.js +2 -0
- package/dist/es/models/routes/IRestRouteResponseExample.js.map +1 -0
- package/dist/es/models/routes/IRestRouteResponseOptions.js +2 -0
- package/dist/es/models/routes/IRestRouteResponseOptions.js.map +1 -0
- package/dist/es/models/routes/ISocketRoute.js +2 -0
- package/dist/es/models/routes/ISocketRoute.js.map +1 -0
- package/dist/es/models/routes/ISocketRouteEntryPoint.js +2 -0
- package/dist/es/models/routes/ISocketRouteEntryPoint.js.map +1 -0
- package/dist/es/models/routes/ITag.js +4 -0
- package/dist/es/models/routes/ITag.js.map +1 -0
- package/dist/es/models/server/IBaseRouteProcessor.js +2 -0
- package/dist/es/models/server/IBaseRouteProcessor.js.map +1 -0
- package/dist/es/models/server/IMimeTypeProcessor.js +2 -0
- package/dist/es/models/server/IMimeTypeProcessor.js.map +1 -0
- package/dist/es/models/server/IRestRouteProcessor.js +2 -0
- package/dist/es/models/server/IRestRouteProcessor.js.map +1 -0
- package/dist/es/models/server/ISocketRouteProcessor.js +2 -0
- package/dist/es/models/server/ISocketRouteProcessor.js.map +1 -0
- package/dist/es/models/server/IWebServer.js +2 -0
- package/dist/es/models/server/IWebServer.js.map +1 -0
- package/dist/es/models/server/IWebServerOptions.js +2 -0
- package/dist/es/models/server/IWebServerOptions.js.map +1 -0
- package/dist/es/models/services/IHealthInfo.js +2 -0
- package/dist/es/models/services/IHealthInfo.js.map +1 -0
- package/dist/es/models/services/IInformationComponent.js +2 -0
- package/dist/es/models/services/IInformationComponent.js.map +1 -0
- package/dist/es/models/services/IServerInfo.js +4 -0
- package/dist/es/models/services/IServerInfo.js.map +1 -0
- package/dist/es/models/services/healthStatus.js +21 -0
- package/dist/es/models/services/healthStatus.js.map +1 -0
- package/dist/types/factories/authenticationGeneratorFactory.d.ts +6 -0
- package/dist/types/factories/mimeTypeProcessorFactory.d.ts +1 -1
- package/dist/types/factories/restRouteProcessorFactory.d.ts +1 -1
- package/dist/types/factories/socketRouteProcessorFactory.d.ts +1 -1
- package/dist/types/helpers/httpErrorHelper.d.ts +1 -1
- package/dist/types/index.d.ts +56 -55
- package/dist/types/models/api/IServerHealthResponse.d.ts +1 -1
- package/dist/types/models/api/IServerInfoResponse.d.ts +1 -1
- package/dist/types/models/client/IAuthenticationGenerator.d.ts +14 -0
- package/dist/types/models/protocol/IHttpRequest.d.ts +2 -2
- package/dist/types/models/protocol/IHttpRequestContext.d.ts +2 -3
- package/dist/types/models/protocol/IHttpServerRequest.d.ts +1 -1
- package/dist/types/models/protocol/ISocketRequestContext.d.ts +1 -1
- package/dist/types/models/protocol/ISocketServerRequest.d.ts +1 -1
- package/dist/types/models/requests/INoContentRequest.d.ts +1 -1
- package/dist/types/models/routes/IBaseRoute.d.ts +10 -0
- package/dist/types/models/routes/IBaseRouteEntryPoint.d.ts +1 -1
- package/dist/types/models/routes/IRestRoute.d.ts +7 -7
- package/dist/types/models/routes/IRestRouteEntryPoint.d.ts +2 -2
- package/dist/types/models/routes/IRestRouteRequestExample.d.ts +1 -1
- package/dist/types/models/routes/IRestRouteResponseExample.d.ts +1 -1
- package/dist/types/models/routes/IRestRouteResponseOptions.d.ts +1 -1
- package/dist/types/models/routes/ISocketRoute.d.ts +4 -4
- package/dist/types/models/routes/ISocketRouteEntryPoint.d.ts +2 -2
- package/dist/types/models/server/IBaseRouteProcessor.d.ts +15 -8
- package/dist/types/models/server/IRestRouteProcessor.d.ts +5 -7
- package/dist/types/models/server/ISocketRouteProcessor.d.ts +5 -7
- package/dist/types/models/server/IWebServer.d.ts +5 -5
- package/dist/types/models/services/IHealthInfo.d.ts +1 -1
- package/dist/types/models/services/IInformationComponent.d.ts +3 -3
- package/docs/changelog.md +47 -0
- package/docs/reference/classes/HttpParameterHelper.md +8 -8
- package/docs/reference/index.md +2 -1
- package/docs/reference/interfaces/IAuthenticationGenerator.md +35 -0
- package/docs/reference/interfaces/IBaseRoute.md +20 -0
- package/docs/reference/interfaces/IBaseRouteProcessor.md +26 -10
- package/docs/reference/interfaces/IHttpRequestContext.md +0 -28
- package/docs/reference/interfaces/IInformationComponent.md +2 -2
- package/docs/reference/interfaces/IRestRoute.md +28 -0
- package/docs/reference/interfaces/IRestRouteProcessor.md +32 -18
- package/docs/reference/interfaces/ISocketRequestContext.md +0 -24
- package/docs/reference/interfaces/ISocketRoute.md +28 -0
- package/docs/reference/interfaces/ISocketRouteProcessor.md +34 -20
- package/docs/reference/variables/AuthenticationGeneratorFactory.md +5 -0
- package/locales/en.json +1 -9
- package/package.json +23 -8
- package/dist/cjs/index.cjs +0 -154
- package/dist/esm/index.mjs +0 -147
- package/dist/types/models/protocol/IHttpRequestIdentity.d.ts +0 -13
- package/docs/reference/interfaces/IHttpRequestIdentity.md +0 -23
|
@@ -8,9 +8,29 @@ The definition for a processor for handling socket routes.
|
|
|
8
8
|
|
|
9
9
|
## Methods
|
|
10
10
|
|
|
11
|
+
### features()?
|
|
12
|
+
|
|
13
|
+
> `optional` **features**(): `string`[]
|
|
14
|
+
|
|
15
|
+
Features supported by this processor.
|
|
16
|
+
If a route has any of these features listed, this processor will be run for that route.
|
|
17
|
+
If this is not implemented, the processor will run for all routes.
|
|
18
|
+
|
|
19
|
+
#### Returns
|
|
20
|
+
|
|
21
|
+
`string`[]
|
|
22
|
+
|
|
23
|
+
The features supported by this processor.
|
|
24
|
+
|
|
25
|
+
#### Inherited from
|
|
26
|
+
|
|
27
|
+
[`IBaseRouteProcessor`](IBaseRouteProcessor.md).[`features`](IBaseRouteProcessor.md#features)
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
11
31
|
### pre()?
|
|
12
32
|
|
|
13
|
-
> `optional` **pre**(`request`, `response`, `route`, `
|
|
33
|
+
> `optional` **pre**(`request`, `response`, `route`, `contextIds`, `processorState`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
14
34
|
|
|
15
35
|
Pre process the REST request for the specified route.
|
|
16
36
|
|
|
@@ -32,13 +52,13 @@ The response data to send if any.
|
|
|
32
52
|
|
|
33
53
|
The route being requested, if a matching one was found.
|
|
34
54
|
|
|
35
|
-
|
|
55
|
+
[`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\> | `undefined`
|
|
36
56
|
|
|
37
|
-
#####
|
|
57
|
+
##### contextIds
|
|
38
58
|
|
|
39
|
-
|
|
59
|
+
`IContextIds`
|
|
40
60
|
|
|
41
|
-
The
|
|
61
|
+
The context IDs of the request.
|
|
42
62
|
|
|
43
63
|
##### processorState
|
|
44
64
|
|
|
@@ -64,7 +84,7 @@ Promise that resolves when the request is processed.
|
|
|
64
84
|
|
|
65
85
|
### post()?
|
|
66
86
|
|
|
67
|
-
> `optional` **post**(`request`, `response`, `route`, `
|
|
87
|
+
> `optional` **post**(`request`, `response`, `route`, `contextIds`, `processorState`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
68
88
|
|
|
69
89
|
Post process the REST request for the specified route.
|
|
70
90
|
|
|
@@ -86,13 +106,13 @@ The response data to send if any.
|
|
|
86
106
|
|
|
87
107
|
The route being requested, if a matching one was found.
|
|
88
108
|
|
|
89
|
-
|
|
109
|
+
[`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\> | `undefined`
|
|
90
110
|
|
|
91
|
-
#####
|
|
111
|
+
##### contextIds
|
|
92
112
|
|
|
93
|
-
|
|
113
|
+
`IContextIds`
|
|
94
114
|
|
|
95
|
-
The
|
|
115
|
+
The context IDs of the request.
|
|
96
116
|
|
|
97
117
|
##### processorState
|
|
98
118
|
|
|
@@ -134,7 +154,7 @@ The server request object containing the socket id and other parameters.
|
|
|
134
154
|
|
|
135
155
|
The route being requested, if a matching one was found.
|
|
136
156
|
|
|
137
|
-
|
|
157
|
+
[`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\> | `undefined`
|
|
138
158
|
|
|
139
159
|
##### loggingComponentType?
|
|
140
160
|
|
|
@@ -168,7 +188,7 @@ The server request object containing the socket id and other parameters.
|
|
|
168
188
|
|
|
169
189
|
The route being requested, if a matching one was found.
|
|
170
190
|
|
|
171
|
-
|
|
191
|
+
[`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\> | `undefined`
|
|
172
192
|
|
|
173
193
|
##### loggingComponentType?
|
|
174
194
|
|
|
@@ -186,7 +206,7 @@ Promise that resolves when the request is processed.
|
|
|
186
206
|
|
|
187
207
|
### process()?
|
|
188
208
|
|
|
189
|
-
> `optional` **process**(`request`, `response`, `route`, `
|
|
209
|
+
> `optional` **process**(`request`, `response`, `route`, `processorState`, `responseEmitter`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
190
210
|
|
|
191
211
|
Process the REST request for the specified route.
|
|
192
212
|
|
|
@@ -208,13 +228,7 @@ The response data to send if any.
|
|
|
208
228
|
|
|
209
229
|
The route being requested, if a matching one was found.
|
|
210
230
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
##### requestIdentity
|
|
214
|
-
|
|
215
|
-
[`IHttpRequestIdentity`](IHttpRequestIdentity.md)
|
|
216
|
-
|
|
217
|
-
The identity context for the request.
|
|
231
|
+
[`ISocketRoute`](ISocketRoute.md)\<`any`, `any`\> | `undefined`
|
|
218
232
|
|
|
219
233
|
##### processorState
|
|
220
234
|
|
package/locales/en.json
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"error": {
|
|
3
|
-
"baseRestClient": {
|
|
4
|
-
"missingRouteProp": "Missing route parameter in data \"{routeProp}\" for route \"{route}\"",
|
|
5
|
-
"decodingFailed": "Decoding JSON failed for route \"{route}\"",
|
|
6
|
-
"failureStatusText": "The request to the API failed: \"{statusText}\""
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
{}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-models",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next.1",
|
|
4
4
|
"description": "Contains models and classes for use with APIs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,25 +14,40 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@twin.org/context": "next",
|
|
17
18
|
"@twin.org/core": "next",
|
|
18
19
|
"@twin.org/nameof": "next",
|
|
19
20
|
"@twin.org/web": "next"
|
|
20
21
|
},
|
|
21
|
-
"main": "./dist/
|
|
22
|
-
"module": "./dist/esm/index.mjs",
|
|
22
|
+
"main": "./dist/es/index.js",
|
|
23
23
|
"types": "./dist/types/index.d.ts",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/types/index.d.ts",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"import": "./dist/es/index.js",
|
|
28
|
+
"default": "./dist/es/index.js"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
|
-
"dist/
|
|
33
|
-
"dist/esm",
|
|
32
|
+
"dist/es",
|
|
34
33
|
"dist/types",
|
|
35
34
|
"locales",
|
|
36
35
|
"docs"
|
|
37
|
-
]
|
|
36
|
+
],
|
|
37
|
+
"keywords": [
|
|
38
|
+
"twin",
|
|
39
|
+
"trade",
|
|
40
|
+
"iota",
|
|
41
|
+
"framework",
|
|
42
|
+
"blockchain",
|
|
43
|
+
"api",
|
|
44
|
+
"models",
|
|
45
|
+
"types",
|
|
46
|
+
"interfaces",
|
|
47
|
+
"schemas"
|
|
48
|
+
],
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "git+https://github.com/twinfoundation/api/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://twindev.org"
|
|
38
53
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@twin.org/core');
|
|
4
|
-
var web = require('@twin.org/web');
|
|
5
|
-
|
|
6
|
-
// Copyright 2024 IOTA Stiftung.
|
|
7
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
8
|
-
/**
|
|
9
|
-
* Factory for creating implementation of mime type processor types.
|
|
10
|
-
*/
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
-
const MimeTypeProcessorFactory = core.Factory.createFactory("mime-type-processor");
|
|
13
|
-
|
|
14
|
-
// Copyright 2024 IOTA Stiftung.
|
|
15
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
16
|
-
/**
|
|
17
|
-
* Factory for creating implementation of REST route processor types.
|
|
18
|
-
*/
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
20
|
-
const RestRouteProcessorFactory = core.Factory.createFactory("rest-route-processor");
|
|
21
|
-
|
|
22
|
-
// Copyright 2024 IOTA Stiftung.
|
|
23
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
24
|
-
/**
|
|
25
|
-
* Factory for creating implementation of socket route processor types.
|
|
26
|
-
*/
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
-
const SocketRouteProcessorFactory = core.Factory.createFactory("socket-route-processor");
|
|
29
|
-
|
|
30
|
-
// Copyright 2024 IOTA Stiftung.
|
|
31
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
32
|
-
/**
|
|
33
|
-
* Class to help with processing http errors.
|
|
34
|
-
*/
|
|
35
|
-
class HttpErrorHelper {
|
|
36
|
-
/**
|
|
37
|
-
* Process the errors from the routes.
|
|
38
|
-
* @param err The error to process.
|
|
39
|
-
* @param includeStack Should the stack be included in the error.
|
|
40
|
-
* @returns The status code and additional error data.
|
|
41
|
-
*/
|
|
42
|
-
static processError(err, includeStack) {
|
|
43
|
-
const error = core.BaseError.fromError(err);
|
|
44
|
-
// If the error or any of its sub errors are of the specific
|
|
45
|
-
// types then set the http response code accordingly
|
|
46
|
-
const flattened = core.BaseError.flatten(error);
|
|
47
|
-
let httpStatusCode = web.HttpStatusCode.internalServerError;
|
|
48
|
-
if (flattened.some(e => core.BaseError.isErrorName(e, core.GuardError.CLASS_NAME)) ||
|
|
49
|
-
flattened.some(e => core.BaseError.isErrorName(e, core.ValidationError.CLASS_NAME))) {
|
|
50
|
-
httpStatusCode = web.HttpStatusCode.badRequest;
|
|
51
|
-
}
|
|
52
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.ConflictError.CLASS_NAME)) ||
|
|
53
|
-
flattened.some(e => core.BaseError.isErrorName(e, core.AlreadyExistsError.CLASS_NAME))) {
|
|
54
|
-
httpStatusCode = web.HttpStatusCode.conflict;
|
|
55
|
-
}
|
|
56
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.NotFoundError.CLASS_NAME))) {
|
|
57
|
-
httpStatusCode = web.HttpStatusCode.notFound;
|
|
58
|
-
}
|
|
59
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.UnauthorizedError.CLASS_NAME))) {
|
|
60
|
-
httpStatusCode = web.HttpStatusCode.unauthorized;
|
|
61
|
-
}
|
|
62
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.NotImplementedError.CLASS_NAME))) {
|
|
63
|
-
httpStatusCode = web.HttpStatusCode.forbidden;
|
|
64
|
-
}
|
|
65
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.UnprocessableError.CLASS_NAME))) {
|
|
66
|
-
httpStatusCode = web.HttpStatusCode.unprocessableEntity;
|
|
67
|
-
}
|
|
68
|
-
const returnError = error.toJsonObject(includeStack);
|
|
69
|
-
return {
|
|
70
|
-
error: returnError,
|
|
71
|
-
httpStatusCode
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Build an error response.
|
|
76
|
-
* @param response The response to build the error into.
|
|
77
|
-
* @param error The error to build the response for.
|
|
78
|
-
* @param statusCode The status code to use for the error.
|
|
79
|
-
*/
|
|
80
|
-
static buildResponse(response, error, statusCode) {
|
|
81
|
-
response.headers ??= {};
|
|
82
|
-
response.headers[web.HeaderTypes.ContentType] = `${web.MimeTypes.Json}; charset=utf-8`;
|
|
83
|
-
response.body = error;
|
|
84
|
-
response.statusCode = statusCode;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Copyright 2024 IOTA Stiftung.
|
|
89
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
90
|
-
/**
|
|
91
|
-
* Class to help with handling http parameters.
|
|
92
|
-
*/
|
|
93
|
-
class HttpParameterHelper {
|
|
94
|
-
/**
|
|
95
|
-
* Convert list query to array.
|
|
96
|
-
* @param values The values query string.
|
|
97
|
-
* @returns The array of values.
|
|
98
|
-
*/
|
|
99
|
-
static arrayFromString(values) {
|
|
100
|
-
return values?.split(",");
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Convert array of values to query string.
|
|
104
|
-
* @param values The values to combine string.
|
|
105
|
-
* @returns The combined.
|
|
106
|
-
*/
|
|
107
|
-
static arrayToString(values) {
|
|
108
|
-
return values?.join(",");
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Convert object string to object.
|
|
112
|
-
* @param value The value query string.
|
|
113
|
-
* @returns The object.
|
|
114
|
-
*/
|
|
115
|
-
static objectFromString(value) {
|
|
116
|
-
return core.Is.json(value) ? JSON.parse(value) : undefined;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Convert object to query string.
|
|
120
|
-
* @param value The value to convert to a string.
|
|
121
|
-
* @returns The converted object.
|
|
122
|
-
*/
|
|
123
|
-
static objectToString(value) {
|
|
124
|
-
return core.Is.empty(value) ? undefined : JSON.stringify(value);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Copyright 2024 IOTA Stiftung.
|
|
129
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
130
|
-
/**
|
|
131
|
-
* The health status of the component.
|
|
132
|
-
*/
|
|
133
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
134
|
-
const HealthStatus = {
|
|
135
|
-
/**
|
|
136
|
-
* OK.
|
|
137
|
-
*/
|
|
138
|
-
Ok: "ok",
|
|
139
|
-
/**
|
|
140
|
-
* Warning.
|
|
141
|
-
*/
|
|
142
|
-
Warning: "warning",
|
|
143
|
-
/**
|
|
144
|
-
* Error.
|
|
145
|
-
*/
|
|
146
|
-
Error: "error"
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
exports.HealthStatus = HealthStatus;
|
|
150
|
-
exports.HttpErrorHelper = HttpErrorHelper;
|
|
151
|
-
exports.HttpParameterHelper = HttpParameterHelper;
|
|
152
|
-
exports.MimeTypeProcessorFactory = MimeTypeProcessorFactory;
|
|
153
|
-
exports.RestRouteProcessorFactory = RestRouteProcessorFactory;
|
|
154
|
-
exports.SocketRouteProcessorFactory = SocketRouteProcessorFactory;
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { Factory, BaseError, GuardError, ValidationError, ConflictError, AlreadyExistsError, NotFoundError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
|
|
2
|
-
import { HttpStatusCode, MimeTypes, HeaderTypes } from '@twin.org/web';
|
|
3
|
-
|
|
4
|
-
// Copyright 2024 IOTA Stiftung.
|
|
5
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
6
|
-
/**
|
|
7
|
-
* Factory for creating implementation of mime type processor types.
|
|
8
|
-
*/
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
-
const MimeTypeProcessorFactory = Factory.createFactory("mime-type-processor");
|
|
11
|
-
|
|
12
|
-
// Copyright 2024 IOTA Stiftung.
|
|
13
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
14
|
-
/**
|
|
15
|
-
* Factory for creating implementation of REST route processor types.
|
|
16
|
-
*/
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
|
-
const RestRouteProcessorFactory = Factory.createFactory("rest-route-processor");
|
|
19
|
-
|
|
20
|
-
// Copyright 2024 IOTA Stiftung.
|
|
21
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
22
|
-
/**
|
|
23
|
-
* Factory for creating implementation of socket route processor types.
|
|
24
|
-
*/
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
26
|
-
const SocketRouteProcessorFactory = Factory.createFactory("socket-route-processor");
|
|
27
|
-
|
|
28
|
-
// Copyright 2024 IOTA Stiftung.
|
|
29
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
30
|
-
/**
|
|
31
|
-
* Class to help with processing http errors.
|
|
32
|
-
*/
|
|
33
|
-
class HttpErrorHelper {
|
|
34
|
-
/**
|
|
35
|
-
* Process the errors from the routes.
|
|
36
|
-
* @param err The error to process.
|
|
37
|
-
* @param includeStack Should the stack be included in the error.
|
|
38
|
-
* @returns The status code and additional error data.
|
|
39
|
-
*/
|
|
40
|
-
static processError(err, includeStack) {
|
|
41
|
-
const error = BaseError.fromError(err);
|
|
42
|
-
// If the error or any of its sub errors are of the specific
|
|
43
|
-
// types then set the http response code accordingly
|
|
44
|
-
const flattened = BaseError.flatten(error);
|
|
45
|
-
let httpStatusCode = HttpStatusCode.internalServerError;
|
|
46
|
-
if (flattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME)) ||
|
|
47
|
-
flattened.some(e => BaseError.isErrorName(e, ValidationError.CLASS_NAME))) {
|
|
48
|
-
httpStatusCode = HttpStatusCode.badRequest;
|
|
49
|
-
}
|
|
50
|
-
else if (flattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME)) ||
|
|
51
|
-
flattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))) {
|
|
52
|
-
httpStatusCode = HttpStatusCode.conflict;
|
|
53
|
-
}
|
|
54
|
-
else if (flattened.some(e => BaseError.isErrorName(e, NotFoundError.CLASS_NAME))) {
|
|
55
|
-
httpStatusCode = HttpStatusCode.notFound;
|
|
56
|
-
}
|
|
57
|
-
else if (flattened.some(e => BaseError.isErrorName(e, UnauthorizedError.CLASS_NAME))) {
|
|
58
|
-
httpStatusCode = HttpStatusCode.unauthorized;
|
|
59
|
-
}
|
|
60
|
-
else if (flattened.some(e => BaseError.isErrorName(e, NotImplementedError.CLASS_NAME))) {
|
|
61
|
-
httpStatusCode = HttpStatusCode.forbidden;
|
|
62
|
-
}
|
|
63
|
-
else if (flattened.some(e => BaseError.isErrorName(e, UnprocessableError.CLASS_NAME))) {
|
|
64
|
-
httpStatusCode = HttpStatusCode.unprocessableEntity;
|
|
65
|
-
}
|
|
66
|
-
const returnError = error.toJsonObject(includeStack);
|
|
67
|
-
return {
|
|
68
|
-
error: returnError,
|
|
69
|
-
httpStatusCode
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Build an error response.
|
|
74
|
-
* @param response The response to build the error into.
|
|
75
|
-
* @param error The error to build the response for.
|
|
76
|
-
* @param statusCode The status code to use for the error.
|
|
77
|
-
*/
|
|
78
|
-
static buildResponse(response, error, statusCode) {
|
|
79
|
-
response.headers ??= {};
|
|
80
|
-
response.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;
|
|
81
|
-
response.body = error;
|
|
82
|
-
response.statusCode = statusCode;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Copyright 2024 IOTA Stiftung.
|
|
87
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
88
|
-
/**
|
|
89
|
-
* Class to help with handling http parameters.
|
|
90
|
-
*/
|
|
91
|
-
class HttpParameterHelper {
|
|
92
|
-
/**
|
|
93
|
-
* Convert list query to array.
|
|
94
|
-
* @param values The values query string.
|
|
95
|
-
* @returns The array of values.
|
|
96
|
-
*/
|
|
97
|
-
static arrayFromString(values) {
|
|
98
|
-
return values?.split(",");
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Convert array of values to query string.
|
|
102
|
-
* @param values The values to combine string.
|
|
103
|
-
* @returns The combined.
|
|
104
|
-
*/
|
|
105
|
-
static arrayToString(values) {
|
|
106
|
-
return values?.join(",");
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Convert object string to object.
|
|
110
|
-
* @param value The value query string.
|
|
111
|
-
* @returns The object.
|
|
112
|
-
*/
|
|
113
|
-
static objectFromString(value) {
|
|
114
|
-
return Is.json(value) ? JSON.parse(value) : undefined;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Convert object to query string.
|
|
118
|
-
* @param value The value to convert to a string.
|
|
119
|
-
* @returns The converted object.
|
|
120
|
-
*/
|
|
121
|
-
static objectToString(value) {
|
|
122
|
-
return Is.empty(value) ? undefined : JSON.stringify(value);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Copyright 2024 IOTA Stiftung.
|
|
127
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
128
|
-
/**
|
|
129
|
-
* The health status of the component.
|
|
130
|
-
*/
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
132
|
-
const HealthStatus = {
|
|
133
|
-
/**
|
|
134
|
-
* OK.
|
|
135
|
-
*/
|
|
136
|
-
Ok: "ok",
|
|
137
|
-
/**
|
|
138
|
-
* Warning.
|
|
139
|
-
*/
|
|
140
|
-
Warning: "warning",
|
|
141
|
-
/**
|
|
142
|
-
* Error.
|
|
143
|
-
*/
|
|
144
|
-
Error: "error"
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export { HealthStatus, HttpErrorHelper, HttpParameterHelper, MimeTypeProcessorFactory, RestRouteProcessorFactory, SocketRouteProcessorFactory };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context data from the HTTP request identity.
|
|
3
|
-
*/
|
|
4
|
-
export interface IHttpRequestIdentity {
|
|
5
|
-
/**
|
|
6
|
-
* The identity of the node the request is being performed on.
|
|
7
|
-
*/
|
|
8
|
-
nodeIdentity?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The identity of the requestor if there is an authenticated user.
|
|
11
|
-
*/
|
|
12
|
-
userIdentity?: string;
|
|
13
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Interface: IHttpRequestIdentity
|
|
2
|
-
|
|
3
|
-
Context data from the HTTP request identity.
|
|
4
|
-
|
|
5
|
-
## Extended by
|
|
6
|
-
|
|
7
|
-
- [`IHttpRequestContext`](IHttpRequestContext.md)
|
|
8
|
-
|
|
9
|
-
## Properties
|
|
10
|
-
|
|
11
|
-
### nodeIdentity?
|
|
12
|
-
|
|
13
|
-
> `optional` **nodeIdentity**: `string`
|
|
14
|
-
|
|
15
|
-
The identity of the node the request is being performed on.
|
|
16
|
-
|
|
17
|
-
***
|
|
18
|
-
|
|
19
|
-
### userIdentity?
|
|
20
|
-
|
|
21
|
-
> `optional` **userIdentity**: `string`
|
|
22
|
-
|
|
23
|
-
The identity of the requestor if there is an authenticated user.
|