@lta.anluu/common 1.0.1 → 1.0.3

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 +10 -0
  2. package/build/errors/bad-request-error.d.ts.map +1 -0
  3. package/build/errors/bad-request-error.js +14 -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 +7 -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 +13 -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 +12 -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 +12 -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 +19 -0
  24. package/build/errors/request-validation-error.js.map +1 -0
  25. package/build/index.d.ts +10 -1
  26. package/build/index.d.ts.map +1 -1
  27. package/build/index.js +10 -8
  28. package/build/index.js.map +1 -1
  29. package/build/middlewares/current-user.d.ts +18 -0
  30. package/build/middlewares/current-user.d.ts.map +1 -0
  31. package/build/middlewares/current-user.js +13 -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 +8 -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 +10 -0
  44. package/build/middlewares/validate-request.js.map +1 -0
  45. package/package.json +12 -2
@@ -0,0 +1,10 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class BadRequestError extends CustomError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
10
+ //# 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;IAG3B,OAAO,EAAE,MAAM;IAFlC,UAAU,SAAO;gBAEE,OAAO,EAAE,MAAM;IAKlC,eAAe;;;CAGhB"}
@@ -0,0 +1,14 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class BadRequestError extends CustomError {
3
+ message;
4
+ statusCode = 400;
5
+ constructor(message) {
6
+ super(message);
7
+ this.message = message;
8
+ Object.setPrototypeOf(this, BadRequestError.prototype);
9
+ }
10
+ serializeErrors() {
11
+ return [{ message: this.message }];
12
+ }
13
+ }
14
+ //# 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAG3B;IAFnB,UAAU,GAAG,GAAG,CAAC;IAEjB,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAEhC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export declare abstract class CustomError extends Error {
2
+ abstract readonly statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): {
5
+ message: string;
6
+ field?: string;
7
+ }[];
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;IAC7C,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;gBAEzB,OAAO,EAAE,MAAM;IAK3B,QAAQ,CAAC,eAAe,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;CAClE"}
@@ -0,0 +1,7 @@
1
+ export class CustomError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ Object.setPrototypeOf(this, CustomError.prototype);
5
+ }
6
+ }
7
+ //# 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,MAAM,OAAgB,WAAY,SAAQ,KAAK;IAG7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;CAGF"}
@@ -0,0 +1,10 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class DatabaseConnectionError extends CustomError {
3
+ readonly statusCode = 500;
4
+ readonly reason = "Error connecting to database";
5
+ constructor();
6
+ serializeErrors(): {
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;IACtD,QAAQ,CAAC,UAAU,OAAO;IAC1B,QAAQ,CAAC,MAAM,kCAAkC;;IAQjD,eAAe;;;CAGhB"}
@@ -0,0 +1,13 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class DatabaseConnectionError extends CustomError {
3
+ statusCode = 500;
4
+ reason = "Error connecting to database";
5
+ constructor() {
6
+ super('Error connecting to database');
7
+ Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
8
+ }
9
+ serializeErrors() {
10
+ return [{ message: this.reason }];
11
+ }
12
+ }
13
+ //# 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IAC7C,UAAU,GAAG,GAAG,CAAC;IACjB,MAAM,GAAG,8BAA8B,CAAC;IAEjD;QACE,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAEtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
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;IACjD,UAAU,SAAO;;IAQjB,eAAe;;;CAGhB"}
@@ -0,0 +1,12 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class NotAuthorizedError extends CustomError {
3
+ statusCode = 401;
4
+ constructor() {
5
+ super("Not authorized");
6
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
7
+ }
8
+ serializeErrors() {
9
+ return [{ message: "Not authorized" }];
10
+ }
11
+ }
12
+ //# 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACjD,UAAU,GAAG,GAAG,CAAC;IAEjB;QACE,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAExB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
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;IAC5C,UAAU,SAAO;;IAQjB,eAAe;;;CAGhB"}
@@ -0,0 +1,12 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class NotFoundError extends CustomError {
3
+ statusCode = 404;
4
+ constructor() {
5
+ super('Route not found');
6
+ Object.setPrototypeOf(this, NotFoundError.prototype);
7
+ }
8
+ serializeErrors() {
9
+ return [{ message: 'Not Found' }];
10
+ }
11
+ }
12
+ //# 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,aAAc,SAAQ,WAAW;IAC5C,UAAU,GAAG,GAAG,CAAC;IAEjB;QACE,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAEzB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import type { ValidationError } from "express-validator";
2
+ import { CustomError } from "./custom-error";
3
+ export declare class RequestValidationError extends CustomError {
4
+ errors: ValidationError[];
5
+ readonly statusCode = 400;
6
+ constructor(errors: ValidationError[]);
7
+ serializeErrors(): ({
8
+ message: any;
9
+ field: string;
10
+ } | {
11
+ message: any;
12
+ field?: never;
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,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,sBAAuB,SAAQ,WAAW;IAGlC,MAAM,EAAE,eAAe,EAAE;IAF5C,QAAQ,CAAC,UAAU,OAAO;gBAEP,MAAM,EAAE,eAAe,EAAE;IAM5C,eAAe;;;;;;;CAQhB"}
@@ -0,0 +1,19 @@
1
+ import { CustomError } from "./custom-error";
2
+ export class RequestValidationError extends CustomError {
3
+ errors;
4
+ statusCode = 400;
5
+ constructor(errors) {
6
+ super('Invalid request parameters');
7
+ this.errors = errors;
8
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
9
+ }
10
+ serializeErrors() {
11
+ return this.errors.map((err) => {
12
+ if (err.type === 'field') {
13
+ return { message: err.msg, field: err.path };
14
+ }
15
+ return { message: err.msg };
16
+ });
17
+ }
18
+ }
19
+ //# 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,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IAGlC;IAFV,UAAU,GAAG,GAAG,CAAC;IAE1B,YAAmB,MAAyB;QAC1C,KAAK,CAAC,4BAA4B,CAAC,CAAC;QADnB,WAAM,GAAN,MAAM,CAAmB;QAG1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACzB,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;YAC/C,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
package/build/index.d.ts CHANGED
@@ -1,2 +1,11 @@
1
- export {};
1
+ export * from "./errors/bad-request-error";
2
+ export * from "./errors/custom-error";
3
+ export * from "./errors/database-connection-error";
4
+ export * from "./errors/not-authorized-error";
5
+ export * from "./errors/not-found-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";
2
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,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,9 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const color = {
4
- red: 255,
5
- green: 0,
6
- blue: 0,
7
- };
8
- console.log(color);
1
+ export * from "./errors/bad-request-error";
2
+ export * from "./errors/custom-error";
3
+ export * from "./errors/database-connection-error";
4
+ export * from "./errors/not-authorized-error";
5
+ export * from "./errors/not-found-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";
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAMA,MAAM,KAAK,GAAU;IACnB,GAAG,EAAE,GAAG;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;CACR,CAAC;AAEF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAElD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ interface UserPayload {
3
+ id: string;
4
+ email: string;
5
+ }
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ session?: {
10
+ jwt?: string;
11
+ } | null;
12
+ currentUser?: UserPayload;
13
+ }
14
+ }
15
+ }
16
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
17
+ export {};
18
+ //# 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,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,UAAU,WAAW;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,OAAO,CAAC,EAAE;gBACR,GAAG,CAAC,EAAE,MAAM,CAAC;aACd,GAAG,IAAI,CAAC;YACT,WAAW,CAAC,EAAE,WAAW,CAAC;SAC3B;KACF;CACF;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,KAAG,IAW7E,CAAC"}
@@ -0,0 +1,13 @@
1
+ import jwt from "jsonwebtoken";
2
+ export const currentUser = (req, res, next) => {
3
+ if (!req.session?.jwt) {
4
+ return next();
5
+ }
6
+ try {
7
+ const payload = jwt.verify(req.session.jwt, process.env.JWT_KEY);
8
+ req.currentUser = payload;
9
+ }
10
+ catch (err) { }
11
+ next();
12
+ };
13
+ //# 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,OAAO,GAAG,MAAM,cAAc,CAAC;AAkB/B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;IACnF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC;QACtB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,OAAQ,CAAgB,CAAC;QACjF,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC,CAAA,CAAC;IAEhB,IAAI,EAAE,CAAC;AACT,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
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,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG/D,eAAO,MAAM,YAAY,GAAI,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,mDAUvF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { CustomError } from "../errors/custom-error";
2
+ export const errorHandler = (err, req, res, next) => {
3
+ if (err instanceof CustomError) {
4
+ return res.status(err.statusCode).send({
5
+ errors: err.serializeErrors(),
6
+ });
7
+ }
8
+ res.status(500).send({
9
+ errors: [{ message: "Something went wrong" }],
10
+ });
11
+ };
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,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAU,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC1F,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YACrC,MAAM,EAAE,GAAG,CAAC,eAAe,EAAE;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;KAC9C,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const requireAuth: (req: Request, _: 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,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI/D,eAAO,MAAM,WAAW,GAAI,KAAK,OAAO,EAAE,GAAG,QAAQ,EAAE,MAAM,YAAY,SAKxE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { NotAuthorizedError } from "../errors/not-authorized-error";
2
+ export const requireAuth = (req, _, next) => {
3
+ if (!req.currentUser) {
4
+ throw new NotAuthorizedError();
5
+ }
6
+ next();
7
+ };
8
+ //# sourceMappingURL=require-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require-auth.js","sourceRoot":"","sources":["../../src/middlewares/require-auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAY,EAAE,CAAW,EAAE,IAAkB,EAAE,EAAE;IAC3E,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Request, Response, NextFunction } from "express";
2
+ export declare const validateRequest: (req: Request, _: 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,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAK/D,eAAO,MAAM,eAAe,GAAI,KAAK,OAAO,EAAE,GAAG,QAAQ,EAAE,MAAM,YAAY,KAAG,IAM/E,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { validationResult } from "express-validator";
2
+ import { RequestValidationError } from "../errors/request-validation-error";
3
+ export const validateRequest = (req, _, next) => {
4
+ const errors = validationResult(req);
5
+ if (!errors.isEmpty()) {
6
+ throw new RequestValidationError(errors.array());
7
+ }
8
+ next();
9
+ };
10
+ //# 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,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAY,EAAE,CAAW,EAAE,IAAkB,EAAQ,EAAE;IACrF,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,IAAI,EAAE,CAAC;AACT,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lta.anluu/common",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -9,7 +9,8 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "build": "npm run clean && tsc",
12
- "clean": "del ./build/*"
12
+ "clean": "del ./build/*",
13
+ "pub": "git add . && git commit -m 'updates' && npm version patch && npm run build && npm publish"
13
14
  },
14
15
  "keywords": [],
15
16
  "author": "",
@@ -18,5 +19,14 @@
18
19
  "devDependencies": {
19
20
  "del-cli": "^7.0.0",
20
21
  "typescript": "^5.9.3"
22
+ },
23
+ "dependencies": {
24
+ "@types/cookie-session": "^2.0.49",
25
+ "@types/express": "^4.17.21",
26
+ "@types/jsonwebtoken": "^9.0.10",
27
+ "cookie-session": "^2.1.1",
28
+ "express": "^4.22.1",
29
+ "express-validator": "^7.3.1",
30
+ "jsonwebtoken": "^9.0.3"
21
31
  }
22
32
  }