wnodex 0.1.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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +103 -0
  3. package/dist/consts/cors.d.ts +15 -0
  4. package/dist/consts/cors.d.ts.map +1 -0
  5. package/dist/consts/cors.js +29 -0
  6. package/dist/consts/error-codes.d.ts +10 -0
  7. package/dist/consts/error-codes.d.ts.map +1 -0
  8. package/dist/consts/error-codes.js +12 -0
  9. package/dist/consts/index.d.ts +8 -0
  10. package/dist/consts/index.d.ts.map +1 -0
  11. package/dist/consts/index.js +10 -0
  12. package/dist/consts/log-levels.d.ts +8 -0
  13. package/dist/consts/log-levels.d.ts.map +1 -0
  14. package/dist/consts/log-levels.js +10 -0
  15. package/dist/consts/node-env.d.ts +7 -0
  16. package/dist/consts/node-env.d.ts.map +1 -0
  17. package/dist/consts/node-env.js +9 -0
  18. package/dist/consts/port.d.ts +6 -0
  19. package/dist/consts/port.d.ts.map +1 -0
  20. package/dist/consts/port.js +26 -0
  21. package/dist/consts/rate-limit.d.ts +9 -0
  22. package/dist/consts/rate-limit.d.ts.map +1 -0
  23. package/dist/consts/rate-limit.js +11 -0
  24. package/dist/consts/session.d.ts +6 -0
  25. package/dist/consts/session.d.ts.map +1 -0
  26. package/dist/consts/session.js +8 -0
  27. package/dist/errors/base-error.d.ts +57 -0
  28. package/dist/errors/base-error.d.ts.map +1 -0
  29. package/dist/errors/base-error.js +93 -0
  30. package/dist/errors/config-error.d.ts +20 -0
  31. package/dist/errors/config-error.d.ts.map +1 -0
  32. package/dist/errors/config-error.js +30 -0
  33. package/dist/errors/http-error.d.ts +17 -0
  34. package/dist/errors/http-error.d.ts.map +1 -0
  35. package/dist/errors/http-error.js +24 -0
  36. package/dist/errors/index.d.ts +5 -0
  37. package/dist/errors/index.d.ts.map +1 -0
  38. package/dist/errors/index.js +7 -0
  39. package/dist/errors/validation-error.d.ts +19 -0
  40. package/dist/errors/validation-error.d.ts.map +1 -0
  41. package/dist/errors/validation-error.js +29 -0
  42. package/dist/helpers/get-node-env.d.ts +13 -0
  43. package/dist/helpers/get-node-env.d.ts.map +1 -0
  44. package/dist/helpers/get-node-env.js +27 -0
  45. package/dist/helpers/index.d.ts +5 -0
  46. package/dist/helpers/index.d.ts.map +1 -0
  47. package/dist/helpers/index.js +7 -0
  48. package/dist/helpers/is-development.d.ts +9 -0
  49. package/dist/helpers/is-development.d.ts.map +1 -0
  50. package/dist/helpers/is-development.js +16 -0
  51. package/dist/helpers/setup-config.d.ts +12 -0
  52. package/dist/helpers/setup-config.d.ts.map +1 -0
  53. package/dist/helpers/setup-config.js +21 -0
  54. package/dist/helpers/setup-middlewares.d.ts +12 -0
  55. package/dist/helpers/setup-middlewares.d.ts.map +1 -0
  56. package/dist/helpers/setup-middlewares.js +45 -0
  57. package/dist/index.d.ts +39 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +41 -0
  60. package/dist/logger.d.ts +3 -0
  61. package/dist/logger.d.ts.map +1 -0
  62. package/dist/logger.js +21 -0
  63. package/dist/middlewares/compression.d.ts +18 -0
  64. package/dist/middlewares/compression.d.ts.map +1 -0
  65. package/dist/middlewares/compression.js +26 -0
  66. package/dist/middlewares/cookie-parser.ts.d.ts +20 -0
  67. package/dist/middlewares/cookie-parser.ts.d.ts.map +1 -0
  68. package/dist/middlewares/cookie-parser.ts.js +33 -0
  69. package/dist/middlewares/cors.d.ts +22 -0
  70. package/dist/middlewares/cors.d.ts.map +1 -0
  71. package/dist/middlewares/cors.js +34 -0
  72. package/dist/middlewares/error-handler.d.ts +21 -0
  73. package/dist/middlewares/error-handler.d.ts.map +1 -0
  74. package/dist/middlewares/error-handler.js +43 -0
  75. package/dist/middlewares/helmet.d.ts +16 -0
  76. package/dist/middlewares/helmet.d.ts.map +1 -0
  77. package/dist/middlewares/helmet.js +28 -0
  78. package/dist/middlewares/hpp.d.ts +18 -0
  79. package/dist/middlewares/hpp.d.ts.map +1 -0
  80. package/dist/middlewares/hpp.js +30 -0
  81. package/dist/middlewares/index.d.ts +10 -0
  82. package/dist/middlewares/index.d.ts.map +1 -0
  83. package/dist/middlewares/index.js +12 -0
  84. package/dist/middlewares/passport.d.ts +16 -0
  85. package/dist/middlewares/passport.d.ts.map +1 -0
  86. package/dist/middlewares/passport.js +27 -0
  87. package/dist/middlewares/rate-limit.d.ts +23 -0
  88. package/dist/middlewares/rate-limit.d.ts.map +1 -0
  89. package/dist/middlewares/rate-limit.js +35 -0
  90. package/dist/middlewares/session.d.ts +16 -0
  91. package/dist/middlewares/session.d.ts.map +1 -0
  92. package/dist/middlewares/session.js +23 -0
  93. package/dist/schemas/compression.d.ts +5 -0
  94. package/dist/schemas/compression.d.ts.map +1 -0
  95. package/dist/schemas/compression.js +5 -0
  96. package/dist/schemas/cookie-parser.d.ts +9 -0
  97. package/dist/schemas/cookie-parser.d.ts.map +1 -0
  98. package/dist/schemas/cookie-parser.js +14 -0
  99. package/dist/schemas/cors.d.ts +6 -0
  100. package/dist/schemas/cors.d.ts.map +1 -0
  101. package/dist/schemas/cors.js +9 -0
  102. package/dist/schemas/error-metadata.d.ts +18 -0
  103. package/dist/schemas/error-metadata.d.ts.map +1 -0
  104. package/dist/schemas/error-metadata.js +12 -0
  105. package/dist/schemas/helmet.d.ts +6 -0
  106. package/dist/schemas/helmet.d.ts.map +1 -0
  107. package/dist/schemas/helmet.js +8 -0
  108. package/dist/schemas/hpp.d.ts +5 -0
  109. package/dist/schemas/hpp.d.ts.map +1 -0
  110. package/dist/schemas/hpp.js +8 -0
  111. package/dist/schemas/index.d.ts +13 -0
  112. package/dist/schemas/index.d.ts.map +1 -0
  113. package/dist/schemas/index.js +15 -0
  114. package/dist/schemas/node-env.d.ts +16 -0
  115. package/dist/schemas/node-env.d.ts.map +1 -0
  116. package/dist/schemas/node-env.js +8 -0
  117. package/dist/schemas/passport.d.ts +6 -0
  118. package/dist/schemas/passport.d.ts.map +1 -0
  119. package/dist/schemas/passport.js +8 -0
  120. package/dist/schemas/port.d.ts +4 -0
  121. package/dist/schemas/port.d.ts.map +1 -0
  122. package/dist/schemas/port.js +16 -0
  123. package/dist/schemas/rate-limit.d.ts +9 -0
  124. package/dist/schemas/rate-limit.d.ts.map +1 -0
  125. package/dist/schemas/rate-limit.js +26 -0
  126. package/dist/schemas/session.d.ts +18 -0
  127. package/dist/schemas/session.d.ts.map +1 -0
  128. package/dist/schemas/session.js +32 -0
  129. package/dist/schemas/wnodex-config.d.ts +31 -0
  130. package/dist/schemas/wnodex-config.d.ts.map +1 -0
  131. package/dist/schemas/wnodex-config.js +24 -0
  132. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  133. package/dist/wnodex.d.ts +69 -0
  134. package/dist/wnodex.d.ts.map +1 -0
  135. package/dist/wnodex.js +131 -0
  136. package/package.json +54 -0
  137. package/src/consts/cors.ts +27 -0
  138. package/src/consts/error-codes.ts +9 -0
  139. package/src/consts/index.ts +7 -0
  140. package/src/consts/log-levels.ts +7 -0
  141. package/src/consts/node-env.ts +6 -0
  142. package/src/consts/port.ts +23 -0
  143. package/src/consts/rate-limit.ts +9 -0
  144. package/src/consts/session.ts +6 -0
  145. package/src/errors/base-error.ts +111 -0
  146. package/src/errors/config-error.ts +31 -0
  147. package/src/errors/http-error.ts +21 -0
  148. package/src/errors/index.ts +4 -0
  149. package/src/errors/validation-error.ts +30 -0
  150. package/src/helpers/get-node-env.ts +27 -0
  151. package/src/helpers/index.ts +4 -0
  152. package/src/helpers/is-development.ts +15 -0
  153. package/src/helpers/setup-config.ts +25 -0
  154. package/src/helpers/setup-middlewares.ts +56 -0
  155. package/src/index.ts +38 -0
  156. package/src/logger.ts +22 -0
  157. package/src/middlewares/compression.ts +32 -0
  158. package/src/middlewares/cookie-parser.ts.ts +37 -0
  159. package/src/middlewares/cors.ts +35 -0
  160. package/src/middlewares/error-handler.ts +54 -0
  161. package/src/middlewares/helmet.ts +29 -0
  162. package/src/middlewares/hpp.ts +31 -0
  163. package/src/middlewares/index.ts +9 -0
  164. package/src/middlewares/passport.ts +30 -0
  165. package/src/middlewares/rate-limit.ts +39 -0
  166. package/src/middlewares/session.ts +25 -0
  167. package/src/schemas/compression.ts +8 -0
  168. package/src/schemas/cookie-parser.ts +21 -0
  169. package/src/schemas/cors.ts +13 -0
  170. package/src/schemas/error-metadata.ts +15 -0
  171. package/src/schemas/helmet.ts +11 -0
  172. package/src/schemas/hpp.ts +9 -0
  173. package/src/schemas/index.ts +12 -0
  174. package/src/schemas/node-env.ts +11 -0
  175. package/src/schemas/passport.ts +11 -0
  176. package/src/schemas/port.ts +22 -0
  177. package/src/schemas/rate-limit.ts +33 -0
  178. package/src/schemas/session.ts +40 -0
  179. package/src/schemas/wnodex-config.ts +26 -0
  180. package/src/wnodex.ts +152 -0
  181. package/tsconfig.json +10 -0
  182. package/tsconfig.lib.json +13 -0
  183. package/tsconfig.tsbuildinfo +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Davide Di Criscito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # wnodex
2
+
3
+ An extensible and robust Express.js server class designed for effortless customization and rapid deployment.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Features](#features)
8
+ - [Usage](#usage)
9
+ - [Import and Instantiate](#import-and-instantiate)
10
+ - [Access the Logger](#access-the-logger)
11
+ - [Get Validated Config](#get-validated-config)
12
+ - [Access the Express App](#access-the-express-app)
13
+ - [Start the Server](#start-the-server)
14
+ - [Graceful Shutdown](#graceful-shutdown)
15
+ - [API Reference](#api-reference)
16
+ - [class Wnodex](#class-wnodex)
17
+ - [Constructor](#constructor)
18
+ - [Methods](#methods)
19
+ - [License](#license)
20
+
21
+ ## Features
22
+
23
+ - **Express App Instantiation**: Quickly create a new Express application instance.
24
+ - **Configuration Validation**: Validate and store configuration using Zod schemas.
25
+ - **Middleware Setup**: Automatically applies global middlewares (helmet, cors, compression, rate-limit, etc.).
26
+ - **Logging**: Integrated with Pino for structured logging.
27
+ - **Error Handling**: Centralized error handler for Express.
28
+ - **Server Startup**: Simple method to start the server and listen on a specified port.
29
+ - **Graceful Shutdown**: Built-in support for graceful server shutdown and async cleanup chores.
30
+
31
+ ## Usage
32
+
33
+ ### Import and Instantiate
34
+
35
+ ```ts
36
+ import { Wnodex } from 'wnodex';
37
+
38
+ const wnodex = new Wnodex({ port: 3000 });
39
+ ```
40
+
41
+ ### Access the Logger
42
+
43
+ ```ts
44
+ const log = wnodex.getLogger();
45
+ log.info('Custom log message');
46
+ ```
47
+
48
+ ### Get Validated Config
49
+
50
+ ```ts
51
+ const config = wnodex.getConfig();
52
+ console.log(config.port); // 3000
53
+ ```
54
+
55
+ ### Access the Express App
56
+
57
+ ```ts
58
+ const app = wnodex.getApp();
59
+ app.get('/health', (req, res) => res.send('OK'));
60
+ ```
61
+
62
+ ### Start the Server
63
+
64
+ ```ts
65
+ await wnodex.start();
66
+ ```
67
+
68
+ ### Graceful Shutdown
69
+
70
+ ```ts
71
+ await wnodex.shutdown(async () => {
72
+ await db.close();
73
+ await cache.clear();
74
+ });
75
+ ```
76
+
77
+ ## API Reference
78
+
79
+ ### class `Wnodex`
80
+
81
+ #### Constructor
82
+
83
+ ```ts
84
+ new Wnodex(config: WnodexConfigInput)
85
+ ```
86
+
87
+ - `config`: Configuration input validated by `WnodexConfigSchema`.
88
+
89
+ #### Methods
90
+
91
+ - `getLogger(): Logger` — Returns the logger instance.
92
+ - `getConfig(): WnodexConfigOutput` — Returns the validated configuration.
93
+ - `getApp(): Application` — Returns the Express app instance.
94
+ - `start(): Promise<void>` — Starts the server and listens on the configured port.
95
+ - `shutdown(chores?: () => Promise<void> | void): Promise<void>` — Gracefully shuts down the server, running optional async cleanup chores.
96
+
97
+ ## License
98
+
99
+ This project is licensed under the MIT License.
100
+
101
+ Copyright (c) 2025 Davide Di Criscito
102
+
103
+ For the full details, see the [LICENSE](./LICENSE) file.
@@ -0,0 +1,15 @@
1
+ export declare const DEFAULT_CORS_ORIGINS: string[];
2
+ export declare const DEFAULT_CORS_METHODS: readonly ["GET", "POST", "PUT", "DELETE", "OPTIONS"];
3
+ export declare const DEFAULT_CORS_ALLOWED_HEADERS: string[];
4
+ export declare const DEFAULT_CORS_CREDENTIALS = true;
5
+ export declare const DEFAULT_CORS_OPTIONS_SUCCESS_STATUS = 204;
6
+ export declare const DEFAULT_CORS_ENABLED = true;
7
+ export declare const DEFAULT_CORS_OPTIONS: {
8
+ enabled: boolean;
9
+ origin: string[];
10
+ methods: ("GET" | "POST" | "PUT" | "DELETE" | "OPTIONS")[];
11
+ allowedHeaders: string[];
12
+ credentials: boolean;
13
+ optionsSuccessStatus: number;
14
+ };
15
+ //# sourceMappingURL=cors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/consts/cors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,UAAuC,CAAC;AACzE,eAAO,MAAM,oBAAoB,sDAMvB,CAAC;AACX,eAAO,MAAM,4BAA4B,UAKxC,CAAC;AACF,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAC7C,eAAO,MAAM,mCAAmC,MAAM,CAAC;AACvD,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,eAAO,MAAM,oBAAoB;;;;;;;CAOhC,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CORS_OPTIONS = exports.DEFAULT_CORS_ENABLED = exports.DEFAULT_CORS_OPTIONS_SUCCESS_STATUS = exports.DEFAULT_CORS_CREDENTIALS = exports.DEFAULT_CORS_ALLOWED_HEADERS = exports.DEFAULT_CORS_METHODS = exports.DEFAULT_CORS_ORIGINS = void 0;
4
+ const port_js_1 = require("./port.js");
5
+ exports.DEFAULT_CORS_ORIGINS = [`http://localhost:${port_js_1.DEFAULT_PORT}`];
6
+ exports.DEFAULT_CORS_METHODS = [
7
+ 'GET',
8
+ 'POST',
9
+ 'PUT',
10
+ 'DELETE',
11
+ 'OPTIONS',
12
+ ];
13
+ exports.DEFAULT_CORS_ALLOWED_HEADERS = [
14
+ 'Content-Type',
15
+ 'Authorization',
16
+ 'Origin',
17
+ 'X-Requested-With',
18
+ ];
19
+ exports.DEFAULT_CORS_CREDENTIALS = true;
20
+ exports.DEFAULT_CORS_OPTIONS_SUCCESS_STATUS = 204;
21
+ exports.DEFAULT_CORS_ENABLED = true;
22
+ exports.DEFAULT_CORS_OPTIONS = {
23
+ enabled: exports.DEFAULT_CORS_ENABLED,
24
+ origin: exports.DEFAULT_CORS_ORIGINS,
25
+ methods: [...exports.DEFAULT_CORS_METHODS],
26
+ allowedHeaders: exports.DEFAULT_CORS_ALLOWED_HEADERS,
27
+ credentials: exports.DEFAULT_CORS_CREDENTIALS,
28
+ optionsSuccessStatus: exports.DEFAULT_CORS_OPTIONS_SUCCESS_STATUS,
29
+ };
@@ -0,0 +1,10 @@
1
+ export declare const ERROR_CODES: {
2
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
3
+ readonly CONFIG_ERROR: "CONFIG_ERROR";
4
+ readonly INTERNAL_ERROR: "INTERNAL_ERROR";
5
+ readonly NOT_FOUND: "NOT_FOUND";
6
+ readonly UNAUTHORIZED: "UNAUTHORIZED";
7
+ readonly FORBIDDEN: "FORBIDDEN";
8
+ readonly BAD_REQUEST: "BAD_REQUEST";
9
+ };
10
+ //# sourceMappingURL=error-codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/consts/error-codes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;CAQd,CAAC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERROR_CODES = void 0;
4
+ exports.ERROR_CODES = {
5
+ VALIDATION_ERROR: 'VALIDATION_ERROR',
6
+ CONFIG_ERROR: 'CONFIG_ERROR',
7
+ INTERNAL_ERROR: 'INTERNAL_ERROR',
8
+ NOT_FOUND: 'NOT_FOUND',
9
+ UNAUTHORIZED: 'UNAUTHORIZED',
10
+ FORBIDDEN: 'FORBIDDEN',
11
+ BAD_REQUEST: 'BAD_REQUEST',
12
+ };
@@ -0,0 +1,8 @@
1
+ export * from './cors.js';
2
+ export * from './error-codes.js';
3
+ export * from './log-levels.js';
4
+ export * from './node-env.js';
5
+ export * from './port.js';
6
+ export * from './rate-limit.js';
7
+ export * from './session.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consts/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./cors.js"), exports);
5
+ tslib_1.__exportStar(require("./error-codes.js"), exports);
6
+ tslib_1.__exportStar(require("./log-levels.js"), exports);
7
+ tslib_1.__exportStar(require("./node-env.js"), exports);
8
+ tslib_1.__exportStar(require("./port.js"), exports);
9
+ tslib_1.__exportStar(require("./rate-limit.js"), exports);
10
+ tslib_1.__exportStar(require("./session.js"), exports);
@@ -0,0 +1,8 @@
1
+ export declare const LOG_LEVELS: {
2
+ readonly ERROR: "error";
3
+ readonly WARN: "warn";
4
+ readonly INFO: "info";
5
+ readonly DEBUG: "debug";
6
+ readonly TRACE: "trace";
7
+ };
8
+ //# sourceMappingURL=log-levels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-levels.d.ts","sourceRoot":"","sources":["../../src/consts/log-levels.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;CAMb,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LOG_LEVELS = void 0;
4
+ exports.LOG_LEVELS = {
5
+ ERROR: 'error',
6
+ WARN: 'warn',
7
+ INFO: 'info',
8
+ DEBUG: 'debug',
9
+ TRACE: 'trace',
10
+ };
@@ -0,0 +1,7 @@
1
+ export declare const NODE_ENV_VALUES: {
2
+ readonly DEVELOPMENT: "development";
3
+ readonly PRODUCTION: "production";
4
+ readonly TEST: "test";
5
+ readonly STAGING: "staging";
6
+ };
7
+ //# sourceMappingURL=node-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-env.d.ts","sourceRoot":"","sources":["../../src/consts/node-env.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NODE_ENV_VALUES = void 0;
4
+ exports.NODE_ENV_VALUES = {
5
+ DEVELOPMENT: 'development',
6
+ PRODUCTION: 'production',
7
+ TEST: 'test',
8
+ STAGING: 'staging',
9
+ };
@@ -0,0 +1,6 @@
1
+ export declare const RESERVED_PORTS: Record<number, string>;
2
+ export declare const DEFAULT_PORT = 4000;
3
+ export declare const MIN_PORT = 1024;
4
+ export declare const MAX_PORT = 65535;
5
+ export declare const ALLOWED_PORTS: Set<number>;
6
+ //# sourceMappingURL=port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../../src/consts/port.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAkBjD,CAAC;AACF,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,QAAQ,OAAO,CAAC;AAC7B,eAAO,MAAM,QAAQ,QAAS,CAAC;AAC/B,eAAO,MAAM,aAAa,aAAsC,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALLOWED_PORTS = exports.MAX_PORT = exports.MIN_PORT = exports.DEFAULT_PORT = exports.RESERVED_PORTS = void 0;
4
+ exports.RESERVED_PORTS = {
5
+ // Databases
6
+ 3306: 'MySQL',
7
+ 5432: 'PostgreSQL',
8
+ 6379: 'Redis',
9
+ 27_017: 'MongoDB',
10
+ 27_018: 'MongoDB shard/replica',
11
+ 9200: 'Elasticsearch',
12
+ 5601: 'Kibana',
13
+ // Dev tools
14
+ 5173: 'Vite default port',
15
+ 8888: 'Jupyter Notebook',
16
+ // AI / ML servers
17
+ 6006: 'TensorBoard',
18
+ 5000: 'MLflow (also common for Flask)',
19
+ 8265: 'Ray Dashboard',
20
+ 8787: 'Dask Dashboard',
21
+ 11_434: 'Ollama API',
22
+ };
23
+ exports.DEFAULT_PORT = 4000;
24
+ exports.MIN_PORT = 1024;
25
+ exports.MAX_PORT = 65_535;
26
+ exports.ALLOWED_PORTS = new Set([exports.DEFAULT_PORT, 8000, 8080]);
@@ -0,0 +1,9 @@
1
+ export declare const DEFAULT_RATE_LIMIT_WINDOW_MS: number;
2
+ export declare const DEFAULT_RATE_LIMIT_MAX = 100;
3
+ export declare const DEFAULT_RATE_LIMIT_MESSAGE = "Too many requests, please try again later.";
4
+ export declare const DEFAULT_RATE_LIMIT_OPTIONS: {
5
+ windowMs: number;
6
+ max: number;
7
+ message: string;
8
+ };
9
+ //# sourceMappingURL=rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/consts/rate-limit.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,QAAiB,CAAC;AAC3D,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,0BAA0B,+CACO,CAAC;AAC/C,eAAO,MAAM,0BAA0B;;;;CAItC,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_RATE_LIMIT_OPTIONS = exports.DEFAULT_RATE_LIMIT_MESSAGE = exports.DEFAULT_RATE_LIMIT_MAX = exports.DEFAULT_RATE_LIMIT_WINDOW_MS = void 0;
4
+ exports.DEFAULT_RATE_LIMIT_WINDOW_MS = 15 * 60 * 1000;
5
+ exports.DEFAULT_RATE_LIMIT_MAX = 100;
6
+ exports.DEFAULT_RATE_LIMIT_MESSAGE = 'Too many requests, please try again later.';
7
+ exports.DEFAULT_RATE_LIMIT_OPTIONS = {
8
+ windowMs: exports.DEFAULT_RATE_LIMIT_WINDOW_MS,
9
+ max: exports.DEFAULT_RATE_LIMIT_MAX,
10
+ message: exports.DEFAULT_RATE_LIMIT_MESSAGE,
11
+ };
@@ -0,0 +1,6 @@
1
+ export declare const DEFAULT_SESSION_COOKIE_MAX_AGE: number;
2
+ export declare const DEFAULT_SESSION_COOKIE_SECURE: boolean;
3
+ export declare const DEFAULT_SESSION_COOKIE_HTTP_ONLY = true;
4
+ export declare const DEFAULT_SESSION_RESAVE = false;
5
+ export declare const DEFAULT_SESSION_SAVE_UNINITIALIZED = false;
6
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/consts/session.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,QAAsB,CAAC;AAClE,eAAO,MAAM,6BAA6B,SACH,CAAC;AACxC,eAAO,MAAM,gCAAgC,OAAO,CAAC;AACrD,eAAO,MAAM,sBAAsB,QAAQ,CAAC;AAC5C,eAAO,MAAM,kCAAkC,QAAQ,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_SESSION_SAVE_UNINITIALIZED = exports.DEFAULT_SESSION_RESAVE = exports.DEFAULT_SESSION_COOKIE_HTTP_ONLY = exports.DEFAULT_SESSION_COOKIE_SECURE = exports.DEFAULT_SESSION_COOKIE_MAX_AGE = void 0;
4
+ exports.DEFAULT_SESSION_COOKIE_MAX_AGE = 1000 * 60 * 60 * 24; // 1 day
5
+ exports.DEFAULT_SESSION_COOKIE_SECURE = process.env.NODE_ENV === 'production';
6
+ exports.DEFAULT_SESSION_COOKIE_HTTP_ONLY = true;
7
+ exports.DEFAULT_SESSION_RESAVE = false;
8
+ exports.DEFAULT_SESSION_SAVE_UNINITIALIZED = false;
@@ -0,0 +1,57 @@
1
+ import type { ErrorMetadataInput } from '../schemas/error-metadata.js';
2
+ /**
3
+ * Base class for all custom application errors.
4
+ * Extends the native `Error` to preserve stack traces and adds structured, validated metadata.
5
+ *
6
+ * Provides consistent error information for debugging and structured logging.
7
+ */
8
+ export declare class BaseError extends Error {
9
+ /**
10
+ * The machine-readable error code, suitable for programmatic handling.
11
+ * @readonly
12
+ */
13
+ readonly code: string;
14
+ /**
15
+ * The optional cause that triggered this error instance.
16
+ * May be any value, but usually another Error object for chained errors.
17
+ * @override
18
+ * @readonly
19
+ */
20
+ readonly cause?: unknown;
21
+ /**
22
+ * Additional error context for debugging (may contain any serializable data).
23
+ * @readonly
24
+ */
25
+ readonly context?: unknown;
26
+ /**
27
+ * Constructs a new instance of BaseError.
28
+ * Validates the provided metadata to ensure it matches the ErrorMetadataSchema.
29
+ * @param message The human-readable error message.
30
+ * @param metadata Structured metadata for this error instance. It will be validated.
31
+ * @throws {Error} Throws if the metadata is invalid according to ErrorMetadataSchema.
32
+ * @example
33
+ * const err = new BaseError('User not found', { code: 'USER_NOT_FOUND' });
34
+ */
35
+ constructor(message: string, metadata: ErrorMetadataInput);
36
+ /**
37
+ * Validates the error metadata using ErrorMetadataSchema.
38
+ * Throws a clear error if validation fails, including the original Zod error as the cause.
39
+ * @param input The raw metadata input.
40
+ * @param parentErrorMessage The message of the error being constructed, for improved diagnostics.
41
+ * @returns {ErrorMetadataOutput} Parsed and validated metadata.
42
+ * @throws {Error} If the metadata does not pass validation.
43
+ * @example
44
+ * this.validateMetadata({ code: 'INVALID', context: { foo: 42 } }, 'Something failed');
45
+ */
46
+ private validateMetadata;
47
+ /**
48
+ * Returns a plain object representation of the error,
49
+ * useful for structured logging, serialization, or external error reporting.
50
+ * Nested error causes include their name, message, and stack trace.
51
+ * @returns {object} A plain, serializable object representing this error.
52
+ * @example
53
+ * JSON.stringify(err.toJSON());
54
+ */
55
+ toJSON(): object;
56
+ }
57
+ //# sourceMappingURL=base-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-error.d.ts","sourceRoot":"","sources":["../../src/errors/base-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAEnB,MAAM,8BAA8B,CAAC;AAGtC;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;;;OAKG;IACH,SAAyB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEzC;;;OAGG;IACH,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElC;;;;;;;;OAQG;gBACS,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB;IAgBzD;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAexB;;;;;;;OAOG;IACH,MAAM,IAAI,MAAM;CAmBjB"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseError = void 0;
4
+ const error_metadata_js_1 = require("../schemas/error-metadata.js");
5
+ /**
6
+ * Base class for all custom application errors.
7
+ * Extends the native `Error` to preserve stack traces and adds structured, validated metadata.
8
+ *
9
+ * Provides consistent error information for debugging and structured logging.
10
+ */
11
+ class BaseError extends Error {
12
+ /**
13
+ * The machine-readable error code, suitable for programmatic handling.
14
+ * @readonly
15
+ */
16
+ code;
17
+ /**
18
+ * The optional cause that triggered this error instance.
19
+ * May be any value, but usually another Error object for chained errors.
20
+ * @override
21
+ * @readonly
22
+ */
23
+ cause;
24
+ /**
25
+ * Additional error context for debugging (may contain any serializable data).
26
+ * @readonly
27
+ */
28
+ context;
29
+ /**
30
+ * Constructs a new instance of BaseError.
31
+ * Validates the provided metadata to ensure it matches the ErrorMetadataSchema.
32
+ * @param message The human-readable error message.
33
+ * @param metadata Structured metadata for this error instance. It will be validated.
34
+ * @throws {Error} Throws if the metadata is invalid according to ErrorMetadataSchema.
35
+ * @example
36
+ * const err = new BaseError('User not found', { code: 'USER_NOT_FOUND' });
37
+ */
38
+ constructor(message, metadata) {
39
+ super(message);
40
+ // Sets the name property to the actual class name (useful with inheritance).
41
+ this.name = new.target.name;
42
+ const validatedMetadata = this.validateMetadata(metadata, message);
43
+ this.code = validatedMetadata.code;
44
+ this.cause = validatedMetadata.cause;
45
+ this.context = validatedMetadata.context;
46
+ // Ensures proper prototype chain for custom errors (required for ES5/TypeScript).
47
+ Object.setPrototypeOf(this, new.target.prototype);
48
+ }
49
+ /**
50
+ * Validates the error metadata using ErrorMetadataSchema.
51
+ * Throws a clear error if validation fails, including the original Zod error as the cause.
52
+ * @param input The raw metadata input.
53
+ * @param parentErrorMessage The message of the error being constructed, for improved diagnostics.
54
+ * @returns {ErrorMetadataOutput} Parsed and validated metadata.
55
+ * @throws {Error} If the metadata does not pass validation.
56
+ * @example
57
+ * this.validateMetadata({ code: 'INVALID', context: { foo: 42 } }, 'Something failed');
58
+ */
59
+ validateMetadata(input, parentErrorMessage) {
60
+ const result = error_metadata_js_1.ErrorMetadataSchema.safeParse(input);
61
+ if (!result.success) {
62
+ const errorMessage = `Invalid metadata provided for error "${parentErrorMessage}" (Code: ${input.code || 'N/A'}).`;
63
+ throw new Error(errorMessage, { cause: result.error });
64
+ }
65
+ return result.data;
66
+ }
67
+ /**
68
+ * Returns a plain object representation of the error,
69
+ * useful for structured logging, serialization, or external error reporting.
70
+ * Nested error causes include their name, message, and stack trace.
71
+ * @returns {object} A plain, serializable object representing this error.
72
+ * @example
73
+ * JSON.stringify(err.toJSON());
74
+ */
75
+ toJSON() {
76
+ const normalizedCause = this.cause instanceof Error
77
+ ? {
78
+ name: this.cause.name,
79
+ message: this.cause.message,
80
+ stack: this.cause.stack,
81
+ }
82
+ : this.cause;
83
+ return {
84
+ name: this.name,
85
+ message: this.message,
86
+ code: this.code,
87
+ cause: normalizedCause,
88
+ context: this.context,
89
+ stack: this.stack,
90
+ };
91
+ }
92
+ }
93
+ exports.BaseError = BaseError;
@@ -0,0 +1,20 @@
1
+ import { BaseError } from './base-error.js';
2
+ /**
3
+ * Custom error class for configuration failures.
4
+ * Represents issues occurring during loading, parsing, or applying application configuration.
5
+ * Automatically sets the error code to `"CONFIG_ERROR"`. Useful for problems involving environment
6
+ * variables, config files, or settings.
7
+ */
8
+ export declare class ConfigError extends BaseError {
9
+ /**
10
+ * Constructs a new ConfigError instance.
11
+ * @param message The human-readable error message describing the configuration problem.
12
+ * @param cause Optional original error or value that triggered the configuration failure, such as a file system or validation error.
13
+ * @param context Optional additional context data, such as the config file path, setting name, or problematic value.
14
+ *
15
+ * @example
16
+ * throw new ConfigError('Failed to load config file', readError, { file: './config.json' });
17
+ */
18
+ constructor(message: string, cause?: unknown, context?: Record<string | number | symbol, unknown>);
19
+ }
20
+ //# sourceMappingURL=config-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-error.d.ts","sourceRoot":"","sources":["../../src/errors/config-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC;;;;;;;;OAQG;gBAED,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC;CAQtD"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigError = void 0;
4
+ const error_codes_js_1 = require("../consts/error-codes.js");
5
+ const base_error_js_1 = require("./base-error.js");
6
+ /**
7
+ * Custom error class for configuration failures.
8
+ * Represents issues occurring during loading, parsing, or applying application configuration.
9
+ * Automatically sets the error code to `"CONFIG_ERROR"`. Useful for problems involving environment
10
+ * variables, config files, or settings.
11
+ */
12
+ class ConfigError extends base_error_js_1.BaseError {
13
+ /**
14
+ * Constructs a new ConfigError instance.
15
+ * @param message The human-readable error message describing the configuration problem.
16
+ * @param cause Optional original error or value that triggered the configuration failure, such as a file system or validation error.
17
+ * @param context Optional additional context data, such as the config file path, setting name, or problematic value.
18
+ *
19
+ * @example
20
+ * throw new ConfigError('Failed to load config file', readError, { file: './config.json' });
21
+ */
22
+ constructor(message, cause, context) {
23
+ super(message, {
24
+ code: error_codes_js_1.ERROR_CODES.CONFIG_ERROR,
25
+ cause,
26
+ context,
27
+ });
28
+ }
29
+ }
30
+ exports.ConfigError = ConfigError;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Custom HTTP error class with status code.
3
+ * Represents an HTTP error with both status code and message.
4
+ */
5
+ export declare class HttpError extends Error {
6
+ readonly statusCode: number;
7
+ /**
8
+ * Creates an instance of HttpError.
9
+ * @param message Error message describing the problem.
10
+ * @param statusCode HTTP status code, default is 500.
11
+ * @example
12
+ * // Throws an error with 404 status code
13
+ * throw new HttpError('Not Found', 404);
14
+ */
15
+ constructor(message: string, statusCode?: number);
16
+ }
17
+ //# sourceMappingURL=http-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../src/errors/http-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC;;;;;;;OAOG;gBACS,OAAO,EAAE,MAAM,EAAE,UAAU,SAAM;CAK9C"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpError = void 0;
4
+ /**
5
+ * Custom HTTP error class with status code.
6
+ * Represents an HTTP error with both status code and message.
7
+ */
8
+ class HttpError extends Error {
9
+ statusCode;
10
+ /**
11
+ * Creates an instance of HttpError.
12
+ * @param message Error message describing the problem.
13
+ * @param statusCode HTTP status code, default is 500.
14
+ * @example
15
+ * // Throws an error with 404 status code
16
+ * throw new HttpError('Not Found', 404);
17
+ */
18
+ constructor(message, statusCode = 500) {
19
+ super(message);
20
+ this.statusCode = statusCode;
21
+ this.name = this.constructor.name;
22
+ }
23
+ }
24
+ exports.HttpError = HttpError;
@@ -0,0 +1,5 @@
1
+ export * from './base-error.js';
2
+ export * from './config-error.js';
3
+ export * from './http-error.js';
4
+ export * from './validation-error.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./base-error.js"), exports);
5
+ tslib_1.__exportStar(require("./config-error.js"), exports);
6
+ tslib_1.__exportStar(require("./http-error.js"), exports);
7
+ tslib_1.__exportStar(require("./validation-error.js"), exports);