@tjticketing/common 1.0.4 → 1.0.5

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,36 +1,18 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.BadRequestError = void 0;
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 = 400;
26
- Object.setPrototypeOf(_this, BadRequestError.prototype);
27
- return _this;
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 = 400;
10
+ Object.setPrototypeOf(this, BadRequestError.prototype);
28
11
  }
29
- BadRequestError.prototype.serializeErrors = function () {
12
+ serializeErrors() {
30
13
  return [{
31
14
  message: this.message,
32
15
  }];
33
- };
34
- return BadRequestError;
35
- }(custom_error_1.CustomError));
16
+ }
17
+ }
36
18
  exports.BadRequestError = BadRequestError;
@@ -1,28 +1,10 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.CustomError = void 0;
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;
4
+ class CustomError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ Object.setPrototypeOf(this, CustomError.prototype);
25
8
  }
26
- return CustomError;
27
- }(Error));
9
+ }
28
10
  exports.CustomError = CustomError;
@@ -1,34 +1,16 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.DatabaseConnectionError = void 0;
19
- var custom_error_1 = require("./custom-error");
20
- var DatabaseConnectionError = /** @class */ (function (_super) {
21
- __extends(DatabaseConnectionError, _super);
22
- function DatabaseConnectionError() {
23
- var _this = _super.call(this, 'Error connecting to DB') || this;
24
- _this.statusCode = 500;
25
- _this.reason = 'Error connecting to database';
26
- Object.setPrototypeOf(_this, DatabaseConnectionError.prototype);
27
- return _this;
4
+ const custom_error_1 = require("./custom-error");
5
+ class DatabaseConnectionError extends custom_error_1.CustomError {
6
+ constructor() {
7
+ super('Error connecting to DB');
8
+ this.statusCode = 500;
9
+ this.reason = 'Error connecting to database';
10
+ Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
28
11
  }
29
- DatabaseConnectionError.prototype.serializeErrors = function () {
12
+ serializeErrors() {
30
13
  return [{ message: this.reason }];
31
- };
32
- return DatabaseConnectionError;
33
- }(custom_error_1.CustomError));
14
+ }
15
+ }
34
16
  exports.DatabaseConnectionError = DatabaseConnectionError;
@@ -1,35 +1,17 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.NotAuthorizedError = void 0;
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;
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);
27
10
  }
28
- NotAuthorizedError.prototype.serializeErrors = function () {
11
+ serializeErrors() {
29
12
  return [{
30
13
  message: 'Not authorized'
31
14
  }];
32
- };
33
- return NotAuthorizedError;
34
- }(custom_error_1.CustomError));
15
+ }
16
+ }
35
17
  exports.NotAuthorizedError = NotAuthorizedError;
@@ -1,35 +1,17 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.NotFoundError = void 0;
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;
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);
27
10
  }
28
- NotFoundError.prototype.serializeErrors = function () {
11
+ serializeErrors() {
29
12
  return [{
30
13
  message: 'Not Found',
31
14
  }];
32
- };
33
- return NotFoundError;
34
- }(custom_error_1.CustomError));
15
+ }
16
+ }
35
17
  exports.NotFoundError = NotFoundError;
@@ -1,34 +1,17 @@
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
- })();
17
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.RequestValidationError = void 0;
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, 'Invalid request parameters') || this;
24
- _this.errors = errors;
25
- _this.statusCode = 400;
4
+ const custom_error_1 = require("./custom-error");
5
+ class RequestValidationError extends custom_error_1.CustomError {
6
+ constructor(errors) {
7
+ super('Invalid request parameters');
8
+ this.errors = errors;
9
+ this.statusCode = 400;
26
10
  // Only because we are extending a built in class
27
- Object.setPrototypeOf(_this, RequestValidationError.prototype);
28
- return _this;
11
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
29
12
  }
30
- RequestValidationError.prototype.serializeErrors = function () {
31
- return this.errors.map(function (error) {
13
+ serializeErrors() {
14
+ return this.errors.map(error => {
32
15
  if (error.type === 'field') {
33
16
  return {
34
17
  message: error.msg,
@@ -37,7 +20,6 @@ var RequestValidationError = /** @class */ (function (_super) {
37
20
  }
38
21
  return { message: error.msg };
39
22
  });
40
- };
41
- return RequestValidationError;
42
- }(custom_error_1.CustomError));
23
+ }
24
+ }
43
25
  exports.RequestValidationError = RequestValidationError;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.currentUser = void 0;
4
- var jsonwebtoken_1 = require("jsonwebtoken");
4
+ const jsonwebtoken_1 = require("jsonwebtoken");
5
5
  require("cookie-session");
6
- var currentUser = function (req, res, next) {
6
+ const currentUser = (req, res, next) => {
7
7
  var _a;
8
8
  if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
9
9
  return next();
10
10
  }
11
11
  try {
12
- var payload = (0, jsonwebtoken_1.verify)(req.session.jwt, process.env.JWT_KEY);
12
+ const payload = (0, jsonwebtoken_1.verify)(req.session.jwt, process.env.JWT_KEY);
13
13
  req.currentUser = payload;
14
14
  }
15
15
  catch (err) {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errorHandler = void 0;
4
- var custom_error_1 = require("../errors/custom-error");
5
- var errorHandler = function (err, req, res, next) {
4
+ const custom_error_1 = require("../errors/custom-error");
5
+ const errorHandler = (err, req, res, next) => {
6
6
  if (err instanceof custom_error_1.CustomError) {
7
7
  return res.status(err.statusCode).send({
8
8
  errors: err.serializeErrors()
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireAuth = void 0;
4
- var not_authorized_error_1 = require("../errors/not-authorized-error");
5
- var requireAuth = function (req, res, next) {
4
+ const not_authorized_error_1 = require("../errors/not-authorized-error");
5
+ const requireAuth = (req, res, next) => {
6
6
  if (!req.currentUser) {
7
7
  throw new not_authorized_error_1.NotAuthorizedError();
8
8
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateRequest = void 0;
4
- var express_validator_1 = require("express-validator");
5
- var request_validation_error_1 = require("../errors/request-validation-error");
6
- var validateRequest = function (req, res, next) {
7
- var errors = (0, express_validator_1.validationResult)(req);
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
8
  if (!errors.isEmpty()) {
9
9
  throw new request_validation_error_1.RequestValidationError(errors.array());
10
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tjticketing/common",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "files": [