@nestia/core 2.4.3-dev.20231207 → 3.0.0-dev.20231209
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 +13 -11
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +29 -12
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/internal/get_binary_body.d.ts +1 -0
- package/lib/decorators/internal/get_binary_body.js +66 -0
- package/lib/decorators/internal/get_binary_body.js.map +1 -0
- package/package.json +3 -3
- package/src/decorators/DynamicModule.ts +39 -39
- package/src/decorators/EncryptedBody.ts +17 -12
- package/src/decorators/EncryptedController.ts +38 -38
- package/src/decorators/EncryptedModule.ts +79 -79
- package/src/decorators/EncryptedRoute.ts +38 -14
- package/src/decorators/PlainBody.ts +72 -72
- package/src/decorators/TypedBody.ts +59 -59
- package/src/decorators/TypedException.ts +89 -89
- package/src/decorators/TypedHeaders.ts +69 -69
- package/src/decorators/TypedParam.ts +65 -65
- package/src/decorators/TypedQuery.ts +246 -246
- package/src/decorators/TypedRoute.ts +144 -144
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/NoTransformConfigureError.ts +8 -8
- package/src/decorators/internal/get_binary_body.ts +18 -0
- package/src/decorators/internal/get_path_and_querify.ts +103 -103
- package/src/decorators/internal/get_path_and_stringify.ts +91 -91
- package/src/decorators/internal/get_text_body.ts +20 -20
- package/src/decorators/internal/headers_to_object.ts +13 -13
- package/src/decorators/internal/load_controller.ts +51 -51
- package/src/decorators/internal/route_error.ts +45 -45
- package/src/decorators/internal/validate_request_body.ts +57 -57
- package/src/decorators/internal/validate_request_headers.ts +68 -68
- package/src/decorators/internal/validate_request_query.ts +56 -56
- package/src/index.ts +5 -5
- package/src/module.ts +14 -14
- package/src/options/INestiaTransformOptions.ts +17 -17
- package/src/options/INestiaTransformProject.ts +7 -7
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +25 -25
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedBodyProgrammer.ts +108 -108
- package/src/programmers/TypedExceptionProgrammer.ts +72 -72
- package/src/programmers/TypedHeadersProgrammer.ts +56 -56
- package/src/programmers/TypedParamProgrammer.ts +24 -24
- package/src/programmers/TypedQueryBodyProgrammer.ts +56 -56
- package/src/programmers/TypedQueryProgrammer.ts +56 -56
- package/src/programmers/TypedQueryRouteProgrammer.ts +51 -51
- package/src/programmers/TypedRouteProgrammer.ts +51 -51
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +58 -58
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +62 -62
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +63 -63
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +66 -66
- package/src/transformers/MethodTransformer.ts +94 -94
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterDecoratorTransformer.ts +121 -121
- package/src/transformers/ParameterTransformer.ts +48 -48
- package/src/transformers/TypedExceptionTransformer.ts +49 -49
- package/src/transformers/TypedRouteTransformer.ts +95 -95
- package/src/typings/Creator.ts +3 -3
- package/src/utils/ExceptionManager.ts +112 -112
- package/src/utils/Singleton.ts +20 -20
- package/src/utils/SourceFinder.ts +57 -57
|
@@ -37,12 +37,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.EncryptedBody = void 0;
|
|
40
|
-
var AesPkcs5_1 = require("@nestia/fetcher/lib/AesPkcs5");
|
|
40
|
+
var AesPkcs5_1 = require("@nestia/fetcher/lib/internal/AesPkcs5");
|
|
41
41
|
var common_1 = require("@nestjs/common");
|
|
42
42
|
var typia_1 = require("typia");
|
|
43
43
|
var Singleton_1 = require("../utils/Singleton");
|
|
44
44
|
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
45
|
-
var
|
|
45
|
+
var get_binary_body_1 = require("./internal/get_binary_body");
|
|
46
46
|
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
47
47
|
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
48
48
|
/**
|
|
@@ -70,28 +70,30 @@ function EncryptedBody(validator) {
|
|
|
70
70
|
var checker = (0, validate_request_body_1.validate_request_body)("EncryptedBody")(validator);
|
|
71
71
|
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown, context) {
|
|
72
72
|
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
-
var request, param, headers,
|
|
73
|
+
var request, param, headers, raw, password, data, error;
|
|
74
74
|
return __generator(this, function (_a) {
|
|
75
75
|
switch (_a.label) {
|
|
76
76
|
case 0:
|
|
77
77
|
request = context
|
|
78
78
|
.switchToHttp()
|
|
79
79
|
.getRequest();
|
|
80
|
-
if (
|
|
81
|
-
throw new common_1.BadRequestException("Request body type is not \"
|
|
80
|
+
if (isApplicationOctetStream(request.headers["content-type"]) === false)
|
|
81
|
+
throw new common_1.BadRequestException("Request body type is not \"application/octet-stream\".");
|
|
82
82
|
param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, context.getClass());
|
|
83
83
|
if (!param)
|
|
84
84
|
throw new Error("Error on nestia.core.EncryptedBody(): no encryption password is given.");
|
|
85
85
|
headers = new Singleton_1.Singleton(function () {
|
|
86
86
|
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
87
87
|
});
|
|
88
|
-
return [4 /*yield*/, (0,
|
|
88
|
+
return [4 /*yield*/, (0, get_binary_body_1.get_binary_body)(request)];
|
|
89
89
|
case 1:
|
|
90
|
-
|
|
90
|
+
raw = _a.sent();
|
|
91
|
+
if (raw.length === 0)
|
|
92
|
+
return [2 /*return*/];
|
|
91
93
|
password = typeof param === "function"
|
|
92
|
-
? param({ headers: headers.get(), body:
|
|
94
|
+
? param({ headers: headers.get(), body: raw, direction: "decode" })
|
|
93
95
|
: param;
|
|
94
|
-
data = JSON.parse(decrypt(
|
|
96
|
+
data = JSON.parse(new TextDecoder().decode(decrypt(raw, password.key, password.iv)));
|
|
95
97
|
error = checker(data);
|
|
96
98
|
if (error !== null)
|
|
97
99
|
throw error;
|
|
@@ -119,11 +121,11 @@ var decrypt = function (body, key, iv) {
|
|
|
119
121
|
throw exp;
|
|
120
122
|
}
|
|
121
123
|
};
|
|
122
|
-
var
|
|
124
|
+
var isApplicationOctetStream = function (text) {
|
|
123
125
|
return text !== undefined &&
|
|
124
126
|
text
|
|
125
127
|
.split(";")
|
|
126
128
|
.map(function (str) { return str.trim(); })
|
|
127
|
-
.some(function (str) { return str === "
|
|
129
|
+
.some(function (str) { return str === "application/octet-stream"; });
|
|
128
130
|
};
|
|
129
131
|
//# sourceMappingURL=EncryptedBody.js.map
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kEAAiE;AACjE,yCAIwB;AAGxB,+BAA6C;AAG7C,gDAA+C;AAC/C,kEAAuE;AACvE,8DAA6D;AAC7D,kEAAiE;AACjE,0EAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CAC3B,SAAoC;IAEpC,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,eAAe,CAA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C;wBAChC,sBAAO,IAAI,EAAC;;;;KACb,CAAC,EAAE,CAAC;AACP,CAAC;AA1CD,sCA0CC;AACD,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,UAAE,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,cAAM,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,gBAAQ,CAAC,CAAC;AAEvC;;GAEG;AACH,IAAM,OAAO,GAAG,UAAC,IAAgB,EAAE,GAAW,EAAE,EAAU;IACxD,IAAI,CAAC;QACH,OAAO,mBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,KAAK;YACtB,MAAM,IAAI,4BAAmB,CAC3B,qFAAqF,CACtF,CAAC;;YACC,MAAM,GAAG,CAAC;IACjB,CAAC;AACH,CAAC,CAAC;AAEF,IAAM,wBAAwB,GAAG,UAAC,IAAa;IAC7C,OAAA,IAAI,KAAK,SAAS;QAClB,IAAI;aACD,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,0BAA0B,EAAlC,CAAkC,CAAC;AAJpD,CAIoD,CAAC"}
|
|
@@ -41,7 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
var e_1, _a, e_2, _b, e_3, _c;
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
43
|
exports.EncryptedRoute = void 0;
|
|
44
|
-
var AesPkcs5_1 = require("@nestia/fetcher/lib/AesPkcs5");
|
|
44
|
+
var AesPkcs5_1 = require("@nestia/fetcher/lib/internal/AesPkcs5");
|
|
45
45
|
var common_1 = require("@nestjs/common");
|
|
46
46
|
var operators_1 = require("rxjs/operators");
|
|
47
47
|
var typia_1 = __importDefault(require("typia"));
|
|
@@ -175,6 +175,8 @@ var EncryptedRouteInterceptor = /** @class */ (function () {
|
|
|
175
175
|
function EncryptedRouteInterceptor(method, stringify) {
|
|
176
176
|
this.method = method;
|
|
177
177
|
this.stringify = stringify;
|
|
178
|
+
this.success =
|
|
179
|
+
this.method === "GET" || this.method === "DELETE" ? 200 : 201;
|
|
178
180
|
}
|
|
179
181
|
EncryptedRouteInterceptor.prototype.intercept = function (context, next) {
|
|
180
182
|
var _this = this;
|
|
@@ -187,17 +189,28 @@ var EncryptedRouteInterceptor = /** @class */ (function () {
|
|
|
187
189
|
var request = http.getRequest();
|
|
188
190
|
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
189
191
|
});
|
|
190
|
-
var body =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
192
|
+
var body = (function () {
|
|
193
|
+
var body = _this.stringify(value);
|
|
194
|
+
if (body === undefined)
|
|
195
|
+
return Buffer.from([]);
|
|
196
|
+
var password = typeof param === "function"
|
|
197
|
+
? param({
|
|
198
|
+
body: body,
|
|
199
|
+
direction: "encode",
|
|
200
|
+
headers: headers.get(),
|
|
201
|
+
})
|
|
202
|
+
: param;
|
|
203
|
+
return AesPkcs5_1.AesPkcs5.encrypt(body, password.key, password.iv);
|
|
204
|
+
})();
|
|
205
|
+
// return body;
|
|
206
|
+
var response = http.getResponse();
|
|
207
|
+
if (isExpressRequest(http.getRequest()))
|
|
208
|
+
response
|
|
209
|
+
.header("Content-Type", "application/octet-stream")
|
|
210
|
+
.status(_this.success)
|
|
211
|
+
.send(body)
|
|
212
|
+
.end();
|
|
213
|
+
return body;
|
|
201
214
|
}), (0, operators_1.catchError)(function (err) { return (0, route_error_1.route_error)(http.getRequest(), err); }));
|
|
202
215
|
};
|
|
203
216
|
return EncryptedRouteInterceptor;
|
|
@@ -212,4 +225,8 @@ var ROUTERS = {
|
|
|
212
225
|
Patch: common_1.Patch,
|
|
213
226
|
Delete: common_1.Delete,
|
|
214
227
|
};
|
|
228
|
+
/**
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
var isExpressRequest = function (request) { return request.app !== undefined; };
|
|
215
232
|
//# sourceMappingURL=EncryptedRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EncryptedRoute.js","sourceRoot":"","sources":["../../src/decorators/EncryptedRoute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"EncryptedRoute.js","sourceRoot":"","sources":["../../src/decorators/EncryptedRoute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kEAAiE;AACjE,yCAWwB;AAIxB,4CAAiD;AACjD,gDAA0B;AAG1B,gDAA+C;AAC/C,kEAAuE;AACvE,kFAAiF;AACjF,4EAA2E;AAC3E,kEAAiE;AACjE,sDAAqD;AAErD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,IAAiB,cAAc,CA8D9B;AA9DD,WAAiB,cAAc;IAC7B;;;;;OAKG;IACU,kBAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpC;;;;;OAKG;IACU,mBAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAEtC;;;;;OAKG;IACU,oBAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAExC;;;;;OAKG;IACU,kBAAG,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpC;;;;;OAKG;IACU,qBAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAE1C,SAAS,SAAS,CAAC,MAAmD;QAUpE,SAAS,KAAK;YAAC,cAAc;iBAAd,UAAc,EAAd,qBAAc,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AAE,CAAC,CAAC;YAC3D,CAAC,CAAC,EAAE,CAAC;YACL,eAAe;YACf,IAAM,QAAQ,GAAqB,IAAI,CAAC,WAAW,EAAE,CAAC;YACtD,IAAI,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrC,QAAQ;qBACL,MAAM,CAAC,cAAc,EAAE,0BAA0B,CAAC;qBAClD,MAAM,CAAC,KAAI,CAAC,OAAO,CAAC;qBACpB,IAAI,CAAC,IAAI,CAAC;qBACV,GAAG,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,EACF,IAAA,sBAAU,EAAC,UAAC,GAAG,IAAK,OAAA,IAAA,yBAAW,EAAC,IAAI,CAAC,UAAU,EAAE,EAAE,GAAG,CAAC,EAAnC,CAAmC,CAAC,CACzD,CAAC;IACJ,CAAC;IACH,gCAAC;AAAD,CAAC,AAxDD,IAwDC;AAED;;GAEG;AACH,IAAM,OAAO,GAAG;IACd,GAAG,cAAA;IACH,IAAI,eAAA;IACJ,GAAG,cAAA;IACH,KAAK,gBAAA;IACL,MAAM,iBAAA;CACP,CAAC;AAEF;;GAEG;AACH,IAAM,gBAAgB,GAAG,UACvB,OAAyC,IACV,OAAC,OAA2B,CAAC,GAAG,KAAK,SAAS,EAA9C,CAA8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
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_binary_body = void 0;
|
|
43
|
+
var raw_body_1 = __importDefault(require("raw-body"));
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
var get_binary_body = function (request) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
|
|
48
|
+
switch (_b.label) {
|
|
49
|
+
case 0:
|
|
50
|
+
if (!isExpressRequest(request)) return [3 /*break*/, 2];
|
|
51
|
+
return [4 /*yield*/, (0, raw_body_1.default)(request)];
|
|
52
|
+
case 1:
|
|
53
|
+
_a = _b.sent();
|
|
54
|
+
return [3 /*break*/, 3];
|
|
55
|
+
case 2:
|
|
56
|
+
_a = request.body;
|
|
57
|
+
_b.label = 3;
|
|
58
|
+
case 3: return [2 /*return*/, _a];
|
|
59
|
+
}
|
|
60
|
+
}); }); };
|
|
61
|
+
exports.get_binary_body = get_binary_body;
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
var isExpressRequest = function (request) { return request.app !== undefined; };
|
|
66
|
+
//# sourceMappingURL=get_binary_body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_binary_body.js","sourceRoot":"","sources":["../../../src/decorators/internal/get_binary_body.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sDAA2B;AAE3B;;GAEG;AACI,IAAM,eAAe,GAAG,UAC7B,OAAyC;;;iBAEzC,gBAAgB,CAAC,OAAO,CAAC,EAAzB,wBAAyB;YAAG,qBAAM,IAAA,kBAAG,EAAC,OAAO,CAAC,EAAA;;YAAlB,KAAA,SAAkB,CAAA;;;YAAG,KAAC,OAAO,CAAC,IAAmB,CAAA;;gBAA7E,0BAA6E;;SAAA,CAAC;AAHnE,QAAA,eAAe,mBAGoD;AAEhF;;GAEG;AACH,IAAM,gBAAgB,GAAG,UACvB,OAAyC,IACV,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": "
|
|
3
|
+
"version": "3.0.0-dev.20231209",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://nestia.io",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@nestia/fetcher": "^
|
|
41
|
+
"@nestia/fetcher": "^3.0.0-dev.20231209",
|
|
42
42
|
"@nestjs/common": ">=7.0.1",
|
|
43
43
|
"@nestjs/core": ">=7.0.1",
|
|
44
44
|
"@nestjs/platform-express": ">=7.0.1",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"typia": "^5.3.4"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@nestia/fetcher": ">=
|
|
54
|
+
"@nestia/fetcher": ">=3.0.0-dev.20231209",
|
|
55
55
|
"@nestjs/common": ">=7.0.1",
|
|
56
56
|
"@nestjs/core": ">=7.0.1",
|
|
57
57
|
"@nestjs/platform-express": ">=7.0.1",
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { Module } from "@nestjs/common";
|
|
2
|
-
import { ModuleMetadata } from "@nestjs/common/interfaces";
|
|
3
|
-
|
|
4
|
-
import { Creator } from "../typings/Creator";
|
|
5
|
-
import { load_controllers } from "./internal/load_controller";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Dynamic module.
|
|
9
|
-
*
|
|
10
|
-
* `DynamicModule` is a namespace wrapping a convenient function, which can load
|
|
11
|
-
* controller classes dynamically just by specifying their directory path.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
*/
|
|
15
|
-
export namespace DynamicModule {
|
|
16
|
-
/**
|
|
17
|
-
* Mount dynamic module.
|
|
18
|
-
*
|
|
19
|
-
* Constructs a module instance with directory path of controller classes.
|
|
20
|
-
*
|
|
21
|
-
* Every controller classes in the target directory would be dynamically mounted.
|
|
22
|
-
*
|
|
23
|
-
* @param path Path of controllers
|
|
24
|
-
* @param metadata Addtional metadata except controllers
|
|
25
|
-
* @returns module instance
|
|
26
|
-
*/
|
|
27
|
-
export async function mount(
|
|
28
|
-
path: string | string[] | { include: string[]; exclude?: string[] },
|
|
29
|
-
metadata: Omit<ModuleMetadata, "controllers"> = {},
|
|
30
|
-
): Promise<object> {
|
|
31
|
-
// LOAD CONTROLLERS
|
|
32
|
-
const controllers: Creator<object>[] = await load_controllers(path);
|
|
33
|
-
|
|
34
|
-
// RETURN WITH DECORATING
|
|
35
|
-
@Module({ ...metadata, controllers })
|
|
36
|
-
class NestiaModule {}
|
|
37
|
-
return NestiaModule;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import { Module } from "@nestjs/common";
|
|
2
|
+
import { ModuleMetadata } from "@nestjs/common/interfaces";
|
|
3
|
+
|
|
4
|
+
import { Creator } from "../typings/Creator";
|
|
5
|
+
import { load_controllers } from "./internal/load_controller";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic module.
|
|
9
|
+
*
|
|
10
|
+
* `DynamicModule` is a namespace wrapping a convenient function, which can load
|
|
11
|
+
* controller classes dynamically just by specifying their directory path.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
*/
|
|
15
|
+
export namespace DynamicModule {
|
|
16
|
+
/**
|
|
17
|
+
* Mount dynamic module.
|
|
18
|
+
*
|
|
19
|
+
* Constructs a module instance with directory path of controller classes.
|
|
20
|
+
*
|
|
21
|
+
* Every controller classes in the target directory would be dynamically mounted.
|
|
22
|
+
*
|
|
23
|
+
* @param path Path of controllers
|
|
24
|
+
* @param metadata Addtional metadata except controllers
|
|
25
|
+
* @returns module instance
|
|
26
|
+
*/
|
|
27
|
+
export async function mount(
|
|
28
|
+
path: string | string[] | { include: string[]; exclude?: string[] },
|
|
29
|
+
metadata: Omit<ModuleMetadata, "controllers"> = {},
|
|
30
|
+
): Promise<object> {
|
|
31
|
+
// LOAD CONTROLLERS
|
|
32
|
+
const controllers: Creator<object>[] = await load_controllers(path);
|
|
33
|
+
|
|
34
|
+
// RETURN WITH DECORATING
|
|
35
|
+
@Module({ ...metadata, controllers })
|
|
36
|
+
class NestiaModule {}
|
|
37
|
+
return NestiaModule;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AesPkcs5 } from "@nestia/fetcher/lib/AesPkcs5";
|
|
2
1
|
import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
|
|
2
|
+
import { AesPkcs5 } from "@nestia/fetcher/lib/internal/AesPkcs5";
|
|
3
3
|
import {
|
|
4
4
|
BadRequestException,
|
|
5
5
|
ExecutionContext,
|
|
@@ -12,7 +12,7 @@ import { assert, is, validate } from "typia";
|
|
|
12
12
|
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
13
13
|
import { Singleton } from "../utils/Singleton";
|
|
14
14
|
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
15
|
-
import {
|
|
15
|
+
import { get_binary_body } from "./internal/get_binary_body";
|
|
16
16
|
import { headers_to_object } from "./internal/headers_to_object";
|
|
17
17
|
import { validate_request_body } from "./internal/validate_request_body";
|
|
18
18
|
|
|
@@ -48,8 +48,10 @@ export function EncryptedBody<T>(
|
|
|
48
48
|
const request: express.Request | FastifyRequest = context
|
|
49
49
|
.switchToHttp()
|
|
50
50
|
.getRequest();
|
|
51
|
-
if (
|
|
52
|
-
throw new BadRequestException(
|
|
51
|
+
if (isApplicationOctetStream(request.headers["content-type"]) === false)
|
|
52
|
+
throw new BadRequestException(
|
|
53
|
+
`Request body type is not "application/octet-stream".`,
|
|
54
|
+
);
|
|
53
55
|
|
|
54
56
|
const param: IEncryptionPassword | IEncryptionPassword.Closure | undefined =
|
|
55
57
|
Reflect.getMetadata(ENCRYPTION_METADATA_KEY, context.getClass());
|
|
@@ -62,14 +64,17 @@ export function EncryptedBody<T>(
|
|
|
62
64
|
const headers: Singleton<Record<string, string>> = new Singleton(() =>
|
|
63
65
|
headers_to_object(request.headers),
|
|
64
66
|
);
|
|
65
|
-
const
|
|
67
|
+
const raw: Uint8Array = await get_binary_body(request);
|
|
68
|
+
if (raw.length === 0) return;
|
|
69
|
+
|
|
70
|
+
// PARSE AND VALIDATE DATA
|
|
66
71
|
const password: IEncryptionPassword =
|
|
67
72
|
typeof param === "function"
|
|
68
|
-
? param({ headers: headers.get(), body, direction: "decode" })
|
|
73
|
+
? param({ headers: headers.get(), body: raw, direction: "decode" })
|
|
69
74
|
: param;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const data: any = JSON.parse(
|
|
76
|
+
new TextDecoder().decode(decrypt(raw, password.key, password.iv)),
|
|
77
|
+
);
|
|
73
78
|
const error: Error | null = checker(data);
|
|
74
79
|
if (error !== null) throw error;
|
|
75
80
|
return data;
|
|
@@ -82,7 +87,7 @@ Object.assign(EncryptedBody, validate);
|
|
|
82
87
|
/**
|
|
83
88
|
* @internal
|
|
84
89
|
*/
|
|
85
|
-
const decrypt = (body:
|
|
90
|
+
const decrypt = (body: Uint8Array, key: string, iv: string): Uint8Array => {
|
|
86
91
|
try {
|
|
87
92
|
return AesPkcs5.decrypt(body, key, iv);
|
|
88
93
|
} catch (exp) {
|
|
@@ -94,9 +99,9 @@ const decrypt = (body: string, key: string, iv: string): string => {
|
|
|
94
99
|
}
|
|
95
100
|
};
|
|
96
101
|
|
|
97
|
-
const
|
|
102
|
+
const isApplicationOctetStream = (text?: string): boolean =>
|
|
98
103
|
text !== undefined &&
|
|
99
104
|
text
|
|
100
105
|
.split(";")
|
|
101
106
|
.map((str) => str.trim())
|
|
102
|
-
.some((str) => str === "
|
|
107
|
+
.some((str) => str === "application/octet-stream");
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
|
|
2
|
-
import { Controller } from "@nestjs/common";
|
|
3
|
-
|
|
4
|
-
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Encrypted controller.
|
|
8
|
-
*
|
|
9
|
-
* `EncryptedController` is an extension of the {@link nest.Controller} class decorator
|
|
10
|
-
* function who configures encryption password of the AES-128/256 algorithm. The
|
|
11
|
-
* encryption algorithm and password would be used by {@link EncryptedRoute} and
|
|
12
|
-
* {@link EncryptedBody} to encrypt the request and response body of the HTTP protocol.
|
|
13
|
-
*
|
|
14
|
-
* By the way, you can configure the encryption password in the global level by using
|
|
15
|
-
* {@link EncryptedModule} instead of the {@link nest.Module} in the module level. In
|
|
16
|
-
* that case, you don't need to use this `EncryptedController` more. Just use the
|
|
17
|
-
* {@link nest.Controller} without duplicated encryption password definitions.
|
|
18
|
-
*
|
|
19
|
-
* Of course, if you want to use different encryption password from the
|
|
20
|
-
* {@link EncryptedModule}, this `EncryptedController` would be useful again. Therefore,
|
|
21
|
-
* I recommend to use this `EncryptedController` decorator function only when you must
|
|
22
|
-
* configure different encryption password from the {@link EncryptedModule}.
|
|
23
|
-
*
|
|
24
|
-
* @param path Path of the HTTP request
|
|
25
|
-
* @param password Encryption password or its getter function
|
|
26
|
-
* @returns Class decorator
|
|
27
|
-
*
|
|
28
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
29
|
-
*/
|
|
30
|
-
export function EncryptedController(
|
|
31
|
-
path: string,
|
|
32
|
-
password: IEncryptionPassword | IEncryptionPassword.Closure,
|
|
33
|
-
): ClassDecorator {
|
|
34
|
-
return function (target: any) {
|
|
35
|
-
Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, target);
|
|
36
|
-
Controller(path)(target);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
1
|
+
import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
|
|
2
|
+
import { Controller } from "@nestjs/common";
|
|
3
|
+
|
|
4
|
+
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Encrypted controller.
|
|
8
|
+
*
|
|
9
|
+
* `EncryptedController` is an extension of the {@link nest.Controller} class decorator
|
|
10
|
+
* function who configures encryption password of the AES-128/256 algorithm. The
|
|
11
|
+
* encryption algorithm and password would be used by {@link EncryptedRoute} and
|
|
12
|
+
* {@link EncryptedBody} to encrypt the request and response body of the HTTP protocol.
|
|
13
|
+
*
|
|
14
|
+
* By the way, you can configure the encryption password in the global level by using
|
|
15
|
+
* {@link EncryptedModule} instead of the {@link nest.Module} in the module level. In
|
|
16
|
+
* that case, you don't need to use this `EncryptedController` more. Just use the
|
|
17
|
+
* {@link nest.Controller} without duplicated encryption password definitions.
|
|
18
|
+
*
|
|
19
|
+
* Of course, if you want to use different encryption password from the
|
|
20
|
+
* {@link EncryptedModule}, this `EncryptedController` would be useful again. Therefore,
|
|
21
|
+
* I recommend to use this `EncryptedController` decorator function only when you must
|
|
22
|
+
* configure different encryption password from the {@link EncryptedModule}.
|
|
23
|
+
*
|
|
24
|
+
* @param path Path of the HTTP request
|
|
25
|
+
* @param password Encryption password or its getter function
|
|
26
|
+
* @returns Class decorator
|
|
27
|
+
*
|
|
28
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
29
|
+
*/
|
|
30
|
+
export function EncryptedController(
|
|
31
|
+
path: string,
|
|
32
|
+
password: IEncryptionPassword | IEncryptionPassword.Closure,
|
|
33
|
+
): ClassDecorator {
|
|
34
|
+
return function (target: any) {
|
|
35
|
+
Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, target);
|
|
36
|
+
Controller(path)(target);
|
|
37
|
+
};
|
|
38
|
+
}
|