@zeltjs/auth-jwt 0.8.1 → 0.8.2-canary.1
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/dist/index.cjs +1351 -0
- package/dist/index.d.cts +82 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +13 -6
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Env, Next, RequestContext, RequestContextSchema } from "@zeltjs/core";
|
|
2
|
+
import * as _$hono_utils_http_status0 from "hono/utils/http-status";
|
|
3
|
+
import * as _$hono_http_exception0 from "hono/http-exception";
|
|
4
|
+
|
|
5
|
+
//#region src/jwt.types.d.ts
|
|
6
|
+
interface JwtPayload {
|
|
7
|
+
sub?: string;
|
|
8
|
+
iat?: number;
|
|
9
|
+
exp?: number;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
type JwtDriver = 'header' | 'cookie';
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/jwt.config.d.ts
|
|
15
|
+
interface ResolveUserResult {
|
|
16
|
+
user: RequestContextSchema['user'];
|
|
17
|
+
roles: RequestContextSchema['authRoles'];
|
|
18
|
+
}
|
|
19
|
+
declare class JwtConfig {
|
|
20
|
+
protected readonly env: Env;
|
|
21
|
+
constructor(env?: Env);
|
|
22
|
+
/**
|
|
23
|
+
* @throws {ZeltJwtConfigError} When JWT_SECRET is not set
|
|
24
|
+
*/
|
|
25
|
+
get secret(): string;
|
|
26
|
+
get expiresIn(): string;
|
|
27
|
+
get driver(): JwtDriver;
|
|
28
|
+
get cookieName(): string;
|
|
29
|
+
get resolveUser(): (payload: JwtPayload) => Promise<ResolveUserResult>;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/jwt.errors.d.ts
|
|
33
|
+
type JwtConfigErrorReason = 'missing_secret';
|
|
34
|
+
declare const ZeltJwtConfigError: new (context: {
|
|
35
|
+
reason: JwtConfigErrorReason;
|
|
36
|
+
}, cause?: unknown) => Error & {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly context: {
|
|
39
|
+
reason: JwtConfigErrorReason;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/jwt.exceptions.d.ts
|
|
44
|
+
type UnauthorizedReason = 'missing_token' | 'invalid_token' | 'expired';
|
|
45
|
+
declare const UnauthorizedException: new (context: {
|
|
46
|
+
reason: UnauthorizedReason;
|
|
47
|
+
}, options?: {
|
|
48
|
+
status?: _$hono_utils_http_status0.ContentfulStatusCode;
|
|
49
|
+
cause?: unknown;
|
|
50
|
+
}) => _$hono_http_exception0.HTTPException & {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly context: {
|
|
53
|
+
reason: UnauthorizedReason;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/jwt.service.d.ts
|
|
58
|
+
declare class JwtService {
|
|
59
|
+
private readonly config;
|
|
60
|
+
constructor(config?: JwtConfig);
|
|
61
|
+
sign(payload: Record<string, unknown>): Promise<string>;
|
|
62
|
+
verify(token: string): Promise<JwtPayload>;
|
|
63
|
+
decode(token: string): JwtPayload | null;
|
|
64
|
+
private parseExpiresIn;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/jwt.middleware.d.ts
|
|
68
|
+
declare class JwtMiddleware {
|
|
69
|
+
private readonly jwtService;
|
|
70
|
+
private readonly config;
|
|
71
|
+
constructor(jwtService?: JwtService, config?: JwtConfig);
|
|
72
|
+
/**
|
|
73
|
+
* @throws {UnauthorizedException} When token is missing (401)
|
|
74
|
+
* @throws {UnauthorizedException} When token is invalid or expired (401)
|
|
75
|
+
* @throws {ZeltContextNotAvailableError}
|
|
76
|
+
*/
|
|
77
|
+
use(c: RequestContext, next: Next): Promise<Response | undefined>;
|
|
78
|
+
private extractToken;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { JwtConfig, type JwtConfigErrorReason, type JwtDriver, JwtMiddleware, type JwtPayload, JwtService, type ResolveUserResult, UnauthorizedException, type UnauthorizedReason, ZeltJwtConfigError };
|
|
82
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/jwt.types.ts","../src/jwt.config.ts","../src/jwt.errors.ts","../src/jwt.exceptions.ts","../src/jwt.service.ts","../src/jwt.middleware.ts"],"mappings":";;;;;UAAiB,UAAA;EACf,GAAA;EACA,GAAA;EACA,GAAA;EAAA,CACC,GAAA;AAAA;AAAA,KAGS,SAAA;;;UCDK,iBAAA;EACf,IAAA,EAAM,oBAAA;EACN,KAAA,EAAO,oBAAA;AAAA;AAAA,cAII,SAAA;EAAA,mBACoB,GAAA,EAAG,GAAA;cAAH,GAAA,GAAG,GAAA;EDXlC;;;EAAA,ICgBI,MAAA,CAAA;EAAA,IAQA,SAAA,CAAA;EAAA,IAIA,MAAA,CAAA,GAAU,SAAA;EAAA,IAIV,UAAA,CAAA;EAAA,IAIA,WAAA,CAAA,IAAgB,OAAA,EAAS,UAAA,KAAe,OAAA,CAAQ,iBAAA;AAAA;;;KCpC1C,oBAAA;AAAA,cAMC,kBAAA,OAAkB,OAAA;UAEb,oBAAA;AAAA;;;YAAA,oBAAA;EAAA;AAAA;;;KCRN,kBAAA;AAAA,cAQC,qBAAA,OAAqB,OAAA;UAGhB,kBAAA;AAAA;WAAkB,yBAAA,CASc,oBAAA;;MAAA,sBAAA,CAAA,aAAA;EAAA;;YAThC,kBAAA;EAAA;AAAA;;;cCNL,UAAA;EAAA,iBACkB,MAAA;cAAA,MAAA,GAAM,SAAA;EAE7B,IAAA,CAAK,OAAA,EAAS,MAAA,oBAA0B,OAAA;EAaxC,MAAA,CAAO,KAAA,WAAgB,OAAA,CAAQ,UAAA;EAMrC,MAAA,CAAO,KAAA,WAAgB,UAAA;EAAA,QAQf,cAAA;AAAA;;;cC7BG,aAAA;EAAA,iBAEQ,UAAA;EAAA,iBACA,MAAA;cADA,UAAA,GAAU,UAAA,EACV,MAAA,GAAM,SAAA;;;;;;EAQnB,GAAA,CAAI,CAAA,EAAG,cAAA,EAAgB,IAAA,EAAM,IAAA,GAAO,OAAA,CAAQ,QAAA;EAAA,QAsB1C,YAAA;AAAA"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/jwt.types.ts","../src/jwt.config.ts","../src/jwt.errors.ts","../src/jwt.exceptions.ts","../src/jwt.service.ts","../src/jwt.middleware.ts"],"mappings":";;;;;UAAiB,UAAA;EACf,GAAA;EACA,GAAA;EACA,GAAA;EAAA,CACC,GAAA;AAAA;AAAA,KAGS,SAAA;;;UCDK,iBAAA;EACf,IAAA,EAAM,oBAAA;EACN,KAAA,EAAO,oBAAA;AAAA;AAAA,cAII,SAAA;EAAA,mBACoB,GAAA,EAAG,GAAA;cAAH,GAAA,GAAG,GAAA;EDXlC;;;EAAA,ICgBI,MAAA,CAAA;EAAA,IAQA,SAAA,CAAA;EAAA,IAIA,MAAA,CAAA,GAAU,SAAA;EAAA,IAIV,UAAA,CAAA;EAAA,IAIA,WAAA,CAAA,IAAgB,OAAA,EAAS,UAAA,KAAe,OAAA,CAAQ,iBAAA;AAAA;;;KCpC1C,oBAAA;AAAA,cAMC,kBAAA,OAAkB,OAAA;UAEb,oBAAA;AAAA;;;YAAA,oBAAA;EAAA;AAAA;;;KCRN,kBAAA;AAAA,cAQC,qBAAA,OAAqB,OAAA;UAGhB,kBAAA;AAAA;WAAkB,yBAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/jwt.types.ts","../src/jwt.config.ts","../src/jwt.errors.ts","../src/jwt.exceptions.ts","../src/jwt.service.ts","../src/jwt.middleware.ts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