@elysiajs/jwt 1.3.3 → 1.4.1

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,11 +1,15 @@
1
- import { Elysia, type TSchema, type UnwrapSchema as Static } from 'elysia';
1
+ import { Elysia } from 'elysia';
2
+ import type { AnySchema, UnwrapSchema } from 'elysia/types';
2
3
  import { type CryptoKey, type JWK, type KeyObject, type JoseHeaderParameters, type JWTVerifyOptions } from 'jose';
3
- type UnwrapSchema<Schema extends TSchema | undefined, Fallback = unknown> = Schema extends TSchema ? Static<NonNullable<Schema>> : Fallback;
4
+ type Prettify<T> = {
5
+ [K in keyof T]: T[K];
6
+ } & {};
4
7
  type NormalizedClaim = 'nbf' | 'exp' | 'iat';
5
8
  type AllowClaimValue = string | number | boolean | null | undefined | AllowClaimValue[] | {
6
9
  [key: string]: AllowClaimValue;
7
10
  };
8
11
  type ClaimType = Record<string, AllowClaimValue>;
12
+ type UnwrapSchemaWithFallback<Schema extends AnySchema | undefined, Fallback = unknown> = Schema extends AnySchema ? UnwrapSchema<NonNullable<Schema>> : Fallback;
9
13
  /**
10
14
  * This interface is a specific, strongly-typed representation of the
11
15
  * standard claims found in a JWT payload.
@@ -115,7 +119,7 @@ export interface JWTHeaderParameters extends JoseHeaderParameters {
115
119
  /** JWS "crit" (Critical) Header Parameter */
116
120
  crit?: string[];
117
121
  }
118
- export interface JWTOption<Name extends string | undefined = 'jwt', Schema extends TSchema | undefined = undefined> extends JWTHeaderParameters, JWTPayloadInput {
122
+ export interface JWTOption<Name extends string | undefined = 'jwt', Schema extends AnySchema | undefined = undefined> extends JWTHeaderParameters, JWTPayloadInput {
119
123
  /**
120
124
  * Name to decorate method as
121
125
  *
@@ -144,14 +148,11 @@ export interface JWTOption<Name extends string | undefined = 'jwt', Schema exten
144
148
  */
145
149
  schema?: Schema;
146
150
  }
147
- export declare const jwt: <const Name extends string = "jwt", const Schema extends TSchema | undefined = undefined>({ name, secret, schema, ...defaultValues }: JWTOption<Name, Schema>) => Elysia<"", {
151
+ export declare const jwt: <const Name extends string = "jwt", const Schema extends AnySchema | undefined = undefined>({ name, secret, schema, ...defaultValues }: JWTOption<Name, Schema>) => Elysia<"", {
148
152
  decorator: { [name in Name extends string ? Name : "jwt"]: {
149
- sign(signValue: Omit<UnwrapSchema<Schema, ClaimType>, NormalizedClaim> & JWTPayloadInput): Promise<string>;
150
- verify(jwt?: string, options?: JWTVerifyOptions): Promise<(UnwrapSchema<Schema, ClaimType> & Omit<JWTPayloadSpec, keyof UnwrapSchema<Schema, {}>>) | false>;
151
- }; } extends infer T ? { [K in keyof T]: { [name in Name extends string ? Name : "jwt"]: {
152
- sign(signValue: Omit<UnwrapSchema<Schema, ClaimType>, NormalizedClaim> & JWTPayloadInput): Promise<string>;
153
- verify(jwt?: string, options?: JWTVerifyOptions): Promise<(UnwrapSchema<Schema, ClaimType> & Omit<JWTPayloadSpec, keyof UnwrapSchema<Schema, {}>>) | false>;
154
- }; }[K]; } : never;
153
+ sign(signValue: Prettify<Omit<UnwrapSchemaWithFallback<Schema, ClaimType>, NormalizedClaim> & JWTPayloadInput>): Promise<string>;
154
+ verify(jwt?: string, options?: JWTVerifyOptions): Promise<(UnwrapSchemaWithFallback<Schema, ClaimType> & Omit<JWTPayloadSpec, keyof UnwrapSchema<Schema, {}>>) | false>;
155
+ }; };
155
156
  store: {};
156
157
  derive: {};
157
158
  resolve: {};
@@ -164,15 +165,18 @@ export declare const jwt: <const Name extends string = "jwt", const Schema exten
164
165
  macro: {};
165
166
  macroFn: {};
166
167
  parser: {};
168
+ response: {};
167
169
  }, {}, {
168
170
  derive: {};
169
171
  resolve: {};
170
172
  schema: {};
171
173
  standaloneSchema: {};
174
+ response: {};
172
175
  }, {
173
176
  derive: {};
174
177
  resolve: {};
175
178
  schema: {};
176
179
  standaloneSchema: {};
180
+ response: {};
177
181
  }>;
178
182
  export default jwt;