@meistrari/data-token 0.0.15 → 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,20 +19,32 @@ 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: {
25
- readonly authData?: any;
26
+ readonly authData: {
27
+ requestId: string;
28
+ workspace: {
29
+ id: string;
30
+ title: string;
31
+ };
32
+ user?: {
33
+ id: string;
34
+ email: string;
35
+ uuid: string | null;
36
+ } | undefined;
37
+ } | null;
26
38
  };
27
39
  resolve: {};
28
40
  }, {
29
- type: {};
41
+ typebox: _sinclair_typebox.TModule<{}>;
30
42
  error: {};
31
43
  }, {
32
44
  schema: {};
33
45
  macro: {};
34
46
  macroFn: {};
47
+ parser: {};
35
48
  }, {}, {
36
49
  derive: {};
37
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,20 +19,32 @@ 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: {
25
- readonly authData?: any;
26
+ readonly authData: {
27
+ requestId: string;
28
+ workspace: {
29
+ id: string;
30
+ title: string;
31
+ };
32
+ user?: {
33
+ id: string;
34
+ email: string;
35
+ uuid: string | null;
36
+ } | undefined;
37
+ } | null;
26
38
  };
27
39
  resolve: {};
28
40
  }, {
29
- type: {};
41
+ typebox: _sinclair_typebox.TModule<{}>;
30
42
  error: {};
31
43
  }, {
32
44
  schema: {};
33
45
  macro: {};
34
46
  macroFn: {};
47
+ parser: {};
35
48
  }, {}, {
36
49
  derive: {};
37
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.81835829.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.81835829.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.81835829.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
  /**
@@ -12,16 +13,23 @@ import 'zod';
12
13
  declare function getValidator(jwksUrl: string, { algorithms }?: {
13
14
  algorithms: string[];
14
15
  }): (token: string) => Promise<{
15
- requestId?: string;
16
- workspace?: {
17
- id?: string;
18
- title?: string;
16
+ requestId: string;
17
+ workspace: {
18
+ id: string;
19
+ title: string;
19
20
  };
20
21
  user?: {
21
- id?: string;
22
- email?: string;
23
- uuid?: string;
24
- };
22
+ id: string;
23
+ email: string;
24
+ uuid: string | null;
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.81835829.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
  /**
@@ -12,16 +13,23 @@ import 'zod';
12
13
  declare function getValidator(jwksUrl: string, { algorithms }?: {
13
14
  algorithms: string[];
14
15
  }): (token: string) => Promise<{
15
- requestId?: string;
16
- workspace?: {
17
- id?: string;
18
- title?: string;
16
+ requestId: string;
17
+ workspace: {
18
+ id: string;
19
+ title: string;
19
20
  };
20
21
  user?: {
21
- id?: string;
22
- email?: string;
23
- uuid?: string;
24
- };
22
+ id: string;
23
+ email: string;
24
+ uuid: string | null;
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 };
@@ -0,0 +1,58 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const DataToken: z.ZodObject<{
4
+ requestId: z.ZodString;
5
+ workspace: z.ZodObject<{
6
+ id: z.ZodString;
7
+ title: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ id: string;
10
+ title: string;
11
+ }, {
12
+ id: string;
13
+ title: string;
14
+ }>;
15
+ user: z.ZodOptional<z.ZodObject<{
16
+ id: z.ZodString;
17
+ email: z.ZodString;
18
+ uuid: z.ZodNullable<z.ZodString>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ id: string;
21
+ email: string;
22
+ uuid: string | null;
23
+ }, {
24
+ id: string;
25
+ email: string;
26
+ uuid: string | null;
27
+ }>>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ requestId: string;
30
+ workspace: {
31
+ id: string;
32
+ title: string;
33
+ };
34
+ user?: {
35
+ id: string;
36
+ email: string;
37
+ uuid: string | null;
38
+ } | undefined;
39
+ }, {
40
+ requestId: string;
41
+ workspace: {
42
+ id: string;
43
+ title: string;
44
+ };
45
+ user?: {
46
+ id: string;
47
+ email: string;
48
+ uuid: string | null;
49
+ } | undefined;
50
+ }>;
51
+ type DataToken = z.infer<typeof DataToken>;
52
+ type ValidatorConfig = {
53
+ jwksUrl: string;
54
+ algorithms?: string[];
55
+ };
56
+
57
+ export { DataToken as D };
58
+ export type { ValidatorConfig as V };
@@ -0,0 +1,58 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const DataToken: z.ZodObject<{
4
+ requestId: z.ZodString;
5
+ workspace: z.ZodObject<{
6
+ id: z.ZodString;
7
+ title: z.ZodString;
8
+ }, "strip", z.ZodTypeAny, {
9
+ id: string;
10
+ title: string;
11
+ }, {
12
+ id: string;
13
+ title: string;
14
+ }>;
15
+ user: z.ZodOptional<z.ZodObject<{
16
+ id: z.ZodString;
17
+ email: z.ZodString;
18
+ uuid: z.ZodNullable<z.ZodString>;
19
+ }, "strip", z.ZodTypeAny, {
20
+ id: string;
21
+ email: string;
22
+ uuid: string | null;
23
+ }, {
24
+ id: string;
25
+ email: string;
26
+ uuid: string | null;
27
+ }>>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ requestId: string;
30
+ workspace: {
31
+ id: string;
32
+ title: string;
33
+ };
34
+ user?: {
35
+ id: string;
36
+ email: string;
37
+ uuid: string | null;
38
+ } | undefined;
39
+ }, {
40
+ requestId: string;
41
+ workspace: {
42
+ id: string;
43
+ title: string;
44
+ };
45
+ user?: {
46
+ id: string;
47
+ email: string;
48
+ uuid: string | null;
49
+ } | undefined;
50
+ }>;
51
+ type DataToken = z.infer<typeof DataToken>;
52
+ type ValidatorConfig = {
53
+ jwksUrl: string;
54
+ algorithms?: string[];
55
+ };
56
+
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.15",
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",
@@ -1,57 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- declare const DataToken: z.ZodObject<{
4
- requestId: z.ZodString;
5
- workspace: z.ZodObject<{
6
- id: z.ZodString;
7
- title: z.ZodString;
8
- }, "strip", z.ZodTypeAny, {
9
- id?: string;
10
- title?: string;
11
- }, {
12
- id?: string;
13
- title?: string;
14
- }>;
15
- user: z.ZodOptional<z.ZodObject<{
16
- id: z.ZodString;
17
- email: z.ZodString;
18
- uuid: z.ZodNullable<z.ZodString>;
19
- }, "strip", z.ZodTypeAny, {
20
- id?: string;
21
- email?: string;
22
- uuid?: string;
23
- }, {
24
- id?: string;
25
- email?: string;
26
- uuid?: string;
27
- }>>;
28
- }, "strip", z.ZodTypeAny, {
29
- requestId?: string;
30
- workspace?: {
31
- id?: string;
32
- title?: string;
33
- };
34
- user?: {
35
- id?: string;
36
- email?: string;
37
- uuid?: string;
38
- };
39
- }, {
40
- requestId?: string;
41
- workspace?: {
42
- id?: string;
43
- title?: string;
44
- };
45
- user?: {
46
- id?: string;
47
- email?: string;
48
- uuid?: string;
49
- };
50
- }>;
51
- type DataToken = z.infer<typeof DataToken>;
52
- type ValidatorConfig = {
53
- jwksUrl: string;
54
- algorithms?: string[];
55
- };
56
-
57
- export { DataToken as D, type ValidatorConfig as V };
@@ -1,57 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- declare const DataToken: z.ZodObject<{
4
- requestId: z.ZodString;
5
- workspace: z.ZodObject<{
6
- id: z.ZodString;
7
- title: z.ZodString;
8
- }, "strip", z.ZodTypeAny, {
9
- id?: string;
10
- title?: string;
11
- }, {
12
- id?: string;
13
- title?: string;
14
- }>;
15
- user: z.ZodOptional<z.ZodObject<{
16
- id: z.ZodString;
17
- email: z.ZodString;
18
- uuid: z.ZodNullable<z.ZodString>;
19
- }, "strip", z.ZodTypeAny, {
20
- id?: string;
21
- email?: string;
22
- uuid?: string;
23
- }, {
24
- id?: string;
25
- email?: string;
26
- uuid?: string;
27
- }>>;
28
- }, "strip", z.ZodTypeAny, {
29
- requestId?: string;
30
- workspace?: {
31
- id?: string;
32
- title?: string;
33
- };
34
- user?: {
35
- id?: string;
36
- email?: string;
37
- uuid?: string;
38
- };
39
- }, {
40
- requestId?: string;
41
- workspace?: {
42
- id?: string;
43
- title?: string;
44
- };
45
- user?: {
46
- id?: string;
47
- email?: string;
48
- uuid?: string;
49
- };
50
- }>;
51
- type DataToken = z.infer<typeof DataToken>;
52
- type ValidatorConfig = {
53
- jwksUrl: string;
54
- algorithms?: string[];
55
- };
56
-
57
- export { DataToken as D, type ValidatorConfig as V };