@twin.org/api-models 0.0.3-next.3 → 0.0.3-next.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +1 -1
  2. package/dist/es/errors/forbiddenError.js +23 -0
  3. package/dist/es/errors/forbiddenError.js.map +1 -0
  4. package/dist/es/errors/tooManyRequestsError.js +25 -0
  5. package/dist/es/errors/tooManyRequestsError.js.map +1 -0
  6. package/dist/es/helpers/httpErrorHelper.js +34 -20
  7. package/dist/es/helpers/httpErrorHelper.js.map +1 -1
  8. package/dist/es/helpers/httpUrlHelper.js +105 -0
  9. package/dist/es/helpers/httpUrlHelper.js.map +1 -0
  10. package/dist/es/index.js +13 -4
  11. package/dist/es/index.js.map +1 -1
  12. package/dist/es/models/api/IServerHealthResponse.js.map +1 -1
  13. package/dist/es/models/api/IServerLivezResponse.js +2 -0
  14. package/dist/es/models/api/IServerLivezResponse.js.map +1 -0
  15. package/dist/es/models/api/IServerReadyzResponse.js +2 -0
  16. package/dist/es/models/api/IServerReadyzResponse.js.map +1 -0
  17. package/dist/es/models/api/IServerRootResponse.js +0 -2
  18. package/dist/es/models/api/IServerRootResponse.js.map +1 -1
  19. package/dist/es/models/config/IBaseRestClientConfig.js.map +1 -1
  20. package/dist/es/models/httpContextIdKeys.js +21 -0
  21. package/dist/es/models/httpContextIdKeys.js.map +1 -0
  22. package/dist/es/models/protocol/IHttpRequestContext.js.map +1 -1
  23. package/dist/es/models/protocol/IHttpRequestPathParams.js.map +1 -1
  24. package/dist/es/models/protocol/IHttpRequestQuery.js.map +1 -1
  25. package/dist/es/models/protocol/IHttpServerRequest.js.map +1 -1
  26. package/dist/es/models/responses/errors/IConflictResponse.js.map +1 -1
  27. package/dist/es/models/responses/errors/INotImplementedResponse.js +2 -0
  28. package/dist/es/models/responses/errors/INotImplementedResponse.js.map +1 -0
  29. package/dist/es/models/responses/errors/ITooManyRequestsResponse.js +2 -0
  30. package/dist/es/models/responses/errors/ITooManyRequestsResponse.js.map +1 -0
  31. package/dist/es/models/routes/IBaseRoute.js.map +1 -1
  32. package/dist/es/models/server/IBaseRouteProcessor.js.map +1 -1
  33. package/dist/es/models/server/IRestRouteProcessor.js.map +1 -1
  34. package/dist/es/models/server/ISocketRouteProcessor.js.map +1 -1
  35. package/dist/es/models/server/IWebServer.js.map +1 -1
  36. package/dist/es/models/services/IHealthComponent.js +2 -0
  37. package/dist/es/models/services/IHealthComponent.js.map +1 -0
  38. package/dist/es/models/services/IHostingComponent.js +2 -0
  39. package/dist/es/models/services/IHostingComponent.js.map +1 -0
  40. package/dist/es/models/services/IInformationComponent.js.map +1 -1
  41. package/dist/es/models/services/ITenant.js +4 -0
  42. package/dist/es/models/services/ITenant.js.map +1 -0
  43. package/dist/es/models/services/ITenantAdminComponent.js +2 -0
  44. package/dist/es/models/services/ITenantAdminComponent.js.map +1 -0
  45. package/dist/es/models/services/IUrlTransformerComponent.js +2 -0
  46. package/dist/es/models/services/IUrlTransformerComponent.js.map +1 -0
  47. package/dist/types/errors/forbiddenError.d.ts +20 -0
  48. package/dist/types/errors/tooManyRequestsError.d.ts +22 -0
  49. package/dist/types/helpers/httpErrorHelper.d.ts +6 -0
  50. package/dist/types/helpers/httpUrlHelper.d.ts +55 -0
  51. package/dist/types/index.d.ts +13 -4
  52. package/dist/types/models/api/IServerHealthResponse.d.ts +6 -3
  53. package/dist/types/models/api/IServerLivezResponse.d.ts +16 -0
  54. package/dist/types/models/api/IServerReadyzResponse.d.ts +16 -0
  55. package/dist/types/models/api/IServerRootResponse.d.ts +7 -0
  56. package/dist/types/models/config/IBaseRestClientConfig.d.ts +16 -0
  57. package/dist/types/models/httpContextIdKeys.d.ts +21 -0
  58. package/dist/types/models/protocol/IHttpRequestContext.d.ts +4 -0
  59. package/dist/types/models/protocol/IHttpRequestPathParams.d.ts +1 -1
  60. package/dist/types/models/protocol/IHttpRequestQuery.d.ts +1 -1
  61. package/dist/types/models/protocol/IHttpServerRequest.d.ts +4 -4
  62. package/dist/types/models/responses/errors/IConflictResponse.d.ts +1 -6
  63. package/dist/types/models/responses/errors/INotImplementedResponse.d.ts +15 -0
  64. package/dist/types/models/responses/errors/ITooManyRequestsResponse.d.ts +15 -0
  65. package/dist/types/models/routes/IBaseRoute.d.ts +9 -1
  66. package/dist/types/models/server/IBaseRouteProcessor.d.ts +14 -4
  67. package/dist/types/models/server/IRestRouteProcessor.d.ts +7 -2
  68. package/dist/types/models/server/IWebServer.d.ts +7 -1
  69. package/dist/types/models/services/IHealthComponent.d.ts +14 -0
  70. package/dist/types/models/services/IHostingComponent.d.ts +24 -0
  71. package/dist/types/models/services/IInformationComponent.d.ts +10 -17
  72. package/dist/types/models/services/ITenant.d.ts +33 -0
  73. package/dist/types/models/services/ITenantAdminComponent.d.ts +63 -0
  74. package/dist/types/models/services/IUrlTransformerComponent.d.ts +66 -0
  75. package/docs/changelog.md +278 -58
  76. package/docs/examples.md +200 -1
  77. package/docs/reference/classes/ForbiddenError.md +55 -0
  78. package/docs/reference/classes/HttpErrorHelper.md +14 -2
  79. package/docs/reference/classes/HttpParameterHelper.md +4 -4
  80. package/docs/reference/classes/HttpUrlHelper.md +197 -0
  81. package/docs/reference/classes/TooManyRequestsError.md +67 -0
  82. package/docs/reference/index.md +14 -5
  83. package/docs/reference/interfaces/IAcceptedResponse.md +2 -2
  84. package/docs/reference/interfaces/IBadRequestResponse.md +2 -2
  85. package/docs/reference/interfaces/IBaseRestClientConfig.md +57 -9
  86. package/docs/reference/interfaces/IBaseRoute.md +25 -9
  87. package/docs/reference/interfaces/IBaseRouteEntryPoint.md +4 -4
  88. package/docs/reference/interfaces/IBaseRouteProcessor.md +33 -13
  89. package/docs/reference/interfaces/IBaseSocketClientConfig.md +7 -7
  90. package/docs/reference/interfaces/IConflictResponse.md +3 -11
  91. package/docs/reference/interfaces/ICreatedResponse.md +2 -2
  92. package/docs/reference/interfaces/IForbiddenResponse.md +2 -2
  93. package/docs/reference/interfaces/IHealthComponent.md +21 -0
  94. package/docs/reference/interfaces/IHostingComponent.md +73 -0
  95. package/docs/reference/interfaces/IHttpRequest.md +8 -8
  96. package/docs/reference/interfaces/IHttpRequestContext.md +12 -4
  97. package/docs/reference/interfaces/IHttpRequestPathParams.md +1 -1
  98. package/docs/reference/interfaces/IHttpRequestQuery.md +1 -1
  99. package/docs/reference/interfaces/IHttpResponse.md +6 -6
  100. package/docs/reference/interfaces/IHttpServerRequest.md +14 -14
  101. package/docs/reference/interfaces/IInformationComponent.md +14 -56
  102. package/docs/reference/interfaces/IInternalServerErrorResponse.md +2 -2
  103. package/docs/reference/interfaces/IMimeTypeProcessor.md +2 -2
  104. package/docs/reference/interfaces/INoContentRequest.md +8 -8
  105. package/docs/reference/interfaces/INoContentResponse.md +1 -1
  106. package/docs/reference/interfaces/INotFoundResponse.md +3 -3
  107. package/docs/reference/interfaces/INotImplementedResponse.md +19 -0
  108. package/docs/reference/interfaces/IOkResponse.md +1 -1
  109. package/docs/reference/interfaces/IRestRoute.md +47 -23
  110. package/docs/reference/interfaces/IRestRouteExample.md +3 -3
  111. package/docs/reference/interfaces/IRestRouteProcessor.md +49 -19
  112. package/docs/reference/interfaces/IRestRouteRequestExample.md +4 -4
  113. package/docs/reference/interfaces/IRestRouteResponseAttachmentOptions.md +6 -6
  114. package/docs/reference/interfaces/IRestRouteResponseExample.md +4 -4
  115. package/docs/reference/interfaces/IRestRouteResponseOptions.md +2 -2
  116. package/docs/reference/interfaces/IServerFavIconResponse.md +7 -7
  117. package/docs/reference/interfaces/IServerHealthResponse.md +11 -3
  118. package/docs/reference/interfaces/IServerInfo.md +2 -2
  119. package/docs/reference/interfaces/IServerInfoResponse.md +1 -1
  120. package/docs/reference/interfaces/IServerLivezResponse.md +23 -0
  121. package/docs/reference/interfaces/IServerReadyzResponse.md +23 -0
  122. package/docs/reference/interfaces/IServerRootResponse.md +13 -1
  123. package/docs/reference/interfaces/IServerSpecResponse.md +4 -4
  124. package/docs/reference/interfaces/ISocketRequestContext.md +17 -5
  125. package/docs/reference/interfaces/ISocketRoute.md +38 -14
  126. package/docs/reference/interfaces/ISocketRouteProcessor.md +42 -22
  127. package/docs/reference/interfaces/ISocketServerRequest.md +17 -17
  128. package/docs/reference/interfaces/ITag.md +2 -2
  129. package/docs/reference/interfaces/ITenant.md +59 -0
  130. package/docs/reference/interfaces/ITenantAdminComponent.md +193 -0
  131. package/docs/reference/interfaces/ITooManyRequestsResponse.md +19 -0
  132. package/docs/reference/interfaces/IUnauthorizedResponse.md +2 -2
  133. package/docs/reference/interfaces/IUnprocessableEntityResponse.md +2 -2
  134. package/docs/reference/interfaces/IUrlTransformerComponent.md +229 -0
  135. package/docs/reference/interfaces/IWebServer.md +34 -4
  136. package/docs/reference/interfaces/IWebServerOptions.md +12 -12
  137. package/docs/reference/type-aliases/HttpContextIdKeys.md +5 -0
  138. package/docs/reference/variables/HttpContextIdKeys.md +25 -0
  139. package/package.json +2 -2
  140. package/dist/es/factories/authenticationGeneratorFactory.js +0 -9
  141. package/dist/es/factories/authenticationGeneratorFactory.js.map +0 -1
  142. package/dist/es/models/client/IAuthenticationGenerator.js +0 -2
  143. package/dist/es/models/client/IAuthenticationGenerator.js.map +0 -1
  144. package/dist/es/models/services/IHealthInfo.js +0 -2
  145. package/dist/es/models/services/IHealthInfo.js.map +0 -1
  146. package/dist/es/models/services/healthStatus.js +0 -21
  147. package/dist/es/models/services/healthStatus.js.map +0 -1
  148. package/dist/types/factories/authenticationGeneratorFactory.d.ts +0 -6
  149. package/dist/types/models/client/IAuthenticationGenerator.d.ts +0 -14
  150. package/dist/types/models/services/IHealthInfo.d.ts +0 -27
  151. package/dist/types/models/services/healthStatus.d.ts +0 -21
  152. package/docs/reference/interfaces/IAuthenticationGenerator.md +0 -35
  153. package/docs/reference/interfaces/IHealthInfo.md +0 -37
  154. package/docs/reference/type-aliases/HealthStatus.md +0 -5
  155. package/docs/reference/variables/AuthenticationGeneratorFactory.md +0 -5
  156. package/docs/reference/variables/HealthStatus.md +0 -25
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN API Models
2
2
 
3
- Contains models for use with APIs.
3
+ This package provides shared API contracts, route types, and response models used across services and clients.
4
4
 
5
5
  ## Installation
6
6
 
@@ -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,10 +2,27 @@
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
  */
8
10
  export class HttpErrorHelper {
11
+ /**
12
+ * Mapping of error types to status codes.
13
+ */
14
+ static ERROR_TYPE_MAP = {
15
+ [GuardError.CLASS_NAME]: HttpStatusCode.badRequest,
16
+ [ValidationError.CLASS_NAME]: HttpStatusCode.badRequest,
17
+ [ConflictError.CLASS_NAME]: HttpStatusCode.conflict,
18
+ [AlreadyExistsError.CLASS_NAME]: HttpStatusCode.conflict,
19
+ [NotFoundError.CLASS_NAME]: HttpStatusCode.notFound,
20
+ [UnauthorizedError.CLASS_NAME]: HttpStatusCode.unauthorized,
21
+ [NotImplementedError.CLASS_NAME]: HttpStatusCode.notImplemented,
22
+ [UnprocessableError.CLASS_NAME]: HttpStatusCode.unprocessableEntity,
23
+ [TooManyRequestsError.CLASS_NAME]: HttpStatusCode.tooManyRequests,
24
+ [ForbiddenError.CLASS_NAME]: HttpStatusCode.forbidden
25
+ };
9
26
  /**
10
27
  * Process the errors from the routes.
11
28
  * @param err The error to process.
@@ -18,25 +35,21 @@ export class HttpErrorHelper {
18
35
  // types then set the http response code accordingly
19
36
  const flattened = BaseError.flatten(error);
20
37
  let httpStatusCode = HttpStatusCode.internalServerError;
21
- if (flattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME)) ||
22
- flattened.some(e => BaseError.isErrorName(e, ValidationError.CLASS_NAME))) {
23
- httpStatusCode = HttpStatusCode.badRequest;
24
- }
25
- else if (flattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME)) ||
26
- flattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))) {
27
- httpStatusCode = HttpStatusCode.conflict;
28
- }
29
- else if (flattened.some(e => BaseError.isErrorName(e, NotFoundError.CLASS_NAME))) {
30
- httpStatusCode = HttpStatusCode.notFound;
31
- }
32
- else if (flattened.some(e => BaseError.isErrorName(e, UnauthorizedError.CLASS_NAME))) {
33
- httpStatusCode = HttpStatusCode.unauthorized;
34
- }
35
- else if (flattened.some(e => BaseError.isErrorName(e, NotImplementedError.CLASS_NAME))) {
36
- httpStatusCode = HttpStatusCode.forbidden;
37
- }
38
- else if (flattened.some(e => BaseError.isErrorName(e, UnprocessableError.CLASS_NAME))) {
39
- httpStatusCode = HttpStatusCode.unprocessableEntity;
38
+ // First check the primary error, as we don't want to override that with a sub error
39
+ if (flattened.length > 0) {
40
+ const primaryError = flattened[0];
41
+ if (HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name]) {
42
+ httpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[primaryError.name];
43
+ }
44
+ // The primary error is still internal server error, check the sub errors
45
+ if (httpStatusCode === HttpStatusCode.internalServerError) {
46
+ for (const className in HttpErrorHelper.ERROR_TYPE_MAP) {
47
+ if (flattened.some(e => BaseError.isErrorName(e, className))) {
48
+ httpStatusCode = HttpErrorHelper.ERROR_TYPE_MAP[className];
49
+ break;
50
+ }
51
+ }
52
+ }
40
53
  }
41
54
  const returnError = error.toJsonObject(includeStack);
42
55
  return {
@@ -53,7 +66,8 @@ export class HttpErrorHelper {
53
66
  static buildResponse(response, error, statusCode) {
54
67
  response.headers ??= {};
55
68
  response.headers[HeaderTypes.ContentType] = `${MimeTypes.Json}; charset=utf-8`;
56
- response.body = error;
69
+ // Fastify treats an Error-typed body as a framework error and overrides the status with 500.
70
+ response.body = BaseError.fromError(error).toJsonObject();
57
71
  response.statusCode = statusCode;
58
72
  }
59
73
  }
@@ -1 +1 @@
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 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 * 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\t\tif (\n\t\t\tflattened.some(e => BaseError.isErrorName(e, GuardError.CLASS_NAME)) ||\n\t\t\tflattened.some(e => BaseError.isErrorName(e, ValidationError.CLASS_NAME))\n\t\t) {\n\t\t\thttpStatusCode = HttpStatusCode.badRequest;\n\t\t} else if (\n\t\t\tflattened.some(e => BaseError.isErrorName(e, ConflictError.CLASS_NAME)) ||\n\t\t\tflattened.some(e => BaseError.isErrorName(e, AlreadyExistsError.CLASS_NAME))\n\t\t) {\n\t\t\thttpStatusCode = HttpStatusCode.conflict;\n\t\t} else if (flattened.some(e => BaseError.isErrorName(e, NotFoundError.CLASS_NAME))) {\n\t\t\thttpStatusCode = HttpStatusCode.notFound;\n\t\t} else if (flattened.some(e => BaseError.isErrorName(e, UnauthorizedError.CLASS_NAME))) {\n\t\t\thttpStatusCode = HttpStatusCode.unauthorized;\n\t\t} else if (flattened.some(e => BaseError.isErrorName(e, NotImplementedError.CLASS_NAME))) {\n\t\t\thttpStatusCode = HttpStatusCode.forbidden;\n\t\t} else if (flattened.some(e => BaseError.isErrorName(e, UnprocessableError.CLASS_NAME))) {\n\t\t\thttpStatusCode = HttpStatusCode.unprocessableEntity;\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"]}
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\t// Fastify treats an Error-typed body as a framework error and overrides the status with 500.\n\t\tresponse.body = BaseError.fromError(error).toJsonObject();\n\t\tresponse.statusCode = statusCode;\n\t}\n}\n"]}
@@ -0,0 +1,105 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { Is, StringHelper } from "@twin.org/core";
4
+ /**
5
+ * Class to help with handling http URLs.
6
+ */
7
+ export class HttpUrlHelper {
8
+ /**
9
+ * Extract the origin from the url which includes protocol,host,port.
10
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/origin
11
+ * @param url The url to extract the origin from.
12
+ * @returns The extracted origin.
13
+ */
14
+ static extractOrigin(url) {
15
+ try {
16
+ const convertedUrl = new URL(url);
17
+ return convertedUrl.origin;
18
+ }
19
+ catch { }
20
+ }
21
+ /**
22
+ * Extract the path from the url.
23
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname
24
+ * @param url The url to extract the path from.
25
+ * @returns The extracted path.
26
+ */
27
+ static extractPath(url) {
28
+ try {
29
+ const convertedUrl = new URL(url);
30
+ return convertedUrl.pathname;
31
+ }
32
+ catch { }
33
+ }
34
+ /**
35
+ * Extract the search from the url.
36
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/search
37
+ * @param url The url to extract the search from.
38
+ * @returns The extracted search.
39
+ */
40
+ static extractSearch(url) {
41
+ try {
42
+ const convertedUrl = new URL(url);
43
+ return convertedUrl.search;
44
+ }
45
+ catch { }
46
+ }
47
+ /**
48
+ * Extract the path and search from the url.
49
+ * @param url The url to extract the path and search from.
50
+ * @returns The extracted path and search.
51
+ */
52
+ static extractPathAndSearch(url) {
53
+ try {
54
+ const convertedUrl = new URL(url);
55
+ return `${convertedUrl.pathname}${convertedUrl.search}`;
56
+ }
57
+ catch { }
58
+ }
59
+ /**
60
+ * Combine the urls parts.
61
+ * @param origin The origin to combine.
62
+ * @param pathAndSearch The path and search to combine.
63
+ * @returns The combined parts.
64
+ */
65
+ static combineParts(origin, pathAndSearch) {
66
+ if (Is.string(origin) && Is.string(pathAndSearch)) {
67
+ return `${StringHelper.trimTrailingSlashes(origin)}/${StringHelper.trimLeadingSlashes(pathAndSearch)}`;
68
+ }
69
+ }
70
+ /**
71
+ * Encode a single URL path segment per RFC 3986 §3.3.
72
+ * Unlike encodeURIComponent, sub-delimiters ($ & + , ; =) and the colon and
73
+ * at-sign characters that are valid unencoded in path segments are preserved.
74
+ * @see https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
75
+ * @param segment The raw path segment value to encode.
76
+ * @returns The percent-encoded path segment.
77
+ */
78
+ static encodeUriPathSegment(segment) {
79
+ // RFC 3986 §3.3: only encode characters outside the allowed path segment set.
80
+ // Allowed: unreserved (A-Za-z0-9 - . _ ~), sub-delimiters (! $ & ' ( ) * + , ; =), and : @
81
+ return segment.replace(/[^\w!$&'()*+,.:;=@~-]/g, ch => encodeURIComponent(ch));
82
+ }
83
+ /**
84
+ * Replace the origin in the url.
85
+ * @param url The url to replace the origin in.
86
+ * @param newOrigin The new origin to use.
87
+ * @returns The url with the replaced origin.
88
+ */
89
+ static replaceOrigin(url, newOrigin) {
90
+ if (!Is.stringValue(url) || !Is.stringValue(newOrigin) || !newOrigin.startsWith("http")) {
91
+ return url;
92
+ }
93
+ try {
94
+ const parsedUrl = new URL(url.startsWith("/") ? `http://placeholder${url}` : url);
95
+ const newParsedUrl = new URL(newOrigin);
96
+ parsedUrl.protocol = newParsedUrl.protocol;
97
+ parsedUrl.host = newParsedUrl.host;
98
+ parsedUrl.port = newParsedUrl.port;
99
+ return parsedUrl.toString();
100
+ }
101
+ catch { }
102
+ return url;
103
+ }
104
+ }
105
+ //# sourceMappingURL=httpUrlHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpUrlHelper.js","sourceRoot":"","sources":["../../../src/helpers/httpUrlHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAElD;;GAEG;AACH,MAAM,OAAO,aAAa;IACzB;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,GAAW;QACtC,IAAI,CAAC;YACJ,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,YAAY,CAAC,MAAM,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,GAAW;QACpC,IAAI,CAAC;YACJ,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,YAAY,CAAC,QAAQ,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,GAAW;QACtC,IAAI,CAAC;YACJ,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,YAAY,CAAC,MAAM,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,oBAAoB,CAAC,GAAW;QAC7C,IAAI,CAAC;YACJ,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,OAAO,GAAG,YAAY,CAAC,QAAQ,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAAC,MAAc,EAAE,aAAqB;QAC/D,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACnD,OAAO,GAAG,YAAY,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC;QACxG,CAAC;IACF,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,oBAAoB,CAAC,OAAe;QACjD,8EAA8E;QAC9E,2FAA2F;QAC3F,OAAO,OAAO,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CAAC,GAAW,EAAE,SAAkB;QAC1D,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACzF,OAAO,GAAG,CAAC;QACZ,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAClF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;YACxC,SAAS,CAAC,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC;YAC3C,SAAS,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;YACnC,SAAS,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;YACnC,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QAEV,OAAO,GAAG,CAAC;IACZ,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Is, StringHelper } from \"@twin.org/core\";\n\n/**\n * Class to help with handling http URLs.\n */\nexport class HttpUrlHelper {\n\t/**\n\t * Extract the origin from the url which includes protocol,host,port.\n\t * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/origin\n\t * @param url The url to extract the origin from.\n\t * @returns The extracted origin.\n\t */\n\tpublic static extractOrigin(url: string): string | undefined {\n\t\ttry {\n\t\t\tconst convertedUrl = new URL(url);\n\t\t\treturn convertedUrl.origin;\n\t\t} catch {}\n\t}\n\n\t/**\n\t * Extract the path from the url.\n\t * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname\n\t * @param url The url to extract the path from.\n\t * @returns The extracted path.\n\t */\n\tpublic static extractPath(url: string): string | undefined {\n\t\ttry {\n\t\t\tconst convertedUrl = new URL(url);\n\t\t\treturn convertedUrl.pathname;\n\t\t} catch {}\n\t}\n\n\t/**\n\t * Extract the search from the url.\n\t * @see https://developer.mozilla.org/en-US/docs/Web/API/URL/search\n\t * @param url The url to extract the search from.\n\t * @returns The extracted search.\n\t */\n\tpublic static extractSearch(url: string): string | undefined {\n\t\ttry {\n\t\t\tconst convertedUrl = new URL(url);\n\t\t\treturn convertedUrl.search;\n\t\t} catch {}\n\t}\n\n\t/**\n\t * Extract the path and search from the url.\n\t * @param url The url to extract the path and search from.\n\t * @returns The extracted path and search.\n\t */\n\tpublic static extractPathAndSearch(url: string): string | undefined {\n\t\ttry {\n\t\t\tconst convertedUrl = new URL(url);\n\t\t\treturn `${convertedUrl.pathname}${convertedUrl.search}`;\n\t\t} catch {}\n\t}\n\n\t/**\n\t * Combine the urls parts.\n\t * @param origin The origin to combine.\n\t * @param pathAndSearch The path and search to combine.\n\t * @returns The combined parts.\n\t */\n\tpublic static combineParts(origin: string, pathAndSearch: string): string | undefined {\n\t\tif (Is.string(origin) && Is.string(pathAndSearch)) {\n\t\t\treturn `${StringHelper.trimTrailingSlashes(origin)}/${StringHelper.trimLeadingSlashes(pathAndSearch)}`;\n\t\t}\n\t}\n\n\t/**\n\t * Encode a single URL path segment per RFC 3986 §3.3.\n\t * Unlike encodeURIComponent, sub-delimiters ($ & + , ; =) and the colon and\n\t * at-sign characters that are valid unencoded in path segments are preserved.\n\t * @see https://datatracker.ietf.org/doc/html/rfc3986#section-3.3\n\t * @param segment The raw path segment value to encode.\n\t * @returns The percent-encoded path segment.\n\t */\n\tpublic static encodeUriPathSegment(segment: string): string {\n\t\t// RFC 3986 §3.3: only encode characters outside the allowed path segment set.\n\t\t// Allowed: unreserved (A-Za-z0-9 - . _ ~), sub-delimiters (! $ & ' ( ) * + , ; =), and : @\n\t\treturn segment.replace(/[^\\w!$&'()*+,.:;=@~-]/g, ch => encodeURIComponent(ch));\n\t}\n\n\t/**\n\t * Replace the origin in the url.\n\t * @param url The url to replace the origin in.\n\t * @param newOrigin The new origin to use.\n\t * @returns The url with the replaced origin.\n\t */\n\tpublic static replaceOrigin(url: string, newOrigin?: string): string {\n\t\tif (!Is.stringValue(url) || !Is.stringValue(newOrigin) || !newOrigin.startsWith(\"http\")) {\n\t\t\treturn url;\n\t\t}\n\n\t\ttry {\n\t\t\tconst parsedUrl = new URL(url.startsWith(\"/\") ? `http://placeholder${url}` : url);\n\t\t\tconst newParsedUrl = new URL(newOrigin);\n\t\t\tparsedUrl.protocol = newParsedUrl.protocol;\n\t\t\tparsedUrl.host = newParsedUrl.host;\n\t\t\tparsedUrl.port = newParsedUrl.port;\n\t\t\treturn parsedUrl.toString();\n\t\t} catch {}\n\n\t\treturn url;\n\t}\n}\n"]}
package/dist/es/index.js CHANGED
@@ -1,19 +1,23 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- export * from "./factories/authenticationGeneratorFactory.js";
3
+ export * from "./errors/forbiddenError.js";
4
+ export * from "./errors/tooManyRequestsError.js";
4
5
  export * from "./factories/mimeTypeProcessorFactory.js";
5
6
  export * from "./factories/restRouteProcessorFactory.js";
6
7
  export * from "./factories/socketRouteProcessorFactory.js";
7
8
  export * from "./helpers/httpErrorHelper.js";
8
9
  export * from "./helpers/httpParameterHelper.js";
10
+ export * from "./helpers/httpUrlHelper.js";
9
11
  export * from "./models/api/IServerFavIconResponse.js";
10
12
  export * from "./models/api/IServerHealthResponse.js";
11
13
  export * from "./models/api/IServerInfoResponse.js";
14
+ export * from "./models/api/IServerLivezResponse.js";
15
+ export * from "./models/api/IServerReadyzResponse.js";
12
16
  export * from "./models/api/IServerRootResponse.js";
13
17
  export * from "./models/api/IServerSpecResponse.js";
14
- export * from "./models/client/IAuthenticationGenerator.js";
15
18
  export * from "./models/config/IBaseRestClientConfig.js";
16
19
  export * from "./models/config/IBaseSocketClientConfig.js";
20
+ export * from "./models/httpContextIdKeys.js";
17
21
  export * from "./models/protocol/IHttpRequest.js";
18
22
  export * from "./models/protocol/IHttpRequestContext.js";
19
23
  export * from "./models/protocol/IHttpRequestPathParams.js";
@@ -28,6 +32,8 @@ export * from "./models/responses/errors/IConflictResponse.js";
28
32
  export * from "./models/responses/errors/IForbiddenResponse.js";
29
33
  export * from "./models/responses/errors/IInternalServerErrorResponse.js";
30
34
  export * from "./models/responses/errors/INotFoundResponse.js";
35
+ export * from "./models/responses/errors/INotImplementedResponse.js";
36
+ export * from "./models/responses/errors/ITooManyRequestsResponse.js";
31
37
  export * from "./models/responses/errors/IUnauthorizedResponse.js";
32
38
  export * from "./models/responses/errors/IUnprocessableEntityResponse.js";
33
39
  export * from "./models/responses/success/IAcceptedResponse.js";
@@ -52,8 +58,11 @@ export * from "./models/server/IRestRouteProcessor.js";
52
58
  export * from "./models/server/ISocketRouteProcessor.js";
53
59
  export * from "./models/server/IWebServer.js";
54
60
  export * from "./models/server/IWebServerOptions.js";
55
- export * from "./models/services/healthStatus.js";
56
- export * from "./models/services/IHealthInfo.js";
61
+ export * from "./models/services/IHealthComponent.js";
62
+ export * from "./models/services/IHostingComponent.js";
57
63
  export * from "./models/services/IInformationComponent.js";
64
+ export * from "./models/services/IUrlTransformerComponent.js";
58
65
  export * from "./models/services/IServerInfo.js";
66
+ export * from "./models/services/ITenant.js";
67
+ export * from "./models/services/ITenantAdminComponent.js";
59
68
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,+CAA+C,CAAC;AAC9D,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AACtD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC;AACpD,cAAc,6CAA6C,CAAC;AAC5D,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,kCAAkC,CAAC;AACjD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,kCAAkC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./factories/authenticationGeneratorFactory.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 \"./models/api/IServerFavIconResponse.js\";\nexport * from \"./models/api/IServerHealthResponse.js\";\nexport * from \"./models/api/IServerInfoResponse.js\";\nexport * from \"./models/api/IServerRootResponse.js\";\nexport * from \"./models/api/IServerSpecResponse.js\";\nexport * from \"./models/client/IAuthenticationGenerator.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/IHealthInfo.js\";\nexport * from \"./models/services/IInformationComponent.js\";\nexport * from \"./models/services/IServerInfo.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,uCAAuC,CAAC;AACtD,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,uCAAuC,CAAC;AACtD,cAAc,wCAAwC,CAAC;AACvD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,+CAA+C,CAAC;AAC9D,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/IServerReadyzResponse.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/IHealthComponent.js\";\nexport * from \"./models/services/IHostingComponent.js\";\nexport * from \"./models/services/IInformationComponent.js\";\nexport * from \"./models/services/IUrlTransformerComponent.js\";\nexport * from \"./models/services/IServerInfo.js\";\nexport * from \"./models/services/ITenant.js\";\nexport * from \"./models/services/ITenantAdminComponent.js\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IServerHealthResponse.js","sourceRoot":"","sources":["../../../../src/models/api/IServerHealthResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHealthInfo } from \"../services/IHealthInfo.js\";\n\n/**\n * The health of the server.\n */\nexport interface IServerHealthResponse {\n\t/**\n\t * The information for the server.\n\t */\n\tbody: IHealthInfo;\n}\n"]}
1
+ {"version":3,"file":"IServerHealthResponse.js","sourceRoot":"","sources":["../../../../src/models/api/IServerHealthResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HealthStatus, IHealth } from \"@twin.org/core\";\n\n/**\n * The health of the server.\n */\nexport interface IServerHealthResponse {\n\t/**\n\t * The health for the server.\n\t */\n\tbody: { status: HealthStatus; components: IHealth[] };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IServerLivezResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IServerLivezResponse.js","sourceRoot":"","sources":["../../../../src/models/api/IServerLivezResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The livez of the server.\n */\nexport interface IServerLivezResponse {\n\t/**\n\t * The headers for the response.\n\t */\n\theaders: {\n\t\t[HeaderTypes.ContentType]: typeof MimeTypes.PlainText;\n\t};\n\n\t/**\n\t * The livez information for the server.\n\t */\n\tbody: \"alive\" | \"dead\";\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IServerReadyzResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IServerReadyzResponse.js","sourceRoot":"","sources":["../../../../src/models/api/IServerReadyzResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The readyz of the server.\n */\nexport interface IServerReadyzResponse {\n\t/**\n\t * The headers for the response.\n\t */\n\theaders: {\n\t\t[HeaderTypes.ContentType]: typeof MimeTypes.PlainText;\n\t};\n\n\t/**\n\t * The readyz information for the server.\n\t */\n\tbody: \"ready\" | \"not ready\";\n}\n"]}
@@ -1,4 +1,2 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
1
  export {};
4
2
  //# sourceMappingURL=IServerRootResponse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IServerRootResponse.js","sourceRoot":"","sources":["../../../../src/models/api/IServerRootResponse.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The root text for the server.\n */\nexport interface IServerRootResponse {\n\t/**\n\t * The root text for the server.\n\t */\n\tbody: string;\n}\n"]}
1
+ {"version":3,"file":"IServerRootResponse.js","sourceRoot":"","sources":["../../../../src/models/api/IServerRootResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The root text for the server.\n */\nexport interface IServerRootResponse {\n\t/**\n\t * The headers for the response.\n\t */\n\theaders: {\n\t\t[HeaderTypes.ContentType]: typeof MimeTypes.PlainText;\n\t};\n\n\t/**\n\t * The root text for the server.\n\t */\n\tbody: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IBaseRestClientConfig.js","sourceRoot":"","sources":["../../../../src/models/config/IBaseRestClientConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * Definition for the configuration of a rest client.\n */\nexport interface IBaseRestClientConfig {\n\t/**\n\t * The endpoint where the api is hosted.\n\t */\n\tendpoint: string;\n\n\t/**\n\t * The prefix to the routes.\n\t */\n\tpathPrefix?: string;\n\n\t/**\n\t * The headers to include in requests.\n\t */\n\theaders?: IHttpHeaders;\n\n\t/**\n\t * Timeout for requests in ms.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Include credentials in the request, defaults to true.\n\t */\n\tincludeCredentials?: boolean;\n}\n"]}
1
+ {"version":3,"file":"IBaseRestClientConfig.js","sourceRoot":"","sources":["../../../../src/models/config/IBaseRestClientConfig.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IError } from \"@twin.org/core\";\nimport type { IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * Definition for the configuration of a rest client.\n */\nexport interface IBaseRestClientConfig {\n\t/**\n\t * The endpoint where the api is hosted.\n\t */\n\tendpoint: string;\n\n\t/**\n\t * The prefix to the routes.\n\t */\n\tpathPrefix?: string;\n\n\t/**\n\t * The headers to include in requests.\n\t */\n\theaders?: IHttpHeaders;\n\n\t/**\n\t * Timeout for requests in ms.\n\t */\n\ttimeout?: number;\n\n\t/**\n\t * Include credentials in the request, defaults to true.\n\t */\n\tincludeCredentials?: boolean;\n\n\t/**\n\t * Hook to provide headers asynchronously.\n\t * @returns A promise that resolves to the headers.\n\t */\n\tcustomHeaders?: () => Promise<IHttpHeaders>;\n\n\t/**\n\t * Hook to provide an authorization header value asynchronously.\n\t * @returns A promise that resolves to the authorization header value.\n\t */\n\tcustomAuthHeader?: () => Promise<string>;\n\n\t/**\n\t * Hook to handle authorization failures asynchronously.\n\t * @returns A promise that resolves when the auth failure handling is complete.\n\t */\n\tonAuthFailure?: (err: IError) => Promise<void>;\n}\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":"IHttpRequestContext.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpRequestContext.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHttpServerRequest } from \"./IHttpServerRequest.js\";\n\n/**\n * Context data from the HTTP request.\n */\nexport interface IHttpRequestContext {\n\t/**\n\t * The raw HTTP request.\n\t */\n\tserverRequest: IHttpServerRequest;\n\n\t/**\n\t * The state handed through the processors.\n\t */\n\tprocessorState: { [id: string]: unknown };\n\n\t/**\n\t * Logging component type for the request.\n\t */\n\tloggingComponentType?: string;\n}\n"]}
1
+ {"version":3,"file":"IHttpRequestContext.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpRequestContext.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IHttpServerRequest } from \"./IHttpServerRequest.js\";\n\n/**\n * Context data from the HTTP request.\n */\nexport interface IHttpRequestContext {\n\t/**\n\t * The raw HTTP request.\n\t */\n\tserverRequest: IHttpServerRequest;\n\n\t/**\n\t * The state handed through the processors.\n\t */\n\tprocessorState: { [id: string]: unknown };\n\n\t/**\n\t * Logging component type for the request.\n\t */\n\tloggingComponentType?: string;\n\n\t/**\n\t * Hosting component type for the request.\n\t */\n\thostingComponentType?: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IHttpRequestPathParams.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpRequestPathParams.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Model for the standard parameters for an http request.\n */\nexport interface IHttpRequestPathParams {\n\t[id: string]: string | number | boolean;\n}\n"]}
1
+ {"version":3,"file":"IHttpRequestPathParams.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpRequestPathParams.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Model for the standard parameters for an http request.\n */\nexport interface IHttpRequestPathParams {\n\t[id: string]: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IHttpRequestQuery.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpRequestQuery.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Model used for Http request query parameters.\n */\nexport interface IHttpRequestQuery {\n\t[id: string]: string | number | boolean;\n}\n"]}
1
+ {"version":3,"file":"IHttpRequestQuery.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpRequestQuery.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Model used for Http request query parameters.\n */\nexport interface IHttpRequestQuery {\n\t[id: string]: string;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IHttpServerRequest.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpServerRequest.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HttpMethod } from \"@twin.org/web\";\nimport type { IHttpRequest } from \"./IHttpRequest.js\";\n\n/**\n * Model for the standard parameters for an http request.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface IHttpServerRequest<T = any> extends IHttpRequest<T> {\n\t/**\n\t * The request method.\n\t */\n\tmethod?: HttpMethod;\n\n\t/**\n\t * The request url.\n\t */\n\turl?: string;\n}\n"]}
1
+ {"version":3,"file":"IHttpServerRequest.js","sourceRoot":"","sources":["../../../../src/models/protocol/IHttpServerRequest.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HttpMethod } from \"@twin.org/web\";\nimport type { IHttpRequest } from \"./IHttpRequest.js\";\n\n/**\n * Model for the standard parameters for an http request.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface IHttpServerRequest<T = any> extends IHttpRequest<T> {\n\t/**\n\t * The request url.\n\t */\n\turl: string;\n\n\t/**\n\t * The request method.\n\t */\n\tmethod?: HttpMethod;\n}\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 & {\n\t\t/**\n\t\t * The conflicting items.\n\t\t */\n\t\tconflicts: string[];\n\t};\n}\n"]}
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=INotImplementedResponse.js.map
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ITooManyRequestsResponse.js.map
@@ -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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IBaseRoute.js","sourceRoot":"","sources":["../../../../src/models/routes/IBaseRoute.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface which defines a route.\n */\nexport interface IBaseRoute {\n\t/**\n\t * The id of the operation.\n\t */\n\toperationId: string;\n\n\t/**\n\t * The path to use for routing.\n\t */\n\tpath: string;\n\n\t/**\n\t * Skips the authentication for this route.\n\t */\n\tskipAuth?: boolean;\n\n\t/**\n\t * The features supported by additional processors to run for this route.\n\t */\n\tprocessorFeatures?: string[];\n\n\t/**\n\t * The data for additional processors to run for this route.\n\t */\n\tprocessorData?: {\n\t\t[key: string]: unknown;\n\t};\n}\n"]}
1
+ {"version":3,"file":"IBaseRoute.js","sourceRoot":"","sources":["../../../../src/models/routes/IBaseRoute.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface which defines a route.\n */\nexport interface IBaseRoute {\n\t/**\n\t * The id of the operation.\n\t */\n\toperationId: string;\n\n\t/**\n\t * The path to use for routing.\n\t */\n\tpath: string;\n\n\t/**\n\t * Skips the authentication requirement for this route.\n\t */\n\tskipAuth?: boolean;\n\n\t/**\n\t * Skips the tenant requirement for this route.\n\t */\n\tskipTenant?: boolean;\n\n\t/**\n\t * The user must have one of the specified scopes to access the route.\n\t */\n\trequiredScope?: string[];\n\n\t/**\n\t * The features supported by additional processors to run for this route.\n\t */\n\tprocessorFeatures?: string[];\n\n\t/**\n\t * The data for additional processors to run for this route.\n\t */\n\tprocessorData?: {\n\t\t[key: string]: unknown;\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IBaseRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/IBaseRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IContextIds } from \"@twin.org/context\";\nimport type { IComponent } from \"@twin.org/core\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { IHttpServerRequest } from \"../protocol/IHttpServerRequest.js\";\nimport type { IBaseRoute } from \"../routes/IBaseRoute.js\";\n\n/**\n * The definition for a base processor for handling REST routes.\n */\nexport interface IBaseRouteProcessor<T = IBaseRoute, R = IHttpServerRequest> extends IComponent {\n\t/**\n\t * Features supported by this processor.\n\t * If a route has any of these features listed, this processor will be run for that route.\n\t * If this is not implemented, the processor will run for all routes.\n\t * @returns The features supported by this processor.\n\t */\n\tfeatures?(): string[];\n\n\t/**\n\t * Pre process the REST request for the specified route.\n\t * @param request The request to handle.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param contextIds The context IDs of the request.\n\t * @param processorState The state handed through the processors.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpre?(\n\t\trequest: R,\n\t\tresponse: IHttpResponse,\n\t\troute: T | undefined,\n\t\tcontextIds: IContextIds,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n\n\t/**\n\t * Post process the REST request for the specified route.\n\t * @param request The request to handle.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param contextIds The context IDs of the request.\n\t * @param processorState The state handed through the processors.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpost?(\n\t\trequest: R,\n\t\tresponse: IHttpResponse,\n\t\troute: T | undefined,\n\t\tcontextIds: IContextIds,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"IBaseRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/IBaseRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IContextIds } from \"@twin.org/context\";\nimport type { IComponent } from \"@twin.org/core\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { IHttpServerRequest } from \"../protocol/IHttpServerRequest.js\";\nimport type { IBaseRoute } from \"../routes/IBaseRoute.js\";\n\n/**\n * The definition for a base processor for handling REST routes.\n */\nexport interface IBaseRouteProcessor<T = IBaseRoute, R = IHttpServerRequest> extends IComponent {\n\t/**\n\t * Features supported by this processor.\n\t * If a route has any of these features listed, this processor will be run for that route.\n\t * If this is not implemented, the processor will run for all routes.\n\t * @returns The features supported by this processor.\n\t */\n\tfeatures?(): string[];\n\n\t/**\n\t * Pre process the REST request for the specified route.\n\t * @param request The request to handle.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param contextIds The context IDs of the request.\n\t * @param processorState The state handed through the processors.\n\t * @param componentTypes The component types for the request.\n\t * @param componentTypes.loggingComponentType The logging component type.\n\t * @param componentTypes.hostingComponentType The hosting component type.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpre?(\n\t\trequest: R,\n\t\tresponse: IHttpResponse,\n\t\troute: T | undefined,\n\t\tcontextIds: IContextIds,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tcomponentTypes?: {\n\t\t\tloggingComponentType?: string;\n\t\t\thostingComponentType?: string;\n\t\t}\n\t): Promise<void>;\n\n\t/**\n\t * Post process the REST request for the specified route.\n\t * @param request The request to handle.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param contextIds The context IDs of the request.\n\t * @param processorState The state handed through the processors.\n\t * @param componentTypes The component types for the request.\n\t * @param componentTypes.loggingComponentType The logging component type.\n\t * @param componentTypes.hostingComponentType The hosting component type.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpost?(\n\t\trequest: R,\n\t\tresponse: IHttpResponse,\n\t\troute: T | undefined,\n\t\tcontextIds: IContextIds,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tcomponentTypes?: {\n\t\t\tloggingComponentType?: string;\n\t\t\thostingComponentType?: string;\n\t\t}\n\t): Promise<void>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IRestRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/IRestRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRouteProcessor } from \"./IBaseRouteProcessor.js\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { IHttpServerRequest } from \"../protocol/IHttpServerRequest.js\";\nimport type { IRestRoute } from \"../routes/IRestRoute.js\";\n\n/**\n * The definition for a processor for handling REST routes.\n */\nexport interface IRestRouteProcessor extends IBaseRouteProcessor<IRestRoute> {\n\t/**\n\t * Process the REST request for the specified route.\n\t * @param request The request to handle.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param processorState The state handed through the processors.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tprocess?(\n\t\trequest: IHttpServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: IRestRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"IRestRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/IRestRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRouteProcessor } from \"./IBaseRouteProcessor.js\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { IHttpServerRequest } from \"../protocol/IHttpServerRequest.js\";\nimport type { IRestRoute } from \"../routes/IRestRoute.js\";\n\n/**\n * The definition for a processor for handling REST routes.\n */\nexport interface IRestRouteProcessor extends IBaseRouteProcessor<IRestRoute> {\n\t/**\n\t * Process the REST request for the specified route.\n\t * @param request The request to handle.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param processorState The state handed through the processors.\n\t * @param componentTypes The component types for the request.\n\t * @param componentTypes.loggingComponentType The logging component type.\n\t * @param componentTypes.hostingComponentType The hosting component type.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tprocess?(\n\t\trequest: IHttpServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: IRestRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tcomponentTypes?: {\n\t\t\tloggingComponentType?: string;\n\t\t\thostingComponentType?: string;\n\t\t}\n\t): Promise<void>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ISocketRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/ISocketRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRouteProcessor } from \"./IBaseRouteProcessor.js\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { ISocketServerRequest } from \"../protocol/ISocketServerRequest.js\";\nimport type { ISocketRoute } from \"../routes/ISocketRoute.js\";\n\n/**\n * The definition for a processor for handling socket routes.\n */\nexport interface ISocketRouteProcessor\n\textends IBaseRouteProcessor<ISocketRoute, ISocketServerRequest> {\n\t/**\n\t * Process the connected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tconnected?(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n\n\t/**\n\t * Process the disconnected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tdisconnected?(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n\n\t/**\n\t * Process the REST request for the specified route.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param processorState The state handed through the processors.\n\t * @param responseEmitter The function to emit a response.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tprocess?(\n\t\trequest: ISocketServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: ISocketRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tresponseEmitter: (topic: string, response: IHttpResponse) => Promise<void>,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"ISocketRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/ISocketRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRouteProcessor } from \"./IBaseRouteProcessor.js\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { ISocketServerRequest } from \"../protocol/ISocketServerRequest.js\";\nimport type { ISocketRoute } from \"../routes/ISocketRoute.js\";\n\n/**\n * The definition for a processor for handling socket routes.\n */\nexport interface ISocketRouteProcessor extends IBaseRouteProcessor<\n\tISocketRoute,\n\tISocketServerRequest\n> {\n\t/**\n\t * Process the connected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tconnected?(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n\n\t/**\n\t * Process the disconnected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tdisconnected?(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n\n\t/**\n\t * Process the REST request for the specified route.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param processorState The state handed through the processors.\n\t * @param responseEmitter The function to emit a response.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tprocess?(\n\t\trequest: ISocketServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: ISocketRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tresponseEmitter: (topic: string, response: IHttpResponse) => Promise<void>,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IWebServer.js","sourceRoot":"","sources":["../../../../src/models/server/IWebServer.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteProcessor } from \"./IRestRouteProcessor.js\";\nimport type { ISocketRouteProcessor } from \"./ISocketRouteProcessor.js\";\nimport type { IWebServerOptions } from \"./IWebServerOptions.js\";\nimport type { IRestRoute } from \"../routes/IRestRoute.js\";\nimport type { ISocketRoute } from \"../routes/ISocketRoute.js\";\n\n/**\n * Interface describing a web server.\n */\nexport interface IWebServer<T> {\n\t/**\n\t * Get the web server instance.\n\t * @returns The web server instance.\n\t */\n\tgetInstance(): T;\n\n\t/**\n\t * Build the server.\n\t * @param restRouteProcessors The processors for incoming requests over REST.\n\t * @param restRoutes The REST routes.\n\t * @param socketRouteProcessors The processors for incoming requests over Sockets.\n\t * @param socketRoutes The socket routes.\n\t * @param options Options for building the server.\n\t * @returns Nothing.\n\t */\n\tbuild(\n\t\trestRouteProcessors?: IRestRouteProcessor[],\n\t\trestRoutes?: IRestRoute[],\n\t\tsocketRouteProcessors?: ISocketRouteProcessor[],\n\t\tsocketRoutes?: ISocketRoute[],\n\t\toptions?: IWebServerOptions\n\t): Promise<void>;\n\n\t/**\n\t * Start the server.\n\t * @returns Nothing.\n\t */\n\tstart(): Promise<void>;\n\n\t/**\n\t * Stop the server.\n\t * @returns Nothing.\n\t */\n\tstop(): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"IWebServer.js","sourceRoot":"","sources":["../../../../src/models/server/IWebServer.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent, IHealth } from \"@twin.org/core\";\nimport type { IRestRouteProcessor } from \"./IRestRouteProcessor.js\";\nimport type { ISocketRouteProcessor } from \"./ISocketRouteProcessor.js\";\nimport type { IWebServerOptions } from \"./IWebServerOptions.js\";\nimport type { IRestRoute } from \"../routes/IRestRoute.js\";\nimport type { ISocketRoute } from \"../routes/ISocketRoute.js\";\n\n/**\n * Interface describing a web server.\n */\nexport interface IWebServer<T> extends IComponent {\n\t/**\n\t * Get the web server instance.\n\t * @returns The web server instance.\n\t */\n\tgetInstance(): T;\n\n\t/**\n\t * Build the server.\n\t * @param restRouteProcessors The processors for incoming requests over REST.\n\t * @param restRoutes The REST routes.\n\t * @param socketRouteProcessors The processors for incoming requests over Sockets.\n\t * @param socketRoutes The socket routes.\n\t * @param options Options for building the server.\n\t * @returns Nothing.\n\t */\n\tbuild(\n\t\trestRouteProcessors?: IRestRouteProcessor[],\n\t\trestRoutes?: IRestRoute[],\n\t\tsocketRouteProcessors?: ISocketRouteProcessor[],\n\t\tsocketRoutes?: ISocketRoute[],\n\t\toptions?: IWebServerOptions\n\t): Promise<void>;\n\n\t/**\n\t * Start the server.\n\t * @returns Nothing.\n\t */\n\tstart(): Promise<void>;\n\n\t/**\n\t * Stop the server.\n\t * @returns Nothing.\n\t */\n\tstop(): Promise<void>;\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component, can return multiple entries for elements within the component.\n\t */\n\thealth(): Promise<IHealth[]>;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IHealthComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IHealthComponent.js","sourceRoot":"","sources":["../../../../src/models/services/IHealthComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { HealthStatus, IComponent, IHealth } from \"@twin.org/core\";\n\n/**\n * The health component for the server.\n */\nexport interface IHealthComponent extends IComponent {\n\t/**\n\t * Get the server health.\n\t * @returns The service health.\n\t */\n\thealthStatus(): Promise<{ status: HealthStatus; components: IHealth[] }>;\n}\n"]}