Skip to content

Commit cec3230

Browse files
authored
Merge pull request #80 from fnberta/fix-typings
Fix typescript typings
2 parents 27ca58f + 123f5fd commit cec3230

File tree

2 files changed

+79
-48
lines changed

2 files changed

+79
-48
lines changed

index.d.ts

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,97 @@
1-
declare module 'jwks-rsa' {
1+
import { SecretCallback, SecretCallbackLong } from 'express-jwt';
22

3-
import * as ExpressJwt from "express-jwt";
3+
declare function JwksRsa(options: JwksRsa.ClientOptions): JwksRsa.JwksClient;
44

5-
function JwksRsa(options: JwksRsa.Options): JwksRsa.JwksClient;
5+
declare namespace JwksRsa {
6+
class JwksClient {
7+
constructor(options: ClientOptions);
68

7-
namespace JwksRsa {
8-
class JwksClient {
9-
constructor(options: Options);
9+
getKeys(cb: (err: Error | null, keys: unknown) => void): void;
10+
getSigningKeys(cb: (err: Error | null, keys: SigningKey[]) => void): void;
11+
getSigningKey: (kid: string, cb: (err: Error | null, key: SigningKey) => void) => void;
12+
}
13+
14+
interface Headers {
15+
[key: string]: string;
16+
}
17+
18+
interface ClientOptions {
19+
jwksUri: string;
20+
rateLimit?: boolean;
21+
cache?: boolean;
22+
cacheMaxEntries?: number;
23+
cacheMaxAge?: number;
24+
jwksRequestsPerMinute?: number;
25+
strictSsl?: boolean;
26+
requestHeaders?: Headers;
27+
}
28+
29+
interface CertSigningKey {
30+
kid: string;
31+
nbf: string;
32+
publicKey: string;
33+
}
34+
35+
interface RsaSigningKey {
36+
kid: string;
37+
nbf: string;
38+
rsaPublicKey: string;
39+
}
40+
41+
type SigningKey = CertSigningKey | RsaSigningKey;
1042

11-
getKeys: (cb: (err: Error, keys: Jwk[]) => any) => any;
12-
getSigningKeys: (cb: (err: Error, keys: Jwk[]) => any) => any;
13-
getSigningKey: (kid: string, cb: (err: Error, key: Jwk) => any) => any;
14-
}
43+
function expressJwtSecret(options: ExpressJwtOptions): SecretCallbackLong;
1544

16-
interface Jwk {
17-
kid: string;
18-
nbf?: number;
19-
publicKey?: string;
20-
rsaPublicKey?: string;
21-
}
45+
function passportJwtSecret(options: ExpressJwtOptions): SecretCallback;
2246

23-
interface Headers {
24-
[key: string]: string;
25-
}
47+
interface ExpressJwtOptions extends ClientOptions {
48+
handleSigningKeyError?: (err: Error | null, cb: (err: Error | null) => void) => void;
49+
}
2650

27-
interface Options {
28-
jwksUri: string;
29-
rateLimit?: boolean;
30-
cache?: boolean;
31-
cacheMaxEntries?: number;
32-
cacheMaxAge?: number;
33-
jwksRequestsPerMinute?: number;
34-
strictSsl?: boolean;
35-
requestHeaders?: Headers;
36-
handleSigningKeyError?(err: Error, cb: (err: Error) => void): any;
37-
}
51+
function hapiJwt2Key(options: HapiJwtOptions): (decodedToken: DecodedToken, cb: HapiCallback) => void;
3852

39-
function expressJwtSecret(options: JwksRsa.Options): ExpressJwt.SecretCallback;
53+
interface HapiJwtOptions extends ClientOptions {
54+
handleSigningKeyError?: (err: Error | null, cb: HapiCallback) => void;
55+
}
4056

41-
function hapiJwt2Key(options: JwksRsa.Options): (name: string, scheme: string, options?: any) => void;
57+
type HapiCallback = (err: Error | null, publicKey: string, signingKey: SigningKey) => void;
4258

43-
function hapiJwt2KeyAsync(options: JwksRsa.Options): (name: string, scheme: string, options?: any) => void;
59+
interface DecodedToken {
60+
header: TokenHeader;
61+
}
62+
63+
interface TokenHeader {
64+
alg: string;
65+
kid: string;
66+
}
4467

45-
function koaJwtSecret(options: JwksRsa.Options): (name: string, scheme: string, options?: any) => void;
68+
function hapiJwt2KeyAsync(options: HapiJwtOptions): (decodedToken: DecodedToken) => Promise<{ key: string }>;
4669

47-
function passportJwtSecret(options: JwksRsa.Options): ExpressJwt.SecretCallback;
70+
function koaJwtSecret(options: KoaJwtOptions): (header: TokenHeader) => Promise<string>;
4871

49-
class ArgumentError extends Error {
50-
constructor(message: string);
51-
}
72+
interface KoaJwtOptions extends ClientOptions {
73+
handleSigningKeyError?(err: Error | null): Promise<void>;
74+
}
5275

53-
class JwksError extends Error {
54-
constructor(message: string);
55-
}
76+
class ArgumentError extends Error {
77+
name: 'ArgumentError';
78+
constructor(message: string);
79+
}
5680

57-
class JwksRateLimitError extends Error {
58-
constructor(message: string);
59-
}
81+
class JwksError extends Error {
82+
name: 'JwksError';
83+
constructor(message: string);
84+
}
6085

61-
class SigningKeyNotFoundError extends Error {
62-
constructor(message: string);
63-
}
86+
class JwksRateLimitError extends Error {
87+
name: 'JwksRateLimitError';
88+
constructor(message: string);
6489
}
6590

66-
export = JwksRsa;
91+
class SigningKeyNotFoundError extends Error {
92+
name: 'SigningKeyNotFoundError';
93+
constructor(message: string);
94+
}
6795
}
96+
97+
export = JwksRsa;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "lib/index.js",
66
"types": "index.d.ts",
77
"dependencies": {
8+
"@types/express-jwt": "0.0.41",
89
"debug": "^2.6.9",
910
"jsonwebtoken": "^8.5.1",
1011
"limiter": "^1.1.4",

0 commit comments

Comments
 (0)