import type { Octokit } from "@octokit/core"; import type { OAuthAppUserAuthentication, GitHubAppUserAuthentication, GitHubAppUserAuthenticationWithExpiration } from "@octokit/auth-oauth-app"; import type { OAuthAppOctokit } from "./oauth-app-octokit.js"; export type ClientType = "oauth-app" | "github-app"; export type OAuthAppOctokitClassType = typeof OAuthAppOctokit; export type GithubAppUserAuthenticationWithOptionalExpiration = GitHubAppUserAuthentication & Partial; export type Scope = string; export type ClientId = string; export type ClientSecret = string; export type Token = string; export type EventName = "token" | "authorization"; export type ActionName = "created" | "reset" | "deleted" | "refreshed" | "scoped"; export type EventAndActionName = "token" | "token.created" | "token.reset" | "token.refreshed" | "token.scoped" | "token.deleted" | "authorization" | "authorization.deleted"; type CommonOptions = { clientId?: ClientId; clientSecret?: ClientSecret; allowSignup?: boolean; baseUrl?: string; redirectUrl?: string; log?: typeof console; Octokit?: TOctokit; }; export type Options = TClientType extends "oauth-app" ? CommonOptions & { clientType?: TClientType; defaultScopes?: Scope[]; } : CommonOptions & { clientType?: TClientType; }; export type ConstructorOptions> = TOptions & { clientId: ClientId; clientSecret: ClientSecret; }; export type OctokitTypeFromOptions> = TOptions["Octokit"] extends typeof Octokit ? InstanceType : Octokit; export type OctokitClassTypeFromOptions> = TOptions["Octokit"] extends typeof Octokit ? TOptions["Octokit"] : typeof Octokit; export type ClientTypeFromOptions> = TOptions["clientType"] extends "github-app" ? "github-app" : "oauth-app"; export type OctokitInstance = InstanceType; export type State = { clientType: ClientType; clientId: ClientId; clientSecret: ClientSecret; defaultScopes: Scope[]; allowSignup?: boolean | undefined; baseUrl?: string | undefined; redirectUrl?: string | undefined; log?: typeof console | undefined; Octokit: OAuthAppOctokitClassType; octokit: OctokitInstance; eventHandlers: { [key: string]: EventHandler>[]; }; }; export type EventHandlerContext> = ClientTypeFromOptions extends "oauth-app" ? { name: EventName; action: ActionName; token: Token; scopes?: Scope[]; octokit: OctokitTypeFromOptions; authentication?: OAuthAppUserAuthentication | GitHubAppUserAuthentication | GitHubAppUserAuthenticationWithExpiration; } : { name: EventName; action: ActionName; token: Token; octokit: OctokitTypeFromOptions; authentication?: GithubAppUserAuthenticationWithOptionalExpiration; }; export type EventHandler> = (context: EventHandlerContext) => void; export type AddEventHandler> = (eventName: EventAndActionName | EventAndActionName[], eventHandler: EventHandler) => void; export {};