@nestia/core 1.2.1-dev.20230505 → 1.2.1-dev.20230507
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.
- package/lib/decorators/EncryptedBody.js +69 -24
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/PlainBody.js +48 -6
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/internal/get_text_body.d.ts +3 -0
- package/lib/decorators/internal/get_text_body.js +63 -0
- package/lib/decorators/internal/get_text_body.js.map +1 -0
- package/package.json +3 -2
- package/src/decorators/EncryptedBody.ts +3 -2
- package/src/decorators/PlainBody.ts +3 -2
- package/src/decorators/internal/get_text_body.ts +14 -0
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.EncryptedBody = void 0;
|
|
4
40
|
var fetcher_1 = require("@nestia/fetcher");
|
|
@@ -6,6 +42,7 @@ var common_1 = require("@nestjs/common");
|
|
|
6
42
|
var typia_1 = require("typia");
|
|
7
43
|
var Singleton_1 = require("../utils/Singleton");
|
|
8
44
|
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
45
|
+
var get_text_body_1 = require("./internal/get_text_body");
|
|
9
46
|
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
10
47
|
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
11
48
|
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
@@ -33,31 +70,39 @@ var validate_request_body_1 = require("./internal/validate_request_body");
|
|
|
33
70
|
function EncryptedBody(validator) {
|
|
34
71
|
var checker = (0, validate_request_body_1.validate_request_body)("EncryptedBody")(validator);
|
|
35
72
|
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown, context) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
var request, param, headers, body, password, data, error;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
request = context
|
|
79
|
+
.switchToHttp()
|
|
80
|
+
.getRequest();
|
|
81
|
+
if (isTextPlain(request.headers["content-type"]) === false)
|
|
82
|
+
return [2 /*return*/, (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Request body type is not \"text/plain\"."))];
|
|
83
|
+
param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, context.getClass());
|
|
84
|
+
if (!param)
|
|
85
|
+
throw new Error("Error on nestia.core.EncryptedBody(): no encryption password is given.");
|
|
86
|
+
headers = new Singleton_1.Singleton(function () {
|
|
87
|
+
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
88
|
+
});
|
|
89
|
+
return [4 /*yield*/, (0, get_text_body_1.get_text_body)(request)];
|
|
90
|
+
case 1:
|
|
91
|
+
body = _a.sent();
|
|
92
|
+
password = typeof param === "function"
|
|
93
|
+
? param({ headers: headers.get(), body: body }, false)
|
|
94
|
+
: param;
|
|
95
|
+
data = JSON.parse(decrypt(body, password.key, password.iv));
|
|
96
|
+
error = checker(data);
|
|
97
|
+
if (error !== null)
|
|
98
|
+
if (error instanceof common_1.HttpException)
|
|
99
|
+
return [2 /*return*/, (0, send_bad_request_1.send_bad_request)(context)(error)];
|
|
100
|
+
else
|
|
101
|
+
throw error;
|
|
102
|
+
return [2 /*return*/, data];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
47
105
|
});
|
|
48
|
-
var body = request.body;
|
|
49
|
-
var password = typeof param === "function"
|
|
50
|
-
? param({ headers: headers.get(), body: body }, false)
|
|
51
|
-
: param;
|
|
52
|
-
// PARSE AND VALIDATE DATA
|
|
53
|
-
var data = JSON.parse(decrypt(body, password.key, password.iv));
|
|
54
|
-
var error = checker(data);
|
|
55
|
-
if (error !== null)
|
|
56
|
-
if (error instanceof common_1.HttpException)
|
|
57
|
-
return (0, send_bad_request_1.send_bad_request)(context)(error);
|
|
58
|
-
else
|
|
59
|
-
throw error;
|
|
60
|
-
return data;
|
|
61
106
|
})();
|
|
62
107
|
}
|
|
63
108
|
exports.EncryptedBody = EncryptedBody;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.PlainBody = void 0;
|
|
4
40
|
var common_1 = require("@nestjs/common");
|
|
41
|
+
var get_text_body_1 = require("./internal/get_text_body");
|
|
5
42
|
var send_bad_request_1 = require("./internal/send_bad_request");
|
|
6
43
|
/**
|
|
7
44
|
* Plain body decorator.
|
|
@@ -25,12 +62,17 @@ var send_bad_request_1 = require("./internal/send_bad_request");
|
|
|
25
62
|
* @author Jeongho Nam - https://github.com/samchon
|
|
26
63
|
*/
|
|
27
64
|
exports.PlainBody = (0, common_1.createParamDecorator)(function PlainBody(_data, context) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var request;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
request = context
|
|
69
|
+
.switchToHttp()
|
|
70
|
+
.getRequest();
|
|
71
|
+
return [2 /*return*/, isTextPlain(request.headers["content-type"])
|
|
72
|
+
? (0, get_text_body_1.get_text_body)(request)
|
|
73
|
+
: (0, send_bad_request_1.send_bad_request)(context)(new common_1.BadRequestException("Request body type is not \"text/plain\"."))];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
34
76
|
});
|
|
35
77
|
var isTextPlain = function (text) {
|
|
36
78
|
return text !== undefined &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAIwB;AAIxB,0DAAyD;AACzD,gEAA+D;AAE/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,SAAS,GAA6B,IAAA,6BAAoB,EACnE,SAAe,SAAS,CAAC,KAAU,EAAE,OAAyB;;;;YACpD,OAAO,GAAqC,OAAO;iBACpD,YAAY,EAAE;iBACd,UAAU,EAAE,CAAC;YAClB,sBAAO,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;oBAC/C,CAAC,CAAC,IAAA,6BAAa,EAAC,OAAO,CAAC;oBACxB,CAAC,CAAC,IAAA,mCAAgB,EAAC,OAAO,CAAC,CACrB,IAAI,4BAAmB,CACnB,0CAAwC,CAC3C,CACJ,EAAC;;;CACX,CACJ,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,IAAI,EAAE,EAAV,CAAU,CAAC;aACxB,IAAI,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,KAAK,YAAY,EAApB,CAAoB,CAAC;AAJxC,CAIwC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.get_text_body = void 0;
|
|
43
|
+
var raw_body_1 = __importDefault(require("raw-body"));
|
|
44
|
+
var get_text_body = function (request) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
+
var _a;
|
|
46
|
+
return __generator(this, function (_b) {
|
|
47
|
+
switch (_b.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
if (!isExpressRequest(request)) return [3 /*break*/, 2];
|
|
50
|
+
return [4 /*yield*/, (0, raw_body_1.default)(request)];
|
|
51
|
+
case 1:
|
|
52
|
+
_a = (_b.sent()).toString("utf8");
|
|
53
|
+
return [3 /*break*/, 3];
|
|
54
|
+
case 2:
|
|
55
|
+
_a = request.body;
|
|
56
|
+
_b.label = 3;
|
|
57
|
+
case 3: return [2 /*return*/, _a];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}); };
|
|
61
|
+
exports.get_text_body = get_text_body;
|
|
62
|
+
var isExpressRequest = function (request) { return request.app !== undefined; };
|
|
63
|
+
//# sourceMappingURL=get_text_body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_text_body.js","sourceRoot":"","sources":["../../../src/decorators/internal/get_text_body.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sDAA2B;AAEpB,IAAM,aAAa,GAAG,UACzB,OAAyC;;;;;qBAEzC,gBAAgB,CAAC,OAAO,CAAC,EAAzB,wBAAyB;gBAClB,qBAAM,IAAA,kBAAG,EAAC,OAAO,CAAC,EAAA;;gBAAnB,KAAA,CAAC,SAAkB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;;;gBACrC,KAAC,OAAO,CAAC,IAAe,CAAA;;oBAF9B,0BAE8B;;;KAAA,CAAC;AALtB,QAAA,aAAa,iBAKS;AAEnC,IAAM,gBAAgB,GAAG,UACrB,OAAyC,IACZ,OAAC,OAA2B,CAAC,GAAG,KAAK,SAAS,EAA9C,CAA8C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "1.2.1-dev.
|
|
3
|
+
"version": "1.2.1-dev.20230507",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -33,13 +33,14 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/samchon/nestia",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nestia/fetcher": "^1.2.
|
|
36
|
+
"@nestia/fetcher": "^1.2.1",
|
|
37
37
|
"@nestjs/common": ">= 7.0.1",
|
|
38
38
|
"@nestjs/core": ">= 7.0.1",
|
|
39
39
|
"@nestjs/platform-express": ">= 7.0.1",
|
|
40
40
|
"@nestjs/platform-fastify": ">= 7.0.1",
|
|
41
41
|
"detect-ts-node": "^1.0.5",
|
|
42
42
|
"glob": "^7.2.0",
|
|
43
|
+
"raw-body": ">= 2.0.0",
|
|
43
44
|
"reflect-metadata": ">= 0.1.12",
|
|
44
45
|
"rxjs": ">= 6.0.0",
|
|
45
46
|
"typia": "^3.8.4"
|
|
@@ -13,6 +13,7 @@ import { assert, is, validate } from "typia";
|
|
|
13
13
|
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
14
14
|
import { Singleton } from "../utils/Singleton";
|
|
15
15
|
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
16
|
+
import { get_text_body } from "./internal/get_text_body";
|
|
16
17
|
import { headers_to_object } from "./internal/headers_to_object";
|
|
17
18
|
import { send_bad_request } from "./internal/send_bad_request";
|
|
18
19
|
import { validate_request_body } from "./internal/validate_request_body";
|
|
@@ -42,7 +43,7 @@ export function EncryptedBody<T>(
|
|
|
42
43
|
validator?: IRequestBodyValidator<T>,
|
|
43
44
|
): ParameterDecorator {
|
|
44
45
|
const checker = validate_request_body("EncryptedBody")(validator);
|
|
45
|
-
return createParamDecorator(function EncryptedBody(
|
|
46
|
+
return createParamDecorator(async function EncryptedBody(
|
|
46
47
|
_unknown: any,
|
|
47
48
|
context: ExecutionContext,
|
|
48
49
|
) {
|
|
@@ -72,7 +73,7 @@ export function EncryptedBody<T>(
|
|
|
72
73
|
const headers: Singleton<Record<string, string>> = new Singleton(() =>
|
|
73
74
|
headers_to_object(request.headers),
|
|
74
75
|
);
|
|
75
|
-
const body: string = request
|
|
76
|
+
const body: string = await get_text_body(request);
|
|
76
77
|
const password: IEncryptionPassword =
|
|
77
78
|
typeof param === "function"
|
|
78
79
|
? param({ headers: headers.get(), body }, false)
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import type express from "express";
|
|
7
7
|
import type { FastifyRequest } from "fastify";
|
|
8
8
|
|
|
9
|
+
import { get_text_body } from "./internal/get_text_body";
|
|
9
10
|
import { send_bad_request } from "./internal/send_bad_request";
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -30,12 +31,12 @@ import { send_bad_request } from "./internal/send_bad_request";
|
|
|
30
31
|
* @author Jeongho Nam - https://github.com/samchon
|
|
31
32
|
*/
|
|
32
33
|
export const PlainBody: () => ParameterDecorator = createParamDecorator(
|
|
33
|
-
function PlainBody(_data: any, context: ExecutionContext) {
|
|
34
|
+
async function PlainBody(_data: any, context: ExecutionContext) {
|
|
34
35
|
const request: express.Request | FastifyRequest = context
|
|
35
36
|
.switchToHttp()
|
|
36
37
|
.getRequest();
|
|
37
38
|
return isTextPlain(request.headers["content-type"])
|
|
38
|
-
? request
|
|
39
|
+
? get_text_body(request)
|
|
39
40
|
: send_bad_request(context)(
|
|
40
41
|
new BadRequestException(
|
|
41
42
|
`Request body type is not "text/plain".`,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type express from "express";
|
|
2
|
+
import type { FastifyRequest } from "fastify";
|
|
3
|
+
import raw from "raw-body";
|
|
4
|
+
|
|
5
|
+
export const get_text_body = async (
|
|
6
|
+
request: express.Request | FastifyRequest,
|
|
7
|
+
): Promise<string> =>
|
|
8
|
+
isExpressRequest(request)
|
|
9
|
+
? (await raw(request)).toString("utf8")
|
|
10
|
+
: (request.body as string);
|
|
11
|
+
|
|
12
|
+
const isExpressRequest = (
|
|
13
|
+
request: express.Request | FastifyRequest,
|
|
14
|
+
): request is express.Request => (request as express.Request).app !== undefined;
|