express-generator-typescript 2.0.15 → 2.1.1

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.
@@ -14,9 +14,9 @@
14
14
  },
15
15
  "rules": {
16
16
  "max-len": [
17
- "error",
17
+ "warn",
18
18
  {
19
- "code": 100
19
+ "code": 80
20
20
  }
21
21
  ],
22
22
  "comma-dangle": ["warn", "always-multiline"],
@@ -22,14 +22,15 @@ const authPath = ('/api' + paths.basePath),
22
22
 
23
23
  // Test message
24
24
  const msgs = {
25
- goodLogin: `should return a response with a status of ${OK} and a cookie with a jwt if the login
26
- was successful.`,
27
- emailNotFound: `should return a response with a status of ${UNAUTHORIZED} and a json with the
28
- "error ${UnauthorizedError.Msg}" if the email was not found.`,
29
- pwdFailed: `should return a response with a status of ${UNAUTHORIZED} and a json with the error
30
- "${UnauthorizedError.Msg}" if the password failed.`,
31
- fallbackErr: `should return a response with a status of ${BAD_REQUEST} and a json with an error
32
- for all other bad responses.`,
25
+ goodLogin: `should return a response with a status of ${OK} and a cookie
26
+ with a jwt if the login was successful.`,
27
+ emailNotFound: `should return a response with a status of ${UNAUTHORIZED}
28
+ and a json with the "error ${UnauthorizedError.Msg}" if the email was
29
+ not found.`,
30
+ pwdFailed: `should return a response with a status of ${UNAUTHORIZED} and a
31
+ json with the error "${UnauthorizedError.Msg}" if the password failed.`,
32
+ fallbackErr: `should return a response with a status of ${BAD_REQUEST} and
33
+ a json with an error for all other bad responses.`,
33
34
  goodLogout: `should return a response with a status of ${OK}.`,
34
35
  } as const;
35
36
 
@@ -8,8 +8,12 @@ import userRepo from '@repos/user-repo';
8
8
  import User, { IUser } from '@models/user-model';
9
9
 
10
10
  import { p as userPaths } from '@routes/user-router';
11
+ import {
12
+ ParamMissingError,
13
+ UserNotFoundError,
14
+ ValidatorFnError,
15
+ } from '@shared/errors';
11
16
  import loginAgent from '../support/login-agent';
12
- import { ParamMissingError, UserNotFoundError, ValidatorFnError } from '@shared/errors';
13
17
 
14
18
 
15
19
  // **** Variables **** //
@@ -36,31 +40,34 @@ const dummyUserData = {
36
40
 
37
41
  // Test messages
38
42
  const msgs = {
39
- getUsersSuccess: `should return a JSON object with all the users and a status code of
40
- "${OK}" if the request was successful.`,
41
- getUsersBad: `should return a JSON object containing an error message and a status code of
42
- "${BAD_REQUEST}" if the request was unsuccessful.`,
43
- addUserSuccess: `should return a status code of "${CREATED}" if the request was successful.`,
44
- addUserFailedMissingParam: `should return a JSON object with an error message of
45
- "${ParamMissingError.Msg}" and a status code of "${BAD_REQUEST}" if the user param was
46
- missing.`,
47
- addUserFallbackErr: `should return a JSON object with an error message and a status code
48
- of "${BAD_REQUEST}" if the request was unsuccessful.`,
49
- updateSuccess: `should return a status code of "${OK}" if the request was successful.`,
43
+ getUsersSuccess: `should return a JSON object with all the users and a
44
+ status code of "${OK}" if the request was successful.`,
45
+ getUsersBad: `should return a JSON object containing an error message and a
46
+ status code of "${BAD_REQUEST}" if the request was unsuccessful.`,
47
+ addUserSuccess: `should return a status code of "${CREATED}" if the request
48
+ was successful.`,
49
+ addUserFailedMissingParam: `should return a JSON object with an error
50
+ message of "${ParamMissingError.Msg}" and a status code of "${BAD_REQUEST}"
51
+ if the user param was missing.`,
52
+ addUserFallbackErr: `should return a JSON object with an error message and a
53
+ status code of "${BAD_REQUEST}" if the request was unsuccessful.`,
54
+ updateSuccess: `should return a status code of "${OK}" if the request was
55
+ successful.`,
50
56
  updateParamMissing: `should return a JSON object with an error message of
51
- "${ParamMissingError.Msg}" and a status code of "${BAD_REQUEST}" if the user param was
52
- missing.`,
57
+ "${ParamMissingError.Msg}" and a status code of "${BAD_REQUEST}" if the
58
+ user param was missing.`,
53
59
  updateUserNotFound: `should return a JSON object with the error message of
54
- ${UserNotFoundError.Msg} and a status code of "${UserNotFoundError.HttpStatus}" if the id
55
- was not found.`,
56
- updateFallbackErr: `should return a JSON object with an error message and a status code of
57
- "${BAD_REQUEST}" if the request was unsuccessful.`,
58
- deleteSuccessful: `should return a status code of "${OK}" if the request was successful.`,
60
+ ${UserNotFoundError.Msg} and a status code of
61
+ "${UserNotFoundError.HttpStatus}" if the id was not found.`,
62
+ updateFallbackErr: `should return a JSON object with an error message and a
63
+ status code of "${BAD_REQUEST}" if the request was unsuccessful.`,
64
+ deleteSuccessful: `should return a status code of "${OK}" if the request was
65
+ successful.`,
59
66
  deleteUserNotFound: `should return a JSON object with the error message of
60
- ${UserNotFoundError.Msg} and a status code of "${UserNotFoundError.HttpStatus}" if the id was
61
- not found.`,
62
- deleteFallbackErr: `should return a JSON object with an error message and a status code of
63
- "${BAD_REQUEST}" if the request was unsuccessful.`,
67
+ ${UserNotFoundError.Msg} and a status code of
68
+ "${UserNotFoundError.HttpStatus}" if the id was not found.`,
69
+ deleteFallbackErr: `should return a JSON object with an error message and a
70
+ status code of "${BAD_REQUEST}" if the request was unsuccessful.`,
64
71
  };
65
72
 
66
73
 
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Pre-start is where we want to place things that must run BEFORE the express server is started.
3
- * This is useful for environment variables, command-line arguments, and cron-jobs.
2
+ * Pre-start is where we want to place things that must run BEFORE the express
3
+ * server is started. This is useful for environment variables, command-line
4
+ * arguments, and cron-jobs.
4
5
  */
5
6
 
6
7
  import path from 'path';
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Put other validator functions here too that may be passed to the validate() function
2
+ * Put other validator functions here too that may be passed to the validate()
3
+ * function.
3
4
  */
4
5
 
5
6
  import { ParamInvalidError, ValidatorFnError } from '@shared/errors';
@@ -15,11 +16,13 @@ type TParamFull = TParam | TValidatorFn;
15
16
  // **** Functions **** //
16
17
 
17
18
  /**
18
- * Make sure parameter is of the specified type. If the type is not provided then 'string' is
19
- * used as the default type. Instead of a type you can also pass a validator function
20
- * which must return 'true' or 'false'. Return false if invalid.
19
+ * Make sure parameter is of the specified type. If the type is not provided
20
+ * then 'string' is used as the default type. Instead of a type you can also
21
+ * pass a validator function which must return 'true' or 'false'. Return false
22
+ * if invalid.
21
23
  *
22
- * Example argument: [id, 'number'], id is the incoming variable, 'number' is the type.
24
+ * Example argument: [id, 'number'], id is the incoming variable, 'number' is
25
+ * the type.
23
26
  *
24
27
  * Example 1: validate(email, [user, 'object'], [isAdmin, 'boolean'])
25
28
  * Example 2: validate(password) // will check that password is a string
@@ -40,11 +40,22 @@ if (envVars.nodeEnv === 'production') {
40
40
  // Add APIs
41
41
  app.use('/api', BaseRouter);
42
42
 
43
- // Error handling
44
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
- app.use((err: Error | CustomError, req: Request, res: Response, _: NextFunction) => {
43
+ // Setup error handler
44
+ app.use((
45
+ err: Error | CustomError,
46
+ _: Request,
47
+ res: Response,
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
+ __: NextFunction,
50
+ ) => {
46
51
  logger.err(err, true);
47
- const status = (err instanceof CustomError ? err.HttpStatus : StatusCodes.BAD_REQUEST);
52
+ // Status
53
+ const status = (
54
+ err instanceof CustomError
55
+ ? err.HttpStatus
56
+ : StatusCodes.BAD_REQUEST
57
+ );
58
+ // Return
48
59
  return res.status(status).json({
49
60
  error: err.message,
50
61
  });
@@ -13,7 +13,8 @@ export abstract class CustomError extends Error {
13
13
 
14
14
  export class ParamMissingError extends CustomError {
15
15
 
16
- public static readonly Msg = 'One or more of the required parameters was missing.';
16
+ public static readonly Msg = 'One or more of the required parameters ' +
17
+ 'was missing.';
17
18
  public static readonly HttpStatus = HttpStatusCodes.BAD_REQUEST;
18
19
 
19
20
  constructor() {
@@ -23,7 +24,8 @@ export class ParamMissingError extends CustomError {
23
24
 
24
25
  export class ParamInvalidError extends CustomError {
25
26
 
26
- public static readonly Msg = 'One or more of the required was missing or invalid.';
27
+ public static readonly Msg = 'One or more of the required was missing ' +
28
+ 'or invalid.';
27
29
  public static readonly HttpStatus = HttpStatusCodes.BAD_REQUEST;
28
30
 
29
31
  constructor() {
@@ -43,7 +45,8 @@ export class ValidatorFnError extends CustomError {
43
45
 
44
46
  export class UserNotFoundError extends CustomError {
45
47
 
46
- public static readonly Msg = 'A user with the given id does not exists in the database.';
48
+ public static readonly Msg = 'A user with the given id does not exists ' +
49
+ 'in the database.';
47
50
  public static readonly HttpStatus = HttpStatusCodes.NOT_FOUND;
48
51
 
49
52
  constructor() {
@@ -1,4 +1,4 @@
1
- import jsonwebtoken, { JwtPayload } from 'jsonwebtoken';
1
+ import jsonwebtoken from 'jsonwebtoken';
2
2
  import envVars from '../shared/env-vars';
3
3
 
4
4
 
@@ -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
- async function decode<T extends JwtPayload>(jwt: string): Promise<string | undefined | T> {
34
+ async 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.0.15",
3
+ "version": "2.1.1",
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",