@meistrari/data-token 0.0.17 → 0.0.19
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/adapters/elysia.mjs +0 -1
- package/dist/adapters/hono.mjs +0 -1
- package/dist/index.d.mts +56 -4
- package/dist/index.d.ts +56 -4
- package/dist/index.mjs +10 -4
- package/package.json +5 -1
package/dist/adapters/elysia.mjs
CHANGED
package/dist/adapters/hono.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createMiddleware } from 'hono/factory';
|
|
2
2
|
import { getValidator } from '../index.mjs';
|
|
3
3
|
import 'jose';
|
|
4
|
-
import 'jose/dist/types/util/errors';
|
|
5
4
|
import 'zod';
|
|
6
5
|
|
|
7
6
|
function createDataTokenMiddleware(url, skipOnError = false, getToken = (c) => c.req.header("x-data-token") ?? "") {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as jose from 'jose';
|
|
2
|
+
import { errors } from 'jose';
|
|
3
|
+
import * as zod from 'zod';
|
|
2
4
|
export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb5e.mjs';
|
|
3
|
-
import 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Get a validator function that can validate a data token.
|
|
@@ -30,6 +31,57 @@ declare function getValidator(jwksUrl: string, { algorithms }?: {
|
|
|
30
31
|
* @param err - The error to check.
|
|
31
32
|
* @returns True if the error is an authentication error, false otherwise.
|
|
32
33
|
*/
|
|
33
|
-
declare function isAuthenticationError(err: unknown): err is JOSEError;
|
|
34
|
+
declare function isAuthenticationError(err: unknown): err is errors.JOSEError;
|
|
35
|
+
/**
|
|
36
|
+
* **THIS DOES NOT VALIDATE THE TOKEN. DO NOT USE IN AUTHENTICATION-SENSITIVE CONTEXTS**
|
|
37
|
+
*
|
|
38
|
+
* Decodes a JWT and tries to parse its payload according to the data token schema.
|
|
39
|
+
*
|
|
40
|
+
* @param jwt JWT string to be parsed
|
|
41
|
+
* @returns Result of trying to porse the payload
|
|
42
|
+
*/
|
|
43
|
+
declare function safeParse(jwt: string): zod.SafeParseReturnType<{
|
|
44
|
+
requestId: string;
|
|
45
|
+
workspace: {
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
};
|
|
49
|
+
user?: {
|
|
50
|
+
id: string;
|
|
51
|
+
email: string;
|
|
52
|
+
uuid: string | null;
|
|
53
|
+
} | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
requestId: string;
|
|
56
|
+
workspace: {
|
|
57
|
+
id: string;
|
|
58
|
+
title: string;
|
|
59
|
+
};
|
|
60
|
+
user?: {
|
|
61
|
+
id: string;
|
|
62
|
+
email: string;
|
|
63
|
+
uuid: string | null;
|
|
64
|
+
} | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* **THIS DOES NOT VALIDATE THE TOKEN. DO NOT USE IN AUTHENTICATION-SENSITIVE CONTEXTS**
|
|
68
|
+
*
|
|
69
|
+
* Type-unsafe version of {@link safeParse}. Decodes a JWT and casts its type to {@link DataToken} but **does not perform any payload validation**.
|
|
70
|
+
*
|
|
71
|
+
* @param jwt JWT string to be decoded
|
|
72
|
+
* @returns The JWT payload typed as a DataToken
|
|
73
|
+
*/
|
|
74
|
+
declare function unsafeDecode(jwt: string): {
|
|
75
|
+
requestId: string;
|
|
76
|
+
workspace: {
|
|
77
|
+
id: string;
|
|
78
|
+
title: string;
|
|
79
|
+
};
|
|
80
|
+
user?: {
|
|
81
|
+
id: string;
|
|
82
|
+
email: string;
|
|
83
|
+
uuid: string | null;
|
|
84
|
+
} | undefined;
|
|
85
|
+
} & jose.JWTPayload;
|
|
34
86
|
|
|
35
|
-
export { getValidator, isAuthenticationError };
|
|
87
|
+
export { getValidator, isAuthenticationError, safeParse, unsafeDecode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as jose from 'jose';
|
|
2
|
+
import { errors } from 'jose';
|
|
3
|
+
import * as zod from 'zod';
|
|
2
4
|
export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb5e.js';
|
|
3
|
-
import 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Get a validator function that can validate a data token.
|
|
@@ -30,6 +31,57 @@ declare function getValidator(jwksUrl: string, { algorithms }?: {
|
|
|
30
31
|
* @param err - The error to check.
|
|
31
32
|
* @returns True if the error is an authentication error, false otherwise.
|
|
32
33
|
*/
|
|
33
|
-
declare function isAuthenticationError(err: unknown): err is JOSEError;
|
|
34
|
+
declare function isAuthenticationError(err: unknown): err is errors.JOSEError;
|
|
35
|
+
/**
|
|
36
|
+
* **THIS DOES NOT VALIDATE THE TOKEN. DO NOT USE IN AUTHENTICATION-SENSITIVE CONTEXTS**
|
|
37
|
+
*
|
|
38
|
+
* Decodes a JWT and tries to parse its payload according to the data token schema.
|
|
39
|
+
*
|
|
40
|
+
* @param jwt JWT string to be parsed
|
|
41
|
+
* @returns Result of trying to porse the payload
|
|
42
|
+
*/
|
|
43
|
+
declare function safeParse(jwt: string): zod.SafeParseReturnType<{
|
|
44
|
+
requestId: string;
|
|
45
|
+
workspace: {
|
|
46
|
+
id: string;
|
|
47
|
+
title: string;
|
|
48
|
+
};
|
|
49
|
+
user?: {
|
|
50
|
+
id: string;
|
|
51
|
+
email: string;
|
|
52
|
+
uuid: string | null;
|
|
53
|
+
} | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
requestId: string;
|
|
56
|
+
workspace: {
|
|
57
|
+
id: string;
|
|
58
|
+
title: string;
|
|
59
|
+
};
|
|
60
|
+
user?: {
|
|
61
|
+
id: string;
|
|
62
|
+
email: string;
|
|
63
|
+
uuid: string | null;
|
|
64
|
+
} | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* **THIS DOES NOT VALIDATE THE TOKEN. DO NOT USE IN AUTHENTICATION-SENSITIVE CONTEXTS**
|
|
68
|
+
*
|
|
69
|
+
* Type-unsafe version of {@link safeParse}. Decodes a JWT and casts its type to {@link DataToken} but **does not perform any payload validation**.
|
|
70
|
+
*
|
|
71
|
+
* @param jwt JWT string to be decoded
|
|
72
|
+
* @returns The JWT payload typed as a DataToken
|
|
73
|
+
*/
|
|
74
|
+
declare function unsafeDecode(jwt: string): {
|
|
75
|
+
requestId: string;
|
|
76
|
+
workspace: {
|
|
77
|
+
id: string;
|
|
78
|
+
title: string;
|
|
79
|
+
};
|
|
80
|
+
user?: {
|
|
81
|
+
id: string;
|
|
82
|
+
email: string;
|
|
83
|
+
uuid: string | null;
|
|
84
|
+
} | undefined;
|
|
85
|
+
} & jose.JWTPayload;
|
|
34
86
|
|
|
35
|
-
export { getValidator, isAuthenticationError };
|
|
87
|
+
export { getValidator, isAuthenticationError, safeParse, unsafeDecode };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { createRemoteJWKSet, jwtVerify, errors } from 'jose';
|
|
2
|
-
import { JOSEError } from 'jose/dist/types/util/errors';
|
|
1
|
+
import { createRemoteJWKSet, jwtVerify, errors, decodeJwt } from 'jose';
|
|
3
2
|
import { z } from 'zod';
|
|
4
3
|
|
|
5
4
|
const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -71,7 +70,14 @@ function getValidator(jwksUrl, { algorithms } = { algorithms: ["RS256"] }) {
|
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
72
|
function isAuthenticationError(err) {
|
|
74
|
-
return err instanceof JOSEError;
|
|
73
|
+
return err instanceof errors.JOSEError;
|
|
74
|
+
}
|
|
75
|
+
function safeParse(jwt) {
|
|
76
|
+
const payload = decodeJwt(jwt);
|
|
77
|
+
return DataToken.safeParse(payload);
|
|
78
|
+
}
|
|
79
|
+
function unsafeDecode(jwt) {
|
|
80
|
+
return decodeJwt(jwt);
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
export { DataToken, getValidator, isAuthenticationError };
|
|
83
|
+
export { DataToken, getValidator, isAuthenticationError, safeParse, unsafeDecode };
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/data-token",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.19",
|
|
5
5
|
"description": "Internal library to verify and decode the API Gateway data token",
|
|
6
6
|
"author": "Roz <roz@meistrari.com>",
|
|
7
7
|
"license": "UNLICENSED",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "github:meistrari/data-token"
|
|
11
|
+
},
|
|
8
12
|
"exports": {
|
|
9
13
|
".": {
|
|
10
14
|
"types": "./dist/index.d.ts",
|