express-generator-typescript 2.2.1 → 2.2.3
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/project-files/package.json +1 -8
- package/lib/project-files/spec/support/login-agent.ts +3 -3
- package/lib/project-files/spec/tests/auth.spec.ts +8 -8
- package/lib/project-files/spec/tests/users.spec.ts +7 -7
- package/lib/project-files/spec/types/supertest/index.d.ts +1 -1
- package/lib/project-files/src/declarations/classes.ts +1 -1
- package/lib/project-files/src/declarations/functions.ts +11 -1
- package/lib/project-files/src/declarations/types.ts +3 -25
- package/lib/project-files/src/index.ts +1 -1
- package/lib/project-files/src/models/User.ts +1 -1
- package/lib/project-files/src/repos/mock-orm.ts +1 -1
- package/lib/project-files/src/repos/user-repo.ts +2 -2
- package/lib/project-files/src/routes/api.ts +1 -1
- package/lib/project-files/src/routes/auth-routes.ts +4 -4
- package/lib/project-files/src/routes/middlware/adminMw.ts +4 -4
- package/lib/project-files/src/routes/middlware/validate.ts +2 -2
- package/lib/project-files/src/routes/shared/types.ts +22 -0
- package/lib/project-files/src/routes/user-routes.ts +4 -4
- package/lib/project-files/src/server.ts +4 -4
- package/lib/project-files/src/services/auth-service.ts +8 -5
- package/lib/project-files/src/services/user-service.ts +4 -4
- package/lib/project-files/tsconfig.json +2 -23
- package/package.json +1 -1
|
@@ -21,14 +21,7 @@
|
|
|
21
21
|
"exec": "./node_modules/.bin/ts-node --files -r tsconfig-paths/register ./src"
|
|
22
22
|
},
|
|
23
23
|
"_moduleAliases": {
|
|
24
|
-
"@
|
|
25
|
-
"@repos": "dist/repos",
|
|
26
|
-
"@models": "dist/models",
|
|
27
|
-
"@configurations": "dist/configurations",
|
|
28
|
-
"@declarations": "dist/declarations",
|
|
29
|
-
"@server": "dist/server",
|
|
30
|
-
"@routes": "dist/routes",
|
|
31
|
-
"@util": "dist/util"
|
|
24
|
+
"@src": "dist"
|
|
32
25
|
},
|
|
33
26
|
"engines": {
|
|
34
27
|
"node": ">=8.10.0"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SuperTest, Test, Response } from 'supertest';
|
|
2
2
|
|
|
3
|
-
import User, { UserRoles } from '@models/User';
|
|
4
|
-
import userRepo from '@repos/user-repo';
|
|
5
|
-
import pwdUtil from '@util/pwd-util';
|
|
3
|
+
import User, { UserRoles } from '@src/models/User';
|
|
4
|
+
import userRepo from '@src/repos/user-repo';
|
|
5
|
+
import pwdUtil from '@src/util/pwd-util';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// **** Variables **** //
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import supertest, { SuperTest, Test, Response } from 'supertest';
|
|
2
2
|
import logger from 'jet-logger';
|
|
3
3
|
|
|
4
|
-
import app from '@server';
|
|
5
|
-
import authRoutes from '@routes/auth-routes';
|
|
6
|
-
import userRepo from '@repos/user-repo';
|
|
7
|
-
import pwdUtil from '@util/pwd-util';
|
|
8
|
-
import EnvVars from '@configurations/EnvVars';
|
|
9
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
10
|
-
import User, { UserRoles } from '@models/User';
|
|
11
|
-
import { errors as authServiceErrs } from '@services/auth-service';
|
|
4
|
+
import app from '@src/server';
|
|
5
|
+
import authRoutes from '@src/routes/auth-routes';
|
|
6
|
+
import userRepo from '@src/repos/user-repo';
|
|
7
|
+
import pwdUtil from '@src/util/pwd-util';
|
|
8
|
+
import EnvVars from '@src/configurations/EnvVars';
|
|
9
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
10
|
+
import User, { UserRoles } from '@src/models/User';
|
|
11
|
+
import { errors as authServiceErrs } from '@src/services/auth-service';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
// **** Variables **** //
|
|
@@ -2,14 +2,14 @@ import supertest from 'supertest';
|
|
|
2
2
|
import { SuperTest, Test, Response } from 'supertest';
|
|
3
3
|
import logger from 'jet-logger';
|
|
4
4
|
|
|
5
|
-
import app from '@server';
|
|
6
|
-
import userRepo from '@repos/user-repo';
|
|
7
|
-
import User, { IUser } from '@models/User';
|
|
8
|
-
import userRoutes from '@routes/user-routes';
|
|
9
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
5
|
+
import app from '@src/server';
|
|
6
|
+
import userRepo from '@src/repos/user-repo';
|
|
7
|
+
import User, { IUser } from '@src/models/User';
|
|
8
|
+
import userRoutes from '@src/routes/user-routes';
|
|
9
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
10
10
|
import loginAgent from '../support/login-agent';
|
|
11
|
-
import { paramInvalidErr } from '@routes/middlware/validate';
|
|
12
|
-
import { userNotFoundErr } from '@services/user-service';
|
|
11
|
+
import { paramInvalidErr } from '@src/routes/middlware/validate';
|
|
12
|
+
import { userNotFoundErr } from '@src/services/user-service';
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
// **** Variables **** //
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Get a random number between 1 and 1,000,000,000,000
|
|
4
3
|
*/
|
|
5
4
|
export function getRandomInt(): number {
|
|
6
5
|
return Math.floor(Math.random() * 1_000_000_000_000);
|
|
7
6
|
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wait for a certain number of milliseconds.
|
|
10
|
+
*/
|
|
11
|
+
export function tick(milliseconds: number): Promise<void> {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
resolve();
|
|
15
|
+
}, milliseconds);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { ISessionUser } from '@routes/middlware/adminMw';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// **** Misc **** //
|
|
1
|
+
/**
|
|
2
|
+
* Place types shared throughout the application here.
|
|
3
|
+
*/
|
|
8
4
|
|
|
9
5
|
export type TAll = string | number | boolean | null | object;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// **** Express **** //
|
|
13
|
-
|
|
14
|
-
export interface IReq<T = void> extends e.Request {
|
|
15
|
-
body: T;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IReqQuery<T extends Query, U = void> extends e.Request {
|
|
19
|
-
query: T;
|
|
20
|
-
body: U;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface IRes extends e.Response {
|
|
24
|
-
locals: {
|
|
25
|
-
sessionUser: ISessionUser;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
@@ -2,7 +2,7 @@ import { Router } from 'express';
|
|
|
2
2
|
|
|
3
3
|
import adminMw from './middlware/adminMw';
|
|
4
4
|
import validate from './middlware/validate';
|
|
5
|
-
import User from '@models/User';
|
|
5
|
+
import User from '@src/models/User';
|
|
6
6
|
import authRoutes from './auth-routes';
|
|
7
7
|
import userRoutes from './user-routes';
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
1
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
2
2
|
|
|
3
|
-
import authService from '@services/auth-service';
|
|
4
|
-
import EnvVars from '@configurations/EnvVars';
|
|
5
|
-
import { IReq, IRes } from '
|
|
3
|
+
import authService from '@src/services/auth-service';
|
|
4
|
+
import EnvVars from '@src/configurations/EnvVars';
|
|
5
|
+
import { IReq, IRes } from './shared/types';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// **** Types **** //
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
import { Request, Response, NextFunction } from 'express';
|
|
6
6
|
import { JwtPayload } from 'jsonwebtoken';
|
|
7
7
|
|
|
8
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
9
|
-
import EnvVars from '@configurations/EnvVars';
|
|
10
|
-
import jwtUtil from '@util/jwt-util';
|
|
11
|
-
import { IUser, UserRoles } from '@models/User';
|
|
8
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
9
|
+
import EnvVars from '@src/configurations/EnvVars';
|
|
10
|
+
import jwtUtil from '@src/util/jwt-util';
|
|
11
|
+
import { IUser, UserRoles } from '@src/models/User';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
// **** Variables **** //
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
|
|
37
37
|
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
|
38
38
|
|
|
39
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
40
|
-
import { TAll } from '@declarations/types';
|
|
39
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
40
|
+
import { TAll } from '@src/declarations/types';
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
// **** Variables **** //
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as e from 'express';
|
|
2
|
+
import { Query } from 'express-serve-static-core';
|
|
3
|
+
|
|
4
|
+
import { ISessionUser } from '@src/routes/middlware/adminMw';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// **** Express **** //
|
|
8
|
+
|
|
9
|
+
export interface IReq<T = void> extends e.Request {
|
|
10
|
+
body: T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IReqQuery<T extends Query, U = void> extends e.Request {
|
|
14
|
+
query: T;
|
|
15
|
+
body: U;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IRes extends e.Response {
|
|
19
|
+
locals: {
|
|
20
|
+
sessionUser: ISessionUser;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
1
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
2
2
|
|
|
3
|
-
import userService from '@services/user-service';
|
|
4
|
-
import { IUser } from '@models/User';
|
|
5
|
-
import { IReq, IRes } from '
|
|
3
|
+
import userService from '@src/services/user-service';
|
|
4
|
+
import { IUser } from '@src/models/User';
|
|
5
|
+
import { IReq, IRes } from './shared/types';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// **** Variables **** //
|
|
@@ -8,10 +8,10 @@ import 'express-async-errors';
|
|
|
8
8
|
|
|
9
9
|
import BaseRouter from './routes/api';
|
|
10
10
|
import logger from 'jet-logger';
|
|
11
|
-
import EnvVars from '@configurations/EnvVars';
|
|
12
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
13
|
-
import { NodeEnvs } from '@declarations/enums';
|
|
14
|
-
import { RouteError } from '@declarations/classes';
|
|
11
|
+
import EnvVars from '@src/configurations/EnvVars';
|
|
12
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
13
|
+
import { NodeEnvs } from '@src/declarations/enums';
|
|
14
|
+
import { RouteError } from '@src/declarations/classes';
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
// **** Init express **** //
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import userRepo from '@repos/user-repo';
|
|
2
|
-
import jwtUtil from '@util/jwt-util';
|
|
3
|
-
import pwdUtil from '@util/pwd-util';
|
|
4
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
5
|
-
import { RouteError } from '@declarations/classes';
|
|
1
|
+
import userRepo from '@src/repos/user-repo';
|
|
2
|
+
import jwtUtil from '@src/util/jwt-util';
|
|
3
|
+
import pwdUtil from '@src/util/pwd-util';
|
|
4
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
5
|
+
import { RouteError } from '@src/declarations/classes';
|
|
6
|
+
import { tick } from '@src/declarations/functions';
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
// **** Variables **** //
|
|
@@ -32,6 +33,8 @@ async function getJwt(email: string, password: string): Promise<string> {
|
|
|
32
33
|
const hash = (user.pwdHash ?? '');
|
|
33
34
|
const pwdPassed = await pwdUtil.compare(password, hash);
|
|
34
35
|
if (!pwdPassed) {
|
|
36
|
+
// If password failed, wait 500ms this will increase security
|
|
37
|
+
await tick(500);
|
|
35
38
|
throw new RouteError(
|
|
36
39
|
HttpStatusCodes.UNAUTHORIZED,
|
|
37
40
|
errors.unauth,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import userRepo from '@repos/user-repo';
|
|
2
|
-
import { IUser } from '@models/User';
|
|
3
|
-
import { RouteError } from '@declarations/classes';
|
|
4
|
-
import HttpStatusCodes from '@configurations/HttpStatusCodes';
|
|
1
|
+
import userRepo from '@src/repos/user-repo';
|
|
2
|
+
import { IUser } from '@src/models/User';
|
|
3
|
+
import { RouteError } from '@src/declarations/classes';
|
|
4
|
+
import HttpStatusCodes from '@src/configurations/HttpStatusCodes';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
// **** Variables **** //
|
|
@@ -66,30 +66,9 @@
|
|
|
66
66
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
67
67
|
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
|
68
68
|
"paths": {
|
|
69
|
-
"@
|
|
70
|
-
"src
|
|
69
|
+
"@src/*": [
|
|
70
|
+
"src/*"
|
|
71
71
|
],
|
|
72
|
-
"@models/*": [
|
|
73
|
-
"src/models/*"
|
|
74
|
-
],
|
|
75
|
-
"@declarations/*": [
|
|
76
|
-
"src/declarations/*"
|
|
77
|
-
],
|
|
78
|
-
"@configurations/*": [
|
|
79
|
-
"src/configurations/*"
|
|
80
|
-
],
|
|
81
|
-
"@server": [
|
|
82
|
-
"src/server"
|
|
83
|
-
],
|
|
84
|
-
"@services/*": [
|
|
85
|
-
"src/services/*"
|
|
86
|
-
],
|
|
87
|
-
"@routes/*": [
|
|
88
|
-
"src/routes/*"
|
|
89
|
-
],
|
|
90
|
-
"@util/*": [
|
|
91
|
-
"src/util/*"
|
|
92
|
-
]
|
|
93
72
|
},
|
|
94
73
|
"useUnknownInCatchVariables": false
|
|
95
74
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
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",
|