@nestia/core 0.1.0
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/LICENSE +21 -0
- package/lib/decorators/EncryptedBody.d.ts +22 -0
- package/lib/decorators/EncryptedBody.js +125 -0
- package/lib/decorators/EncryptedBody.js.map +1 -0
- package/lib/decorators/EncryptedController.d.ts +31 -0
- package/lib/decorators/EncryptedController.js +42 -0
- package/lib/decorators/EncryptedController.js.map +1 -0
- package/lib/decorators/EncryptedModule.d.ts +48 -0
- package/lib/decorators/EncryptedModule.js +270 -0
- package/lib/decorators/EncryptedModule.js.map +1 -0
- package/lib/decorators/EncryptedRoute.d.ts +78 -0
- package/lib/decorators/EncryptedRoute.js +191 -0
- package/lib/decorators/EncryptedRoute.js.map +1 -0
- package/lib/decorators/PlainBody.d.ts +22 -0
- package/lib/decorators/PlainBody.js +83 -0
- package/lib/decorators/PlainBody.js.map +1 -0
- package/lib/decorators/TypedBody.d.ts +14 -0
- package/lib/decorators/TypedBody.js +93 -0
- package/lib/decorators/TypedBody.js.map +1 -0
- package/lib/decorators/TypedParam.d.ts +25 -0
- package/lib/decorators/TypedParam.js +62 -0
- package/lib/decorators/TypedParam.js.map +1 -0
- package/lib/decorators/TypedRoute.d.ts +71 -0
- package/lib/decorators/TypedRoute.js +159 -0
- package/lib/decorators/TypedRoute.js.map +1 -0
- package/lib/decorators/internal/EncryptedConstant.d.ts +1 -0
- package/lib/decorators/internal/EncryptedConstant.js +8 -0
- package/lib/decorators/internal/EncryptedConstant.js.map +1 -0
- package/lib/decorators/internal/get_path_and_stringify.d.ts +1 -0
- package/lib/decorators/internal/get_path_and_stringify.js +75 -0
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -0
- package/lib/decorators/internal/headers_to_object.d.ts +1 -0
- package/lib/decorators/internal/headers_to_object.js +53 -0
- package/lib/decorators/internal/headers_to_object.js.map +1 -0
- package/lib/decorators/internal/route_error.d.ts +1 -0
- package/lib/decorators/internal/route_error.js +90 -0
- package/lib/decorators/internal/route_error.js.map +1 -0
- package/lib/decorators/internal/validate_request_body.d.ts +2 -0
- package/lib/decorators/internal/validate_request_body.js +56 -0
- package/lib/decorators/internal/validate_request_body.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +32 -0
- package/lib/index.js.map +1 -0
- package/lib/module.d.ts +9 -0
- package/lib/module.js +26 -0
- package/lib/module.js.map +1 -0
- package/lib/options/INestiaTransformOptions.d.ts +5 -0
- package/lib/options/INestiaTransformOptions.js +3 -0
- package/lib/options/INestiaTransformOptions.js.map +1 -0
- package/lib/options/INestiaTransformProject.d.ts +5 -0
- package/lib/options/INestiaTransformProject.js +3 -0
- package/lib/options/INestiaTransformProject.js.map +1 -0
- package/lib/options/IRequestBodyValidator.d.ts +16 -0
- package/lib/options/IRequestBodyValidator.js +3 -0
- package/lib/options/IRequestBodyValidator.js.map +1 -0
- package/lib/options/IResponseBodyStringifier.d.ts +20 -0
- package/lib/options/IResponseBodyStringifier.js +3 -0
- package/lib/options/IResponseBodyStringifier.js.map +1 -0
- package/lib/transform.d.ts +3 -0
- package/lib/transform.js +21 -0
- package/lib/transform.js.map +1 -0
- package/lib/transformers/BodyTransformer.d.ts +5 -0
- package/lib/transformers/BodyTransformer.js +69 -0
- package/lib/transformers/BodyTransformer.js.map +1 -0
- package/lib/transformers/FileTransformer.d.ts +5 -0
- package/lib/transformers/FileTransformer.js +33 -0
- package/lib/transformers/FileTransformer.js.map +1 -0
- package/lib/transformers/MethodTransformer.d.ts +5 -0
- package/lib/transformers/MethodTransformer.js +55 -0
- package/lib/transformers/MethodTransformer.js.map +1 -0
- package/lib/transformers/NodeTransformer.d.ts +5 -0
- package/lib/transformers/NodeTransformer.js +21 -0
- package/lib/transformers/NodeTransformer.js.map +1 -0
- package/lib/transformers/ParameterTransformer.d.ts +5 -0
- package/lib/transformers/ParameterTransformer.js +31 -0
- package/lib/transformers/ParameterTransformer.js.map +1 -0
- package/lib/transformers/RouteTransformer.d.ts +5 -0
- package/lib/transformers/RouteTransformer.js +115 -0
- package/lib/transformers/RouteTransformer.js.map +1 -0
- package/lib/typings/Creator.d.ts +3 -0
- package/lib/typings/Creator.js +3 -0
- package/lib/typings/Creator.js.map +1 -0
- package/lib/utils/ExceptionManager.d.ts +64 -0
- package/lib/utils/ExceptionManager.js +113 -0
- package/lib/utils/ExceptionManager.js.map +1 -0
- package/lib/utils/Singleton.d.ts +1 -0
- package/lib/utils/Singleton.js +24 -0
- package/lib/utils/Singleton.js.map +1 -0
- package/package.json +66 -0
- package/src/decorators/EncryptedBody.ts +102 -0
- package/src/decorators/EncryptedController.ts +43 -0
- package/src/decorators/EncryptedModule.ts +127 -0
- package/src/decorators/EncryptedRoute.ts +200 -0
- package/src/decorators/PlainBody.ts +38 -0
- package/src/decorators/TypedBody.ts +49 -0
- package/src/decorators/TypedParam.ts +70 -0
- package/src/decorators/TypedRoute.ts +149 -0
- package/src/decorators/internal/EncryptedConstant.ts +4 -0
- package/src/decorators/internal/get_path_and_stringify.ts +76 -0
- package/src/decorators/internal/headers_to_object.ts +13 -0
- package/src/decorators/internal/route_error.ts +41 -0
- package/src/decorators/internal/validate_request_body.ts +58 -0
- package/src/index.ts +5 -0
- package/src/module.ts +9 -0
- package/src/options/INestiaTransformOptions.ts +6 -0
- package/src/options/INestiaTransformProject.ts +6 -0
- package/src/options/IRequestBodyValidator.ts +20 -0
- package/src/options/IResponseBodyStringifier.ts +25 -0
- package/src/transform.ts +20 -0
- package/src/transformers/BodyTransformer.ts +106 -0
- package/src/transformers/FileTransformer.ts +49 -0
- package/src/transformers/MethodTransformer.ts +91 -0
- package/src/transformers/NodeTransformer.ts +18 -0
- package/src/transformers/ParameterTransformer.ts +45 -0
- package/src/transformers/RouteTransformer.ts +134 -0
- package/src/typings/Creator.ts +3 -0
- package/src/utils/ExceptionManager.ts +126 -0
- package/src/utils/Singleton.ts +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Jeongho Nam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
2
|
+
/**
|
|
3
|
+
* Encrypted body decorator.
|
|
4
|
+
*
|
|
5
|
+
* `EncryptedBody` is a decorator function getting JSON data from HTTP request who've
|
|
6
|
+
* been encrypted by AES-128/256 algorithm. Also, `EncyrptedBody` validates the JSON
|
|
7
|
+
* data type through
|
|
8
|
+
* [`typia.assert()`](https://github.com/samchon/typia#runtime-type-checkers)
|
|
9
|
+
* function and throws `BadRequestException` error (status code: 400), if the JSON
|
|
10
|
+
* data is not following the promised type.
|
|
11
|
+
*
|
|
12
|
+
* For reference, `EncryptedRoute` decrypts request body usnig those options.
|
|
13
|
+
*
|
|
14
|
+
* - AES-128/256
|
|
15
|
+
* - CBC mode
|
|
16
|
+
* - PKCS #5 Padding
|
|
17
|
+
* - Base64 Encoding
|
|
18
|
+
*
|
|
19
|
+
* @return Parameter decorator
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
*/
|
|
22
|
+
export declare function EncryptedBody<T>(validator: IRequestBodyValidator<T>): ParameterDecorator;
|
|
@@ -0,0 +1,125 @@
|
|
|
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.EncryptedBody = void 0;
|
|
43
|
+
var fetcher_1 = require("@nestia/fetcher");
|
|
44
|
+
var common_1 = require("@nestjs/common");
|
|
45
|
+
var raw_body_1 = __importDefault(require("raw-body"));
|
|
46
|
+
var typia_1 = require("typia");
|
|
47
|
+
var Singleton_1 = require("../utils/Singleton");
|
|
48
|
+
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
49
|
+
var headers_to_object_1 = require("./internal/headers_to_object");
|
|
50
|
+
var validate_request_body_1 = require("./internal/validate_request_body");
|
|
51
|
+
/**
|
|
52
|
+
* Encrypted body decorator.
|
|
53
|
+
*
|
|
54
|
+
* `EncryptedBody` is a decorator function getting JSON data from HTTP request who've
|
|
55
|
+
* been encrypted by AES-128/256 algorithm. Also, `EncyrptedBody` validates the JSON
|
|
56
|
+
* data type through
|
|
57
|
+
* [`typia.assert()`](https://github.com/samchon/typia#runtime-type-checkers)
|
|
58
|
+
* function and throws `BadRequestException` error (status code: 400), if the JSON
|
|
59
|
+
* data is not following the promised type.
|
|
60
|
+
*
|
|
61
|
+
* For reference, `EncryptedRoute` decrypts request body usnig those options.
|
|
62
|
+
*
|
|
63
|
+
* - AES-128/256
|
|
64
|
+
* - CBC mode
|
|
65
|
+
* - PKCS #5 Padding
|
|
66
|
+
* - Base64 Encoding
|
|
67
|
+
*
|
|
68
|
+
* @return Parameter decorator
|
|
69
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
70
|
+
*/
|
|
71
|
+
function EncryptedBody(validator) {
|
|
72
|
+
var checker = (0, validate_request_body_1.validate_request_body)("EncryptedBody")(validator);
|
|
73
|
+
return (0, common_1.createParamDecorator)(function EncryptedBody(_unknown, ctx) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var request, param, headers, body, password, disabled, data;
|
|
76
|
+
return __generator(this, function (_a) {
|
|
77
|
+
switch (_a.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
request = ctx.switchToHttp().getRequest();
|
|
80
|
+
if (request.readable === false)
|
|
81
|
+
throw new common_1.BadRequestException("Request body is not the text/plain.");
|
|
82
|
+
param = Reflect.getMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, ctx.getClass());
|
|
83
|
+
if (!param)
|
|
84
|
+
throw new Error("Error on EncryptedBody(): no encryption password is given.");
|
|
85
|
+
headers = new Singleton_1.Singleton(function () {
|
|
86
|
+
return (0, headers_to_object_1.headers_to_object)(request.headers);
|
|
87
|
+
});
|
|
88
|
+
return [4 /*yield*/, (0, raw_body_1.default)(request, "utf8")];
|
|
89
|
+
case 1:
|
|
90
|
+
body = (_a.sent()).trim();
|
|
91
|
+
password = typeof param === "function"
|
|
92
|
+
? param({ headers: headers.get(), body: body }, false)
|
|
93
|
+
: param;
|
|
94
|
+
disabled = password.disabled === undefined
|
|
95
|
+
? false
|
|
96
|
+
: typeof password.disabled === "function"
|
|
97
|
+
? password.disabled({ headers: headers.get(), body: body }, true)
|
|
98
|
+
: password.disabled;
|
|
99
|
+
data = JSON.parse(disabled ? body : decrypt(body, password.key, password.iv));
|
|
100
|
+
checker(data);
|
|
101
|
+
return [2 /*return*/, data];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
})();
|
|
106
|
+
}
|
|
107
|
+
exports.EncryptedBody = EncryptedBody;
|
|
108
|
+
Object.assign(EncryptedBody, typia_1.assert);
|
|
109
|
+
Object.assign(EncryptedBody, typia_1.is);
|
|
110
|
+
Object.assign(EncryptedBody, typia_1.validate);
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
function decrypt(body, key, iv) {
|
|
115
|
+
try {
|
|
116
|
+
return fetcher_1.AesPkcs5.decrypt(body, key, iv);
|
|
117
|
+
}
|
|
118
|
+
catch (exp) {
|
|
119
|
+
if (exp instanceof Error)
|
|
120
|
+
throw new common_1.BadRequestException("Failed to decrypt the request body. Check your body content or encryption password.");
|
|
121
|
+
else
|
|
122
|
+
throw exp;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=EncryptedBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedBody.js","sourceRoot":"","sources":["../../src/decorators/EncryptedBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,yCAIwB;AAExB,sDAA2B;AAC3B,+BAA6C;AAG7C,gDAA+C;AAC/C,kEAAuE;AACvE,kEAAiE;AACjE,0EAAyE;AAEzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,aAAa,CAAI,SAAmC;IAChE,IAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC;IAClE,OAAO,IAAA,6BAAoB,EAAC,SAAe,aAAa,CACpD,QAAa,EACb,GAAqB;;;;;;wBAEf,OAAO,GAAoB,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;wBACjE,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK;4BAC1B,MAAM,IAAI,4BAAmB,CACzB,qCAAqC,CACxC,CAAC;wBAEA,KAAK,GAGO,OAAO,CAAC,WAAW,CACjC,2CAAuB,EACvB,GAAG,CAAC,QAAQ,EAAE,CACjB,CAAC;wBACF,IAAI,CAAC,KAAK;4BACN,MAAM,IAAI,KAAK,CACX,4DAA4D,CAC/D,CAAC;wBAGA,OAAO,GAAsC,IAAI,qBAAS,CAAC;4BAC7D,OAAA,IAAA,qCAAiB,EAAC,OAAO,CAAC,OAAO,CAAC;wBAAlC,CAAkC,CACrC,CAAC;wBACoB,qBAAM,IAAA,kBAAG,EAAC,OAAO,EAAE,MAAM,CAAC,EAAA;;wBAA1C,IAAI,GAAW,CAAC,SAA0B,CAAC,CAAC,IAAI,EAAE;wBAClD,QAAQ,GACV,OAAO,KAAK,KAAK,UAAU;4BACvB,CAAC,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,MAAA,EAAE,EAAE,KAAK,CAAC;4BAChD,CAAC,CAAC,KAAK,CAAC;wBACV,QAAQ,GACV,QAAQ,CAAC,QAAQ,KAAK,SAAS;4BAC3B,CAAC,CAAC,KAAK;4BACP,CAAC,CAAC,OAAO,QAAQ,CAAC,QAAQ,KAAK,UAAU;gCACzC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,MAAA,EAAE,EAAE,IAAI,CAAC;gCAC3D,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;wBAGtB,IAAI,GAAQ,IAAI,CAAC,KAAK,CACxB,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,CAC7D,CAAC;wBACF,OAAO,CAAC,IAAI,CAAC,CAAC;wBACd,sBAAO,IAAI,EAAC;;;;KACf,CAAC,EAAE,CAAC;AACT,CAAC;AA/CD,sCA+CC;AACD,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,cAAM,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,UAAE,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,gBAAQ,CAAC,CAAC;AAEvC;;GAEG;AACH,SAAS,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU;IAClD,IAAI;QACA,OAAO,kBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;KAC1C;IAAC,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,YAAY,KAAK;YACpB,MAAM,IAAI,4BAAmB,CACzB,qFAAqF,CACxF,CAAC;;YACD,MAAM,GAAG,CAAC;KAClB;AACL,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IEncryptionPassword } from "@nestia/fetcher";
|
|
2
|
+
/**
|
|
3
|
+
* Encrypted controller.
|
|
4
|
+
*
|
|
5
|
+
* `EncryptedController` is an extension of the {@link nest.Controller} class decorator
|
|
6
|
+
* function who configures encryption password of the AES-128/256 algorithm. The
|
|
7
|
+
* encryption algorithm and password would be used by {@link EncryptedRoute} and
|
|
8
|
+
* {@link EncryptedBody} to encrypt the request and response body of the HTTP protocol.
|
|
9
|
+
*
|
|
10
|
+
* > However, if you've configure the {@link IEncryptionPassword.disabled} to be `true`,
|
|
11
|
+
* > you can disable the encryption and decryption algorithm. Therefore, when the
|
|
12
|
+
* > {@link IEncryptionPassword.disable} becomes the `true`, content like request and
|
|
13
|
+
* > response body would be considered as a plain text instead.
|
|
14
|
+
*
|
|
15
|
+
* By the way, you can configure the encryption password in the global level by using
|
|
16
|
+
* {@link EncryptedModule} instead of the {@link nest.Module} in the module level. In
|
|
17
|
+
* that case, you don't need to use this `EncryptedController` more. Just use the
|
|
18
|
+
* {@link nest.Controller} without duplicated encryption password definitions.
|
|
19
|
+
*
|
|
20
|
+
* Of course, if you want to use different encryption password from the
|
|
21
|
+
* {@link EncryptedModule}, this `EncryptedController` would be useful again. Therefore,
|
|
22
|
+
* I recommend to use this `EncryptedController` decorator function only when you must
|
|
23
|
+
* configure different encryption password from the {@link EncryptedModule}.
|
|
24
|
+
*
|
|
25
|
+
* @param path Path of the HTTP request
|
|
26
|
+
* @param password Encryption password or its getter function
|
|
27
|
+
* @returns Class decorator
|
|
28
|
+
*
|
|
29
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export declare function EncryptedController(path: string, password: IEncryptionPassword | IEncryptionPassword.Closure): ClassDecorator;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EncryptedController = void 0;
|
|
4
|
+
var common_1 = require("@nestjs/common");
|
|
5
|
+
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
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
|
+
* > However, if you've configure the {@link IEncryptionPassword.disabled} to be `true`,
|
|
15
|
+
* > you can disable the encryption and decryption algorithm. Therefore, when the
|
|
16
|
+
* > {@link IEncryptionPassword.disable} becomes the `true`, content like request and
|
|
17
|
+
* > response body would be considered as a plain text instead.
|
|
18
|
+
*
|
|
19
|
+
* By the way, you can configure the encryption password in the global level by using
|
|
20
|
+
* {@link EncryptedModule} instead of the {@link nest.Module} in the module level. In
|
|
21
|
+
* that case, you don't need to use this `EncryptedController` more. Just use the
|
|
22
|
+
* {@link nest.Controller} without duplicated encryption password definitions.
|
|
23
|
+
*
|
|
24
|
+
* Of course, if you want to use different encryption password from the
|
|
25
|
+
* {@link EncryptedModule}, this `EncryptedController` would be useful again. Therefore,
|
|
26
|
+
* I recommend to use this `EncryptedController` decorator function only when you must
|
|
27
|
+
* configure different encryption password from the {@link EncryptedModule}.
|
|
28
|
+
*
|
|
29
|
+
* @param path Path of the HTTP request
|
|
30
|
+
* @param password Encryption password or its getter function
|
|
31
|
+
* @returns Class decorator
|
|
32
|
+
*
|
|
33
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
34
|
+
*/
|
|
35
|
+
function EncryptedController(path, password) {
|
|
36
|
+
return function (target) {
|
|
37
|
+
Reflect.defineMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, password, target);
|
|
38
|
+
(0, common_1.Controller)(path)(target);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.EncryptedController = EncryptedController;
|
|
42
|
+
//# sourceMappingURL=EncryptedController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedController.js","sourceRoot":"","sources":["../../src/decorators/EncryptedController.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAE5C,kEAAuE;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,mBAAmB,CAC/B,IAAY,EACZ,QAA2D;IAE3D,OAAO,UAAU,MAAW;QACxB,OAAO,CAAC,cAAc,CAAC,2CAAuB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClE,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;AACN,CAAC;AARD,kDAQC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
|
|
2
|
+
import { ModuleMetadata } from "@nestjs/common";
|
|
3
|
+
/**
|
|
4
|
+
* Encrypted module.
|
|
5
|
+
*
|
|
6
|
+
* `EncryptedModule` is an extension of the {@link Module} class decorator function
|
|
7
|
+
* who configures encryption password of the AES-128/256 algorithm. The encryption
|
|
8
|
+
* algorithm and password would be used by {@link EncryptedRoute} and {@link EncryptedBody}
|
|
9
|
+
* to encrypt the request and response bod of the HTTP protocol.
|
|
10
|
+
*
|
|
11
|
+
* By using this `EncryptedModule` decorator function, all of the
|
|
12
|
+
* {@link Controller controllers} configured in the *metadata* would be automatically
|
|
13
|
+
* changed to the {@link EncryptedController} with the *password*. If there're some
|
|
14
|
+
* original {@link EncryptedController} decorated classes in the *metadata*, their
|
|
15
|
+
* encryption password would be kept.
|
|
16
|
+
*
|
|
17
|
+
* Therefore, if you're planning to place original {@link EncryptedController} decorated
|
|
18
|
+
* classes in the *metadata*, I hope them to have different encryption password from the
|
|
19
|
+
* module level. If not, I recommend you use the {@link Controller} decorator
|
|
20
|
+
* function instead.
|
|
21
|
+
*
|
|
22
|
+
* In addition, the `EncryptedModule` supports a convenient dynamic controller importing
|
|
23
|
+
* function, {@link EncryptedModule.dynamic}. If you utilize the function with directory
|
|
24
|
+
* path of the controller classes, it imports and configures the controller classes into
|
|
25
|
+
* the `Module`, automatically.
|
|
26
|
+
*
|
|
27
|
+
* @param metadata Module configuration metadata
|
|
28
|
+
* @param password Encryption password or its getter function
|
|
29
|
+
* @returns Class decorator
|
|
30
|
+
*
|
|
31
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
+
*/
|
|
33
|
+
export declare function EncryptedModule(metadata: ModuleMetadata, password: IEncryptionPassword | IEncryptionPassword.Closure): ClassDecorator;
|
|
34
|
+
export declare namespace EncryptedModule {
|
|
35
|
+
/**
|
|
36
|
+
* Dynamic encrypted module.
|
|
37
|
+
*
|
|
38
|
+
* `EncryptedModule.dynamic` is an extension of the {@link EncryptedModule} function
|
|
39
|
+
* who configures controller classes by the dynamic importing. By specifying directory
|
|
40
|
+
* path of the controller classes, those controllers would be automatically imported
|
|
41
|
+
* and configured.
|
|
42
|
+
*
|
|
43
|
+
* @param path Directory path of the controller classes
|
|
44
|
+
* @param password Encryption password or its getter function
|
|
45
|
+
* @returns Class decorated module instance
|
|
46
|
+
*/
|
|
47
|
+
function dynamic(path: string, password: IEncryptionPassword | IEncryptionPassword.Closure): Promise<object>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
32
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
41
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
42
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
43
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
44
|
+
function step(op) {
|
|
45
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
46
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
47
|
+
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;
|
|
48
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
49
|
+
switch (op[0]) {
|
|
50
|
+
case 0: case 1: t = op; break;
|
|
51
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
52
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
53
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
54
|
+
default:
|
|
55
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
56
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
57
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
58
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
59
|
+
if (t[2]) _.ops.pop();
|
|
60
|
+
_.trys.pop(); continue;
|
|
61
|
+
}
|
|
62
|
+
op = body.call(thisArg, _);
|
|
63
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
64
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var __values = (this && this.__values) || function(o) {
|
|
68
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
69
|
+
if (m) return m.call(o);
|
|
70
|
+
if (o && typeof o.length === "number") return {
|
|
71
|
+
next: function () {
|
|
72
|
+
if (o && i >= o.length) o = void 0;
|
|
73
|
+
return { value: o && o[i++], done: !o };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
77
|
+
};
|
|
78
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
+
};
|
|
81
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
82
|
+
exports.EncryptedModule = void 0;
|
|
83
|
+
var common_1 = require("@nestjs/common");
|
|
84
|
+
var detect_ts_node_1 = __importDefault(require("detect-ts-node"));
|
|
85
|
+
var fs_1 = __importDefault(require("fs"));
|
|
86
|
+
var EncryptedConstant_1 = require("./internal/EncryptedConstant");
|
|
87
|
+
/**
|
|
88
|
+
* Encrypted module.
|
|
89
|
+
*
|
|
90
|
+
* `EncryptedModule` is an extension of the {@link Module} class decorator function
|
|
91
|
+
* who configures encryption password of the AES-128/256 algorithm. The encryption
|
|
92
|
+
* algorithm and password would be used by {@link EncryptedRoute} and {@link EncryptedBody}
|
|
93
|
+
* to encrypt the request and response bod of the HTTP protocol.
|
|
94
|
+
*
|
|
95
|
+
* By using this `EncryptedModule` decorator function, all of the
|
|
96
|
+
* {@link Controller controllers} configured in the *metadata* would be automatically
|
|
97
|
+
* changed to the {@link EncryptedController} with the *password*. If there're some
|
|
98
|
+
* original {@link EncryptedController} decorated classes in the *metadata*, their
|
|
99
|
+
* encryption password would be kept.
|
|
100
|
+
*
|
|
101
|
+
* Therefore, if you're planning to place original {@link EncryptedController} decorated
|
|
102
|
+
* classes in the *metadata*, I hope them to have different encryption password from the
|
|
103
|
+
* module level. If not, I recommend you use the {@link Controller} decorator
|
|
104
|
+
* function instead.
|
|
105
|
+
*
|
|
106
|
+
* In addition, the `EncryptedModule` supports a convenient dynamic controller importing
|
|
107
|
+
* function, {@link EncryptedModule.dynamic}. If you utilize the function with directory
|
|
108
|
+
* path of the controller classes, it imports and configures the controller classes into
|
|
109
|
+
* the `Module`, automatically.
|
|
110
|
+
*
|
|
111
|
+
* @param metadata Module configuration metadata
|
|
112
|
+
* @param password Encryption password or its getter function
|
|
113
|
+
* @returns Class decorator
|
|
114
|
+
*
|
|
115
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
116
|
+
*/
|
|
117
|
+
function EncryptedModule(metadata, password) {
|
|
118
|
+
return function (target) {
|
|
119
|
+
var e_1, _a;
|
|
120
|
+
(0, common_1.Module)(metadata)(target);
|
|
121
|
+
if (metadata.controllers === undefined)
|
|
122
|
+
return;
|
|
123
|
+
try {
|
|
124
|
+
for (var _b = __values(metadata.controllers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
125
|
+
var controller = _c.value;
|
|
126
|
+
if (Reflect.hasMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, controller) ===
|
|
127
|
+
false)
|
|
128
|
+
Reflect.defineMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, password, controller);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
132
|
+
finally {
|
|
133
|
+
try {
|
|
134
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
135
|
+
}
|
|
136
|
+
finally { if (e_1) throw e_1.error; }
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
exports.EncryptedModule = EncryptedModule;
|
|
141
|
+
(function (EncryptedModule) {
|
|
142
|
+
/**
|
|
143
|
+
* Dynamic encrypted module.
|
|
144
|
+
*
|
|
145
|
+
* `EncryptedModule.dynamic` is an extension of the {@link EncryptedModule} function
|
|
146
|
+
* who configures controller classes by the dynamic importing. By specifying directory
|
|
147
|
+
* path of the controller classes, those controllers would be automatically imported
|
|
148
|
+
* and configured.
|
|
149
|
+
*
|
|
150
|
+
* @param path Directory path of the controller classes
|
|
151
|
+
* @param password Encryption password or its getter function
|
|
152
|
+
* @returns Class decorated module instance
|
|
153
|
+
*/
|
|
154
|
+
function dynamic(path, password) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var metadata, Module;
|
|
157
|
+
var _a;
|
|
158
|
+
return __generator(this, function (_b) {
|
|
159
|
+
switch (_b.label) {
|
|
160
|
+
case 0:
|
|
161
|
+
_a = {};
|
|
162
|
+
return [4 /*yield*/, controllers(path, password)];
|
|
163
|
+
case 1:
|
|
164
|
+
metadata = (_a.controllers = _b.sent(),
|
|
165
|
+
_a);
|
|
166
|
+
Module = /** @class */ (function () {
|
|
167
|
+
function Module() {
|
|
168
|
+
}
|
|
169
|
+
Module = __decorate([
|
|
170
|
+
EncryptedModule(metadata, password)
|
|
171
|
+
], Module);
|
|
172
|
+
return Module;
|
|
173
|
+
}());
|
|
174
|
+
return [2 /*return*/, Module];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
EncryptedModule.dynamic = dynamic;
|
|
180
|
+
function controllers(path, password) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
182
|
+
var output, output_1, output_1_1, controller;
|
|
183
|
+
var e_2, _a;
|
|
184
|
+
return __generator(this, function (_b) {
|
|
185
|
+
switch (_b.label) {
|
|
186
|
+
case 0:
|
|
187
|
+
output = [];
|
|
188
|
+
return [4 /*yield*/, iterate(output, path)];
|
|
189
|
+
case 1:
|
|
190
|
+
_b.sent();
|
|
191
|
+
try {
|
|
192
|
+
for (output_1 = __values(output), output_1_1 = output_1.next(); !output_1_1.done; output_1_1 = output_1.next()) {
|
|
193
|
+
controller = output_1_1.value;
|
|
194
|
+
if (Reflect.hasMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, controller) ===
|
|
195
|
+
false)
|
|
196
|
+
Reflect.defineMetadata(EncryptedConstant_1.ENCRYPTION_METADATA_KEY, password, controller);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
200
|
+
finally {
|
|
201
|
+
try {
|
|
202
|
+
if (output_1_1 && !output_1_1.done && (_a = output_1.return)) _a.call(output_1);
|
|
203
|
+
}
|
|
204
|
+
finally { if (e_2) throw e_2.error; }
|
|
205
|
+
}
|
|
206
|
+
return [2 /*return*/, output];
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function iterate(controllers, path) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
213
|
+
var directory, directory_1, directory_1_1, file, current, stats, external_1, key, instance, e_3_1;
|
|
214
|
+
var e_3, _a;
|
|
215
|
+
return __generator(this, function (_b) {
|
|
216
|
+
var _c;
|
|
217
|
+
switch (_b.label) {
|
|
218
|
+
case 0: return [4 /*yield*/, fs_1.default.promises.readdir(path)];
|
|
219
|
+
case 1:
|
|
220
|
+
directory = _b.sent();
|
|
221
|
+
_b.label = 2;
|
|
222
|
+
case 2:
|
|
223
|
+
_b.trys.push([2, 10, 11, 12]);
|
|
224
|
+
directory_1 = __values(directory), directory_1_1 = directory_1.next();
|
|
225
|
+
_b.label = 3;
|
|
226
|
+
case 3:
|
|
227
|
+
if (!!directory_1_1.done) return [3 /*break*/, 9];
|
|
228
|
+
file = directory_1_1.value;
|
|
229
|
+
current = "".concat(path, "/").concat(file);
|
|
230
|
+
return [4 /*yield*/, fs_1.default.promises.lstat(current)];
|
|
231
|
+
case 4:
|
|
232
|
+
stats = _b.sent();
|
|
233
|
+
if (!(stats.isDirectory() === true)) return [3 /*break*/, 6];
|
|
234
|
+
return [4 /*yield*/, iterate(controllers, current)];
|
|
235
|
+
case 5:
|
|
236
|
+
_b.sent();
|
|
237
|
+
return [3 /*break*/, 8];
|
|
238
|
+
case 6:
|
|
239
|
+
if (!(file.substring(file.length - 3) === ".".concat(EXTENSION))) return [3 /*break*/, 8];
|
|
240
|
+
return [4 /*yield*/, (_c = current, Promise.resolve().then(function () { return __importStar(require(_c)); }))];
|
|
241
|
+
case 7:
|
|
242
|
+
external_1 = _b.sent();
|
|
243
|
+
for (key in external_1) {
|
|
244
|
+
instance = external_1[key];
|
|
245
|
+
if (Reflect.getMetadata("path", instance) !== undefined)
|
|
246
|
+
controllers.push(instance);
|
|
247
|
+
}
|
|
248
|
+
_b.label = 8;
|
|
249
|
+
case 8:
|
|
250
|
+
directory_1_1 = directory_1.next();
|
|
251
|
+
return [3 /*break*/, 3];
|
|
252
|
+
case 9: return [3 /*break*/, 12];
|
|
253
|
+
case 10:
|
|
254
|
+
e_3_1 = _b.sent();
|
|
255
|
+
e_3 = { error: e_3_1 };
|
|
256
|
+
return [3 /*break*/, 12];
|
|
257
|
+
case 11:
|
|
258
|
+
try {
|
|
259
|
+
if (directory_1_1 && !directory_1_1.done && (_a = directory_1.return)) _a.call(directory_1);
|
|
260
|
+
}
|
|
261
|
+
finally { if (e_3) throw e_3.error; }
|
|
262
|
+
return [7 /*endfinally*/];
|
|
263
|
+
case 12: return [2 /*return*/];
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
})(EncryptedModule = exports.EncryptedModule || (exports.EncryptedModule = {}));
|
|
269
|
+
var EXTENSION = detect_ts_node_1.default ? "ts" : "js";
|
|
270
|
+
//# sourceMappingURL=EncryptedModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedModule.js","sourceRoot":"","sources":["../../src/decorators/EncryptedModule.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encrypted router decorator functions.
|
|
3
|
+
*
|
|
4
|
+
* `EncryptedRoute` is a module containing router decorator functions which encrypts
|
|
5
|
+
* response body data through AES-128/250 encryption. Also, those decorator functions
|
|
6
|
+
* can boost up JSON string conversion speed about 5x times faster, through
|
|
7
|
+
* [`typia.stringify()`](https://github.com/samchon/typia#fastest-json-string-conversion).
|
|
8
|
+
*
|
|
9
|
+
* For reference, `EncryptedRoute` encrypts response body usnig those options.
|
|
10
|
+
*
|
|
11
|
+
* - AES-128/256
|
|
12
|
+
* - CBC mode
|
|
13
|
+
* - PKCS #5 Padding
|
|
14
|
+
* - Base64 Encoding
|
|
15
|
+
*
|
|
16
|
+
* Also, router functions in `EncryptedRoute` can convert custom error classes to the
|
|
17
|
+
* regular {@link nest.HttpException} class automatically, through
|
|
18
|
+
* {@link ExceptionManager}.
|
|
19
|
+
*
|
|
20
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
21
|
+
*/
|
|
22
|
+
export declare namespace EncryptedRoute {
|
|
23
|
+
/**
|
|
24
|
+
* Encrypted router decorator function for the GET method.
|
|
25
|
+
*
|
|
26
|
+
* @param paths Path(s) of the HTTP request
|
|
27
|
+
* @returns Method decorator
|
|
28
|
+
*/
|
|
29
|
+
const Get: {
|
|
30
|
+
(path?: string | string[]): MethodDecorator;
|
|
31
|
+
(stringify?: ((input: any) => string) | undefined): MethodDecorator;
|
|
32
|
+
(path: string | string[], stringify: (input: any) => string): MethodDecorator;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Encrypted router decorator function for the GET method.
|
|
36
|
+
*
|
|
37
|
+
* @param paths Path(s) of the HTTP request
|
|
38
|
+
* @returns Method decorator
|
|
39
|
+
*/
|
|
40
|
+
const Post: {
|
|
41
|
+
(path?: string | string[]): MethodDecorator;
|
|
42
|
+
(stringify?: ((input: any) => string) | undefined): MethodDecorator;
|
|
43
|
+
(path: string | string[], stringify: (input: any) => string): MethodDecorator;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Encrypted router decorator function for the PATCH method.
|
|
47
|
+
*
|
|
48
|
+
* @param path Path of the HTTP request
|
|
49
|
+
* @returns Method decorator
|
|
50
|
+
*/
|
|
51
|
+
const Patch: {
|
|
52
|
+
(path?: string | string[]): MethodDecorator;
|
|
53
|
+
(stringify?: ((input: any) => string) | undefined): MethodDecorator;
|
|
54
|
+
(path: string | string[], stringify: (input: any) => string): MethodDecorator;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Encrypted router decorator function for the PUT method.
|
|
58
|
+
*
|
|
59
|
+
* @param path Path of the HTTP request
|
|
60
|
+
* @returns Method decorator
|
|
61
|
+
*/
|
|
62
|
+
const Put: {
|
|
63
|
+
(path?: string | string[]): MethodDecorator;
|
|
64
|
+
(stringify?: ((input: any) => string) | undefined): MethodDecorator;
|
|
65
|
+
(path: string | string[], stringify: (input: any) => string): MethodDecorator;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Encrypted router decorator function for the DELETE method.
|
|
69
|
+
*
|
|
70
|
+
* @param path Path of the HTTP request
|
|
71
|
+
* @returns Method decorator
|
|
72
|
+
*/
|
|
73
|
+
const Delete: {
|
|
74
|
+
(path?: string | string[]): MethodDecorator;
|
|
75
|
+
(stringify?: ((input: any) => string) | undefined): MethodDecorator;
|
|
76
|
+
(path: string | string[], stringify: (input: any) => string): MethodDecorator;
|
|
77
|
+
};
|
|
78
|
+
}
|