@easyweb/authentication 1.0.0 → 2.0.0
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/README.md +31 -9
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/authenticate.d.ts +23 -1
- package/dist/middleware/authenticate.d.ts.map +1 -1
- package/dist/middleware/authenticate.js +34 -13
- package/dist/middleware/authenticate.js.map +1 -1
- package/package.json +6 -5
- package/dist/errors/bad-request-error.d.ts +0 -10
- package/dist/errors/bad-request-error.d.ts.map +0 -1
- package/dist/errors/bad-request-error.js +0 -16
- package/dist/errors/bad-request-error.js.map +0 -1
- package/dist/errors/custom-error.d.ts +0 -9
- package/dist/errors/custom-error.d.ts.map +0 -1
- package/dist/errors/custom-error.js +0 -11
- package/dist/errors/custom-error.js.map +0 -1
- package/dist/errors/database-connection-error.d.ts +0 -10
- package/dist/errors/database-connection-error.d.ts.map +0 -1
- package/dist/errors/database-connection-error.js +0 -17
- package/dist/errors/database-connection-error.js.map +0 -1
- package/dist/errors/index.d.ts +0 -6
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -22
- package/dist/errors/index.js.map +0 -1
- package/dist/errors/not-authorized-error.d.ts +0 -9
- package/dist/errors/not-authorized-error.d.ts.map +0 -1
- package/dist/errors/not-authorized-error.js +0 -16
- package/dist/errors/not-authorized-error.js.map +0 -1
- package/dist/errors/not-found-error.d.ts +0 -9
- package/dist/errors/not-found-error.d.ts.map +0 -1
- package/dist/errors/not-found-error.js +0 -16
- package/dist/errors/not-found-error.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
# @easyweb/authentication
|
|
2
2
|
|
|
3
3
|
Shared authentication primitives for Easyweb microservices — stateless JWT middleware,
|
|
4
|
-
request-context middleware, and the
|
|
4
|
+
request-context middleware, and the token verification helpers services build on.
|
|
5
5
|
|
|
6
|
-
Companion to [`@easyweb/
|
|
7
|
-
|
|
6
|
+
Companion to [`@easyweb/events`](https://www.npmjs.com/package/@easyweb/events) for
|
|
7
|
+
messaging, and [`@easyweb/errors`](https://www.npmjs.com/package/@easyweb/errors) for
|
|
8
|
+
the HTTP error taxonomy.
|
|
9
|
+
|
|
10
|
+
## Upgrading to 2.0.0 — BREAKING
|
|
11
|
+
|
|
12
|
+
The error classes moved to `@easyweb/errors`. Error handling is cross-cutting and has
|
|
13
|
+
nothing to do with JWTs; a service needing `ConflictError` should not have to depend on
|
|
14
|
+
an auth package for it.
|
|
15
|
+
|
|
16
|
+
```diff
|
|
17
|
+
- import { NotAuthorizedError } from "@easyweb/authentication";
|
|
18
|
+
+ import { NotAuthorizedError } from "@easyweb/errors";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`@easyweb/errors` is a **peerDependency** — install it alongside this package. Do not let
|
|
22
|
+
it end up nested under `node_modules/@easyweb/authentication/`: two copies of
|
|
23
|
+
`CustomError` means `instanceof` fails across the boundary and the error handler answers
|
|
24
|
+
500 for everything, with no type error to warn you. Verify with `npm ls @easyweb/errors`.
|
|
25
|
+
|
|
26
|
+
Also new in 2.0.0: `extractToken` and `isValidAccessPayload` are exported, for services
|
|
27
|
+
that keep their own DB-backed middleware (see below) and would otherwise copy them.
|
|
8
28
|
|
|
9
29
|
## Install
|
|
10
30
|
|
|
@@ -23,11 +43,7 @@ package never has to reach into a service's `config` module.
|
|
|
23
43
|
```ts
|
|
24
44
|
import express from "express";
|
|
25
45
|
import cookieParser from "cookie-parser";
|
|
26
|
-
import {
|
|
27
|
-
createAuthMiddleware,
|
|
28
|
-
requestContext,
|
|
29
|
-
NotAuthorizedError,
|
|
30
|
-
} from "@easyweb/authentication";
|
|
46
|
+
import { createAuthMiddleware, requestContext } from "@easyweb/authentication";
|
|
31
47
|
import config from "./config";
|
|
32
48
|
|
|
33
49
|
const app = express();
|
|
@@ -83,9 +99,15 @@ would deny every request.
|
|
|
83
99
|
| `requestContext` | propagates / generates `x-request-id` |
|
|
84
100
|
| `createJwtVerifier(config)` | `(token) => JwtAccessPayload`, throws on invalid |
|
|
85
101
|
| `createJwtSigner(config)` | `(claims) => string` |
|
|
86
|
-
| `
|
|
102
|
+
| `extractToken(req)` | Bearer header, then the `accessToken` cookie |
|
|
103
|
+
| `isValidAccessPayload(decoded)` | type guard: is this a well-formed *access* token? |
|
|
87
104
|
| `JwtAccessPayload`, `JwtAccessClaims`, `JwtVerifyConfig`, `JwtSignConfig` | types |
|
|
88
105
|
|
|
106
|
+
`extractToken` and `isValidAccessPayload` exist for services that must keep a DB-backed
|
|
107
|
+
middleware. They were previously private, so auth-service copied them — and the copies
|
|
108
|
+
drifted. If you need the same checks with different error messages, import these rather
|
|
109
|
+
than reimplementing them.
|
|
110
|
+
|
|
89
111
|
Importing the package also augments `Express.Request` with `user`, `auth`, and
|
|
90
112
|
`requestId`. Remove any local copy of that `declare global` block or TypeScript will
|
|
91
113
|
report duplicate members.
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./errors"), exports);
|
|
18
17
|
__exportStar(require("./jwt"), exports);
|
|
19
18
|
__exportStar(require("./middleware"), exports);
|
|
20
19
|
__exportStar(require("./types/jwt"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,+CAA6B;AAC7B,8CAA4B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from "express";
|
|
2
|
-
import type { JwtVerifyConfig } from "../types/jwt";
|
|
2
|
+
import type { JwtAccessPayload, JwtVerifyConfig } from "../types/jwt";
|
|
3
3
|
/**
|
|
4
4
|
* Stateless verification. Unlike auth-service's own middleware there is no
|
|
5
5
|
* database round trip: the access token is verified against the shared secret
|
|
@@ -35,6 +35,28 @@ declare global {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Bearer header first, then the `accessToken` cookie auth-service sets.
|
|
40
|
+
*
|
|
41
|
+
* Exported because auth-service keeps its own DB-backed middleware (see the
|
|
42
|
+
* trade-off above) and would otherwise copy this verbatim — which it did, and
|
|
43
|
+
* the copy drifted.
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractToken(req: Request): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Is this a well-formed *access* token payload?
|
|
48
|
+
*
|
|
49
|
+
* A valid signature only proves we minted the token, not that we minted it for
|
|
50
|
+
* this purpose — a refresh token is signed with the same secret. Without the
|
|
51
|
+
* `type` check a refresh token would authenticate a request.
|
|
52
|
+
*
|
|
53
|
+
* `iat` is required because DB-backed consumers compare it against
|
|
54
|
+
* `passwordChangedAt` to invalidate tokens issued before a password change.
|
|
55
|
+
*
|
|
56
|
+
* Exported alongside `extractToken` for auth-service's own middleware, which
|
|
57
|
+
* needs the same guard but reports failure with its own message.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isValidAccessPayload(decoded: JwtAccessPayload | null | undefined): decoded is JwtAccessPayload;
|
|
38
60
|
export type AuthMiddleware = {
|
|
39
61
|
/** Rejects with 401 unless the request carries a valid access token. */
|
|
40
62
|
authenticate: (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/middleware/authenticate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/middleware/authenticate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEtE;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE;gBACL,EAAE,EAAE,MAAM,CAAC;gBACX,KAAK,EAAE,MAAM,CAAC;gBACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;gBACxB,KAAK,EAAE,MAAM,EAAE,CAAC;gBAChB,WAAW,EAAE,MAAM,EAAE,CAAC;aACvB,CAAC;YACF,IAAI,CAAC,EAAE;gBACL,MAAM,EAAE,MAAM,CAAC;gBACf,SAAS,CAAC,EAAE,MAAM,CAAC;aACpB,CAAC;SACH;KACF;CACF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAYxD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC3C,OAAO,IAAI,gBAAgB,CAQ7B;AAqBD,MAAM,MAAM,cAAc,GAAG;IAC3B,wEAAwE;IACxE,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACxE,yEAAyE;IACzE,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACxE,4CAA4C;IAC5C,SAAS,EAAE,CACT,YAAY,EAAE,MAAM,EAAE,KACnB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;CAChE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc,CAsE5E"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractToken = extractToken;
|
|
4
|
+
exports.isValidAccessPayload = isValidAccessPayload;
|
|
3
5
|
exports.createAuthMiddleware = createAuthMiddleware;
|
|
4
6
|
const verify_1 = require("../jwt/verify");
|
|
5
|
-
const
|
|
6
|
-
/**
|
|
7
|
+
const errors_1 = require("@easyweb/errors");
|
|
8
|
+
/**
|
|
9
|
+
* Bearer header first, then the `accessToken` cookie auth-service sets.
|
|
10
|
+
*
|
|
11
|
+
* Exported because auth-service keeps its own DB-backed middleware (see the
|
|
12
|
+
* trade-off above) and would otherwise copy this verbatim — which it did, and
|
|
13
|
+
* the copy drifted.
|
|
14
|
+
*/
|
|
7
15
|
function extractToken(req) {
|
|
8
16
|
const authHeader = req.headers.authorization;
|
|
9
17
|
if (authHeader && authHeader.startsWith("Bearer ")) {
|
|
@@ -14,6 +22,26 @@ function extractToken(req) {
|
|
|
14
22
|
}
|
|
15
23
|
return null;
|
|
16
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Is this a well-formed *access* token payload?
|
|
27
|
+
*
|
|
28
|
+
* A valid signature only proves we minted the token, not that we minted it for
|
|
29
|
+
* this purpose — a refresh token is signed with the same secret. Without the
|
|
30
|
+
* `type` check a refresh token would authenticate a request.
|
|
31
|
+
*
|
|
32
|
+
* `iat` is required because DB-backed consumers compare it against
|
|
33
|
+
* `passwordChangedAt` to invalidate tokens issued before a password change.
|
|
34
|
+
*
|
|
35
|
+
* Exported alongside `extractToken` for auth-service's own middleware, which
|
|
36
|
+
* needs the same guard but reports failure with its own message.
|
|
37
|
+
*/
|
|
38
|
+
function isValidAccessPayload(decoded) {
|
|
39
|
+
return Boolean(decoded &&
|
|
40
|
+
decoded.type === "access" &&
|
|
41
|
+
decoded.sub &&
|
|
42
|
+
decoded.sessionId &&
|
|
43
|
+
decoded.iat);
|
|
44
|
+
}
|
|
17
45
|
function attachClaims(req, decoded) {
|
|
18
46
|
req.user = {
|
|
19
47
|
id: decoded.sub,
|
|
@@ -51,23 +79,16 @@ function createAuthMiddleware(config) {
|
|
|
51
79
|
catch {
|
|
52
80
|
return null;
|
|
53
81
|
}
|
|
54
|
-
|
|
55
|
-
decoded.type !== "access" ||
|
|
56
|
-
!decoded.sub ||
|
|
57
|
-
!decoded.sessionId ||
|
|
58
|
-
!decoded.iat) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
return decoded;
|
|
82
|
+
return isValidAccessPayload(decoded) ? decoded : null;
|
|
62
83
|
}
|
|
63
84
|
const authenticate = (req, _res, next) => {
|
|
64
85
|
const token = extractToken(req);
|
|
65
86
|
if (!token) {
|
|
66
|
-
throw new
|
|
87
|
+
throw new errors_1.NotAuthorizedError();
|
|
67
88
|
}
|
|
68
89
|
const decoded = decodeAccessToken(token);
|
|
69
90
|
if (!decoded) {
|
|
70
|
-
throw new
|
|
91
|
+
throw new errors_1.NotAuthorizedError();
|
|
71
92
|
}
|
|
72
93
|
attachClaims(req, decoded);
|
|
73
94
|
next();
|
|
@@ -85,7 +106,7 @@ function createAuthMiddleware(config) {
|
|
|
85
106
|
return (req, _res, next) => {
|
|
86
107
|
const roles = req.user?.roles ?? [];
|
|
87
108
|
if (!roles.some((r) => allowedRoles.includes(r))) {
|
|
88
|
-
throw new
|
|
109
|
+
throw new errors_1.NotAuthorizedError("Insufficient role");
|
|
89
110
|
}
|
|
90
111
|
next();
|
|
91
112
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/middleware/authenticate.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/middleware/authenticate.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyweb/authentication",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Shared authentication primitives for Easyweb microservices: stateless JWT middleware, request context, and
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Shared authentication primitives for Easyweb microservices: stateless JWT middleware, request context, and token verification helpers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
19
|
+
"build": "npm run clean && tsc",
|
|
20
20
|
"build:watch": "tsc --watch",
|
|
21
21
|
"prepublishOnly": "npm run build",
|
|
22
22
|
"clean": "rimraf dist"
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
"express",
|
|
27
27
|
"middleware",
|
|
28
28
|
"authentication",
|
|
29
|
-
"jwt"
|
|
30
|
-
"error-handling"
|
|
29
|
+
"jwt"
|
|
31
30
|
],
|
|
32
31
|
"author": "Easy Web Team",
|
|
33
32
|
"license": "MIT",
|
|
@@ -37,10 +36,12 @@
|
|
|
37
36
|
"directory": "common-auth"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
39
|
+
"@easyweb/errors": "^1.0.0",
|
|
40
40
|
"express": "^5.0.0",
|
|
41
41
|
"jsonwebtoken": "^9.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
+
"@easyweb/errors": "^1.0.0",
|
|
44
45
|
"@types/express": "^5.0.6",
|
|
45
46
|
"@types/jsonwebtoken": "^9.0.10",
|
|
46
47
|
"@types/node": "^26.0.1",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CustomError } from "./custom-error";
|
|
2
|
-
declare class BadRequestError extends CustomError {
|
|
3
|
-
statusCode: number;
|
|
4
|
-
constructor(message: string);
|
|
5
|
-
serializeErrors(): {
|
|
6
|
-
message: string;
|
|
7
|
-
}[];
|
|
8
|
-
}
|
|
9
|
-
export { BadRequestError };
|
|
10
|
-
//# sourceMappingURL=bad-request-error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,cAAM,eAAgB,SAAQ,WAAW;IACvC,UAAU,SAAO;gBAEL,OAAO,EAAE,MAAM;IAK3B,eAAe;;;CAGhB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BadRequestError = void 0;
|
|
4
|
-
const custom_error_1 = require("./custom-error");
|
|
5
|
-
class BadRequestError extends custom_error_1.CustomError {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.statusCode = 400;
|
|
9
|
-
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
10
|
-
}
|
|
11
|
-
serializeErrors() {
|
|
12
|
-
return [{ message: this.message }];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.BadRequestError = BadRequestError;
|
|
16
|
-
//# sourceMappingURL=bad-request-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bad-request-error.js","sourceRoot":"","sources":["../../src/errors/bad-request-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAM,eAAgB,SAAQ,0BAAW;IAGvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHjB,eAAU,GAAG,GAAG,CAAC;QAIf,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;AAEQ,0CAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
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,UAAU,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM;IAK3B,QAAQ,CAAC,eAAe,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;CAClE"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomError = void 0;
|
|
4
|
-
class CustomError extends Error {
|
|
5
|
-
constructor(message) {
|
|
6
|
-
super(message);
|
|
7
|
-
Object.setPrototypeOf(this, CustomError.prototype);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
exports.CustomError = CustomError;
|
|
11
|
-
//# sourceMappingURL=custom-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../src/errors/custom-error.ts"],"names":[],"mappings":";;;AAAA,MAAsB,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;AATD,kCASC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CustomError } from "./custom-error";
|
|
2
|
-
export declare class DatabaseConnectionError extends CustomError {
|
|
3
|
-
statusCode: number;
|
|
4
|
-
reason: string;
|
|
5
|
-
constructor();
|
|
6
|
-
serializeErrors(): {
|
|
7
|
-
message: string;
|
|
8
|
-
}[];
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=database-connection-error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,UAAU,SAAO;IACjB,MAAM,SAAkC;;IAQxC,eAAe;;;CAGhB"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DatabaseConnectionError = void 0;
|
|
4
|
-
const custom_error_1 = require("./custom-error");
|
|
5
|
-
class DatabaseConnectionError extends custom_error_1.CustomError {
|
|
6
|
-
constructor() {
|
|
7
|
-
super("Error connecting to database");
|
|
8
|
-
this.statusCode = 500;
|
|
9
|
-
this.reason = "Error connecting to database";
|
|
10
|
-
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
11
|
-
}
|
|
12
|
-
serializeErrors() {
|
|
13
|
-
return [{ message: this.reason }];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
17
|
-
//# sourceMappingURL=database-connection-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database-connection-error.js","sourceRoot":"","sources":["../../src/errors/database-connection-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,uBAAwB,SAAQ,0BAAW;IAItD;QACE,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAJxC,eAAU,GAAG,GAAG,CAAC;QACjB,WAAM,GAAG,8BAA8B,CAAC;QAKtC,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;AAbD,0DAaC"}
|
package/dist/errors/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC"}
|
package/dist/errors/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./custom-error"), exports);
|
|
18
|
-
__exportStar(require("./bad-request-error"), exports);
|
|
19
|
-
__exportStar(require("./not-authorized-error"), exports);
|
|
20
|
-
__exportStar(require("./not-found-error"), exports);
|
|
21
|
-
__exportStar(require("./database-connection-error"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/errors/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,sDAAoC;AACpC,yDAAuC;AACvC,oDAAkC;AAClC,8DAA4C"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CustomError } from "./custom-error";
|
|
2
|
-
export declare class NotAuthorizedError extends CustomError {
|
|
3
|
-
statusCode: number;
|
|
4
|
-
constructor(message?: string);
|
|
5
|
-
serializeErrors(): {
|
|
6
|
-
message: string;
|
|
7
|
-
}[];
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=not-authorized-error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;gBAEL,OAAO,GAAE,MAAyB;IAK9C,eAAe;;;CAGhB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotAuthorizedError = void 0;
|
|
4
|
-
const custom_error_1 = require("./custom-error");
|
|
5
|
-
class NotAuthorizedError extends custom_error_1.CustomError {
|
|
6
|
-
constructor(message = "Not authorized") {
|
|
7
|
-
super(message);
|
|
8
|
-
this.statusCode = 401;
|
|
9
|
-
Object.setPrototypeOf(this, NotAuthorizedError.prototype);
|
|
10
|
-
}
|
|
11
|
-
serializeErrors() {
|
|
12
|
-
return [{ message: this.message }];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.NotAuthorizedError = NotAuthorizedError;
|
|
16
|
-
//# sourceMappingURL=not-authorized-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"not-authorized-error.js","sourceRoot":"","sources":["../../src/errors/not-authorized-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,kBAAmB,SAAQ,0BAAW;IAGjD,YAAY,UAAkB,gBAAgB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAHjB,eAAU,GAAG,GAAG,CAAC;QAIf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAED,eAAe;QACb,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AAXD,gDAWC"}
|
|
@@ -1 +0,0 @@
|
|
|
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;;IAOjB,eAAe;;;CAGhB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotFoundError = void 0;
|
|
4
|
-
const custom_error_1 = require("./custom-error");
|
|
5
|
-
class NotFoundError extends custom_error_1.CustomError {
|
|
6
|
-
constructor() {
|
|
7
|
-
super("Route not found");
|
|
8
|
-
this.statusCode = 404;
|
|
9
|
-
Object.setPrototypeOf(this, NotFoundError.prototype);
|
|
10
|
-
}
|
|
11
|
-
serializeErrors() {
|
|
12
|
-
return [{ message: "Not Found" }];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.NotFoundError = NotFoundError;
|
|
16
|
-
//# sourceMappingURL=not-found-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"not-found-error.js","sourceRoot":"","sources":["../../src/errors/not-found-error.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAE7C,MAAa,aAAc,SAAQ,0BAAW;IAG5C;QACE,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAH3B,eAAU,GAAG,GAAG,CAAC;QAIf,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;AAXD,sCAWC"}
|