/** * fetch a URL. * Apart from the first parameter, this implements the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). * (Using this method rather than another enables outputting of curl commands with `-c` and a couple of defaults suitable for pentf). * * @example * ```javascript * const response = await fetch(config, 'https://example.org/json-api', { * method: 'POST', * headers: { * 'Content-Type': 'application/json', * }, * body: JSON.stringify({ * key: 'value', * }), * }); * assert.strictEqual(response.status, 200); * const data = await response.json(); * ``` * @param {*} config The pentf configuration object. * @param {string} url URL to fetch. * @param {RequestInit & { agent?: any, curl_include_headers?: boolean, curl_extra_options?: any, cookieJar?: any}} [init] fetch options, see [`RequestInit` in the Fetch Spec](https://fetch.spec.whatwg.org/#requestinit). * On top of the standard Fetch parameters, we support the following nonstandard parameters: * - `agent`: node [HTTP/HTTPS agent](https://nodejs.org/api/https.html#https_class_https_agent) * - `curl_include_headers`: boolean (default false) of whether to include `-k` in the curl output. * - `curl_extra_options`: List of extra options for the curl output. * - `cookieJar`: A [CookieJar object](https://github.com/salesforce/tough-cookie/blob/master/README.md#cookiejar) to use. * Pass in the string `'create'` to create a new one (returned as `response.cookieJar`). * The response will have a utility function `async getCookieValue(name)` to quickly retrieve a cookie value from the jar. * - `preferNativeFetch`: use native node.js fetch instead of node-fetch. (experimental, doesn't work with self-signed certificates) * - `timeout`: timeout in ms */ export function fetch(config: any, url: string, init?: (RequestInit & { agent?: any; curl_include_headers?: boolean | undefined; curl_extra_options?: any; cookieJar?: any; }) | undefined): any; /** * Modify fetch options for a request authenticated with a client-side TLS certificate. * * @example * ```javascript * const init = {method: 'POST', body: '{"something": "secret"}'}; * await setupTLSClientAuth(init, 'key.pem', 'cert.crt'); * const response = await fetch(config, 'https://protected.example.org/', init); * assert.equal(response.status, 200); // 401 = invalid certificate * ``` * @param {Object} fetchOptions The fetch request option object to modify. (`init` parameter in [[fetch]] above) * @param {string} keyFilename Name of the private key file in PEM format (e.g. beginning with `-----BEGIN RSA PRIVATE KEY-----`) * @param {string} certFilename Name of the certificate file in PEM format (beginning with `-----BEGIN CERTIFICATE-----`) * @param {boolean} rejectUnauthorized to validate the server's certificate, false (=default) to accept invalid certificates as well. */ export function setupTLSClientAuth(fetchOptions: Object, keyFilename: string, certFilename: string, rejectUnauthorized?: boolean): Promise;