import type { StrictUnion } from 'simplytyped'; /** If the variable `GITHUB_API_URL` or `GITHUB_API` exists, use that, otherwise use the value `https://api.github.com`. */ declare type GitHubApiUrl = StrictUnion<{ /** https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables */ GITHUB_API_URL: string; } | { /** https://github.com/search?l=JavaScript&q=GITHUB_API&type=Code */ GITHUB_API: string; }>; /** * If the variable `GITHUB_ACCESS_TOKEN` or `GITHUB_TOKEN` exists, use that according to: * https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter */ declare type GitHubToken = StrictUnion<{ /** https://github.com/search?q=GITHUB_ACCESS_TOKEN&type=code */ GITHUB_ACCESS_TOKEN: string; } | { /** https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret */ GITHUB_TOKEN: string; }>; /** * If the variables `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` exist, use that according to: * https://developer.github.com/v3/#oauth2-keysecret */ interface GitHubClient { GITHUB_CLIENT_ID: string; GITHUB_CLIENT_SECRET: string; } /** * Provide `GITHUB_ACCESS_TOKEN` or `GITHUB_TOKEN`, * or a combination of `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`, * optionally with `GITHUB_ACCESS_TOKEN` or `GITHUB_TOKEN`. * https://developer.github.com/v3/#authentication */ export declare type GitHubCredentials = StrictUnion & Partial; /** * Check whether or not sufficient GitHub credentials were supplied. * @returns `true` if valid * @throws if invalid */ export declare function validate(credentials: GitHubCredentials): boolean; /** * Get the desired GitHub Access Token from the credentials. * You probably want to use {@link fetch} directly, instead of going through this method. */ export declare function getAccessToken(credentials: GitHubCredentials): string | null; /** * Get the GitHub Authorization Search Params. * You probably want to use {@link fetch} directly, instead of going through this method. * @param credentials The params to use for the authorization variables. * @param params If you wish to set the params on an existing URLSearchParams instance, then provide it here. * @returns The search params that you should append to your github API request url. * @throws If no valid GitHub Authorization was provided. */ export declare function getSearchParams(credentials: GitHubCredentials, params?: URLSearchParams): URLSearchParams; /** * Remove any GitHub Credentials from a URL Search Params instance. * You probably want to use {@link fetch} directly, instead of going through this method. */ export declare function removeSearchParams(params?: URLSearchParams): URLSearchParams; /** * Redact any GitHub Credentials from a URL string. * You probably want to use {@link fetch} directly, instead of going through this method. * @param value The string to redact credentials from. * @returns The string with the credentials redacted. */ export declare function redactSearchParams(value: string): string; /** * Get the GitHub Authorization as a Query String. * You probably want to use {@link getURL} directly, instead of going through this method. */ export declare function getQueryString(credentials: GitHubCredentials): string; /** * Get the GitHub Authorization Header. * Use as the `Authorization` header within {@link fetch} calls. * You probably want to use {@link getHeaders} or {@link fetch} directly, instead of going through this method. * @throws If no valid GitHub Authorization was provided. */ export declare function getAuthHeader(credentials: GitHubCredentials): string; /** * Get the headers to attach to the request to the GitHub API. * Use as the headers object within {@link fetch} calls. * You probably want to use {@link fetch} directly, instead of going through this method. */ export declare function getHeaders(credentials: GitHubCredentials, headers?: Record): { Accept: string; Authorization: string; }; /** * Remove any GitHub Credentials from a Headers instance. * You probably want to use {@link fetch} directly, instead of going through this method. */ export declare function removeHeaders(headers: Record): Record; /** * Get the desired Github API URL, using {@link removeSearchParams}.to ensure there are no credentials. * As this URL does not include credentials, use with {@link getAuthHeader} to authorize correctly. * Otherwise use {@link getCredentialedURL} to get a credentialed URL. * You probably want to use {@link fetch} directly, instead of going through this method. * If the credentials property is nullish, then the environment variables are attempted. */ export declare function getURL(props?: { credentials?: GitHubCredentials; url?: string; pathname?: string; searchParams?: URLSearchParams | Record; }): URL; /** * Get the credentialed GitHub API URL instance. * Uses {@link getURL} to get the URL, then uses {@link getSearchParams} to add the credentials. * You probably want to use {@link fetch} directly, instead of going through this method. * If the credentials property is nullish, then the environment variables are attempted. */ export declare function getCredentialedURL(props?: { credentials?: GitHubCredentials; url?: string; pathname?: string; searchParams?: URLSearchParams | Record; }): URL; /** * Fetches a GitHub API response via secure headers authorization. * Uses {@link getURL} to get the URL, then uses {@link getHeaders} to add the credentials. * This is probably the method you want to use. * If the credentials property is nullish, then the environment variables are attempted. */ export declare function fetch(props?: { credentials?: GitHubCredentials; url?: string; pathname?: string; searchParams?: URLSearchParams | Record; headers?: Record; }): Promise; export {}; //# sourceMappingURL=index.d.ts.map