@arikajs/http 0.0.4 → 0.0.6

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 (53) hide show
  1. package/README.md +33 -11
  2. package/dist/HttpKernel.d.ts +40 -0
  3. package/dist/HttpKernel.d.ts.map +1 -0
  4. package/dist/HttpKernel.js +75 -0
  5. package/dist/HttpKernel.js.map +1 -0
  6. package/dist/HttpServiceProvider.d.ts +13 -0
  7. package/dist/HttpServiceProvider.d.ts.map +1 -0
  8. package/dist/HttpServiceProvider.js +25 -0
  9. package/dist/HttpServiceProvider.js.map +1 -0
  10. package/dist/Middleware/BodyParserMiddleware.d.ts.map +1 -1
  11. package/dist/Middleware/BodyParserMiddleware.js +30 -2
  12. package/dist/Middleware/BodyParserMiddleware.js.map +1 -1
  13. package/dist/Middleware/SecurityHeaders.d.ts +12 -0
  14. package/dist/Middleware/SecurityHeaders.d.ts.map +1 -0
  15. package/dist/Middleware/SecurityHeaders.js +31 -0
  16. package/dist/Middleware/SecurityHeaders.js.map +1 -0
  17. package/dist/Middleware/ServeStaticMiddleware.d.ts +8 -0
  18. package/dist/Middleware/ServeStaticMiddleware.d.ts.map +1 -0
  19. package/dist/Middleware/ServeStaticMiddleware.js +35 -0
  20. package/dist/Middleware/ServeStaticMiddleware.js.map +1 -0
  21. package/dist/Middleware/Throttle.d.ts +17 -0
  22. package/dist/Middleware/Throttle.d.ts.map +1 -0
  23. package/dist/Middleware/Throttle.js +61 -0
  24. package/dist/Middleware/Throttle.js.map +1 -0
  25. package/dist/ObjectPool.d.ts +27 -0
  26. package/dist/ObjectPool.d.ts.map +1 -0
  27. package/dist/ObjectPool.js +50 -0
  28. package/dist/ObjectPool.js.map +1 -0
  29. package/dist/Pipeline.d.ts +23 -0
  30. package/dist/Pipeline.d.ts.map +1 -0
  31. package/dist/Pipeline.js +61 -0
  32. package/dist/Pipeline.js.map +1 -0
  33. package/dist/RawResponse.d.ts +9 -0
  34. package/dist/RawResponse.d.ts.map +1 -0
  35. package/dist/RawResponse.js +27 -0
  36. package/dist/RawResponse.js.map +1 -0
  37. package/dist/Request.d.ts +53 -3
  38. package/dist/Request.d.ts.map +1 -1
  39. package/dist/Request.js +170 -7
  40. package/dist/Request.js.map +1 -1
  41. package/dist/Response.d.ts +20 -3
  42. package/dist/Response.d.ts.map +1 -1
  43. package/dist/Response.js +48 -4
  44. package/dist/Response.js.map +1 -1
  45. package/dist/Router.d.ts +34 -0
  46. package/dist/Router.d.ts.map +1 -0
  47. package/dist/Router.js +150 -0
  48. package/dist/Router.js.map +1 -0
  49. package/dist/index.d.ts +8 -0
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +8 -0
  52. package/dist/index.js.map +1 -1
  53. package/package.json +13 -6
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Arika HTTP
2
2
 
3
+ <div align="center">
4
+
5
+ <img src="../cli/templates/app/public/assets/img/logo.png" alt="ArikaJS Logo" width="400">
6
+
7
+ </div>
8
+
3
9
  `@arikajs/http` is the **web engine** for the ArikaJS ecosystem.
4
10
 
5
11
  Arika HTTP provides a native, framework-controlled HTTP layer that sits directly on top of Node.js HTTP primitives. It handles the request lifecycle, routing, and middleware without relying on external frameworks like Express or Fastify.
@@ -199,17 +205,33 @@ return response
199
205
 
200
206
  ---
201
207
 
202
- ## Project Structure (recommended)
203
-
204
- - `src/`
205
- - `HttpKernel.ts` – The main HTTP entry point
206
- - `Router.ts` – The route collection and dispatcher
207
- - `Request.ts` – HTTP Request abstraction
208
- - `Response.ts` – HTTP Response builder
209
- - `Pipeline.ts` – Middleware execution engine
210
- - `Middleware/` – Built-in middleware (e.g., BodyParser)
211
- - `index.ts` – Public exports
212
- - `tests/` – Unit tests for the HTTP layer
208
+ ## 🏗 Architecture
209
+
210
+ ```text
211
+ http/
212
+ ├── src/
213
+ │ ├── Contracts
214
+ │ │ └── Application.ts
215
+ │ ├── Exceptions
216
+ │ │ └── HttpException.ts
217
+ │ ├── Middleware
218
+ │ │ ├── BodyParserMiddleware.ts
219
+ │ │ ├── ConvertEmptyStringsToNull.ts
220
+ │ │ ├── CorsMiddleware.ts
221
+ │ │ └── TrimStrings.ts
222
+ │ ├── HttpKernel.ts
223
+ │ ├── HttpServiceProvider.ts
224
+ │ ├── index.ts
225
+ │ ├── Middleware.ts
226
+ │ ├── Pipeline.ts
227
+ │ ├── Request.ts
228
+ │ ├── Response.ts
229
+ │ └── Router.ts
230
+ ├── tests/
231
+ ├── package.json
232
+ ├── tsconfig.json
233
+ └── README.md
234
+ ```
213
235
 
214
236
  ---
215
237
 
@@ -0,0 +1,40 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { Application } from './Contracts/Application';
3
+ import { Request } from './Request';
4
+ import { Response } from './Response';
5
+ import { Router } from './Router';
6
+ export declare class HttpKernel {
7
+ protected app: Application;
8
+ protected middleware: any[];
9
+ protected router: Router;
10
+ constructor(app: Application);
11
+ /**
12
+ * Get the router instance.
13
+ */
14
+ getRouter(): Router;
15
+ /**
16
+ * Set the router instance.
17
+ */
18
+ setRouter(router: Router): void;
19
+ /**
20
+ * Add global middleware.
21
+ */
22
+ use(middleware: any): this;
23
+ /**
24
+ * Handle an incoming HTTP request.
25
+ */
26
+ handle(req: IncomingMessage, res: ServerResponse): Promise<void>;
27
+ /**
28
+ * Send the given request through the middleware / router.
29
+ */
30
+ protected sendRequestThroughRouter(request: Request, response: Response): Promise<Response>;
31
+ /**
32
+ * Dispatch the request to the router.
33
+ */
34
+ protected dispatchToRouter(request: Request, response: Response): Promise<Response>;
35
+ /**
36
+ * Handle an exception during request execution.
37
+ */
38
+ protected handleException(error: any, res: ServerResponse): void;
39
+ }
40
+ //# sourceMappingURL=HttpKernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpKernel.d.ts","sourceRoot":"","sources":["../src/HttpKernel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,UAAU;IAIP,SAAS,CAAC,GAAG,EAAE,WAAW;IAHtC,SAAS,CAAC,UAAU,EAAE,GAAG,EAAE,CAAM;IACjC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEH,GAAG,EAAE,WAAW;IAItC;;OAEG;IACI,SAAS,IAAI,MAAM;IAI1B;;OAEG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAItC;;OAEG;IACI,GAAG,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAKjC;;OAEG;IACU,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAa7E;;OAEG;cACa,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMjG;;OAEG;cACa,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIzF;;OAEG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,cAAc,GAAG,IAAI;CAYnE"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpKernel = void 0;
4
+ const Request_1 = require("./Request");
5
+ const Response_1 = require("./Response");
6
+ const Pipeline_1 = require("./Pipeline");
7
+ const Router_1 = require("./Router");
8
+ class HttpKernel {
9
+ constructor(app) {
10
+ this.app = app;
11
+ this.middleware = [];
12
+ this.router = new Router_1.Router();
13
+ }
14
+ /**
15
+ * Get the router instance.
16
+ */
17
+ getRouter() {
18
+ return this.router;
19
+ }
20
+ /**
21
+ * Set the router instance.
22
+ */
23
+ setRouter(router) {
24
+ this.router = router;
25
+ }
26
+ /**
27
+ * Add global middleware.
28
+ */
29
+ use(middleware) {
30
+ this.middleware.push(middleware);
31
+ return this;
32
+ }
33
+ /**
34
+ * Handle an incoming HTTP request.
35
+ */
36
+ async handle(req, res) {
37
+ try {
38
+ const request = new Request_1.Request(this.app, req);
39
+ const response = new Response_1.Response(res);
40
+ const result = await this.sendRequestThroughRouter(request, response);
41
+ result.terminate();
42
+ }
43
+ catch (error) {
44
+ this.handleException(error, res);
45
+ }
46
+ }
47
+ /**
48
+ * Send the given request through the middleware / router.
49
+ */
50
+ async sendRequestThroughRouter(request, response) {
51
+ return (new Pipeline_1.Pipeline(this.app.getContainer()))
52
+ .pipe(this.middleware)
53
+ .handle(request, (req) => this.dispatchToRouter(req, response), response);
54
+ }
55
+ /**
56
+ * Dispatch the request to the router.
57
+ */
58
+ async dispatchToRouter(request, response) {
59
+ return this.router.dispatch(request, response);
60
+ }
61
+ /**
62
+ * Handle an exception during request execution.
63
+ */
64
+ handleException(error, res) {
65
+ const response = new Response_1.Response(res);
66
+ const status = error.statusCode || error.status || 500;
67
+ response.status(status).json({
68
+ message: error.message || 'Internal Server Error',
69
+ error: process.env.NODE_ENV === 'development' ? error.stack : undefined
70
+ });
71
+ response.terminate();
72
+ }
73
+ }
74
+ exports.HttpKernel = HttpKernel;
75
+ //# sourceMappingURL=HttpKernel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpKernel.js","sourceRoot":"","sources":["../src/HttpKernel.ts"],"names":[],"mappings":";;;AAEA,uCAAoC;AACpC,yCAAsC;AACtC,yCAAsC;AACtC,qCAAkC;AAElC,MAAa,UAAU;IAInB,YAAsB,GAAgB;QAAhB,QAAG,GAAH,GAAG,CAAa;QAH5B,eAAU,GAAU,EAAE,CAAC;QAI7B,IAAI,CA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jE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACO,eAAe,CAAC,KAAU,EAAE,GAAmB;QACrD,MAAM,QAAQ,GAAG,IAAI,mBAAQ,CAAC,GAAG,CAAC,CAAC;QAEnC,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;QAEvD,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC;YACzB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,uBAAuB;YACjD,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAC1E,CAAC,CAAC;QAEH,QAAQ,CAAC,SAAS,EAAE,CAAC;IACzB,CAAC;CACJ;AA7ED,gCA6EC"}
@@ -0,0 +1,13 @@
1
+ export declare class HttpServiceProvider {
2
+ protected app: any;
3
+ constructor(app: any);
4
+ /**
5
+ * Register the service provider.
6
+ */
7
+ register(): void;
8
+ /**
9
+ * Boot the service provider.
10
+ */
11
+ boot(): void;
12
+ }
13
+ //# sourceMappingURL=HttpServiceProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpServiceProvider.d.ts","sourceRoot":"","sources":["../src/HttpServiceProvider.ts"],"names":[],"mappings":"AAEA,qBAAa,mBAAmB;IAChB,SAAS,CAAC,GAAG,EAAE,GAAG;gBAAR,GAAG,EAAE,GAAG;IAE9B;;OAEG;IACH,QAAQ;IAMR;;OAEG;IACH,IAAI;CAGP"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpServiceProvider = void 0;
4
+ const HttpKernel_1 = require("./HttpKernel");
5
+ class HttpServiceProvider {
6
+ constructor(app) {
7
+ this.app = app;
8
+ }
9
+ /**
10
+ * Register the service provider.
11
+ */
12
+ register() {
13
+ this.app.singleton(HttpKernel_1.HttpKernel, (app) => {
14
+ return new HttpKernel_1.HttpKernel(app);
15
+ });
16
+ }
17
+ /**
18
+ * Boot the service provider.
19
+ */
20
+ boot() {
21
+ //
22
+ }
23
+ }
24
+ exports.HttpServiceProvider = HttpServiceProvider;
25
+ //# sourceMappingURL=HttpServiceProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpServiceProvider.js","sourceRoot":"","sources":["../src/HttpServiceProvider.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,MAAa,mBAAmB;IAC5B,YAAsB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;IAAI,CAAC;IAEnC;;OAEG;IACH,QAAQ;QACJ,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,uBAAU,EAAE,CAAC,GAAQ,EAAE,EAAE;YACxC,OAAO,IAAI,uBAAU,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,IAAI;QACA,EAAE;IACN,CAAC;CACJ;AAlBD,kDAkBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BodyParserMiddleware.d.ts","sourceRoot":"","sources":["../../src/Middleware/BodyParserMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,oBAAqB,YAAW,UAAU;IACnD;;OAEG;IACG,MAAM,CACR,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;IAiBpB;;OAEG;IACH,OAAO,CAAC,SAAS;CAmCpB"}
1
+ {"version":3,"file":"BodyParserMiddleware.d.ts","sourceRoot":"","sources":["../../src/Middleware/BodyParserMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,oBAAqB,YAAW,UAAU;IACnD;;OAEG;IACG,MAAM,CACR,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;IAiBpB;;OAEG;IACH,OAAO,CAAC,SAAS;CAoEpB"}
@@ -25,13 +25,41 @@ class BodyParserMiddleware {
25
25
  */
26
26
  parseBody(request) {
27
27
  return new Promise((resolve, reject) => {
28
- let body = '';
28
+ const contentType = request.header('content-type');
29
29
  const req = request.getRaw();
30
+ if (contentType?.includes('multipart/form-data')) {
31
+ try {
32
+ const Busboy = require('busboy');
33
+ const busboy = Busboy({ headers: request.headers() });
34
+ const data = {};
35
+ busboy.on('field', (name, value, info) => {
36
+ data[name] = value;
37
+ });
38
+ busboy.on('file', (name, file, info) => {
39
+ // For now we just consume the file stream to prevent hang
40
+ file.resume();
41
+ });
42
+ busboy.on('close', () => {
43
+ resolve(data);
44
+ });
45
+ busboy.on('finish', () => {
46
+ resolve(data);
47
+ });
48
+ busboy.on('error', (err) => {
49
+ reject(err);
50
+ });
51
+ req.pipe(busboy);
52
+ }
53
+ catch (e) {
54
+ reject(e);
55
+ }
56
+ return;
57
+ }
58
+ let body = '';
30
59
  req.on('data', (chunk) => {
31
60
  body += chunk.toString();
32
61
  });
33
62
  req.on('end', () => {
34
- const contentType = request.header('content-type');
35
63
  if (contentType?.includes('application/json')) {
36
64
  try {
37
65
  resolve(JSON.parse(body || '{}'));
@@ -1 +1 @@
1
- {"version":3,"file":"BodyParserMiddleware.js","sourceRoot":"","sources":["../../src/Middleware/BodyParserMiddleware.ts"],"names":[],"mappings":";;;AAIA,MAAa,oBAAoB;IAC7B;;OAEG;IACH,KAAK,CAAC,MAAM,CACR,OAAgB,EAChB,IAAwD,EACxD,QAAmB;QAEnB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAuB,CAAC;QAEzE,8CAA8C;QAC9C,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;YACrE,IAAI,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC3C,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,wDAAwD;YAC5D,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,OAAgB;QAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAI,IAAI,GAAG,EAAE,CAAC;YACd,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YAE7B,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBAC7B,IAAI,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YAC7B,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBACf,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAuB,C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,GAAwB,EAAE,CAAC;oBACrC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;wBAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;oBACtB,CAAC,CAAC,CAAC;oBACH,OAAO,CAAC,IAAI,CAAC,CAAC;gBAClB,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,EAAE,CAAC,CAAC;gBAChB,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;gBAC3B,MAAM,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAhGD,oDAgGC"}
@@ -0,0 +1,12 @@
1
+ import { Request, Response } from '../index';
2
+ import { Middleware } from '../Middleware';
3
+ /**
4
+ * Sets essential HTTP security headers to protect the application.
5
+ */
6
+ export declare class SecurityHeaders implements Middleware {
7
+ /**
8
+ * Handle the incoming request.
9
+ */
10
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response, response?: Response): Promise<Response>;
11
+ }
12
+ //# sourceMappingURL=SecurityHeaders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecurityHeaders.d.ts","sourceRoot":"","sources":["../../src/Middleware/SecurityHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,qBAAa,eAAgB,YAAW,UAAU;IAC9C;;OAEG;IACU,MAAM,CACf,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;CAyBvB"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecurityHeaders = void 0;
4
+ /**
5
+ * Sets essential HTTP security headers to protect the application.
6
+ */
7
+ class SecurityHeaders {
8
+ /**
9
+ * Handle the incoming request.
10
+ */
11
+ async handle(request, next, response) {
12
+ const res = await next(request);
13
+ res.header('X-Content-Type-Options', 'nosniff');
14
+ res.header('X-Frame-Options', 'SAMEORIGIN');
15
+ res.header('X-XSS-Protection', '1; mode=block');
16
+ res.header('Referrer-Policy', 'strict-origin-when-cross-origin');
17
+ res.header('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
18
+ if (process.env.NODE_ENV === 'production') {
19
+ res.header('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload');
20
+ }
21
+ res.header('Content-Security-Policy', "default-src 'self'; " +
22
+ "script-src 'self' 'unsafe-inline'; " +
23
+ "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; " +
24
+ "img-src 'self' data:; " +
25
+ "font-src 'self' https://fonts.gstatic.com; " +
26
+ "connect-src 'self'");
27
+ return res;
28
+ }
29
+ }
30
+ exports.SecurityHeaders = SecurityHeaders;
31
+ //# sourceMappingURL=SecurityHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecurityHeaders.js","sourceRoot":"","sources":["../../src/Middleware/SecurityHeaders.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,MAAa,eAAe;IACxB;;OAEG;IACI,KAAK,CAAC,MAAM,CACf,OAAgB,EAChB,IAAwD,EACxD,QAAmB;QAEnB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;QAEhC,GAAG,CAAC,MAAM,CAAC,wBAAwB,EAAE,SAAS,CAAC,CAAC;QAChD,GAAG,CAAC,MAAM,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;QAChD,GAAG,CAAC,MAAM,CAAC,iBAAiB,EAAE,iCAAiC,CAAC,CAAC;QACjE,GAAG,CAAC,MAAM,CAAC,oBAAoB,EAAE,0CAA0C,CAAC,CAAC;QAE7E,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YACxC,GAAG,CAAC,MAAM,CAAC,2BAA2B,EAAE,8CAA8C,CAAC,CAAC;QAC5F,CAAC;QAED,GAAG,CAAC,MAAM,CACN,yBAAyB,EACzB,sBAAsB;YACtB,qCAAqC;YACrC,iEAAiE;YACjE,wBAAwB;YACxB,6CAA6C;YAC7C,oBAAoB,CACvB,CAAC;QAEF,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAjCD,0CAiCC"}
@@ -0,0 +1,8 @@
1
+ import { Request } from '../Request';
2
+ import { Response } from '../Response';
3
+ export declare class ServeStaticMiddleware {
4
+ private serve;
5
+ constructor(publicPath: string);
6
+ handle(request: Request, next: (req: Request) => Promise<Response>, response: Response): Promise<Response>;
7
+ }
8
+ //# sourceMappingURL=ServeStaticMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServeStaticMiddleware.d.ts","sourceRoot":"","sources":["../../src/Middleware/ServeStaticMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,KAAK,CAAiC;gBAElC,UAAU,EAAE,MAAM;IAOjB,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;CAmB1H"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ServeStaticMiddleware = void 0;
7
+ const serve_static_1 = __importDefault(require("serve-static"));
8
+ class ServeStaticMiddleware {
9
+ constructor(publicPath) {
10
+ this.serve = (0, serve_static_1.default)(publicPath, {
11
+ index: false,
12
+ fallthrough: true,
13
+ });
14
+ }
15
+ async handle(request, next, response) {
16
+ return new Promise((resolve, reject) => {
17
+ const req = request.getIncomingMessage();
18
+ const res = response.getOriginalResponse();
19
+ this.serve(req, res, async (err) => {
20
+ if (err) {
21
+ return reject(err);
22
+ }
23
+ try {
24
+ const result = await next(request);
25
+ resolve(result);
26
+ }
27
+ catch (e) {
28
+ reject(e);
29
+ }
30
+ });
31
+ });
32
+ }
33
+ }
34
+ exports.ServeStaticMiddleware = ServeStaticMiddleware;
35
+ //# sourceMappingURL=ServeStaticMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ServeStaticMiddleware.js","sourceRoot":"","sources":["../../src/Middleware/ServeStaticMiddleware.ts"],"names":[],"mappings":";;;;;;AAEA,gEAAuC;AAEvC,MAAa,qBAAqB;IAG9B,YAAY,UAAkB;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAA,sBAAW,EAAC,UAAU,EAAE;YACjC,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,IAAI;SACpB,CAAC,CAAC;IACP,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,OAAgB,EAAE,IAAyC,EAAE,QAAkB;QAC/F,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,GAAG,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;YACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,mBAAmB,EAAE,CAAC;YAE3C,IAAI,CAAC,KAAK,CAAC,GAAU,EAAE,GAAU,EAAE,KAAK,EAAE,GAAQ,EAAE,EAAE;gBAClD,IAAI,GAAG,EAAE,CAAC;oBACN,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,CAAC;gBAED,IAAI,CAAC;oBACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;oBACnC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpB,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,MAAM,CAAC,CAAC,CAAC,CAAC;gBACd,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA7BD,sDA6BC"}
@@ -0,0 +1,17 @@
1
+ import { Request, Response } from '../index';
2
+ import { Middleware } from '../Middleware';
3
+ /**
4
+ * Simple in-memory rate limiter middleware.
5
+ */
6
+ export declare class Throttle implements Middleware {
7
+ private maxAttempts;
8
+ private windowSeconds;
9
+ private store;
10
+ constructor(maxAttempts?: number, windowSeconds?: number);
11
+ /**
12
+ * Handle the incoming request.
13
+ */
14
+ handle(request: Request, next: (request: Request) => Promise<Response> | Response, response?: Response): Promise<Response>;
15
+ private cleanup;
16
+ }
17
+ //# sourceMappingURL=Throttle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Throttle.d.ts","sourceRoot":"","sources":["../../src/Middleware/Throttle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C;;GAEG;AACH,qBAAa,QAAS,YAAW,UAAU;IAInC,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,aAAa;IAJzB,OAAO,CAAC,KAAK,CAAyC;gBAG1C,WAAW,GAAE,MAAW,EACxB,aAAa,GAAE,MAAW;IAGtC;;OAEG;IACU,MAAM,CACf,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACxD,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;IA0CpB,OAAO,CAAC,OAAO;CAQlB"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Throttle = void 0;
4
+ const index_1 = require("../index");
5
+ /**
6
+ * Simple in-memory rate limiter middleware.
7
+ */
8
+ class Throttle {
9
+ constructor(maxAttempts = 60, windowSeconds = 60) {
10
+ this.maxAttempts = maxAttempts;
11
+ this.windowSeconds = windowSeconds;
12
+ this.store = new Map();
13
+ }
14
+ /**
15
+ * Handle the incoming request.
16
+ */
17
+ async handle(request, next, response) {
18
+ const ip = request.ip() || '127.0.0.1';
19
+ const key = `throttle:${ip}:${request.path()}`;
20
+ const now = Date.now();
21
+ const windowMs = this.windowSeconds * 1000;
22
+ const entry = this.store.get(key);
23
+ if (entry && now < entry.resetAt) {
24
+ if (entry.count >= this.maxAttempts) {
25
+ const retryAfter = Math.ceil((entry.resetAt - now) / 1000);
26
+ // If it's a 429, we should return early
27
+ const errorRes = response || new index_1.Response(request.getRaw());
28
+ errorRes.header('Retry-After', String(retryAfter));
29
+ errorRes.header('X-RateLimit-Limit', String(this.maxAttempts));
30
+ errorRes.header('X-RateLimit-Remaining', '0');
31
+ return errorRes.status(429).json({
32
+ message: `Too many requests. Please try again in ${retryAfter} seconds.`,
33
+ retry_after: retryAfter
34
+ });
35
+ }
36
+ entry.count++;
37
+ }
38
+ else {
39
+ this.store.set(key, { count: 1, resetAt: now + windowMs });
40
+ }
41
+ const res = await next(request);
42
+ const currentEntry = this.store.get(key);
43
+ res.header('X-RateLimit-Limit', String(this.maxAttempts));
44
+ res.header('X-RateLimit-Remaining', String(Math.max(0, this.maxAttempts - currentEntry.count)));
45
+ // Cleanup expired entries probabilistically
46
+ if (Math.random() < 0.01) {
47
+ this.cleanup();
48
+ }
49
+ return res;
50
+ }
51
+ cleanup() {
52
+ const now = Date.now();
53
+ for (const [key, entry] of this.store.entries()) {
54
+ if (now >= entry.resetAt) {
55
+ this.store.delete(key);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ exports.Throttle = Throttle;
61
+ //# sourceMappingURL=Throttle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Throttle.js","sourceRoot":"","sources":["../../src/Middleware/Throttle.ts"],"names":[],"mappings":";;;AAAA,oCAA6C;AAQ7C;;GAEG;AACH,MAAa,QAAQ;IAGjB,YACY,cAAsB,EAAE,EACxB,gBAAwB,EAAE;QAD1B,gBAAW,GAAX,WAAW,CAAa;QACxB,kBAAa,GAAb,aAAa,CAAa;QAJ9B,UAAK,GAA+B,IAAI,GAAG,EAAE,CAAC;IAKlD,CAAC;IAEL;;OAEG;IACI,KAAK,CAAC,MAAM,CACf,OAAgB,EAChB,IAAwD,EACxD,QAAmB;QAEnB,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,IAAI,WAAW,CAAC;QACvC,MAAM,GAAG,GAAG,YAAY,EAAE,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAE3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,KAAK,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBAClC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;gBAE3D,wCAAwC;gBACxC,MAAM,QAAQ,GAAG,QAAQ,IAAI,IAAI,gBAAQ,CAAC,OAAO,CAAC,MAAM,EAAS,CAAC,CAAC;gBACnE,QAAQ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M,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,GAAG,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBACvB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAjED,4BAiEC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * A high-performance generic object pool.
3
+ * Prevents repeated memory allocation/GC by recycling objects across requests.
4
+ *
5
+ * Strategy: maintain a fixed-size free list (stack). On acquire(), pop a
6
+ * pre-warmed object and reset its state. On release(), push it back.
7
+ */
8
+ export declare class ObjectPool<T> {
9
+ private readonly pool;
10
+ private readonly maxSize;
11
+ private readonly factory;
12
+ private readonly reset;
13
+ constructor(factory: () => T, reset: (obj: T) => void, poolSize?: number);
14
+ /**
15
+ * Acquire an object from the pool (or allocate a new one if the pool is empty).
16
+ */
17
+ acquire(): T;
18
+ /**
19
+ * Return an object to the pool after resetting its state.
20
+ */
21
+ release(obj: T): void;
22
+ /**
23
+ * Current number of available objects in the pool.
24
+ */
25
+ get available(): number;
26
+ }
27
+ //# sourceMappingURL=ObjectPool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectPool.d.ts","sourceRoot":"","sources":["../src/ObjectPool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,UAAU,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;gBAE7B,OAAO,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE,QAAQ,SAAM;IAYrE;;OAEG;IACH,OAAO,IAAI,CAAC;IAOZ;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI;IAQrB;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;CACJ"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectPool = void 0;
4
+ /**
5
+ * A high-performance generic object pool.
6
+ * Prevents repeated memory allocation/GC by recycling objects across requests.
7
+ *
8
+ * Strategy: maintain a fixed-size free list (stack). On acquire(), pop a
9
+ * pre-warmed object and reset its state. On release(), push it back.
10
+ */
11
+ class ObjectPool {
12
+ constructor(factory, reset, poolSize = 512) {
13
+ this.pool = [];
14
+ this.factory = factory;
15
+ this.reset = reset;
16
+ this.maxSize = poolSize;
17
+ // Pre-warm the pool — allocate & shape objects at startup so V8
18
+ // can immediately JIT-compile them into a stable hidden class.
19
+ for (let i = 0; i < poolSize; i++) {
20
+ this.pool.push(factory());
21
+ }
22
+ }
23
+ /**
24
+ * Acquire an object from the pool (or allocate a new one if the pool is empty).
25
+ */
26
+ acquire() {
27
+ if (this.pool.length > 0) {
28
+ return this.pool.pop();
29
+ }
30
+ return this.factory();
31
+ }
32
+ /**
33
+ * Return an object to the pool after resetting its state.
34
+ */
35
+ release(obj) {
36
+ if (this.pool.length < this.maxSize) {
37
+ this.reset(obj);
38
+ this.pool.push(obj);
39
+ }
40
+ // If pool is full, let the object be GC'd — this is rare at high concurrency.
41
+ }
42
+ /**
43
+ * Current number of available objects in the pool.
44
+ */
45
+ get available() {
46
+ return this.pool.length;
47
+ }
48
+ }
49
+ exports.ObjectPool = ObjectPool;
50
+ //# sourceMappingURL=ObjectPool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ObjectPool.js","sourceRoot":"","sources":["../src/ObjectPool.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,UAAU;IAMnB,YAAY,OAAgB,EAAE,KAAuB,EAAE,QAAQ,GAAG,GAAG;QALpD,SAAI,GAAQ,EAAE,CAAC;QAM5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;QAExB,gEAAgE;QAChE,+DAA+D;QAC/D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9B,CAAC;IACL,CAAC;IAED;;OAEG;IACH,OAAO;QACH,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAG,CAAC;QAC5B,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,GAAM;QACV,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QACD,8EAA8E;IAClF,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;CACJ;AA7CD,gCA6CC"}
@@ -0,0 +1,23 @@
1
+ import { Request } from './Request';
2
+ import { Response } from './Response';
3
+ /**
4
+ * Pipeline executes a stack of middleware for HTTP requests.
5
+ */
6
+ export declare class Pipeline {
7
+ private container?;
8
+ private handlers;
9
+ constructor(container?: any | undefined);
10
+ /**
11
+ * Add middleware to the pipeline.
12
+ */
13
+ pipe(middleware: any | any[]): this;
14
+ /**
15
+ * Run the pipeline through the given destination.
16
+ */
17
+ handle(request: Request, destination: (request: Request, response?: Response) => Promise<Response> | Response, response?: Response): Promise<Response>;
18
+ /**
19
+ * Resolve the middleware handler.
20
+ */
21
+ private resolve;
22
+ }
23
+ //# sourceMappingURL=Pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pipeline.d.ts","sourceRoot":"","sources":["../src/Pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,qBAAa,QAAQ;IAGL,OAAO,CAAC,SAAS,CAAC;IAF9B,OAAO,CAAC,QAAQ,CAAa;gBAET,SAAS,CAAC,EAAE,GAAG,YAAA;IAEnC;;OAEG;IACI,IAAI,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,IAAI;IAS1C;;OAEG;IACU,MAAM,CACf,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EACpF,QAAQ,CAAC,EAAE,QAAQ,GACpB,OAAO,CAAC,QAAQ,CAAC;IAsBpB;;OAEG;IACH,OAAO,CAAC,OAAO;CAgBlB"}