@twin.org/api-models 0.0.1-next.32 → 0.0.1-next.34
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/cjs/index.cjs +4 -5
- package/dist/esm/index.mjs +5 -6
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/HttpErrorHelper.md +4 -4
- package/docs/reference/classes/HttpParameterHelper.md +19 -11
- package/docs/reference/interfaces/IBaseRouteEntryPoint.md +3 -1
- package/docs/reference/interfaces/IBaseRouteProcessor.md +3 -1
- package/docs/reference/interfaces/IHttpRequest.md +3 -1
- package/docs/reference/interfaces/IHttpResponse.md +3 -1
- package/docs/reference/interfaces/IHttpServerRequest.md +3 -1
- package/docs/reference/interfaces/IInformationComponent.md +1 -1
- package/docs/reference/interfaces/IRestRoute.md +6 -2
- package/docs/reference/interfaces/IRestRouteRequestExample.md +3 -1
- package/docs/reference/interfaces/IRestRouteResponseExample.md +3 -1
- package/docs/reference/interfaces/ISocketRoute.md +6 -2
- package/docs/reference/interfaces/IWebServer.md +4 -2
- package/docs/reference/type-aliases/HealthStatus.md +1 -1
- package/docs/reference/type-aliases/IRestRouteEntryPoint.md +1 -1
- package/docs/reference/type-aliases/ISocketRouteEntryPoint.md +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -45,18 +45,17 @@ class HttpErrorHelper {
|
|
|
45
45
|
// types then set the http response code accordingly
|
|
46
46
|
const flattened = core.BaseError.flatten(error);
|
|
47
47
|
let httpStatusCode = web.HttpStatusCode.internalServerError;
|
|
48
|
-
if (flattened.some(e => core.BaseError.isErrorName(e, core.GuardError.CLASS_NAME))
|
|
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))) {
|
|
49
50
|
httpStatusCode = web.HttpStatusCode.badRequest;
|
|
50
51
|
}
|
|
51
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.ConflictError.CLASS_NAME))
|
|
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))) {
|
|
52
54
|
httpStatusCode = web.HttpStatusCode.conflict;
|
|
53
55
|
}
|
|
54
56
|
else if (flattened.some(e => core.BaseError.isErrorName(e, core.NotFoundError.CLASS_NAME))) {
|
|
55
57
|
httpStatusCode = web.HttpStatusCode.notFound;
|
|
56
58
|
}
|
|
57
|
-
else if (flattened.some(e => core.BaseError.isErrorName(e, core.AlreadyExistsError.CLASS_NAME))) {
|
|
58
|
-
httpStatusCode = web.HttpStatusCode.conflict;
|
|
59
|
-
}
|
|
60
59
|
else if (flattened.some(e => core.BaseError.isErrorName(e, core.UnauthorizedError.CLASS_NAME))) {
|
|
61
60
|
httpStatusCode = web.HttpStatusCode.unauthorized;
|
|
62
61
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Factory, BaseError, GuardError,
|
|
1
|
+
import { Factory, BaseError, GuardError, ValidationError, ConflictError, AlreadyExistsError, NotFoundError, UnauthorizedError, NotImplementedError, UnprocessableError, Is } from '@twin.org/core';
|
|
2
2
|
import { HttpStatusCode, MimeTypes, HeaderTypes } from '@twin.org/web';
|
|
3
3
|
|
|
4
4
|
// Copyright 2024 IOTA Stiftung.
|
|
@@ -43,18 +43,17 @@ class HttpErrorHelper {
|
|
|
43
43
|
// types then set the http response code accordingly
|
|
44
44
|
const flattened = BaseError.flatten(error);
|
|
45
45
|
let httpStatusCode = HttpStatusCode.internalServerError;
|
|
46
|
-
if (flattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME))
|
|
46
|
+
if (flattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME)) ||
|
|
47
|
+
flattened.some(e => BaseError.isErrorName(e, ValidationError.CLASS_NAME))) {
|
|
47
48
|
httpStatusCode = HttpStatusCode.badRequest;
|
|
48
49
|
}
|
|
49
|
-
else if (flattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME))
|
|
50
|
+
else if (flattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME)) ||
|
|
51
|
+
flattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))) {
|
|
50
52
|
httpStatusCode = HttpStatusCode.conflict;
|
|
51
53
|
}
|
|
52
54
|
else if (flattened.some(e => BaseError.isErrorName(e, NotFoundError.CLASS_NAME))) {
|
|
53
55
|
httpStatusCode = HttpStatusCode.notFound;
|
|
54
56
|
}
|
|
55
|
-
else if (flattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))) {
|
|
56
|
-
httpStatusCode = HttpStatusCode.conflict;
|
|
57
|
-
}
|
|
58
57
|
else if (flattened.some(e => BaseError.isErrorName(e, UnauthorizedError.CLASS_NAME))) {
|
|
59
58
|
httpStatusCode = HttpStatusCode.unauthorized;
|
|
60
59
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @twin.org/api-models - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.1-next.34](https://github.com/twinfoundation/api/compare/api-models-v0.0.1-next.33...api-models-v0.0.1-next.34) (2025-05-27)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* validationError mapped to http status badrequest ([adc5eb1](https://github.com/twinfoundation/api/commit/adc5eb11d987abb0ab9f7e0dc8e1fdae207e436e))
|
|
9
|
+
|
|
10
|
+
## [0.0.1-next.33](https://github.com/twinfoundation/api/compare/api-models-v0.0.1-next.32...api-models-v0.0.1-next.33) (2025-04-17)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* use shared store mechanism ([#19](https://github.com/twinfoundation/api/issues/19)) ([32116df](https://github.com/twinfoundation/api/commit/32116df3b4380a30137f5056f242a5c99afa2df9))
|
|
16
|
+
|
|
3
17
|
## [0.0.1-next.32](https://github.com/twinfoundation/api/compare/api-models-v0.0.1-next.31...api-models-v0.0.1-next.32) (2025-03-28)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -4,19 +4,19 @@ Class to help with processing http errors.
|
|
|
4
4
|
|
|
5
5
|
## Constructors
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Constructor
|
|
8
8
|
|
|
9
|
-
> **new HttpErrorHelper**():
|
|
9
|
+
> **new HttpErrorHelper**(): `HttpErrorHelper`
|
|
10
10
|
|
|
11
11
|
#### Returns
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`HttpErrorHelper`
|
|
14
14
|
|
|
15
15
|
## Methods
|
|
16
16
|
|
|
17
17
|
### processError()
|
|
18
18
|
|
|
19
|
-
> `static` **processError**(`err`, `includeStack
|
|
19
|
+
> `static` **processError**(`err`, `includeStack?`): `object`
|
|
20
20
|
|
|
21
21
|
Process the errors from the routes.
|
|
22
22
|
|
|
@@ -4,25 +4,27 @@ Class to help with handling http parameters.
|
|
|
4
4
|
|
|
5
5
|
## Constructors
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### Constructor
|
|
8
8
|
|
|
9
|
-
> **new HttpParameterHelper**():
|
|
9
|
+
> **new HttpParameterHelper**(): `HttpParameterHelper`
|
|
10
10
|
|
|
11
11
|
#### Returns
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`HttpParameterHelper`
|
|
14
14
|
|
|
15
15
|
## Methods
|
|
16
16
|
|
|
17
17
|
### arrayFromString()
|
|
18
18
|
|
|
19
|
-
> `static` **arrayFromString**\<`T`\>(`values
|
|
19
|
+
> `static` **arrayFromString**\<`T`\>(`values?`): `undefined` \| `T`[]
|
|
20
20
|
|
|
21
21
|
Convert list query to array.
|
|
22
22
|
|
|
23
23
|
#### Type Parameters
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
##### T
|
|
26
|
+
|
|
27
|
+
`T` = `string`
|
|
26
28
|
|
|
27
29
|
#### Parameters
|
|
28
30
|
|
|
@@ -42,13 +44,15 @@ The array of values.
|
|
|
42
44
|
|
|
43
45
|
### arrayToString()
|
|
44
46
|
|
|
45
|
-
> `static` **arrayToString**\<`T`\>(`values
|
|
47
|
+
> `static` **arrayToString**\<`T`\>(`values?`): `undefined` \| `string`
|
|
46
48
|
|
|
47
49
|
Convert array of values to query string.
|
|
48
50
|
|
|
49
51
|
#### Type Parameters
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
##### T
|
|
54
|
+
|
|
55
|
+
`T` = `string`
|
|
52
56
|
|
|
53
57
|
#### Parameters
|
|
54
58
|
|
|
@@ -68,13 +72,15 @@ The combined.
|
|
|
68
72
|
|
|
69
73
|
### objectFromString()
|
|
70
74
|
|
|
71
|
-
> `static` **objectFromString**\<`T`\>(`value
|
|
75
|
+
> `static` **objectFromString**\<`T`\>(`value?`): `undefined` \| `T`
|
|
72
76
|
|
|
73
77
|
Convert object string to object.
|
|
74
78
|
|
|
75
79
|
#### Type Parameters
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
##### T
|
|
82
|
+
|
|
83
|
+
`T` = `unknown`
|
|
78
84
|
|
|
79
85
|
#### Parameters
|
|
80
86
|
|
|
@@ -94,13 +100,15 @@ The object.
|
|
|
94
100
|
|
|
95
101
|
### objectToString()
|
|
96
102
|
|
|
97
|
-
> `static` **objectToString**\<`T`\>(`value
|
|
103
|
+
> `static` **objectToString**\<`T`\>(`value?`): `undefined` \| `string`
|
|
98
104
|
|
|
99
105
|
Convert object to query string.
|
|
100
106
|
|
|
101
107
|
#### Type Parameters
|
|
102
108
|
|
|
103
|
-
|
|
109
|
+
##### T
|
|
110
|
+
|
|
111
|
+
`T` = `unknown`
|
|
104
112
|
|
|
105
113
|
#### Parameters
|
|
106
114
|
|
|
@@ -8,9 +8,13 @@ Interface which defines a REST route.
|
|
|
8
8
|
|
|
9
9
|
## Type Parameters
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### T
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`T` *extends* [`IHttpRequest`](IHttpRequest.md) = `any`
|
|
14
|
+
|
|
15
|
+
### U
|
|
16
|
+
|
|
17
|
+
`U` *extends* [`IHttpResponse`](IHttpResponse.md) & [`IRestRouteResponseOptions`](IRestRouteResponseOptions.md) = `any`
|
|
14
18
|
|
|
15
19
|
## Properties
|
|
16
20
|
|
|
@@ -8,9 +8,13 @@ Interface which defines a socket route.
|
|
|
8
8
|
|
|
9
9
|
## Type Parameters
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### T
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
`T` *extends* [`IHttpRequest`](IHttpRequest.md) = `any`
|
|
14
|
+
|
|
15
|
+
### U
|
|
16
|
+
|
|
17
|
+
`U` *extends* [`IHttpResponse`](IHttpResponse.md) = `any`
|
|
14
18
|
|
|
15
19
|
## Properties
|
|
16
20
|
|
|
@@ -4,7 +4,9 @@ Interface describing a web server.
|
|
|
4
4
|
|
|
5
5
|
## Type Parameters
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### T
|
|
8
|
+
|
|
9
|
+
`T`
|
|
8
10
|
|
|
9
11
|
## Methods
|
|
10
12
|
|
|
@@ -24,7 +26,7 @@ The web server instance.
|
|
|
24
26
|
|
|
25
27
|
### build()
|
|
26
28
|
|
|
27
|
-
> **build**(`restRouteProcessors
|
|
29
|
+
> **build**(`restRouteProcessors?`, `restRoutes?`, `socketRouteProcessors?`, `socketRoutes?`, `options?`): `Promise`\<`void`\>
|
|
28
30
|
|
|
29
31
|
Build the server.
|
|
30
32
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Type Alias: HealthStatus
|
|
2
2
|
|
|
3
|
-
> **HealthStatus
|
|
3
|
+
> **HealthStatus** = *typeof* [`HealthStatus`](../variables/HealthStatus.md)\[keyof *typeof* [`HealthStatus`](../variables/HealthStatus.md)\]
|
|
4
4
|
|
|
5
5
|
The health status of the component.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Type Alias: IRestRouteEntryPoint
|
|
2
2
|
|
|
3
|
-
> **IRestRouteEntryPoint
|
|
3
|
+
> **IRestRouteEntryPoint** = [`IBaseRouteEntryPoint`](../interfaces/IBaseRouteEntryPoint.md)\<[`IRestRoute`](../interfaces/IRestRoute.md)\>
|
|
4
4
|
|
|
5
5
|
Route entry points are used for exposing the REST routes from a package.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Type Alias: ISocketRouteEntryPoint
|
|
2
2
|
|
|
3
|
-
> **ISocketRouteEntryPoint
|
|
3
|
+
> **ISocketRouteEntryPoint** = [`IBaseRouteEntryPoint`](../interfaces/IBaseRouteEntryPoint.md)\<[`ISocketRoute`](../interfaces/ISocketRoute.md)\>
|
|
4
4
|
|
|
5
5
|
Route entry points are used for exposing the socket routes from a package.
|