UNPKG

5.13 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Agent } from "http";
3import { endpoint } from "@octokit/endpoint";
4export interface request {
5 /**
6 * Sends a request based on endpoint options
7 *
8 * @param {object} endpoint Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
9 */
10 <T = any>(options: Endpoint): Promise<OctokitResponse<T>>;
11 /**
12 * Sends a request based on endpoint options
13 *
14 * @param {string} route Request method + URL. Example: `'GET /orgs/:org'`
15 * @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
16 */
17 <T = any>(route: Route, parameters?: Parameters): Promise<OctokitResponse<T>>;
18 /**
19 * Returns a new `endpoint` with updated route and parameters
20 */
21 defaults: (newDefaults: Parameters) => request;
22 /**
23 * Octokit endpoint API, see {@link https://github.com/octokit/endpoint.js|@octokit/endpoint}
24 */
25 endpoint: typeof endpoint;
26}
27export declare type endpoint = typeof endpoint;
28/**
29 * Request method + URL. Example: `'GET /orgs/:org'`
30 */
31export declare type Route = string;
32/**
33 * Relative or absolute URL. Examples: `'/orgs/:org'`, `https://example.com/foo/bar`
34 */
35export declare type Url = string;
36/**
37 * Request method
38 */
39export declare type Method = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT";
40/**
41 * Endpoint parameters
42 */
43export declare type Parameters = {
44 /**
45 * Base URL to be used when a relative URL is passed, such as `/orgs/:org`.
46 * If `baseUrl` is `https://enterprise.acme-inc.com/api/v3`, then the request
47 * will be sent to `https://enterprise.acme-inc.com/api/v3/orgs/:org`.
48 */
49 baseUrl?: string;
50 /**
51 * HTTP headers. Use lowercase keys.
52 */
53 headers?: RequestHeaders;
54 /**
55 * Media type options, see {@link https://developer.github.com/v3/media/|GitHub Developer Guide}
56 */
57 mediaType?: {
58 /**
59 * `json` by default. Can be `raw`, `text`, `html`, `full`, `diff`, `patch`, `sha`, `base64`. Depending on endpoint
60 */
61 format?: string;
62 /**
63 * Custom media type names of {@link https://developer.github.com/v3/media/|API Previews} without the `-preview` suffix.
64 * Example for single preview: `['squirrel-girl']`.
65 * Example for multiple previews: `['squirrel-girl', 'mister-fantastic']`.
66 */
67 previews?: string[];
68 };
69 /**
70 * Pass custom meta information for the request. The `request` object will be returned as is.
71 */
72 request?: OctokitRequestOptions;
73 /**
74 * Any additional parameter will be passed as follows
75 * 1. URL parameter if `':parameter'` or `{parameter}` is part of `url`
76 * 2. Query parameter if `method` is `'GET'` or `'HEAD'`
77 * 3. Request body if `parameter` is `'data'`
78 * 4. JSON in the request body in the form of `body[parameter]` unless `parameter` key is `'data'`
79 */
80 [parameter: string]: any;
81};
82export declare type Endpoint = Parameters & {
83 method: Method;
84 url: Url;
85};
86export declare type Defaults = Parameters & {
87 method: Method;
88 baseUrl: string;
89 headers: RequestHeaders & {
90 accept: string;
91 "user-agent": string;
92 };
93 mediaType: {
94 format: string;
95 previews: string[];
96 };
97};
98export declare type OctokitResponse<T> = {
99 headers: ResponseHeaders;
100 /**
101 * http response code
102 */
103 status: number;
104 /**
105 * URL of response after all redirects
106 */
107 url: string;
108 /**
109 * This is the data you would see in https://developer.Octokit.com/v3/
110 */
111 data: T;
112};
113export declare type AnyResponse = OctokitResponse<any>;
114export declare type RequestHeaders = {
115 /**
116 * Avoid setting `accept`, use `mediaFormat.{format|previews}` instead.
117 */
118 accept?: string;
119 /**
120 * Use `authorization` to send authenticated request, remember `token ` / `bearer ` prefixes. Example: `token 1234567890abcdef1234567890abcdef12345678`
121 */
122 authorization?: string;
123 /**
124 * `user-agent` is set do a default and can be overwritten as needed.
125 */
126 "user-agent"?: string;
127 [header: string]: string | number | undefined;
128};
129export declare type ResponseHeaders = {
130 [header: string]: string;
131};
132export declare type Fetch = any;
133export declare type Signal = any;
134export declare type OctokitRequestOptions = {
135 /**
136 * Node only. Useful for custom proxy, certificate, or dns lookup.
137 */
138 agent?: Agent;
139 /**
140 * Custom replacement for built-in fetch method. Useful for testing or request hooks.
141 */
142 fetch?: Fetch;
143 /**
144 * Use an `AbortController` instance to cancel a request. In node you can only cancel streamed requests.
145 */
146 signal?: Signal;
147 /**
148 * Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). `options.request.signal` is recommended instead.
149 */
150 timeout?: number;
151 [option: string]: any;
152};