@elysiajs/jwt 1.4.0 → 1.4.2

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/index.d.ts CHANGED
@@ -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,11 +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]: T[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
+ }; };
152
156
  store: {};
153
157
  derive: {};
154
158
  resolve: {};