@carecard/jwt-read 3.0.2 → 3.0.3
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/index.d.ts +78 -0
- package/package.json +12 -6
package/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for reading and verifying JWTs.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Verifies a JWT from the 'Authorization: Bearer <token>' header and extracts it into req.jwt.
|
|
7
|
+
* Throws an error if invalid.
|
|
8
|
+
*/
|
|
9
|
+
export function verifyJwt(req: any, publicKey: string, customErrorFunction?: () => void): Promise<any>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verifies a JWT from a custom header and extracts it into req.jwt.
|
|
13
|
+
* Throws an error if invalid.
|
|
14
|
+
*/
|
|
15
|
+
export function verifyWebToken(req: any, publicKey: string, headerName: string, customErrorFunction?: () => void): Promise<any>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Verifies a JWT from the 'Authorization: Bearer <token>' header and extracts it into req.jwt.
|
|
19
|
+
* Returns false instead of throwing if invalid.
|
|
20
|
+
*/
|
|
21
|
+
export function verifyJwtNoThrow(req: any, publicKey: string): Promise<boolean>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Verifies a JWT from a custom header and extracts it into req.jwt.
|
|
25
|
+
* Returns false instead of throwing if invalid.
|
|
26
|
+
*/
|
|
27
|
+
export function verifyWebTokenNoThrow(req: any, publicKey: string, headerName: string): Promise<boolean>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Verifies a visitor token from the 'x-visitor-token' header and extracts it into req.visitor.
|
|
31
|
+
* Returns false instead of throwing if invalid.
|
|
32
|
+
*/
|
|
33
|
+
export function verifyVisitorNoThrow(req: any, publicKey: string): Promise<boolean>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns the client_id from the extracted JWT in req.jwt.
|
|
37
|
+
*/
|
|
38
|
+
export function jwtClientId(req: any): string | undefined;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the client_id from the extracted visitor token in req.visitor.
|
|
42
|
+
*/
|
|
43
|
+
export function visitorClientId(req: any): string | undefined;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Checks if the extracted JWT in req.jwt has expired.
|
|
47
|
+
*/
|
|
48
|
+
export function isJwtExpired(req: any, jwtValiditySeconds?: number): boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns the age of the extracted JWT in seconds.
|
|
52
|
+
*/
|
|
53
|
+
export function jwtAgeInSeconds(req: any): number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Verifies the JWT and checks if the user has the required role.
|
|
57
|
+
*/
|
|
58
|
+
export function verifyJwtAndRole(req: any, publicKey: string, userRole: string, customErrorFunction?: () => void): Promise<any>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Throws a Used_Token error.
|
|
62
|
+
*/
|
|
63
|
+
export function throwUsedTokenError(): never;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Checks if the user in the extracted JWT has the specified role.
|
|
67
|
+
*/
|
|
68
|
+
export function doesJwtUserHasRole(req: any, userRole: string): boolean;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets the full name of a role from its code (e.g., 'ad' -> 'admin').
|
|
72
|
+
*/
|
|
73
|
+
export function getNameOfRole(roleCode: string): string;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Gets the code of a role from its name (e.g., 'admin' -> 'ad').
|
|
77
|
+
*/
|
|
78
|
+
export function getCodeOfRole(roleName: string): string;
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carecard/jwt-read",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/CareCard-ca/pkg-jwt-read.git"
|
|
7
7
|
},
|
|
8
8
|
"description": "Jwt read functions",
|
|
9
9
|
"main": "index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"test": "export NODE_ENV=test && mocha --watch --recursive"
|
|
12
|
+
"test": "export NODE_ENV=test && mocha --watch --recursive",
|
|
13
|
+
"test:types": "tsc --noEmit && mocha -r ts-node/register test/types.test.ts"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
16
|
"auth",
|
|
@@ -18,11 +20,15 @@
|
|
|
18
20
|
"author": "CareCard team",
|
|
19
21
|
"license": "ISC",
|
|
20
22
|
"devDependencies": {
|
|
21
|
-
"mocha": "
|
|
23
|
+
"@types/mocha": "10.0.10",
|
|
24
|
+
"@types/node": "25.5.0",
|
|
25
|
+
"mocha": "11.7.5",
|
|
26
|
+
"ts-node": "10.9.2",
|
|
27
|
+
"typescript": "5.9.3"
|
|
22
28
|
},
|
|
23
29
|
"dependencies": {
|
|
24
|
-
"@carecard/auth-util": "3.0.
|
|
25
|
-
"@carecard/common-util": "
|
|
26
|
-
"@carecard/validate": "
|
|
30
|
+
"@carecard/auth-util": "3.0.3",
|
|
31
|
+
"@carecard/common-util": "3.0.3",
|
|
32
|
+
"@carecard/validate": "3.0.3"
|
|
27
33
|
}
|
|
28
34
|
}
|