Skip to content

Commit ae7a41a

Browse files
authored
feat(typescript): export all the method types \o/ (#5)
1 parent 8976945 commit ae7a41a

12 files changed

+184
-149
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [OAuth APP authentication](#oauth-app-authentication)
2626
- [GitHub App with non-expiring user authentication](#github-app-with-non-expiring-user-authentication)
2727
- [GitHub App with expiring user authentication](#github-app-with-expiring-user-authentication)
28+
- [Types](#types)
2829
- [Contributing](#contributing)
2930
- [License](#license)
3031

@@ -1568,6 +1569,43 @@ import {
15681569
OAuthAppAuthentication,
15691570
GitHubAppAuthentication,
15701571
GitHubAppAuthenticationWithExpiration,
1572+
GetWebFlowAuthorizationUrlOAuthAppOptions,
1573+
GetWebFlowAuthorizationUrlGitHubAppOptions,
1574+
GetWebFlowAuthorizationUrlOAuthAppResult,
1575+
GetWebFlowAuthorizationUrlGitHubAppResult,
1576+
CheckTokenOAuthAppOptions,
1577+
CheckTokenGitHubAppOptions,
1578+
CheckTokenOAuthAppResponse,
1579+
CheckTokenGitHubAppResponse,
1580+
ExchangeWebFlowCodeOAuthAppOptions,
1581+
ExchangeWebFlowCodeGitHubAppOptions,
1582+
ExchangeWebFlowCodeOAuthAppResponse,
1583+
ExchangeWebFlowCodeGitHubAppResponse,
1584+
CreateDeviceCodeOAuthAppOptions,
1585+
CreateDeviceCodeGitHubAppOptions,
1586+
CreateDeviceCodeDeviceTokenResponse,
1587+
ExchangeDeviceCodeOAuthAppOptionsWithoutClientSecret,
1588+
ExchangeDeviceCodeOAuthAppOptions,
1589+
ExchangeDeviceCodeGitHubAppOptionsWithoutClientSecret,
1590+
ExchangeDeviceCodeGitHubAppOptions,
1591+
ExchangeDeviceCodeOAuthAppResponse,
1592+
ExchangeDeviceCodeOAuthAppResponseWithoutClientSecret,
1593+
ExchangeDeviceCodeGitHubAppResponse,
1594+
ExchangeDeviceCodeGitHubAppResponseWithoutClientSecret,
1595+
RefreshTokenOptions,
1596+
RefreshTokenResponse,
1597+
ScopeTokenOptions,
1598+
ScopeTokenResponse,
1599+
ResetTokenOAuthAppOptions,
1600+
ResetTokenGitHubAppOptions,
1601+
ResetTokenOAuthAppResponse,
1602+
ResetTokenGitHubAppResponse,
1603+
DeleteTokenOAuthAppOptions,
1604+
DeleteTokenGitHubAppOptions,
1605+
DeleteTokenResponse,
1606+
DeleteAuthorizationOAuthAppOptions,
1607+
DeleteAuthorizationGitHubAppOptions,
1608+
DeleteAuthorizationResponse,
15711609
} from "@octokit/oauth-methods";
15721610
```
15731611

src/check-token.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ import btoa from "btoa-lite";
44

55
import { OAuthAppAuthentication, GitHubAppAuthentication } from "./types";
66

7-
type OAuthAppOptions = {
7+
export type CheckTokenOAuthAppOptions = {
88
clientType: "oauth-app";
99
clientId: string;
1010
clientSecret: string;
1111
token: string;
1212
request?: RequestInterface;
1313
};
14-
type GitHubAppOptions = {
14+
export type CheckTokenGitHubAppOptions = {
1515
clientType: "github-app";
1616
clientId: string;
1717
clientSecret: string;
1818
token: string;
1919
request?: RequestInterface;
2020
};
2121

22-
type OAuthAppResult = Endpoints["POST /applications/{client_id}/token"]["response"] & {
22+
export type CheckTokenOAuthAppResponse = Endpoints["POST /applications/{client_id}/token"]["response"] & {
2323
authentication: OAuthAppAuthentication;
2424
};
25-
type GitHubAppResult = Endpoints["POST /applications/{client_id}/token"]["response"] & {
25+
export type CheckTokenGitHubAppResponse = Endpoints["POST /applications/{client_id}/token"]["response"] & {
2626
authentication: GitHubAppAuthentication;
2727
};
2828

2929
export async function checkToken(
30-
options: OAuthAppOptions
31-
): Promise<OAuthAppResult>;
30+
options: CheckTokenOAuthAppOptions
31+
): Promise<CheckTokenOAuthAppResponse>;
3232
export async function checkToken(
33-
options: GitHubAppOptions
34-
): Promise<GitHubAppResult>;
33+
options: CheckTokenGitHubAppOptions
34+
): Promise<CheckTokenGitHubAppResponse>;
3535

3636
export async function checkToken(
37-
options: OAuthAppOptions | GitHubAppOptions
37+
options: CheckTokenOAuthAppOptions | CheckTokenGitHubAppOptions
3838
): Promise<any> {
3939
const request =
4040
options.request ||

src/create-device-code.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ import { OctokitResponse, RequestInterface } from "@octokit/types";
33

44
import { oauthRequest } from "./utils";
55

6-
type OAuthAppOptions = {
6+
export type CreateDeviceCodeOAuthAppOptions = {
77
clientType: "oauth-app";
88
clientId: string;
99
scopes?: string[];
1010
request?: RequestInterface;
1111
};
12-
type GitHubAppOptions = {
12+
export type CreateDeviceCodeGitHubAppOptions = {
1313
clientType: "github-app";
1414
clientId: string;
1515
request?: RequestInterface;
1616
};
1717

18-
type DeviceTokenResponse = {
18+
export type CreateDeviceCodeDeviceTokenResponse = OctokitResponse<{
1919
device_code: string;
2020
user_code: string;
2121
verification_uri: string;
2222
expires_in: number;
2323
interval: number;
24-
};
24+
}>;
2525

2626
export async function createDeviceCode(
27-
options: OAuthAppOptions | GitHubAppOptions
28-
): Promise<OctokitResponse<DeviceTokenResponse>> {
27+
options: CreateDeviceCodeOAuthAppOptions | CreateDeviceCodeGitHubAppOptions
28+
): Promise<CreateDeviceCodeDeviceTokenResponse> {
2929
const request =
3030
options.request ||
3131
/* istanbul ignore next: we always pass a custom request in tests */

src/delete-authorization.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@ import { request as defaultRequest } from "@octokit/request";
22
import { RequestInterface, Endpoints } from "@octokit/types";
33
import btoa from "btoa-lite";
44

5-
type OAuthAppOptions = {
5+
export type DeleteAuthorizationOAuthAppOptions = {
66
clientType: "oauth-app";
77
clientId: string;
88
clientSecret: string;
99
token: string;
1010
request?: RequestInterface;
1111
};
12-
type GitHubAppOptions = {
12+
export type DeleteAuthorizationGitHubAppOptions = {
1313
clientType: "github-app";
1414
clientId: string;
1515
clientSecret: string;
1616
token: string;
1717
request?: RequestInterface;
1818
};
19+
export type DeleteAuthorizationResponse = Endpoints["DELETE /applications/{client_id}/grant"]["response"];
1920

2021
export async function deleteAuthorization(
21-
options: OAuthAppOptions
22-
): Promise<Endpoints["DELETE /applications/{client_id}/grant"]["response"]>;
22+
options: DeleteAuthorizationOAuthAppOptions
23+
): Promise<DeleteAuthorizationResponse>;
2324
export async function deleteAuthorization(
24-
options: GitHubAppOptions
25-
): Promise<Endpoints["DELETE /applications/{client_id}/grant"]["response"]>;
25+
options: DeleteAuthorizationGitHubAppOptions
26+
): Promise<DeleteAuthorizationResponse>;
2627

2728
export async function deleteAuthorization(
28-
options: OAuthAppOptions | GitHubAppOptions
29+
options:
30+
| DeleteAuthorizationOAuthAppOptions
31+
| DeleteAuthorizationGitHubAppOptions
2932
): Promise<any> {
3033
const request =
3134
options.request ||

src/delete-token.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@ import { request as defaultRequest } from "@octokit/request";
22
import { RequestInterface, Endpoints } from "@octokit/types";
33
import btoa from "btoa-lite";
44

5-
type OAuthAppOptions = {
5+
export type DeleteTokenOAuthAppOptions = {
66
clientType: "oauth-app";
77
clientId: string;
88
clientSecret: string;
99
token: string;
1010
request?: RequestInterface;
1111
};
12-
type GitHubAppOptions = {
12+
export type DeleteTokenGitHubAppOptions = {
1313
clientType: "github-app";
1414
clientId: string;
1515
clientSecret: string;
1616
token: string;
1717
request?: RequestInterface;
1818
};
1919

20+
export type DeleteTokenResponse = Endpoints["DELETE /applications/{client_id}/token"]["response"];
21+
2022
export async function deleteToken(
21-
options: OAuthAppOptions
22-
): Promise<Endpoints["DELETE /applications/{client_id}/token"]["response"]>;
23+
options: DeleteTokenOAuthAppOptions
24+
): Promise<DeleteTokenResponse>;
2325
export async function deleteToken(
24-
options: GitHubAppOptions
25-
): Promise<Endpoints["DELETE /applications/{client_id}/token"]["response"]>;
26+
options: DeleteTokenGitHubAppOptions
27+
): Promise<DeleteTokenResponse>;
2628

2729
export async function deleteToken(
28-
options: OAuthAppOptions | GitHubAppOptions
30+
options: DeleteTokenOAuthAppOptions | DeleteTokenGitHubAppOptions
2931
): Promise<any> {
3032
const request =
3133
options.request ||

src/exchange-device-code.ts

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import {
1111
} from "./types";
1212
import { oauthRequest } from "./utils";
1313

14-
type OAuthAppOptionsWithoutClientSecret = {
14+
export type ExchangeDeviceCodeOAuthAppOptionsWithoutClientSecret = {
1515
clientType: "oauth-app";
1616
clientId: string;
1717
code: string;
1818
redirectUrl?: string;
1919
state?: string;
2020
request?: RequestInterface;
2121
};
22-
type OAuthAppOptions = OAuthAppOptionsWithoutClientSecret & {
22+
export type ExchangeDeviceCodeOAuthAppOptions = ExchangeDeviceCodeOAuthAppOptionsWithoutClientSecret & {
2323
clientSecret: string;
2424
};
25-
type GitHubAppOptionsWithoutClientSecret = {
25+
export type ExchangeDeviceCodeGitHubAppOptionsWithoutClientSecret = {
2626
clientType: "github-app";
2727
clientId: string;
2828
code: string;
@@ -31,7 +31,7 @@ type GitHubAppOptionsWithoutClientSecret = {
3131
request?: RequestInterface;
3232
};
3333

34-
type GitHubAppOptions = GitHubAppOptionsWithoutClientSecret & {
34+
export type ExchangeDeviceCodeGitHubAppOptions = ExchangeDeviceCodeGitHubAppOptionsWithoutClientSecret & {
3535
clientSecret: string;
3636
};
3737

@@ -48,78 +48,67 @@ type GitHubAppAuthenticationWithExpirationWithoutClientSecret = Omit<
4848
"clientSecret"
4949
>;
5050

51+
export type ExchangeDeviceCodeOAuthAppResponse = OctokitResponse<OAuthAppCreateTokenResponseData> & {
52+
authentication: OAuthAppAuthentication;
53+
};
54+
55+
export type ExchangeDeviceCodeOAuthAppResponseWithoutClientSecret = OctokitResponse<OAuthAppCreateTokenResponseData> & {
56+
authentication: OAuthAppAuthenticationWithoutClientSecret;
57+
};
58+
59+
export type ExchangeDeviceCodeGitHubAppResponse = OctokitResponse<
60+
| GitHubAppCreateTokenResponseData
61+
| GitHubAppCreateTokenWithExpirationResponseData
62+
> & {
63+
authentication:
64+
| GitHubAppAuthentication
65+
| GitHubAppAuthenticationWithExpiration;
66+
};
67+
68+
export type ExchangeDeviceCodeGitHubAppResponseWithoutClientSecret = OctokitResponse<
69+
| GitHubAppCreateTokenResponseData
70+
| GitHubAppCreateTokenWithExpirationResponseData
71+
> & {
72+
authentication:
73+
| GitHubAppAuthenticationWithoutClientSecret
74+
| GitHubAppAuthenticationWithExpirationWithoutClientSecret;
75+
};
76+
5177
/**
5278
* Exchange the code from GitHub's OAuth Web flow for OAuth Apps.
5379
*/
5480
export async function exchangeDeviceCode(
55-
options: OAuthAppOptions
56-
): Promise<
57-
OctokitResponse<OAuthAppCreateTokenResponseData> & {
58-
authentication: OAuthAppAuthentication;
59-
}
60-
>;
81+
options: ExchangeDeviceCodeOAuthAppOptions
82+
): Promise<ExchangeDeviceCodeOAuthAppResponse>;
6183

6284
/**
6385
* Exchange the code from GitHub's OAuth Web flow for OAuth Apps without clientSecret
6486
*/
6587
export async function exchangeDeviceCode(
66-
options: OAuthAppOptionsWithoutClientSecret
67-
): Promise<
68-
OctokitResponse<OAuthAppCreateTokenResponseData> & {
69-
authentication: OAuthAppAuthenticationWithoutClientSecret;
70-
}
71-
>;
88+
options: ExchangeDeviceCodeOAuthAppOptionsWithoutClientSecret
89+
): Promise<ExchangeDeviceCodeOAuthAppResponseWithoutClientSecret>;
7290

7391
/**
7492
* Exchange the code from GitHub's OAuth Web flow for GitHub Apps. `scopes` are not supported by GitHub Apps.
7593
*/
7694
export async function exchangeDeviceCode(
77-
options: GitHubAppOptions
78-
): Promise<
79-
OctokitResponse<
80-
| GitHubAppCreateTokenResponseData
81-
| GitHubAppCreateTokenWithExpirationResponseData
82-
> & {
83-
authentication:
84-
| GitHubAppAuthentication
85-
| GitHubAppAuthenticationWithExpiration;
86-
}
87-
>;
95+
options: ExchangeDeviceCodeGitHubAppOptions
96+
): Promise<ExchangeDeviceCodeGitHubAppResponse>;
8897

8998
/**
9099
* Exchange the code from GitHub's OAuth Web flow for GitHub Apps without using `clientSecret`. `scopes` are not supported by GitHub Apps.
91100
*/
92101
export async function exchangeDeviceCode(
93-
options: GitHubAppOptionsWithoutClientSecret
94-
): Promise<
95-
OctokitResponse<
96-
| GitHubAppCreateTokenResponseData
97-
| GitHubAppCreateTokenWithExpirationResponseData
98-
> & {
99-
authentication:
100-
| GitHubAppAuthenticationWithoutClientSecret
101-
| GitHubAppAuthenticationWithExpirationWithoutClientSecret;
102-
}
103-
>;
102+
options: ExchangeDeviceCodeGitHubAppOptionsWithoutClientSecret
103+
): Promise<ExchangeDeviceCodeGitHubAppResponseWithoutClientSecret>;
104104

105105
export async function exchangeDeviceCode(
106106
options:
107-
| OAuthAppOptions
108-
| GitHubAppOptions
109-
| OAuthAppOptionsWithoutClientSecret
110-
| GitHubAppOptionsWithoutClientSecret
111-
): Promise<
112-
OctokitResponse<
113-
| GitHubAppCreateTokenWithExpirationResponseData
114-
| GitHubAppCreateTokenResponseData
115-
| GitHubAppCreateTokenWithExpirationResponseData
116-
| OAuthAppAuthenticationWithoutClientSecret
117-
| GitHubAppAuthenticationWithoutClientSecret
118-
| GitHubAppAuthenticationWithExpirationWithoutClientSecret
119-
> & {
120-
authentication: any;
121-
}
122-
> {
107+
| ExchangeDeviceCodeOAuthAppOptions
108+
| ExchangeDeviceCodeGitHubAppOptions
109+
| ExchangeDeviceCodeOAuthAppOptionsWithoutClientSecret
110+
| ExchangeDeviceCodeGitHubAppOptionsWithoutClientSecret
111+
): Promise<any> {
123112
const request =
124113
options.request ||
125114
/* istanbul ignore next: we always pass a custom request in tests */

0 commit comments

Comments
 (0)