@aichatwar/shared 1.0.6 → 1.0.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aichatwar/shared",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "./build/index.js",
5
5
  "typs": "./build/index.d.ts",
6
6
  "files": [
@@ -1,2 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorHandler = void 0;
4
- const customError_1 = require("../errors/customError");
5
- `common structure for errors:
6
- {
7
- errors:{
8
- message: string, field?: string
9
- }[]
10
- }
11
- `;
12
- const errorHandler = (err, req, res, next) => {
13
- console.log("Error:", err);
14
- if (err instanceof customError_1.CustomError) {
15
- return res.status(err.statusCode).send({ errors: err.serializeDetails() });
16
- }
17
- return res.status(400).send({
18
- errors: [{ message: "an error occurred!" }]
19
- });
20
- };
21
- exports.errorHandler = errorHandler;
@@ -1,14 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- interface JwtPayload {
3
- id: string;
4
- email: string;
5
- }
6
- declare global {
7
- namespace Express {
8
- interface Request {
9
- jwtPayload?: JwtPayload;
10
- }
11
- }
12
- }
13
- declare const extractJWTPayload: (req: Request, res: Response, next: NextFunction) => void;
14
- export { extractJWTPayload };
@@ -1,25 +0,0 @@
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.extractJWTPayload = void 0;
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- ;
9
- const extractJWTPayload = (req, res, next) => {
10
- var _a;
11
- if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
12
- return next();
13
- }
14
- else {
15
- try {
16
- const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_DEV);
17
- req.jwtPayload = payload;
18
- }
19
- catch (error) {
20
- console.log(error.message);
21
- }
22
- next();
23
- }
24
- };
25
- exports.extractJWTPayload = extractJWTPayload;
@@ -1,3 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- declare const loginRequired: (req: Request, res: Response, next: NextFunction) => Promise<void>;
3
- export { loginRequired };
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.loginRequired = void 0;
13
- const notAuthorizedError_1 = require("../errors/notAuthorizedError");
14
- const loginRequired = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
- if (!req.jwtPayload) {
16
- throw new notAuthorizedError_1.NotAuthorizedError(['not authorized']);
17
- }
18
- else {
19
- next();
20
- }
21
- });
22
- exports.loginRequired = loginRequired;
@@ -1,2 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- export declare const validateRequest: (req: Request, res: Response, next: NextFunction) => void;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateRequest = void 0;
4
- const requestValidationError_1 = require("../errors/requestValidationError");
5
- const express_validator_1 = require("express-validator");
6
- const validateRequest = (req, res, next) => {
7
- const errors = (0, express_validator_1.validationResult)(req);
8
- if (!errors.isEmpty()) {
9
- throw new requestValidationError_1.RequestValidationError(errors.array());
10
- }
11
- else {
12
- next();
13
- }
14
- };
15
- exports.validateRequest = validateRequest;