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

Add types #8

Merged
merged 2 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 52 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
declare module '@articulate/authentic' {
interface VerifyOpts {
algorithms?: string[]
audience?: string | RegExp | Array<string | RegExp>
clockTimestamp?: number
clockTolerance?: number
issuer?: string | string[]
ignoreExpiration?: boolean
ignoreNotBefore?: boolean
jwtid?: string
subject?: string
maxAge?: string
}

interface JWKSOpts {
cache?: boolean,
rateLimit?: boolean
}

interface AuthenticOpts {
issWhitelist: string[],
jwks?: JWKSOpts,
verify?: VerifyOpts
}

interface Validator {
(token: string): Promise<Authentic.JWT>
}

function Authentic(opts: AuthenticOpts): Validator

namespace Authentic {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason for the namespace here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to use a namespace so we're able to use a namespace import

import * as Authentic from "@articulate/authentic";

This allows users to still be able to do

import * as Authentic from "@articulate/authentic"
Authentic() // function
Authentic.JWT // interface
import authentic from "@articulate/authentic"
authentic() // function
import { JWT } from "@articulate/authentic"
JWT // interface

Copy link
Member Author

Choose a reason for hiding this comment

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

Without the namespace, you'll get an error in typscript: Cannot invoke an expression whose type lacks a call signature.

interface JWT {
// Standard JWT claims
aud: string,
cid?: number,
exp: number,
iat: number,
iss: string
jti?: number,
scp?: Array<String>
sub: string
uid?: number,
tylerodonnell marked this conversation as resolved.
Show resolved Hide resolved

// Custom JWT claims
aid?: string,
tylerodonnell marked this conversation as resolved.
Show resolved Hide resolved
staff?: boolean,
}
}

export = Authentic
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.0",
"description": "Proper validation of JWT's against JWK's",
"main": "index.js",
"types": "index.d.ts",
"repository": "git@github.com:articulate/authentic.git",
"author": "articulate",
"license": "MIT",
Expand Down