@senhainfo/shared-utils 1.0.10 → 1.0.11

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.
@@ -0,0 +1,5 @@
1
+ import { AppException } from "./app-exception";
2
+ export declare class BadRequestException extends AppException {
3
+ constructor(message?: string, details?: object);
4
+ }
5
+ //# sourceMappingURL=bad-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bad-request.d.ts","sourceRoot":"","sources":["../../src/exceptions/bad-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAEjE,qBAAa,mBAAoB,SAAQ,YAAY;gBACvC,OAAO,SAAiC,EAAE,OAAO,CAAC,EAAE,MAAM;CAGvE"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BadRequestException = void 0;
4
+ const http_status_enum_1 = require("../http-status-enum");
5
+ const app_exception_1 = require("./app-exception");
6
+ class BadRequestException extends app_exception_1.AppException {
7
+ constructor(message = "Erro ao processar requisição", details) {
8
+ super(app_exception_1.AppExceptionEnum.BAD_REQUEST, message, http_status_enum_1.HttpStatusCodes.BAD_REQUEST, details);
9
+ }
10
+ }
11
+ exports.BadRequestException = BadRequestException;
12
+ //# sourceMappingURL=bad-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bad-request.js","sourceRoot":"","sources":["../../src/exceptions/bad-request.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AACtD,mDAAiE;AAEjE,MAAa,mBAAoB,SAAQ,4BAAY;IACnD,YAAY,OAAO,GAAG,8BAA8B,EAAE,OAAgB;QACpE,KAAK,CAAC,gCAAgB,CAAC,WAAW,EAAE,OAAO,EAAE,kCAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACrF,CAAC;CACF;AAJD,kDAIC"}
@@ -1,4 +1,5 @@
1
1
  export * from "./app-exception";
2
+ export * from "./bad-request";
2
3
  export * from "./forbidden";
3
4
  export * from "./inactive";
4
5
  export * from "./invalid-credentials";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC"}
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./app-exception"), exports);
18
+ __exportStar(require("./bad-request"), exports);
18
19
  __exportStar(require("./forbidden"), exports);
19
20
  __exportStar(require("./inactive"), exports);
20
21
  __exportStar(require("./invalid-credentials"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,8CAA4B;AAC5B,6CAA2B;AAC3B,wDAAsC;AACtC,kDAAgC;AAChC,kDAAgC;AAChC,8CAA4B;AAC5B,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B;AAC5B,6CAA2B;AAC3B,wDAAsC;AACtC,kDAAgC;AAChC,kDAAgC;AAChC,8CAA4B;AAC5B,2DAAyC"}
@@ -0,0 +1,22 @@
1
+ import jwt, { JwtPayload, SignOptions } from "jsonwebtoken";
2
+ interface TokenData {
3
+ userId: number;
4
+ }
5
+ type TokenType = "access" | "refresh";
6
+ interface GenerateTokenProps {
7
+ payload: JwtPayload;
8
+ options?: SignOptions & {
9
+ type?: TokenType;
10
+ };
11
+ }
12
+ export declare class HandleJwtToken {
13
+ private jwtSecretKey;
14
+ private jwtRefreshSecretKey;
15
+ constructor(jwtSecretKey: string, jwtRefreshSecretKey: string);
16
+ private getSecret;
17
+ generate({ payload, options }: GenerateTokenProps): string;
18
+ verify(token: string, type?: TokenType): JwtPayload & TokenData;
19
+ decode(token: string): string | jwt.JwtPayload | null;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=handle-jwt-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-jwt-token.d.ts","sourceRoot":"","sources":["../src/handle-jwt-token.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE5D,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEtC,UAAU,kBAAkB;IAC1B,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,WAAW,GAAG;QACtB,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,CAAC;CACH;AAED,qBAAa,cAAc;IACb,OAAO,CAAC,YAAY;IAAU,OAAO,CAAC,mBAAmB;gBAAjD,YAAY,EAAE,MAAM,EAAU,mBAAmB,EAAE,MAAM;IAE7E,OAAO,CAAC,SAAS;IAIjB,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,kBAAkB;IAMjD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,SAAoB,GAAG,UAAU,GAAG,SAAS;IAKzE,MAAM,CAAC,KAAK,EAAE,MAAM;CAGrB"}
@@ -0,0 +1,30 @@
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.HandleJwtToken = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ class HandleJwtToken {
9
+ constructor(jwtSecretKey, jwtRefreshSecretKey) {
10
+ this.jwtSecretKey = jwtSecretKey;
11
+ this.jwtRefreshSecretKey = jwtRefreshSecretKey;
12
+ }
13
+ getSecret(type = "access") {
14
+ return type === "access" ? this.jwtSecretKey : this.jwtRefreshSecretKey;
15
+ }
16
+ generate({ payload, options }) {
17
+ const SECRET = this.getSecret(options === null || options === void 0 ? void 0 : options.type);
18
+ options === null || options === void 0 ? true : delete options.type;
19
+ return jsonwebtoken_1.default.sign(payload, SECRET, options);
20
+ }
21
+ verify(token, type = "access") {
22
+ const SECRET = this.getSecret(type);
23
+ return jsonwebtoken_1.default.verify(token, SECRET);
24
+ }
25
+ decode(token) {
26
+ return jsonwebtoken_1.default.decode(token);
27
+ }
28
+ }
29
+ exports.HandleJwtToken = HandleJwtToken;
30
+ //# sourceMappingURL=handle-jwt-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle-jwt-token.js","sourceRoot":"","sources":["../src/handle-jwt-token.ts"],"names":[],"mappings":";;;;;;AAAA,gEAA4D;AAe5D,MAAa,cAAc;IACzB,YAAoB,YAAoB,EAAU,mBAA2B;QAAzD,iBAAY,GAAZ,YAAY,CAAQ;QAAU,wBAAmB,GAAnB,mBAAmB,CAAQ;IAAG,CAAC;IAEzE,SAAS,CAAC,OAAkB,QAAQ;QAC1C,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;IAC1E,CAAC;IAED,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,EAAsB;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,CAAC;QACtC,OAAO,aAAP,OAAO,4BAAP,OAAO,CAAE,IAAI,CAAC;QACrB,OAAO,sBAAG,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,KAAa,EAAE,OAAkB,QAAQ;QAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAA2B,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,OAAO,sBAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;CACF;AArBD,wCAqBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senhainfo/shared-utils",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "repository": "https://github.com/senha-info/senha-shared-utils.git",
5
5
  "author": "Bruno Gaspar <bruninhoogaspar@gmail.com>",
6
6
  "license": "MIT",