@twin.org/api-models 0.0.3-next.3 → 0.0.3-next.31
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/README.md +1 -1
- package/dist/es/errors/forbiddenError.js +23 -0
- package/dist/es/errors/forbiddenError.js.map +1 -0
- package/dist/es/errors/tooManyRequestsError.js +25 -0
- package/dist/es/errors/tooManyRequestsError.js.map +1 -0
- package/dist/es/helpers/httpErrorHelper.js +34 -20
- package/dist/es/helpers/httpErrorHelper.js.map +1 -1
- package/dist/es/helpers/httpUrlHelper.js +105 -0
- package/dist/es/helpers/httpUrlHelper.js.map +1 -0
- package/dist/es/index.js +13 -4
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/api/IServerHealthResponse.js.map +1 -1
- package/dist/es/models/api/IServerLivezResponse.js +2 -0
- package/dist/es/models/api/IServerLivezResponse.js.map +1 -0
- package/dist/es/models/api/IServerReadyzResponse.js +2 -0
- package/dist/es/models/api/IServerReadyzResponse.js.map +1 -0
- package/dist/es/models/api/IServerRootResponse.js +0 -2
- package/dist/es/models/api/IServerRootResponse.js.map +1 -1
- package/dist/es/models/config/IBaseRestClientConfig.js.map +1 -1
- package/dist/es/models/httpContextIdKeys.js +21 -0
- package/dist/es/models/httpContextIdKeys.js.map +1 -0
- package/dist/es/models/protocol/IHttpRequestContext.js.map +1 -1
- package/dist/es/models/protocol/IHttpRequestPathParams.js.map +1 -1
- package/dist/es/models/protocol/IHttpRequestQuery.js.map +1 -1
- package/dist/es/models/protocol/IHttpServerRequest.js.map +1 -1
- package/dist/es/models/responses/errors/IConflictResponse.js.map +1 -1
- package/dist/es/models/responses/errors/INotImplementedResponse.js +2 -0
- package/dist/es/models/responses/errors/INotImplementedResponse.js.map +1 -0
- package/dist/es/models/responses/errors/ITooManyRequestsResponse.js +2 -0
- package/dist/es/models/responses/errors/ITooManyRequestsResponse.js.map +1 -0
- package/dist/es/models/routes/IBaseRoute.js.map +1 -1
- package/dist/es/models/server/IBaseRouteProcessor.js.map +1 -1
- package/dist/es/models/server/IRestRouteProcessor.js.map +1 -1
- package/dist/es/models/server/ISocketRouteProcessor.js.map +1 -1
- package/dist/es/models/server/IWebServer.js.map +1 -1
- package/dist/es/models/services/IHealthComponent.js +2 -0
- package/dist/es/models/services/IHealthComponent.js.map +1 -0
- package/dist/es/models/services/IHostingComponent.js +2 -0
- package/dist/es/models/services/IHostingComponent.js.map +1 -0
- package/dist/es/models/services/IInformationComponent.js.map +1 -1
- package/dist/es/models/services/ITenant.js +4 -0
- package/dist/es/models/services/ITenant.js.map +1 -0
- package/dist/es/models/services/ITenantAdminComponent.js +2 -0
- package/dist/es/models/services/ITenantAdminComponent.js.map +1 -0
- package/dist/es/models/services/IUrlTransformerComponent.js +2 -0
- package/dist/es/models/services/IUrlTransformerComponent.js.map +1 -0
- package/dist/types/errors/forbiddenError.d.ts +20 -0
- package/dist/types/errors/tooManyRequestsError.d.ts +22 -0
- package/dist/types/helpers/httpErrorHelper.d.ts +6 -0
- package/dist/types/helpers/httpUrlHelper.d.ts +55 -0
- package/dist/types/index.d.ts +13 -4
- package/dist/types/models/api/IServerHealthResponse.d.ts +6 -3
- package/dist/types/models/api/IServerLivezResponse.d.ts +16 -0
- package/dist/types/models/api/IServerReadyzResponse.d.ts +16 -0
- package/dist/types/models/api/IServerRootResponse.d.ts +7 -0
- package/dist/types/models/config/IBaseRestClientConfig.d.ts +16 -0
- package/dist/types/models/httpContextIdKeys.d.ts +21 -0
- package/dist/types/models/protocol/IHttpRequestContext.d.ts +4 -0
- package/dist/types/models/protocol/IHttpRequestPathParams.d.ts +1 -1
- package/dist/types/models/protocol/IHttpRequestQuery.d.ts +1 -1
- package/dist/types/models/protocol/IHttpServerRequest.d.ts +4 -4
- package/dist/types/models/responses/errors/IConflictResponse.d.ts +1 -6
- package/dist/types/models/responses/errors/INotImplementedResponse.d.ts +15 -0
- package/dist/types/models/responses/errors/ITooManyRequestsResponse.d.ts +15 -0
- package/dist/types/models/routes/IBaseRoute.d.ts +9 -1
- package/dist/types/models/server/IBaseRouteProcessor.d.ts +14 -4
- package/dist/types/models/server/IRestRouteProcessor.d.ts +7 -2
- package/dist/types/models/server/IWebServer.d.ts +7 -1
- package/dist/types/models/services/IHealthComponent.d.ts +14 -0
- package/dist/types/models/services/IHostingComponent.d.ts +24 -0
- package/dist/types/models/services/IInformationComponent.d.ts +10 -17
- package/dist/types/models/services/ITenant.d.ts +33 -0
- package/dist/types/models/services/ITenantAdminComponent.d.ts +63 -0
- package/dist/types/models/services/IUrlTransformerComponent.d.ts +66 -0
- package/docs/changelog.md +285 -58
- package/docs/examples.md +200 -1
- package/docs/reference/classes/ForbiddenError.md +55 -0
- package/docs/reference/classes/HttpErrorHelper.md +14 -2
- package/docs/reference/classes/HttpParameterHelper.md +4 -4
- package/docs/reference/classes/HttpUrlHelper.md +197 -0
- package/docs/reference/classes/TooManyRequestsError.md +67 -0
- package/docs/reference/index.md +14 -5
- package/docs/reference/interfaces/IAcceptedResponse.md +2 -2
- package/docs/reference/interfaces/IBadRequestResponse.md +2 -2
- package/docs/reference/interfaces/IBaseRestClientConfig.md +57 -9
- package/docs/reference/interfaces/IBaseRoute.md +25 -9
- package/docs/reference/interfaces/IBaseRouteEntryPoint.md +4 -4
- package/docs/reference/interfaces/IBaseRouteProcessor.md +33 -13
- package/docs/reference/interfaces/IBaseSocketClientConfig.md +7 -7
- package/docs/reference/interfaces/IConflictResponse.md +3 -11
- package/docs/reference/interfaces/ICreatedResponse.md +2 -2
- package/docs/reference/interfaces/IForbiddenResponse.md +2 -2
- package/docs/reference/interfaces/IHealthComponent.md +21 -0
- package/docs/reference/interfaces/IHostingComponent.md +73 -0
- package/docs/reference/interfaces/IHttpRequest.md +8 -8
- package/docs/reference/interfaces/IHttpRequestContext.md +12 -4
- package/docs/reference/interfaces/IHttpRequestPathParams.md +1 -1
- package/docs/reference/interfaces/IHttpRequestQuery.md +1 -1
- package/docs/reference/interfaces/IHttpResponse.md +6 -6
- package/docs/reference/interfaces/IHttpServerRequest.md +14 -14
- package/docs/reference/interfaces/IInformationComponent.md +14 -56
- package/docs/reference/interfaces/IInternalServerErrorResponse.md +2 -2
- package/docs/reference/interfaces/IMimeTypeProcessor.md +2 -2
- package/docs/reference/interfaces/INoContentRequest.md +8 -8
- package/docs/reference/interfaces/INoContentResponse.md +1 -1
- package/docs/reference/interfaces/INotFoundResponse.md +3 -3
- package/docs/reference/interfaces/INotImplementedResponse.md +19 -0
- package/docs/reference/interfaces/IOkResponse.md +1 -1
- package/docs/reference/interfaces/IRestRoute.md +47 -23
- package/docs/reference/interfaces/IRestRouteExample.md +3 -3
- package/docs/reference/interfaces/IRestRouteProcessor.md +49 -19
- package/docs/reference/interfaces/IRestRouteRequestExample.md +4 -4
- package/docs/reference/interfaces/IRestRouteResponseAttachmentOptions.md +6 -6
- package/docs/reference/interfaces/IRestRouteResponseExample.md +4 -4
- package/docs/reference/interfaces/IRestRouteResponseOptions.md +2 -2
- package/docs/reference/interfaces/IServerFavIconResponse.md +7 -7
- package/docs/reference/interfaces/IServerHealthResponse.md +11 -3
- package/docs/reference/interfaces/IServerInfo.md +2 -2
- package/docs/reference/interfaces/IServerInfoResponse.md +1 -1
- package/docs/reference/interfaces/IServerLivezResponse.md +23 -0
- package/docs/reference/interfaces/IServerReadyzResponse.md +23 -0
- package/docs/reference/interfaces/IServerRootResponse.md +13 -1
- package/docs/reference/interfaces/IServerSpecResponse.md +4 -4
- package/docs/reference/interfaces/ISocketRequestContext.md +17 -5
- package/docs/reference/interfaces/ISocketRoute.md +38 -14
- package/docs/reference/interfaces/ISocketRouteProcessor.md +42 -22
- package/docs/reference/interfaces/ISocketServerRequest.md +17 -17
- package/docs/reference/interfaces/ITag.md +2 -2
- package/docs/reference/interfaces/ITenant.md +59 -0
- package/docs/reference/interfaces/ITenantAdminComponent.md +193 -0
- package/docs/reference/interfaces/ITooManyRequestsResponse.md +19 -0
- package/docs/reference/interfaces/IUnauthorizedResponse.md +2 -2
- package/docs/reference/interfaces/IUnprocessableEntityResponse.md +2 -2
- package/docs/reference/interfaces/IUrlTransformerComponent.md +229 -0
- package/docs/reference/interfaces/IWebServer.md +34 -4
- package/docs/reference/interfaces/IWebServerOptions.md +12 -12
- package/docs/reference/type-aliases/HttpContextIdKeys.md +5 -0
- package/docs/reference/variables/HttpContextIdKeys.md +25 -0
- package/package.json +2 -2
- package/dist/es/factories/authenticationGeneratorFactory.js +0 -9
- package/dist/es/factories/authenticationGeneratorFactory.js.map +0 -1
- package/dist/es/models/client/IAuthenticationGenerator.js +0 -2
- package/dist/es/models/client/IAuthenticationGenerator.js.map +0 -1
- package/dist/es/models/services/IHealthInfo.js +0 -2
- package/dist/es/models/services/IHealthInfo.js.map +0 -1
- package/dist/es/models/services/healthStatus.js +0 -21
- package/dist/es/models/services/healthStatus.js.map +0 -1
- package/dist/types/factories/authenticationGeneratorFactory.d.ts +0 -6
- package/dist/types/models/client/IAuthenticationGenerator.d.ts +0 -14
- package/dist/types/models/services/IHealthInfo.d.ts +0 -27
- package/dist/types/models/services/healthStatus.d.ts +0 -21
- package/docs/reference/interfaces/IAuthenticationGenerator.md +0 -35
- package/docs/reference/interfaces/IHealthInfo.md +0 -37
- package/docs/reference/type-aliases/HealthStatus.md +0 -5
- package/docs/reference/variables/AuthenticationGeneratorFactory.md +0 -5
- package/docs/reference/variables/HealthStatus.md +0 -25
package/docs/examples.md
CHANGED
|
@@ -1 +1,200 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Models Examples
|
|
2
|
+
|
|
3
|
+
These snippets show practical helpers for URL manipulation, request parameter conversion, consistent error responses, and secure parameter encryption.
|
|
4
|
+
|
|
5
|
+
## HttpUrlHelper
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { HttpUrlHelper } from '@twin.org/api-models';
|
|
9
|
+
|
|
10
|
+
const fullUrl = 'https://tenant.example.org/orders?page=2';
|
|
11
|
+
|
|
12
|
+
console.log(HttpUrlHelper.extractOrigin(fullUrl)); // https://tenant.example.org
|
|
13
|
+
console.log(HttpUrlHelper.extractPath(fullUrl)); // /orders
|
|
14
|
+
console.log(HttpUrlHelper.extractSearch(fullUrl)); // ?page=2
|
|
15
|
+
console.log(HttpUrlHelper.extractPathAndSearch(fullUrl)); // /orders?page=2
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { HttpUrlHelper } from '@twin.org/api-models';
|
|
20
|
+
|
|
21
|
+
const combined = HttpUrlHelper.combineParts('https://tenant.example.org/', '/api/v1/orders');
|
|
22
|
+
const replaced = HttpUrlHelper.replaceOrigin(combined ?? '', 'https://edge.example.org');
|
|
23
|
+
|
|
24
|
+
console.log(combined); // https://tenant.example.org/api/v1/orders
|
|
25
|
+
console.log(replaced); // https://edge.example.org/api/v1/orders
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## HttpParameterHelper
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { HttpParameterHelper } from '@twin.org/api-models';
|
|
32
|
+
|
|
33
|
+
const ids = HttpParameterHelper.arrayFromString('id-1,id-2,id-3');
|
|
34
|
+
const idsAsString = HttpParameterHelper.arrayToString(ids);
|
|
35
|
+
|
|
36
|
+
const filterObject = HttpParameterHelper.objectFromString('{"status":"active"}');
|
|
37
|
+
const filterString = HttpParameterHelper.objectToString(filterObject);
|
|
38
|
+
|
|
39
|
+
console.log(ids.length); // 3
|
|
40
|
+
console.log(idsAsString); // id-1,id-2,id-3
|
|
41
|
+
console.log(filterString); // {"status":"active"}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## HttpErrorHelper
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { HttpErrorHelper } from '@twin.org/api-models';
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
throw new Error('Invalid request');
|
|
51
|
+
} catch (err) {
|
|
52
|
+
const mapped = HttpErrorHelper.processError(err, false);
|
|
53
|
+
const response: {
|
|
54
|
+
body?: unknown;
|
|
55
|
+
statusCode?: number;
|
|
56
|
+
headers?: { [id: string]: string };
|
|
57
|
+
} = {};
|
|
58
|
+
HttpErrorHelper.buildResponse(response, mapped.error, mapped.httpStatusCode);
|
|
59
|
+
|
|
60
|
+
console.log(response.statusCode); // 500
|
|
61
|
+
console.log(mapped.error.message); // Error: Invalid request
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## IHostingComponent
|
|
66
|
+
|
|
67
|
+
When working with the hosting component, you can encrypt and decrypt query parameters for secure transmission. The encryption mechanism automatically handles salt generation to prevent rainbow table attacks.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import type { IComponent, IHttpRequestQuery } from '@twin.org/api-models';
|
|
71
|
+
import { ComponentFactory } from '@twin.org/core';
|
|
72
|
+
|
|
73
|
+
interface IHostingComponent extends IComponent {
|
|
74
|
+
addEncryptedParamsToUrl(url: string, params: IHttpRequestQuery): Promise<string>;
|
|
75
|
+
getDecryptedParamsFromQueryParams(
|
|
76
|
+
queryParams: IHttpRequestQuery | undefined,
|
|
77
|
+
keys: string[]
|
|
78
|
+
): Promise<IHttpRequestQuery>;
|
|
79
|
+
encryptParam(paramValue: string): Promise<string>;
|
|
80
|
+
decryptParam(encryptedValue: string): Promise<string>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Get the hosting component from the component factory
|
|
84
|
+
const hosting = ComponentFactory.get<IHostingComponent>('hosting');
|
|
85
|
+
|
|
86
|
+
// Encrypt parameters and add them to a URL
|
|
87
|
+
const baseUrl = 'https://api.example.com/callback';
|
|
88
|
+
const encrypted = await hosting.addEncryptedParamsToUrl(baseUrl, {
|
|
89
|
+
token: 'secret-token-123',
|
|
90
|
+
userId: 'user-456'
|
|
91
|
+
});
|
|
92
|
+
console.log(encrypted); // https://api.example.com/callback?x-enc-token=...&x-enc-userId=...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import type { IHttpRequestQuery } from '@twin.org/api-models';
|
|
97
|
+
import { ComponentFactory } from '@twin.org/core';
|
|
98
|
+
|
|
99
|
+
interface IHostingComponent {
|
|
100
|
+
addEncryptedParamsToUrl(url: string, params: IHttpRequestQuery): Promise<string>;
|
|
101
|
+
getDecryptedParamsFromQueryParams(
|
|
102
|
+
queryParams: IHttpRequestQuery | undefined,
|
|
103
|
+
keys: string[]
|
|
104
|
+
): Promise<IHttpRequestQuery>;
|
|
105
|
+
encryptQueryParams(
|
|
106
|
+
httpRequestQuery: IHttpRequestQuery | undefined,
|
|
107
|
+
keys: string[]
|
|
108
|
+
): Promise<void>;
|
|
109
|
+
decryptQueryParams(
|
|
110
|
+
httpRequestQuery: IHttpRequestQuery | undefined,
|
|
111
|
+
keys: string[]
|
|
112
|
+
): Promise<void>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const hosting = ComponentFactory.get<IHostingComponent>('hosting');
|
|
116
|
+
|
|
117
|
+
// Decrypt specific parameters from a query object
|
|
118
|
+
const queryParams: IHttpRequestQuery = {
|
|
119
|
+
'x-enc-token': 'CngBAgMEBQYH...',
|
|
120
|
+
'x-enc-userId': 'CxgICSoLDAwN...',
|
|
121
|
+
status: 'active'
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const decrypted = await hosting.getDecryptedParamsFromQueryParams(queryParams, ['token', 'userId']);
|
|
125
|
+
console.log(decrypted); // { token: 'secret-token-123', userId: 'user-456' }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import type { IHttpRequestQuery } from '@twin.org/api-models';
|
|
130
|
+
import { ComponentFactory } from '@twin.org/core';
|
|
131
|
+
|
|
132
|
+
interface IHostingComponent {
|
|
133
|
+
addTenantTokenToUrl(url: string, tenantId: string): Promise<string>;
|
|
134
|
+
getTenantTokenFromQueryParams(
|
|
135
|
+
queryParams: IHttpRequestQuery | undefined
|
|
136
|
+
): Promise<string | undefined>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const hosting = ComponentFactory.get<IHostingComponent>('hosting');
|
|
140
|
+
|
|
141
|
+
// Add encrypted tenant token to a URL
|
|
142
|
+
const redirectUrl = 'https://tenant.example.com/dashboard';
|
|
143
|
+
const urlWithTenant = await hosting.addTenantTokenToUrl(
|
|
144
|
+
redirectUrl,
|
|
145
|
+
'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'
|
|
146
|
+
);
|
|
147
|
+
console.log(urlWithTenant); // https://tenant.example.com/dashboard?x-enc-tenant-token=...
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import type { IHttpRequestQuery } from '@twin.org/api-models';
|
|
152
|
+
import { ComponentFactory } from '@twin.org/core';
|
|
153
|
+
|
|
154
|
+
interface IHostingComponent {
|
|
155
|
+
encryptQueryParams(
|
|
156
|
+
httpRequestQuery: IHttpRequestQuery | undefined,
|
|
157
|
+
keys: string[]
|
|
158
|
+
): Promise<void>;
|
|
159
|
+
decryptQueryParams(
|
|
160
|
+
httpRequestQuery: IHttpRequestQuery | undefined,
|
|
161
|
+
keys: string[]
|
|
162
|
+
): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const hosting = ComponentFactory.get<IHostingComponent>('hosting');
|
|
166
|
+
|
|
167
|
+
// Encrypt specific query parameters in place
|
|
168
|
+
const query: IHttpRequestQuery = {
|
|
169
|
+
token: 'secret-123',
|
|
170
|
+
apiKey: 'key-456',
|
|
171
|
+
status: 'active'
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
await hosting.encryptQueryParams(query, ['token', 'apiKey']);
|
|
175
|
+
console.log(query); // { 'x-enc-token': '...', 'x-enc-apiKey': '...', status: 'active' }
|
|
176
|
+
|
|
177
|
+
// Decrypt the parameters back to their original keys
|
|
178
|
+
await hosting.decryptQueryParams(query, ['token', 'apiKey']);
|
|
179
|
+
console.log(query); // { token: 'secret-123', apiKey: 'key-456', status: 'active' }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { ComponentFactory } from '@twin.org/core';
|
|
184
|
+
|
|
185
|
+
interface IHostingComponent {
|
|
186
|
+
encryptParam(paramValue: string): Promise<string>;
|
|
187
|
+
decryptParam(encryptedValue: string): Promise<string>;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const hosting = ComponentFactory.get<IHostingComponent>('hosting');
|
|
191
|
+
|
|
192
|
+
// Encrypt a single parameter value
|
|
193
|
+
const plainText = 'confidential-data';
|
|
194
|
+
const encrypted = await hosting.encryptParam(plainText);
|
|
195
|
+
console.log(encrypted); // CngBAgMEBQYHCAkKCwwNDg8QERAh...
|
|
196
|
+
|
|
197
|
+
// Decrypt the parameter value
|
|
198
|
+
const decrypted = await hosting.decryptParam(encrypted);
|
|
199
|
+
console.log(decrypted); // confidential-data
|
|
200
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Class: ForbiddenError
|
|
2
|
+
|
|
3
|
+
Class to handle errors which are triggered by forbidden actions.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `BaseError`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
> **new ForbiddenError**(`source`, `message`, `properties?`, `cause?`): `ForbiddenError`
|
|
14
|
+
|
|
15
|
+
Create a new instance of ForbiddenError.
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
##### source
|
|
20
|
+
|
|
21
|
+
`string`
|
|
22
|
+
|
|
23
|
+
The source of the error.
|
|
24
|
+
|
|
25
|
+
##### message
|
|
26
|
+
|
|
27
|
+
`string`
|
|
28
|
+
|
|
29
|
+
The message as a code.
|
|
30
|
+
|
|
31
|
+
##### properties?
|
|
32
|
+
|
|
33
|
+
Any additional information for the error.
|
|
34
|
+
|
|
35
|
+
##### cause?
|
|
36
|
+
|
|
37
|
+
`unknown`
|
|
38
|
+
|
|
39
|
+
The cause of the error if we have wrapped another error.
|
|
40
|
+
|
|
41
|
+
#### Returns
|
|
42
|
+
|
|
43
|
+
`ForbiddenError`
|
|
44
|
+
|
|
45
|
+
#### Overrides
|
|
46
|
+
|
|
47
|
+
`BaseError.constructor`
|
|
48
|
+
|
|
49
|
+
## Properties
|
|
50
|
+
|
|
51
|
+
### CLASS\_NAME {#class_name}
|
|
52
|
+
|
|
53
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
54
|
+
|
|
55
|
+
Runtime name for the class.
|
|
@@ -12,9 +12,21 @@ Class to help with processing http errors.
|
|
|
12
12
|
|
|
13
13
|
`HttpErrorHelper`
|
|
14
14
|
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
### ERROR\_TYPE\_MAP {#error_type_map}
|
|
18
|
+
|
|
19
|
+
> `readonly` `static` **ERROR\_TYPE\_MAP**: `object`
|
|
20
|
+
|
|
21
|
+
Mapping of error types to status codes.
|
|
22
|
+
|
|
23
|
+
#### Index Signature
|
|
24
|
+
|
|
25
|
+
\[`id`: `string`\]: `HttpStatusCode`
|
|
26
|
+
|
|
15
27
|
## Methods
|
|
16
28
|
|
|
17
|
-
### processError()
|
|
29
|
+
### processError() {#processerror}
|
|
18
30
|
|
|
19
31
|
> `static` **processError**(`err`, `includeStack?`): `object`
|
|
20
32
|
|
|
@@ -50,7 +62,7 @@ The status code and additional error data.
|
|
|
50
62
|
|
|
51
63
|
***
|
|
52
64
|
|
|
53
|
-
### buildResponse()
|
|
65
|
+
### buildResponse() {#buildresponse}
|
|
54
66
|
|
|
55
67
|
> `static` **buildResponse**(`response`, `error`, `statusCode`): `void`
|
|
56
68
|
|
|
@@ -14,7 +14,7 @@ Class to help with handling http parameters.
|
|
|
14
14
|
|
|
15
15
|
## Methods
|
|
16
16
|
|
|
17
|
-
### arrayFromString()
|
|
17
|
+
### arrayFromString() {#arrayfromstring}
|
|
18
18
|
|
|
19
19
|
> `static` **arrayFromString**\<`T`\>(`values?`): `T`[] \| `undefined`
|
|
20
20
|
|
|
@@ -42,7 +42,7 @@ The array of values.
|
|
|
42
42
|
|
|
43
43
|
***
|
|
44
44
|
|
|
45
|
-
### arrayToString()
|
|
45
|
+
### arrayToString() {#arraytostring}
|
|
46
46
|
|
|
47
47
|
> `static` **arrayToString**\<`T`\>(`values?`): `string` \| `undefined`
|
|
48
48
|
|
|
@@ -70,7 +70,7 @@ The combined.
|
|
|
70
70
|
|
|
71
71
|
***
|
|
72
72
|
|
|
73
|
-
### objectFromString()
|
|
73
|
+
### objectFromString() {#objectfromstring}
|
|
74
74
|
|
|
75
75
|
> `static` **objectFromString**\<`T`\>(`value?`): `T` \| `undefined`
|
|
76
76
|
|
|
@@ -98,7 +98,7 @@ The object.
|
|
|
98
98
|
|
|
99
99
|
***
|
|
100
100
|
|
|
101
|
-
### objectToString()
|
|
101
|
+
### objectToString() {#objecttostring}
|
|
102
102
|
|
|
103
103
|
> `static` **objectToString**\<`T`\>(`value?`): `string` \| `undefined`
|
|
104
104
|
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Class: HttpUrlHelper
|
|
2
|
+
|
|
3
|
+
Class to help with handling http URLs.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
> **new HttpUrlHelper**(): `HttpUrlHelper`
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
`HttpUrlHelper`
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### extractOrigin() {#extractorigin}
|
|
18
|
+
|
|
19
|
+
> `static` **extractOrigin**(`url`): `string` \| `undefined`
|
|
20
|
+
|
|
21
|
+
Extract the origin from the url which includes protocol,host,port.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
##### url
|
|
26
|
+
|
|
27
|
+
`string`
|
|
28
|
+
|
|
29
|
+
The url to extract the origin from.
|
|
30
|
+
|
|
31
|
+
#### Returns
|
|
32
|
+
|
|
33
|
+
`string` \| `undefined`
|
|
34
|
+
|
|
35
|
+
The extracted origin.
|
|
36
|
+
|
|
37
|
+
#### See
|
|
38
|
+
|
|
39
|
+
https://developer.mozilla.org/en-US/docs/Web/API/URL/origin
|
|
40
|
+
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
### extractPath() {#extractpath}
|
|
44
|
+
|
|
45
|
+
> `static` **extractPath**(`url`): `string` \| `undefined`
|
|
46
|
+
|
|
47
|
+
Extract the path from the url.
|
|
48
|
+
|
|
49
|
+
#### Parameters
|
|
50
|
+
|
|
51
|
+
##### url
|
|
52
|
+
|
|
53
|
+
`string`
|
|
54
|
+
|
|
55
|
+
The url to extract the path from.
|
|
56
|
+
|
|
57
|
+
#### Returns
|
|
58
|
+
|
|
59
|
+
`string` \| `undefined`
|
|
60
|
+
|
|
61
|
+
The extracted path.
|
|
62
|
+
|
|
63
|
+
#### See
|
|
64
|
+
|
|
65
|
+
https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname
|
|
66
|
+
|
|
67
|
+
***
|
|
68
|
+
|
|
69
|
+
### extractSearch() {#extractsearch}
|
|
70
|
+
|
|
71
|
+
> `static` **extractSearch**(`url`): `string` \| `undefined`
|
|
72
|
+
|
|
73
|
+
Extract the search from the url.
|
|
74
|
+
|
|
75
|
+
#### Parameters
|
|
76
|
+
|
|
77
|
+
##### url
|
|
78
|
+
|
|
79
|
+
`string`
|
|
80
|
+
|
|
81
|
+
The url to extract the search from.
|
|
82
|
+
|
|
83
|
+
#### Returns
|
|
84
|
+
|
|
85
|
+
`string` \| `undefined`
|
|
86
|
+
|
|
87
|
+
The extracted search.
|
|
88
|
+
|
|
89
|
+
#### See
|
|
90
|
+
|
|
91
|
+
https://developer.mozilla.org/en-US/docs/Web/API/URL/search
|
|
92
|
+
|
|
93
|
+
***
|
|
94
|
+
|
|
95
|
+
### extractPathAndSearch() {#extractpathandsearch}
|
|
96
|
+
|
|
97
|
+
> `static` **extractPathAndSearch**(`url`): `string` \| `undefined`
|
|
98
|
+
|
|
99
|
+
Extract the path and search from the url.
|
|
100
|
+
|
|
101
|
+
#### Parameters
|
|
102
|
+
|
|
103
|
+
##### url
|
|
104
|
+
|
|
105
|
+
`string`
|
|
106
|
+
|
|
107
|
+
The url to extract the path and search from.
|
|
108
|
+
|
|
109
|
+
#### Returns
|
|
110
|
+
|
|
111
|
+
`string` \| `undefined`
|
|
112
|
+
|
|
113
|
+
The extracted path and search.
|
|
114
|
+
|
|
115
|
+
***
|
|
116
|
+
|
|
117
|
+
### combineParts() {#combineparts}
|
|
118
|
+
|
|
119
|
+
> `static` **combineParts**(`origin`, `pathAndSearch`): `string` \| `undefined`
|
|
120
|
+
|
|
121
|
+
Combine the urls parts.
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
##### origin
|
|
126
|
+
|
|
127
|
+
`string`
|
|
128
|
+
|
|
129
|
+
The origin to combine.
|
|
130
|
+
|
|
131
|
+
##### pathAndSearch
|
|
132
|
+
|
|
133
|
+
`string`
|
|
134
|
+
|
|
135
|
+
The path and search to combine.
|
|
136
|
+
|
|
137
|
+
#### Returns
|
|
138
|
+
|
|
139
|
+
`string` \| `undefined`
|
|
140
|
+
|
|
141
|
+
The combined parts.
|
|
142
|
+
|
|
143
|
+
***
|
|
144
|
+
|
|
145
|
+
### encodeUriPathSegment() {#encodeuripathsegment}
|
|
146
|
+
|
|
147
|
+
> `static` **encodeUriPathSegment**(`segment`): `string`
|
|
148
|
+
|
|
149
|
+
Encode a single URL path segment per RFC 3986 §3.3.
|
|
150
|
+
Unlike encodeURIComponent, sub-delimiters ($ & + , ; =) and the colon and
|
|
151
|
+
at-sign characters that are valid unencoded in path segments are preserved.
|
|
152
|
+
|
|
153
|
+
#### Parameters
|
|
154
|
+
|
|
155
|
+
##### segment
|
|
156
|
+
|
|
157
|
+
`string`
|
|
158
|
+
|
|
159
|
+
The raw path segment value to encode.
|
|
160
|
+
|
|
161
|
+
#### Returns
|
|
162
|
+
|
|
163
|
+
`string`
|
|
164
|
+
|
|
165
|
+
The percent-encoded path segment.
|
|
166
|
+
|
|
167
|
+
#### See
|
|
168
|
+
|
|
169
|
+
https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
|
|
170
|
+
|
|
171
|
+
***
|
|
172
|
+
|
|
173
|
+
### replaceOrigin() {#replaceorigin}
|
|
174
|
+
|
|
175
|
+
> `static` **replaceOrigin**(`url`, `newOrigin?`): `string`
|
|
176
|
+
|
|
177
|
+
Replace the origin in the url.
|
|
178
|
+
|
|
179
|
+
#### Parameters
|
|
180
|
+
|
|
181
|
+
##### url
|
|
182
|
+
|
|
183
|
+
`string`
|
|
184
|
+
|
|
185
|
+
The url to replace the origin in.
|
|
186
|
+
|
|
187
|
+
##### newOrigin?
|
|
188
|
+
|
|
189
|
+
`string`
|
|
190
|
+
|
|
191
|
+
The new origin to use.
|
|
192
|
+
|
|
193
|
+
#### Returns
|
|
194
|
+
|
|
195
|
+
`string`
|
|
196
|
+
|
|
197
|
+
The url with the replaced origin.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Class: TooManyRequestsError
|
|
2
|
+
|
|
3
|
+
Class to handle errors which are triggered by too many requests.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `BaseError`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
> **new TooManyRequestsError**(`source`, `message`, `requestCount`, `nextRequestTime`, `properties?`, `cause?`): `TooManyRequestsError`
|
|
14
|
+
|
|
15
|
+
Create a new instance of TooManyRequestsError.
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
##### source
|
|
20
|
+
|
|
21
|
+
`string`
|
|
22
|
+
|
|
23
|
+
The source of the error.
|
|
24
|
+
|
|
25
|
+
##### message
|
|
26
|
+
|
|
27
|
+
`string`
|
|
28
|
+
|
|
29
|
+
The message as a code.
|
|
30
|
+
|
|
31
|
+
##### requestCount
|
|
32
|
+
|
|
33
|
+
`number`
|
|
34
|
+
|
|
35
|
+
The current request count.
|
|
36
|
+
|
|
37
|
+
##### nextRequestTime
|
|
38
|
+
|
|
39
|
+
`string`
|
|
40
|
+
|
|
41
|
+
The time when the next request can be made, as date ISO string.
|
|
42
|
+
|
|
43
|
+
##### properties?
|
|
44
|
+
|
|
45
|
+
Any additional information for the error.
|
|
46
|
+
|
|
47
|
+
##### cause?
|
|
48
|
+
|
|
49
|
+
`unknown`
|
|
50
|
+
|
|
51
|
+
The cause of the error if we have wrapped another error.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`TooManyRequestsError`
|
|
56
|
+
|
|
57
|
+
#### Overrides
|
|
58
|
+
|
|
59
|
+
`BaseError.constructor`
|
|
60
|
+
|
|
61
|
+
## Properties
|
|
62
|
+
|
|
63
|
+
### CLASS\_NAME {#class_name}
|
|
64
|
+
|
|
65
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
66
|
+
|
|
67
|
+
Runtime name for the class.
|
package/docs/reference/index.md
CHANGED
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## Classes
|
|
4
4
|
|
|
5
|
+
- [ForbiddenError](classes/ForbiddenError.md)
|
|
6
|
+
- [TooManyRequestsError](classes/TooManyRequestsError.md)
|
|
5
7
|
- [HttpErrorHelper](classes/HttpErrorHelper.md)
|
|
6
8
|
- [HttpParameterHelper](classes/HttpParameterHelper.md)
|
|
9
|
+
- [HttpUrlHelper](classes/HttpUrlHelper.md)
|
|
7
10
|
|
|
8
11
|
## Interfaces
|
|
9
12
|
|
|
10
13
|
- [IServerFavIconResponse](interfaces/IServerFavIconResponse.md)
|
|
11
14
|
- [IServerHealthResponse](interfaces/IServerHealthResponse.md)
|
|
12
15
|
- [IServerInfoResponse](interfaces/IServerInfoResponse.md)
|
|
16
|
+
- [IServerLivezResponse](interfaces/IServerLivezResponse.md)
|
|
17
|
+
- [IServerReadyzResponse](interfaces/IServerReadyzResponse.md)
|
|
13
18
|
- [IServerRootResponse](interfaces/IServerRootResponse.md)
|
|
14
19
|
- [IServerSpecResponse](interfaces/IServerSpecResponse.md)
|
|
15
|
-
- [IAuthenticationGenerator](interfaces/IAuthenticationGenerator.md)
|
|
16
20
|
- [IBaseRestClientConfig](interfaces/IBaseRestClientConfig.md)
|
|
17
21
|
- [IBaseSocketClientConfig](interfaces/IBaseSocketClientConfig.md)
|
|
18
22
|
- [IHttpRequest](interfaces/IHttpRequest.md)
|
|
@@ -29,6 +33,8 @@
|
|
|
29
33
|
- [IForbiddenResponse](interfaces/IForbiddenResponse.md)
|
|
30
34
|
- [IInternalServerErrorResponse](interfaces/IInternalServerErrorResponse.md)
|
|
31
35
|
- [INotFoundResponse](interfaces/INotFoundResponse.md)
|
|
36
|
+
- [INotImplementedResponse](interfaces/INotImplementedResponse.md)
|
|
37
|
+
- [ITooManyRequestsResponse](interfaces/ITooManyRequestsResponse.md)
|
|
32
38
|
- [IUnauthorizedResponse](interfaces/IUnauthorizedResponse.md)
|
|
33
39
|
- [IUnprocessableEntityResponse](interfaces/IUnprocessableEntityResponse.md)
|
|
34
40
|
- [IAcceptedResponse](interfaces/IAcceptedResponse.md)
|
|
@@ -51,20 +57,23 @@
|
|
|
51
57
|
- [ISocketRouteProcessor](interfaces/ISocketRouteProcessor.md)
|
|
52
58
|
- [IWebServer](interfaces/IWebServer.md)
|
|
53
59
|
- [IWebServerOptions](interfaces/IWebServerOptions.md)
|
|
54
|
-
- [
|
|
60
|
+
- [IHealthComponent](interfaces/IHealthComponent.md)
|
|
61
|
+
- [IHostingComponent](interfaces/IHostingComponent.md)
|
|
55
62
|
- [IInformationComponent](interfaces/IInformationComponent.md)
|
|
56
63
|
- [IServerInfo](interfaces/IServerInfo.md)
|
|
64
|
+
- [ITenant](interfaces/ITenant.md)
|
|
65
|
+
- [ITenantAdminComponent](interfaces/ITenantAdminComponent.md)
|
|
66
|
+
- [IUrlTransformerComponent](interfaces/IUrlTransformerComponent.md)
|
|
57
67
|
|
|
58
68
|
## Type Aliases
|
|
59
69
|
|
|
70
|
+
- [HttpContextIdKeys](type-aliases/HttpContextIdKeys.md)
|
|
60
71
|
- [IRestRouteEntryPoint](type-aliases/IRestRouteEntryPoint.md)
|
|
61
72
|
- [ISocketRouteEntryPoint](type-aliases/ISocketRouteEntryPoint.md)
|
|
62
|
-
- [HealthStatus](type-aliases/HealthStatus.md)
|
|
63
73
|
|
|
64
74
|
## Variables
|
|
65
75
|
|
|
66
|
-
- [AuthenticationGeneratorFactory](variables/AuthenticationGeneratorFactory.md)
|
|
67
76
|
- [MimeTypeProcessorFactory](variables/MimeTypeProcessorFactory.md)
|
|
68
77
|
- [RestRouteProcessorFactory](variables/RestRouteProcessorFactory.md)
|
|
69
78
|
- [SocketRouteProcessorFactory](variables/SocketRouteProcessorFactory.md)
|
|
70
|
-
- [
|
|
79
|
+
- [HttpContextIdKeys](variables/HttpContextIdKeys.md)
|
|
@@ -4,7 +4,7 @@ The rest request ended in accepted response.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### statusCode
|
|
7
|
+
### statusCode {#statuscode}
|
|
8
8
|
|
|
9
9
|
> **statusCode**: `202`
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ Response status code.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### headers
|
|
15
|
+
### headers {#headers}
|
|
16
16
|
|
|
17
17
|
> **headers**: `object`
|
|
18
18
|
|
|
@@ -4,7 +4,7 @@ The server cannot process the request, see the content for more details.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### statusCode
|
|
7
|
+
### statusCode {#statuscode}
|
|
8
8
|
|
|
9
9
|
> **statusCode**: `400`
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ Response status code.
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### body
|
|
15
|
+
### body {#body}
|
|
16
16
|
|
|
17
17
|
> **body**: `IError`
|
|
18
18
|
|