@tsed/platform-express 6.75.8 → 6.75.12

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="express-serve-static-core" />
2
1
  import { RouterOptions } from "express";
3
2
  export interface PlatformExpressSettings {
4
3
  /**
@@ -1 +1,4 @@
1
- export declare function rawBodyMiddleware(request: any, response: any, next: any): void;
1
+ import { Request } from "express";
2
+ export declare function rawBodyMiddleware(request: Request & {
3
+ rawBody: string;
4
+ }, response: any, next: any): void;
@@ -1,12 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rawBodyMiddleware = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const bytes_1 = tslib_1.__importDefault(require("bytes"));
6
+ const limit = bytes_1.default.parse("100kb");
7
+ function isLimitReached(length) {
8
+ return limit !== null && length !== null && length > limit;
9
+ }
10
+ function getContentLength(request) {
11
+ const contentLength = request.get("content-length");
12
+ return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;
13
+ }
4
14
  function rawBodyMiddleware(request, response, next) {
5
- if (!request.is("multipart/form-data")) {
6
- request.rawBody = "";
7
- request.on("data", (chunk) => {
8
- request.rawBody += chunk;
9
- });
15
+ if (request.method !== "GET") {
16
+ const length = getContentLength(request);
17
+ if (!isLimitReached(length) && request.is(["application/x-www-form-urlencoded", "application/json"])) {
18
+ request.rawBody = "";
19
+ request.on("data", (chunk) => {
20
+ request.rawBody += chunk;
21
+ });
22
+ }
10
23
  }
11
24
  next();
12
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":";;;AAAA,SAAgB,iBAAiB,CAAC,OAAY,EAAE,QAAa,EAAE,IAAS;IACtE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,qBAAqB,CAAC,EAAE;QACtC,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC;QACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YACnC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;QAC3B,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,EAAE,CAAC;AACT,CAAC;AATD,8CASC","sourcesContent":["export function rawBodyMiddleware(request: any, response: any, next: any) {\n if (!request.is(\"multipart/form-data\")) {\n request.rawBody = \"\";\n request.on(\"data\", (chunk: string) => {\n request.rawBody += chunk;\n });\n }\n\n next();\n}\n"]}
1
+ {"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":";;;;AACA,0DAA0B;AAE1B,MAAM,KAAK,GAAG,eAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnC,SAAS,cAAc,CAAC,MAAqB;IAC3C,OAAO,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoC;IAC5D,MAAM,aAAa,GAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,aAAa,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAoC,EAAE,QAAa,EAAE,IAAS;IAC9F,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE;QAC5B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,mCAAmC,EAAE,kBAAkB,CAAC,CAAC,EAAE;YACpG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC;YACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACnC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC;SACJ;KACF;IAED,IAAI,EAAE,CAAC;AACT,CAAC;AAbD,8CAaC","sourcesContent":["import {Request} from \"express\";\nimport bytes from \"bytes\";\n\nconst limit = bytes.parse(\"100kb\");\n\nfunction isLimitReached(length: number | null) {\n return limit !== null && length !== null && length > limit;\n}\n\nfunction getContentLength(request: Request & {rawBody: string}) {\n const contentLength: any = request.get(\"content-length\");\n return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;\n}\n\nexport function rawBodyMiddleware(request: Request & {rawBody: string}, response: any, next: any) {\n if (request.method !== \"GET\") {\n const length = getContentLength(request);\n\n if (!isLimitReached(length) && request.is([\"application/x-www-form-urlencoded\", \"application/json\"])) {\n request.rawBody = \"\";\n request.on(\"data\", (chunk: string) => {\n request.rawBody += chunk;\n });\n }\n }\n\n next();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-express",
3
- "version": "6.75.8",
3
+ "version": "6.75.12",
4
4
  "description": "A TypeScript Framework on top of Express",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/index.js",
@@ -45,10 +45,10 @@
45
45
  "tslib": "2.2.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@tsed/common": "6.75.8",
49
- "@tsed/core": "6.75.8",
50
- "@tsed/di": "6.75.8",
51
- "@tsed/platform-test-utils": "6.75.8",
48
+ "@tsed/common": "6.75.12",
49
+ "@tsed/core": "6.75.12",
50
+ "@tsed/di": "6.75.12",
51
+ "@tsed/platform-test-utils": "6.75.12",
52
52
  "@types/body-parser": "1.19.0",
53
53
  "@types/compression": "1.7.0",
54
54
  "@types/cookie-parser": "1.4.2",
@@ -64,13 +64,13 @@
64
64
  "method-override": "3.0.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "@tsed/common": "^6.75.8",
68
- "@tsed/core": "^6.75.8",
69
- "@tsed/di": "^6.75.8",
70
- "@tsed/json-mapper": "^6.75.8",
71
- "@tsed/logger": "^5.16.0",
72
- "@tsed/openspec": "^6.75.8",
73
- "@tsed/schema": "^6.75.8",
67
+ "@tsed/common": "^6.75.12",
68
+ "@tsed/core": "^6.75.12",
69
+ "@tsed/di": "^6.75.12",
70
+ "@tsed/json-mapper": "^6.75.12",
71
+ "@tsed/logger": ">=6.0.0",
72
+ "@tsed/openspec": "^6.75.12",
73
+ "@tsed/schema": "^6.75.12",
74
74
  "@types/multer": "^1.4.5",
75
75
  "body-parser": "1.19.0"
76
76
  }