wnodex 0.1.0 → 0.2.2

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 (207) hide show
  1. package/.turbo/turbo-build.log +7 -0
  2. package/LICENSE +1 -1
  3. package/README.md +73 -67
  4. package/dist/{schemas/wnodex-config.d.ts → config.d.ts} +14 -9
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/config.js +22 -0
  7. package/dist/index.d.ts +68 -38
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +126 -41
  10. package/dist/setup-config.d.ts +3 -0
  11. package/dist/setup-config.d.ts.map +1 -0
  12. package/dist/setup-config.js +9 -0
  13. package/dist/setup-middlewares.d.ts +4 -0
  14. package/dist/setup-middlewares.d.ts.map +1 -0
  15. package/dist/setup-middlewares.js +32 -0
  16. package/package.json +51 -15
  17. package/rolldown.config.ts +20 -0
  18. package/src/config.ts +27 -0
  19. package/src/index.ts +149 -38
  20. package/src/setup-config.ts +17 -0
  21. package/src/setup-middlewares.ts +49 -0
  22. package/tests/body-parser.schema.test.ts +57 -0
  23. package/tests/compression.schema.test.ts +27 -0
  24. package/tests/cookie-parser.schema.test.ts +56 -0
  25. package/tests/cors.schema.test.ts +35 -0
  26. package/tests/helmet.schema.test.ts +33 -0
  27. package/tests/hpp.schema.test.ts +31 -0
  28. package/tests/index.test.ts +105 -0
  29. package/tests/passport.schema.test.ts +33 -0
  30. package/tests/rate-limit.schema.test.ts +56 -0
  31. package/tests/session.schema.test.ts +80 -0
  32. package/tsconfig.json +8 -8
  33. package/vitest.config.ts +13 -0
  34. package/dist/consts/cors.d.ts +0 -15
  35. package/dist/consts/cors.d.ts.map +0 -1
  36. package/dist/consts/cors.js +0 -29
  37. package/dist/consts/error-codes.d.ts +0 -10
  38. package/dist/consts/error-codes.d.ts.map +0 -1
  39. package/dist/consts/error-codes.js +0 -12
  40. package/dist/consts/index.d.ts +0 -8
  41. package/dist/consts/index.d.ts.map +0 -1
  42. package/dist/consts/index.js +0 -10
  43. package/dist/consts/log-levels.d.ts +0 -8
  44. package/dist/consts/log-levels.d.ts.map +0 -1
  45. package/dist/consts/log-levels.js +0 -10
  46. package/dist/consts/node-env.d.ts +0 -7
  47. package/dist/consts/node-env.d.ts.map +0 -1
  48. package/dist/consts/node-env.js +0 -9
  49. package/dist/consts/port.d.ts +0 -6
  50. package/dist/consts/port.d.ts.map +0 -1
  51. package/dist/consts/port.js +0 -26
  52. package/dist/consts/rate-limit.d.ts +0 -9
  53. package/dist/consts/rate-limit.d.ts.map +0 -1
  54. package/dist/consts/rate-limit.js +0 -11
  55. package/dist/consts/session.d.ts +0 -6
  56. package/dist/consts/session.d.ts.map +0 -1
  57. package/dist/consts/session.js +0 -8
  58. package/dist/errors/base-error.d.ts +0 -57
  59. package/dist/errors/base-error.d.ts.map +0 -1
  60. package/dist/errors/base-error.js +0 -93
  61. package/dist/errors/config-error.d.ts +0 -20
  62. package/dist/errors/config-error.d.ts.map +0 -1
  63. package/dist/errors/config-error.js +0 -30
  64. package/dist/errors/http-error.d.ts +0 -17
  65. package/dist/errors/http-error.d.ts.map +0 -1
  66. package/dist/errors/http-error.js +0 -24
  67. package/dist/errors/index.d.ts +0 -5
  68. package/dist/errors/index.d.ts.map +0 -1
  69. package/dist/errors/index.js +0 -7
  70. package/dist/errors/validation-error.d.ts +0 -19
  71. package/dist/errors/validation-error.d.ts.map +0 -1
  72. package/dist/errors/validation-error.js +0 -29
  73. package/dist/helpers/get-node-env.d.ts +0 -13
  74. package/dist/helpers/get-node-env.d.ts.map +0 -1
  75. package/dist/helpers/get-node-env.js +0 -27
  76. package/dist/helpers/index.d.ts +0 -5
  77. package/dist/helpers/index.d.ts.map +0 -1
  78. package/dist/helpers/index.js +0 -7
  79. package/dist/helpers/is-development.d.ts +0 -9
  80. package/dist/helpers/is-development.d.ts.map +0 -1
  81. package/dist/helpers/is-development.js +0 -16
  82. package/dist/helpers/setup-config.d.ts +0 -12
  83. package/dist/helpers/setup-config.d.ts.map +0 -1
  84. package/dist/helpers/setup-config.js +0 -21
  85. package/dist/helpers/setup-middlewares.d.ts +0 -12
  86. package/dist/helpers/setup-middlewares.d.ts.map +0 -1
  87. package/dist/helpers/setup-middlewares.js +0 -45
  88. package/dist/logger.d.ts +0 -3
  89. package/dist/logger.d.ts.map +0 -1
  90. package/dist/logger.js +0 -21
  91. package/dist/middlewares/compression.d.ts +0 -18
  92. package/dist/middlewares/compression.d.ts.map +0 -1
  93. package/dist/middlewares/compression.js +0 -26
  94. package/dist/middlewares/cookie-parser.ts.d.ts +0 -20
  95. package/dist/middlewares/cookie-parser.ts.d.ts.map +0 -1
  96. package/dist/middlewares/cookie-parser.ts.js +0 -33
  97. package/dist/middlewares/cors.d.ts +0 -22
  98. package/dist/middlewares/cors.d.ts.map +0 -1
  99. package/dist/middlewares/cors.js +0 -34
  100. package/dist/middlewares/error-handler.d.ts +0 -21
  101. package/dist/middlewares/error-handler.d.ts.map +0 -1
  102. package/dist/middlewares/error-handler.js +0 -43
  103. package/dist/middlewares/helmet.d.ts +0 -16
  104. package/dist/middlewares/helmet.d.ts.map +0 -1
  105. package/dist/middlewares/helmet.js +0 -28
  106. package/dist/middlewares/hpp.d.ts +0 -18
  107. package/dist/middlewares/hpp.d.ts.map +0 -1
  108. package/dist/middlewares/hpp.js +0 -30
  109. package/dist/middlewares/index.d.ts +0 -10
  110. package/dist/middlewares/index.d.ts.map +0 -1
  111. package/dist/middlewares/index.js +0 -12
  112. package/dist/middlewares/passport.d.ts +0 -16
  113. package/dist/middlewares/passport.d.ts.map +0 -1
  114. package/dist/middlewares/passport.js +0 -27
  115. package/dist/middlewares/rate-limit.d.ts +0 -23
  116. package/dist/middlewares/rate-limit.d.ts.map +0 -1
  117. package/dist/middlewares/rate-limit.js +0 -35
  118. package/dist/middlewares/session.d.ts +0 -16
  119. package/dist/middlewares/session.d.ts.map +0 -1
  120. package/dist/middlewares/session.js +0 -23
  121. package/dist/schemas/compression.d.ts +0 -5
  122. package/dist/schemas/compression.d.ts.map +0 -1
  123. package/dist/schemas/compression.js +0 -5
  124. package/dist/schemas/cookie-parser.d.ts +0 -9
  125. package/dist/schemas/cookie-parser.d.ts.map +0 -1
  126. package/dist/schemas/cookie-parser.js +0 -14
  127. package/dist/schemas/cors.d.ts +0 -6
  128. package/dist/schemas/cors.d.ts.map +0 -1
  129. package/dist/schemas/cors.js +0 -9
  130. package/dist/schemas/error-metadata.d.ts +0 -18
  131. package/dist/schemas/error-metadata.d.ts.map +0 -1
  132. package/dist/schemas/error-metadata.js +0 -12
  133. package/dist/schemas/helmet.d.ts +0 -6
  134. package/dist/schemas/helmet.d.ts.map +0 -1
  135. package/dist/schemas/helmet.js +0 -8
  136. package/dist/schemas/hpp.d.ts +0 -5
  137. package/dist/schemas/hpp.d.ts.map +0 -1
  138. package/dist/schemas/hpp.js +0 -8
  139. package/dist/schemas/index.d.ts +0 -13
  140. package/dist/schemas/index.d.ts.map +0 -1
  141. package/dist/schemas/index.js +0 -15
  142. package/dist/schemas/node-env.d.ts +0 -16
  143. package/dist/schemas/node-env.d.ts.map +0 -1
  144. package/dist/schemas/node-env.js +0 -8
  145. package/dist/schemas/passport.d.ts +0 -6
  146. package/dist/schemas/passport.d.ts.map +0 -1
  147. package/dist/schemas/passport.js +0 -8
  148. package/dist/schemas/port.d.ts +0 -4
  149. package/dist/schemas/port.d.ts.map +0 -1
  150. package/dist/schemas/port.js +0 -16
  151. package/dist/schemas/rate-limit.d.ts +0 -9
  152. package/dist/schemas/rate-limit.d.ts.map +0 -1
  153. package/dist/schemas/rate-limit.js +0 -26
  154. package/dist/schemas/session.d.ts +0 -18
  155. package/dist/schemas/session.d.ts.map +0 -1
  156. package/dist/schemas/session.js +0 -32
  157. package/dist/schemas/wnodex-config.d.ts.map +0 -1
  158. package/dist/schemas/wnodex-config.js +0 -24
  159. package/dist/tsconfig.lib.tsbuildinfo +0 -1
  160. package/dist/wnodex.d.ts +0 -69
  161. package/dist/wnodex.d.ts.map +0 -1
  162. package/dist/wnodex.js +0 -131
  163. package/src/consts/cors.ts +0 -27
  164. package/src/consts/error-codes.ts +0 -9
  165. package/src/consts/index.ts +0 -7
  166. package/src/consts/log-levels.ts +0 -7
  167. package/src/consts/node-env.ts +0 -6
  168. package/src/consts/port.ts +0 -23
  169. package/src/consts/rate-limit.ts +0 -9
  170. package/src/consts/session.ts +0 -6
  171. package/src/errors/base-error.ts +0 -111
  172. package/src/errors/config-error.ts +0 -31
  173. package/src/errors/http-error.ts +0 -21
  174. package/src/errors/index.ts +0 -4
  175. package/src/errors/validation-error.ts +0 -30
  176. package/src/helpers/get-node-env.ts +0 -27
  177. package/src/helpers/index.ts +0 -4
  178. package/src/helpers/is-development.ts +0 -15
  179. package/src/helpers/setup-config.ts +0 -25
  180. package/src/helpers/setup-middlewares.ts +0 -56
  181. package/src/logger.ts +0 -22
  182. package/src/middlewares/compression.ts +0 -32
  183. package/src/middlewares/cookie-parser.ts.ts +0 -37
  184. package/src/middlewares/cors.ts +0 -35
  185. package/src/middlewares/error-handler.ts +0 -54
  186. package/src/middlewares/helmet.ts +0 -29
  187. package/src/middlewares/hpp.ts +0 -31
  188. package/src/middlewares/index.ts +0 -9
  189. package/src/middlewares/passport.ts +0 -30
  190. package/src/middlewares/rate-limit.ts +0 -39
  191. package/src/middlewares/session.ts +0 -25
  192. package/src/schemas/compression.ts +0 -8
  193. package/src/schemas/cookie-parser.ts +0 -21
  194. package/src/schemas/cors.ts +0 -13
  195. package/src/schemas/error-metadata.ts +0 -15
  196. package/src/schemas/helmet.ts +0 -11
  197. package/src/schemas/hpp.ts +0 -9
  198. package/src/schemas/index.ts +0 -12
  199. package/src/schemas/node-env.ts +0 -11
  200. package/src/schemas/passport.ts +0 -11
  201. package/src/schemas/port.ts +0 -22
  202. package/src/schemas/rate-limit.ts +0 -33
  203. package/src/schemas/session.ts +0 -40
  204. package/src/schemas/wnodex-config.ts +0 -26
  205. package/src/wnodex.ts +0 -152
  206. package/tsconfig.lib.json +0 -13
  207. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,105 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import supertest from 'supertest';
4
+
5
+ import { Wnodex } from '../src/index.js';
6
+
7
+ describe('Wnodex', () => {
8
+ let wnodex: Wnodex;
9
+
10
+ beforeEach(() => {
11
+ // To see the logs, uncomment the following line
12
+ // vi.spyOn(console, 'log').mockImplementation(() => {});
13
+ });
14
+
15
+ it('should create a new Wnodex instance', () => {
16
+ wnodex = new Wnodex({ port: 3000 });
17
+ expect(wnodex).toBeInstanceOf(Wnodex);
18
+ });
19
+
20
+ it('should get the express app instance', () => {
21
+ wnodex = new Wnodex({ port: 3000 });
22
+ const app = wnodex.getApp();
23
+ expect(app).toBeDefined();
24
+ });
25
+
26
+ it('should get the config', () => {
27
+ const config = { port: 3001 };
28
+ wnodex = new Wnodex(config);
29
+ const wnodexConfig = wnodex.getConfig();
30
+ expect(wnodexConfig.port).toBe(3001);
31
+ });
32
+
33
+ it('should get the logger', () => {
34
+ wnodex = new Wnodex({ port: 3000 });
35
+ const logger = wnodex.getLogger();
36
+ expect(logger).toBeDefined();
37
+ });
38
+
39
+ it('should start and shutdown the server', async () => {
40
+ wnodex = new Wnodex({ port: 3002 });
41
+ const logger = wnodex.getLogger();
42
+ const infoSpy = vi.spyOn(logger, 'info');
43
+
44
+ await wnodex.start();
45
+ expect(infoSpy).toHaveBeenCalledWith(
46
+ 'Server running @ http://localhost:3002'
47
+ );
48
+
49
+ await wnodex.shutdown();
50
+ expect(infoSpy).toHaveBeenCalledWith('Shutdown initiated...');
51
+ expect(infoSpy).toHaveBeenCalledWith('Server stopped gracefully.');
52
+ });
53
+
54
+ it('should respond to a basic request', async () => {
55
+ wnodex = new Wnodex({ port: 3003 });
56
+ const app = wnodex.getApp();
57
+
58
+ app.get('/test', (req, res) => {
59
+ res.status(200).send('OK');
60
+ });
61
+
62
+ await wnodex.start();
63
+
64
+ const response = await supertest(app).get('/test');
65
+ expect(response.status).toBe(200);
66
+ expect(response.text).toBe('OK');
67
+ await wnodex.shutdown();
68
+ });
69
+
70
+ it('should not throw when shutdown is called on a non-running server', async () => {
71
+ wnodex = new Wnodex({ port: 3000 });
72
+ const logger = wnodex.getLogger();
73
+ const warnSpy = vi.spyOn(logger, 'warn');
74
+
75
+ await wnodex.shutdown();
76
+
77
+ expect(warnSpy).toHaveBeenCalledWith('Server not running.');
78
+ });
79
+
80
+ it('should call cleanup chores on shutdown', async () => {
81
+ wnodex = new Wnodex({ port: 3004 });
82
+ const chores = vi.fn().mockImplementation(() => Promise.resolve());
83
+
84
+ await wnodex.start();
85
+ await wnodex.shutdown(chores);
86
+
87
+ expect(chores).toHaveBeenCalled();
88
+ });
89
+
90
+ it('should handle errors during cleanup chores', async () => {
91
+ wnodex = new Wnodex({ port: 3005 });
92
+ const logger = wnodex.getLogger();
93
+ const errorSpy = vi.spyOn(logger, 'error');
94
+ const chores = vi.fn().mockRejectedValue(new Error('Cleanup failed'));
95
+
96
+ await wnodex.start();
97
+ await wnodex.shutdown(chores);
98
+
99
+ expect(chores).toHaveBeenCalled();
100
+ expect(errorSpy).toHaveBeenCalledWith(
101
+ expect.any(Error),
102
+ 'Error during cleanup chores'
103
+ );
104
+ });
105
+ });
@@ -0,0 +1,33 @@
1
+ import passport from 'passport';
2
+
3
+ import { describe, expect, it } from 'vitest';
4
+
5
+ import { parsePassportOptions } from '../../passport/src/parse-options';
6
+
7
+ describe('PassportOptionsSchema', () => {
8
+ it('should return default when input is undefined', () => {
9
+ const options = parsePassportOptions();
10
+ expect(options).toBe(false);
11
+ });
12
+
13
+ it('should return true when input is true', () => {
14
+ const options = parsePassportOptions(true);
15
+ expect(options).toBe(true);
16
+ });
17
+
18
+ it('should return false when input is false', () => {
19
+ const options = parsePassportOptions(false);
20
+ expect(options).toBe(false);
21
+ });
22
+
23
+ it('should return the passport instance when provided', () => {
24
+ const customPassport = new passport.Passport();
25
+ const options = parsePassportOptions(customPassport);
26
+ expect(options).toBe(customPassport);
27
+ });
28
+
29
+ it('should throw an error for invalid input', () => {
30
+ // @ts-expect-error - Testing invalid input
31
+ expect(() => parsePassportOptions(123)).toThrow('Invalid Passport options');
32
+ });
33
+ });
@@ -0,0 +1,56 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { DEFAULT_RATE_LIMIT_OPTIONS } from '../../rate-limit/src/defaults';
4
+ import { parseRateLimitOptions } from '../../rate-limit/src/parse-options';
5
+
6
+ describe('RateLimitOptionsSchema', () => {
7
+ it('should return default when input is undefined', () => {
8
+ const options = parseRateLimitOptions();
9
+ expect(options).toEqual(DEFAULT_RATE_LIMIT_OPTIONS);
10
+ });
11
+
12
+ it('should return true when input is true', () => {
13
+ const options = parseRateLimitOptions(true);
14
+ expect(options).toBe(true);
15
+ });
16
+
17
+ it('should return false when input is false', () => {
18
+ const options = parseRateLimitOptions(false);
19
+ expect(options).toBe(false);
20
+ });
21
+
22
+ it('should return the custom options when provided', () => {
23
+ const customOptions = {
24
+ windowMs: 1000,
25
+ max: 10,
26
+ message: 'Too many requests',
27
+ };
28
+ const options = parseRateLimitOptions(customOptions);
29
+ expect(options).toEqual(customOptions);
30
+ });
31
+
32
+ it('should use defaults for missing properties', () => {
33
+ const customOptions = {
34
+ max: 50,
35
+ };
36
+ const options = parseRateLimitOptions(customOptions);
37
+ expect(options).toEqual({
38
+ ...DEFAULT_RATE_LIMIT_OPTIONS,
39
+ ...customOptions,
40
+ });
41
+ });
42
+
43
+ it('should throw an error for invalid input', () => {
44
+ // @ts-expect-error - Testing invalid input
45
+ expect(() => parseRateLimitOptions('invalid')).toThrow(
46
+ 'Invalid rate-limit options'
47
+ );
48
+ });
49
+
50
+ it('should throw an error for an invalid object', () => {
51
+ // @ts-expect-error - Testing invalid input
52
+ expect(() => parseRateLimitOptions({ windowMs: -100 })).toThrow(
53
+ 'Invalid rate-limit options'
54
+ );
55
+ });
56
+ });
@@ -0,0 +1,80 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ DEFAULT_SESSION_COOKIE_HTTP_ONLY,
5
+ DEFAULT_SESSION_COOKIE_MAX_AGE,
6
+ DEFAULT_SESSION_COOKIE_SECURE,
7
+ DEFAULT_SESSION_RESAVE,
8
+ DEFAULT_SESSION_SAVE_UNINITIALIZED,
9
+ } from '../../session/src/defaults';
10
+ import { parseSessionOptions } from '../../session/src/parse-options';
11
+
12
+ describe('SessionOptionsSchema', () => {
13
+ it('should return default when input is undefined', () => {
14
+ const options = parseSessionOptions();
15
+ expect(options).toBe(false);
16
+ });
17
+
18
+ it('should return false when input is false', () => {
19
+ const options = parseSessionOptions(false);
20
+ expect(options).toBe(false);
21
+ });
22
+
23
+ it('should return the session options with defaults for a valid secret', () => {
24
+ const secret = 'my-secret';
25
+ const options = parseSessionOptions({ secret });
26
+ expect(options).toEqual({
27
+ secret,
28
+ resave: DEFAULT_SESSION_RESAVE,
29
+ saveUninitialized: DEFAULT_SESSION_SAVE_UNINITIALIZED,
30
+ cookie: {
31
+ secure: DEFAULT_SESSION_COOKIE_SECURE,
32
+ maxAge: DEFAULT_SESSION_COOKIE_MAX_AGE,
33
+ httpOnly: DEFAULT_SESSION_COOKIE_HTTP_ONLY,
34
+ },
35
+ });
36
+ });
37
+
38
+ it('should return the full custom options when provided', () => {
39
+ const customOptions = {
40
+ secret: 'my-secret',
41
+ resave: true,
42
+ saveUninitialized: true,
43
+ cookie: {
44
+ secure: true,
45
+ maxAge: 86_400_000,
46
+ httpOnly: false,
47
+ },
48
+ };
49
+ const options = parseSessionOptions(customOptions);
50
+ expect(options).toEqual(customOptions);
51
+ });
52
+
53
+ it('should throw an error for invalid input', () => {
54
+ // @ts-expect-error - Testing invalid input
55
+ expect(() => parseSessionOptions(true)).toThrow('Invalid session options');
56
+ });
57
+
58
+ it('should throw an error for an empty object', () => {
59
+ // @ts-expect-error - Testing invalid input
60
+ expect(() => parseSessionOptions({})).toThrow('Invalid session options');
61
+ });
62
+
63
+ it('should use defaults for cookie when partial cookie is provided', () => {
64
+ const secret = 'my-secret';
65
+ const options = parseSessionOptions({
66
+ secret,
67
+ cookie: { maxAge: 1000 },
68
+ });
69
+ expect(options).toEqual({
70
+ secret,
71
+ resave: DEFAULT_SESSION_RESAVE,
72
+ saveUninitialized: DEFAULT_SESSION_SAVE_UNINITIALIZED,
73
+ cookie: {
74
+ secure: DEFAULT_SESSION_COOKIE_SECURE,
75
+ maxAge: 1000,
76
+ httpOnly: DEFAULT_SESSION_COOKIE_HTTP_ONLY,
77
+ },
78
+ });
79
+ });
80
+ });
package/tsconfig.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
- "extends": "../../tsconfig.base.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "./tsconfig.lib.json"
8
- }
9
- ]
2
+ "extends": "@wnodex/typescript-config/base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "tsBuildInfoFile": "./dist/.tsbuildinfo"
7
+ },
8
+ "include": ["src/**/*"],
9
+ "exclude": ["node_modules", "**/*.test.ts"]
10
10
  }
@@ -0,0 +1,13 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vitest/config';
3
+
4
+ export default defineConfig({
5
+ test: {
6
+ globals: true,
7
+ environment: 'node',
8
+ coverage: {
9
+ provider: 'v8',
10
+ reporter: ['text', 'json', 'html'],
11
+ },
12
+ },
13
+ });
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,29 +0,0 @@
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
- };
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/consts/error-codes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;CAQd,CAAC"}
@@ -1,12 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,10 +0,0 @@
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);
@@ -1,8 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"log-levels.d.ts","sourceRoot":"","sources":["../../src/consts/log-levels.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;CAMb,CAAC"}
@@ -1,10 +0,0 @@
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
- };
@@ -1,7 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-env.d.ts","sourceRoot":"","sources":["../../src/consts/node-env.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC"}
@@ -1,9 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,26 +0,0 @@
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]);
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,11 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,8 +0,0 @@
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;
@@ -1,57 +0,0 @@
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
@@ -1 +0,0 @@
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"}