Skip to content

Commit

Permalink
fix(typescript): fix void/undefined inconsistencies and ts lint
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Sep 30, 2019
1 parent cbf4898 commit 96c9415
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 59 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"scripts": {
"coverage": "nyc node ./test/run",
"heroku-postbuild": "npm install mongodb@^3.0.0 openid-client@^3.0.0",
"lint": "eslint lib example certification test && dtslint --onlyTestTsNext types",
"lint": "eslint lib example certification test && dtslint types",
"lint-fix": "eslint lib example certification test --fix",
"test": "node ./test/run"
},
Expand Down Expand Up @@ -83,7 +83,8 @@
"paseto": "^0.9.1",
"sinon": "^7.5.0",
"supertest": "^4.0.2",
"timekeeper": "^2.2.0"
"timekeeper": "^2.2.0",
"typescript": "^3.6.3"
},
"engines": {
"node": "^10.13.0 || >=12.0.0"
Expand Down
89 changes: 45 additions & 44 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="node" />
// TypeScript Version: 3.6

import * as events from 'events';
import * as http from 'http';
Expand Down Expand Up @@ -210,40 +211,40 @@ declare class Session extends BaseModel {
[clientId: string]: ClientAuthorizationState;
};

accountId(): string | void;
authTime(): string | void;
accountId(): string | undefined;
authTime(): string | undefined;
past(age: number): boolean;

ensureClientContainer(clientId: string): void;
ensureClientContainer(clientId: string): undefined;
loginAccount(details: {
account: string;
acr?: string;
amr?: string[];
loginTs?: number;
transient?: boolean;
}): void;
authorizationFor(clientId: string): ClientAuthorizationState | void;
}): undefined;
authorizationFor(clientId: string): ClientAuthorizationState | undefined;
stateFor(clientId: string): string;
sidFor(clientId: string): string;
sidFor(clientId: string, value: string): void;
sidFor(clientId: string, value: string): undefined;
grantIdFor(clientId: string): string;
grantIdFor(clientId: string, value: string): void;
metaFor(clientId: string): AnyObject | void;
metaFor(clientId: string, value: string): void;
grantIdFor(clientId: string, value: string): undefined;
metaFor(clientId: string): AnyObject | undefined;
metaFor(clientId: string, value: string): undefined;
acceptedScopesFor(clientId: string): Set<string>;
acceptedClaimsFor(clientId: string): Set<string>;
promptedScopesFor(clientId: string): Set<string>;
promptedScopesFor(clientId: string, scopes: string[]): void;
promptedScopesFor(clientId: string, scopes: string[]): undefined;
promptedClaimsFor(clientId: string): Set<string>;
promptedClaimsFor(clientId: string, claims: string[]): void;
promptedClaimsFor(clientId: string, claims: string[]): undefined;
rejectedScopesFor(clientId: string): Set<string>;
rejectedScopesFor(clientId: string, scopes: string[], replace?: boolean): void;
rejectedScopesFor(clientId: string, scopes: string[], replace?: boolean): undefined;
rejectedClaimsFor(clientId: string): Set<string>;
rejectedClaimsFor(clientId: string, claims: string[], replace?: boolean): void;
rejectedClaimsFor(clientId: string, claims: string[], replace?: boolean): undefined;

save(ttl?: number): Promise<string>;
destroy(): Promise<void>;
resetIdentifier(): void;
destroy(): Promise<undefined>;
resetIdentifier(): undefined;
static find<T>(this: { new (...args: any[]): T }, cookieId: string): Promise<T | undefined>;
static findByUid(uid: string): Promise<Session | undefined>;
static get(ctx: Koa.Context): Promise<Session>;
Expand Down Expand Up @@ -275,7 +276,7 @@ declare class BaseModel {
readonly adapter: Adapter;

save(ttl?: number): Promise<string>;
destroy(): Promise<void>;
destroy(): Promise<undefined>;
emit(eventName: string): void;

static readonly adapter: Adapter;
Expand Down Expand Up @@ -371,7 +372,7 @@ declare class RefreshToken extends BaseToken {

totalLifetime(): number;
isSenderConstrained(): boolean;
consume(): Promise<void>;
consume(): Promise<undefined>;
}

declare class AuthorizationCode extends BaseToken {
Expand Down Expand Up @@ -417,7 +418,7 @@ declare class AuthorizationCode extends BaseToken {
grantId?: string;
gty?: string;

consume(): Promise<void>;
consume(): Promise<undefined>;
}

declare class DeviceCode extends BaseToken {
Expand Down Expand Up @@ -453,7 +454,7 @@ declare class DeviceCode extends BaseToken {
gty: string;
consumed: any;

consume(): Promise<void>;
consume(): Promise<undefined>;
}

declare class ClientCredentials extends BaseToken {
Expand Down Expand Up @@ -543,7 +544,7 @@ declare class IdToken {
declare class ClientKeystore {
fresh(): boolean;
stale(): boolean;
refresh(): Promise<void>;
refresh(): Promise<undefined>;
readonly size: number;
all(parameters?: jose.JWKS.KeyQuery): jose.JWK.Key[];
get(parameters?: jose.JWKS.KeyQuery): jose.JWK.Key;
Expand Down Expand Up @@ -677,7 +678,7 @@ declare class OIDCContext {
readonly body?: AnyObject;
readonly params?: AnyObject;

acceptedScope(): string[] | void;
acceptedScope(): string[] | undefined;
resolvedClaims(): ClaimsWithRejects;

getAccessToken(opts?: { acceptDPoP?: boolean, acceptQueryParam?: boolean }): string;
Expand Down Expand Up @@ -773,13 +774,13 @@ export interface AdapterPayload {
}

export interface Adapter {
upsert(id: string, payload: AdapterPayload, expiresIn: number): Promise<void>;
upsert(id: string, payload: AdapterPayload, expiresIn: number): Promise<undefined>;
find(id: string): Promise<AdapterPayload | undefined>;
findByUserCode(userCode: string): Promise<AdapterPayload | undefined>;
findByUid(uid: string): Promise<AdapterPayload | undefined>;
consume(id: string): Promise<void>;
destroy(id: string): Promise<void>;
revokeByGrantId(grantId: string): Promise<void>;
consume(id: string): Promise<undefined>;
destroy(id: string): Promise<undefined>;
revokeByGrantId(grantId: string): Promise<undefined>;
}

export interface AdapterConstructor {
Expand Down Expand Up @@ -869,9 +870,9 @@ export interface Configuration {
charset?: 'base-20' | 'digits';
mask?: string;
deviceInfo?: (ctx: KoaContextWithOIDC) => AnyObject;
userCodeInputSource?: (ctx: KoaContextWithOIDC, form: string, out?: ErrorOut, err?: errors.OIDCProviderError | Error) => Promise<void> | void;
userCodeConfirmSource?: (ctx: KoaContextWithOIDC, form: string, client: Client, deviceInfo: AnyObject, userCode: string) => Promise<void> | void;
successSource?: (ctx: KoaContextWithOIDC) => Promise<void> | void;
userCodeInputSource?: (ctx: KoaContextWithOIDC, form: string, out?: ErrorOut, err?: errors.OIDCProviderError | Error) => Promise<undefined> | undefined;
userCodeConfirmSource?: (ctx: KoaContextWithOIDC, form: string, client: Client, deviceInfo: AnyObject, userCode: string) => Promise<undefined> | undefined;
successSource?: (ctx: KoaContextWithOIDC) => Promise<undefined> | undefined;
};

requestObjects?: {
Expand All @@ -883,27 +884,27 @@ export interface Configuration {
whitelist?: string[] | Set<string>;
};
};
dPoP?: { enabled?: boolean, iatTolerance?: number, ack?: number | string },
dPoP?: { enabled?: boolean, iatTolerance?: number, ack?: 'id-02' },

sessionManagement?: { enabled?: boolean, keepHeaders?: boolean, ack?: number | string },
sessionManagement?: { enabled?: boolean, keepHeaders?: boolean, ack?: 28 },

backchannelLogout?: { enabled?: boolean, ack?: number | string },
backchannelLogout?: { enabled?: boolean, ack?: 4 },

ietfJWTAccessTokenProfile?: { enabled?: boolean, ack?: number | string },
ietfJWTAccessTokenProfile?: { enabled?: boolean, ack?: 2 },

fapiRW?: { enabled?: boolean, ack?: number | string },
fapiRW?: { enabled?: boolean, ack?: 'id02-rev.3' },

webMessageResponseMode?: { enabled?: boolean, ack?: number | string },
webMessageResponseMode?: { enabled?: boolean, ack?: 'id-00' },

jwtIntrospection?: { enabled?: boolean, ack?: number | string },
jwtIntrospection?: { enabled?: boolean, ack?: 8 },

jwtResponseModes?: { enabled?: boolean, ack?: number | string },
jwtResponseModes?: { enabled?: boolean, ack?: 1 | 2 },

pushedAuthorizationRequests?: { enabled?: boolean, ack?: number | string },
pushedAuthorizationRequests?: { enabled?: boolean, ack?: 0 },

mTLS?: {
enabled?: boolean;
ack?: number | string;
ack?: '15-rc.1' | 16 | 17;
certificateBoundAccessTokens?: boolean;
selfSignedTlsClientAuth?: boolean;
tlsClientAuth?: boolean;
Expand All @@ -914,18 +915,18 @@ export interface Configuration {

resourceIndicators?: {
enabled?: boolean;
ack?: number | string;
ack?: 2 | 3 | 4 | 5 | 6 | 7;
allowedPolicy?: (ctx: KoaContextWithOIDC, resources: string | string[], client: Client) => Promise<boolean> | boolean;
};

frontchannelLogout?: {
enabled?: boolean;
ack?: number | string;
logoutPendingSource?: (ctx: KoaContextWithOIDC, frames: string[], postLogoutRedirectUri?: string) => Promise<void>;
ack?: 2;
logoutPendingSource?: (ctx: KoaContextWithOIDC, frames: string[], postLogoutRedirectUri?: string) => Promise<undefined>;
};
};

extraAccessTokenClaims?: (ctx: KoaContextWithOIDC, token: AccessToken | ClientCredentials) => Promise<AnyObject> | AnyObject | Promise<void> | void;
extraAccessTokenClaims?: (ctx: KoaContextWithOIDC, token: AccessToken | ClientCredentials) => Promise<AnyObject> | AnyObject | Promise<undefined> | undefined;

formats?: {
AccessToken?: AccessTokenFormatFunction | TokenFormat;
Expand Down Expand Up @@ -1098,7 +1099,7 @@ export class Provider extends events.EventEmitter {
res: http.ServerResponse | http2.Http2ServerResponse,
result: InteractionResults,
options?: { mergeWithLastSubmission?: boolean }
): Promise<void>;
): Promise<undefined>;

interactionDetails(req: http.IncomingMessage | http2.Http2ServerRequest, res: http.ServerResponse | http2.Http2ServerResponse): Promise<Interaction>;

Expand All @@ -1116,7 +1117,7 @@ export class Provider extends events.EventEmitter {

registerGrantType(
name: string,
handler: (ctx: KoaContextWithOIDC, next: () => Promise<void>) => Promise<void> | void,
handler: (ctx: KoaContextWithOIDC, next: () => Promise<undefined>) => Promise<undefined> | undefined,
params?: string | string[] | Set<string>,
dupes?: string | string[] | Set<string>
): void;
Expand Down
38 changes: 25 additions & 13 deletions types/oidc-provider-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ const provider = new Provider('https://op.example.com', {
this.name = name;
}

async upsert(id: string, payload: object, expiresIn: number) {}
async consume(id: string) {}
async destroy(id: string) {}
async revokeByGrantId(grantId: string) {}
async upsert(id: string, payload: object, expiresIn: number) {
return undefined;
}
async consume(id: string) {
return undefined;
}
async destroy(id: string) {
return undefined;
}
async revokeByGrantId(grantId: string) {
return undefined;
}

async find(id: string) {
return {};
Expand Down Expand Up @@ -280,12 +288,12 @@ const provider = new Provider('https://op.example.com', {
introspection: { enabled: false },
userinfo: { enabled: false },
jwtUserinfo: { enabled: false },
webMessageResponseMode: { enabled: false, ack: 2 },
webMessageResponseMode: { enabled: false, ack: 'id-00' },
revocation: { enabled: false },
sessionManagement: { enabled: false, ack: 2, keepHeaders: false },
jwtIntrospection: { enabled: false, ack: 2 },
sessionManagement: { enabled: false, ack: 28, keepHeaders: false },
jwtIntrospection: { enabled: false, ack: 8 },
jwtResponseModes: { enabled: false, ack: 2 },
pushedAuthorizationRequests: { enabled: false, ack: 2 },
pushedAuthorizationRequests: { enabled: false, ack: 0 },
registration: {
enabled: true,
initialAccessToken: true,
Expand All @@ -311,7 +319,7 @@ const provider = new Provider('https://op.example.com', {
},
resourceIndicators: {
enabled: true,
ack: 2,
ack: 7,
async allowedPolicy(ctx, resources, client) {
ctx.oidc.issuer.substring(0);
if (Array.isArray(resources)) {
Expand All @@ -332,11 +340,11 @@ const provider = new Provider('https://op.example.com', {
},
},
encryption: { enabled: false },
fapiRW: { enabled: false, ack: 2 },
fapiRW: { enabled: false, ack: 'id02-rev.3' },
clientCredentials: { enabled: false },
backchannelLogout: { enabled: false, ack: 2 },
backchannelLogout: { enabled: false, ack: 4 },
ietfJWTAccessTokenProfile: { enabled: false, ack: 2 },
dPoP: { enabled: false, ack: 2, iatTolerance: 120 },
dPoP: { enabled: false, ack: 'id-02', iatTolerance: 120 },
frontchannelLogout: {
ack: 2,
enabled: false,
Expand All @@ -346,6 +354,7 @@ const provider = new Provider('https://op.example.com', {
if (postLogoutRedirectUri) {
postLogoutRedirectUri.substring(0);
}
return undefined;
}
},
deviceFlow: {
Expand All @@ -365,24 +374,27 @@ const provider = new Provider('https://op.example.com', {
if (err) {
err.message.substring(0);
}
return undefined;
},
async userCodeConfirmSource(ctx, form, client, deviceInfo, userCode) {
ctx.oidc.issuer.substring(0);
form.substring(0);
client.clientId.substring(0);
JSON.stringify(deviceInfo.foo);
userCode.substring(0);
return undefined;
},
async successSource(ctx) {
ctx.oidc.issuer.substring(0);
return undefined;
}
},
mTLS: {
enabled: false,
certificateBoundAccessTokens: true,
selfSignedTlsClientAuth: true,
tlsClientAuth: true,
ack: 2,
ack: 17,
getCertificate(ctx) {
ctx.oidc.issuer.substring(0);
return 'foo';
Expand Down

0 comments on commit 96c9415

Please sign in to comment.