express-generator-typescript 2.2.8 → 2.3.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.
- package/lib/express-generator-typescript.js +12 -12
- package/lib/project-files/.eslintrc.json +1 -0
- package/lib/project-files/env/development.env +1 -0
- package/lib/project-files/env/production.env +1 -0
- package/lib/project-files/env/test.env +1 -0
- package/lib/project-files/package.json +4 -4
- package/lib/project-files/spec/index.ts +32 -12
- package/lib/project-files/spec/support/login.ts +43 -0
- package/lib/project-files/spec/support/types.ts +1 -0
- package/lib/project-files/spec/tests/auth.spec.ts +75 -89
- package/lib/project-files/spec/tests/users.spec.ts +133 -212
- package/lib/project-files/src/constants/EnvVars.ts +28 -0
- package/lib/project-files/src/{declarations/major → constants}/HttpStatusCodes.ts +0 -0
- package/lib/project-files/src/{declarations/enums.ts → constants/misc.ts} +2 -6
- package/lib/project-files/src/index.ts +6 -4
- package/lib/project-files/src/models/User.ts +9 -2
- package/lib/project-files/src/{declarations → other}/classes.ts +1 -1
- package/lib/project-files/src/other/types.ts +4 -0
- package/lib/project-files/src/pre-start.ts +17 -15
- package/lib/project-files/src/repos/{mock-orm.ts → MockOrm.ts} +4 -4
- package/lib/project-files/src/repos/{user-repo.ts → UserRepo.ts} +4 -4
- package/lib/project-files/src/routes/AuthRoutes.ts +47 -0
- package/lib/project-files/src/routes/UserRoutes.ts +53 -0
- package/lib/project-files/src/routes/api.ts +27 -20
- package/lib/project-files/src/routes/constants/FullPaths.ts +40 -0
- package/lib/project-files/src/routes/constants/Paths.ts +28 -0
- package/lib/project-files/src/routes/{shared → middleware}/adminMw.ts +12 -22
- package/lib/project-files/src/{types → routes/types}/express/index.d.ts +0 -0
- package/lib/project-files/src/routes/types/express/misc.ts +16 -0
- package/lib/project-files/src/routes/{shared → types}/types.ts +1 -1
- package/lib/project-files/src/routes/user-routes.ts +2 -8
- package/lib/project-files/src/server.ts +28 -21
- package/lib/project-files/src/services/{auth-service.ts → AuthService.ts} +16 -14
- package/lib/project-files/src/services/{user-service.ts → UserService.ts} +12 -12
- package/lib/project-files/src/util/{jwt-util.ts → JwtUtil.ts} +8 -8
- package/lib/project-files/src/util/{pwd-util.ts → PwdUtil.ts} +3 -3
- package/lib/project-files/src/{declarations/functions.ts → util/misc.ts} +1 -0
- package/package.json +1 -1
- package/lib/project-files/spec/load-env.ts +0 -12
- package/lib/project-files/spec/support/login-agent.ts +0 -46
- package/lib/project-files/src/declarations/major/EnvVars.ts +0 -22
- package/lib/project-files/src/routes/auth-routes.ts +0 -57
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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",
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { SuperTest, Test, Response } from 'supertest';
|
|
2
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
// **** Variables **** //
|
|
9
|
-
|
|
10
|
-
const creds = {
|
|
11
|
-
email: 'jsmith@gmail.com',
|
|
12
|
-
password: 'Password@1',
|
|
13
|
-
} as const;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// **** Functions **** //
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Login a user.
|
|
20
|
-
*/
|
|
21
|
-
function login(beforeAgent: SuperTest<Test>, done: (arg: string) => void) {
|
|
22
|
-
// Setup dummy data
|
|
23
|
-
const role = UserRoles.Admin;
|
|
24
|
-
const pwdHash = pwdUtil.hashSync(creds.password);
|
|
25
|
-
const loginUser = User.new('john smith', creds.email, role, pwdHash);
|
|
26
|
-
spyOn(userRepo, 'getOne').and.returnValue(Promise.resolve(loginUser));
|
|
27
|
-
// Call Login API
|
|
28
|
-
beforeAgent
|
|
29
|
-
.post('/api/auth/login')
|
|
30
|
-
.type('form')
|
|
31
|
-
.send(creds)
|
|
32
|
-
.end((err: Error, res: Response) => {
|
|
33
|
-
if (err) {
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
const cookie = res.headers['set-cookie'][0];
|
|
37
|
-
return done(cookie);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// **** Export default **** //
|
|
43
|
-
|
|
44
|
-
export default {
|
|
45
|
-
login,
|
|
46
|
-
} as const;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/* eslint-disable node/no-process-env */
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
nodeEnv: (process.env.NODE_ENV ?? ''),
|
|
5
|
-
port: (process.env.PORT ?? 0),
|
|
6
|
-
cookieProps: {
|
|
7
|
-
key: 'ExpressGeneratorTs',
|
|
8
|
-
secret: (process.env.COOKIE_SECRET ?? ''),
|
|
9
|
-
options: {
|
|
10
|
-
httpOnly: true,
|
|
11
|
-
signed: true,
|
|
12
|
-
path: (process.env.COOKIE_PATH ?? ''),
|
|
13
|
-
maxAge: Number(process.env.COOKIE_EXP ?? 0),
|
|
14
|
-
domain: (process.env.COOKIE_DOMAIN ?? ''),
|
|
15
|
-
secure: (process.env.SECURE_COOKIE === 'true'),
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
jwt: {
|
|
19
|
-
secret: (process.env.JWT_SECRET ?? ''),
|
|
20
|
-
exp: (process.env.COOKIE_EXP ?? ''), // exp at the same time as the cookie
|
|
21
|
-
},
|
|
22
|
-
} as const;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import HttpStatusCodes from '@src/declarations/major/HttpStatusCodes';
|
|
2
|
-
|
|
3
|
-
import authService from '@src/services/auth-service';
|
|
4
|
-
import EnvVars from '@src/declarations/major/EnvVars';
|
|
5
|
-
import { IReq, IRes } from './shared/types';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// **** Variables **** //
|
|
9
|
-
|
|
10
|
-
// Paths
|
|
11
|
-
const paths = {
|
|
12
|
-
basePath: '/auth',
|
|
13
|
-
login: '/login',
|
|
14
|
-
logout: '/logout',
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// **** Types **** //
|
|
19
|
-
|
|
20
|
-
interface ILoginReq {
|
|
21
|
-
email: string;
|
|
22
|
-
password: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// **** Functions **** //
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Login a user.
|
|
30
|
-
*/
|
|
31
|
-
async function login(req: IReq<ILoginReq>, res: IRes) {
|
|
32
|
-
const { email, password } = req.body;
|
|
33
|
-
// Add jwt to cookie
|
|
34
|
-
const jwt = await authService.getJwt(email, password);
|
|
35
|
-
const { key, options } = EnvVars.cookieProps;
|
|
36
|
-
res.cookie(key, jwt, options);
|
|
37
|
-
// Return
|
|
38
|
-
return res.status(HttpStatusCodes.OK).end();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Logout the user.
|
|
43
|
-
*/
|
|
44
|
-
function logout(_: IReq, res: IRes) {
|
|
45
|
-
const { key, options } = EnvVars.cookieProps;
|
|
46
|
-
res.clearCookie(key, options);
|
|
47
|
-
return res.status(HttpStatusCodes.OK).end();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// **** Export default **** //
|
|
52
|
-
|
|
53
|
-
export default {
|
|
54
|
-
paths,
|
|
55
|
-
login,
|
|
56
|
-
logout,
|
|
57
|
-
} as const;
|