@meistrari/data-token 0.0.16 → 0.0.17

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.
@@ -1,3 +1,4 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
1
2
  import Elysia, { Context } from 'elysia';
2
3
 
3
4
  /**
@@ -18,7 +19,7 @@ import Elysia, { Context } from 'elysia';
18
19
  * .get('/', ({ authData }) => ({ authData }))
19
20
  * ```
20
21
  */
21
- declare function createDataTokenPlugin(url: string, skipOnError?: boolean, getToken?: (c: Context) => string): Elysia<"", false, {
22
+ declare function createDataTokenPlugin(url: string, skipOnError?: boolean, getToken?: (c: Context) => string): Elysia<"", {
22
23
  decorator: {};
23
24
  store: {};
24
25
  derive: {
@@ -37,12 +38,13 @@ declare function createDataTokenPlugin(url: string, skipOnError?: boolean, getTo
37
38
  };
38
39
  resolve: {};
39
40
  }, {
40
- type: {};
41
+ typebox: _sinclair_typebox.TModule<{}>;
41
42
  error: {};
42
43
  }, {
43
44
  schema: {};
44
45
  macro: {};
45
46
  macroFn: {};
47
+ parser: {};
46
48
  }, {}, {
47
49
  derive: {};
48
50
  resolve: {};
@@ -1,3 +1,4 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
1
2
  import Elysia, { Context } from 'elysia';
2
3
 
3
4
  /**
@@ -18,7 +19,7 @@ import Elysia, { Context } from 'elysia';
18
19
  * .get('/', ({ authData }) => ({ authData }))
19
20
  * ```
20
21
  */
21
- declare function createDataTokenPlugin(url: string, skipOnError?: boolean, getToken?: (c: Context) => string): Elysia<"", false, {
22
+ declare function createDataTokenPlugin(url: string, skipOnError?: boolean, getToken?: (c: Context) => string): Elysia<"", {
22
23
  decorator: {};
23
24
  store: {};
24
25
  derive: {
@@ -37,12 +38,13 @@ declare function createDataTokenPlugin(url: string, skipOnError?: boolean, getTo
37
38
  };
38
39
  resolve: {};
39
40
  }, {
40
- type: {};
41
+ typebox: _sinclair_typebox.TModule<{}>;
41
42
  error: {};
42
43
  }, {
43
44
  schema: {};
44
45
  macro: {};
45
46
  macroFn: {};
47
+ parser: {};
46
48
  }, {}, {
47
49
  derive: {};
48
50
  resolve: {};
@@ -1,6 +1,7 @@
1
1
  import Elysia from 'elysia';
2
2
  import { getValidator } from '../index.mjs';
3
3
  import 'jose';
4
+ import 'jose/dist/types/util/errors';
4
5
  import 'zod';
5
6
 
6
7
  function createDataTokenPlugin(url, skipOnError = false, getToken = (c) => c.headers["x-data-token"] ?? "") {
@@ -1,6 +1,6 @@
1
1
  import * as hono from 'hono';
2
2
  import { Context } from 'hono';
3
- import { D as DataToken } from '../shared/data-token.815fae84.mjs';
3
+ import { D as DataToken } from '../shared/data-token.1d70cb5e.mjs';
4
4
  import 'zod';
5
5
 
6
6
  type DataTokenContext = {
@@ -28,4 +28,5 @@ type DataTokenContext = {
28
28
  */
29
29
  declare function createDataTokenMiddleware<Env extends DataTokenContext>(url: string | ((c: Context<Env>) => string), skipOnError?: boolean, getToken?: (c: Context<Env>) => string): hono.MiddlewareHandler<Env, string, {}>;
30
30
 
31
- export { type DataTokenContext, createDataTokenMiddleware };
31
+ export { createDataTokenMiddleware };
32
+ export type { DataTokenContext };
@@ -1,6 +1,6 @@
1
1
  import * as hono from 'hono';
2
2
  import { Context } from 'hono';
3
- import { D as DataToken } from '../shared/data-token.815fae84.js';
3
+ import { D as DataToken } from '../shared/data-token.1d70cb5e.js';
4
4
  import 'zod';
5
5
 
6
6
  type DataTokenContext = {
@@ -28,4 +28,5 @@ type DataTokenContext = {
28
28
  */
29
29
  declare function createDataTokenMiddleware<Env extends DataTokenContext>(url: string | ((c: Context<Env>) => string), skipOnError?: boolean, getToken?: (c: Context<Env>) => string): hono.MiddlewareHandler<Env, string, {}>;
30
30
 
31
- export { type DataTokenContext, createDataTokenMiddleware };
31
+ export { createDataTokenMiddleware };
32
+ export type { DataTokenContext };
@@ -1,6 +1,7 @@
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';
4
5
  import 'zod';
5
6
 
6
7
  function createDataTokenMiddleware(url, skipOnError = false, getToken = (c) => c.req.header("x-data-token") ?? "") {
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- export { D as DataToken, V as ValidatorConfig } from './shared/data-token.815fae84.mjs';
1
+ import { JOSEError } from 'jose/dist/types/util/errors';
2
+ export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb5e.mjs';
2
3
  import 'zod';
3
4
 
4
5
  /**
@@ -23,5 +24,12 @@ declare function getValidator(jwksUrl: string, { algorithms }?: {
23
24
  uuid: string | null;
24
25
  } | undefined;
25
26
  }>;
27
+ /**
28
+ * Check if an error is an authentication error.
29
+ *
30
+ * @param err - The error to check.
31
+ * @returns True if the error is an authentication error, false otherwise.
32
+ */
33
+ declare function isAuthenticationError(err: unknown): err is JOSEError;
26
34
 
27
- export { getValidator };
35
+ export { getValidator, isAuthenticationError };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { D as DataToken, V as ValidatorConfig } from './shared/data-token.815fae84.js';
1
+ import { JOSEError } from 'jose/dist/types/util/errors';
2
+ export { D as DataToken, V as ValidatorConfig } from './shared/data-token.1d70cb5e.js';
2
3
  import 'zod';
3
4
 
4
5
  /**
@@ -23,5 +24,12 @@ declare function getValidator(jwksUrl: string, { algorithms }?: {
23
24
  uuid: string | null;
24
25
  } | undefined;
25
26
  }>;
27
+ /**
28
+ * Check if an error is an authentication error.
29
+ *
30
+ * @param err - The error to check.
31
+ * @returns True if the error is an authentication error, false otherwise.
32
+ */
33
+ declare function isAuthenticationError(err: unknown): err is JOSEError;
26
34
 
27
- export { getValidator };
35
+ export { getValidator, isAuthenticationError };
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createRemoteJWKSet, jwtVerify, errors } from 'jose';
2
+ import { JOSEError } from 'jose/dist/types/util/errors';
2
3
  import { z } from 'zod';
3
4
 
4
5
  const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -69,5 +70,8 @@ function getValidator(jwksUrl, { algorithms } = { algorithms: ["RS256"] }) {
69
70
  return DataToken.parse(payload);
70
71
  };
71
72
  }
73
+ function isAuthenticationError(err) {
74
+ return err instanceof JOSEError;
75
+ }
72
76
 
73
- export { DataToken, getValidator };
77
+ export { DataToken, getValidator, isAuthenticationError };
@@ -54,4 +54,5 @@ type ValidatorConfig = {
54
54
  algorithms?: string[];
55
55
  };
56
56
 
57
- export { DataToken as D, type ValidatorConfig as V };
57
+ export { DataToken as D };
58
+ export type { ValidatorConfig as V };
@@ -54,4 +54,5 @@ type ValidatorConfig = {
54
54
  algorithms?: string[];
55
55
  };
56
56
 
57
- export { DataToken as D, type ValidatorConfig as V };
57
+ export { DataToken as D };
58
+ export type { ValidatorConfig as V };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/data-token",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.17",
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",