bemoore-be-ticketing-common 1.0.0 → 1.0.2

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.
@@ -1,16 +1,34 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.BadRequestError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class BadRequestError extends custom_error_1.CustomError {
6
- constructor(message) {
7
- super(message);
8
- this.message = message;
9
- this.statusCode = 500;
10
- Object.setPrototypeOf(this, BadRequestError.prototype);
19
+ var custom_error_1 = require("./custom-error");
20
+ var BadRequestError = /** @class */ (function (_super) {
21
+ __extends(BadRequestError, _super);
22
+ function BadRequestError(message) {
23
+ var _this = _super.call(this, message) || this;
24
+ _this.message = message;
25
+ _this.statusCode = 500;
26
+ Object.setPrototypeOf(_this, BadRequestError.prototype);
27
+ return _this;
11
28
  }
12
- serializeErrors() {
29
+ BadRequestError.prototype.serializeErrors = function () {
13
30
  return [{ message: this.message }];
14
- }
15
- }
31
+ };
32
+ return BadRequestError;
33
+ }(custom_error_1.CustomError));
16
34
  exports.BadRequestError = BadRequestError;
@@ -1,10 +1,28 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.CustomError = void 0;
4
- class CustomError extends Error {
5
- constructor(message) {
6
- super(message);
7
- Object.setPrototypeOf(this, CustomError.prototype);
19
+ var CustomError = /** @class */ (function (_super) {
20
+ __extends(CustomError, _super);
21
+ function CustomError(message) {
22
+ var _this = _super.call(this, message) || this;
23
+ Object.setPrototypeOf(_this, CustomError.prototype);
24
+ return _this;
8
25
  }
9
- }
26
+ return CustomError;
27
+ }(Error));
10
28
  exports.CustomError = CustomError;
@@ -1,16 +1,34 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.DatabaseConnextionError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class DatabaseConnextionError extends custom_error_1.CustomError {
6
- constructor() {
7
- super('Error connecting to db!');
8
- this.reason = 'Unable to connect to database';
9
- this.statusCode = 500;
10
- this.serializeErrors = () => {
11
- return [{ message: this.reason }];
19
+ var custom_error_1 = require("./custom-error");
20
+ var DatabaseConnextionError = /** @class */ (function (_super) {
21
+ __extends(DatabaseConnextionError, _super);
22
+ function DatabaseConnextionError() {
23
+ var _this = _super.call(this, 'Error connecting to db!') || this;
24
+ _this.reason = 'Unable to connect to database';
25
+ _this.statusCode = 500;
26
+ _this.serializeErrors = function () {
27
+ return [{ message: _this.reason }];
12
28
  };
13
- Object.setPrototypeOf(this, DatabaseConnextionError.prototype);
29
+ Object.setPrototypeOf(_this, DatabaseConnextionError.prototype);
30
+ return _this;
14
31
  }
15
- }
32
+ return DatabaseConnextionError;
33
+ }(custom_error_1.CustomError));
16
34
  exports.DatabaseConnextionError = DatabaseConnextionError;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestValidationError = exports.NotFoundError = exports.NotAuthorizedError = exports.DatabaseConnextionError = exports.CustomError = exports.BadRequestError = void 0;
4
- const bad_request_error_1 = require("./bad-request-error");
4
+ var bad_request_error_1 = require("./bad-request-error");
5
5
  Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return bad_request_error_1.BadRequestError; } });
6
- const custom_error_1 = require("./custom-error");
6
+ var custom_error_1 = require("./custom-error");
7
7
  Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } });
8
- const database_connection_error_1 = require("./database-connection-error");
8
+ var database_connection_error_1 = require("./database-connection-error");
9
9
  Object.defineProperty(exports, "DatabaseConnextionError", { enumerable: true, get: function () { return database_connection_error_1.DatabaseConnextionError; } });
10
- const not_authorized_1 = require("./not-authorized");
10
+ var not_authorized_1 = require("./not-authorized");
11
11
  Object.defineProperty(exports, "NotAuthorizedError", { enumerable: true, get: function () { return not_authorized_1.NotAuthorizedError; } });
12
- const not_found_error_1 = require("./not-found-error");
12
+ var not_found_error_1 = require("./not-found-error");
13
13
  Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return not_found_error_1.NotFoundError; } });
14
- const request_validation_error_1 = require("./request-validation-error");
14
+ var request_validation_error_1 = require("./request-validation-error");
15
15
  Object.defineProperty(exports, "RequestValidationError", { enumerable: true, get: function () { return request_validation_error_1.RequestValidationError; } });
@@ -1,15 +1,33 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.NotAuthorizedError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class NotAuthorizedError extends custom_error_1.CustomError {
6
- constructor() {
7
- super('Not authorized');
8
- this.statusCode = 401;
9
- Object.setPrototypeOf(this, NotAuthorizedError.prototype);
19
+ var custom_error_1 = require("./custom-error");
20
+ var NotAuthorizedError = /** @class */ (function (_super) {
21
+ __extends(NotAuthorizedError, _super);
22
+ function NotAuthorizedError() {
23
+ var _this = _super.call(this, 'Not authorized') || this;
24
+ _this.statusCode = 401;
25
+ Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
26
+ return _this;
10
27
  }
11
- serializeErrors() {
28
+ NotAuthorizedError.prototype.serializeErrors = function () {
12
29
  return [{ message: 'Not authorized' }];
13
- }
14
- }
30
+ };
31
+ return NotAuthorizedError;
32
+ }(custom_error_1.CustomError));
15
33
  exports.NotAuthorizedError = NotAuthorizedError;
@@ -1,15 +1,33 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  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);
19
+ var custom_error_1 = require("./custom-error");
20
+ var NotFoundError = /** @class */ (function (_super) {
21
+ __extends(NotFoundError, _super);
22
+ function NotFoundError() {
23
+ var _this = _super.call(this, 'Route not found') || this;
24
+ _this.statusCode = 404;
25
+ Object.setPrototypeOf(_this, NotFoundError.prototype);
26
+ return _this;
10
27
  }
11
- serializeErrors() {
28
+ NotFoundError.prototype.serializeErrors = function () {
12
29
  return [{ message: 'Not Found' }];
13
- }
14
- }
30
+ };
31
+ return NotFoundError;
32
+ }(custom_error_1.CustomError));
15
33
  exports.NotFoundError = NotFoundError;
@@ -1,20 +1,38 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.RequestValidationError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class RequestValidationError extends custom_error_1.CustomError {
6
- constructor(errors) {
7
- super('Validation Error occured!');
8
- this.errors = errors;
9
- this.statusCode = 400;
10
- this.serializeErrors = () => {
11
- return this.errors.map((error) => {
19
+ var custom_error_1 = require("./custom-error");
20
+ var RequestValidationError = /** @class */ (function (_super) {
21
+ __extends(RequestValidationError, _super);
22
+ function RequestValidationError(errors) {
23
+ var _this = _super.call(this, 'Validation Error occured!') || this;
24
+ _this.errors = errors;
25
+ _this.statusCode = 400;
26
+ _this.serializeErrors = function () {
27
+ return _this.errors.map(function (error) {
12
28
  if (error.type === 'field') {
13
29
  return { message: error.msg, field: error.path };
14
30
  }
15
31
  return { message: error.msg };
16
32
  });
17
33
  };
34
+ return _this;
18
35
  }
19
- }
36
+ return RequestValidationError;
37
+ }(custom_error_1.CustomError));
20
38
  exports.RequestValidationError = RequestValidationError;
@@ -0,0 +1,3 @@
1
+ export * from './errors';
2
+ export * from './middlewares';
3
+ export * from './middlewares';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
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);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors"), exports);
18
+ __exportStar(require("./middlewares"), exports);
19
+ __exportStar(require("./middlewares"), exports);
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.currentUser = void 0;
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- const currentUser = (req, res, next) => {
7
+ var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ var currentUser = function (req, res, next) {
9
9
  var _a;
10
10
  if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt))
11
11
  return next();
12
12
  try {
13
- const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
13
+ var payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
14
14
  req.currentUser = payload;
15
15
  }
16
16
  catch (error) { }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errorHandler = void 0;
4
- const errors_1 = require("../errors");
5
- const errorHandler = (err, req, res, next) => {
4
+ var errors_1 = require("../errors");
5
+ var errorHandler = function (err, req, res, next) {
6
6
  if (err instanceof errors_1.CustomError) {
7
7
  return res.status(err.statusCode).send({
8
8
  errors: err.serializeErrors(),
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireAuth = exports.errorHandler = exports.currentUser = void 0;
4
- const current_user_1 = require("./current-user");
4
+ var current_user_1 = require("./current-user");
5
5
  Object.defineProperty(exports, "currentUser", { enumerable: true, get: function () { return current_user_1.currentUser; } });
6
- const error_handler_1 = require("./error-handler");
6
+ var error_handler_1 = require("./error-handler");
7
7
  Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return error_handler_1.errorHandler; } });
8
- const require_auth_1 = require("./require-auth");
8
+ var require_auth_1 = require("./require-auth");
9
9
  Object.defineProperty(exports, "requireAuth", { enumerable: true, get: function () { return require_auth_1.requireAuth; } });
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireAuth = void 0;
4
- const not_authorized_1 = require("../errors/not-authorized");
5
- const requireAuth = (req, res, next) => {
4
+ var not_authorized_1 = require("../errors/not-authorized");
5
+ var requireAuth = function (req, res, next) {
6
6
  if (!req.currentUser) {
7
7
  throw new not_authorized_1.NotAuthorizedError();
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bemoore-be-ticketing-common",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsc"
11
+ "build": "tsc --skipLibCheck"
12
12
  },
13
13
  "keywords": [
14
14
  "typescript",
@@ -26,4 +26,4 @@
26
26
  "jsonwebtoken": "^9.0.2",
27
27
  "typescript": "^5.7.2"
28
28
  }
29
- }
29
+ }