@taleswords/common 1.0.5 → 1.0.7

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/constants/auth/user.interfaces.d.ts +8 -0
  2. package/build/constants/auth/user.interfaces.d.ts.map +1 -0
  3. package/build/constants/auth/user.interfaces.js +2 -0
  4. package/build/constants/auth/user.interfaces.js.map +1 -0
  5. package/build/constants/globals.d.ts +5 -0
  6. package/build/constants/globals.d.ts.map +1 -0
  7. package/build/constants/globals.js +2 -0
  8. package/build/constants/globals.js.map +1 -0
  9. package/build/errors/bad-request-error.d.ts +1 -1
  10. package/build/errors/bad-request-error.js +13 -0
  11. package/build/errors/bad-request-error.js.map +1 -0
  12. package/build/errors/custom-error.js +6 -0
  13. package/build/errors/custom-error.js.map +1 -0
  14. package/build/errors/database-connection-error.d.ts +1 -1
  15. package/build/errors/database-connection-error.d.ts.map +1 -1
  16. package/build/errors/database-connection-error.js +11 -0
  17. package/build/errors/database-connection-error.js.map +1 -0
  18. package/build/errors/not-authorized-error.d.ts +1 -1
  19. package/build/errors/not-authorized-error.d.ts.map +1 -1
  20. package/build/errors/not-authorized-error.js +11 -0
  21. package/build/errors/not-authorized-error.js.map +1 -0
  22. package/build/errors/not-found-error.d.ts +1 -1
  23. package/build/errors/not-found-error.d.ts.map +1 -1
  24. package/build/errors/not-found-error.js +11 -0
  25. package/build/errors/not-found-error.js.map +1 -0
  26. package/build/errors/request-validation-error.d.ts +1 -1
  27. package/build/errors/request-validation-error.js +18 -0
  28. package/build/errors/request-validation-error.js.map +1 -0
  29. package/build/index.d.ts +2 -0
  30. package/build/index.d.ts.map +1 -1
  31. package/build/index.js +13 -0
  32. package/build/index.js.map +1 -0
  33. package/build/middlewares/current-user.js +16 -0
  34. package/build/middlewares/current-user.js.map +1 -0
  35. package/build/middlewares/error-handler.js +8 -0
  36. package/build/middlewares/error-handler.js.map +1 -0
  37. package/build/middlewares/require-auth.js +8 -0
  38. package/build/middlewares/require-auth.js.map +1 -0
  39. package/build/middlewares/validation-request.js +10 -0
  40. package/build/middlewares/validation-request.js.map +1 -0
  41. package/build/services/authentication.service.d.ts +8 -0
  42. package/build/services/authentication.service.d.ts.map +1 -0
  43. package/build/services/authentication.service.js +25 -0
  44. package/build/services/authentication.service.js.map +1 -0
  45. package/package.json +1 -1
@@ -0,0 +1,8 @@
1
+ import mongoose from 'mongoose';
2
+ export interface UserDoc extends mongoose.Document {
3
+ email: string;
4
+ password: string;
5
+ }
6
+ export interface UserModel extends mongoose.Model<UserDoc> {
7
+ }
8
+ //# sourceMappingURL=user.interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.interfaces.d.ts","sourceRoot":"","sources":["../../../src/constants/auth/user.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAE/B,MAAM,WAAW,OAAQ,SAAQ,QAAQ,CAAC,QAAQ;IAC9C,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,SAAU,SAAQ,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;CAAG"}
@@ -0,0 +1,2 @@
1
+ import mongoose from 'mongoose';
2
+ //# sourceMappingURL=user.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.interfaces.js","sourceRoot":"","sources":["../../../src/constants/auth/user.interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAA"}
@@ -0,0 +1,5 @@
1
+ export interface JWTPayload {
2
+ email: string;
3
+ userId: string;
4
+ }
5
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../src/constants/globals.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACjB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=globals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/constants/globals.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { CustomError } from './custom-error.ts';
1
+ import { CustomError } from './custom-error.js';
2
2
  export declare class BadRequestError extends CustomError {
3
3
  message: string;
4
4
  statusCode: number;
@@ -0,0 +1,13 @@
1
+ import { CustomError } from './custom-error.js';
2
+ export class BadRequestError extends CustomError {
3
+ message;
4
+ statusCode = 400;
5
+ constructor(message) {
6
+ super(message);
7
+ this.message = message;
8
+ }
9
+ generateErrors() {
10
+ return [{ message: this.message }];
11
+ }
12
+ }
13
+ //# 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,mBAAmB,CAAA;AAE/C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAEzB;IADZ,UAAU,GAAG,GAAG,CAAA;IACvB,YAAmB,OAAe;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAA;QADC,YAAO,GAAP,OAAO,CAAQ;IAElC,CAAC;IAED,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACtC,CAAC;CACJ"}
@@ -0,0 +1,6 @@
1
+ export class CustomError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ }
5
+ }
6
+ //# 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;IAG3C,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,CAAC,CAAA;IAClB,CAAC;CAGJ"}
@@ -1,4 +1,4 @@
1
- import { CustomError } from './custom-error.ts';
1
+ import { CustomError } from './custom-error.js';
2
2
  export declare class DatabaseConnectionError extends CustomError {
3
3
  statusCode: number;
4
4
  constructor();
@@ -1 +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,mBAAmB,CAAC;AAEhD,qBAAa,uBAAwB,SAAQ,WAAW;IAC7C,UAAU,SAAM;;IAKvB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAAE,EAAE;CAG3D"}
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,mBAAmB,CAAA;AAE/C,qBAAa,uBAAwB,SAAQ,WAAW;IAC7C,UAAU,SAAM;;IAKvB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAAE,EAAE;CAG3D"}
@@ -0,0 +1,11 @@
1
+ import { CustomError } from './custom-error.js';
2
+ export class DatabaseConnectionError extends CustomError {
3
+ statusCode = 500;
4
+ constructor() {
5
+ super('database connection error');
6
+ }
7
+ generateErrors() {
8
+ return [{ message: 'database connection error' }];
9
+ }
10
+ }
11
+ //# 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,mBAAmB,CAAA;AAE/C,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IAC7C,UAAU,GAAG,GAAG,CAAA;IACvB;QACI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IACtC,CAAC;IAED,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC,CAAA;IACrD,CAAC;CACJ"}
@@ -1,4 +1,4 @@
1
- import { CustomError } from './custom-error.ts';
1
+ import { CustomError } from './custom-error.js';
2
2
  export declare class NotAuthorizedError extends CustomError {
3
3
  statusCode: number;
4
4
  constructor();
@@ -1 +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,mBAAmB,CAAC;AAEhD,qBAAa,kBAAmB,SAAQ,WAAW;IACxC,UAAU,SAAM;;IAKvB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAAE,EAAE;CAG3D"}
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,mBAAmB,CAAA;AAE/C,qBAAa,kBAAmB,SAAQ,WAAW;IACxC,UAAU,SAAM;;IAKvB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAAE,EAAE;CAG3D"}
@@ -0,0 +1,11 @@
1
+ import { CustomError } from './custom-error.js';
2
+ export class NotAuthorizedError extends CustomError {
3
+ statusCode = 401;
4
+ constructor() {
5
+ super('not authorized');
6
+ }
7
+ generateErrors() {
8
+ return [{ message: 'not authorized' }];
9
+ }
10
+ }
11
+ //# 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,mBAAmB,CAAA;AAE/C,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IACxC,UAAU,GAAG,GAAG,CAAA;IACvB;QACI,KAAK,CAAC,gBAAgB,CAAC,CAAA;IAC3B,CAAC;IAED,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAA;IAC1C,CAAC;CACJ"}
@@ -1,4 +1,4 @@
1
- import { CustomError } from './custom-error.ts';
1
+ import { CustomError } from './custom-error.js';
2
2
  export declare class NotFoundError extends CustomError {
3
3
  statusCode: number;
4
4
  constructor();
@@ -1 +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,mBAAmB,CAAC;AAEhD,qBAAa,aAAc,SAAQ,WAAW;IACnC,UAAU,SAAM;;IAKvB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAAE,EAAE;CAG3D"}
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,mBAAmB,CAAA;AAE/C,qBAAa,aAAc,SAAQ,WAAW;IACnC,UAAU,SAAM;;IAKvB,cAAc,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAAE,EAAE;CAG3D"}
@@ -0,0 +1,11 @@
1
+ import { CustomError } from './custom-error.js';
2
+ export class NotFoundError extends CustomError {
3
+ statusCode = 404;
4
+ constructor() {
5
+ super('not found');
6
+ }
7
+ generateErrors() {
8
+ return [{ message: 'not found' }];
9
+ }
10
+ }
11
+ //# 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,mBAAmB,CAAA;AAE/C,MAAM,OAAO,aAAc,SAAQ,WAAW;IACnC,UAAU,GAAG,GAAG,CAAA;IACvB;QACI,KAAK,CAAC,WAAW,CAAC,CAAA;IACtB,CAAC;IAED,cAAc;QACV,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;IACrC,CAAC;CACJ"}
@@ -1,4 +1,4 @@
1
- import { CustomError } from './custom-error.ts';
1
+ import { CustomError } from './custom-error.js';
2
2
  import type { ValidationError } from 'express-validator';
3
3
  export declare class RequestValidationError extends CustomError {
4
4
  errors: ValidationError[];
@@ -0,0 +1,18 @@
1
+ import { CustomError } from './custom-error.js';
2
+ export class RequestValidationError extends CustomError {
3
+ errors;
4
+ statusCode = 400;
5
+ constructor(errors) {
6
+ super('invalid request');
7
+ this.errors = errors;
8
+ }
9
+ generateErrors() {
10
+ return this.errors.map(error => {
11
+ return {
12
+ message: error.msg,
13
+ field: error.type === 'field' ? error.path : ''
14
+ };
15
+ });
16
+ }
17
+ }
18
+ //# 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":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IAEhC;IADZ,UAAU,GAAG,GAAG,CAAA;IACvB,YAAmB,MAAyB;QACxC,KAAK,CAAC,iBAAiB,CAAC,CAAA;QADT,WAAM,GAAN,MAAM,CAAmB;IAE5C,CAAC;IAED,cAAc;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO;gBACH,OAAO,EAAE,KAAK,CAAC,GAAG;gBAClB,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;aAClD,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ"}
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './constants/auth/user.interfaces.js';
1
2
  export * from './errors/bad-request-error.js';
2
3
  export * from './errors/custom-error.js';
3
4
  export * from './errors/database-connection-error.js';
@@ -8,4 +9,5 @@ export * from './middlewares/current-user.js';
8
9
  export * from './middlewares/error-handler.js';
9
10
  export * from './middlewares/require-auth.js';
10
11
  export * from './middlewares/validation-request.js';
12
+ export * from './services/authentication.service.js';
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,0BAA0B,CAAA;AACxC,cAAc,uCAAuC,CAAA;AACrD,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,sCAAsC,CAAA;AAEpD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,qCAAqC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AAEnD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,0BAA0B,CAAA;AACxC,cAAc,uCAAuC,CAAA;AACrD,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,sCAAsC,CAAA;AAEpD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,qCAAqC,CAAA;AAEnD,cAAc,sCAAsC,CAAA"}
package/build/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from './constants/auth/user.interfaces.js';
2
+ export * from './errors/bad-request-error.js';
3
+ export * from './errors/custom-error.js';
4
+ export * from './errors/database-connection-error.js';
5
+ export * from './errors/not-authorized-error.js';
6
+ export * from './errors/not-found-error.js';
7
+ export * from './errors/request-validation-error.js';
8
+ export * from './middlewares/current-user.js';
9
+ export * from './middlewares/error-handler.js';
10
+ export * from './middlewares/require-auth.js';
11
+ export * from './middlewares/validation-request.js';
12
+ export * from './services/authentication.service.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AAEnD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,0BAA0B,CAAA;AACxC,cAAc,uCAAuC,CAAA;AACrD,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,sCAAsC,CAAA;AAEpD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,qCAAqC,CAAA;AAEnD,cAAc,sCAAsC,CAAA"}
@@ -0,0 +1,16 @@
1
+ import jwt from 'jsonwebtoken';
2
+ export const currentUser = (jwtKey) => {
3
+ return (req, res, next) => {
4
+ if (!req.session?.jwt) {
5
+ return next();
6
+ }
7
+ try {
8
+ const payload = jwt.verify(req.session.jwt, jwtKey);
9
+ req.currentUser = payload;
10
+ }
11
+ catch (err) {
12
+ next(err);
13
+ }
14
+ };
15
+ };
16
+ //# sourceMappingURL=current-user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"current-user.js","sourceRoot":"","sources":["../../src/middlewares/current-user.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAA;AAU9B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,EAAE;IAC1C,OAAO,CACH,GAAQ,EACR,GAAa,EACb,IAAkB,EACpB,EAAE;QACA,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC;YACpB,OAAO,IAAI,EAAE,CAAA;QACjB,CAAC;QACD,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CACtB,GAAG,CAAC,OAAO,CAAC,GAAG,EACf,MAAM,CACT,CAAA;YAED,GAAG,CAAC,WAAW,GAAG,OAAO,CAAA;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,CAAA;QACb,CAAC;IACL,CAAC,CAAA;AACL,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { CustomError } from '../errors/custom-error.js';
2
+ export const errorHandler = (err, req, res, next) => {
3
+ if (err instanceof CustomError) {
4
+ return res.status(err.statusCode).json({ errors: err.generateErrors() });
5
+ }
6
+ res.status(500).json({ errors: [{ message: 'something went wrong ' }] });
7
+ };
8
+ //# 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,2BAA2B,CAAA;AAEvD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAU,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxF,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAC5E,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,uBAAuB,EAAC,CAAC,EAAC,CAAC,CAAA;AAC1E,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { NotAuthorizedError } from '../index.js';
2
+ export const requireAuth = async (req, res, next) => {
3
+ if (!req.currentUser) {
4
+ return next(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":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,GAAQ,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC7E,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAA;IACzC,CAAC;IACD,IAAI,EAAE,CAAA;AACV,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { validationResult } from 'express-validator';
2
+ import { RequestValidationError } from '../index.js';
3
+ export const validationRequest = async (err, req, res, next) => {
4
+ const errors = validationResult(req);
5
+ if (!errors.isEmpty()) {
6
+ return next(new RequestValidationError(errors.array()));
7
+ }
8
+ next();
9
+ };
10
+ //# sourceMappingURL=validation-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation-request.js","sourceRoot":"","sources":["../../src/middlewares/validation-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAU,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACnG,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACpC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IAC3D,CAAC;IAED,IAAI,EAAE,CAAA;AACV,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { JWTPayload } from '../constants/globals.js';
2
+ export declare class AuthenticationService {
3
+ generateJWT(payload: JWTPayload, JWT_KEY: string): string;
4
+ pwdToHash(password: string): Promise<string>;
5
+ pwdCompare(storedPassword: string, suppliedPassword: string): Promise<Boolean>;
6
+ verifyJWT(jwtToken: string, JWT_KEY: string): JWTPayload;
7
+ }
8
+ //# sourceMappingURL=authentication.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.d.ts","sourceRoot":"","sources":["../../src/services/authentication.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAKzD,qBAAa,qBAAqB;IACvB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM;IAI1C,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO5C,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASpF,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU;CAGlE"}
@@ -0,0 +1,25 @@
1
+ import jwt from 'jsonwebtoken';
2
+ import { scrypt, randomBytes } from 'crypto';
3
+ import { promisify } from 'util';
4
+ const scryptAsync = promisify(scrypt);
5
+ export class AuthenticationService {
6
+ generateJWT(payload, JWT_KEY) {
7
+ return jwt.sign(payload, JWT_KEY);
8
+ }
9
+ async pwdToHash(password) {
10
+ const salt = randomBytes(8).toString('hex');
11
+ const buf = (await scryptAsync(password, salt, 64));
12
+ return `${buf.toString('hex')}.${salt}`;
13
+ }
14
+ async pwdCompare(storedPassword, suppliedPassword) {
15
+ const [hashedPassword, salt] = storedPassword.split('.');
16
+ if (!salt)
17
+ return false;
18
+ const buf = (await scryptAsync(suppliedPassword, salt, 64));
19
+ return buf.toString('hex') === hashedPassword;
20
+ }
21
+ verifyJWT(jwtToken, JWT_KEY) {
22
+ return jwt.verify(jwtToken, JWT_KEY);
23
+ }
24
+ }
25
+ //# sourceMappingURL=authentication.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["../../src/services/authentication.service.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAA;AAC9B,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAEhC,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,OAAO,qBAAqB;IACvB,WAAW,CAAC,OAAmB,EAAE,OAAe;QACnD,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IACrC,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,QAAgB;QACnC,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAC3C,MAAM,GAAG,GAAG,CAAC,MAAM,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAW,CAAA;QAE7D,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAA;IAC3C,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,cAAsB,EAAE,gBAAwB;QACpE,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACxD,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAA;QAEvB,MAAM,GAAG,GAAG,CAAC,MAAM,WAAW,CAAC,gBAAgB,EAAE,IAAI,EAAE,EAAE,CAAC,CAAW,CAAA;QAErE,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,cAAc,CAAA;IACjD,CAAC;IAEM,SAAS,CAAC,QAAgB,EAAE,OAAe;QAC9C,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAe,CAAA;IACtD,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taleswords/common",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",