express-generator-typescript 2.4.25 → 2.5.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.
Files changed (93) hide show
  1. package/README.md +24 -33
  2. package/lib/cli.js +5 -25
  3. package/lib/express-generator-typescript.js +11 -19
  4. package/lib/project-files/README.md +18 -1
  5. package/lib/{project-files-auth/env/development.env → project-files/config/.env.development} +0 -9
  6. package/lib/project-files/config/.env.production +14 -0
  7. package/lib/project-files/{env/test.env → config/.env.test} +0 -10
  8. package/lib/project-files/config.js +18 -0
  9. package/lib/project-files/config.ts +22 -0
  10. package/lib/project-files/eslint.config.ts +96 -0
  11. package/lib/project-files/gitignore +2 -0
  12. package/lib/project-files/package.json +16 -9
  13. package/lib/project-files/scripts/build.ts +4 -0
  14. package/lib/project-files/spec/support/Paths.ts +1 -6
  15. package/lib/project-files/spec/support/apiCb.ts +18 -6
  16. package/lib/project-files/spec/tests/users.spec.ts +28 -33
  17. package/lib/project-files/spec/types/misc.ts +7 -6
  18. package/lib/project-files/spec/types/supertest/index.d.ts +2 -2
  19. package/lib/project-files/src/common/Env.ts +10 -0
  20. package/lib/project-files/src/common/route-errors.ts +41 -0
  21. package/lib/project-files/src/index.ts +3 -3
  22. package/lib/project-files/src/models/User.ts +9 -57
  23. package/lib/project-files/src/repos/MockOrm.ts +0 -2
  24. package/lib/project-files/src/repos/database.json +1 -1
  25. package/lib/project-files/src/routes/UserRoutes.ts +14 -5
  26. package/lib/project-files/src/{common → routes/common}/Paths.ts +0 -4
  27. package/lib/project-files/src/routes/common/index.ts +37 -0
  28. package/lib/project-files/src/routes/index.ts +1 -1
  29. package/lib/project-files/src/server.ts +7 -9
  30. package/lib/project-files/src/services/UserService.ts +1 -1
  31. package/lib/project-files/src/util/misc.ts +0 -16
  32. package/lib/project-files/src/util/schema.ts +11 -0
  33. package/lib/project-files/src/util/validators.ts +322 -0
  34. package/lib/project-files/tsconfig.json +20 -71
  35. package/lib/project-files/tsconfig.prod.json +22 -2
  36. package/package.json +1 -1
  37. package/lib/project-files/env/development.env +0 -24
  38. package/lib/project-files/env/production.env +0 -25
  39. package/lib/project-files/eslint.config.mjs +0 -58
  40. package/lib/project-files/preload.js +0 -23
  41. package/lib/project-files/src/common/EnvVars.ts +0 -24
  42. package/lib/project-files/src/common/classes.ts +0 -32
  43. package/lib/project-files/src/common/misc.ts +0 -5
  44. package/lib/project-files/src/routes/common/check.ts +0 -143
  45. package/lib/project-files/src/routes/common/types.ts +0 -8
  46. package/lib/project-files-auth/README.md +0 -35
  47. package/lib/project-files-auth/env/production.env +0 -25
  48. package/lib/project-files-auth/env/test.env +0 -24
  49. package/lib/project-files-auth/eslint.config.mjs +0 -58
  50. package/lib/project-files-auth/gitignore +0 -3
  51. package/lib/project-files-auth/package.json +0 -60
  52. package/lib/project-files-auth/preload.js +0 -23
  53. package/lib/project-files-auth/scripts/build.ts +0 -62
  54. package/lib/project-files-auth/spec/index.ts +0 -46
  55. package/lib/project-files-auth/spec/support/Paths.ts +0 -10
  56. package/lib/project-files-auth/spec/support/apiCb.ts +0 -76
  57. package/lib/project-files-auth/spec/support/jasmine.json +0 -11
  58. package/lib/project-files-auth/spec/support/login.ts +0 -42
  59. package/lib/project-files-auth/spec/tests/auth.spec.ts +0 -115
  60. package/lib/project-files-auth/spec/tests/users.spec.ts +0 -190
  61. package/lib/project-files-auth/spec/types/misc.ts +0 -12
  62. package/lib/project-files-auth/spec/types/supertest/index.d.ts +0 -14
  63. package/lib/project-files-auth/src/common/EnvVars.ts +0 -24
  64. package/lib/project-files-auth/src/common/HttpStatusCodes.ts +0 -386
  65. package/lib/project-files-auth/src/common/Paths.ts +0 -20
  66. package/lib/project-files-auth/src/common/classes.ts +0 -31
  67. package/lib/project-files-auth/src/index.ts +0 -12
  68. package/lib/project-files-auth/src/models/User.ts +0 -89
  69. package/lib/project-files-auth/src/public/scripts/http.js +0 -26
  70. package/lib/project-files-auth/src/public/scripts/login.js +0 -15
  71. package/lib/project-files-auth/src/public/scripts/users.js +0 -138
  72. package/lib/project-files-auth/src/public/stylesheets/login.css +0 -24
  73. package/lib/project-files-auth/src/public/stylesheets/users.css +0 -43
  74. package/lib/project-files-auth/src/repos/MockOrm.ts +0 -42
  75. package/lib/project-files-auth/src/repos/UserRepo.ts +0 -93
  76. package/lib/project-files-auth/src/repos/database.json +0 -1
  77. package/lib/project-files-auth/src/routes/AuthRoutes.ts +0 -42
  78. package/lib/project-files-auth/src/routes/UserRoutes.ts +0 -55
  79. package/lib/project-files-auth/src/routes/common/check.ts +0 -143
  80. package/lib/project-files-auth/src/routes/common/types.ts +0 -22
  81. package/lib/project-files-auth/src/routes/index.ts +0 -43
  82. package/lib/project-files-auth/src/routes/middleware/adminMw.ts +0 -47
  83. package/lib/project-files-auth/src/server.ts +0 -91
  84. package/lib/project-files-auth/src/services/AuthService.ts +0 -57
  85. package/lib/project-files-auth/src/services/UserService.ts +0 -59
  86. package/lib/project-files-auth/src/util/PwdUtil.ts +0 -39
  87. package/lib/project-files-auth/src/util/SessionUtil.ts +0 -94
  88. package/lib/project-files-auth/src/util/misc.ts +0 -22
  89. package/lib/project-files-auth/src/views/login.html +0 -58
  90. package/lib/project-files-auth/src/views/users.html +0 -140
  91. package/lib/project-files-auth/tsconfig.json +0 -87
  92. package/lib/project-files-auth/tsconfig.prod.json +0 -12
  93. /package/lib/{project-files-auth/src/common/misc.ts → project-files/src/common/constants.ts} +0 -0
@@ -1,115 +0,0 @@
1
- import supertest, { Test, Response } from 'supertest';
2
- import TestAgent from 'supertest/lib/agent';
3
-
4
- import app from '@src/server';
5
-
6
- import UserRepo from '@src/repos/UserRepo';
7
- import PwdUtil from '@src/util/PwdUtil';
8
- import User, { UserRoles } from '@src/models/User';
9
- import { Errors } from '@src/services/AuthService';
10
-
11
- import EnvVars from '@src/common/EnvVars';
12
- import HttpStatusCodes from '@src/common/HttpStatusCodes';
13
-
14
- import Paths from 'spec/support/Paths';
15
- import apiCb from 'spec/support/apiCb';
16
- import { TApiCb } from 'spec/types/misc';
17
-
18
-
19
- // Login Creds
20
- const LoginCreds = {
21
- email: 'jsmith@gmail.com',
22
- password: 'Password@1',
23
- } as const;
24
-
25
-
26
- // Tests
27
- describe('AuthRouter', () => {
28
-
29
- let agent: TestAgent<Test>;
30
-
31
- // Run before all tests
32
- beforeAll((done) => {
33
- agent = supertest.agent(app);
34
- done();
35
- });
36
-
37
- // Login
38
- describe(`"POST:${Paths.Auth.Login}"`, () => {
39
-
40
- const EMAIL_NOT_FOUND_ERR = Errors.EmailNotFound(LoginCreds.email);
41
-
42
- // Setup API
43
- const callApi = (creds: typeof LoginCreds, cb: TApiCb) =>
44
- agent
45
- .post(Paths.Auth.Login)
46
- .send(creds)
47
- .end(apiCb(cb));
48
-
49
- // Success
50
- it(`should return a response with a status of "${HttpStatusCodes.OK}" ` +
51
- 'and a cookie with a jwt if the login was successful.', done => {
52
- // Setup data
53
- const pwdHash = PwdUtil.hashSync(LoginCreds.password),
54
- loginUser = User.new('john smith', LoginCreds.email, new Date(),
55
- UserRoles.Standard, pwdHash);
56
- // Add spy
57
- spyOn(UserRepo, 'getOne').and.resolveTo(loginUser);
58
- // Call API
59
- callApi(LoginCreds, res => {
60
- expect(res.status).toBe(HttpStatusCodes.OK);
61
- const cookie = res.headers['set-cookie'][0];
62
- expect(cookie).toContain(EnvVars.CookieProps.Key);
63
- done();
64
- });
65
- });
66
-
67
- // Email not found error
68
- it('should return a response with a status of ' +
69
- `"${HttpStatusCodes.UNAUTHORIZED}" and a json with an error message of ` +
70
- `"${EMAIL_NOT_FOUND_ERR}" if the email was not found.`, done => {
71
- // Spy
72
- spyOn(UserRepo, 'getOne').and.resolveTo(null);
73
- // Call
74
- callApi(LoginCreds, res => {
75
- expect(res.status).toBe(HttpStatusCodes.UNAUTHORIZED);
76
- expect(res.body.error).toBe(EMAIL_NOT_FOUND_ERR);
77
- done();
78
- });
79
- });
80
-
81
- // Password failed
82
- it('should return a response with a status of ' +
83
- `"${HttpStatusCodes.UNAUTHORIZED}" and a json with the error ` +
84
- `"${Errors.Unauth}" if the password failed.`, done => {
85
- // Setup data
86
- const pwdHash = PwdUtil.hashSync('bad password'),
87
- loginUser = User.new('john smith', LoginCreds.email, new Date(),
88
- UserRoles.Standard, pwdHash);
89
- // Add spy
90
- spyOn(UserRepo, 'getOne').and.resolveTo(loginUser);
91
- // Call API
92
- callApi(LoginCreds, res => {
93
- expect(res.status).toBe(HttpStatusCodes.UNAUTHORIZED);
94
- expect(res.body.error).toBe(Errors.Unauth);
95
- done();
96
- });
97
- });
98
-
99
- });
100
-
101
- // Test logout
102
- describe(`"GET:${Paths.Auth.Logout}"`, () => {
103
-
104
- // Successful logout
105
- it(`should return a response with a status of ${HttpStatusCodes.OK}`,
106
- done => {
107
- agent
108
- .get(Paths.Auth.Logout)
109
- .end((_: Error, res: Response) => {
110
- expect(res.status).toBe(HttpStatusCodes.OK);
111
- done();
112
- });
113
- });
114
- });
115
- });
@@ -1,190 +0,0 @@
1
- import supertest, { Test } from 'supertest';
2
- import TestAgent from 'supertest/lib/agent';
3
- import insertUrlParams from 'inserturlparams';
4
-
5
- import app from '@src/server';
6
-
7
- import UserRepo from '@src/repos/UserRepo';
8
- import User, { IUser } from '@src/models/User';
9
- import HttpStatusCodes from '@src/common/HttpStatusCodes';
10
- import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
11
-
12
- import Paths from 'spec/support/Paths';
13
- import apiCb from 'spec/support/apiCb';
14
- import login from 'spec/support/login';
15
- import { TApiCb } from 'spec/types/misc';
16
- import { ValidationErr } from '@src/common/classes';
17
-
18
-
19
- // Dummy users for GET req
20
- const getDummyUsers = () => {
21
- return [
22
- User.new('Sean Maxwell', 'sean.maxwell@gmail.com'),
23
- User.new('John Smith', 'john.smith@gmail.com'),
24
- User.new('Gordan Freeman', 'gordan.freeman@gmail.com'),
25
- ];
26
- };
27
-
28
-
29
- // Tests
30
- describe('UserRouter', () => {
31
-
32
- let agent: TestAgent<Test>;
33
-
34
- // Run before all tests
35
- beforeAll((done) => {
36
- agent = supertest.agent(app);
37
- login(agent, cookie => {
38
- agent.set('Cookie', cookie);
39
- done();
40
- });
41
- });
42
-
43
- // Get all users
44
- describe(`"GET:${Paths.Users.Get}"`, () => {
45
-
46
- // Setup API
47
- const api = (cb: TApiCb) =>
48
- agent
49
- .get(Paths.Users.Get)
50
- .end(apiCb(cb));
51
-
52
- // Success
53
- it('should return a JSON object with all the users and a status code ' +
54
- `of "${HttpStatusCodes.OK}" if the request was successful.`, done => {
55
- // Add spy
56
- const data = getDummyUsers();
57
- spyOn(UserRepo, 'getAll').and.resolveTo(data);
58
- // Call API
59
- api(res => {
60
- expect(res.status).toBe(HttpStatusCodes.OK);
61
- expect(res.body).toEqual({ users: data });
62
- done();
63
- });
64
- });
65
- });
66
-
67
- // Test add user
68
- describe(`"POST:${Paths.Users.Add}"`, () => {
69
-
70
- const ERROR_MSG = ValidationErr.GetMsg('user'),
71
- DUMMY_USER = getDummyUsers()[0];
72
-
73
- // Setup API
74
- const callApi = (user: IUser | null, cb: TApiCb) =>
75
- agent
76
- .post(Paths.Users.Add)
77
- .send({ user })
78
- .end(apiCb(cb));
79
-
80
- // Test add user success
81
- it(`should return a status code of "${HttpStatusCodes.CREATED}" if the ` +
82
- 'request was successful.', done => {
83
- // Spy
84
- spyOn(UserRepo, 'add').and.resolveTo();
85
- // Call api
86
- callApi(DUMMY_USER, res => {
87
- expect(res.status).toBe(HttpStatusCodes.CREATED);
88
- done();
89
- });
90
- });
91
-
92
- // Missing param
93
- it(`should return a JSON object with an error message of "${ERROR_MSG}" ` +
94
- `and a status code of "${HttpStatusCodes.BAD_REQUEST}" if the user ` +
95
- 'param was missing.', done => {
96
- // Call api
97
- callApi(null, res => {
98
- expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
99
- expect(res.body.error).toBe(ERROR_MSG);
100
- done();
101
- });
102
- });
103
- });
104
-
105
- // Update users
106
- describe(`"PUT:${Paths.Users.Update}"`, () => {
107
-
108
- const ERROR_MSG = ValidationErr.GetMsg('user'),
109
- DUMMY_USER = getDummyUsers()[0];
110
-
111
- // Setup API
112
- const callApi = (user: IUser | null, cb: TApiCb) =>
113
- agent
114
- .put(Paths.Users.Update)
115
- .send({ user })
116
- .end(apiCb(cb));
117
-
118
- // Success
119
- it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
120
- 'request was successful.', done => {
121
- // Setup spies
122
- spyOn(UserRepo, 'update').and.resolveTo();
123
- spyOn(UserRepo, 'persists').and.resolveTo(true);
124
- // Call api
125
- callApi(DUMMY_USER, res => {
126
- expect(res.status).toBe(HttpStatusCodes.OK);
127
- done();
128
- });
129
- });
130
-
131
- // Param missing
132
- it(`should return a JSON object with an error message of "${ERROR_MSG}" ` +
133
- `and a status code of "${HttpStatusCodes.BAD_REQUEST}" if the user ` +
134
- 'param was missing.', done => {
135
- // Call api
136
- callApi(null, res => {
137
- expect(res.status).toBe(HttpStatusCodes.BAD_REQUEST);
138
- expect(res.body.error).toBe(ERROR_MSG);
139
- done();
140
- });
141
- });
142
-
143
- // User not found
144
- it('should return a JSON object with the error message of ' +
145
- `"${USER_NOT_FOUND_ERR}" and a status code of ` +
146
- `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, (done) => {
147
- // Call api
148
- callApi(DUMMY_USER, res => {
149
- expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
150
- expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
151
- done();
152
- });
153
- });
154
- });
155
-
156
- // Delete User
157
- describe(`"DELETE:${Paths.Users.Delete}"`, () => {
158
-
159
- // Call API
160
- const callApi = (id: number, cb: TApiCb) =>
161
- agent
162
- .delete(insertUrlParams(Paths.Users.Delete, { id }))
163
- .end(apiCb(cb));
164
-
165
- // Success
166
- it(`should return a status code of "${HttpStatusCodes.OK}" if the ` +
167
- 'request was successful.', (done) => {
168
- // Setup spies
169
- spyOn(UserRepo, 'delete').and.resolveTo();
170
- spyOn(UserRepo, 'persists').and.resolveTo(true);
171
- // Call api
172
- callApi(5, res => {
173
- expect(res.status).toBe(HttpStatusCodes.OK);
174
- done();
175
- });
176
- });
177
-
178
- // User not found
179
- it('should return a JSON object with the error message of ' +
180
- `"${USER_NOT_FOUND_ERR}" and a status code of ` +
181
- `"${HttpStatusCodes.NOT_FOUND}" if the id was not found.`, done => {
182
- // Setup spies
183
- callApi(-1, res => {
184
- expect(res.status).toBe(HttpStatusCodes.NOT_FOUND);
185
- expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
186
- done();
187
- });
188
- });
189
- });
190
- });
@@ -1,12 +0,0 @@
1
- import { Response } from 'supertest';
2
- import { IUser } from '@src/models/User';
3
-
4
-
5
- // Misc
6
- export type TReqBody = Record<string, unknown>;
7
- export type TRes = Omit<Response, 'body'> & { body: {
8
- error?: string;
9
- user?: IUser
10
- users?: IUser[]
11
- }};
12
- export type TApiCb = (res: TRes) => void;
@@ -1,14 +0,0 @@
1
- import { IUser } from '@src/models/User';
2
- import 'supertest';
3
-
4
-
5
- declare module 'supertest' {
6
-
7
- export interface Response {
8
- headers: Record<string, string[]>;
9
- body: {
10
- error: string;
11
- users: IUser[];
12
- };
13
- }
14
- }
@@ -1,24 +0,0 @@
1
- /* eslint-disable n/no-process-env */
2
-
3
-
4
- export default {
5
- NodeEnv: (process.env.NODE_ENV ?? ''),
6
- Port: (process.env.PORT ?? 0),
7
- CookieProps: {
8
- Key: 'ExpressGeneratorTs',
9
- Secret: (process.env.COOKIE_SECRET ?? ''),
10
- // Casing to match express cookie options
11
- Options: {
12
- httpOnly: true,
13
- signed: true,
14
- path: (process.env.COOKIE_PATH ?? ''),
15
- maxAge: Number(process.env.COOKIE_EXP ?? 0),
16
- domain: (process.env.COOKIE_DOMAIN ?? ''),
17
- secure: (process.env.SECURE_COOKIE === 'true'),
18
- },
19
- },
20
- Jwt: {
21
- Secret: (process.env.JWT_SECRET ?? ''),
22
- Exp: (process.env.COOKIE_EXP ?? ''), // exp at the same time as the cookie
23
- },
24
- } as const;