@meistrari/data-token 1.0.1 → 1.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.
@@ -2,7 +2,6 @@ import Elysia from 'elysia';
2
2
  import { getValidator } from '../index.mjs';
3
3
  import 'node:buffer';
4
4
  import 'jose';
5
- import 'jose/dist/types/util/errors';
6
5
  import 'zod';
7
6
 
8
7
  function createDataTokenPlugin(url, skipOnError = false, getToken = (c) => c.headers["x-data-token"] ?? "") {
@@ -2,7 +2,6 @@ import { createMiddleware } from 'hono/factory';
2
2
  import { getValidator } from '../index.mjs';
3
3
  import 'node:buffer';
4
4
  import 'jose';
5
- import 'jose/dist/types/util/errors';
6
5
  import 'zod';
7
6
 
8
7
  function createDataTokenMiddleware(url, skipOnError = false, getToken = (c) => c.req.header("x-data-token") ?? "") {
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { createRemoteJWKSet, jwtVerify, errors, decodeJwt } from 'jose';
3
- import { JWKSNoMatchingKey } from 'jose/dist/types/util/errors';
4
3
  import { z } from 'zod';
5
4
 
6
5
  const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -81,20 +80,21 @@ function getValidator(jwksUrl, {
81
80
  );
82
81
  return DataToken.parse(payload);
83
82
  } catch (error) {
84
- if (error instanceof JWKSNoMatchingKey) {
85
- const [header] = token.split(".");
86
- const tokenHeader = JSON.parse(Buffer.from(header, "base64").toString("utf-8"));
87
- const jwksResponse = await fetch(jwksUrl);
88
- const jwksText = await jwksResponse.json();
89
- logger.error({
90
- level: "error",
91
- message: "No matching key found in JWKS for token",
92
- jwksUrl,
93
- algorithms,
94
- jwks: jwksText,
95
- tokenHeader
96
- });
83
+ if (error instanceof errors.JWTExpired) {
84
+ throw error;
97
85
  }
86
+ const [header] = token.split(".");
87
+ const tokenHeader = JSON.parse(Buffer.from(header, "base64").toString("utf-8"));
88
+ const jwksResponse = await fetch(jwksUrl);
89
+ const jwksText = await jwksResponse.json();
90
+ logger.error({
91
+ level: "error",
92
+ error,
93
+ jwksUrl,
94
+ algorithms,
95
+ jwks: jwksText,
96
+ tokenHeader
97
+ }, "Failed to validate data token");
98
98
  throw error;
99
99
  }
100
100
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/data-token",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
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",