@skillstew/common 1.0.7 → 1.0.9

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,27 @@
1
+ export declare enum HttpStatus {
2
+ OK = 200,
3
+ CREATED = 201,
4
+ ACCEPTED = 202,
5
+ NO_CONTENT = 204,
6
+ MOVED_PERMANENTLY = 301,
7
+ FOUND = 302,
8
+ NOT_MODIFIED = 304,
9
+ BAD_REQUEST = 400,
10
+ UNAUTHORIZED = 401,
11
+ PAYMENT_REQUIRED = 402,
12
+ FORBIDDEN = 403,
13
+ NOT_FOUND = 404,
14
+ METHOD_NOT_ALLOWED = 405,
15
+ NOT_ACCEPTABLE = 406,
16
+ REQUEST_TIMEOUT = 408,
17
+ CONFLICT = 409,
18
+ GONE = 410,
19
+ PAYLOAD_TOO_LARGE = 413,
20
+ UNSUPPORTED_MEDIA_TYPE = 415,
21
+ TOO_MANY_REQUESTS = 429,
22
+ INTERNAL_SERVER_ERROR = 500,
23
+ NOT_IMPLEMENTED = 501,
24
+ BAD_GATEWAY = 502,
25
+ SERVICE_UNAVAILABLE = 503,
26
+ GATEWAY_TIMEOUT = 504
27
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpStatus = void 0;
4
+ var HttpStatus;
5
+ (function (HttpStatus) {
6
+ // 2xx Success
7
+ HttpStatus[HttpStatus["OK"] = 200] = "OK";
8
+ HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
9
+ HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
10
+ HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
11
+ // 3xx Redirection
12
+ HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
13
+ HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
14
+ HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
15
+ // 4xx Client Errors
16
+ HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
17
+ HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
18
+ HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
19
+ HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
20
+ HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
21
+ HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
22
+ HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
23
+ HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
24
+ HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
25
+ HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
26
+ HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
27
+ HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
28
+ HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
29
+ // 5xx Server Errors
30
+ HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
31
+ HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
32
+ HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
33
+ HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
34
+ HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
35
+ })(HttpStatus || (exports.HttpStatus = HttpStatus = {}));
@@ -0,0 +1,5 @@
1
+ import { DomainError } from "./AppError";
2
+ export declare class UnauthorizedError extends DomainError {
3
+ constructor();
4
+ toJSON(): object;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnauthorizedError = void 0;
4
+ const AppError_1 = require("./AppError");
5
+ class UnauthorizedError extends AppError_1.DomainError {
6
+ constructor() {
7
+ super("You are not authorized", "UNAUTHORIZED");
8
+ }
9
+ toJSON() {
10
+ return { error: this.name, message: this.message, code: this.code };
11
+ }
12
+ }
13
+ exports.UnauthorizedError = UnauthorizedError;
package/build/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from "./jwt-utils/JwtHelper";
6
6
  export * from "./middlewares/authMiddleware";
7
7
  export * from "./types/UserRoles";
8
8
  export * from "./middlewares/requireRole";
9
+ export * from "./constants/HttpStatus";
package/build/index.js CHANGED
@@ -22,3 +22,4 @@ __exportStar(require("./jwt-utils/JwtHelper"), exports);
22
22
  __exportStar(require("./middlewares/authMiddleware"), exports);
23
23
  __exportStar(require("./types/UserRoles"), exports);
24
24
  __exportStar(require("./middlewares/requireRole"), exports);
25
+ __exportStar(require("./constants/HttpStatus"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skillstew/common",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "./build/index.js",
5
5
  "types": "./build/index.d.ts",
6
6
  "scripts": {
@@ -0,0 +1,34 @@
1
+ export enum HttpStatus {
2
+ // 2xx Success
3
+ OK = 200,
4
+ CREATED = 201,
5
+ ACCEPTED = 202,
6
+ NO_CONTENT = 204,
7
+
8
+ // 3xx Redirection
9
+ MOVED_PERMANENTLY = 301,
10
+ FOUND = 302,
11
+ NOT_MODIFIED = 304,
12
+
13
+ // 4xx Client Errors
14
+ BAD_REQUEST = 400,
15
+ UNAUTHORIZED = 401,
16
+ PAYMENT_REQUIRED = 402,
17
+ FORBIDDEN = 403,
18
+ NOT_FOUND = 404,
19
+ METHOD_NOT_ALLOWED = 405,
20
+ NOT_ACCEPTABLE = 406,
21
+ REQUEST_TIMEOUT = 408,
22
+ CONFLICT = 409,
23
+ GONE = 410,
24
+ PAYLOAD_TOO_LARGE = 413,
25
+ UNSUPPORTED_MEDIA_TYPE = 415,
26
+ TOO_MANY_REQUESTS = 429,
27
+
28
+ // 5xx Server Errors
29
+ INTERNAL_SERVER_ERROR = 500,
30
+ NOT_IMPLEMENTED = 501,
31
+ BAD_GATEWAY = 502,
32
+ SERVICE_UNAVAILABLE = 503,
33
+ GATEWAY_TIMEOUT = 504,
34
+ }
@@ -0,0 +1,10 @@
1
+ import { DomainError } from "./AppError";
2
+
3
+ export class UnauthorizedError extends DomainError {
4
+ constructor() {
5
+ super("You are not authorized", "UNAUTHORIZED");
6
+ }
7
+ toJSON(): object {
8
+ return { error: this.name, message: this.message, code: this.code };
9
+ }
10
+ }
package/src/index.ts CHANGED
@@ -9,3 +9,5 @@ export * from "./middlewares/authMiddleware";
9
9
  export * from "./types/UserRoles";
10
10
 
11
11
  export * from "./middlewares/requireRole";
12
+
13
+ export * from "./constants/HttpStatus";