@motway_ticketing/common 1.0.4 → 1.0.6

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 (45) hide show
  1. package/build/errors/bad-request-error.d.ts +10 -0
  2. package/build/errors/bad-request-error.d.ts.map +1 -0
  3. package/build/errors/bad-request-error.js +14 -0
  4. package/build/errors/bad-request-error.js.map +1 -0
  5. package/build/errors/custom-error.d.ts +9 -0
  6. package/build/errors/custom-error.d.ts.map +1 -0
  7. package/build/errors/custom-error.js +8 -0
  8. package/build/errors/custom-error.js.map +1 -0
  9. package/build/errors/database-connection-error.d.ts +10 -0
  10. package/build/errors/database-connection-error.d.ts.map +1 -0
  11. package/build/errors/database-connection-error.js +14 -0
  12. package/build/errors/database-connection-error.js.map +1 -0
  13. package/build/errors/not-authorized-error.d.ts +9 -0
  14. package/build/errors/not-authorized-error.d.ts.map +1 -0
  15. package/build/errors/not-authorized-error.js +12 -0
  16. package/build/errors/not-authorized-error.js.map +1 -0
  17. package/build/errors/not-found-error.d.ts +9 -0
  18. package/build/errors/not-found-error.d.ts.map +1 -0
  19. package/build/errors/not-found-error.js +12 -0
  20. package/build/errors/not-found-error.js.map +1 -0
  21. package/build/errors/request-validation-error.d.ts +15 -0
  22. package/build/errors/request-validation-error.d.ts.map +1 -0
  23. package/build/errors/request-validation-error.js +20 -0
  24. package/build/errors/request-validation-error.js.map +1 -0
  25. package/build/index.d.ts +10 -7
  26. package/build/index.d.ts.map +1 -1
  27. package/build/index.js +10 -7
  28. package/build/index.js.map +1 -1
  29. package/build/middlewares/current-user.d.ts +15 -0
  30. package/build/middlewares/current-user.d.ts.map +1 -0
  31. package/build/middlewares/current-user.js +14 -0
  32. package/build/middlewares/current-user.js.map +1 -0
  33. package/build/middlewares/error-handler.d.ts +3 -0
  34. package/build/middlewares/error-handler.d.ts.map +1 -0
  35. package/build/middlewares/error-handler.js +11 -0
  36. package/build/middlewares/error-handler.js.map +1 -0
  37. package/build/middlewares/require-auth.d.ts +3 -0
  38. package/build/middlewares/require-auth.d.ts.map +1 -0
  39. package/build/middlewares/require-auth.js +8 -0
  40. package/build/middlewares/require-auth.js.map +1 -0
  41. package/build/middlewares/validate-request.d.ts +3 -0
  42. package/build/middlewares/validate-request.d.ts.map +1 -0
  43. package/build/middlewares/validate-request.js +10 -0
  44. package/build/middlewares/validate-request.js.map +1 -0
  45. package/package.json +13 -5
@@ -0,0 +1,10 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class BadRequestError extends CustomError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
10
+ //# sourceMappingURL=bad-request-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bad-request-error.d.ts","sourceRoot":"","sources":["../../src/errors/bad-request-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,eAAgB,SAAQ,WAAW;IAE3B,OAAO,EAAE,MAAM;IADlC,UAAU,SAAO;gBACE,OAAO,EAAE,MAAM;IAMlC,eAAe;;;CAGhB"}
@@ -0,0 +1,14 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class BadRequestError extends CustomError {
3
+ message;
4
+ statusCode = 400;
5
+ constructor(message) {
6
+ super(message);
7
+ this.message = message;
8
+ Object.setPrototypeOf(this, BadRequestError.prototype);
9
+ }
10
+ serializeErrors() {
11
+ return [{ message: this.message }];
12
+ }
13
+ }
14
+ //# sourceMappingURL=bad-request-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bad-request-error.js","sourceRoot":"","sources":["../../src/errors/bad-request-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAE3B;IADnB,UAAU,GAAG,GAAG,CAAC;IACjB,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAGhC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export declare abstract class CustomError extends Error {
2
+ abstract statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): {
5
+ message: string;
6
+ field?: string;
7
+ }[];
8
+ }
9
+ //# sourceMappingURL=custom-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../src/errors/custom-error.ts"],"names":[],"mappings":"AAAA,8BAAsB,WAAY,SAAQ,KAAK;IAC7C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM;IAO3B,QAAQ,CAAC,eAAe,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;CAClE"}
@@ -0,0 +1,8 @@
1
+ export class CustomError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ // Only because we are extending a built-in class
5
+ Object.setPrototypeOf(this, CustomError.prototype);
6
+ }
7
+ }
8
+ //# sourceMappingURL=custom-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../src/errors/custom-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAgB,WAAY,SAAQ,KAAK;IAG7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,iDAAiD;QACjD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CAGF"}
@@ -0,0 +1,10 @@
1
+ import { CustomError } from './custom-error';
2
+ export declare class DatabaseConnectionError extends CustomError {
3
+ statusCode: number;
4
+ reason: string;
5
+ constructor();
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
10
+ //# sourceMappingURL=database-connection-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-connection-error.d.ts","sourceRoot":"","sources":["../../src/errors/database-connection-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,uBAAwB,SAAQ,WAAW;IACtD,UAAU,SAAO;IACjB,MAAM,SAA4B;;IASlC,eAAe;;;CAGhB"}
@@ -0,0 +1,14 @@
1
+ import { CustomError } from './custom-error';
2
+ export class DatabaseConnectionError extends CustomError {
3
+ statusCode = 500;
4
+ reason = 'Error connecting to DB';
5
+ constructor() {
6
+ super("Error connecting to DB");
7
+ // Only because we are extending a built-in class
8
+ Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
9
+ }
10
+ serializeErrors() {
11
+ return [{ message: this.reason }];
12
+ }
13
+ }
14
+ //# sourceMappingURL=database-connection-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-connection-error.js","sourceRoot":"","sources":["../../src/errors/database-connection-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACtD,UAAU,GAAG,GAAG,CAAC;IACjB,MAAM,GAAG,wBAAwB,CAAC;IAElC;QACE,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAEhC,iDAAiD;QACjD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
9
+ //# sourceMappingURL=not-authorized-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-authorized-error.d.ts","sourceRoot":"","sources":["../../src/errors/not-authorized-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,UAAU,SAAO;;IAOjB,eAAe;;;CAGhB"}
@@ -0,0 +1,12 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class NotAuthorizedError extends CustomError {
3
+ statusCode = 401;
4
+ constructor() {
5
+ super('Not authorized');
6
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
7
+ }
8
+ serializeErrors() {
9
+ return [{ message: 'Not authorized' }];
10
+ }
11
+ }
12
+ //# sourceMappingURL=not-authorized-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-authorized-error.js","sourceRoot":"","sources":["../../src/errors/not-authorized-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,UAAU,GAAG,GAAG,CAAC;IAEjB;QACE,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
9
+ //# sourceMappingURL=not-found-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-found-error.d.ts","sourceRoot":"","sources":["../../src/errors/not-found-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,aAAc,SAAQ,WAAW;IAC5C,UAAU,SAAO;;IAQjB,eAAe;;;CAGhB"}
@@ -0,0 +1,12 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class NotFoundError extends CustomError {
3
+ statusCode = 404;
4
+ constructor() {
5
+ super("Resource not found");
6
+ Object.setPrototypeOf(this, NotFoundError.prototype);
7
+ }
8
+ serializeErrors() {
9
+ return [{ message: "Resource not found" }];
10
+ }
11
+ }
12
+ //# sourceMappingURL=not-found-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-found-error.js","sourceRoot":"","sources":["../../src/errors/not-found-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,aAAc,SAAQ,WAAW;IAC5C,UAAU,GAAG,GAAG,CAAC;IAEjB;QACE,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAE5B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import type { ValidationError } from "express-validator";
2
+ import { CustomError } from './custom-error';
3
+ export declare class RequestValidationError extends CustomError {
4
+ errors: ValidationError[];
5
+ statusCode: number;
6
+ constructor(errors: ValidationError[]);
7
+ serializeErrors(): ({
8
+ message: any;
9
+ field: string;
10
+ } | {
11
+ message: any;
12
+ field?: never;
13
+ })[];
14
+ }
15
+ //# sourceMappingURL=request-validation-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-validation-error.d.ts","sourceRoot":"","sources":["../../src/errors/request-validation-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,sBAAuB,SAAQ,WAAW;IAGlC,MAAM,EAAE,eAAe,EAAE;IAF5C,UAAU,SAAO;gBAEE,MAAM,EAAE,eAAe,EAAE;IAO5C,eAAe;;;;;;;CAShB"}
@@ -0,0 +1,20 @@
1
+ import { CustomError } from './custom-error';
2
+ export class RequestValidationError extends CustomError {
3
+ errors;
4
+ statusCode = 400;
5
+ constructor(errors) {
6
+ super("Invalid request parameters");
7
+ this.errors = errors;
8
+ // Only because we are extending a built-in class
9
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return this.errors.map(error => {
13
+ if (error.type === 'field') {
14
+ return { message: error.msg, field: error.path };
15
+ }
16
+ return { message: error.msg };
17
+ });
18
+ }
19
+ }
20
+ //# sourceMappingURL=request-validation-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-validation-error.js","sourceRoot":"","sources":["../../src/errors/request-validation-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IAGlC;IAFnB,UAAU,GAAG,GAAG,CAAC;IAEjB,YAAmB,MAAyB;QAC1C,KAAK,CAAC,4BAA4B,CAAC,CAAC;QADnB,WAAM,GAAN,MAAM,CAAmB;QAG1C,iDAAiD;QACjD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBAC3B,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YACnD,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
package/build/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- interface Color {
2
- red: number;
3
- green: number;
4
- blue: number;
5
- }
6
- declare const color: Color;
7
- export default color;
1
+ export * from './errors/bad-request-error';
2
+ export * from './errors/custom-error';
3
+ export * from './errors/database-connection-error';
4
+ export * from './errors/not-authorized-error';
5
+ export * from './errors/not-found-error';
6
+ export * from './errors/request-validation-error';
7
+ export * from './middlewares/current-user';
8
+ export * from './middlewares/error-handler';
9
+ export * from './middlewares/require-auth';
10
+ export * from './middlewares/validate-request';
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU,KAAK;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,QAAA,MAAM,KAAK,EAAE,KAIZ,CAAC;AAIF,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAElD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC"}
package/build/index.js CHANGED
@@ -1,8 +1,11 @@
1
- const color = {
2
- red: 255,
3
- green: 10,
4
- blue: 127,
5
- };
6
- console.log(`Color - R: ${color.red}, G: ${color.green}, B: ${color.blue}`);
7
- export default color;
1
+ export * from './errors/bad-request-error';
2
+ export * from './errors/custom-error';
3
+ export * from './errors/database-connection-error';
4
+ export * from './errors/not-authorized-error';
5
+ export * from './errors/not-found-error';
6
+ export * from './errors/request-validation-error';
7
+ export * from './middlewares/current-user';
8
+ export * from './middlewares/error-handler';
9
+ export * from './middlewares/require-auth';
10
+ export * from './middlewares/validate-request';
8
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,KAAK,GAAU;IACnB,GAAG,EAAE,GAAG;IACR,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,GAAG;CACV,CAAC;AAEF,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,GAAG,QAAQ,KAAK,CAAC,KAAK,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;AAE5E,eAAe,KAAK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAElD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ interface UserPayload {
3
+ id: string;
4
+ email: string;
5
+ }
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ currentUser?: UserPayload;
10
+ }
11
+ }
12
+ }
13
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
14
+ export {};
15
+ //# sourceMappingURL=current-user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.d.ts","sourceRoot":"","sources":["../../src/middlewares/current-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,UAAU,WAAW;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,WAAW,CAAC,EAAE,WAAW,CAAC;SAC3B;KACF;CACF;AAED,eAAO,MAAM,WAAW,GACtB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAkBhD,CAAA"}
@@ -0,0 +1,14 @@
1
+ import jwt from 'jsonwebtoken';
2
+ export const currentUser = (req, res, next) => {
3
+ if (!req.session?.jwt) {
4
+ return next();
5
+ }
6
+ try {
7
+ const payload = jwt.verify(req.session.jwt, process.env.JWT_KEY);
8
+ req.currentUser = payload;
9
+ }
10
+ catch (err) {
11
+ }
12
+ next();
13
+ };
14
+ //# sourceMappingURL=current-user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.js","sourceRoot":"","sources":["../../src/middlewares/current-user.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,cAAc,CAAC;AAe/B,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAY,EAAE,GAAa,EAAE,IAAkB,EAC/C,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC;QACtB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CACxB,GAAG,CAAC,OAAO,CAAC,GAAG,EACf,OAAO,CAAC,GAAG,CAAC,OAAQ,CACN,CAAC;QAEjB,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;IAEf,CAAC;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
3
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/middlewares/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,eAAO,MAAM,YAAY,GAAI,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,mDASvF,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { CustomError } from '../errors/custom-error';
2
+ export const errorHandler = (err, req, res, next) => {
3
+ //console.error('Something went wrong!', err);
4
+ if (err instanceof CustomError) {
5
+ return res.status(err.statusCode).send({ errors: err.serializeErrors() });
6
+ }
7
+ res.status(400).send({
8
+ errors: [{ message: 'Something went wrong' }]
9
+ });
10
+ };
11
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/middlewares/error-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAU,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC1F,8CAA8C;IAE9C,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;KAC9C,CAAC,CAAC;AACL,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
3
+ //# sourceMappingURL=require-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require-auth.d.ts","sourceRoot":"","sources":["../../src/middlewares/require-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,eAAO,MAAM,WAAW,GACtB,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAMhD,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { NotAuthorizedError } from '../errors/not-authorized-error';
2
+ export const requireAuth = (req, res, next) => {
3
+ if (!req.currentUser) {
4
+ throw new NotAuthorizedError();
5
+ }
6
+ next();
7
+ };
8
+ //# sourceMappingURL=require-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require-auth.js","sourceRoot":"","sources":["../../src/middlewares/require-auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAY,EAAE,GAAa,EAAE,IAAkB,EAC/C,EAAE;IACF,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response, NextFunction } from 'express';
2
+ export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void;
3
+ //# sourceMappingURL=validate-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-request.d.ts","sourceRoot":"","sources":["../../src/middlewares/validate-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI/D,eAAO,MAAM,eAAe,GAC1B,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,SAOnB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { validationResult } from 'express-validator';
2
+ import { RequestValidationError } from '../errors/request-validation-error';
3
+ export const validateRequest = (req, res, next) => {
4
+ const errors = validationResult(req);
5
+ if (!errors.isEmpty()) {
6
+ throw new RequestValidationError(errors.array());
7
+ }
8
+ next();
9
+ };
10
+ //# sourceMappingURL=validate-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-request.js","sourceRoot":"","sources":["../../src/middlewares/validate-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAAY,EACZ,GAAa,EACb,IAAkB,EAClB,EAAE;IACF,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@motway_ticketing/common",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -12,12 +12,20 @@
12
12
  "clean": "del-cli ./build/*",
13
13
  "pub": "git add . && git commit -m 'updates' && npm version patch && npm run build && npm publish"
14
14
  },
15
- "keywords": [],
16
- "author": "",
17
15
  "license": "ISC",
18
16
  "type": "module",
17
+ "peerDependencies": {
18
+ "express": "^4.0.0",
19
+ "cookie-session": "^2.0.0",
20
+ "express-validator": "^7.0.0",
21
+ "jsonwebtoken": "^9.0.0"
22
+ },
19
23
  "devDependencies": {
20
- "del-cli": "^7.0.0",
21
- "typescript": "^5.9.3"
24
+ "@types/express": "^4.17.21",
25
+ "@types/cookie-session": "^2.0.49",
26
+ "@types/jsonwebtoken": "^9.0.10",
27
+ "express-validator": "^7.3.1",
28
+ "typescript": "^5.9.3",
29
+ "del-cli": "^7.0.0"
22
30
  }
23
31
  }