From d3a75d5e5d8603f1282b61cbc747c560c1370d2d Mon Sep 17 00:00:00 2001 From: Joabesv Date: Thu, 16 Nov 2023 14:54:57 -0300 Subject: [PATCH 1/4] change mentions to literal types --- types/index.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index e97ac3e..4caa237 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -25,10 +25,10 @@ declare namespace fastifyOauth2 { scope?: string[]; credentials: Credentials; callbackUri: string; - callbackUriParams?: Object; - tokenRequestParams?: Object; - generateStateFunction?: Function; - checkStateFunction?: Function; + callbackUriParams?: Record; + tokenRequestParams?: Record; + generateStateFunction?: (request: FastifyRequest) => string; + checkStateFunction?: (request?: FastifyRequest, callback?: (err: any) => void) => string | void; startRedirectPath?: string; tags?: string[]; schema?: object; @@ -126,11 +126,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, @@ -140,19 +140,19 @@ 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 + revokeAllToken(revokeToken: Token, httpOptions: Record | undefined): Promise } export const fastifyOauth2: FastifyOauth2 From 3e337b6ed930ae456f2139b13d0df30bbcf80b87 Mon Sep 17 00:00:00 2001 From: Joabesv Date: Thu, 16 Nov 2023 15:00:45 -0300 Subject: [PATCH 2/4] fix tests --- types/index.test-d.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 5ecd830..75682e2 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -43,10 +43,6 @@ const OAuth2Options: FastifyOAuth2Options = { credentials: credentials, callbackUri: 'http://localhost/testOauth/callback', callbackUriParams: {}, - generateStateFunction: () => { - }, - checkStateFunction: () => { - }, startRedirectPath: '/login/testOauth', cookie: { secure: true, @@ -93,7 +89,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 From 276298f3530477c20e64eb339b1a1d2dd689ff0c Mon Sep 17 00:00:00 2001 From: Joabesv Date: Fri, 17 Nov 2023 13:20:30 -0300 Subject: [PATCH 3/4] refac: return void and make params obligatory --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 4caa237..ccd679d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,7 +28,7 @@ declare namespace fastifyOauth2 { callbackUriParams?: Record; tokenRequestParams?: Record; generateStateFunction?: (request: FastifyRequest) => string; - checkStateFunction?: (request?: FastifyRequest, callback?: (err: any) => void) => string | void; + checkStateFunction?: (request: FastifyRequest, callback : (err: any) => void) => void; startRedirectPath?: string; tags?: string[]; schema?: object; From 599a5fd8299bc3b571d3020508fbf74b89e379c0 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 26 Dec 2023 15:46:58 +0100 Subject: [PATCH 4/4] patch --- types/index.test-d.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 75682e2..ca8235a 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,4 +1,4 @@ -import fastify from 'fastify'; +import fastify, { FastifyRequest } from 'fastify'; import {expectAssignable, expectError, expectType} from 'tsd'; import fastifyOauth2, { FastifyOAuth2Options, @@ -43,6 +43,14 @@ const OAuth2Options: FastifyOAuth2Options = { credentials: credentials, callbackUri: 'http://localhost/testOauth/callback', callbackUriParams: {}, + generateStateFunction: (request) => { + expectAssignable(request); + return 'result'; + }, + checkStateFunction: (request, callback) => { + expectAssignable(request); + expectType<(err: any) => void>(callback); + }, startRedirectPath: '/login/testOauth', cookie: { secure: true,