@twin.org/api-models 0.0.3-next.21 → 0.0.3-next.23
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/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 +6 -2
- package/dist/es/helpers/httpErrorHelper.js.map +1 -1
- package/dist/es/index.js +5 -0
- package/dist/es/index.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/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/types/errors/forbiddenError.d.ts +20 -0
- package/dist/types/errors/tooManyRequestsError.d.ts +22 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/models/httpContextIdKeys.d.ts +21 -0
- 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/docs/changelog.md +14 -0
- package/docs/reference/classes/ForbiddenError.md +55 -0
- package/docs/reference/classes/HttpErrorHelper.md +3 -3
- package/docs/reference/classes/HttpParameterHelper.md +4 -4
- package/docs/reference/classes/HttpUrlHelper.md +6 -6
- package/docs/reference/classes/TooManyRequestsError.md +67 -0
- package/docs/reference/index.md +6 -0
- package/docs/reference/interfaces/IAcceptedResponse.md +2 -2
- package/docs/reference/interfaces/IBadRequestResponse.md +2 -2
- package/docs/reference/interfaces/IBaseRestClientConfig.md +9 -9
- package/docs/reference/interfaces/IBaseRoute.md +12 -12
- package/docs/reference/interfaces/IBaseRouteEntryPoint.md +4 -4
- package/docs/reference/interfaces/IBaseRouteProcessor.md +7 -7
- 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/IHealthComponentInfo.md +4 -4
- package/docs/reference/interfaces/IHealthInfo.md +3 -3
- package/docs/reference/interfaces/IHostingComponent.md +3 -3
- package/docs/reference/interfaces/IHttpRequest.md +8 -8
- package/docs/reference/interfaces/IHttpRequestContext.md +6 -6
- 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 +11 -11
- package/docs/reference/interfaces/IInformationComponent.md +8 -8
- 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 +26 -26
- package/docs/reference/interfaces/IRestRouteExample.md +3 -3
- package/docs/reference/interfaces/IRestRouteProcessor.md +10 -10
- 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 +1 -1
- package/docs/reference/interfaces/IServerInfo.md +2 -2
- package/docs/reference/interfaces/IServerInfoResponse.md +1 -1
- package/docs/reference/interfaces/IServerLivezResponse.md +2 -2
- package/docs/reference/interfaces/IServerRootResponse.md +2 -2
- package/docs/reference/interfaces/IServerSpecResponse.md +4 -4
- package/docs/reference/interfaces/ISocketRequestContext.md +7 -7
- package/docs/reference/interfaces/ISocketRoute.md +17 -17
- package/docs/reference/interfaces/ISocketRouteProcessor.md +16 -16
- package/docs/reference/interfaces/ISocketServerRequest.md +12 -12
- package/docs/reference/interfaces/ITag.md +2 -2
- package/docs/reference/interfaces/ITenant.md +8 -8
- package/docs/reference/interfaces/ITenantAdminComponent.md +7 -7
- 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/IWebServer.md +4 -4
- package/docs/reference/interfaces/IWebServerOptions.md +36 -12
- package/docs/reference/type-aliases/HttpContextIdKeys.md +5 -0
- package/docs/reference/variables/HealthStatus.md +3 -3
- package/docs/reference/variables/HttpContextIdKeys.md +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseError } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* Class to handle errors which are triggered by forbidden actions.
|
|
6
|
+
*/
|
|
7
|
+
export class ForbiddenError extends BaseError {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "ForbiddenError";
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of ForbiddenError.
|
|
14
|
+
* @param source The source of the error.
|
|
15
|
+
* @param message The message as a code.
|
|
16
|
+
* @param properties Any additional information for the error.
|
|
17
|
+
* @param cause The cause of the error if we have wrapped another error.
|
|
18
|
+
*/
|
|
19
|
+
constructor(source, message, properties, cause) {
|
|
20
|
+
super(ForbiddenError.CLASS_NAME, source, message, properties, cause);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=forbiddenError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forbiddenError.js","sourceRoot":"","sources":["../../../src/errors/forbiddenError.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,SAAS;IAC5C;;OAEG;IACI,MAAM,CAAU,UAAU,oBAAoC;IAErE;;;;;;OAMG;IACH,YACC,MAAc,EACd,OAAe,EACf,UAAsC,EACtC,KAAe;QAEf,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to handle errors which are triggered by forbidden actions.\n */\nexport class ForbiddenError extends BaseError {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ForbiddenError>();\n\n\t/**\n\t * Create a new instance of ForbiddenError.\n\t * @param source The source of the error.\n\t * @param message The message as a code.\n\t * @param properties Any additional information for the error.\n\t * @param cause The cause of the error if we have wrapped another error.\n\t */\n\tconstructor(\n\t\tsource: string,\n\t\tmessage: string,\n\t\tproperties?: { [id: string]: unknown },\n\t\tcause?: unknown\n\t) {\n\t\tsuper(ForbiddenError.CLASS_NAME, source, message, properties, cause);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseError } from "@twin.org/core";
|
|
4
|
+
/**
|
|
5
|
+
* Class to handle errors which are triggered by too many requests.
|
|
6
|
+
*/
|
|
7
|
+
export class TooManyRequestsError extends BaseError {
|
|
8
|
+
/**
|
|
9
|
+
* Runtime name for the class.
|
|
10
|
+
*/
|
|
11
|
+
static CLASS_NAME = "TooManyRequestsError";
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of TooManyRequestsError.
|
|
14
|
+
* @param source The source of the error.
|
|
15
|
+
* @param message The message as a code.
|
|
16
|
+
* @param requestCount The current request count.
|
|
17
|
+
* @param nextRequestTime The time when the next request can be made, as date ISO string.
|
|
18
|
+
* @param properties Any additional information for the error.
|
|
19
|
+
* @param cause The cause of the error if we have wrapped another error.
|
|
20
|
+
*/
|
|
21
|
+
constructor(source, message, requestCount, nextRequestTime, properties, cause) {
|
|
22
|
+
super(TooManyRequestsError.CLASS_NAME, source, message, { requestCount, nextRequestTime, ...properties }, cause);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=tooManyRequestsError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooManyRequestsError.js","sourceRoot":"","sources":["../../../src/errors/tooManyRequestsError.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAClD;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;;;;;;OAQG;IACH,YACC,MAAc,EACd,OAAe,EACf,YAAoB,EACpB,eAAuB,EACvB,UAAsC,EACtC,KAAe;QAEf,KAAK,CACJ,oBAAoB,CAAC,UAAU,EAC/B,MAAM,EACN,OAAO,EACP,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,UAAU,EAAE,EAChD,KAAK,CACL,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Class to handle errors which are triggered by too many requests.\n */\nexport class TooManyRequestsError extends BaseError {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TooManyRequestsError>();\n\n\t/**\n\t * Create a new instance of TooManyRequestsError.\n\t * @param source The source of the error.\n\t * @param message The message as a code.\n\t * @param requestCount The current request count.\n\t * @param nextRequestTime The time when the next request can be made, as date ISO string.\n\t * @param properties Any additional information for the error.\n\t * @param cause The cause of the error if we have wrapped another error.\n\t */\n\tconstructor(\n\t\tsource: string,\n\t\tmessage: string,\n\t\trequestCount: number,\n\t\tnextRequestTime: string,\n\t\tproperties?: { [id: string]: unknown },\n\t\tcause?: unknown\n\t) {\n\t\tsuper(\n\t\t\tTooManyRequestsError.CLASS_NAME,\n\t\t\tsource,\n\t\t\tmessage,\n\t\t\t{ requestCount, nextRequestTime, ...properties },\n\t\t\tcause\n\t\t);\n\t}\n}\n"]}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { AlreadyExistsError, BaseError, ConflictError, GuardError, NotFoundError, NotImplementedError, UnauthorizedError, UnprocessableError, ValidationError } from "@twin.org/core";
|
|
4
4
|
import { HeaderTypes, HttpStatusCode, MimeTypes } from "@twin.org/web";
|
|
5
|
+
import { ForbiddenError } from "../errors/forbiddenError.js";
|
|
6
|
+
import { TooManyRequestsError } from "../errors/tooManyRequestsError.js";
|
|
5
7
|
/**
|
|
6
8
|
* Class to help with processing http errors.
|
|
7
9
|
*/
|
|
@@ -16,8 +18,10 @@ export class HttpErrorHelper {
|
|
|
16
18
|
[AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,
|
|
17
19
|
[NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,
|
|
18
20
|
[UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,
|
|
19
|
-
[NotImplementedError.CLASS_NAME]: HttpStatusCode.
|
|
20
|
-
[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity
|
|
21
|
+
[NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,
|
|
22
|
+
[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,
|
|
23
|
+
[TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,
|
|
24
|
+
[ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden
|
|
21
25
|
};
|
|
22
26
|
/**
|
|
23
27
|
* Process the errors from the routes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpErrorHelper.js","sourceRoot":"","sources":["../../../src/helpers/httpErrorHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,UAAU,EAEV,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"httpErrorHelper.js","sourceRoot":"","sources":["../../../src/helpers/httpErrorHelper.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tAlreadyExistsError,\n\tBaseError,\n\tConflictError,\n\tGuardError,\n\ttype IError,\n\tNotFoundError,\n\tNotImplementedError,\n\tUnauthorizedError,\n\tUnprocessableError,\n\tValidationError\n} from \"@twin.org/core\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\nimport { ForbiddenError } from \"../errors/forbiddenError.js\";\nimport { TooManyRequestsError } from \"../errors/tooManyRequestsError.js\";\nimport type { IHttpResponse } from \"../models/protocol/IHttpResponse.js\";\n\n/**\n * Class to help with processing http errors.\n */\nexport class HttpErrorHelper {\n\t/**\n\t * Mapping of error types to status codes.\n\t */\n\tpublic static readonly ERROR_TYPE_MAP: { [id: string]: HttpStatusCode } = {\n\t\t[GuardError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ValidationError.CLASS_NAME]: HttpStatusCode.badRequest,\n\t\t[ConflictError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,\n\t\t[NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,\n\t\t[UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,\n\t\t[NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,\n\t\t[UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,\n\t\t[TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,\n\t\t[ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden\n\t};\n\n\t/**\n\t * Process the errors from the routes.\n\t * @param err The error to process.\n\t * @param includeStack Should the stack be included in the error.\n\t * @returns The status code and additional error data.\n\t */\n\tpublic static processError(\n\t\terr: unknown,\n\t\tincludeStack?: boolean\n\t): {\n\t\terror: IError;\n\t\thttpStatusCode: HttpStatusCode;\n\t} {\n\t\tconst error: BaseError = BaseError.fromError(err);\n\n\t\t// If the error or any of its sub errors are of the specific\n\t\t// types then set the http response code accordingly\n\t\tconst flattened = BaseError.flatten(error);\n\n\t\tlet httpStatusCode: HttpStatusCode = HttpStatusCode.internalServerError;\n\n\t\t// First check the primary error, as we don't want to override that with a sub error\n\t\tif (flattened.length > 0) {\n\t\t\tconst primaryError = flattened[0];\n\t\t\tif (HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name]) {\n\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name];\n\t\t\t}\n\n\t\t\t// The primary error is still internal server error, check the sub errors\n\t\t\tif (httpStatusCode === HttpStatusCode.internalServerError) {\n\t\t\t\tfor (const className in HttpErrorHelper.ERROR_TYPE_MAP) {\n\t\t\t\t\tif (flattened.some(e => BaseError.isErrorName(e, className))) {\n\t\t\t\t\t\thttpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[className];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst returnError = error.toJsonObject(includeStack);\n\n\t\treturn {\n\t\t\terror: returnError,\n\t\t\thttpStatusCode\n\t\t};\n\t}\n\n\t/**\n\t * Build an error response.\n\t * @param response The response to build the error into.\n\t * @param error The error to build the response for.\n\t * @param statusCode The status code to use for the error.\n\t */\n\tpublic static buildResponse(\n\t\tresponse: IHttpResponse,\n\t\terror: IError,\n\t\tstatusCode: HttpStatusCode\n\t): void {\n\t\tresponse.headers ??= {};\n\t\tresponse.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;\n\t\tresponse.body = error;\n\t\tresponse.statusCode = statusCode;\n\t}\n}\n"]}
|
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./errors/forbiddenError.js";
|
|
4
|
+
export * from "./errors/tooManyRequestsError.js";
|
|
3
5
|
export * from "./factories/mimeTypeProcessorFactory.js";
|
|
4
6
|
export * from "./factories/restRouteProcessorFactory.js";
|
|
5
7
|
export * from "./factories/socketRouteProcessorFactory.js";
|
|
@@ -14,6 +16,7 @@ export * from "./models/api/IServerRootResponse.js";
|
|
|
14
16
|
export * from "./models/api/IServerSpecResponse.js";
|
|
15
17
|
export * from "./models/config/IBaseRestClientConfig.js";
|
|
16
18
|
export * from "./models/config/IBaseSocketClientConfig.js";
|
|
19
|
+
export * from "./models/httpContextIdKeys.js";
|
|
17
20
|
export * from "./models/protocol/IHttpRequest.js";
|
|
18
21
|
export * from "./models/protocol/IHttpRequestContext.js";
|
|
19
22
|
export * from "./models/protocol/IHttpRequestPathParams.js";
|
|
@@ -28,6 +31,8 @@ export * from "./models/responses/errors/IConflictResponse.js";
|
|
|
28
31
|
export * from "./models/responses/errors/IForbiddenResponse.js";
|
|
29
32
|
export * from "./models/responses/errors/IInternalServerErrorResponse.js";
|
|
30
33
|
export * from "./models/responses/errors/INotFoundResponse.js";
|
|
34
|
+
export * from "./models/responses/errors/INotImplementedResponse.js";
|
|
35
|
+
export * from "./models/responses/errors/ITooManyRequestsResponse.js";
|
|
31
36
|
export * from "./models/responses/errors/IUnauthorizedResponse.js";
|
|
32
37
|
export * from "./models/responses/errors/IUnprocessableEntityResponse.js";
|
|
33
38
|
export * from "./models/responses/success/IAcceptedResponse.js";
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,mCAAmC,CAAC;AAClD,cAAc,0CAA0C,CAAC;AACzD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wCAAwC,CAAC;AACvD,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,iDAAiD,CAAC;AAChE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,gDAAgD,CAAC;AAC/D,cAAc,oDAAoD,CAAC;AACnE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,iDAAiD,CAAC;AAChE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,wDAAwD,CAAC;AACvE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,iCAAiC,CAAC;AAChD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./factories/mimeTypeProcessorFactory.js\";\nexport * from \"./factories/restRouteProcessorFactory.js\";\nexport * from \"./factories/socketRouteProcessorFactory.js\";\nexport * from \"./helpers/httpErrorHelper.js\";\nexport * from \"./helpers/httpParameterHelper.js\";\nexport * from \"./helpers/httpUrlHelper.js\";\nexport * from \"./models/api/IServerFavIconResponse.js\";\nexport * from \"./models/api/IServerHealthResponse.js\";\nexport * from \"./models/api/IServerInfoResponse.js\";\nexport * from \"./models/api/IServerLivezResponse.js\";\nexport * from \"./models/api/IServerRootResponse.js\";\nexport * from \"./models/api/IServerSpecResponse.js\";\nexport * from \"./models/config/IBaseRestClientConfig.js\";\nexport * from \"./models/config/IBaseSocketClientConfig.js\";\nexport * from \"./models/protocol/IHttpRequest.js\";\nexport * from \"./models/protocol/IHttpRequestContext.js\";\nexport * from \"./models/protocol/IHttpRequestPathParams.js\";\nexport * from \"./models/protocol/IHttpRequestQuery.js\";\nexport * from \"./models/protocol/IHttpResponse.js\";\nexport * from \"./models/protocol/IHttpServerRequest.js\";\nexport * from \"./models/protocol/ISocketRequestContext.js\";\nexport * from \"./models/protocol/ISocketServerRequest.js\";\nexport * from \"./models/requests/INoContentRequest.js\";\nexport * from \"./models/responses/errors/IBadRequestResponse.js\";\nexport * from \"./models/responses/errors/IConflictResponse.js\";\nexport * from \"./models/responses/errors/IForbiddenResponse.js\";\nexport * from \"./models/responses/errors/IInternalServerErrorResponse.js\";\nexport * from \"./models/responses/errors/INotFoundResponse.js\";\nexport * from \"./models/responses/errors/IUnauthorizedResponse.js\";\nexport * from \"./models/responses/errors/IUnprocessableEntityResponse.js\";\nexport * from \"./models/responses/success/IAcceptedResponse.js\";\nexport * from \"./models/responses/success/ICreatedResponse.js\";\nexport * from \"./models/responses/success/INoContentResponse.js\";\nexport * from \"./models/responses/success/IOkResponse.js\";\nexport * from \"./models/routes/IBaseRoute.js\";\nexport * from \"./models/routes/IBaseRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRoute.js\";\nexport * from \"./models/routes/IRestRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRouteExample.js\";\nexport * from \"./models/routes/IRestRouteRequestExample.js\";\nexport * from \"./models/routes/IRestRouteResponseAttachmentOptions.js\";\nexport * from \"./models/routes/IRestRouteResponseExample.js\";\nexport * from \"./models/routes/IRestRouteResponseOptions.js\";\nexport * from \"./models/routes/ISocketRoute.js\";\nexport * from \"./models/routes/ISocketRouteEntryPoint.js\";\nexport * from \"./models/routes/ITag.js\";\nexport * from \"./models/server/IBaseRouteProcessor.js\";\nexport * from \"./models/server/IMimeTypeProcessor.js\";\nexport * from \"./models/server/IRestRouteProcessor.js\";\nexport * from \"./models/server/ISocketRouteProcessor.js\";\nexport * from \"./models/server/IWebServer.js\";\nexport * from \"./models/server/IWebServerOptions.js\";\nexport * from \"./models/services/healthStatus.js\";\nexport * from \"./models/services/IHealthComponentInfo.js\";\nexport * from \"./models/services/IHealthInfo.js\";\nexport * from \"./models/services/IHostingComponent.js\";\nexport * from \"./models/services/IInformationComponent.js\";\nexport * from \"./models/services/IServerInfo.js\";\nexport * from \"./models/services/ITenant.js\";\nexport * from \"./models/services/ITenantAdminComponent.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0CAA0C,CAAC;AACzD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,wCAAwC,CAAC;AACvD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wCAAwC,CAAC;AACvD,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,iDAAiD,CAAC;AAChE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,gDAAgD,CAAC;AAC/D,cAAc,sDAAsD,CAAC;AACrE,cAAc,uDAAuD,CAAC;AACtE,cAAc,oDAAoD,CAAC;AACnE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,iDAAiD,CAAC;AAChE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,sCAAsC,CAAC;AACrD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,wDAAwD,CAAC;AACvE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,iCAAiC,CAAC;AAChD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4CAA4C,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./errors/forbiddenError.js\";\nexport * from \"./errors/tooManyRequestsError.js\";\nexport * from \"./factories/mimeTypeProcessorFactory.js\";\nexport * from \"./factories/restRouteProcessorFactory.js\";\nexport * from \"./factories/socketRouteProcessorFactory.js\";\nexport * from \"./helpers/httpErrorHelper.js\";\nexport * from \"./helpers/httpParameterHelper.js\";\nexport * from \"./helpers/httpUrlHelper.js\";\nexport * from \"./models/api/IServerFavIconResponse.js\";\nexport * from \"./models/api/IServerHealthResponse.js\";\nexport * from \"./models/api/IServerInfoResponse.js\";\nexport * from \"./models/api/IServerLivezResponse.js\";\nexport * from \"./models/api/IServerRootResponse.js\";\nexport * from \"./models/api/IServerSpecResponse.js\";\nexport * from \"./models/config/IBaseRestClientConfig.js\";\nexport * from \"./models/config/IBaseSocketClientConfig.js\";\nexport * from \"./models/httpContextIdKeys.js\";\nexport * from \"./models/protocol/IHttpRequest.js\";\nexport * from \"./models/protocol/IHttpRequestContext.js\";\nexport * from \"./models/protocol/IHttpRequestPathParams.js\";\nexport * from \"./models/protocol/IHttpRequestQuery.js\";\nexport * from \"./models/protocol/IHttpResponse.js\";\nexport * from \"./models/protocol/IHttpServerRequest.js\";\nexport * from \"./models/protocol/ISocketRequestContext.js\";\nexport * from \"./models/protocol/ISocketServerRequest.js\";\nexport * from \"./models/requests/INoContentRequest.js\";\nexport * from \"./models/responses/errors/IBadRequestResponse.js\";\nexport * from \"./models/responses/errors/IConflictResponse.js\";\nexport * from \"./models/responses/errors/IForbiddenResponse.js\";\nexport * from \"./models/responses/errors/IInternalServerErrorResponse.js\";\nexport * from \"./models/responses/errors/INotFoundResponse.js\";\nexport * from \"./models/responses/errors/INotImplementedResponse.js\";\nexport * from \"./models/responses/errors/ITooManyRequestsResponse.js\";\nexport * from \"./models/responses/errors/IUnauthorizedResponse.js\";\nexport * from \"./models/responses/errors/IUnprocessableEntityResponse.js\";\nexport * from \"./models/responses/success/IAcceptedResponse.js\";\nexport * from \"./models/responses/success/ICreatedResponse.js\";\nexport * from \"./models/responses/success/INoContentResponse.js\";\nexport * from \"./models/responses/success/IOkResponse.js\";\nexport * from \"./models/routes/IBaseRoute.js\";\nexport * from \"./models/routes/IBaseRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRoute.js\";\nexport * from \"./models/routes/IRestRouteEntryPoint.js\";\nexport * from \"./models/routes/IRestRouteExample.js\";\nexport * from \"./models/routes/IRestRouteRequestExample.js\";\nexport * from \"./models/routes/IRestRouteResponseAttachmentOptions.js\";\nexport * from \"./models/routes/IRestRouteResponseExample.js\";\nexport * from \"./models/routes/IRestRouteResponseOptions.js\";\nexport * from \"./models/routes/ISocketRoute.js\";\nexport * from \"./models/routes/ISocketRouteEntryPoint.js\";\nexport * from \"./models/routes/ITag.js\";\nexport * from \"./models/server/IBaseRouteProcessor.js\";\nexport * from \"./models/server/IMimeTypeProcessor.js\";\nexport * from \"./models/server/IRestRouteProcessor.js\";\nexport * from \"./models/server/ISocketRouteProcessor.js\";\nexport * from \"./models/server/IWebServer.js\";\nexport * from \"./models/server/IWebServerOptions.js\";\nexport * from \"./models/services/healthStatus.js\";\nexport * from \"./models/services/IHealthComponentInfo.js\";\nexport * from \"./models/services/IHealthInfo.js\";\nexport * from \"./models/services/IHostingComponent.js\";\nexport * from \"./models/services/IInformationComponent.js\";\nexport * from \"./models/services/IServerInfo.js\";\nexport * from \"./models/services/ITenant.js\";\nexport * from \"./models/services/ITenantAdminComponent.js\";\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* HTTP definition of some context keys.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const HttpContextIdKeys = {
|
|
8
|
+
/**
|
|
9
|
+
* IP address of the client.
|
|
10
|
+
*/
|
|
11
|
+
IpAddress: "ipAddress",
|
|
12
|
+
/**
|
|
13
|
+
* User agent of the client.
|
|
14
|
+
*/
|
|
15
|
+
UserAgent: "userAgent",
|
|
16
|
+
/**
|
|
17
|
+
* Correlation ID of the request.
|
|
18
|
+
*/
|
|
19
|
+
CorrelationId: "correlationId"
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=httpContextIdKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpContextIdKeys.js","sourceRoot":"","sources":["../../../src/models/httpContextIdKeys.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAChC;;OAEG;IACH,SAAS,EAAE,WAAW;IAEtB;;OAEG;IACH,SAAS,EAAE,WAAW;IAEtB;;OAEG;IACH,aAAa,EAAE,eAAe;CACrB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * HTTP definition of some context keys.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const HttpContextIdKeys = {\n\t/**\n\t * IP address of the client.\n\t */\n\tIpAddress: \"ipAddress\",\n\n\t/**\n\t * User agent of the client.\n\t */\n\tUserAgent: \"userAgent\",\n\n\t/**\n\t * Correlation ID of the request.\n\t */\n\tCorrelationId: \"correlationId\"\n} as const;\n\n/**\n * HTTP definition of some context keys.\n */\nexport type HttpContextIdKeys = (typeof HttpContextIdKeys)[keyof typeof HttpContextIdKeys];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IConflictResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/IConflictResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The request resulted in a conflicting operation, see the content for more details.\n */\nexport interface IConflictResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.conflict;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError
|
|
1
|
+
{"version":3,"file":"IConflictResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/IConflictResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The request resulted in a conflicting operation, see the content for more details.\n */\nexport interface IConflictResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.conflict;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"INotImplementedResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/INotImplementedResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The operation that you tried to perform is not implemented, see the content for more details.\n */\nexport interface INotImplementedResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.notImplemented;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITooManyRequestsResponse.js","sourceRoot":"","sources":["../../../../../src/models/responses/errors/ITooManyRequestsResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The request resulted in too many requests, see the content for more details.\n */\nexport interface ITooManyRequestsResponse {\n\t/**\n\t * Response status code.\n\t */\n\tstatusCode: typeof HttpStatusCode.tooManyRequests;\n\n\t/**\n\t * The body which contains the error.\n\t */\n\tbody: IError;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseError } from "@twin.org/core";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by forbidden actions.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ForbiddenError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of ForbiddenError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param properties Any additional information for the error.
|
|
15
|
+
* @param cause The cause of the error if we have wrapped another error.
|
|
16
|
+
*/
|
|
17
|
+
constructor(source: string, message: string, properties?: {
|
|
18
|
+
[id: string]: unknown;
|
|
19
|
+
}, cause?: unknown);
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseError } from "@twin.org/core";
|
|
2
|
+
/**
|
|
3
|
+
* Class to handle errors which are triggered by too many requests.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TooManyRequestsError extends BaseError {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
static readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of TooManyRequestsError.
|
|
12
|
+
* @param source The source of the error.
|
|
13
|
+
* @param message The message as a code.
|
|
14
|
+
* @param requestCount The current request count.
|
|
15
|
+
* @param nextRequestTime The time when the next request can be made, as date ISO string.
|
|
16
|
+
* @param properties Any additional information for the error.
|
|
17
|
+
* @param cause The cause of the error if we have wrapped another error.
|
|
18
|
+
*/
|
|
19
|
+
constructor(source: string, message: string, requestCount: number, nextRequestTime: string, properties?: {
|
|
20
|
+
[id: string]: unknown;
|
|
21
|
+
}, cause?: unknown);
|
|
22
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export * from "./errors/forbiddenError.js";
|
|
2
|
+
export * from "./errors/tooManyRequestsError.js";
|
|
1
3
|
export * from "./factories/mimeTypeProcessorFactory.js";
|
|
2
4
|
export * from "./factories/restRouteProcessorFactory.js";
|
|
3
5
|
export * from "./factories/socketRouteProcessorFactory.js";
|
|
@@ -12,6 +14,7 @@ export * from "./models/api/IServerRootResponse.js";
|
|
|
12
14
|
export * from "./models/api/IServerSpecResponse.js";
|
|
13
15
|
export * from "./models/config/IBaseRestClientConfig.js";
|
|
14
16
|
export * from "./models/config/IBaseSocketClientConfig.js";
|
|
17
|
+
export * from "./models/httpContextIdKeys.js";
|
|
15
18
|
export * from "./models/protocol/IHttpRequest.js";
|
|
16
19
|
export * from "./models/protocol/IHttpRequestContext.js";
|
|
17
20
|
export * from "./models/protocol/IHttpRequestPathParams.js";
|
|
@@ -26,6 +29,8 @@ export * from "./models/responses/errors/IConflictResponse.js";
|
|
|
26
29
|
export * from "./models/responses/errors/IForbiddenResponse.js";
|
|
27
30
|
export * from "./models/responses/errors/IInternalServerErrorResponse.js";
|
|
28
31
|
export * from "./models/responses/errors/INotFoundResponse.js";
|
|
32
|
+
export * from "./models/responses/errors/INotImplementedResponse.js";
|
|
33
|
+
export * from "./models/responses/errors/ITooManyRequestsResponse.js";
|
|
29
34
|
export * from "./models/responses/errors/IUnauthorizedResponse.js";
|
|
30
35
|
export * from "./models/responses/errors/IUnprocessableEntityResponse.js";
|
|
31
36
|
export * from "./models/responses/success/IAcceptedResponse.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP definition of some context keys.
|
|
3
|
+
*/
|
|
4
|
+
export declare const HttpContextIdKeys: {
|
|
5
|
+
/**
|
|
6
|
+
* IP address of the client.
|
|
7
|
+
*/
|
|
8
|
+
readonly IpAddress: "ipAddress";
|
|
9
|
+
/**
|
|
10
|
+
* User agent of the client.
|
|
11
|
+
*/
|
|
12
|
+
readonly UserAgent: "userAgent";
|
|
13
|
+
/**
|
|
14
|
+
* Correlation ID of the request.
|
|
15
|
+
*/
|
|
16
|
+
readonly CorrelationId: "correlationId";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* HTTP definition of some context keys.
|
|
20
|
+
*/
|
|
21
|
+
export type HttpContextIdKeys = (typeof HttpContextIdKeys)[keyof typeof HttpContextIdKeys];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IError } from "@twin.org/core";
|
|
2
|
+
import type { HttpStatusCode } from "@twin.org/web";
|
|
3
|
+
/**
|
|
4
|
+
* The operation that you tried to perform is not implemented, see the content for more details.
|
|
5
|
+
*/
|
|
6
|
+
export interface INotImplementedResponse {
|
|
7
|
+
/**
|
|
8
|
+
* Response status code.
|
|
9
|
+
*/
|
|
10
|
+
statusCode: typeof HttpStatusCode.notImplemented;
|
|
11
|
+
/**
|
|
12
|
+
* The body which contains the error.
|
|
13
|
+
*/
|
|
14
|
+
body: IError;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IError } from "@twin.org/core";
|
|
2
|
+
import type { HttpStatusCode } from "@twin.org/web";
|
|
3
|
+
/**
|
|
4
|
+
* The request resulted in too many requests, see the content for more details.
|
|
5
|
+
*/
|
|
6
|
+
export interface ITooManyRequestsResponse {
|
|
7
|
+
/**
|
|
8
|
+
* Response status code.
|
|
9
|
+
*/
|
|
10
|
+
statusCode: typeof HttpStatusCode.tooManyRequests;
|
|
11
|
+
/**
|
|
12
|
+
* The body which contains the error.
|
|
13
|
+
*/
|
|
14
|
+
body: IError;
|
|
15
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.23](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.22...api-models-v0.0.3-next.23) (2026-04-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* auth enhancements ([#93](https://github.com/twinfoundation/api/issues/93)) ([921a50c](https://github.com/twinfoundation/api/commit/921a50cd89d26e530a6be6174a5a803060fa0eb6))
|
|
9
|
+
|
|
10
|
+
## [0.0.3-next.22](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.21...api-models-v0.0.3-next.22) (2026-03-27)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add new error types ([#86](https://github.com/twinfoundation/api/issues/86)) ([71e3c07](https://github.com/twinfoundation/api/commit/71e3c07c792984af01c307943e0e09a3ae98710d))
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.21](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.20...api-models-v0.0.3-next.21) (2026-03-11)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -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.
|
|
@@ -14,7 +14,7 @@ Class to help with processing http errors.
|
|
|
14
14
|
|
|
15
15
|
## Properties
|
|
16
16
|
|
|
17
|
-
### ERROR\_TYPE\_MAP
|
|
17
|
+
### ERROR\_TYPE\_MAP {#error_type_map}
|
|
18
18
|
|
|
19
19
|
> `readonly` `static` **ERROR\_TYPE\_MAP**: `object`
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ Mapping of error types to status codes.
|
|
|
26
26
|
|
|
27
27
|
## Methods
|
|
28
28
|
|
|
29
|
-
### processError()
|
|
29
|
+
### processError() {#processerror}
|
|
30
30
|
|
|
31
31
|
> `static` **processError**(`err`, `includeStack?`): `object`
|
|
32
32
|
|
|
@@ -62,7 +62,7 @@ The status code and additional error data.
|
|
|
62
62
|
|
|
63
63
|
***
|
|
64
64
|
|
|
65
|
-
### buildResponse()
|
|
65
|
+
### buildResponse() {#buildresponse}
|
|
66
66
|
|
|
67
67
|
> `static` **buildResponse**(`response`, `error`, `statusCode`): `void`
|
|
68
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
|
|
|
@@ -14,7 +14,7 @@ Class to help with handling http URLs.
|
|
|
14
14
|
|
|
15
15
|
## Methods
|
|
16
16
|
|
|
17
|
-
### extractOrigin()
|
|
17
|
+
### extractOrigin() {#extractorigin}
|
|
18
18
|
|
|
19
19
|
> `static` **extractOrigin**(`url`): `string` \| `undefined`
|
|
20
20
|
|
|
@@ -40,7 +40,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/URL/origin
|
|
|
40
40
|
|
|
41
41
|
***
|
|
42
42
|
|
|
43
|
-
### extractPath()
|
|
43
|
+
### extractPath() {#extractpath}
|
|
44
44
|
|
|
45
45
|
> `static` **extractPath**(`url`): `string` \| `undefined`
|
|
46
46
|
|
|
@@ -66,7 +66,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname
|
|
|
66
66
|
|
|
67
67
|
***
|
|
68
68
|
|
|
69
|
-
### extractSearch()
|
|
69
|
+
### extractSearch() {#extractsearch}
|
|
70
70
|
|
|
71
71
|
> `static` **extractSearch**(`url`): `string` \| `undefined`
|
|
72
72
|
|
|
@@ -92,7 +92,7 @@ https://developer.mozilla.org/en-US/docs/Web/API/URL/search
|
|
|
92
92
|
|
|
93
93
|
***
|
|
94
94
|
|
|
95
|
-
### extractPathAndSearch()
|
|
95
|
+
### extractPathAndSearch() {#extractpathandsearch}
|
|
96
96
|
|
|
97
97
|
> `static` **extractPathAndSearch**(`url`): `string` \| `undefined`
|
|
98
98
|
|
|
@@ -114,7 +114,7 @@ The extracted path and search.
|
|
|
114
114
|
|
|
115
115
|
***
|
|
116
116
|
|
|
117
|
-
### combineParts()
|
|
117
|
+
### combineParts() {#combineparts}
|
|
118
118
|
|
|
119
119
|
> `static` **combineParts**(`origin`, `pathAndSearch`): `string` \| `undefined`
|
|
120
120
|
|
|
@@ -142,7 +142,7 @@ The combined parts.
|
|
|
142
142
|
|
|
143
143
|
***
|
|
144
144
|
|
|
145
|
-
### replaceOrigin()
|
|
145
|
+
### replaceOrigin() {#replaceorigin}
|
|
146
146
|
|
|
147
147
|
> `static` **replaceOrigin**(`url`, `newOrigin?`): `string`
|
|
148
148
|
|
|
@@ -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.
|