@mehul-mrtickets/common 1.0.1 → 1.0.4

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 +9 -0
  2. package/build/errors/bad-request-error.d.ts.map +1 -0
  3. package/build/errors/bad-request-error.js +19 -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 +11 -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 +19 -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 +16 -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 +16 -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 +38 -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 +24 -7
  28. package/build/index.js.map +1 -1
  29. package/build/middlewares/current-user.d.ts +16 -0
  30. package/build/middlewares/current-user.d.ts.map +1 -0
  31. package/build/middlewares/current-user.js +23 -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 +12 -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 +12 -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 +14 -0
  44. package/build/middlewares/validate-request.js.map +1 -0
  45. package/package.json +12 -2
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class BadRequestError extends CustomError {
3
+ statusCode: number;
4
+ constructor(message: string);
5
+ serializeError(): {
6
+ message: string;
7
+ }[];
8
+ }
9
+ //# 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;IAC5C,UAAU,SAAO;IAIjB,YAAY,OAAO,EAAE,MAAM,EAI1B;IAED,cAAc;;QAEb;CACJ"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BadRequestError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class BadRequestError extends custom_error_1.CustomError {
6
+ // super(message) must be called before accessing this because BadRequestError extends the built-in Error class. In a derived class constructor, JavaScript does not allow us to access this until the parent constructor has been called.
7
+ // super(message) calls the Error constructor, initializes the parent Error object, and sets the message property. After that, this is available, so we can use Object.setPrototypeOf(this, BadRequestError.prototype) to ensure the prototype chain correctly identifies the object as a BadRequestError.
8
+ constructor(message) {
9
+ // super is kind of executed before the message we have received is assigned to this error class so if we pass this.message inside super it wouldn't have created the property at this point in time
10
+ super(message);
11
+ this.statusCode = 400;
12
+ Object.setPrototypeOf(this, BadRequestError.prototype);
13
+ }
14
+ serializeError() {
15
+ return [{ message: this.message }];
16
+ }
17
+ }
18
+ exports.BadRequestError = BadRequestError;
19
+ //# 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,iDAA6C;AAE7C,qBAA6B,SAAQ,0BAAW;IAG5C,0OAA0O;IAC1O,0SAA0S;IAC1S,YAAY,OAAe;QACvB,qMAAqM;QACrM,KAAK,CAAC,OAAO,CAAC,CAAC;QANnB,eAAU,GAAG,GAAG,CAAC;QAOb,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAED,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACtC,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ export declare abstract class CustomError extends Error {
2
+ abstract statusCode: number;
3
+ abstract serializeError(): {
4
+ message: string;
5
+ field?: string;
6
+ }[];
7
+ constructor(message: string);
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;IAC3C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,cAAc,IAAI;QACvB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,EAAE,CAAA;IACH,YAAY,OAAO,EAAE,MAAM,EAG1B;CACJ"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomError = void 0;
4
+ class CustomError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ Object.setPrototypeOf(this, CustomError.prototype);
8
+ }
9
+ }
10
+ exports.CustomError = CustomError;
11
+ //# 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,iBAAkC,SAAQ,KAAK;IAM3C,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;CACJ"}
@@ -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
+ serializeError(): {
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;IACpD,UAAU,SAAO;IACjB,MAAM,SAAkC;IACxC,cAGC;IACD,cAAc;;QAIb;CACJ"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseConnectionError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class DatabaseConnectionError extends custom_error_1.CustomError {
6
+ constructor() {
7
+ super('Error connecting to database');
8
+ this.statusCode = 500;
9
+ this.reason = "Error connecting to database";
10
+ Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
11
+ }
12
+ serializeError() {
13
+ return [
14
+ { message: this.reason }
15
+ ];
16
+ }
17
+ }
18
+ exports.DatabaseConnectionError = DatabaseConnectionError;
19
+ //# 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,iDAA6C;AAE7C,6BAAqC,SAAQ,0BAAW;IAGpD;QACI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAH1C,eAAU,GAAG,GAAG,CAAC;QACjB,WAAM,GAAG,8BAA8B,CAAC;QAGpC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC;IACD,cAAc;QACV,OAAO;YACH,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE;SAC3B,CAAA;IACL,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor(message?: string);
5
+ serializeError(): {
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;IAC/C,UAAU,EAAE,MAAM,CAAO;IACzB,YAAY,OAAO,GAAE,MAAyB,EAG7C;IACD,cAAc;;QAEb;CACJ"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAuthorizedError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class NotAuthorizedError extends custom_error_1.CustomError {
6
+ constructor(message = "Not authorized") {
7
+ super(message);
8
+ this.statusCode = 401;
9
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
10
+ }
11
+ serializeError() {
12
+ return [{ message: this.message }];
13
+ }
14
+ }
15
+ exports.NotAuthorizedError = NotAuthorizedError;
16
+ //# 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,iDAA6C;AAE7C,wBAAgC,SAAQ,0BAAW;IAE/C,YAAY,OAAO,GAAW,gBAAgB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QAFnB,eAAU,GAAW,GAAG,CAAC;QAGrB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAA;IAC7D,CAAC;IACD,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACtC,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeError(): {
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;IAC1C,UAAU,SAAO;IACjB,cAGC;IACD,cAAc;;QAEb;CACJ"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotFoundError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class NotFoundError extends custom_error_1.CustomError {
6
+ constructor() {
7
+ super('Route not found');
8
+ this.statusCode = 404;
9
+ Object.setPrototypeOf(this, NotFoundError.prototype);
10
+ }
11
+ serializeError() {
12
+ return [{ message: "Route not found" }];
13
+ }
14
+ }
15
+ exports.NotFoundError = NotFoundError;
16
+ //# 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,iDAA6C;AAE7C,mBAA2B,SAAQ,0BAAW;IAE1C;QACI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAF7B,eAAU,GAAG,GAAG,CAAC;QAGb,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IACD,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAA;IAC3C,CAAC;CACJ"}
@@ -0,0 +1,15 @@
1
+ import { 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
+ serializeError(): ({
8
+ message: any;
9
+ field: string;
10
+ } | {
11
+ field?: undefined;
12
+ message: any;
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,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAqB7C,qBAAa,sBAAuB,SAAQ,WAAW;IAEhC,MAAM,EAAE,eAAe,EAAE;IAD5C,UAAU,SAAO;IACjB,YAAmB,MAAM,EAAE,eAAe,EAAE,EAI3C;IAED,cAAc;;;;;;SAOb;CAEJ"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestValidationError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ //Why we are using abstract class instead of interface is because if we use interface we are going to implement and not extend so in our error-handler middleware we will have to check if err instance of all the possible types of errors we are going to handle in our app so instead of writing this much checks for every error we can just extend and abstract class customError and then in our middleware we can just check if err instance of and as all the custom error class will be implementing that abstract class eventually they all will have same structure and will be instance of CustomErrors class only so we will just need to add one if statement instead of many
6
+ // We use an abstract class instead of an interface because we want to leverage class inheritance and runtime instanceof checks.
7
+ // If we used an interface, the custom errors would implement that interface, but interfaces don't exist at runtime in TypeScript. So in our error-handling middleware, we couldn't simply do err instanceof CustomError. We would potentially need to check for each specific error type individually.
8
+ // By having all our custom error classes extend a common abstract CustomError class, they share the same structure and, more importantly, they are all runtime instances of CustomError.
9
+ // So our middleware can simply do:
10
+ // if (err instanceof CustomError) {
11
+ // // handle all our custom application errors
12
+ // }
13
+ // This gives us a single common check instead of having separate instanceof checks for every custom error type.
14
+ // interface CustomErrors {
15
+ // statusCode: number
16
+ // serializeError(): {
17
+ // message: string;
18
+ // field?: string;
19
+ // }[]
20
+ // }
21
+ class RequestValidationError extends custom_error_1.CustomError {
22
+ constructor(errors) {
23
+ super('Invalid request parameters');
24
+ this.errors = errors;
25
+ this.statusCode = 400;
26
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
27
+ }
28
+ serializeError() {
29
+ return this.errors.map((error) => {
30
+ if (error.type === 'field') {
31
+ return { message: error.msg, field: error.path };
32
+ }
33
+ return { message: error.msg };
34
+ });
35
+ }
36
+ }
37
+ exports.RequestValidationError = RequestValidationError;
38
+ //# 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,iDAA6C;AAE7C,6pBAA6pB;AAE7pB,gIAAgI;AAChI,uSAAuS;AACvS,yLAAyL;AACzL,mCAAmC;AACnC,oCAAoC;AACpC,gDAAgD;AAChD,IAAI;AACJ,gHAAgH;AAEhH,2BAA2B;AAC3B,yBAAyB;AACzB,0BAA0B;AAC1B,2BAA2B;AAC3B,0BAA0B;AAC1B,UAAU;AACV,IAAI;AAEJ,4BAAoC,SAAQ,0BAAW;IAEnD,YAAmB,MAAyB;QACxC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QADrB,WAAM,GAAN,MAAM,CAAmB;QAD5C,eAAU,GAAG,GAAG,CAAC;QAGb,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAElE,CAAC;IAED,cAAc;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACzB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;YACrD,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,CAAA;QACjC,CAAC,CAAC,CAAC;IACP,CAAC;CAEJ"}
package/build/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- interface Color {
2
- red: number;
3
- blue: number;
4
- green: 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/not-authorized-error";
4
+ export * from "./errors/not-found-error";
5
+ export * from "./errors/database-connection-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;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,QAAA,MAAM,KAAK,EAAE,KAIZ,CAAA;eAIc,KAAK"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oCAAoC,CAAC;AACnD,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,10 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const color = {
4
- red: 10,
5
- green: 20,
6
- blue: 35
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
7
15
  };
8
- console.log(color);
9
- exports.default = color;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors/bad-request-error"), exports);
18
+ __exportStar(require("./errors/custom-error"), exports);
19
+ __exportStar(require("./errors/not-authorized-error"), exports);
20
+ __exportStar(require("./errors/not-found-error"), exports);
21
+ __exportStar(require("./errors/database-connection-error"), exports);
22
+ __exportStar(require("./errors/request-validation-error"), exports);
23
+ __exportStar(require("./middlewares/current-user"), exports);
24
+ __exportStar(require("./middlewares/error-handler"), exports);
25
+ __exportStar(require("./middlewares/require-auth"), exports);
26
+ __exportStar(require("./middlewares/validate-request"), exports);
10
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAMA,MAAM,KAAK,GAAU;IACjB,GAAG,EAAE,EAAE;IACP,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;CACX,CAAA;AAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;kBAEH,KAAK"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,wDAAsC;AACtC,gEAA8C;AAC9C,2DAAyC;AACzC,qEAAmD;AACnD,oEAAkD;AAElD,6DAA2C;AAC3C,8DAA4C;AAC5C,6DAA2C;AAC3C,iEAA+C"}
@@ -0,0 +1,16 @@
1
+ import { NextFunction, Request, Response } 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
+ session?: any;
11
+ }
12
+ }
13
+ }
14
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
15
+ export {};
16
+ //# 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,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D,UAAU,WAAW;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,WAAW,CAAC,EAAE,WAAW,CAAC;YAC1B,OAAO,CAAC,EAAE,GAAG,CAAC;SACjB;KACJ;CACJ;AAED,eAAO,MAAM,WAAW,QAAS,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAW1E,CAAA"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.currentUser = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const currentUser = (req, res, next) => {
9
+ if (!req.session?.jwt) {
10
+ return next();
11
+ }
12
+ try {
13
+ const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
14
+ req.currentUser = payload;
15
+ }
16
+ catch (err) {
17
+ }
18
+ finally {
19
+ next();
20
+ }
21
+ };
22
+ exports.currentUser = currentUser;
23
+ //# 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,gEAA8B;AAgBvB,MAAM,WAAW,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC3E,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC;QACpB,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC;IACD,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,sBAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAgB,CAAC;QACjF,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC;IAC9B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;YAAS,CAAC;QACP,IAAI,EAAE,CAAC;IACX,CAAC;AACL,CAAC,CAAA;AAXY,QAAA,WAAW,GAAX,WAAW,CAWvB"}
@@ -0,0 +1,3 @@
1
+ import { NextFunction, Request, Response } from "express";
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>>;
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,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG1D,eAAO,MAAM,YAAY,QAAS,KAAK,OAAO,OAAO,OAAO,QAAQ,QAAQ,YAAY,uCAMvF,CAAA"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorHandler = void 0;
4
+ const custom_error_1 = require("../errors/custom-error");
5
+ const errorHandler = (err, req, res, next) => {
6
+ if (err instanceof custom_error_1.CustomError) {
7
+ return res.status(err.statusCode).send({ errors: err.serializeError() });
8
+ }
9
+ return res.status(500).send({ errors: [{ message: "Something went wrong!!!" }] });
10
+ };
11
+ exports.errorHandler = errorHandler;
12
+ //# 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,yDAAqD;AAE9C,MAAM,YAAY,GAAG,CAAC,GAAU,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxF,IAAI,GAAG,YAAY,0BAAW,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC,EAAE,CAAC,CAAA;AACrF,CAAC,CAAA;AANY,QAAA,YAAY,GAAZ,YAAY,CAMxB"}
@@ -0,0 +1,3 @@
1
+ import { 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,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D,eAAO,MAAM,WAAW,QAAS,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAM1E,CAAA"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireAuth = void 0;
4
+ const not_authorized_error_1 = require("../errors/not-authorized-error");
5
+ const requireAuth = (req, res, next) => {
6
+ if (!req.currentUser) {
7
+ throw new not_authorized_error_1.NotAuthorizedError();
8
+ }
9
+ next();
10
+ };
11
+ exports.requireAuth = requireAuth;
12
+ //# 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,yEAAoE;AAG7D,MAAM,WAAW,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC3E,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACnB,MAAM,IAAI,yCAAkB,EAAE,CAAC;IACnC,CAAC;IACD,IAAI,EAAE,CAAC;AAEX,CAAC,CAAA;AANY,QAAA,WAAW,GAAX,WAAW,CAMvB"}
@@ -0,0 +1,3 @@
1
+ import { 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,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI1D,eAAO,MAAM,eAAe,QAAS,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAO9E,CAAA"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRequest = void 0;
4
+ const express_validator_1 = require("express-validator");
5
+ const request_validation_error_1 = require("../errors/request-validation-error");
6
+ const validateRequest = (req, res, next) => {
7
+ const errors = (0, express_validator_1.validationResult)(req);
8
+ if (!errors.isEmpty()) {
9
+ throw new request_validation_error_1.RequestValidationError(errors.array());
10
+ }
11
+ next();
12
+ };
13
+ exports.validateRequest = validateRequest;
14
+ //# 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,yDAAqD;AACrD,iFAA4E;AAErE,MAAM,eAAe,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC/E,MAAM,MAAM,GAAG,IAAA,oCAAgB,EAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACpB,MAAM,IAAI,iDAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,EAAE,CAAC;AAEX,CAAC,CAAA;AAPY,QAAA,eAAe,GAAf,eAAe,CAO3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mehul-mrtickets/common",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "scripts": {
13
13
  "clean": "del-cli --force ./build/*",
14
- "build": "npm run clean && tsc"
14
+ "build": "npm run clean && tsc",
15
+ "pub": "npm version patch && npm run build && npm publish --access public"
15
16
  },
16
17
  "keywords": [],
17
18
  "author": "",
@@ -20,5 +21,14 @@
20
21
  "devDependencies": {
21
22
  "del-cli": "^7.0.0",
22
23
  "typescript": "^7.0.2"
24
+ },
25
+ "dependencies": {
26
+ "@types/cookie-session": "^2.0.49",
27
+ "@types/express": "^5.0.6",
28
+ "@types/jsonwebtoken": "^9.0.10",
29
+ "cookie-session": "^2.1.1",
30
+ "express": "^5.2.1",
31
+ "express-validator": "^7.3.2",
32
+ "jsonwebtoken": "^9.0.3"
23
33
  }
24
34
  }