@nestia/core 0.1.5 → 0.1.7
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 +1 -1
- package/README.md +336 -0
- package/lib/decorators/PlainBody.d.ts +1 -1
- package/lib/decorators/PlainBody.js +1 -1
- package/lib/executable/core.d.ts +2 -0
- package/lib/executable/core.js +100 -0
- package/lib/executable/core.js.map +1 -0
- package/lib/executable/internal/CommandParser.d.ts +3 -0
- package/lib/executable/internal/CommandParser.js +21 -0
- package/lib/executable/internal/CommandParser.js.map +1 -0
- package/lib/executable/internal/CoreSetupWizard.d.ts +4 -0
- package/lib/executable/internal/CoreSetupWizard.js +259 -0
- package/lib/executable/internal/CoreSetupWizard.js.map +1 -0
- package/package.json +5 -1
- package/src/decorators/EncryptedBody.ts +102 -102
- package/src/decorators/EncryptedController.ts +43 -43
- package/src/decorators/EncryptedModule.ts +77 -77
- package/src/decorators/EncryptedRoute.ts +203 -203
- package/src/decorators/PlainBody.ts +38 -38
- package/src/decorators/TypedBody.ts +49 -49
- package/src/decorators/TypedParam.ts +70 -70
- package/src/decorators/TypedRoute.ts +149 -149
- package/src/decorators/internal/EncryptedConstant.ts +4 -4
- package/src/decorators/internal/get_path_and_stringify.ts +77 -77
- package/src/decorators/internal/headers_to_object.ts +10 -10
- package/src/decorators/internal/route_error.ts +38 -38
- package/src/decorators/internal/validate_request_body.ts +59 -59
- package/src/executable/core.ts +46 -0
- package/src/executable/internal/CommandParser.ts +15 -0
- package/src/executable/internal/CoreSetupWizard.ts +177 -0
- package/src/index.ts +5 -5
- package/src/module.ts +11 -11
- package/src/options/INestiaTransformOptions.ts +6 -6
- package/src/options/INestiaTransformProject.ts +7 -7
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IResponseBodyStringifier.ts +25 -25
- package/src/transform.ts +20 -20
- package/src/transformers/BodyTransformer.ts +106 -106
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/MethodTransformer.ts +91 -91
- package/src/transformers/NodeTransformer.ts +18 -18
- package/src/transformers/ParameterTransformer.ts +45 -45
- package/src/transformers/RouteTransformer.ts +131 -131
- package/src/typings/Creator.ts +3 -3
- package/src/utils/ExceptionManager.ts +126 -126
- package/src/utils/Singleton.ts +20 -20
|
@@ -0,0 +1,259 @@
|
|
|
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 __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
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;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.CoreSetupWizard = void 0;
|
|
66
|
+
var child_process_1 = __importDefault(require("child_process"));
|
|
67
|
+
var fs_1 = __importDefault(require("fs"));
|
|
68
|
+
var CoreSetupWizard;
|
|
69
|
+
(function (CoreSetupWizard) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
function ttypescript(manager) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var pack;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0: return [4 /*yield*/, prepare(manager)];
|
|
77
|
+
case 1:
|
|
78
|
+
pack = _a.sent();
|
|
79
|
+
add(manager)(pack)("ttypescript", true);
|
|
80
|
+
add(manager)(pack)("ts-node", true);
|
|
81
|
+
// TSCONFIG.JSON
|
|
82
|
+
return [4 /*yield*/, configure(manager)(pack)];
|
|
83
|
+
case 2:
|
|
84
|
+
// TSCONFIG.JSON
|
|
85
|
+
_a.sent();
|
|
86
|
+
return [2 /*return*/];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
CoreSetupWizard.ttypescript = ttypescript;
|
|
92
|
+
function tsPatch(manager) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var _a, pack, _b, _c;
|
|
95
|
+
return __generator(this, function (_d) {
|
|
96
|
+
switch (_d.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
// INSTALL
|
|
99
|
+
_a = add(manager);
|
|
100
|
+
return [4 /*yield*/, prepare(manager)];
|
|
101
|
+
case 1:
|
|
102
|
+
// INSTALL
|
|
103
|
+
_a.apply(void 0, [_d.sent()])("ts-patch", true);
|
|
104
|
+
execute("npx ts-patch install");
|
|
105
|
+
_c = (_b = JSON).parse;
|
|
106
|
+
return [4 /*yield*/, fs_1.default.promises.readFile("package.json", "utf8")];
|
|
107
|
+
case 2:
|
|
108
|
+
pack = _c.apply(_b, [_d.sent()]);
|
|
109
|
+
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
110
|
+
pack.scripts = {};
|
|
111
|
+
if (typeof pack.scripts.prepare === "string") {
|
|
112
|
+
if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
113
|
+
pack.scripts.prepare =
|
|
114
|
+
"ts-patch install && " + pack.scripts.prepare;
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
pack.scripts.prepare = "ts-patch install";
|
|
118
|
+
return [4 /*yield*/, fs_1.default.promises.writeFile("package.json", JSON.stringify(pack, null, 2), "utf8")];
|
|
119
|
+
case 3:
|
|
120
|
+
_d.sent();
|
|
121
|
+
// TSCONFIG.JSON
|
|
122
|
+
return [4 /*yield*/, configure(manager)(pack)];
|
|
123
|
+
case 4:
|
|
124
|
+
// TSCONFIG.JSON
|
|
125
|
+
_d.sent();
|
|
126
|
+
return [2 /*return*/];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
CoreSetupWizard.tsPatch = tsPatch;
|
|
132
|
+
function prepare(manager) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var pack, _a, _b;
|
|
135
|
+
return __generator(this, function (_c) {
|
|
136
|
+
switch (_c.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
if (fs_1.default.existsSync("package.json") === false)
|
|
139
|
+
halt(function () { })("make package.json file or move to it.");
|
|
140
|
+
_b = (_a = JSON).parse;
|
|
141
|
+
return [4 /*yield*/, fs_1.default.promises.readFile("package.json", "utf8")];
|
|
142
|
+
case 1:
|
|
143
|
+
pack = _b.apply(_a, [_c.sent()]);
|
|
144
|
+
add(manager)(pack)("typescript", true);
|
|
145
|
+
add(manager)(pack)("typia", false);
|
|
146
|
+
add(manager)(pack)("@nestia/core", false);
|
|
147
|
+
return [2 /*return*/, pack];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
var configure = function (manager) {
|
|
153
|
+
return function (pack) { return __awaiter(_this, void 0, void 0, function () {
|
|
154
|
+
var temporary, halter, Comment, config, _a, _b, options, plugins, strict, core, typia;
|
|
155
|
+
return __generator(this, function (_c) {
|
|
156
|
+
var _d;
|
|
157
|
+
switch (_c.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
// VALIDATE PRERATATION
|
|
160
|
+
if (fs_1.default.existsSync("tsconfig.json") === false) {
|
|
161
|
+
execute("npx tsc --init");
|
|
162
|
+
if (fs_1.default.existsSync("tsconfig.json") === false)
|
|
163
|
+
halt(function () { })("tsconfig.json file does not exist.");
|
|
164
|
+
}
|
|
165
|
+
temporary = !fs_1.default.existsSync("node_modules/comment-json");
|
|
166
|
+
if (temporary === true)
|
|
167
|
+
add(manager)(pack)("comment-json", true);
|
|
168
|
+
halter = halt(function () {
|
|
169
|
+
if (temporary === true)
|
|
170
|
+
remove(manager)("comment-json", true);
|
|
171
|
+
});
|
|
172
|
+
return [4 /*yield*/, (_d = process.cwd() + "/node_modules/comment-json", Promise.resolve().then(function () { return __importStar(require(_d)); }))];
|
|
173
|
+
case 1:
|
|
174
|
+
Comment = _c.sent();
|
|
175
|
+
_b = (_a = Comment).parse;
|
|
176
|
+
return [4 /*yield*/, fs_1.default.promises.readFile("tsconfig.json", "utf8")];
|
|
177
|
+
case 2:
|
|
178
|
+
config = _b.apply(_a, [_c.sent()]);
|
|
179
|
+
options = config.compilerOptions;
|
|
180
|
+
if (options === undefined)
|
|
181
|
+
halter("tsconfig.json file does not have \"compilerOptions\" property.");
|
|
182
|
+
plugins = (function () {
|
|
183
|
+
var plugins = options.plugins;
|
|
184
|
+
if (plugins === undefined)
|
|
185
|
+
return (options.plugins = []);
|
|
186
|
+
else if (!Array.isArray(plugins))
|
|
187
|
+
halter("\"plugins\" property of tsconfig.json must be array type.");
|
|
188
|
+
return plugins;
|
|
189
|
+
})();
|
|
190
|
+
strict = options.strict === true;
|
|
191
|
+
core = plugins.find(function (p) {
|
|
192
|
+
return typeof p === "object" &&
|
|
193
|
+
p !== null &&
|
|
194
|
+
p.transform === "@nestia/core/lib/transform";
|
|
195
|
+
});
|
|
196
|
+
typia = plugins.find(function (p) {
|
|
197
|
+
return typeof p === "object" &&
|
|
198
|
+
p !== null &&
|
|
199
|
+
p.transform === "typia/lib/transform";
|
|
200
|
+
});
|
|
201
|
+
if (!(strict === true && core !== undefined && typia !== undefined)) return [3 /*break*/, 3];
|
|
202
|
+
console.log("you've been already configured the tsconfig.json file.");
|
|
203
|
+
return [3 /*break*/, 5];
|
|
204
|
+
case 3:
|
|
205
|
+
// DO CONFIGURE
|
|
206
|
+
options.strict = true;
|
|
207
|
+
if (core === undefined)
|
|
208
|
+
plugins.push({
|
|
209
|
+
transform: "@nestia/core/lib/transform",
|
|
210
|
+
});
|
|
211
|
+
if (!(typia === undefined)) return [3 /*break*/, 5];
|
|
212
|
+
return [4 /*yield*/, fs_1.default.promises.writeFile("tsconfig.json", Comment.stringify(config, null, 2))];
|
|
213
|
+
case 4:
|
|
214
|
+
_c.sent();
|
|
215
|
+
_c.label = 5;
|
|
216
|
+
case 5:
|
|
217
|
+
if (temporary === true)
|
|
218
|
+
remove(manager)("comment-json", false);
|
|
219
|
+
return [2 /*return*/];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}); };
|
|
223
|
+
};
|
|
224
|
+
})(CoreSetupWizard = exports.CoreSetupWizard || (exports.CoreSetupWizard = {}));
|
|
225
|
+
var add = function (manager) {
|
|
226
|
+
return function (pack) {
|
|
227
|
+
return function (modulo, devOnly) {
|
|
228
|
+
var exists = (devOnly === false
|
|
229
|
+
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
230
|
+
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
231
|
+
fs_1.default.existsSync("node_modules/" + modulo);
|
|
232
|
+
var middle = manager === "yarn"
|
|
233
|
+
? "add".concat(devOnly ? " -D" : "")
|
|
234
|
+
: "install ".concat(devOnly ? "--save-dev" : "--save");
|
|
235
|
+
if (exists === false)
|
|
236
|
+
execute("".concat(manager, " ").concat(middle, " ").concat(modulo));
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
var remove = function (manager) {
|
|
241
|
+
return function (modulo, devOnly) {
|
|
242
|
+
var middle = manager === "yarn"
|
|
243
|
+
? "remove".concat(devOnly ? " -D" : "")
|
|
244
|
+
: "uninstall ".concat(devOnly ? "--save-dev" : "--save");
|
|
245
|
+
execute("".concat(manager, " ").concat(middle, " ").concat(modulo));
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
var halt = function (closer) {
|
|
249
|
+
return function (desc) {
|
|
250
|
+
closer();
|
|
251
|
+
console.error(desc);
|
|
252
|
+
process.exit(-1);
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
function execute(command) {
|
|
256
|
+
console.log(command);
|
|
257
|
+
child_process_1.default.execSync(command, { stdio: "inherit" });
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=CoreSetupWizard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreSetupWizard.js","sourceRoot":"","sources":["../../../src/executable/internal/CoreSetupWizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA+B;AAE/B,0CAAoB;AAEpB,IAAiB,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AC,CAAC,CAAC,CAAC;IACrB,CAAC;AAJD,CAIC,CAAC;AAEN,SAAS,OAAO,CAAC,OAAe;IAC5B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,uBAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Super-fast validation decorators of NestJS",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"@nestia/core": "lib/executable/core.js"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "rimraf lib && tsc",
|
|
9
12
|
"build:test": "rimraf bin && ttsc -p test/tsconfig.json",
|
|
@@ -37,6 +40,7 @@
|
|
|
37
40
|
"@types/express": "^4.17.15",
|
|
38
41
|
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
39
42
|
"@typescript-eslint/parser": "^5.46.1",
|
|
43
|
+
"comment-json": "^4.2.3",
|
|
40
44
|
"eslint-plugin-deprecation": "^1.3.3",
|
|
41
45
|
"git-last-commit": "^1.0.1",
|
|
42
46
|
"rimraf": "^3.0.2",
|
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import { AesPkcs5, IEncryptionPassword } from "@nestia/fetcher";
|
|
2
|
-
import {
|
|
3
|
-
BadRequestException,
|
|
4
|
-
ExecutionContext,
|
|
5
|
-
createParamDecorator,
|
|
6
|
-
} from "@nestjs/common";
|
|
7
|
-
import type express from "express";
|
|
8
|
-
import raw from "raw-body";
|
|
9
|
-
import { assert, is, validate } from "typia";
|
|
10
|
-
|
|
11
|
-
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
12
|
-
import { Singleton } from "../utils/Singleton";
|
|
13
|
-
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
14
|
-
import { headers_to_object } from "./internal/headers_to_object";
|
|
15
|
-
import { validate_request_body } from "./internal/validate_request_body";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Encrypted body decorator.
|
|
19
|
-
*
|
|
20
|
-
* `EncryptedBody` is a decorator function getting JSON data from HTTP request who've
|
|
21
|
-
* been encrypted by AES-128/256 algorithm. Also, `EncyrptedBody` validates the JSON
|
|
22
|
-
* data type through
|
|
23
|
-
* [`typia.assert()`](https://github.com/samchon/typia#runtime-type-checkers)
|
|
24
|
-
* function and throws `BadRequestException` error (status code: 400), if the JSON
|
|
25
|
-
* data is not following the promised type.
|
|
26
|
-
*
|
|
27
|
-
* For reference, `EncryptedRoute` decrypts request body usnig those options.
|
|
28
|
-
*
|
|
29
|
-
* - AES-128/256
|
|
30
|
-
* - CBC mode
|
|
31
|
-
* - PKCS #5 Padding
|
|
32
|
-
* - Base64 Encoding
|
|
33
|
-
*
|
|
34
|
-
* @return Parameter decorator
|
|
35
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
-
*/
|
|
37
|
-
export function EncryptedBody<T>(validator?: IRequestBodyValidator<T>) {
|
|
38
|
-
const checker = validate_request_body("EncryptedBody")(validator);
|
|
39
|
-
return createParamDecorator(async function EncryptedBody(
|
|
40
|
-
_unknown: any,
|
|
41
|
-
ctx: ExecutionContext,
|
|
42
|
-
) {
|
|
43
|
-
const request: express.Request = ctx.switchToHttp().getRequest();
|
|
44
|
-
if (request.readable === false)
|
|
45
|
-
throw new BadRequestException(
|
|
46
|
-
"Request body is not the text/plain.",
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const param:
|
|
50
|
-
| IEncryptionPassword
|
|
51
|
-
| IEncryptionPassword.Closure
|
|
52
|
-
| undefined = Reflect.getMetadata(
|
|
53
|
-
ENCRYPTION_METADATA_KEY,
|
|
54
|
-
ctx.getClass(),
|
|
55
|
-
);
|
|
56
|
-
if (!param)
|
|
57
|
-
throw new Error(
|
|
58
|
-
"Error on EncryptedBody(): no encryption password is given.",
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
// GET BODY DATA
|
|
62
|
-
const headers: Singleton<Record<string, string>> = new Singleton(() =>
|
|
63
|
-
headers_to_object(request.headers),
|
|
64
|
-
);
|
|
65
|
-
const body: string = (await raw(request, "utf8")).trim();
|
|
66
|
-
const password: IEncryptionPassword =
|
|
67
|
-
typeof param === "function"
|
|
68
|
-
? param({ headers: headers.get(), body }, false)
|
|
69
|
-
: param;
|
|
70
|
-
const disabled: boolean =
|
|
71
|
-
password.disabled === undefined
|
|
72
|
-
? false
|
|
73
|
-
: typeof password.disabled === "function"
|
|
74
|
-
? password.disabled({ headers: headers.get(), body }, true)
|
|
75
|
-
: password.disabled;
|
|
76
|
-
|
|
77
|
-
// PARSE AND VALIDATE DATA
|
|
78
|
-
const data: any = JSON.parse(
|
|
79
|
-
disabled ? body : decrypt(body, password.key, password.iv),
|
|
80
|
-
);
|
|
81
|
-
checker(data);
|
|
82
|
-
return data;
|
|
83
|
-
})();
|
|
84
|
-
}
|
|
85
|
-
Object.assign(EncryptedBody, assert);
|
|
86
|
-
Object.assign(EncryptedBody, is);
|
|
87
|
-
Object.assign(EncryptedBody, validate);
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @internal
|
|
91
|
-
*/
|
|
92
|
-
function decrypt(body: string, key: string, iv: string): string {
|
|
93
|
-
try {
|
|
94
|
-
return AesPkcs5.decrypt(body, key, iv);
|
|
95
|
-
} catch (exp) {
|
|
96
|
-
if (exp instanceof Error)
|
|
97
|
-
throw new BadRequestException(
|
|
98
|
-
"Failed to decrypt the request body. Check your body content or encryption password.",
|
|
99
|
-
);
|
|
100
|
-
else throw exp;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
import { AesPkcs5, IEncryptionPassword } from "@nestia/fetcher";
|
|
2
|
+
import {
|
|
3
|
+
BadRequestException,
|
|
4
|
+
ExecutionContext,
|
|
5
|
+
createParamDecorator,
|
|
6
|
+
} from "@nestjs/common";
|
|
7
|
+
import type express from "express";
|
|
8
|
+
import raw from "raw-body";
|
|
9
|
+
import { assert, is, validate } from "typia";
|
|
10
|
+
|
|
11
|
+
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
|
|
12
|
+
import { Singleton } from "../utils/Singleton";
|
|
13
|
+
import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
|
|
14
|
+
import { headers_to_object } from "./internal/headers_to_object";
|
|
15
|
+
import { validate_request_body } from "./internal/validate_request_body";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Encrypted body decorator.
|
|
19
|
+
*
|
|
20
|
+
* `EncryptedBody` is a decorator function getting JSON data from HTTP request who've
|
|
21
|
+
* been encrypted by AES-128/256 algorithm. Also, `EncyrptedBody` validates the JSON
|
|
22
|
+
* data type through
|
|
23
|
+
* [`typia.assert()`](https://github.com/samchon/typia#runtime-type-checkers)
|
|
24
|
+
* function and throws `BadRequestException` error (status code: 400), if the JSON
|
|
25
|
+
* data is not following the promised type.
|
|
26
|
+
*
|
|
27
|
+
* For reference, `EncryptedRoute` decrypts request body usnig those options.
|
|
28
|
+
*
|
|
29
|
+
* - AES-128/256
|
|
30
|
+
* - CBC mode
|
|
31
|
+
* - PKCS #5 Padding
|
|
32
|
+
* - Base64 Encoding
|
|
33
|
+
*
|
|
34
|
+
* @return Parameter decorator
|
|
35
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
*/
|
|
37
|
+
export function EncryptedBody<T>(validator?: IRequestBodyValidator<T>) {
|
|
38
|
+
const checker = validate_request_body("EncryptedBody")(validator);
|
|
39
|
+
return createParamDecorator(async function EncryptedBody(
|
|
40
|
+
_unknown: any,
|
|
41
|
+
ctx: ExecutionContext,
|
|
42
|
+
) {
|
|
43
|
+
const request: express.Request = ctx.switchToHttp().getRequest();
|
|
44
|
+
if (request.readable === false)
|
|
45
|
+
throw new BadRequestException(
|
|
46
|
+
"Request body is not the text/plain.",
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const param:
|
|
50
|
+
| IEncryptionPassword
|
|
51
|
+
| IEncryptionPassword.Closure
|
|
52
|
+
| undefined = Reflect.getMetadata(
|
|
53
|
+
ENCRYPTION_METADATA_KEY,
|
|
54
|
+
ctx.getClass(),
|
|
55
|
+
);
|
|
56
|
+
if (!param)
|
|
57
|
+
throw new Error(
|
|
58
|
+
"Error on EncryptedBody(): no encryption password is given.",
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// GET BODY DATA
|
|
62
|
+
const headers: Singleton<Record<string, string>> = new Singleton(() =>
|
|
63
|
+
headers_to_object(request.headers),
|
|
64
|
+
);
|
|
65
|
+
const body: string = (await raw(request, "utf8")).trim();
|
|
66
|
+
const password: IEncryptionPassword =
|
|
67
|
+
typeof param === "function"
|
|
68
|
+
? param({ headers: headers.get(), body }, false)
|
|
69
|
+
: param;
|
|
70
|
+
const disabled: boolean =
|
|
71
|
+
password.disabled === undefined
|
|
72
|
+
? false
|
|
73
|
+
: typeof password.disabled === "function"
|
|
74
|
+
? password.disabled({ headers: headers.get(), body }, true)
|
|
75
|
+
: password.disabled;
|
|
76
|
+
|
|
77
|
+
// PARSE AND VALIDATE DATA
|
|
78
|
+
const data: any = JSON.parse(
|
|
79
|
+
disabled ? body : decrypt(body, password.key, password.iv),
|
|
80
|
+
);
|
|
81
|
+
checker(data);
|
|
82
|
+
return data;
|
|
83
|
+
})();
|
|
84
|
+
}
|
|
85
|
+
Object.assign(EncryptedBody, assert);
|
|
86
|
+
Object.assign(EncryptedBody, is);
|
|
87
|
+
Object.assign(EncryptedBody, validate);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
function decrypt(body: string, key: string, iv: string): string {
|
|
93
|
+
try {
|
|
94
|
+
return AesPkcs5.decrypt(body, key, iv);
|
|
95
|
+
} catch (exp) {
|
|
96
|
+
if (exp instanceof Error)
|
|
97
|
+
throw new BadRequestException(
|
|
98
|
+
"Failed to decrypt the request body. Check your body content or encryption password.",
|
|
99
|
+
);
|
|
100
|
+
else throw exp;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { IEncryptionPassword } from "@nestia/fetcher";
|
|
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
|
-
* > 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
|
-
export function EncryptedController(
|
|
36
|
-
path: string,
|
|
37
|
-
password: IEncryptionPassword | IEncryptionPassword.Closure,
|
|
38
|
-
): ClassDecorator {
|
|
39
|
-
return function (target: any) {
|
|
40
|
-
Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, target);
|
|
41
|
-
Controller(path)(target);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
1
|
+
import { IEncryptionPassword } from "@nestia/fetcher";
|
|
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
|
+
* > 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
|
+
export function EncryptedController(
|
|
36
|
+
path: string,
|
|
37
|
+
password: IEncryptionPassword | IEncryptionPassword.Closure,
|
|
38
|
+
): ClassDecorator {
|
|
39
|
+
return function (target: any) {
|
|
40
|
+
Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, target);
|
|
41
|
+
Controller(path)(target);
|
|
42
|
+
};
|
|
43
|
+
}
|