express-generator-typescript 2.1.4 → 2.1.5
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.
|
@@ -91,23 +91,24 @@ export async function adminMw(
|
|
|
91
91
|
* Sample argument: ['id', 'number'], id is the incoming variable, 'number'
|
|
92
92
|
* is the type, and body is where to extract 'id' from.
|
|
93
93
|
*
|
|
94
|
-
* Example 1:
|
|
94
|
+
* Example 1: validate('email', ['user', 'object'], ['id', 'number', 'params'])
|
|
95
95
|
* will check that 'email' is a string in req.body, that user is of type
|
|
96
96
|
* object in req.body, and that 'id' is a boolean in req.params.
|
|
97
|
-
* Example 2:
|
|
97
|
+
* Example 2: validate('password') will check that 'password' is a string on
|
|
98
98
|
* req.body.
|
|
99
|
-
* Example 3:
|
|
99
|
+
* Example 3: validate(['isAdmin', 'boolean']) will check that 'isAdmin' is a
|
|
100
100
|
* boolean on req.body
|
|
101
|
-
* Example 4:
|
|
101
|
+
* Example 4: validate(['user', isInstanceOfUser]) will check that 'user'
|
|
102
102
|
* satifies the 'isInstanceOfUser()' function.
|
|
103
|
-
* Example 5:
|
|
103
|
+
* Example 5: validate(['email']) will check that 'email' is a string in
|
|
104
|
+
* req.body,
|
|
104
105
|
*/
|
|
105
106
|
export function validate(...params: Array<string | TParamArr>): RequestHandler {
|
|
106
107
|
return (req: Request, _: Response, next: NextFunction) => {
|
|
107
108
|
for (const param of params) {
|
|
108
109
|
// Check params
|
|
109
110
|
if (typeof param !== 'string' && !(param instanceof Array)) {
|
|
110
|
-
throw Error('
|
|
111
|
+
throw Error('"validate()" arg must be a string or array');
|
|
111
112
|
}
|
|
112
113
|
// If param is a string, make sure param is of type string on req.body
|
|
113
114
|
if (typeof param === 'string') {
|
|
@@ -140,6 +141,8 @@ export function validate(...params: Array<string | TParamArr>): RequestHandler {
|
|
|
140
141
|
const fn = param[1];
|
|
141
142
|
if (!fn(toValidate)) {
|
|
142
143
|
throw new ValidatorFnError(fn.name);
|
|
144
|
+
} else {
|
|
145
|
+
continue;
|
|
143
146
|
}
|
|
144
147
|
// If type is a number, see note above.
|
|
145
148
|
} else if (param[1] === 'number') {
|
|
@@ -31,7 +31,7 @@ function sign(data: string | object | Buffer): Promise<string> {
|
|
|
31
31
|
/**
|
|
32
32
|
* Decrypt JWT and extract client data.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
function decode<T>(jwt: string): Promise<string | undefined | T> {
|
|
35
35
|
return new Promise((res, rej) => {
|
|
36
36
|
jsonwebtoken.verify(jwt, envVars.jwt.secret, (err, decoded) => {
|
|
37
37
|
return err ? rej(errors.validation) : res(decoded as T);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"express-generator-typescript": "node bin/cli.js",
|