express-generator-typescript 2.4.8 → 2.4.11
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/spec/support/Paths.ts +1 -1
- package/lib/project-files/spec/tests/users.spec.ts +1 -1
- package/lib/project-files/src/{other/classes.ts → common/RouteError.ts} +7 -6
- package/lib/project-files/src/index.ts +1 -1
- package/lib/project-files/src/routes/UserRoutes.ts +1 -1
- package/lib/project-files/src/routes/{api.ts → index.ts} +1 -1
- package/lib/project-files/src/server.ts +7 -8
- package/lib/project-files/src/services/UserService.ts +3 -2
- package/lib/project-files-auth/spec/support/Paths.ts +1 -1
- package/lib/project-files-auth/spec/tests/auth.spec.ts +2 -2
- package/lib/project-files-auth/spec/tests/users.spec.ts +6 -6
- package/lib/project-files-auth/src/{other/classes.ts → common/RouteError.ts} +7 -6
- package/lib/project-files-auth/src/index.ts +1 -1
- package/lib/project-files-auth/src/public/scripts/users.js +6 -0
- package/lib/project-files-auth/src/routes/AuthRoutes.ts +1 -1
- package/lib/project-files-auth/src/routes/UserRoutes.ts +1 -1
- package/lib/project-files-auth/src/routes/{api.ts → index.ts} +4 -3
- package/lib/project-files-auth/src/routes/middleware/adminMw.ts +1 -1
- package/lib/project-files-auth/src/server.ts +6 -6
- package/lib/project-files-auth/src/services/AuthService.ts +3 -2
- package/lib/project-files-auth/src/services/UserService.ts +3 -4
- package/lib/project-files-auth/src/util/SessionUtil.ts +25 -23
- package/package.json +1 -1
- /package/lib/project-files/src/{constants → common}/EnvVars.ts +0 -0
- /package/lib/project-files/src/{constants → common}/HttpStatusCodes.ts +0 -0
- /package/lib/project-files/src/{constants → common}/Paths.ts +0 -0
- /package/lib/project-files/src/{constants → common}/misc.ts +0 -0
- /package/lib/project-files-auth/src/{constants → common}/EnvVars.ts +0 -0
- /package/lib/project-files-auth/src/{constants → common}/HttpStatusCodes.ts +0 -0
- /package/lib/project-files-auth/src/{constants → common}/Paths.ts +0 -0
- /package/lib/project-files-auth/src/{constants → common}/misc.ts +0 -0
|
@@ -7,7 +7,7 @@ import app from '@src/server';
|
|
|
7
7
|
|
|
8
8
|
import UserRepo from '@src/repos/UserRepo';
|
|
9
9
|
import User, { IUser } from '@src/models/User';
|
|
10
|
-
import HttpStatusCodes from '@src/
|
|
10
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
11
11
|
import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
|
|
12
12
|
|
|
13
13
|
import Paths from 'spec/support/Paths';
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* Miscellaneous shared classes go here.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
1
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
6
2
|
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* Error with status code and message
|
|
10
6
|
*/
|
|
11
|
-
|
|
7
|
+
class RouteError extends Error {
|
|
12
8
|
|
|
13
9
|
public status: HttpStatusCodes;
|
|
14
10
|
|
|
@@ -17,3 +13,8 @@ export class RouteError extends Error {
|
|
|
17
13
|
this.status = status;
|
|
18
14
|
}
|
|
19
15
|
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// **** Export default **** //
|
|
19
|
+
|
|
20
|
+
export default RouteError;
|
|
@@ -11,14 +11,13 @@ import logger from 'jet-logger';
|
|
|
11
11
|
|
|
12
12
|
import 'express-async-errors';
|
|
13
13
|
|
|
14
|
-
import BaseRouter from '@src/routes
|
|
15
|
-
import Paths from '@src/constants/Paths';
|
|
14
|
+
import BaseRouter from '@src/routes';
|
|
16
15
|
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
import {
|
|
16
|
+
import Paths from '@src/common/Paths';
|
|
17
|
+
import EnvVars from '@src/common/EnvVars';
|
|
18
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
19
|
+
import RouteError from '@src/common/RouteError';
|
|
20
|
+
import { NodeEnvs } from '@src/common/misc';
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
// **** Variables **** //
|
|
@@ -65,7 +64,7 @@ app.use((
|
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
|
|
68
|
-
//
|
|
67
|
+
// **** Front-End Content **** //
|
|
69
68
|
|
|
70
69
|
// Set views directory (html)
|
|
71
70
|
const viewsDir = path.join(__dirname, 'views');
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import RouteError from '@src/common/RouteError';
|
|
2
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
3
|
+
|
|
1
4
|
import UserRepo from '@src/repos/UserRepo';
|
|
2
5
|
import { IUser } from '@src/models/User';
|
|
3
|
-
import { RouteError } from '@src/other/classes';
|
|
4
|
-
import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
// **** Variables **** //
|
|
@@ -8,8 +8,8 @@ import PwdUtil from '@src/util/PwdUtil';
|
|
|
8
8
|
import User, { UserRoles } from '@src/models/User';
|
|
9
9
|
import { Errors } from '@src/services/AuthService';
|
|
10
10
|
|
|
11
|
-
import EnvVars from '@src/
|
|
12
|
-
import HttpStatusCodes from '@src/
|
|
11
|
+
import EnvVars from '@src/common/EnvVars';
|
|
12
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
13
13
|
|
|
14
14
|
import Paths from 'spec/support/Paths';
|
|
15
15
|
import apiCb from 'spec/support/apiCb';
|
|
@@ -7,7 +7,7 @@ import app from '@src/server';
|
|
|
7
7
|
|
|
8
8
|
import UserRepo from '@src/repos/UserRepo';
|
|
9
9
|
import User, { IUser } from '@src/models/User';
|
|
10
|
-
import HttpStatusCodes from '@src/
|
|
10
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
11
11
|
import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
|
|
12
12
|
|
|
13
13
|
import Paths from 'spec/support/Paths';
|
|
@@ -51,7 +51,7 @@ describe('UserRouter', () => {
|
|
|
51
51
|
|
|
52
52
|
// Success
|
|
53
53
|
it('should return a JSON object with all the users and a status code ' +
|
|
54
|
-
`of "${HttpStatusCodes.OK}" if the request was successful.`,
|
|
54
|
+
`of "${HttpStatusCodes.OK}" if the request was successful.`, done => {
|
|
55
55
|
// Add spy
|
|
56
56
|
const data = getDummyUsers();
|
|
57
57
|
spyOn(UserRepo, 'getAll').and.resolveTo(data);
|
|
@@ -79,7 +79,7 @@ describe('UserRouter', () => {
|
|
|
79
79
|
|
|
80
80
|
// Test add user success
|
|
81
81
|
it(`should return a status code of "${HttpStatusCodes.CREATED}" if the ` +
|
|
82
|
-
'request was successful.',
|
|
82
|
+
'request was successful.', done => {
|
|
83
83
|
// Spy
|
|
84
84
|
spyOn(UserRepo, 'add').and.resolveTo();
|
|
85
85
|
// Call api
|
|
@@ -92,7 +92,7 @@ describe('UserRouter', () => {
|
|
|
92
92
|
// Missing param
|
|
93
93
|
it(`should return a JSON object with an error message of "${ERROR_MSG}" ` +
|
|
94
94
|
`and a status code of "${HttpStatusCodes.BAD_REQUEST}" if the user ` +
|
|
95
|
-
'param was missing.',
|
|
95
|
+
'param was missing.', done => {
|
|
96
96
|
// Call api
|
|
97
97
|
callApi(null, res => {
|
|
98
98
|
expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
|
|
@@ -117,7 +117,7 @@ describe('UserRouter', () => {
|
|
|
117
117
|
|
|
118
118
|
// Success
|
|
119
119
|
it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
|
|
120
|
-
'request was successful.',
|
|
120
|
+
'request was successful.', done => {
|
|
121
121
|
// Setup spies
|
|
122
122
|
spyOn(UserRepo, 'update').and.resolveTo();
|
|
123
123
|
spyOn(UserRepo, 'persists').and.resolveTo(true);
|
|
@@ -131,7 +131,7 @@ describe('UserRouter', () => {
|
|
|
131
131
|
// Param missing
|
|
132
132
|
it(`should return a JSON object with an error message of "${ERROR_MSG}" ` +
|
|
133
133
|
`and a status code of "${HttpStatusCodes.BAD_REQUEST}" if the user ` +
|
|
134
|
-
'param was missing.',
|
|
134
|
+
'param was missing.', done => {
|
|
135
135
|
// Call api
|
|
136
136
|
callApi(null, res => {
|
|
137
137
|
expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
* Miscellaneous shared classes go here.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
1
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
6
2
|
|
|
7
3
|
|
|
8
4
|
/**
|
|
9
5
|
* Error with status code and message
|
|
10
6
|
*/
|
|
11
|
-
|
|
7
|
+
class RouteError extends Error {
|
|
12
8
|
|
|
13
9
|
public status: HttpStatusCodes;
|
|
14
10
|
|
|
@@ -17,3 +13,8 @@ export class RouteError extends Error {
|
|
|
17
13
|
this.status = status;
|
|
18
14
|
}
|
|
19
15
|
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// **** Export default **** //
|
|
19
|
+
|
|
20
|
+
export default RouteError;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import jetValidator from 'jet-validator';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import Paths from '../constants/Paths';
|
|
4
|
+
import Paths from '@src/common/Paths';
|
|
6
5
|
import User from '@src/models/User';
|
|
6
|
+
|
|
7
|
+
import adminMw from './middleware/adminMw';
|
|
7
8
|
import AuthRoutes from './AuthRoutes';
|
|
8
9
|
import UserRoutes from './UserRoutes';
|
|
9
10
|
|
|
@@ -14,7 +15,7 @@ const apiRouter = Router(),
|
|
|
14
15
|
validate = jetValidator();
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
// ****
|
|
18
|
+
// **** Add AuthRouter **** //
|
|
18
19
|
|
|
19
20
|
const authRouter = Router();
|
|
20
21
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Request, Response, NextFunction } from 'express';
|
|
6
6
|
import { JwtPayload } from 'jsonwebtoken';
|
|
7
7
|
|
|
8
|
-
import HttpStatusCodes from '@src/
|
|
8
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
9
9
|
|
|
10
10
|
import SessionUtil from '@src/util/SessionUtil';
|
|
11
11
|
import { ISessionUser, UserRoles } from '@src/models/User';
|
|
@@ -11,14 +11,14 @@ import logger from 'jet-logger';
|
|
|
11
11
|
|
|
12
12
|
import 'express-async-errors';
|
|
13
13
|
|
|
14
|
-
import BaseRouter from '@src/routes
|
|
15
|
-
import Paths from '@src/constants/Paths';
|
|
14
|
+
import BaseRouter from '@src/routes';
|
|
16
15
|
|
|
17
|
-
import
|
|
18
|
-
import
|
|
16
|
+
import Paths from '@src/common/Paths';
|
|
17
|
+
import EnvVars from '@src/common/EnvVars';
|
|
18
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
19
|
+
import { NodeEnvs } from '@src/common/misc';
|
|
19
20
|
|
|
20
|
-
import
|
|
21
|
-
import { RouteError } from '@src/other/classes';
|
|
21
|
+
import RouteError from '@src/common/RouteError';
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
// **** Variables **** //
|
|
@@ -3,8 +3,9 @@ import UserRepo from '@src/repos/UserRepo';
|
|
|
3
3
|
import PwdUtil from '@src/util/PwdUtil';
|
|
4
4
|
import { tick } from '@src/util/misc';
|
|
5
5
|
|
|
6
|
-
import HttpStatusCodes from '@src/
|
|
7
|
-
import
|
|
6
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
7
|
+
import RouteError from '@src/common/RouteError';
|
|
8
|
+
|
|
8
9
|
import { IUser } from '@src/models/User';
|
|
9
10
|
|
|
10
11
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import RouteError from '@src/common/RouteError';
|
|
2
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
3
|
+
|
|
1
4
|
import UserRepo from '@src/repos/UserRepo';
|
|
2
5
|
import { IUser } from '@src/models/User';
|
|
3
|
-
import { RouteError } from '@src/other/classes';
|
|
4
|
-
import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
// **** Variables **** //
|
|
@@ -33,7 +34,6 @@ async function updateOne(user: IUser): Promise<void> {
|
|
|
33
34
|
if (!persists) {
|
|
34
35
|
throw new RouteError(HttpStatusCodes.NOT_FOUND, USER_NOT_FOUND_ERR);
|
|
35
36
|
}
|
|
36
|
-
// Return user
|
|
37
37
|
return UserRepo.update(user);
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -45,7 +45,6 @@ async function _delete(id: number): Promise<void> {
|
|
|
45
45
|
if (!persists) {
|
|
46
46
|
throw new RouteError(HttpStatusCodes.NOT_FOUND, USER_NOT_FOUND_ERR);
|
|
47
47
|
}
|
|
48
|
-
// Delete user
|
|
49
48
|
return UserRepo.delete(id);
|
|
50
49
|
}
|
|
51
50
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
|
-
|
|
3
|
-
import HttpStatusCodes from '@src/constants/HttpStatusCodes';
|
|
4
|
-
import { RouteError } from '@src/other/classes';
|
|
5
2
|
import jsonwebtoken from 'jsonwebtoken';
|
|
6
3
|
|
|
7
|
-
import
|
|
4
|
+
import HttpStatusCodes from '@src/common/HttpStatusCodes';
|
|
5
|
+
import RouteError from '@src/common/RouteError';
|
|
6
|
+
import EnvVars from '@src/common/EnvVars';
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
// **** Variables **** //
|
|
@@ -32,6 +31,23 @@ function getSessionData<T>(req: Request): Promise<string | T | undefined> {
|
|
|
32
31
|
return _decode(jwt);
|
|
33
32
|
}
|
|
34
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Decrypt JWT and extract client data.
|
|
36
|
+
*/
|
|
37
|
+
function _decode<T>(jwt: string): Promise<string | undefined | T> {
|
|
38
|
+
return new Promise((res, rej) => {
|
|
39
|
+
jsonwebtoken.verify(jwt, EnvVars.Jwt.Secret, (err, decoded) => {
|
|
40
|
+
if (!!err) {
|
|
41
|
+
const err = new RouteError(HttpStatusCodes.UNAUTHORIZED,
|
|
42
|
+
Errors.Validation);
|
|
43
|
+
return rej(err);
|
|
44
|
+
} else {
|
|
45
|
+
return res(decoded as T);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
/**
|
|
36
52
|
* Add a JWT to the response
|
|
37
53
|
*/
|
|
@@ -49,37 +65,23 @@ async function addSessionData(
|
|
|
49
65
|
return res.cookie(Key, jwt, Options);
|
|
50
66
|
}
|
|
51
67
|
|
|
52
|
-
/**
|
|
53
|
-
* Remove cookie
|
|
54
|
-
*/
|
|
55
|
-
function clearCookie(res: Response): Response {
|
|
56
|
-
const { Key, Options } = EnvVars.CookieProps;
|
|
57
|
-
return res.clearCookie(Key, Options);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// **** Helper Functions **** //
|
|
62
|
-
|
|
63
68
|
/**
|
|
64
69
|
* Encrypt data and return jwt.
|
|
65
70
|
*/
|
|
66
71
|
function _sign(data: string | object | Buffer): Promise<string> {
|
|
67
72
|
return new Promise((res, rej) => {
|
|
68
73
|
jsonwebtoken.sign(data, EnvVars.Jwt.Secret, Options, (err, token) => {
|
|
69
|
-
return err ? rej(err) : res(token
|
|
74
|
+
return (err ? rej(err) : res(token ?? ''));
|
|
70
75
|
});
|
|
71
76
|
});
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
/**
|
|
75
|
-
*
|
|
80
|
+
* Remove cookie
|
|
76
81
|
*/
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return err ? rej(Errors.Validation) : res(decoded as T);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
82
|
+
function clearCookie(res: Response): Response {
|
|
83
|
+
const { Key, Options } = EnvVars.CookieProps;
|
|
84
|
+
return res.clearCookie(Key, Options);
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.11",
|
|
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",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|