Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Improve Flow type coverage (#100)
Browse files Browse the repository at this point in the history
* Add Flow type definitions for jsonwebtoken

* Improve Flow coverage for src files

* Added type definitions for Tape Cup

* Added @flow to test files

* Added .eslintignore to ignore lint checking /flow-typed/ folder

* Added additional type definitions, including for node-fetch and just

* Update Flow and fix related errors

* Ignore eslint complaints on a per-file basis
  • Loading branch information
AlexMSmithCA committed Mar 29, 2018
1 parent 2a60998 commit 66efd23
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 72 deletions.
8 changes: 7 additions & 1 deletion flow-typed/globals.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// @flow
/** Copyright (c) 2018 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

declare var __NODE__: boolean;
declare var __BROWSER__: boolean;
8 changes: 8 additions & 0 deletions flow-typed/just-safe-get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @flow

declare module 'just-safe-get' {
declare export default function get(
obj: mixed,
key: string | Array<string>
): mixed;
}
9 changes: 9 additions & 0 deletions flow-typed/just-safe-set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @flow

declare module 'just-safe-set' {
declare export default function set(
obj: mixed,
key: string | Array<string>,
value: mixed
): boolean;
}
114 changes: 114 additions & 0 deletions flow-typed/npm/jsonwebtoken_v8.1.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// flow-typed signature: a2d5ea66c7bcab10e48b4d9cf6fcbcb0
// flow-typed version: 40e00ed01a/jsonwebtoken_v8.1.x/flow_>=v0.56.x

/* eslint-disable */

declare module "jsonwebtoken" {
declare module.exports: {
sign: jwt$Sign,
decode: jwt$Decode,
verify: jwt$Verify,
JsonWebTokenError: Class<jwt$WebTokenError>,
NotBeforeError: Class<jwt$NotBeforeError>,
TokenExpiredError: Class<jwt$TokenExpiredError>
}
}

declare type jwt$Encodable = String | Buffer | Object;
declare type jwt$Key = { key: string | Buffer, passphrase: string | Buffer };
declare type jwt$Algorithm =
'RS256'
| 'RS384'
| 'RS512'
| 'ES256'
| 'ES384'
| 'ES512'
| 'HS256'
| 'HS384'
| 'HS512'
| 'none';

declare type jwt$Callback = (tokenOrError: Error | string) => void;
declare type jwt$SigningOptions<Headers> = $Shape<{
algorithm: jwt$Algorithm,
expiresIn: number | string,
notBefore: number | string,
audience: string | string[],
issuer: string,
jwtid: string,
subject: string,
noTimestamp: boolean,
header: Headers,
keyid: string
}>;

declare type jwt$SigningOptionsWithAlgorithm<H> = jwt$SigningOptions<H> & { algorithm: jwt$Algorithm };
declare type jwt$VerifyOptionsWithAlgorithm = jwt$VerifyOptions & { algorithms: Array<jwt$Algorithm> };

declare type jwt$VerifyOptions = $Shape<{
algorithms: Array<jwt$Algorithm>,
audience: string,
issuer: string | string[],
ignoreExpiration: boolean,
ignoreNotBefore: boolean,
subject: string | string[],
clockTolerance: number,
maxAge: string | number,
clockTimestamp: number
}>;

declare type jwt$DecodingOptions = $Shape<{
complete: boolean,
json: boolean,
encoding: string,
}>;

declare interface jwt$Sign {
<P: jwt$Encodable>
(payload: P, secretOrPrivateKey: string | Buffer): string;

<P: jwt$Encodable>
(payload: P, secretOrPrivateKey: string | Buffer, callback: jwt$Callback): string;

<P: jwt$Encodable, H>
(payload: P, secretOrPrivateKey: jwt$Key, options: jwt$SigningOptionsWithAlgorithm<H>): string;

<P: jwt$Encodable, H>
(payload: P, secretOrPrivateKey: string | Buffer, options: $Shape<jwt$SigningOptions<H>>): string;

<P: jwt$Encodable, H>
(payload: P, secretOrPrivateKey: string | Buffer, options: $Shape<jwt$SigningOptions<H>>, callback: jwt$Callback): string;

<P: jwt$Encodable, H>
(payload: P, secretOrPrivateKey: jwt$Key, options: jwt$SigningOptionsWithAlgorithm<H>, callback: jwt$Callback): string;
}

declare interface jwt$Decode {
(jwt: string): mixed;

(jwt: string, options: jwt$DecodingOptions): mixed;

(jwt: string, options: jwt$DecodingOptions & { complete: true }): { header: Object, payload: mixed, signature: string };
}

declare interface jwt$Verify {
(jwt: string, secretOrPrivateKey: string | Buffer): mixed;

(jwt: string, secretOrPrivateKey: string | Buffer, options: jwt$VerifyOptions | jwt$Callback): mixed;

(jwt: string, secretOrPrivateKey: string | Buffer, options: jwt$VerifyOptions, callback: jwt$Callback): mixed;

(jwt: string, secretOrPrivateKey: jwt$Key, options: jwt$VerifyOptionsWithAlgorithm): mixed;

(jwt: string, secretOrPrivateKey: jwt$Key, options: jwt$VerifyOptionsWithAlgorithm, callback: jwt$Callback): mixed;
}

declare class jwt$TokenExpiredError extends Error {
}

declare class jwt$WebTokenError extends Error {
}

declare class jwt$NotBeforeError extends Error {
}

108 changes: 108 additions & 0 deletions flow-typed/npm/node-fetch_v1.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// flow-typed signature: 284e255a331cbe00e3ddf88897c9452d
// flow-typed version: 7e7beb7540/node-fetch_v1.x.x/flow_>=v0.44.x

/* eslint-disable */

declare module 'node-fetch' {
declare export class Request mixins Body {
constructor(input: string | Request, init?: RequestInit): this;
method: string;
url: string;
headers: Headers;
context: RequestContext;
referrer: string;
redirect: RequestRedirect;

// node-fetch extensions
compress: boolean;
agent: http$Agent;
counter: number;
follow: number;
hostname: string;
protocol: string;
port: number;
timeout: number;
size: number
}

declare type HeaderObject = {
[index: string]: string
}

declare interface RequestInit {
method?: string,
headers?: HeaderObject,
body?: BodyInit,
redirect?: RequestRedirect,

// node-fetch extensions
timeout?: number,
compress?: boolean,
size?: number,
agent?: http$Agent,
follow?: number
}

declare type RequestContext =
'audio' | 'beacon' | 'cspreport' | 'download' | 'embed' |
'eventsource' | 'favicon' | 'fetch' | 'font' | 'form' | 'frame' |
'hyperlink' | 'iframe' | 'image' | 'imageset' | 'import' |
'internal' | 'location' | 'manifest' | 'object' | 'ping' | 'plugin' |
'prefetch' | 'script' | 'serviceworker' | 'sharedworker' |
'subresource' | 'style' | 'track' | 'video' | 'worker' |
'xmlhttprequest' | 'xslt';
declare type RequestRedirect = 'follow' | 'error' | 'manual';

declare export class Headers {
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string;
getAll(name: string): Array<string>;
has(name: string): boolean;
set(name: string, value: string): void;
forEach(callback: (value: string, name: string) => void): void
}

declare export class Body {
bodyUsed: boolean;
body: stream$Readable;
json(): Promise<any>;
json<T>(): Promise<T>;
text(): Promise<string>;
buffer(): Promise<Buffer >
}

declare export class Response mixins Body {
constructor(body?: BodyInit, init?: ResponseInit): this;
error(): Response;
redirect(url: string, status: number): Response;
type: ResponseType;
url: string;
status: number;
ok: boolean;
size: number;
statusText: string;
timeout: number;
headers: Headers;
clone(): Response
}

declare type ResponseType =
| 'basic'
| 'cors'
| 'default'
| 'error'
| 'opaque'
| 'opaqueredirect';

declare interface ResponseInit {
status: number,
statusText?: string,
headers?: HeaderInit
}

declare type HeaderInit = Headers | Array<string>;
declare type BodyInit = string;

declare export default function fetch(url: string | Request, init?: RequestInit): Promise<Response>
}
105 changes: 105 additions & 0 deletions flow-typed/tape-cup_v4.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable */

declare type tape$TestOpts = {
skip: boolean,
timeout?: number,
} | {
skip?: boolean,
timeout: number,
};

declare type tape$TestCb = (t: tape$Context) => mixed;
declare type tape$TestFn = (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestOpts | tape$TestCb, c?: tape$TestCb) => void;

declare interface tape$Context {
fail(msg?: string): void,
pass(msg?: string): void,

error(err: mixed, msg?: string): void,
ifError(err: mixed, msg?: string): void,
ifErr(err: mixed, msg?: string): void,
iferror(err: mixed, msg?: string): void,

ok(value: mixed, msg?: string): void,
true(value: mixed, msg?: string): void,
assert(value: mixed, msg?: string): void,

notOk(value: mixed, msg?: string): void,
false(value: mixed, msg?: string): void,
notok(value: mixed, msg?: string): void,

// equal + aliases
equal(actual: mixed, expected: mixed, msg?: string): void,
equals(actual: mixed, expected: mixed, msg?: string): void,
isEqual(actual: mixed, expected: mixed, msg?: string): void,
is(actual: mixed, expected: mixed, msg?: string): void,
strictEqual(actual: mixed, expected: mixed, msg?: string): void,
strictEquals(actual: mixed, expected: mixed, msg?: string): void,

// notEqual + aliases
notEqual(actual: mixed, expected: mixed, msg?: string): void,
notEquals(actual: mixed, expected: mixed, msg?: string): void,
notStrictEqual(actual: mixed, expected: mixed, msg?: string): void,
notStrictEquals(actual: mixed, expected: mixed, msg?: string): void,
isNotEqual(actual: mixed, expected: mixed, msg?: string): void,
isNot(actual: mixed, expected: mixed, msg?: string): void,
not(actual: mixed, expected: mixed, msg?: string): void,
doesNotEqual(actual: mixed, expected: mixed, msg?: string): void,
isInequal(actual: mixed, expected: mixed, msg?: string): void,

// deepEqual + aliases
deepEqual(actual: mixed, expected: mixed, msg?: string): void,
deepEquals(actual: mixed, expected: mixed, msg?: string): void,
isEquivalent(actual: mixed, expected: mixed, msg?: string): void,
same(actual: mixed, expected: mixed, msg?: string): void,

// notDeepEqual
notDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
notEquivalent(actual: mixed, expected: mixed, msg?: string): void,
notDeeply(actual: mixed, expected: mixed, msg?: string): void,
notSame(actual: mixed, expected: mixed, msg?: string): void,
isNotDeepEqual(actual: mixed, expected: mixed, msg?: string): void,
isNotDeeply(actual: mixed, expected: mixed, msg?: string): void,
isNotEquivalent(actual: mixed, expected: mixed, msg?: string): void,
isInequivalent(actual: mixed, expected: mixed, msg?: string): void,

// deepLooseEqual
deepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
looseEqual(actual: mixed, expected: mixed, msg?: string): void,
looseEquals(actual: mixed, expected: mixed, msg?: string): void,

// notDeepLooseEqual
notDeepLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
notLooseEqual(actual: mixed, expected: mixed, msg?: string): void,
notLooseEquals(actual: mixed, expected: mixed, msg?: string): void,

throws(fn: Function, expected?: RegExp | Function, msg?: string): void,
doesNotThrow(fn: Function, expected?: RegExp | Function, msg?: string): void,

timeoutAfter(ms: number): void,

skip(msg?: string): void,
plan(n: number): void,
onFinish(fn: Function): void,
end(): void,
comment(msg: string): void,
test: tape$TestFn,
}

declare module 'tape-cup' {
declare type TestHarness = Tape;
declare type StreamOpts = {
objectMode?: boolean,
};

declare type Tape = {
(a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>): void,
test: tape$TestFn,
skip: (name: string, cb?: tape$TestCb) => void,
createHarness: () => TestHarness,
createStream: (opts?: StreamOpts) => stream$Readable,
only: (a: string | tape$TestOpts | tape$TestCb, b?: tape$TestCb | tape$TestOpts, c?: tape$TestCb, ...rest: Array<void>) => void,
};

declare module.exports: Tape;
}
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"version": "1.0.3",
"license": "MIT",
"repository": "fusionjs/fusion-plugin-jwt",
"files": ["dist", "src"],
"files": [
"dist",
"src"
],
"main": "./dist/index.js",
"module": "./dist/index.es.js",
"browser": {
Expand Down Expand Up @@ -52,8 +55,7 @@
"lint": "eslint . --ignore-path .gitignore",
"transpile": "npm run clean && cup build",
"build-test": "rm -rf dist-tests && cup build-tests",
"just-test":
"node_modules/.bin/unitest --browser=dist-tests/browser.js --node=dist-tests/node.js",
"just-test": "node_modules/.bin/unitest --browser=dist-tests/browser.js --node=dist-tests/node.js",
"test": "npm run build-test && npm run just-test",
"cover": "npm run build-test && nyc npm run just-test",
"prepublish": "npm run transpile"
Expand Down
Loading

0 comments on commit 66efd23

Please sign in to comment.