-
Notifications
You must be signed in to change notification settings - Fork 13
/
types.ts
154 lines (132 loc) · 4.27 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import {
EndpointOptions,
RequestParameters,
Route,
RequestInterface,
OctokitResponse,
} from "@octokit/types";
import * as AuthOAuthUser from "@octokit/auth-oauth-user";
import * as DeviceTypes from "@octokit/auth-oauth-device";
export type ClientType = "oauth-app" | "github-app";
// STRATEGY OPTIONS
export type OAuthAppStrategyOptions = {
clientType?: "oauth-app";
clientId: string;
clientSecret: string;
request?: RequestInterface;
};
export type GitHubAppStrategyOptions = {
clientType: "github-app";
clientId: string;
clientSecret: string;
request?: RequestInterface;
};
// AUTH OPTIONS
export type AppAuthOptions = {
type: "oauth-app";
};
export type WebFlowAuthOptions = {
type: "oauth-user";
code: string;
redirectUrl?: string;
state?: string;
};
export type OAuthAppDeviceFlowAuthOptions = {
type: "oauth-user";
onVerification: DeviceTypes.OAuthAppStrategyOptions["onVerification"];
scopes?: string[];
};
export type GitHubAppDeviceFlowAuthOptions = {
type: "oauth-user";
onVerification: DeviceTypes.OAuthAppStrategyOptions["onVerification"];
};
// AUTHENTICATION OBJECT
export type AppAuthentication = {
type: "oauth-app";
clientId: string;
clientSecret: string;
clientType: ClientType;
headers: {
authorization: string;
};
};
export type OAuthAppUserAuthentication = AuthOAuthUser.OAuthAppAuthentication;
export type GitHubAppUserAuthentication = AuthOAuthUser.GitHubAppAuthentication;
export type GitHubAppUserAuthenticationWithExpiration = AuthOAuthUser.GitHubAppAuthenticationWithExpiration;
export type FactoryOAuthAppWebFlowOptions = OAuthAppStrategyOptions &
Omit<WebFlowAuthOptions, "type"> & { clientType: "oauth-app" };
export type FactoryOAuthAppDeviceFlowOptions = OAuthAppStrategyOptions &
Omit<OAuthAppDeviceFlowAuthOptions, "type"> & { clientType: "oauth-app" };
export type FactoryGitHubAppWebFlowOptions = GitHubAppStrategyOptions &
Omit<WebFlowAuthOptions, "type"> & { clientType: "github-app" };
export type FactoryGitHubAppDeviceFlowOptions = GitHubAppStrategyOptions &
Omit<GitHubAppDeviceFlowAuthOptions, "type"> & {
clientType: "github-app";
};
export interface FactoryOAuthAppWebFlow<T> {
(options: FactoryOAuthAppWebFlowOptions): T;
}
export interface FactoryOAuthAppDeviceFlow<T> {
(options: FactoryOAuthAppDeviceFlowOptions): T;
}
export interface FactoryGitHubWebFlow<T> {
(options: FactoryGitHubAppWebFlowOptions): T;
}
export interface FactoryGitHubDeviceFlow<T> {
(options: FactoryGitHubAppDeviceFlowOptions): T;
}
export interface OAuthAppAuthInterface {
// app auth
(options: AppAuthOptions): Promise<AppAuthentication>;
// user auth with `factory` option
<T = unknown>(
options: WebFlowAuthOptions & { factory: FactoryOAuthAppWebFlow<T> }
): Promise<T>;
<T = unknown>(
options: OAuthAppDeviceFlowAuthOptions & {
factory: FactoryOAuthAppDeviceFlow<T>;
}
): Promise<T>;
// user auth without `factory` option
(options: WebFlowAuthOptions): Promise<OAuthAppUserAuthentication>;
(options: OAuthAppDeviceFlowAuthOptions): Promise<OAuthAppUserAuthentication>;
hook(
request: RequestInterface,
route: Route | EndpointOptions,
parameters?: RequestParameters
): Promise<OctokitResponse<any>>;
}
export interface GitHubAuthInterface {
// app auth
(options?: AppAuthOptions): Promise<AppAuthentication>;
// user auth with `factory` option
<T = unknown>(
options: WebFlowAuthOptions & { factory: FactoryGitHubWebFlow<T> }
): Promise<T>;
<T = unknown>(
options: GitHubAppDeviceFlowAuthOptions & {
factory: FactoryGitHubDeviceFlow<T>;
}
): Promise<T>;
// user auth without `factory` option
(options?: WebFlowAuthOptions): Promise<
GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration
>;
(options?: GitHubAppDeviceFlowAuthOptions): Promise<
GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration
>;
hook(
request: RequestInterface,
route: Route | EndpointOptions,
parameters?: RequestParameters
): Promise<OctokitResponse<any>>;
}
// INTERNAL
export type OAuthAppState = OAuthAppStrategyOptions & {
clientType: "oauth-app";
request: RequestInterface;
};
export type GitHubAppState = OAuthAppStrategyOptions & {
clientType: "github-app";
request: RequestInterface;
};