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
@@ -0,0 +1,19 @@
1
+ import { BaseError } from './base-error.js';
2
+ /**
3
+ * Custom error class for validation failures.
4
+ * Used for input errors, schema violations, or data integrity issues.
5
+ * Automatically sets the error code to `"VALIDATION_ERROR"` to allow standard handling of validation errors.
6
+ */
7
+ export declare class ValidationError extends BaseError {
8
+ /**
9
+ * Constructs a new ValidationError instance.
10
+ * @param message The human-readable error message describing what failed validation.
11
+ * @param cause Optional original error or value that caused the validation failure, such as a ZodError or validation detail.
12
+ * @param context Optional additional context data, for example the invalid field, config path, or offending input.
13
+ *
14
+ * @example
15
+ * throw new ValidationError('Invalid email format', zodResult.error, { field: 'email' });
16
+ */
17
+ constructor(message: string, cause?: unknown, context?: Record<string | number | symbol, unknown>);
18
+ }
19
+ //# sourceMappingURL=validation-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-error.d.ts","sourceRoot":"","sources":["../../src/errors/validation-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC5C;;;;;;;;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,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = 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 validation failures.
8
+ * Used for input errors, schema violations, or data integrity issues.
9
+ * Automatically sets the error code to `"VALIDATION_ERROR"` to allow standard handling of validation errors.
10
+ */
11
+ class ValidationError extends base_error_js_1.BaseError {
12
+ /**
13
+ * Constructs a new ValidationError instance.
14
+ * @param message The human-readable error message describing what failed validation.
15
+ * @param cause Optional original error or value that caused the validation failure, such as a ZodError or validation detail.
16
+ * @param context Optional additional context data, for example the invalid field, config path, or offending input.
17
+ *
18
+ * @example
19
+ * throw new ValidationError('Invalid email format', zodResult.error, { field: 'email' });
20
+ */
21
+ constructor(message, cause, context) {
22
+ super(message, {
23
+ code: error_codes_js_1.ERROR_CODES.VALIDATION_ERROR,
24
+ cause,
25
+ context,
26
+ });
27
+ }
28
+ }
29
+ exports.ValidationError = ValidationError;
@@ -0,0 +1,13 @@
1
+ import { type NodeEnv } from '../schemas/node-env.js';
2
+ /**
3
+ * Parses the `NODE_ENV` environment variable from `process.env`.
4
+ * @returns {NodeEnv} The validated environment value.
5
+ * @throws {ValidationError} Thrown if `NODE_ENV` is invalid or not defined according to schema.
6
+ *
7
+ * @example
8
+ * // Example usage:
9
+ * const env = getNodeEnv();
10
+ * // env will be one of 'production', 'development', etc.
11
+ */
12
+ export declare function getNodeEnv(): NodeEnv;
13
+ //# sourceMappingURL=get-node-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-node-env.d.ts","sourceRoot":"","sources":["../../src/helpers/get-node-env.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,wBAAwB,CAAC;AAErE;;;;;;;;;GASG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAYpC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNodeEnv = getNodeEnv;
4
+ const node_env_js_1 = require("../consts/node-env.js");
5
+ const validation_error_js_1 = require("../errors/validation-error.js");
6
+ const node_env_js_2 = require("../schemas/node-env.js");
7
+ /**
8
+ * Parses the `NODE_ENV` environment variable from `process.env`.
9
+ * @returns {NodeEnv} The validated environment value.
10
+ * @throws {ValidationError} Thrown if `NODE_ENV` is invalid or not defined according to schema.
11
+ *
12
+ * @example
13
+ * // Example usage:
14
+ * const env = getNodeEnv();
15
+ * // env will be one of 'production', 'development', etc.
16
+ */
17
+ function getNodeEnv() {
18
+ const rawNodeEnv = process.env.NODE_ENV;
19
+ const result = node_env_js_2.NodeEnvSchema.safeParse(rawNodeEnv);
20
+ if (!result.success) {
21
+ throw new validation_error_js_1.ValidationError('Invalid Node Env', result.error, {
22
+ provided: rawNodeEnv,
23
+ expected: Object.values(node_env_js_1.NODE_ENV_VALUES).join('|'),
24
+ });
25
+ }
26
+ return result.data;
27
+ }
@@ -0,0 +1,5 @@
1
+ export * from './get-node-env.js';
2
+ export * from './is-development.js';
3
+ export * from './setup-config.js';
4
+ export * from './setup-middlewares.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,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("./get-node-env.js"), exports);
5
+ tslib_1.__exportStar(require("./is-development.js"), exports);
6
+ tslib_1.__exportStar(require("./setup-config.js"), exports);
7
+ tslib_1.__exportStar(require("./setup-middlewares.js"), exports);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns true if process.env.NODE_ENV is set to 'development'.
3
+ * @returns {boolean} Returns `true` if the current Node environment is development, otherwise `false`.
4
+ *
5
+ * @example
6
+ * const dev = isDevelopment();
7
+ */
8
+ export declare function isDevelopment(): boolean;
9
+ //# sourceMappingURL=is-development.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-development.d.ts","sourceRoot":"","sources":["../../src/helpers/is-development.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAIvC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDevelopment = isDevelopment;
4
+ const node_env_js_1 = require("../consts/node-env.js");
5
+ const get_node_env_js_1 = require("./get-node-env.js");
6
+ /**
7
+ * Returns true if process.env.NODE_ENV is set to 'development'.
8
+ * @returns {boolean} Returns `true` if the current Node environment is development, otherwise `false`.
9
+ *
10
+ * @example
11
+ * const dev = isDevelopment();
12
+ */
13
+ function isDevelopment() {
14
+ const nodeEnv = (0, get_node_env_js_1.getNodeEnv)();
15
+ return nodeEnv === node_env_js_1.NODE_ENV_VALUES.DEVELOPMENT;
16
+ }
@@ -0,0 +1,12 @@
1
+ import { WnodexConfigInput, WnodexConfigOutput } from '../schemas';
2
+ /**
3
+ * Validates the provided config using NodexConfigSchema.
4
+ * Throws ValidationError if validation fails.
5
+ * @param config Raw configuration input for Nodex.
6
+ * @returns Validated configuration.
7
+ * @throws {ConfigError} If configuration is invalid.
8
+ * @example
9
+ * const config = setupConfig(rawConfig);
10
+ */
11
+ export declare function setupConfig(config: WnodexConfigInput): WnodexConfigOutput;
12
+ //# sourceMappingURL=setup-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-config.d.ts","sourceRoot":"","sources":["../../src/helpers/setup-config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,kBAAkB,CAQzE"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupConfig = setupConfig;
4
+ const config_error_js_1 = require("../errors/config-error.js");
5
+ const schemas_1 = require("../schemas");
6
+ /**
7
+ * Validates the provided config using NodexConfigSchema.
8
+ * Throws ValidationError if validation fails.
9
+ * @param config Raw configuration input for Nodex.
10
+ * @returns Validated configuration.
11
+ * @throws {ConfigError} If configuration is invalid.
12
+ * @example
13
+ * const config = setupConfig(rawConfig);
14
+ */
15
+ function setupConfig(config) {
16
+ const result = schemas_1.WnodexConfigSchema.safeParse(config);
17
+ if (!result.success) {
18
+ throw new config_error_js_1.ConfigError('Invalid Nodex Configuration', result.error);
19
+ }
20
+ return result.data;
21
+ }
@@ -0,0 +1,12 @@
1
+ import { type Application } from 'express';
2
+ import type { WnodexConfigOutput } from '../schemas/wnodex-config.js';
3
+ /**
4
+ * Sets up Express middlewares for the application.
5
+ * Currently applies the helmet security middleware.
6
+ * @param app The express application instance.
7
+ * @param config The Nodex parsed config object.
8
+ * @example
9
+ * this.config = setupMiddlewares();
10
+ */
11
+ export declare function setupMiddlewares(app: Application, config: WnodexConfigOutput): void;
12
+ //# sourceMappingURL=setup-middlewares.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-middlewares.d.ts","sourceRoot":"","sources":["../../src/helpers/setup-middlewares.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAWpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,kBAAkB,GACzB,IAAI,CA+BN"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupMiddlewares = setupMiddlewares;
4
+ const tslib_1 = require("tslib");
5
+ const express_1 = tslib_1.__importDefault(require("express"));
6
+ const compression_js_1 = require("../middlewares/compression.js");
7
+ const cookie_parser_ts_js_1 = require("../middlewares/cookie-parser.ts.js");
8
+ const cors_js_1 = require("../middlewares/cors.js");
9
+ const error_handler_js_1 = require("../middlewares/error-handler.js");
10
+ const helmet_js_1 = require("../middlewares/helmet.js");
11
+ const hpp_js_1 = require("../middlewares/hpp.js");
12
+ const passport_js_1 = require("../middlewares/passport.js");
13
+ const rate_limit_js_1 = require("../middlewares/rate-limit.js");
14
+ const session_js_1 = require("../middlewares/session.js");
15
+ /**
16
+ * Sets up Express middlewares for the application.
17
+ * Currently applies the helmet security middleware.
18
+ * @param app The express application instance.
19
+ * @param config The Nodex parsed config object.
20
+ * @example
21
+ * this.config = setupMiddlewares();
22
+ */
23
+ function setupMiddlewares(app, config) {
24
+ // Helmet
25
+ (0, helmet_js_1.configureHelmet)(app, config);
26
+ // CORS
27
+ (0, cors_js_1.configureCors)(app, config);
28
+ // Body Parsers
29
+ app.use(express_1.default.json());
30
+ app.use(express_1.default.urlencoded({ extended: true }));
31
+ // cookie-parser
32
+ (0, cookie_parser_ts_js_1.configureCookieParser)(app, config);
33
+ // compression
34
+ (0, compression_js_1.configureCompression)(app, config);
35
+ // express-rate-limit
36
+ (0, rate_limit_js_1.configureRateLimit)(app, config);
37
+ // hpp
38
+ (0, hpp_js_1.configureHpp)(app, config);
39
+ // express-session - Session management
40
+ (0, session_js_1.configureSession)(app, config);
41
+ // passport - Authentication middleware
42
+ (0, passport_js_1.configurePassport)(app, config);
43
+ // Error Handler (keep it last)
44
+ app.use(error_handler_js_1.errorHandler);
45
+ }
@@ -0,0 +1,39 @@
1
+ export * from './consts/cors.js';
2
+ export * from './consts/error-codes.js';
3
+ export * from './consts/log-levels.js';
4
+ export * from './consts/node-env.js';
5
+ export * from './consts/port.js';
6
+ export * from './consts/rate-limit.js';
7
+ export * from './consts/session.js';
8
+ export * from './errors/base-error.js';
9
+ export * from './errors/config-error.js';
10
+ export * from './errors/http-error.js';
11
+ export * from './errors/validation-error.js';
12
+ export * from './helpers/get-node-env.js';
13
+ export * from './helpers/is-development.js';
14
+ export * from './helpers/setup-config.js';
15
+ export * from './helpers/setup-middlewares.js';
16
+ export * from './logger.js';
17
+ export * from './middlewares/compression.js';
18
+ export * from './middlewares/cookie-parser.ts.js';
19
+ export * from './middlewares/cors.js';
20
+ export * from './middlewares/error-handler.js';
21
+ export * from './middlewares/helmet.js';
22
+ export * from './middlewares/hpp.js';
23
+ export * from './middlewares/passport.js';
24
+ export * from './middlewares/rate-limit.js';
25
+ export * from './middlewares/session.js';
26
+ export * from './schemas/compression.js';
27
+ export * from './schemas/cookie-parser.js';
28
+ export * from './schemas/cors.js';
29
+ export * from './schemas/error-metadata.js';
30
+ export * from './schemas/helmet.js';
31
+ export * from './schemas/hpp.js';
32
+ export * from './schemas/node-env.js';
33
+ export * from './schemas/passport.js';
34
+ export * from './schemas/port.js';
35
+ export * from './schemas/rate-limit.js';
36
+ export * from './schemas/session.js';
37
+ export * from './schemas/wnodex-config.js';
38
+ export * from './wnodex.js';
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./consts/cors.js"), exports);
5
+ tslib_1.__exportStar(require("./consts/error-codes.js"), exports);
6
+ tslib_1.__exportStar(require("./consts/log-levels.js"), exports);
7
+ tslib_1.__exportStar(require("./consts/node-env.js"), exports);
8
+ tslib_1.__exportStar(require("./consts/port.js"), exports);
9
+ tslib_1.__exportStar(require("./consts/rate-limit.js"), exports);
10
+ tslib_1.__exportStar(require("./consts/session.js"), exports);
11
+ tslib_1.__exportStar(require("./errors/base-error.js"), exports);
12
+ tslib_1.__exportStar(require("./errors/config-error.js"), exports);
13
+ tslib_1.__exportStar(require("./errors/http-error.js"), exports);
14
+ tslib_1.__exportStar(require("./errors/validation-error.js"), exports);
15
+ tslib_1.__exportStar(require("./helpers/get-node-env.js"), exports);
16
+ tslib_1.__exportStar(require("./helpers/is-development.js"), exports);
17
+ tslib_1.__exportStar(require("./helpers/setup-config.js"), exports);
18
+ tslib_1.__exportStar(require("./helpers/setup-middlewares.js"), exports);
19
+ tslib_1.__exportStar(require("./logger.js"), exports);
20
+ tslib_1.__exportStar(require("./middlewares/compression.js"), exports);
21
+ tslib_1.__exportStar(require("./middlewares/cookie-parser.ts.js"), exports);
22
+ tslib_1.__exportStar(require("./middlewares/cors.js"), exports);
23
+ tslib_1.__exportStar(require("./middlewares/error-handler.js"), exports);
24
+ tslib_1.__exportStar(require("./middlewares/helmet.js"), exports);
25
+ tslib_1.__exportStar(require("./middlewares/hpp.js"), exports);
26
+ tslib_1.__exportStar(require("./middlewares/passport.js"), exports);
27
+ tslib_1.__exportStar(require("./middlewares/rate-limit.js"), exports);
28
+ tslib_1.__exportStar(require("./middlewares/session.js"), exports);
29
+ tslib_1.__exportStar(require("./schemas/compression.js"), exports);
30
+ tslib_1.__exportStar(require("./schemas/cookie-parser.js"), exports);
31
+ tslib_1.__exportStar(require("./schemas/cors.js"), exports);
32
+ tslib_1.__exportStar(require("./schemas/error-metadata.js"), exports);
33
+ tslib_1.__exportStar(require("./schemas/helmet.js"), exports);
34
+ tslib_1.__exportStar(require("./schemas/hpp.js"), exports);
35
+ tslib_1.__exportStar(require("./schemas/node-env.js"), exports);
36
+ tslib_1.__exportStar(require("./schemas/passport.js"), exports);
37
+ tslib_1.__exportStar(require("./schemas/port.js"), exports);
38
+ tslib_1.__exportStar(require("./schemas/rate-limit.js"), exports);
39
+ tslib_1.__exportStar(require("./schemas/session.js"), exports);
40
+ tslib_1.__exportStar(require("./schemas/wnodex-config.js"), exports);
41
+ tslib_1.__exportStar(require("./wnodex.js"), exports);
@@ -0,0 +1,3 @@
1
+ import pino from 'pino';
2
+ export declare const logger: pino.Logger<never, boolean>;
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAiBxB,eAAO,MAAM,MAAM,6BAEE,CAAC"}
package/dist/logger.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pino_pretty_1 = tslib_1.__importDefault(require("pino-pretty"));
6
+ const pino_1 = tslib_1.__importDefault(require("pino"));
7
+ const log_levels_js_1 = require("./consts/log-levels.js");
8
+ const is_development_js_1 = require("./helpers/is-development.js");
9
+ const prettyStream = (0, pino_pretty_1.default)({
10
+ colorize: true,
11
+ levelFirst: true,
12
+ translateTime: true,
13
+ ignore: 'pid,hostname',
14
+ singleLine: true,
15
+ });
16
+ const baseOptions = {
17
+ level: log_levels_js_1.LOG_LEVELS.INFO,
18
+ };
19
+ exports.logger = (0, is_development_js_1.isDevelopment)()
20
+ ? (0, pino_1.default)(baseOptions, prettyStream)
21
+ : (0, pino_1.default)(baseOptions);
@@ -0,0 +1,18 @@
1
+ import type { Application } from 'express';
2
+ import type { WnodexConfigOutput } from '../schemas/wnodex-config.js';
3
+ /**
4
+ * Configures compression middleware to compress HTTP responses,
5
+ * improving network performance by reducing response size.
6
+ * Reads a flag from the app configuration to enable or disable compression.
7
+ * @param app Express Application instance to apply compression middleware on.
8
+ * @param config Typed Nodex configuration object containing compression option.
9
+ *
10
+ * @returns The result of app.use(compression()) if enabled, otherwise undefined.
11
+ *
12
+ * @example
13
+ * private setupMiddlewares() {
14
+ * configureCors(this.app, this.config);
15
+ * }
16
+ */
17
+ export declare function configureCompression(app: Application, config: WnodexConfigOutput): Application | undefined;
18
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/middlewares/compression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,kBAAkB,2BAS3B"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureCompression = configureCompression;
4
+ const tslib_1 = require("tslib");
5
+ const compression_1 = tslib_1.__importDefault(require("compression"));
6
+ /**
7
+ * Configures compression middleware to compress HTTP responses,
8
+ * improving network performance by reducing response size.
9
+ * Reads a flag from the app configuration to enable or disable compression.
10
+ * @param app Express Application instance to apply compression middleware on.
11
+ * @param config Typed Nodex configuration object containing compression option.
12
+ *
13
+ * @returns The result of app.use(compression()) if enabled, otherwise undefined.
14
+ *
15
+ * @example
16
+ * private setupMiddlewares() {
17
+ * configureCors(this.app, this.config);
18
+ * }
19
+ */
20
+ function configureCompression(app, config) {
21
+ const { compression: isCompressionEnabled } = config;
22
+ if (!isCompressionEnabled) {
23
+ return;
24
+ }
25
+ return app.use((0, compression_1.default)());
26
+ }
@@ -0,0 +1,20 @@
1
+ import type { Application } from 'express';
2
+ import type { WnodexConfigOutput } from '../schemas/wnodex-config.js';
3
+ /**
4
+ * Configures the cookie-parser middleware for the Express app based on the provided configuration.
5
+ * @param app The Express application instance to configure.
6
+ * @param config The application configuration object, which includes cookieParser options.
7
+ * @returns Void.
8
+ *
9
+ * @example
10
+ * ```
11
+ * import express from 'express';
12
+ * import { configureCookieParser } from './middlewares/cookie-parser';
13
+ * import config from './config';
14
+ *
15
+ * const app = express();
16
+ * configureCookieParser(app, config);
17
+ * ```
18
+ */
19
+ export declare function configureCookieParser(app: Application, config: WnodexConfigOutput): Application | undefined;
20
+ //# sourceMappingURL=cookie-parser.ts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie-parser.ts.d.ts","sourceRoot":"","sources":["../../src/middlewares/cookie-parser.ts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,kBAAkB,2BAY3B"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureCookieParser = configureCookieParser;
4
+ const tslib_1 = require("tslib");
5
+ const cookie_parser_1 = tslib_1.__importDefault(require("cookie-parser"));
6
+ /**
7
+ * Configures the cookie-parser middleware for the Express app based on the provided configuration.
8
+ * @param app The Express application instance to configure.
9
+ * @param config The application configuration object, which includes cookieParser options.
10
+ * @returns Void.
11
+ *
12
+ * @example
13
+ * ```
14
+ * import express from 'express';
15
+ * import { configureCookieParser } from './middlewares/cookie-parser';
16
+ * import config from './config';
17
+ *
18
+ * const app = express();
19
+ * configureCookieParser(app, config);
20
+ * ```
21
+ */
22
+ function configureCookieParser(app, config) {
23
+ const { cookieParser: options } = config;
24
+ if (typeof options === 'boolean') {
25
+ if (!options)
26
+ return;
27
+ return app.use((0, cookie_parser_1.default)());
28
+ }
29
+ else {
30
+ const { secret, options: opts } = options;
31
+ return app.use((0, cookie_parser_1.default)(secret, opts));
32
+ }
33
+ }
@@ -0,0 +1,22 @@
1
+ import type { Application } from 'express';
2
+ import type { WnodexConfigOutput } from '../schemas/wnodex-config.js';
3
+ /**
4
+ * Configures the CORS middleware for an Express application.
5
+ * Reads the `cors` option from the provided config.
6
+ * If the option is a boolean:
7
+ * - `false` disables CORS middleware.
8
+ * - `true` enables CORS middleware with default settings.
9
+ * If the option is an object, it is spread into the CORS middleware options.
10
+ * @param app The Express Application instance to attach middleware to.
11
+ * @param config Typed configuration input that includes the CORS option.
12
+ *
13
+ * @returns The Express Application instance with CORS middleware applied,
14
+ * or undefined if CORS is disabled.
15
+ *
16
+ * @example
17
+ * private setupMiddlewares() {
18
+ * configureCors(this.app, this.config);
19
+ * }
20
+ */
21
+ export declare function configureCors(app: Application, config: WnodexConfigOutput): Application | undefined;
22
+ //# sourceMappingURL=cors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middlewares/cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,2BAUzE"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureCors = configureCors;
4
+ const tslib_1 = require("tslib");
5
+ const cors_1 = tslib_1.__importDefault(require("cors"));
6
+ /**
7
+ * Configures the CORS middleware for an Express application.
8
+ * Reads the `cors` option from the provided config.
9
+ * If the option is a boolean:
10
+ * - `false` disables CORS middleware.
11
+ * - `true` enables CORS middleware with default settings.
12
+ * If the option is an object, it is spread into the CORS middleware options.
13
+ * @param app The Express Application instance to attach middleware to.
14
+ * @param config Typed configuration input that includes the CORS option.
15
+ *
16
+ * @returns The Express Application instance with CORS middleware applied,
17
+ * or undefined if CORS is disabled.
18
+ *
19
+ * @example
20
+ * private setupMiddlewares() {
21
+ * configureCors(this.app, this.config);
22
+ * }
23
+ */
24
+ function configureCors(app, config) {
25
+ const { cors: options } = config;
26
+ if (typeof options === 'boolean') {
27
+ if (options === false || !options)
28
+ return;
29
+ return app.use((0, cors_1.default)());
30
+ }
31
+ else {
32
+ return app.use((0, cors_1.default)({ ...options }));
33
+ }
34
+ }
@@ -0,0 +1,21 @@
1
+ import type { NextFunction, Request, Response } from 'express';
2
+ import type { HttpError } from '../errors/http-error.js';
3
+ /**
4
+ * Middleware for centralized error handling.
5
+ * Catches all errors thrown in the application and responds with a structured JSON.
6
+ * Logs the error for debugging purposes.
7
+ * @param err The thrown error object or value.
8
+ * @param _req The current Express request object.
9
+ * @param res The current Express response object.
10
+ * @param _next Next middleware function in chain.
11
+ *
12
+ * @example
13
+ * private setupMiddlewares() {
14
+ * // other middlewares
15
+ * // ...
16
+ * // Configure errorHandler as the last one middleware.
17
+ * app.use(errorHandler);
18
+ * }
19
+ */
20
+ export declare function errorHandler(err: HttpError | Error, _req: Request, res: Response, _next: NextFunction): void;
21
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/middlewares/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGzD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,SAAS,GAAG,KAAK,EACtB,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,YAAY,GAClB,IAAI,CA0BN"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorHandler = errorHandler;
4
+ const is_development_js_1 = require("../helpers/is-development.js");
5
+ /**
6
+ * Middleware for centralized error handling.
7
+ * Catches all errors thrown in the application and responds with a structured JSON.
8
+ * Logs the error for debugging purposes.
9
+ * @param err The thrown error object or value.
10
+ * @param _req The current Express request object.
11
+ * @param res The current Express response object.
12
+ * @param _next Next middleware function in chain.
13
+ *
14
+ * @example
15
+ * private setupMiddlewares() {
16
+ * // other middlewares
17
+ * // ...
18
+ * // Configure errorHandler as the last one middleware.
19
+ * app.use(errorHandler);
20
+ * }
21
+ */
22
+ function errorHandler(err, _req, res, _next) {
23
+ // Log the error for server debugging
24
+ console.error(err);
25
+ // Determine HTTP status code; default to 500 if unavailable
26
+ const statusCode = typeof err === 'object' && err !== null && 'statusCode' in err
27
+ ? err.statusCode
28
+ : 500;
29
+ // Get message or default to 'Internal Server Error'
30
+ const message = typeof err === 'object' && err !== null && 'message' in err
31
+ ? err.message
32
+ : 'Internal Server Error';
33
+ // Send JSON response
34
+ res.status(statusCode).json({
35
+ error: {
36
+ message,
37
+ // Show stack trace only in development environment
38
+ ...((0, is_development_js_1.isDevelopment)() && {
39
+ stack: err.stack,
40
+ }),
41
+ },
42
+ });
43
+ }
@@ -0,0 +1,16 @@
1
+ import type { Application } from 'express';
2
+ import type { WnodexConfigOutput } from '../schemas/wnodex-config.js';
3
+ /**
4
+ * Configures the Helmet middleware in an Express app.
5
+ * @param app The Express Application instance on which to apply Helmet.
6
+ * @param config Typed project configuration from which the Helmet option is read.
7
+ *
8
+ * @returns The Express Application instance (`app`) if Helmet is enable.
9
+ *
10
+ * @example
11
+ * private setupMiddlewares() {
12
+ * configureHelmet(this.app, this.config);
13
+ * }
14
+ */
15
+ export declare function configureHelmet(app: Application, config: WnodexConfigOutput): Application | undefined;
16
+ //# sourceMappingURL=helmet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helmet.d.ts","sourceRoot":"","sources":["../../src/middlewares/helmet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,kBAAkB,2BAU3E"}