@bonnethood/common
Advanced tools
@@ -1,2 +0,2 @@ | ||
| import { CustomError } from './custom-error'; | ||
| import { CustomError } from "./custom-error"; | ||
| export declare class BadRequestError extends CustomError { | ||
@@ -3,0 +3,0 @@ message: string; |
@@ -16,4 +16,4 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.BadRequestError = void 0; | ||
| var custom_error_1 = require("./custom-error"); | ||
| // BadRequestError is adding up to CustomError | ||
| var BadRequestError = /** @class */ (function (_super) { | ||
@@ -25,2 +25,3 @@ __extends(BadRequestError, _super); | ||
| _this.statusCode = 400; | ||
| // extend a JS class | ||
| Object.setPrototypeOf(_this, BadRequestError.prototype); | ||
@@ -27,0 +28,0 @@ return _this; |
@@ -16,7 +16,9 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.CustomError = void 0; | ||
| var CustomError = /** @class */ (function (_super) { | ||
| __extends(CustomError, _super); | ||
| // Require to extends a class | ||
| function CustomError(message) { | ||
| var _this = _super.call(this, message) || this; | ||
| var _this = | ||
| // Require | ||
| _super.call(this, message) || this; | ||
| Object.setPrototypeOf(_this, CustomError.prototype); | ||
@@ -23,0 +25,0 @@ return _this; |
@@ -1,2 +0,2 @@ | ||
| import { CustomError } from './custom-error'; | ||
| import { CustomError } from "./custom-error"; | ||
| export declare class DatabaseConnectionError extends CustomError { | ||
@@ -3,0 +3,0 @@ statusCode: number; |
@@ -16,3 +16,2 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.DatabaseConnectionError = void 0; | ||
| var custom_error_1 = require("./custom-error"); | ||
@@ -22,5 +21,8 @@ var DatabaseConnectionError = /** @class */ (function (_super) { | ||
| function DatabaseConnectionError() { | ||
| var _this = _super.call(this, 'Error connecting to db') || this; | ||
| var _this = _super.call(this, "DB in super") || this; | ||
| // Error code return | ||
| _this.statusCode = 500; | ||
| _this.reason = 'Error connecting to database'; | ||
| // this.reason data | ||
| _this.reason = "DB connection module"; | ||
| // Extend a class | ||
| Object.setPrototypeOf(_this, DatabaseConnectionError.prototype); | ||
@@ -27,0 +29,0 @@ return _this; |
@@ -1,2 +0,2 @@ | ||
| import { CustomError } from './custom-error'; | ||
| import { CustomError } from "./custom-error"; | ||
| export declare class NotAuthorizedError extends CustomError { | ||
@@ -3,0 +3,0 @@ statusCode: number; |
@@ -16,3 +16,2 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NotAuthorizedError = void 0; | ||
| var custom_error_1 = require("./custom-error"); | ||
@@ -22,3 +21,3 @@ var NotAuthorizedError = /** @class */ (function (_super) { | ||
| function NotAuthorizedError() { | ||
| var _this = _super.call(this, 'Not Authorized') || this; | ||
| var _this = _super.call(this, "Not Authorized") || this; | ||
| _this.statusCode = 401; | ||
@@ -29,3 +28,3 @@ Object.setPrototypeOf(_this, NotAuthorizedError.prototype); | ||
| NotAuthorizedError.prototype.serializeErrors = function () { | ||
| return [{ message: 'Not authorized' }]; | ||
| return [{ message: "Not authorized" }]; | ||
| }; | ||
@@ -32,0 +31,0 @@ return NotAuthorizedError; |
@@ -1,2 +0,2 @@ | ||
| import { CustomError } from './custom-error'; | ||
| import { CustomError } from "./custom-error"; | ||
| export declare class NotFoundError extends CustomError { | ||
@@ -3,0 +3,0 @@ statusCode: number; |
@@ -16,3 +16,2 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NotFoundError = void 0; | ||
| var custom_error_1 = require("./custom-error"); | ||
@@ -22,3 +21,3 @@ var NotFoundError = /** @class */ (function (_super) { | ||
| function NotFoundError() { | ||
| var _this = _super.call(this, 'Route not found') || this; | ||
| var _this = _super.call(this, "Route not found") || this; | ||
| _this.statusCode = 404; | ||
@@ -29,3 +28,3 @@ Object.setPrototypeOf(_this, NotFoundError.prototype); | ||
| NotFoundError.prototype.serializeErrors = function () { | ||
| return [{ message: 'Not Found' }]; | ||
| return [{ message: "Not found" }]; | ||
| }; | ||
@@ -32,0 +31,0 @@ return NotFoundError; |
@@ -1,3 +0,3 @@ | ||
| import { ValidationError } from 'express-validator'; | ||
| import { CustomError } from './custom-error'; | ||
| import { CustomError } from "./custom-error"; | ||
| import { ValidationError } from "express-validator"; | ||
| export declare class RequestValidationError extends CustomError { | ||
@@ -4,0 +4,0 @@ errors: ValidationError[]; |
@@ -16,3 +16,2 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.RequestValidationError = void 0; | ||
| var custom_error_1 = require("./custom-error"); | ||
@@ -22,6 +21,6 @@ var RequestValidationError = /** @class */ (function (_super) { | ||
| function RequestValidationError(errors) { | ||
| var _this = _super.call(this, 'Invalid request parameters') || this; | ||
| var _this = _super.call(this, "REQ in super") || this; | ||
| _this.errors = errors; | ||
| _this.statusCode = 400; | ||
| // Only because we are extending a built in class | ||
| // Extend a class | ||
| Object.setPrototypeOf(_this, RequestValidationError.prototype); | ||
@@ -28,0 +27,0 @@ return _this; |
+10
-10
@@ -1,10 +0,10 @@ | ||
| export * from './errors/bad-request-error'; | ||
| export * from './errors/custom-error'; | ||
| export * from './errors/database-connection-error'; | ||
| export * from './errors/not-authorized-error'; | ||
| export * from './errors/not-found-error'; | ||
| export * from './errors/request-validation-error'; | ||
| export * from './middlewares/current-user'; | ||
| export * from './middlewares/error-handler'; | ||
| export * from './middlewares/require-auth'; | ||
| export * from './middlewares/validate-request'; | ||
| export * from "./errors/bad-request-error"; | ||
| export * from "./errors/custom-error"; | ||
| export * from "./errors/database-connection-error"; | ||
| export * from "./errors/not-authorized-error"; | ||
| export * from "./errors/not-found-error"; | ||
| export * from "./errors/request-validation-error"; | ||
| export * from "./middlewares/current-user"; | ||
| export * from "./middlewares/error-handler"; | ||
| export * from "./middlewares/require-auth"; | ||
| export * from "./middlewares/validate-request"; |
+13
-21
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
| }; | ||
| function __export(m) { | ||
| for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
| } | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| // Re-export stuff from errors and middlewares | ||
| __exportStar(require("./errors/bad-request-error"), exports); | ||
| __exportStar(require("./errors/custom-error"), exports); | ||
| __exportStar(require("./errors/database-connection-error"), exports); | ||
| __exportStar(require("./errors/not-authorized-error"), exports); | ||
| __exportStar(require("./errors/not-found-error"), exports); | ||
| __exportStar(require("./errors/request-validation-error"), exports); | ||
| __exportStar(require("./middlewares/current-user"), exports); | ||
| __exportStar(require("./middlewares/error-handler"), exports); | ||
| __exportStar(require("./middlewares/require-auth"), exports); | ||
| __exportStar(require("./middlewares/validate-request"), exports); | ||
| __export(require("./errors/bad-request-error")); | ||
| __export(require("./errors/custom-error")); | ||
| __export(require("./errors/database-connection-error")); | ||
| __export(require("./errors/not-authorized-error")); | ||
| __export(require("./errors/not-found-error")); | ||
| __export(require("./errors/request-validation-error")); | ||
| __export(require("./middlewares/current-user")); | ||
| __export(require("./middlewares/error-handler")); | ||
| __export(require("./middlewares/require-auth")); | ||
| __export(require("./middlewares/validate-request")); |
@@ -1,2 +0,2 @@ | ||
| import { Request, Response, NextFunction } from 'express'; | ||
| import { Request, Response, NextFunction } from "express"; | ||
| interface UserPayload { | ||
@@ -13,3 +13,3 @@ id: string; | ||
| } | ||
| export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void; | ||
| export declare const currentUser: (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("express-serve-static-core").Query>, res: Response<any>, next: NextFunction) => void; | ||
| export {}; |
@@ -6,3 +6,2 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.currentUser = void 0; | ||
| var jsonwebtoken_1 = __importDefault(require("jsonwebtoken")); | ||
@@ -9,0 +8,0 @@ exports.currentUser = function (req, res, next) { |
| import { Request, Response, NextFunction } from "express"; | ||
| export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined; | ||
| export declare const errorHandler: (err: Error, req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("express-serve-static-core").Query>, res: Response<any>, next: NextFunction) => Response<any> | undefined; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.errorHandler = void 0; | ||
| // Middleware error handler | ||
| var custom_error_1 = require("../errors/custom-error"); | ||
| exports.errorHandler = function (err, req, res, next) { | ||
| // Uniform return errors | ||
| // https://en.wikipedia.org/wiki/List_of_HTTP_status_codes - 500 internal error or 503 | ||
| if (err instanceof custom_error_1.CustomError) { | ||
| // 400 user sent bad data | ||
| // console.log(err) | ||
| return res.status(err.statusCode).send({ errors: err.serializeErrors() }); | ||
| } | ||
| // Logging errors | ||
| console.log(err); | ||
| // Return | ||
| res.status(400).send({ | ||
| errors: [{ message: "Something went wrong" }], | ||
| message: "Something went wrong", | ||
| }); | ||
| }; |
@@ -1,2 +0,2 @@ | ||
| import { Request, Response, NextFunction } from 'express'; | ||
| export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void; | ||
| import { Request, Response, NextFunction } from "express"; | ||
| export declare const requireAuth: (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("express-serve-static-core").Query>, res: Response<any>, next: NextFunction) => void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.requireAuth = void 0; | ||
| var not_authorized_error_1 = require("../errors/not-authorized-error"); | ||
@@ -5,0 +4,0 @@ exports.requireAuth = function (req, res, next) { |
@@ -1,2 +0,2 @@ | ||
| import { Request, Response, NextFunction } from 'express'; | ||
| export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void; | ||
| import { Request, Response, NextFunction } from "express"; | ||
| export declare const validateRequest: (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("express-serve-static-core").Query>, res: Response<any>, next: NextFunction) => void; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.validateRequest = void 0; | ||
| var express_validator_1 = require("express-validator"); | ||
@@ -5,0 +4,0 @@ var request_validation_error_1 = require("../errors/request-validation-error"); |
+3
-2
| { | ||
| "name": "@bonnethood/common", | ||
| "version": "1.0.12", | ||
| "version": "1.0.14", | ||
| "description": "", | ||
@@ -29,4 +29,5 @@ "main": "./build/index.js", | ||
| "express-validator": "^6.4.0", | ||
| "jsonwebtoken": "^8.5.1" | ||
| "jsonwebtoken": "^8.5.1", | ||
| "node-nats-streaming": "^0.3.2" | ||
| } | ||
| } |
14508
-1.04%8
14.29%341
-2.29%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added