@meistrari/data-token 1.0.3 → 1.1.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/dist/adapters/elysia.mjs +1 -0
- package/dist/adapters/hono.mjs +1 -0
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +8 -3
- package/package.json +2 -1
package/dist/adapters/elysia.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import Elysia from 'elysia';
|
|
|
2
2
|
import { getValidator } from '../index.mjs';
|
|
3
3
|
import 'node:buffer';
|
|
4
4
|
import 'jose';
|
|
5
|
+
import '@meistrari/logger';
|
|
5
6
|
import 'zod';
|
|
6
7
|
|
|
7
8
|
function createDataTokenPlugin(url, skipOnError = false, getToken = (c) => c.headers["x-data-token"] ?? "") {
|
package/dist/adapters/hono.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { createMiddleware } from 'hono/factory';
|
|
|
2
2
|
import { getValidator } from '../index.mjs';
|
|
3
3
|
import 'node:buffer';
|
|
4
4
|
import 'jose';
|
|
5
|
+
import '@meistrari/logger';
|
|
5
6
|
import 'zod';
|
|
6
7
|
|
|
7
8
|
function createDataTokenMiddleware(url, skipOnError = false, getToken = (c) => c.req.header("x-data-token") ?? "") {
|
package/dist/index.d.mts
CHANGED
|
@@ -13,10 +13,9 @@ export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb
|
|
|
13
13
|
* @param options.logger - The logger to use for logging errors.
|
|
14
14
|
* @returns A function that can validate a data token.
|
|
15
15
|
*/
|
|
16
|
-
declare function getValidator(jwksUrl: string, { algorithms, remoteJwksOptions,
|
|
16
|
+
declare function getValidator(jwksUrl: string, { algorithms, remoteJwksOptions, }?: {
|
|
17
17
|
algorithms?: string[] | undefined;
|
|
18
18
|
remoteJwksOptions?: RemoteJWKSetOptions | undefined;
|
|
19
|
-
logger?: any;
|
|
20
19
|
}): (token: string) => Promise<{
|
|
21
20
|
requestId: string;
|
|
22
21
|
workspace: {
|
package/dist/index.d.ts
CHANGED
|
@@ -13,10 +13,9 @@ export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb
|
|
|
13
13
|
* @param options.logger - The logger to use for logging errors.
|
|
14
14
|
* @returns A function that can validate a data token.
|
|
15
15
|
*/
|
|
16
|
-
declare function getValidator(jwksUrl: string, { algorithms, remoteJwksOptions,
|
|
16
|
+
declare function getValidator(jwksUrl: string, { algorithms, remoteJwksOptions, }?: {
|
|
17
17
|
algorithms?: string[] | undefined;
|
|
18
18
|
remoteJwksOptions?: RemoteJWKSetOptions | undefined;
|
|
19
|
-
logger?: any;
|
|
20
19
|
}): (token: string) => Promise<{
|
|
21
20
|
requestId: string;
|
|
22
21
|
workspace: {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { createRemoteJWKSet, jwtVerify, errors, decodeJwt } from 'jose';
|
|
3
|
+
import pino from '@meistrari/logger';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
6
|
+
const logger = pino({
|
|
7
|
+
base: {
|
|
8
|
+
module: "@meistrari/data-token"
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
5
12
|
const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
6
13
|
function calculateDelay(options, attempt) {
|
|
7
14
|
let delay = options.baseDelay * options.factor ** attempt;
|
|
@@ -59,8 +66,7 @@ const retry = createExponentialBackoff({
|
|
|
59
66
|
});
|
|
60
67
|
function getValidator(jwksUrl, {
|
|
61
68
|
algorithms = ["RS256"],
|
|
62
|
-
remoteJwksOptions = {}
|
|
63
|
-
logger = console
|
|
69
|
+
remoteJwksOptions = {}
|
|
64
70
|
} = {}) {
|
|
65
71
|
let JWKS;
|
|
66
72
|
return async (token) => {
|
|
@@ -88,7 +94,6 @@ function getValidator(jwksUrl, {
|
|
|
88
94
|
const jwksResponse = await fetch(jwksUrl);
|
|
89
95
|
const jwksText = await jwksResponse.json();
|
|
90
96
|
logger.error({
|
|
91
|
-
level: "error",
|
|
92
97
|
error,
|
|
93
98
|
jwksUrl,
|
|
94
99
|
algorithms,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/data-token",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"prepack": "bun run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@meistrari/logger": "2.0.1",
|
|
44
45
|
"cockatiel": "^3.2.1",
|
|
45
46
|
"jose": "^5.8.0",
|
|
46
47
|
"zod": "^3.23.8"
|