diff --git a/types/index.d.ts b/types/index.d.ts index 4a4c4ba..463db17 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -35,8 +35,8 @@ declare namespace fastifyOauth2 { scope?: string[]; credentials: Credentials; callbackUri: string; - callbackUriParams?: Object; - tokenRequestParams?: Object; + callbackUriParams?: Record; + tokenRequestParams?: Record; generateStateFunction?: FastifyGenerateStateFunction; checkStateFunction?: FastifyCheckStateFunction; startRedirectPath?: string; @@ -149,11 +149,11 @@ declare namespace fastifyOauth2 { getNewAccessTokenUsingRefreshToken( refreshToken: Token, - params: Object, + params: Record, callback: (err: any, token: OAuth2Token) => void, ): void; - getNewAccessTokenUsingRefreshToken(refreshToken: Token, params: Object): Promise; + getNewAccessTokenUsingRefreshToken(refreshToken: Token, params: Record): Promise; generateAuthorizationUri( request: FastifyRequest, @@ -169,21 +169,22 @@ declare namespace fastifyOauth2 { revokeToken( revokeToken: Token, tokenType: TToken, - httpOptions: Object | undefined, + httpOptions: Record | undefined, callback: (err: any) => void ): void; - revokeToken(revokeToken: Token, tokenType: TToken, httpOptions: Object | undefined): Promise; + revokeToken(revokeToken: Token, tokenType: TToken, httpOptions: Record | undefined): Promise revokeAllToken( revokeToken: Token, - httpOptions: Object | undefined, + httpOptions: Record | undefined, callback: (err: any) => void ): void; revokeAllToken(revokeToken: Token, httpOptions: Object | undefined): Promise; - userinfo(tokenSetOrToken: Token | string): Promise; + revokeAllToken(revokeToken: Token, httpOptions: Record | undefined): Promise + } userinfo(tokenSetOrToken: Token | string, userInfoExtraOptions: UserInfoExtraOptions | undefined): Promise; diff --git a/types/index.test-d.ts b/types/index.test-d.ts index e73745d..9aa2634 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,5 +1,5 @@ -import fastify from 'fastify'; -import {expectAssignable, expectError, expectNotAssignable, expectType} from 'tsd'; +import fastify, { FastifyInstance, FastifyRequest } from 'fastify'; +import {expectAssignable, expectError, expectType, expectNotAssignable} from 'tsd'; import fastifyOauth2, { FastifyOAuth2Options, Credentials, @@ -9,7 +9,6 @@ import fastifyOauth2, { UserInfoExtraOptions } from '..'; import type { ModuleOptions } from 'simple-oauth2'; -import { FastifyInstance } from 'fastify'; /** * Preparing some data for testing. @@ -45,13 +44,15 @@ const OAuth2Options: FastifyOAuth2Options = { credentials: credentials, callbackUri: 'http://localhost/testOauth/callback', callbackUriParams: {}, - generateStateFunction: function () { + generateStateFunction: function (request) { expectType(this) - return 'test' + expectAssignable(request); + return 'test'; }, - checkStateFunction: function () { + checkStateFunction: function (request, callback) { expectType(this) - return true + expectAssignable(request); + expectType<(err: any) => void>(callback); }, startRedirectPath: '/login/testOauth', cookie: { @@ -152,7 +153,7 @@ expectType(scope); expectType(tags); expectType(credentials); -// Ensure duplicayed simple-oauth2 are compatible with simple-oauth2 +// Ensure duplicated simple-oauth2 are compatible with simple-oauth2 expectAssignable>(credentials); expectAssignable(auth); // Ensure published types of simple-oauth2 are accepted