|
| 1 | +import { Agent } from "http"; |
| 2 | + |
1 | 3 | import { Octokit } from "."; |
2 | 4 |
|
3 | 5 | export type OctokitOptions = { |
| 6 | + request?: OctokitRequestOptions; |
4 | 7 | [option: string]: any; |
5 | 8 | }; |
6 | 9 |
|
7 | 10 | export type Plugin = (octokit: Octokit, options?: OctokitOptions) => void; |
| 11 | + |
| 12 | +// TODO: deduplicate |
| 13 | + |
| 14 | +/** |
| 15 | + * Endpoint parameters |
| 16 | + */ |
| 17 | +export type Parameters = { |
| 18 | + /** |
| 19 | + * Base URL to be used when a relative URL is passed, such as `/orgs/:org`. |
| 20 | + * If `baseUrl` is `https://enterprise.acme-inc.com/api/v3`, then the request |
| 21 | + * will be sent to `https://enterprise.acme-inc.com/api/v3/orgs/:org`. |
| 22 | + */ |
| 23 | + baseUrl?: string; |
| 24 | + |
| 25 | + /** |
| 26 | + * HTTP headers. Use lowercase keys. |
| 27 | + */ |
| 28 | + headers?: RequestHeaders; |
| 29 | + |
| 30 | + /** |
| 31 | + * Media type options, see {@link https://developer.github.com/v3/media/|GitHub Developer Guide} |
| 32 | + */ |
| 33 | + mediaType?: { |
| 34 | + /** |
| 35 | + * `json` by default. Can be `raw`, `text`, `html`, `full`, `diff`, `patch`, `sha`, `base64`. Depending on endpoint |
| 36 | + */ |
| 37 | + format?: string; |
| 38 | + |
| 39 | + /** |
| 40 | + * Custom media type names of {@link https://developer.github.com/v3/media/|API Previews} without the `-preview` suffix. |
| 41 | + * Example for single preview: `['squirrel-girl']`. |
| 42 | + * Example for multiple previews: `['squirrel-girl', 'mister-fantastic']`. |
| 43 | + */ |
| 44 | + previews?: string[]; |
| 45 | + }; |
| 46 | + |
| 47 | + /** |
| 48 | + * Pass custom meta information for the request. The `request` object will be returned as is. |
| 49 | + */ |
| 50 | + request?: OctokitRequestOptions; |
| 51 | + |
| 52 | + /** |
| 53 | + * Any additional parameter will be passed as follows |
| 54 | + * 1. URL parameter if `':parameter'` or `{parameter}` is part of `url` |
| 55 | + * 2. Query parameter if `method` is `'GET'` or `'HEAD'` |
| 56 | + * 3. Request body if `parameter` is `'data'` |
| 57 | + * 4. JSON in the request body in the form of `body[parameter]` unless `parameter` key is `'data'` |
| 58 | + */ |
| 59 | + [parameter: string]: any; |
| 60 | +}; |
| 61 | + |
| 62 | +export type RequestHeaders = { |
| 63 | + /** |
| 64 | + * Avoid setting `accept`, use `mediaFormat.{format|previews}` instead. |
| 65 | + */ |
| 66 | + accept?: string; |
| 67 | + /** |
| 68 | + * Use `authorization` to send authenticated request, remember `token ` / `bearer ` prefixes. Example: `token 1234567890abcdef1234567890abcdef12345678` |
| 69 | + */ |
| 70 | + authorization?: string; |
| 71 | + /** |
| 72 | + * `user-agent` is set do a default and can be overwritten as needed. |
| 73 | + */ |
| 74 | + "user-agent"?: string; |
| 75 | + |
| 76 | + [header: string]: string | number | undefined; |
| 77 | +}; |
| 78 | + |
| 79 | +export type Fetch = any; |
| 80 | +export type Signal = any; |
| 81 | + |
| 82 | +export type OctokitRequestOptions = { |
| 83 | + /** |
| 84 | + * Node only. Useful for custom proxy, certificate, or dns lookup. |
| 85 | + */ |
| 86 | + agent?: Agent; |
| 87 | + /** |
| 88 | + * Custom replacement for built-in fetch method. Useful for testing or request hooks. |
| 89 | + */ |
| 90 | + fetch?: Fetch; |
| 91 | + /** |
| 92 | + * Use an `AbortController` instance to cancel a request. In node you can only cancel streamed requests. |
| 93 | + */ |
| 94 | + signal?: Signal; |
| 95 | + /** |
| 96 | + * Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). `options.request.signal` is recommended instead. |
| 97 | + */ |
| 98 | + timeout?: number; |
| 99 | + |
| 100 | + [option: string]: any; |
| 101 | +}; |
0 commit comments