@privateaim/server-http-kit 0.7.0

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 (157) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/LICENSE +202 -0
  3. package/README.md +6 -0
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +28 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/middlewares/basic.d.ts +3 -0
  9. package/dist/middlewares/basic.d.ts.map +1 -0
  10. package/dist/middlewares/basic.js +14 -0
  11. package/dist/middlewares/basic.js.map +1 -0
  12. package/dist/middlewares/cors.d.ts +3 -0
  13. package/dist/middlewares/cors.d.ts.map +1 -0
  14. package/dist/middlewares/cors.js +23 -0
  15. package/dist/middlewares/cors.js.map +1 -0
  16. package/dist/middlewares/decorators.d.ts +4 -0
  17. package/dist/middlewares/decorators.d.ts.map +1 -0
  18. package/dist/middlewares/decorators.js +39 -0
  19. package/dist/middlewares/decorators.js.map +1 -0
  20. package/dist/middlewares/error.d.ts +3 -0
  21. package/dist/middlewares/error.d.ts.map +1 -0
  22. package/dist/middlewares/error.js +50 -0
  23. package/dist/middlewares/error.js.map +1 -0
  24. package/dist/middlewares/force-logged-in.d.ts +6 -0
  25. package/dist/middlewares/force-logged-in.d.ts.map +1 -0
  26. package/dist/middlewares/force-logged-in.js +22 -0
  27. package/dist/middlewares/force-logged-in.js.map +1 -0
  28. package/dist/middlewares/index.d.ts +9 -0
  29. package/dist/middlewares/index.d.ts.map +1 -0
  30. package/dist/middlewares/index.js +31 -0
  31. package/dist/middlewares/index.js.map +1 -0
  32. package/dist/middlewares/module.d.ts +4 -0
  33. package/dist/middlewares/module.d.ts.map +1 -0
  34. package/dist/middlewares/module.js +46 -0
  35. package/dist/middlewares/module.js.map +1 -0
  36. package/dist/middlewares/prometheus.d.ts +3 -0
  37. package/dist/middlewares/prometheus.d.ts.map +1 -0
  38. package/dist/middlewares/prometheus.js +14 -0
  39. package/dist/middlewares/prometheus.js.map +1 -0
  40. package/dist/middlewares/rate-limit.d.ts +3 -0
  41. package/dist/middlewares/rate-limit.d.ts.map +1 -0
  42. package/dist/middlewares/rate-limit.js +40 -0
  43. package/dist/middlewares/rate-limit.js.map +1 -0
  44. package/dist/middlewares/swagger.d.ts +4 -0
  45. package/dist/middlewares/swagger.d.ts.map +1 -0
  46. package/dist/middlewares/swagger.js +29 -0
  47. package/dist/middlewares/swagger.js.map +1 -0
  48. package/dist/middlewares/types.d.ts +20 -0
  49. package/dist/middlewares/types.d.ts.map +1 -0
  50. package/dist/middlewares/types.js +9 -0
  51. package/dist/middlewares/types.js.map +1 -0
  52. package/dist/request/env.d.ts +6 -0
  53. package/dist/request/env.d.ts.map +1 -0
  54. package/dist/request/env.js +21 -0
  55. package/dist/request/env.js.map +1 -0
  56. package/dist/request/index.d.ts +3 -0
  57. package/dist/request/index.d.ts.map +1 -0
  58. package/dist/request/index.js +25 -0
  59. package/dist/request/index.js.map +1 -0
  60. package/dist/request/types.d.ts +15 -0
  61. package/dist/request/types.d.ts.map +1 -0
  62. package/dist/request/types.js +9 -0
  63. package/dist/request/types.js.map +1 -0
  64. package/dist/services/authup/index.d.ts +3 -0
  65. package/dist/services/authup/index.d.ts.map +1 -0
  66. package/dist/services/authup/index.js +25 -0
  67. package/dist/services/authup/index.js.map +1 -0
  68. package/dist/services/authup/middleware.d.ts +4 -0
  69. package/dist/services/authup/middleware.d.ts.map +1 -0
  70. package/dist/services/authup/middleware.js +86 -0
  71. package/dist/services/authup/middleware.js.map +1 -0
  72. package/dist/services/authup/types.d.ts +10 -0
  73. package/dist/services/authup/types.d.ts.map +1 -0
  74. package/dist/services/authup/types.js +9 -0
  75. package/dist/services/authup/types.js.map +1 -0
  76. package/dist/services/authup/utils.d.ts +7 -0
  77. package/dist/services/authup/utils.d.ts.map +1 -0
  78. package/dist/services/authup/utils.js +59 -0
  79. package/dist/services/authup/utils.js.map +1 -0
  80. package/dist/services/index.d.ts +2 -0
  81. package/dist/services/index.d.ts.map +1 -0
  82. package/dist/services/index.js +24 -0
  83. package/dist/services/index.js.map +1 -0
  84. package/dist/swagger/index.d.ts +2 -0
  85. package/dist/swagger/index.d.ts.map +1 -0
  86. package/dist/swagger/index.js +24 -0
  87. package/dist/swagger/index.js.map +1 -0
  88. package/dist/swagger/module.d.ts +3 -0
  89. package/dist/swagger/module.d.ts.map +1 -0
  90. package/dist/swagger/module.js +66 -0
  91. package/dist/swagger/module.js.map +1 -0
  92. package/dist/swagger/types.d.ts +7 -0
  93. package/dist/swagger/types.d.ts.map +1 -0
  94. package/dist/swagger/types.js +9 -0
  95. package/dist/swagger/types.js.map +1 -0
  96. package/dist/utils/boolable-to-object.d.ts +2 -0
  97. package/dist/utils/boolable-to-object.d.ts.map +1 -0
  98. package/dist/utils/boolable-to-object.js +16 -0
  99. package/dist/utils/boolable-to-object.js.map +1 -0
  100. package/dist/utils/index.d.ts +2 -0
  101. package/dist/utils/index.d.ts.map +1 -0
  102. package/dist/utils/index.js +24 -0
  103. package/dist/utils/index.js.map +1 -0
  104. package/dist/validation/index.d.ts +5 -0
  105. package/dist/validation/index.d.ts.map +1 -0
  106. package/dist/validation/index.js +27 -0
  107. package/dist/validation/index.js.map +1 -0
  108. package/dist/validation/message.d.ts +2 -0
  109. package/dist/validation/message.d.ts.map +1 -0
  110. package/dist/validation/message.js +17 -0
  111. package/dist/validation/message.js.map +1 -0
  112. package/dist/validation/module.d.ts +6 -0
  113. package/dist/validation/module.d.ts.map +1 -0
  114. package/dist/validation/module.js +45 -0
  115. package/dist/validation/module.js.map +1 -0
  116. package/dist/validation/result.d.ts +7 -0
  117. package/dist/validation/result.d.ts.map +1 -0
  118. package/dist/validation/result.js +43 -0
  119. package/dist/validation/result.js.map +1 -0
  120. package/dist/validation/type.d.ts +15 -0
  121. package/dist/validation/type.d.ts.map +1 -0
  122. package/dist/validation/type.js +9 -0
  123. package/dist/validation/type.js.map +1 -0
  124. package/package.json +49 -0
  125. package/src/index.ts +12 -0
  126. package/src/middlewares/basic.ts +13 -0
  127. package/src/middlewares/cors.ts +19 -0
  128. package/src/middlewares/decorators.ts +42 -0
  129. package/src/middlewares/error.ts +55 -0
  130. package/src/middlewares/force-logged-in.ts +26 -0
  131. package/src/middlewares/index.ts +15 -0
  132. package/src/middlewares/module.ts +53 -0
  133. package/src/middlewares/prometheus.ts +13 -0
  134. package/src/middlewares/rate-limit.ts +47 -0
  135. package/src/middlewares/swagger.ts +26 -0
  136. package/src/middlewares/types.ts +30 -0
  137. package/src/request/env.ts +28 -0
  138. package/src/request/index.ts +9 -0
  139. package/src/request/types.ts +22 -0
  140. package/src/services/authup/index.ts +9 -0
  141. package/src/services/authup/middleware.ts +110 -0
  142. package/src/services/authup/types.ts +17 -0
  143. package/src/services/authup/utils.ts +79 -0
  144. package/src/services/index.ts +8 -0
  145. package/src/swagger/index.ts +8 -0
  146. package/src/swagger/module.ts +67 -0
  147. package/src/swagger/types.ts +13 -0
  148. package/src/utils/boolable-to-object.ts +14 -0
  149. package/src/utils/index.ts +8 -0
  150. package/src/validation/index.ts +11 -0
  151. package/src/validation/message.ts +17 -0
  152. package/src/validation/module.ts +49 -0
  153. package/src/validation/result.ts +58 -0
  154. package/src/validation/type.ts +28 -0
  155. package/tsconfig.build.json +11 -0
  156. package/tsconfig.json +9 -0
  157. package/writable/.gitkeep +0 -0
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./module"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/swagger/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB"}
@@ -0,0 +1,3 @@
1
+ import type { SwaggerGenerateOptions } from './types';
2
+ export declare function generateSwagger(options: SwaggerGenerateOptions): Promise<import("@routup/swagger").SpecV2>;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/swagger/module.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,6CAoDpE"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021-2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.generateSwagger = generateSwagger;
13
+ const node_path_1 = __importDefault(require("node:path"));
14
+ const swagger_1 = require("@routup/swagger");
15
+ const locter_1 = require("locter");
16
+ const node_process_1 = __importDefault(require("node:process"));
17
+ async function generateSwagger(options) {
18
+ const cwd = options.cwd || node_process_1.default.cwd();
19
+ const packageJson = await (0, locter_1.load)(node_path_1.default.join(cwd, 'package.json'));
20
+ const securityDefinitions = {
21
+ bearer: {
22
+ name: 'Bearer',
23
+ type: 'apiKey',
24
+ in: 'header',
25
+ },
26
+ basicAuth: {
27
+ type: 'http',
28
+ schema: 'basic',
29
+ },
30
+ };
31
+ if (options.authupURL) {
32
+ securityDefinitions.oauth2 = {
33
+ type: 'oauth2',
34
+ flows: {
35
+ password: {
36
+ tokenUrl: new URL('token', options.authupURL).href,
37
+ },
38
+ },
39
+ };
40
+ }
41
+ return (0, swagger_1.generate)({
42
+ version: swagger_1.Version.V2,
43
+ options: {
44
+ metadata: {
45
+ cache: false,
46
+ entryPoint: [
47
+ { pattern: '**/*.ts', cwd: options.controllerBasePath },
48
+ ],
49
+ ignore: ['**/node_modules/**'],
50
+ allow: ['**/@authup/**'],
51
+ },
52
+ yaml: false,
53
+ servers: [
54
+ options.baseURL,
55
+ ],
56
+ name: 'API Documentation',
57
+ description: 'Explore the REST Endpoints.',
58
+ version: packageJson.version,
59
+ outputDirectory: node_path_1.default.join(cwd, 'writable'),
60
+ securityDefinitions,
61
+ consumes: ['application/json'],
62
+ produces: ['application/json'],
63
+ },
64
+ });
65
+ }
66
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/swagger/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AASH,0CAoDC;AA3DD,0DAA6B;AAE7B,6CAAoD;AACpD,mCAA8B;AAC9B,gEAAmC;AAG5B,KAAK,UAAU,eAAe,CAAC,OAA+B;IACjE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,sBAAO,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,WAAW,GAAG,MAAM,IAAA,aAAI,EAAC,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAwB,CAAC;IAEtF,MAAM,mBAAmB,GAAkD;QACvE,MAAM,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;YACd,EAAE,EAAE,QAAQ;SACf;QAED,SAAS,EAAE;YACP,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,OAAO;SAClB;KACJ,CAAC;IAEF,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACpB,mBAAmB,CAAC,MAAM,GAAG;YACzB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE;gBACH,QAAQ,EAAE;oBACN,QAAQ,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI;iBACrD;aACJ;SACJ,CAAC;IACN,CAAC;IAED,OAAO,IAAA,kBAAQ,EAAC;QACZ,OAAO,EAAE,iBAAO,CAAC,EAAE;QACnB,OAAO,EAAE;YACL,QAAQ,EAAE;gBACN,KAAK,EAAE,KAAK;gBACZ,UAAU,EAAE;oBACR,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,kBAAkB,EAAE;iBAC1D;gBACD,MAAM,EAAE,CAAC,oBAAoB,CAAC;gBAC9B,KAAK,EAAE,CAAC,eAAe,CAAC;aAC3B;YACD,IAAI,EAAE,KAAK;YACX,OAAO,EAAE;gBACL,OAAO,CAAC,OAAO;aAClB;YACD,IAAI,EAAE,mBAAmB;YACzB,WAAW,EAAE,6BAA6B;YAC1C,OAAO,EAAE,WAAW,CAAC,OAAO;YAC5B,eAAe,EAAE,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC;YAC3C,mBAAmB;YACnB,QAAQ,EAAE,CAAC,kBAAkB,CAAC;YAC9B,QAAQ,EAAE,CAAC,kBAAkB,CAAC;SACjC;KACJ,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type SwaggerGenerateOptions = {
2
+ baseURL: string;
3
+ authupURL?: string;
4
+ cwd?: string;
5
+ controllerBasePath: string;
6
+ };
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/swagger/types.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,sBAAsB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,CAAC;CAC9B,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/swagger/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -0,0 +1,2 @@
1
+ export declare function boolableToObject<T extends Record<string, any>>(input: T | boolean): T;
2
+ //# sourceMappingURL=boolable-to-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolable-to-object.d.ts","sourceRoot":"","sources":["../../src/utils/boolable-to-object.ts"],"names":[],"mappings":"AAOA,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,GAAI,CAAC,CAMtF"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.boolableToObject = boolableToObject;
10
+ function boolableToObject(input) {
11
+ if (typeof input === 'boolean') {
12
+ return {};
13
+ }
14
+ return input;
15
+ }
16
+ //# sourceMappingURL=boolable-to-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolable-to-object.js","sourceRoot":"","sources":["../../src/utils/boolable-to-object.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,4CAMC;AAND,SAAgB,gBAAgB,CAAgC,KAAkB;IAC9E,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,EAAO,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './boolable-to-object';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAOA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./boolable-to-object"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,uDAAqC"}
@@ -0,0 +1,5 @@
1
+ export * from './message';
2
+ export * from './module';
3
+ export * from './type';
4
+ export * from './result';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAOA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021-2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./message"), exports);
24
+ __exportStar(require("./module"), exports);
25
+ __exportStar(require("./type"), exports);
26
+ __exportStar(require("./result"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,4CAA0B;AAC1B,2CAAyB;AACzB,yCAAuB;AACvB,2CAAyB"}
@@ -0,0 +1,2 @@
1
+ export declare function buildHTTPValidationErrorMessage<T extends Record<string, any> = Record<string, any>>(name: keyof T | (keyof T)[]): string;
2
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/validation/message.ts"],"names":[],"mappings":"AAOA,wBAAgB,+BAA+B,CAC3C,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,UAO5B"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.buildHTTPValidationErrorMessage = buildHTTPValidationErrorMessage;
10
+ function buildHTTPValidationErrorMessage(name) {
11
+ const names = Array.isArray(name) ? name : [name];
12
+ if (names.length > 1) {
13
+ return `The parameters ${names.join(', ')} is invalid.`;
14
+ }
15
+ return `The parameter ${String(names[0])} is invalid.`;
16
+ }
17
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/validation/message.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,0EASC;AATD,SAAgB,+BAA+B,CAE7C,IAA2B;IACzB,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAElD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACnB,OAAO,kBAAkB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;IAC5D,CAAC;IACD,OAAO,iBAAiB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { BadRequestError } from '@ebec/http';
2
+ import type { Result, ValidationError } from 'express-validator';
3
+ export declare class HTTPValidationError extends BadRequestError {
4
+ constructor(validation: Result<ValidationError>);
5
+ }
6
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/validation/module.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGjE,qBAAa,mBAAoB,SAAQ,eAAe;gBACxC,UAAU,EAAE,MAAM,CAAC,eAAe,CAAC;CAoClD"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022-2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HTTPValidationError = void 0;
10
+ const http_1 = require("@ebec/http");
11
+ const message_1 = require("./message");
12
+ class HTTPValidationError extends http_1.BadRequestError {
13
+ constructor(validation) {
14
+ const errors = validation.array();
15
+ const parameterNames = [];
16
+ for (let i = 0; i < errors.length; i++) {
17
+ const item = errors[i];
18
+ switch (item.type) {
19
+ case 'field': {
20
+ parameterNames.push(item.path);
21
+ break;
22
+ }
23
+ case 'alternative': {
24
+ parameterNames.push(item.nestedErrors.map(((el) => el.path)).join('|'));
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ let message;
30
+ if (parameterNames.length > 0) {
31
+ message = (0, message_1.buildHTTPValidationErrorMessage)(Array.from(new Set(parameterNames)));
32
+ }
33
+ else {
34
+ message = 'An unexpected validation error occurred.';
35
+ }
36
+ super({
37
+ message,
38
+ data: {
39
+ errors,
40
+ },
41
+ });
42
+ }
43
+ }
44
+ exports.HTTPValidationError = HTTPValidationError;
45
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/validation/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAA6C;AAE7C,uCAA4D;AAE5D,MAAa,mBAAoB,SAAQ,sBAAe;IACpD,YAAY,UAAmC;QAC3C,MAAM,MAAM,GAAuB,UAAU,CAAC,KAAK,EAAE,CAAC;QAEtD,MAAM,cAAc,GAAG,EAAE,CAAC;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAEvB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAChB,KAAK,OAAO,CAAC,CAAC,CAAC;oBACX,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC/B,MAAM;gBACV,CAAC;gBACD,KAAK,aAAa,CAAC,CAAC,CAAC;oBACjB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CACrC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CACpB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;oBACb,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;QAED,IAAI,OAAgB,CAAC;QAErB,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,GAAG,IAAA,yCAA+B,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QACnF,CAAC;aAAM,CAAC;YACJ,OAAO,GAAG,0CAA0C,CAAC;QACzD,CAAC;QAED,KAAK,CAAC;YACF,OAAO;YACP,IAAI,EAAE;gBACF,MAAM;aACT;SACJ,CAAC,CAAC;IACP,CAAC;CACJ;AArCD,kDAqCC"}
@@ -0,0 +1,7 @@
1
+ import type { MatchedDataOptions } from 'express-validator';
2
+ import type { Request } from 'routup';
3
+ import type { EntityTarget } from 'typeorm';
4
+ import type { HTTPValidationExtendKeys, HTTPValidationResult } from './type';
5
+ export declare function createHTTPValidationResult<R extends Record<string, any>, M extends Record<string, any> = Record<string, any>>(req: Request, options?: Partial<MatchedDataOptions>): HTTPValidationResult<R, M>;
6
+ export declare function extendHTTPValidationResultWithRelation<R extends Record<string, any>>(result: HTTPValidationResult<R>, target: EntityTarget<any>, keys: HTTPValidationExtendKeys<R>): Promise<HTTPValidationResult<R>>;
7
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/validation/result.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAE7E,wBAAgB,0BAA0B,CACtC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACrD,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM,GAAI,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CActF;AAED,wBAAsB,sCAAsC,CACxD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAE7B,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,EAC/B,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,EACzB,IAAI,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAcnC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022-2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createHTTPValidationResult = createHTTPValidationResult;
10
+ exports.extendHTTPValidationResultWithRelation = extendHTTPValidationResultWithRelation;
11
+ const http_1 = require("@ebec/http");
12
+ const kit_1 = require("@privateaim/kit");
13
+ const express_validator_1 = require("express-validator");
14
+ const typeorm_extension_1 = require("typeorm-extension");
15
+ const message_1 = require("./message");
16
+ const module_1 = require("./module");
17
+ function createHTTPValidationResult(req, options = {}) {
18
+ const validation = (0, express_validator_1.validationResult)(req);
19
+ if (!validation.isEmpty()) {
20
+ throw new module_1.HTTPValidationError(validation);
21
+ }
22
+ return {
23
+ data: (0, kit_1.deleteUndefinedObjectProperties)((0, express_validator_1.matchedData)(req, {
24
+ includeOptionals: true,
25
+ ...options,
26
+ })),
27
+ meta: {},
28
+ relation: {},
29
+ };
30
+ }
31
+ async function extendHTTPValidationResultWithRelation(result, target, keys) {
32
+ if (result.data[keys.id]) {
33
+ const dataSource = await (0, typeorm_extension_1.useDataSource)();
34
+ const repository = dataSource.getRepository(target);
35
+ const entity = await repository.findOneBy({ id: result.data[keys.id] });
36
+ if (!entity) {
37
+ throw new http_1.BadRequestError((0, message_1.buildHTTPValidationErrorMessage)(keys.id));
38
+ }
39
+ result.relation[keys.entity] = entity;
40
+ }
41
+ return result;
42
+ }
43
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/validation/result.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAaH,gEAiBC;AAED,wFAoBC;AAlDD,qCAA6C;AAC7C,yCAAkE;AAElE,yDAAkE;AAGlE,yDAAkD;AAClD,uCAA4D;AAC5D,qCAA+C;AAG/C,SAAgB,0BAA0B,CAGxC,GAAY,EAAE,UAAuC,EAAE;IACrD,MAAM,UAAU,GAAG,IAAA,oCAAgB,EAAC,GAAG,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,4BAAmB,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO;QACH,IAAI,EAAE,IAAA,qCAA+B,EAAC,IAAA,+BAAW,EAAC,GAAG,EAAE;YACnD,gBAAgB,EAAE,IAAI;YACtB,GAAG,OAAO;SACb,CAAC,CAAM;QACR,IAAI,EAAE,EAAO;QACb,QAAQ,EAAE,EAAE;KACf,CAAC;AACN,CAAC;AAEM,KAAK,UAAU,sCAAsC,CAGxD,MAA+B,EAC/B,MAAyB,EACzB,IAAiC;IAEjC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,MAAM,IAAA,iCAAa,GAAE,CAAC;QAEzC,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACpD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,sBAAe,CAAC,IAAA,yCAA+B,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAmD,CAAC,GAAG,MAAM,CAAC;IACvF,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type HTTPValidationResultMetaKey<T extends Record<string, any>> = ({
2
+ [K in keyof T]?: T[K] extends Record<string, any> ? T[K] extends Date ? never : K : never;
3
+ })[keyof T];
4
+ export type HTTPValidationResult<T extends Record<string, any>, M extends Record<string, any> = Record<string, any>> = {
5
+ data: Partial<T>;
6
+ relation: {
7
+ [K in HTTPValidationResultMetaKey<T>]?: T[K];
8
+ };
9
+ meta: M;
10
+ };
11
+ export type HTTPValidationExtendKeys<T extends Record<string, any>> = {
12
+ id: keyof T;
13
+ entity: HTTPValidationResultMetaKey<T>;
14
+ };
15
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/validation/type.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,2BAA2B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;KACrE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7C,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAC7B,KAAK;CACZ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEZ,MAAM,MAAM,oBAAoB,CAC5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAC/C;IACA,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACjB,QAAQ,EAAE;SACL,CAAC,IAAI,2BAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC/C,CAAC;IACF,IAAI,EAAE,CAAC,CAAA;CACV,CAAC;AAEN,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAClE,EAAE,EAAE,MAAM,CAAC,CAAC;IACZ,MAAM,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAA;CACzC,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022-2024.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/validation/type.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@privateaim/server-http-kit",
3
+ "version": "0.7.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "author": {
7
+ "name": "Peter Placzek",
8
+ "email": "contact@tada5hi.net",
9
+ "url": "https://tada5hi.net"
10
+ },
11
+ "license": "Apache-2.0",
12
+ "description": "This package contains the realtime application which connects the API with socket based clients.",
13
+ "dependencies": {
14
+ "@authup/kit": "^1.0.0-beta.18",
15
+ "@authup/core-kit": "^1.0.0-beta.18",
16
+ "@authup/core-http-kit": "^1.0.0-beta.18",
17
+ "@authup/server-core-plugin-kit": "^1.0.0-beta.18",
18
+ "@authup/server-core-plugin-http": "^1.0.0-beta.18",
19
+ "@ebec/http": "^2.3.0",
20
+ "@privateaim/kit": "^0.7.0",
21
+ "@privateaim/server-kit": "^0.7.0",
22
+ "@routup/basic": "^1.3.1",
23
+ "@routup/decorators": "^3.3.1",
24
+ "@routup/prometheus": "^2.3.0",
25
+ "@routup/rate-limit": "^2.3.0",
26
+ "@routup/swagger": "^2.3.6",
27
+ "cors": "^2.8.5",
28
+ "hapic": "^2.5.1",
29
+ "locter": "^2.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/cors": "^2.8.17",
33
+ "express-validator": "^7.1.0",
34
+ "redis-extension": "^1.5.0",
35
+ "routup": "^3.3.0",
36
+ "typeorm-extension": "^3.5.1"
37
+ },
38
+ "peerDependencies": {
39
+ "express-validator": "^7.1.0",
40
+ "redis-extension": "^1.5.0",
41
+ "routup": "^3.3.0",
42
+ "typeorm-extension": "^3.5.1"
43
+ },
44
+ "scripts": {
45
+ "dev": "ts-node src/index.ts",
46
+ "build": "rimraf dist && tsc -p tsconfig.build.json",
47
+ "start": "node dist/index.js"
48
+ }
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './middlewares';
9
+ export * from './request';
10
+ export * from './services';
11
+ export * from './swagger';
12
+ export * from './validation';
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { basic } from '@routup/basic';
9
+ import type { Router } from 'routup';
10
+
11
+ export function mountBasicMiddleware(router: Router) {
12
+ router.use(basic());
13
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import cors from 'cors';
9
+ import { coreHandler } from 'routup';
10
+ import type { Router } from 'routup';
11
+
12
+ export function mountCorsMiddleware(router: Router) {
13
+ router.use(coreHandler((req, res, next) => cors({
14
+ origin(origin, callback) {
15
+ callback(null, true);
16
+ },
17
+ credentials: true,
18
+ })(req, res, next)));
19
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { useRequestBody } from '@routup/basic/body';
9
+ import { useRequestCookie, useRequestCookies } from '@routup/basic/cookie';
10
+ import { useRequestQuery } from '@routup/basic/query';
11
+ import { decorators } from '@routup/decorators';
12
+ import type { Router } from 'routup';
13
+ import type { MiddlewareDecoratorsOptions } from './types';
14
+
15
+ export function mountDecoratorsMiddleware(router: Router, options: MiddlewareDecoratorsOptions) {
16
+ router.use(decorators({
17
+ controllers: options.controllers,
18
+ parameter: {
19
+ body: (context, name) => {
20
+ if (name) {
21
+ return useRequestBody(context.request, name);
22
+ }
23
+
24
+ return useRequestBody(context.request);
25
+ },
26
+ cookie: (context, name) => {
27
+ if (name) {
28
+ return useRequestCookie(context.request, name);
29
+ }
30
+
31
+ return useRequestCookies(context.request);
32
+ },
33
+ query: (context, name) => {
34
+ if (name) {
35
+ return useRequestQuery(context.request, name);
36
+ }
37
+
38
+ return useRequestQuery(context.request);
39
+ },
40
+ },
41
+ }));
42
+ }
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { isObject } from '@privateaim/kit';
9
+ import type { Router } from 'routup';
10
+ import { errorHandler } from 'routup';
11
+ import { useLogger } from '@privateaim/server-kit';
12
+
13
+ export function mountErrorMiddleware(router: Router) {
14
+ router.use(errorHandler((error, req, res) => {
15
+ // catch and decorate some db errors :)
16
+ switch (error.code) {
17
+ case 'ER_DUP_ENTRY':
18
+ case 'SQLITE_CONSTRAINT_UNIQUE': {
19
+ error.statusCode = 409;
20
+ error.message = 'An entry with some unique attributes already exist.';
21
+ error.expose = true;
22
+ break;
23
+ }
24
+ case 'ER_DISK_FULL':
25
+ error.statusCode = 507;
26
+ error.message = 'No database operation possible, due the leak of free disk space.';
27
+ error.expose = true;
28
+ break;
29
+ }
30
+
31
+ const isServerError = (typeof error.expose !== 'undefined' && !error.expose) ||
32
+ (error.statusCode >= 500 && error.statusCode < 600);
33
+
34
+ if (isServerError || error.logMessage) {
35
+ useLogger().error(error);
36
+
37
+ if (error.cause) {
38
+ useLogger().error(error.cause);
39
+ }
40
+ }
41
+
42
+ if (isServerError) {
43
+ error.message = 'An internal server error occurred.';
44
+ }
45
+
46
+ res.statusCode = error.statusCode;
47
+
48
+ return {
49
+ statusCode: error.statusCode,
50
+ code: `${error.code}`,
51
+ message: error.message,
52
+ ...(isObject(error.data) && !isServerError ? error.data : {}),
53
+ };
54
+ }));
55
+ }