sentri 1.1.1 → 1.1.2
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 +107 -43
- package/dist/client.d.ts +10 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/errors/AuthError.d.ts +20 -22
- package/dist/errors/AuthError.d.ts.map +1 -1
- package/dist/errors/AuthError.js +17 -19
- package/dist/errors/AuthError.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/libs/config.d.ts +2 -2
- package/dist/libs/config.js +8 -8
- package/dist/libs/config.js.map +1 -1
- package/dist/libs/token.d.ts +2 -2
- package/dist/libs/token.js +10 -10
- package/dist/libs/token.js.map +1 -1
- package/dist/middleware/authorize.d.ts +1 -1
- package/dist/middleware/authorize.js +4 -4
- package/dist/middleware/authorize.js.map +1 -1
- package/dist/middleware/errorHandler.d.ts +11 -13
- package/dist/middleware/errorHandler.d.ts.map +1 -1
- package/dist/middleware/errorHandler.js +11 -13
- package/dist/middleware/errorHandler.js.map +1 -1
- package/dist/middleware/permit.d.ts +1 -1
- package/dist/middleware/permit.js +4 -4
- package/dist/middleware/permit.js.map +1 -1
- package/dist/middleware/protect.d.ts +1 -1
- package/dist/middleware/protect.js +4 -4
- package/dist/middleware/protect.js.map +1 -1
- package/dist/middleware/router.d.ts.map +1 -1
- package/dist/middleware/router.js +10 -10
- package/dist/middleware/router.js.map +1 -1
- package/dist/services/auth.d.ts +5 -5
- package/dist/services/auth.d.ts.map +1 -1
- package/dist/services/auth.js +15 -15
- package/dist/services/auth.js.map +1 -1
- package/dist/types/auth.d.ts +21 -21
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +1 -1
- package/dist/types/auth.js.map +1 -1
- package/package.json +1 -1
- package/templates/drizzle/auth.ts +5 -5
- package/templates/prisma/auth.ts +5 -5
package/dist/libs/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/libs/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/libs/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAkBrD,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,MAAkB;IAC/C,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,WAAW,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,iBAAiB,EAAE,CAAC;QAC7C,MAAM,IAAI,WAAW,CACnB,qBAAqB,EACrB,2BAA2B,iBAAiB,0CAA0C,CACvF,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,eAAe,IAAI,UAAU,GAAG,eAAe,EAAE,CAAC;QAClG,MAAM,IAAI,WAAW,CACnB,qBAAqB,EACrB,yCAAyC,eAAe,QAAQ,eAAe,EAAE,CAClF,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,WAAW,CAAC,qBAAqB,EAAE,2CAA2C,CAAC,CAAC;IAC5F,CAAC;IAED,IAAI,CAA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AAC,CAAC;IACpF,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;AACvC,CAAC"}
|
package/dist/libs/token.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare function signRefreshToken(sessionId: string, config: AuthConfig):
|
|
|
29
29
|
* @param token - Compact JWT access token string.
|
|
30
30
|
* @param config - Auth configuration used to derive the secret and algorithm.
|
|
31
31
|
* @returns Decoded `AuthUser` payload (id, identifier, roles).
|
|
32
|
-
* @throws {
|
|
32
|
+
* @throws {SentriError} With `TOKEN_EXPIRED` if expired, `TOKEN_INVALID` otherwise.
|
|
33
33
|
*/
|
|
34
34
|
export declare function verifyAccessToken(token: string, config: AuthConfig): AuthUser;
|
|
35
35
|
/**
|
|
@@ -38,7 +38,7 @@ export declare function verifyAccessToken(token: string, config: AuthConfig): Au
|
|
|
38
38
|
* @param token - Compact JWT refresh token string.
|
|
39
39
|
* @param config - Auth configuration used to derive the secret and algorithm.
|
|
40
40
|
* @returns Object with `sessionId` matching the one passed to {@link signRefreshToken}.
|
|
41
|
-
* @throws {
|
|
41
|
+
* @throws {SentriError} With `TOKEN_EXPIRED` if expired, `TOKEN_INVALID` otherwise.
|
|
42
42
|
*/
|
|
43
43
|
export declare function verifyRefreshToken(token: string, config: AuthConfig): {
|
|
44
44
|
sessionId: string;
|
package/dist/libs/token.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import jwt, {} from 'jsonwebtoken';
|
|
2
|
-
import {
|
|
2
|
+
import { SentriError } from '../errors/AuthError.js';
|
|
3
3
|
import { resolveConfig } from './config.js';
|
|
4
4
|
/**
|
|
5
5
|
* Derive separate HMAC secrets for access and refresh tokens from a single
|
|
@@ -31,30 +31,30 @@ function sign(payload, secret, expiresIn, algorithm) {
|
|
|
31
31
|
return jwt.sign(payload, secret, options);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
* Verify and decode a JWT, mapping jsonwebtoken errors to typed {@link
|
|
34
|
+
* Verify and decode a JWT, mapping jsonwebtoken errors to typed {@link SentriError}s.
|
|
35
35
|
*
|
|
36
36
|
* @param token - Compact JWT string to verify.
|
|
37
37
|
* @param secret - HMAC key used to sign the token.
|
|
38
38
|
* @param algorithm - Expected signing algorithm.
|
|
39
39
|
* @returns Decoded payload cast to `T`.
|
|
40
|
-
* @throws {
|
|
41
|
-
* @throws {
|
|
40
|
+
* @throws {SentriError} With `TOKEN_EXPIRED` if the token's `exp` claim is in the past.
|
|
41
|
+
* @throws {SentriError} With `TOKEN_INVALID` for any other verification failure.
|
|
42
42
|
*/
|
|
43
43
|
function verify(token, secret, algorithm) {
|
|
44
44
|
try {
|
|
45
45
|
const decoded = jwt.verify(token, secret, { algorithms: [algorithm] });
|
|
46
46
|
if (typeof decoded === 'string' || decoded === null) {
|
|
47
|
-
throw new
|
|
47
|
+
throw new SentriError('TOKEN_INVALID', 'Token payload is not an object');
|
|
48
48
|
}
|
|
49
49
|
return decoded;
|
|
50
50
|
}
|
|
51
51
|
catch (err) {
|
|
52
|
-
if (err instanceof
|
|
52
|
+
if (err instanceof SentriError)
|
|
53
53
|
throw err;
|
|
54
54
|
if (err instanceof jwt.TokenExpiredError) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new SentriError('TOKEN_EXPIRED', 'Token has expired');
|
|
56
56
|
}
|
|
57
|
-
throw new
|
|
57
|
+
throw new SentriError('TOKEN_INVALID', 'Token is invalid or malformed');
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
@@ -95,7 +95,7 @@ export function signRefreshToken(sessionId, config) {
|
|
|
95
95
|
* @param token - Compact JWT access token string.
|
|
96
96
|
* @param config - Auth configuration used to derive the secret and algorithm.
|
|
97
97
|
* @returns Decoded `AuthUser` payload (id, identifier, roles).
|
|
98
|
-
* @throws {
|
|
98
|
+
* @throws {SentriError} With `TOKEN_EXPIRED` if expired, `TOKEN_INVALID` otherwise.
|
|
99
99
|
*/
|
|
100
100
|
export function verifyAccessToken(token, config) {
|
|
101
101
|
const resolved = resolveConfig(config);
|
|
@@ -108,7 +108,7 @@ export function verifyAccessToken(token, config) {
|
|
|
108
108
|
* @param token - Compact JWT refresh token string.
|
|
109
109
|
* @param config - Auth configuration used to derive the secret and algorithm.
|
|
110
110
|
* @returns Object with `sessionId` matching the one passed to {@link signRefreshToken}.
|
|
111
|
-
* @throws {
|
|
111
|
+
* @throws {SentriError} With `TOKEN_EXPIRED` if expired, `TOKEN_INVALID` otherwise.
|
|
112
112
|
*/
|
|
113
113
|
export function verifyRefreshToken(token, config) {
|
|
114
114
|
const resolved = resolveConfig(config);
|
package/dist/libs/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/libs/token.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAoB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/libs/token.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,EAAE,EAAoB,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO;QACL,MAAM,EAAE,GAAG,MAAM,SAAS;QAC1B,OAAO,EAAE,GAAG,MAAM,UAAU;KAC7B,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,IAAI,CACX,OAAe,EACf,MAAc,EACd,SAA0B,EAC1B,SAAsC;IAEtC,MAAM,OAAO,GAAgB;QAC3B,SAAS,EAAE,SAAyD;QACpE,SAAS;KACV,CAAC;IACF,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED;;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OAAO,IAAI,CAAC,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;AACrF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,MAAkB;IACjE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClD,OAAO,MAAM,CAAW,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,MAAkB;IAClE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnD,OAAO,MAAM,CAAwB,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -3,7 +3,7 @@ import type { RequestHandler } from 'express';
|
|
|
3
3
|
* Express middleware factory for role-based access control (RBAC).
|
|
4
4
|
*
|
|
5
5
|
* Passes if the authenticated user (set by `protect()`) has **at least one**
|
|
6
|
-
* of the specified `allowedRoles`. Calls `next(
|
|
6
|
+
* of the specified `allowedRoles`. Calls `next(SentriError)` with code `FORBIDDEN`
|
|
7
7
|
* if no roles match, or `UNAUTHORIZED` if `req.user` is absent.
|
|
8
8
|
*
|
|
9
9
|
* Must be used **after** `protect()`.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SentriError } from '../errors/AuthError.js';
|
|
2
2
|
/**
|
|
3
3
|
* Express middleware factory for role-based access control (RBAC).
|
|
4
4
|
*
|
|
5
5
|
* Passes if the authenticated user (set by `protect()`) has **at least one**
|
|
6
|
-
* of the specified `allowedRoles`. Calls `next(
|
|
6
|
+
* of the specified `allowedRoles`. Calls `next(SentriError)` with code `FORBIDDEN`
|
|
7
7
|
* if no roles match, or `UNAUTHORIZED` if `req.user` is absent.
|
|
8
8
|
*
|
|
9
9
|
* Must be used **after** `protect()`.
|
|
@@ -17,12 +17,12 @@ import { AuthError } from '../errors/AuthError.js';
|
|
|
17
17
|
export function authorize(...allowedRoles) {
|
|
18
18
|
return (request, _response, next) => {
|
|
19
19
|
if (!request.user) {
|
|
20
|
-
return next(new
|
|
20
|
+
return next(new SentriError('UNAUTHORIZED', 'Not authenticated'));
|
|
21
21
|
}
|
|
22
22
|
const userRoles = request.user.roles;
|
|
23
23
|
const hasRole = allowedRoles.some((role) => userRoles.includes(role));
|
|
24
24
|
if (!hasRole) {
|
|
25
|
-
return next(new
|
|
25
|
+
return next(new SentriError('FORBIDDEN', `Requires one of roles: ${allowedRoles.join(', ')}`));
|
|
26
26
|
}
|
|
27
27
|
next();
|
|
28
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/middleware/authorize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/middleware/authorize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CAAuB,GAAG,YAAqB;IACtE,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,IAAI,WAAW,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAC,CAAC;QACpE,CAAC;QACD,MAAM,SAAS,GAAsB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;QACxD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CACT,IAAI,WAAW,CAAC,WAAW,EAAE,0BAA0B,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAClF,CAAC;QACJ,CAAC;QACD,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,64 +4,62 @@ import type { ErrorRequestHandler } from 'express';
|
|
|
4
4
|
*/
|
|
5
5
|
export interface ErrorHandlerOptions {
|
|
6
6
|
/**
|
|
7
|
-
* Called for errors that are **not**
|
|
7
|
+
* Called for errors that are **not** a `SentriError` instance (or subclass).
|
|
8
8
|
*
|
|
9
9
|
* Use this to log unexpected server errors before the generic 500 response
|
|
10
10
|
* is sent. The error is passed as-is and may be any unknown value.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
-
* app.use(
|
|
13
|
+
* app.use(auth.errorHandler({
|
|
14
14
|
* onUnhandled: (err) => logger.error('Unhandled error', { err }),
|
|
15
15
|
* }));
|
|
16
16
|
*/
|
|
17
17
|
onUnhandled?: (error: unknown) => void;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Creates an Express error-handling middleware that formats every `
|
|
20
|
+
* Creates an Express error-handling middleware that formats every `SentriError`
|
|
21
21
|
* (including subclasses) into the standard sentri response envelope:
|
|
22
22
|
*
|
|
23
23
|
* ```json
|
|
24
24
|
* { "error": true, "statusCode": 401, "code": "UNAUTHORIZED", "message": "...", "data": null }
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
-
*
|
|
27
|
+
* Prefer using `auth.errorHandler()` instead of calling this directly:
|
|
28
28
|
*
|
|
29
29
|
* ```typescript
|
|
30
|
-
* import { createErrorHandler } from 'sentri';
|
|
31
|
-
*
|
|
32
30
|
* app.use('/auth', auth.router());
|
|
33
31
|
* app.use('/api', apiRouter);
|
|
34
32
|
*
|
|
35
33
|
* // Must come after all route/middleware registrations
|
|
36
|
-
* app.use(
|
|
34
|
+
* app.use(auth.errorHandler());
|
|
37
35
|
* ```
|
|
38
36
|
*
|
|
39
37
|
* ---
|
|
40
38
|
*
|
|
41
39
|
* **Works with built-in sentri errors and your own subclasses**
|
|
42
40
|
*
|
|
43
|
-
* Because `instanceof
|
|
41
|
+
* Because `instanceof SentriError` matches any subclass, you can define
|
|
44
42
|
* application-specific error types and have them automatically formatted
|
|
45
43
|
* by this handler:
|
|
46
44
|
*
|
|
47
45
|
* ```typescript
|
|
48
|
-
* import {
|
|
46
|
+
* import { SentriError } from 'sentri';
|
|
49
47
|
*
|
|
50
|
-
* // Extend
|
|
51
|
-
* export class NotFoundError extends
|
|
48
|
+
* // Extend SentriError for domain-specific failures
|
|
49
|
+
* export class NotFoundError extends SentriError {
|
|
52
50
|
* constructor(resource: string) {
|
|
53
51
|
* super('NOT_FOUND', `${resource} not found`, 404);
|
|
54
52
|
* }
|
|
55
53
|
* }
|
|
56
54
|
*
|
|
57
|
-
* export class PaymentError extends
|
|
55
|
+
* export class PaymentError extends SentriError {
|
|
58
56
|
* constructor(message: string) {
|
|
59
57
|
* super('PAYMENT_FAILED', message, 402);
|
|
60
58
|
* }
|
|
61
59
|
* }
|
|
62
60
|
*
|
|
63
61
|
* // All of the above are caught and formatted by one handler
|
|
64
|
-
* app.use(
|
|
62
|
+
* app.use(auth.errorHandler({
|
|
65
63
|
* onUnhandled: (err) => console.error('Unexpected error:', err),
|
|
66
64
|
* }));
|
|
67
65
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAED
|
|
1
|
+
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,mBAAmB,CAsBrF"}
|
|
@@ -1,50 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SentriError } from '../errors/AuthError.js';
|
|
2
2
|
/**
|
|
3
|
-
* Creates an Express error-handling middleware that formats every `
|
|
3
|
+
* Creates an Express error-handling middleware that formats every `SentriError`
|
|
4
4
|
* (including subclasses) into the standard sentri response envelope:
|
|
5
5
|
*
|
|
6
6
|
* ```json
|
|
7
7
|
* { "error": true, "statusCode": 401, "code": "UNAUTHORIZED", "message": "...", "data": null }
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* Prefer using `auth.errorHandler()` instead of calling this directly:
|
|
11
11
|
*
|
|
12
12
|
* ```typescript
|
|
13
|
-
* import { createErrorHandler } from 'sentri';
|
|
14
|
-
*
|
|
15
13
|
* app.use('/auth', auth.router());
|
|
16
14
|
* app.use('/api', apiRouter);
|
|
17
15
|
*
|
|
18
16
|
* // Must come after all route/middleware registrations
|
|
19
|
-
* app.use(
|
|
17
|
+
* app.use(auth.errorHandler());
|
|
20
18
|
* ```
|
|
21
19
|
*
|
|
22
20
|
* ---
|
|
23
21
|
*
|
|
24
22
|
* **Works with built-in sentri errors and your own subclasses**
|
|
25
23
|
*
|
|
26
|
-
* Because `instanceof
|
|
24
|
+
* Because `instanceof SentriError` matches any subclass, you can define
|
|
27
25
|
* application-specific error types and have them automatically formatted
|
|
28
26
|
* by this handler:
|
|
29
27
|
*
|
|
30
28
|
* ```typescript
|
|
31
|
-
* import {
|
|
29
|
+
* import { SentriError } from 'sentri';
|
|
32
30
|
*
|
|
33
|
-
* // Extend
|
|
34
|
-
* export class NotFoundError extends
|
|
31
|
+
* // Extend SentriError for domain-specific failures
|
|
32
|
+
* export class NotFoundError extends SentriError {
|
|
35
33
|
* constructor(resource: string) {
|
|
36
34
|
* super('NOT_FOUND', `${resource} not found`, 404);
|
|
37
35
|
* }
|
|
38
36
|
* }
|
|
39
37
|
*
|
|
40
|
-
* export class PaymentError extends
|
|
38
|
+
* export class PaymentError extends SentriError {
|
|
41
39
|
* constructor(message: string) {
|
|
42
40
|
* super('PAYMENT_FAILED', message, 402);
|
|
43
41
|
* }
|
|
44
42
|
* }
|
|
45
43
|
*
|
|
46
44
|
* // All of the above are caught and formatted by one handler
|
|
47
|
-
* app.use(
|
|
45
|
+
* app.use(auth.errorHandler({
|
|
48
46
|
* onUnhandled: (err) => console.error('Unexpected error:', err),
|
|
49
47
|
* }));
|
|
50
48
|
* ```
|
|
@@ -54,7 +52,7 @@ import { AuthError } from '../errors/AuthError.js';
|
|
|
54
52
|
*/
|
|
55
53
|
export function createErrorHandler(options) {
|
|
56
54
|
return (err, _req, res, _next) => {
|
|
57
|
-
if (err instanceof
|
|
55
|
+
if (err instanceof SentriError) {
|
|
58
56
|
res.status(err.statusCode).json({
|
|
59
57
|
error: true,
|
|
60
58
|
statusCode: err.statusCode,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../src/middleware/errorHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAoBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA6B;IAC9D,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAC/B,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;YAC/B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;gBAC9B,KAAK,EAAE,IAAI;gBACX,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,IAAI,EAAE,IAAI;aACX,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;QAE5B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACnB,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,uBAAuB;YAChC,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -31,7 +31,7 @@ export interface PermitOptions<TRole extends string> {
|
|
|
31
31
|
* Express middleware factory for resource-level permission checks.
|
|
32
32
|
*
|
|
33
33
|
* Must be used **after** `protect()`. Evaluates a check function against the
|
|
34
|
-
* current request; calls `next(
|
|
34
|
+
* current request; calls `next(SentriError)` with code `FORBIDDEN` if it returns `false`.
|
|
35
35
|
*
|
|
36
36
|
* Accepts either a bare check function or an options object with an optional
|
|
37
37
|
* `roles` list whose members bypass the check entirely.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SentriError } from '../errors/AuthError.js';
|
|
2
2
|
/**
|
|
3
3
|
* Express middleware factory for resource-level permission checks.
|
|
4
4
|
*
|
|
5
5
|
* Must be used **after** `protect()`. Evaluates a check function against the
|
|
6
|
-
* current request; calls `next(
|
|
6
|
+
* current request; calls `next(SentriError)` with code `FORBIDDEN` if it returns `false`.
|
|
7
7
|
*
|
|
8
8
|
* Accepts either a bare check function or an options object with an optional
|
|
9
9
|
* `roles` list whose members bypass the check entirely.
|
|
@@ -36,7 +36,7 @@ export function permit(optionsOrCheck) {
|
|
|
36
36
|
: optionsOrCheck;
|
|
37
37
|
return async (request, _response, next) => {
|
|
38
38
|
if (!request.user) {
|
|
39
|
-
return next(new
|
|
39
|
+
return next(new SentriError('UNAUTHORIZED', 'Not authenticated'));
|
|
40
40
|
}
|
|
41
41
|
if (options.roles && options.roles.length > 0) {
|
|
42
42
|
const userRoles = request.user.roles;
|
|
@@ -50,7 +50,7 @@ export function permit(optionsOrCheck) {
|
|
|
50
50
|
next();
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
next(new
|
|
53
|
+
next(new SentriError('FORBIDDEN', 'You do not have permission to perform this action'));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/middleware/permit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/middleware/permit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAgCrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,MAAM,CACpB,cAAkD;IAElD,MAAM,OAAO,GACX,OAAO,cAAc,KAAK,UAAU;QAClC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE;QAC3B,CAAC,CAAC,cAAc,CAAC;IAErB,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;QACxC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,IAAI,WAAW,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9C,MAAM,SAAS,GAAsB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YACxD,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAC7E,IAAI,aAAa;gBAAE,OAAO,IAAI,EAAE,CAAC;QACnC,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,EAAE,CAAC;YACT,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,WAAW,CAAC,WAAW,EAAE,mDAAmD,CAAC,CAAC,CAAC;YAC1F,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -4,7 +4,7 @@ import type { AuthConfig } from '../types/auth.js';
|
|
|
4
4
|
* Express middleware factory that enforces JWT authentication and session validity.
|
|
5
5
|
*
|
|
6
6
|
* Reads the `Authorization: Bearer <token>` header, verifies the access token,
|
|
7
|
-
* and attaches the decoded payload to `req.user`. Calls `next(
|
|
7
|
+
* and attaches the decoded payload to `req.user`. Calls `next(SentriError)` on
|
|
8
8
|
* any failure so your error handler can convert it to an HTTP response.
|
|
9
9
|
*
|
|
10
10
|
* Since sentri 1.1.0 access tokens embed a `sessionId` claim. When this claim
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SentriError } from '../errors/AuthError.js';
|
|
2
2
|
import { verifyAccessToken } from '../libs/token.js';
|
|
3
3
|
/**
|
|
4
4
|
* Express middleware factory that enforces JWT authentication and session validity.
|
|
5
5
|
*
|
|
6
6
|
* Reads the `Authorization: Bearer <token>` header, verifies the access token,
|
|
7
|
-
* and attaches the decoded payload to `req.user`. Calls `next(
|
|
7
|
+
* and attaches the decoded payload to `req.user`. Calls `next(SentriError)` on
|
|
8
8
|
* any failure so your error handler can convert it to an HTTP response.
|
|
9
9
|
*
|
|
10
10
|
* Since sentri 1.1.0 access tokens embed a `sessionId` claim. When this claim
|
|
@@ -31,7 +31,7 @@ export function protect(config) {
|
|
|
31
31
|
return async (request, _response, next) => {
|
|
32
32
|
const authHeader = request.headers['authorization'];
|
|
33
33
|
if (!authHeader?.startsWith('Bearer ')) {
|
|
34
|
-
return next(new
|
|
34
|
+
return next(new SentriError('UNAUTHORIZED', 'Missing or malformed Authorization header'));
|
|
35
35
|
}
|
|
36
36
|
const token = authHeader.slice(7);
|
|
37
37
|
try {
|
|
@@ -41,7 +41,7 @@ export function protect(config) {
|
|
|
41
41
|
if (payload.sessionId) {
|
|
42
42
|
const session = await config.adapter.session.findById(payload.sessionId);
|
|
43
43
|
if (!session) {
|
|
44
|
-
return next(new
|
|
44
|
+
return next(new SentriError('UNAUTHORIZED', 'Session has been revoked'));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../src/middleware/protect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"protect.js","sourceRoot":"","sources":["../../src/middleware/protect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC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ourceRoot":"","sources":["../../src/middleware/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkD,MAAM,SAAS,CAAC;AAEjF,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/middleware/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkD,MAAM,SAAS,CAAC;AAEjF,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,kBAAkB,CAAC;AA4E9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,SAAS,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,MAAM,CAwLxF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { SentriError } from '../errors/AuthError.js';
|
|
3
|
+
import { register, login, refresh, logout, logoutAll, assignRoles } from '../services/auth.js';
|
|
4
4
|
import { resolveConfig, parseExpiry } from '../libs/config.js';
|
|
5
5
|
import { protect } from './protect.js';
|
|
6
6
|
import { authorize } from './authorize.js';
|
|
@@ -11,7 +11,7 @@ const MIN_PASSWORD_LENGTH = 8;
|
|
|
11
11
|
const MAX_PASSWORD_LENGTH = 72;
|
|
12
12
|
const MAX_IDENTIFIER_LENGTH = 255;
|
|
13
13
|
function badRequest(message) {
|
|
14
|
-
return new
|
|
14
|
+
return new SentriError('VALIDATION_ERROR', message);
|
|
15
15
|
}
|
|
16
16
|
function ok(response, statusCode, message, data) {
|
|
17
17
|
response.status(statusCode).json({ error: false, statusCode, message, data });
|
|
@@ -21,7 +21,7 @@ function fail(response, error) {
|
|
|
21
21
|
}
|
|
22
22
|
function parseBody(body) {
|
|
23
23
|
if (body === null || body === undefined || typeof body !== 'object' || Array.isArray(body)) {
|
|
24
|
-
throw new
|
|
24
|
+
throw new SentriError('VALIDATION_ERROR', 'Request body is missing or not a JSON object. Did you apply express.json()?');
|
|
25
25
|
}
|
|
26
26
|
return body;
|
|
27
27
|
}
|
|
@@ -56,14 +56,14 @@ function clearCookie(response, config) {
|
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Validate the `X-Api-Key` header when `config.apiKey` is set.
|
|
59
|
-
* Throws `
|
|
59
|
+
* Throws `SentriError` with code `UNAUTHORIZED` on mismatch.
|
|
60
60
|
*/
|
|
61
61
|
function validateApiKey(request, config) {
|
|
62
62
|
if (!config.apiKey)
|
|
63
63
|
return;
|
|
64
64
|
const provided = request.headers['x-api-key'];
|
|
65
65
|
if (typeof provided !== 'string' || provided !== config.apiKey) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new SentriError('UNAUTHORIZED', 'Invalid or missing API key');
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
@@ -100,7 +100,7 @@ export function createAuthRouter(config) {
|
|
|
100
100
|
const router = Router();
|
|
101
101
|
// Resolve service functions — use custom override from config.router when provided, else fall back to the built-in service.
|
|
102
102
|
const baseConfig = config;
|
|
103
|
-
const registerFn = config.router?.register ?? ((input) =>
|
|
103
|
+
const registerFn = config.router?.register ?? ((input) => register(input, baseConfig));
|
|
104
104
|
const loginFn = config.router?.login ?? ((input) => login(input, baseConfig));
|
|
105
105
|
const refreshFn = config.router?.refresh ?? ((token) => refresh(token, baseConfig));
|
|
106
106
|
const logoutFn = config.router?.logout ?? ((token) => token !== undefined ? logout(token, baseConfig) : Promise.resolve());
|
|
@@ -184,7 +184,7 @@ export function createAuthRouter(config) {
|
|
|
184
184
|
try {
|
|
185
185
|
const fromCookie = readCookie(request.headers['cookie'], getCookieName(config));
|
|
186
186
|
if (!fromCookie) {
|
|
187
|
-
throw new
|
|
187
|
+
throw new SentriError('UNAUTHORIZED', 'Refresh token cookie is missing');
|
|
188
188
|
}
|
|
189
189
|
const result = await refreshFn(fromCookie);
|
|
190
190
|
if (!result.success) {
|
|
@@ -249,10 +249,10 @@ export function createAuthRouter(config) {
|
|
|
249
249
|
next(error);
|
|
250
250
|
}
|
|
251
251
|
});
|
|
252
|
-
// Centralized error handler — converts
|
|
252
|
+
// Centralized error handler — converts SentriError (and unexpected errors) to the
|
|
253
253
|
// standard envelope so every endpoint produces a consistent shape on failure.
|
|
254
254
|
router.use((error, _request, response, _next) => {
|
|
255
|
-
if (error instanceof
|
|
255
|
+
if (error instanceof SentriError) {
|
|
256
256
|
fail(response, error);
|
|
257
257
|
}
|
|
258
258
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/middleware/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkD,MAAM,SAAS,CAAC;AACjF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/middleware/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkD,MAAM,SAAS,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,6EAA6E;AAC7E,6EAA6E;AAC7E,wCAAwC;AACxC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAElC,SAAS,UAAU,CAAC,OAAe;IACjC,OAAO,IAAI,WAAW,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,EAAE,CA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|
+
import type { AssignRolesResult, AuthConfig, AuthResult, LoginInput, RefreshResult, RegisterInput, RegisterResult } from '../types/auth.js';
|
|
2
2
|
/**
|
|
3
3
|
* Register a new user.
|
|
4
4
|
*
|
|
@@ -6,15 +6,15 @@ import type { AssignRolesResult, AuthConfig, AuthResult, LoginInput, RefreshResu
|
|
|
6
6
|
* identifiers, hashes the password with bcrypt, creates the user record via
|
|
7
7
|
* the adapter, and returns the created user.
|
|
8
8
|
*
|
|
9
|
-
* No tokens are issued — the caller should invoke `login` after
|
|
10
|
-
* immediate authentication is desired.
|
|
9
|
+
* No tokens are issued — the caller should invoke `login` after registration
|
|
10
|
+
* if immediate authentication is desired.
|
|
11
11
|
*
|
|
12
|
-
* @param input -
|
|
12
|
+
* @param input - Registration data: identifier, plain-text password, and optional roles.
|
|
13
13
|
* @param config - Auth configuration containing the adapter and role definitions.
|
|
14
14
|
* @returns `{ success: true, user }` on success, or `{ success: false, error }` with
|
|
15
15
|
* code `INVALID_ROLE` or `USER_ALREADY_EXISTS` on failure.
|
|
16
16
|
*/
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function register(input: RegisterInput, config: AuthConfig): Promise<RegisterResult>;
|
|
18
18
|
/**
|
|
19
19
|
* Authenticate an existing user by identifier and plain-text password.
|
|
20
20
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE5I;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,cAAc,CAAC,CAoBzB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,KAAK,CACzB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAqBrB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAC3B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,aAAa,CAAC,CA+BxB;AAED;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAC1B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAAE,EACpB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,iBAAiB,CAAC,CAiB5B"}
|