Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type definition #9

Merged
merged 4 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,ts}]
charset = utf-8
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ node_modules
# Build output
lib
!src/lib

# IDE files
.idea/
*.iml
56 changes: 56 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
declare module 'jwks-rsa' {

import * as ExpressJwt from "express-jwt";

function JwksRsa(options: JwksRsa.Options): JwksRsa.JwksClient;

namespace JwksRsa {
class JwksClient {
constructor(options: Options);

getKeys: (cb: (err: Error, keys: Jwk[]) => any) => any;
getSigningKeys: (cb: (err: Error, keys: Jwk[]) => any) => any;
getSigningKey: (kid: string, cb: (err: Error, key: Jwk) => any) => any;
}

interface Jwk {
kid: string;
nbf?: number;
publicKey?: string;
rsaPublicKey?: string;
}

interface Options {
jwksUri: string;
rateLimit?: boolean;
cache?: boolean;
cacheMaxEntries?: number;
cacheMaxAge?: number;
jwksRequestsPerMinute?: number;
strictSsl?: boolean;
handleSigningKeyError?(err: Error, cb: (err: Error) => void): any;
}

function ExpressJwtSecret(options: JwksRsa.Options): ExpressJwt.SecretCallback;

function HapiJwt2Key(options: JwksRsa.Options): (name: string, scheme: string, options?: any) => void;

class ArgumentError extends Error {
constructor(message: string);
}

class JwksError extends Error {
constructor(message: string);
}

class JwksRateLimitError extends Error {
constructor(message: string);
}

class SigningKeyNotFoundError extends Error {
constructor(message: string);
}
}

export = JwksRsa;
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.1.1",
"description": "Library to retrieve RSA public keys from a JWKS endpoint",
"main": "lib/index.js",
"types": "index.d.ts",
"dependencies": {
"@types/express-jwt": "0.0.34",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in devDependencies?

Copy link
Contributor Author

@brunokrebs brunokrebs Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DevDependencies of dependencies are not installed along. That is, if I have a TypeScript project that has jwks-rsa as a dependency, @types/express-jwt will not get installed if it is defined as a devDependency instead of as a denpendency. Then the project won't compile and the developer will have to manually install @types/express-jwt.

My first attempt was to configure it as a devDependency, but it didn't work. Also, the publishing page on the TypeScript documentation states that the developer has to:

Make sure all the declaration packages you depend on are marked appropriately in the "dependencies" section in your package.json.

"debug": "^2.2.0",
"limiter": "^1.1.0",
"lru-memoizer": "^1.6.0",
Expand Down