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

Update types #237

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 9 additions & 8 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ declare namespace fastifyOauth2 {
scope?: string[];
credentials: Credentials;
callbackUri: string;
callbackUriParams?: Object;
tokenRequestParams?: Object;
callbackUriParams?: Record<string, string>;
tokenRequestParams?: Record<string, string>;
generateStateFunction?: FastifyGenerateStateFunction;
checkStateFunction?: FastifyCheckStateFunction;
startRedirectPath?: string;
Expand Down Expand Up @@ -149,11 +149,11 @@ declare namespace fastifyOauth2 {

getNewAccessTokenUsingRefreshToken(
refreshToken: Token,
params: Object,
params: Record<string, string>,
callback: (err: any, token: OAuth2Token) => void,
): void;

getNewAccessTokenUsingRefreshToken(refreshToken: Token, params: Object): Promise<OAuth2Token>;
getNewAccessTokenUsingRefreshToken(refreshToken: Token, params: Record<string, string>): Promise<OAuth2Token>;

generateAuthorizationUri(
request: FastifyRequest,
Expand All @@ -169,21 +169,22 @@ declare namespace fastifyOauth2 {
revokeToken(
revokeToken: Token,
tokenType: TToken,
httpOptions: Object | undefined,
httpOptions: Record<string, string> | undefined,
callback: (err: any) => void
): void;

revokeToken(revokeToken: Token, tokenType: TToken, httpOptions: Object | undefined): Promise<void>;
revokeToken(revokeToken: Token, tokenType: TToken, httpOptions: Record<string, string> | undefined): Promise<void>

revokeAllToken(
revokeToken: Token,
httpOptions: Object | undefined,
httpOptions: Record<string, string> | undefined,
callback: (err: any) => void
): void;

revokeAllToken(revokeToken: Token, httpOptions: Object | undefined): Promise<void>;

userinfo(tokenSetOrToken: Token | string): Promise<Object>;
revokeAllToken(revokeToken: Token, httpOptions: Record<string, string> | undefined): Promise<void>
}

userinfo(tokenSetOrToken: Token | string, userInfoExtraOptions: UserInfoExtraOptions | undefined): Promise<Object>;

Expand Down
17 changes: 9 additions & 8 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -9,7 +9,6 @@ import fastifyOauth2, {
UserInfoExtraOptions
} from '..';
import type { ModuleOptions } from 'simple-oauth2';
import { FastifyInstance } from 'fastify';

/**
* Preparing some data for testing.
Expand Down Expand Up @@ -45,13 +44,15 @@ const OAuth2Options: FastifyOAuth2Options = {
credentials: credentials,
callbackUri: 'http://localhost/testOauth/callback',
callbackUriParams: {},
generateStateFunction: function () {
generateStateFunction: function (request) {
expectType<FastifyInstance>(this)
return 'test'
expectAssignable<FastifyRequest>(request);
return 'test';
},
checkStateFunction: function () {
checkStateFunction: function (request, callback) {
expectType<FastifyInstance>(this)
return true
expectAssignable<FastifyRequest>(request);
expectType<(err: any) => void>(callback);
},
startRedirectPath: '/login/testOauth',
cookie: {
Expand Down Expand Up @@ -152,7 +153,7 @@ expectType<string[]>(scope);
expectType<string[]>(tags);
expectType<Credentials>(credentials);

// Ensure duplicayed simple-oauth2 are compatible with simple-oauth2
// Ensure duplicated simple-oauth2 are compatible with simple-oauth2
expectAssignable<ModuleOptions<string>>(credentials);
expectAssignable<ModuleOptions["auth"]>(auth);
// Ensure published types of simple-oauth2 are accepted
Expand Down
Loading