got 10.5.7 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/source/{calculate-retry-delay.d.ts → as-promise/calculate-retry-delay.d.ts} +0 -0
  2. package/dist/source/{calculate-retry-delay.js → as-promise/calculate-retry-delay.js} +6 -7
  3. package/dist/source/as-promise/core.d.ts +13 -0
  4. package/dist/source/as-promise/core.js +124 -0
  5. package/dist/source/as-promise/create-rejection.d.ts +2 -0
  6. package/dist/source/as-promise/create-rejection.js +30 -0
  7. package/dist/source/as-promise/index.d.ts +5 -0
  8. package/dist/source/as-promise/index.js +203 -0
  9. package/dist/source/as-promise/types.d.ts +77 -0
  10. package/dist/source/as-promise/types.js +27 -0
  11. package/dist/source/core/index.d.ts +272 -0
  12. package/dist/source/core/index.js +1091 -0
  13. package/dist/source/{utils → core/utils}/get-body-size.d.ts +0 -0
  14. package/dist/source/{utils → core/utils}/get-body-size.js +0 -0
  15. package/dist/source/core/utils/is-form-data.d.ts +8 -0
  16. package/dist/source/{utils → core/utils}/is-form-data.js +0 -0
  17. package/dist/source/core/utils/options-to-url.d.ts +15 -0
  18. package/dist/source/{utils → core/utils}/options-to-url.js +5 -34
  19. package/dist/source/core/utils/proxy-events.d.ts +3 -0
  20. package/dist/source/core/utils/proxy-events.js +17 -0
  21. package/dist/source/{utils → core/utils}/timed-out.d.ts +0 -0
  22. package/dist/source/{utils → core/utils}/timed-out.js +2 -5
  23. package/dist/source/{utils → core/utils}/unhandle.d.ts +1 -1
  24. package/dist/source/{utils → core/utils}/unhandle.js +0 -0
  25. package/dist/source/{utils → core/utils}/url-to-options.d.ts +0 -0
  26. package/dist/source/{utils → core/utils}/url-to-options.js +0 -0
  27. package/dist/source/core/utils/weakable-map.d.ts +8 -0
  28. package/dist/source/core/utils/weakable-map.js +29 -0
  29. package/dist/source/create.d.ts +3 -79
  30. package/dist/source/create.js +83 -39
  31. package/dist/source/index.d.ts +3 -6
  32. package/dist/source/index.js +13 -19
  33. package/dist/source/types.d.ts +84 -198
  34. package/dist/source/types.js +0 -1
  35. package/package.json +41 -37
  36. package/readme.md +211 -97
  37. package/dist/source/as-promise.d.ts +0 -3
  38. package/dist/source/as-promise.js +0 -152
  39. package/dist/source/as-stream.d.ts +0 -7
  40. package/dist/source/as-stream.js +0 -121
  41. package/dist/source/errors.d.ts +0 -41
  42. package/dist/source/errors.js +0 -103
  43. package/dist/source/get-response.d.ts +0 -6
  44. package/dist/source/get-response.js +0 -25
  45. package/dist/source/known-hook-events.d.ts +0 -88
  46. package/dist/source/known-hook-events.js +0 -11
  47. package/dist/source/normalize-arguments.d.ts +0 -19
  48. package/dist/source/normalize-arguments.js +0 -436
  49. package/dist/source/progress.d.ts +0 -4
  50. package/dist/source/progress.js +0 -40
  51. package/dist/source/request-as-event-emitter.d.ts +0 -12
  52. package/dist/source/request-as-event-emitter.js +0 -284
  53. package/dist/source/utils/dynamic-require.d.ts +0 -3
  54. package/dist/source/utils/dynamic-require.js +0 -4
  55. package/dist/source/utils/is-form-data.d.ts +0 -3
  56. package/dist/source/utils/merge.d.ts +0 -6
  57. package/dist/source/utils/merge.js +0 -35
  58. package/dist/source/utils/options-to-url.d.ts +0 -19
  59. package/dist/source/utils/supports-brotli.d.ts +0 -2
  60. package/dist/source/utils/supports-brotli.js +0 -4
@@ -1,152 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const EventEmitter = require("events");
4
- const getStream = require("get-stream");
5
- const PCancelable = require("p-cancelable");
6
- const is_1 = require("@sindresorhus/is");
7
- const errors_1 = require("./errors");
8
- const normalize_arguments_1 = require("./normalize-arguments");
9
- const request_as_event_emitter_1 = require("./request-as-event-emitter");
10
- const parseBody = (body, responseType, encoding) => {
11
- if (responseType === 'json') {
12
- return body.length === 0 ? '' : JSON.parse(body.toString());
13
- }
14
- if (responseType === 'buffer') {
15
- return Buffer.from(body);
16
- }
17
- if (responseType === 'text') {
18
- return body.toString(encoding);
19
- }
20
- throw new TypeError(`Unknown body type '${responseType}'`);
21
- };
22
- function createRejection(error) {
23
- const promise = Promise.reject(error);
24
- const returnPromise = () => promise;
25
- promise.json = returnPromise;
26
- promise.text = returnPromise;
27
- promise.buffer = returnPromise;
28
- promise.on = returnPromise;
29
- return promise;
30
- }
31
- exports.createRejection = createRejection;
32
- function asPromise(options) {
33
- const proxy = new EventEmitter();
34
- let body;
35
- const promise = new PCancelable((resolve, reject, onCancel) => {
36
- const emitter = request_as_event_emitter_1.default(options);
37
- onCancel(emitter.abort);
38
- const emitError = async (error) => {
39
- try {
40
- for (const hook of options.hooks.beforeError) {
41
- // eslint-disable-next-line no-await-in-loop
42
- error = await hook(error);
43
- }
44
- reject(error);
45
- }
46
- catch (error_) {
47
- reject(error_);
48
- }
49
- };
50
- emitter.on('response', async (response) => {
51
- var _a;
52
- proxy.emit('response', response);
53
- // Download body
54
- try {
55
- body = await getStream.buffer(response, { encoding: 'binary' });
56
- }
57
- catch (error) {
58
- emitError(new errors_1.ReadError(error, options));
59
- return;
60
- }
61
- if ((_a = response.req) === null || _a === void 0 ? void 0 : _a.aborted) {
62
- // Canceled while downloading - will throw a `CancelError` or `TimeoutError` error
63
- return;
64
- }
65
- const isOk = () => {
66
- const { statusCode } = response;
67
- const limitStatusCode = options.followRedirect ? 299 : 399;
68
- return (statusCode >= 200 && statusCode <= limitStatusCode) || statusCode === 304;
69
- };
70
- // Parse body
71
- try {
72
- response.body = parseBody(body, options.responseType, options.encoding);
73
- }
74
- catch (error) {
75
- // Fall back to `utf8`
76
- response.body = body.toString();
77
- if (isOk()) {
78
- const parseError = new errors_1.ParseError(error, response, options);
79
- emitError(parseError);
80
- return;
81
- }
82
- }
83
- try {
84
- for (const [index, hook] of options.hooks.afterResponse.entries()) {
85
- // @ts-ignore TS doesn't notice that CancelableRequest is a Promise
86
- // eslint-disable-next-line no-await-in-loop
87
- response = await hook(response, async (updatedOptions) => {
88
- const typedOptions = normalize_arguments_1.normalizeArguments(normalize_arguments_1.mergeOptions(options, {
89
- ...updatedOptions,
90
- retry: {
91
- calculateDelay: () => 0
92
- },
93
- throwHttpErrors: false,
94
- resolveBodyOnly: false
95
- }));
96
- // Remove any further hooks for that request, because we'll call them anyway.
97
- // The loop continues. We don't want duplicates (asPromise recursion).
98
- typedOptions.hooks.afterResponse = options.hooks.afterResponse.slice(0, index);
99
- for (const hook of options.hooks.beforeRetry) {
100
- // eslint-disable-next-line no-await-in-loop
101
- await hook(typedOptions);
102
- }
103
- const promise = asPromise(typedOptions);
104
- onCancel(() => {
105
- promise.catch(() => { });
106
- promise.cancel();
107
- });
108
- return promise;
109
- });
110
- }
111
- }
112
- catch (error) {
113
- emitError(error);
114
- return;
115
- }
116
- // Check for HTTP error codes
117
- if (!isOk()) {
118
- const error = new errors_1.HTTPError(response, options);
119
- if (emitter.retry(error)) {
120
- return;
121
- }
122
- if (options.throwHttpErrors) {
123
- emitError(error);
124
- return;
125
- }
126
- }
127
- resolve(options.resolveBodyOnly ? response.body : response);
128
- });
129
- emitter.once('error', reject);
130
- request_as_event_emitter_1.proxyEvents(proxy, emitter);
131
- });
132
- promise.on = (name, fn) => {
133
- proxy.on(name, fn);
134
- return promise;
135
- };
136
- const shortcut = (responseType) => {
137
- // eslint-disable-next-line promise/prefer-await-to-then
138
- const newPromise = promise.then(() => parseBody(body, responseType, options.encoding));
139
- Object.defineProperties(newPromise, Object.getOwnPropertyDescriptors(promise));
140
- return newPromise;
141
- };
142
- promise.json = () => {
143
- if (is_1.default.undefined(body) && is_1.default.undefined(options.headers.accept)) {
144
- options.headers.accept = 'application/json';
145
- }
146
- return shortcut('json');
147
- };
148
- promise.buffer = () => shortcut('buffer');
149
- promise.text = () => shortcut('text');
150
- return promise;
151
- }
152
- exports.default = asPromise;
@@ -1,7 +0,0 @@
1
- /// <reference types="node" />
2
- import { Duplex as DuplexStream } from 'stream';
3
- import { GotEvents, NormalizedOptions } from './types';
4
- export declare class ProxyStream<T = unknown> extends DuplexStream implements GotEvents<ProxyStream<T>> {
5
- isFromCache?: boolean;
6
- }
7
- export default function asStream<T>(options: NormalizedOptions): ProxyStream<T>;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const duplexer3 = require("duplexer3");
4
- const http_1 = require("http");
5
- const stream_1 = require("stream");
6
- const errors_1 = require("./errors");
7
- const request_as_event_emitter_1 = require("./request-as-event-emitter");
8
- class ProxyStream extends stream_1.Duplex {
9
- }
10
- exports.ProxyStream = ProxyStream;
11
- function asStream(options) {
12
- const input = new stream_1.PassThrough();
13
- const output = new stream_1.PassThrough();
14
- const proxy = duplexer3(input, output);
15
- const piped = new Set();
16
- let isFinished = false;
17
- options.retry.calculateDelay = () => 0;
18
- if (options.body || options.json || options.form) {
19
- proxy.write = () => {
20
- proxy.destroy();
21
- throw new Error('Got\'s stream is not writable when the `body`, `json` or `form` option is used');
22
- };
23
- }
24
- else if (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH') {
25
- options.body = input;
26
- }
27
- else {
28
- proxy.write = () => {
29
- proxy.destroy();
30
- throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
31
- };
32
- }
33
- const emitter = request_as_event_emitter_1.default(options);
34
- const emitError = async (error) => {
35
- try {
36
- for (const hook of options.hooks.beforeError) {
37
- // eslint-disable-next-line no-await-in-loop
38
- error = await hook(error);
39
- }
40
- proxy.emit('error', error);
41
- }
42
- catch (error_) {
43
- proxy.emit('error', error_);
44
- }
45
- };
46
- // Cancels the request
47
- proxy._destroy = (error, callback) => {
48
- callback(error);
49
- emitter.abort();
50
- };
51
- emitter.on('response', (response) => {
52
- const { statusCode, isFromCache } = response;
53
- proxy.isFromCache = isFromCache;
54
- if (options.throwHttpErrors && statusCode !== 304 && (statusCode < 200 || statusCode > 299)) {
55
- emitError(new errors_1.HTTPError(response, options));
56
- return;
57
- }
58
- {
59
- const read = proxy._read;
60
- proxy._read = (...args) => {
61
- isFinished = true;
62
- proxy._read = read;
63
- return read.apply(proxy, args);
64
- };
65
- }
66
- if (options.encoding) {
67
- proxy.setEncoding(options.encoding);
68
- }
69
- // We cannot use `stream.pipeline(...)` here,
70
- // because if we did then `output` would throw
71
- // the original error before throwing `ReadError`.
72
- response.pipe(output);
73
- response.once('error', error => {
74
- emitError(new errors_1.ReadError(error, options));
75
- });
76
- for (const destination of piped) {
77
- if (destination.headersSent) {
78
- continue;
79
- }
80
- for (const [key, value] of Object.entries(response.headers)) {
81
- // Got gives *decompressed* data. Overriding `content-encoding` header would result in an error.
82
- // It's not possible to decompress already decompressed data, is it?
83
- const isAllowed = options.decompress ? key !== 'content-encoding' : true;
84
- if (isAllowed) {
85
- destination.setHeader(key, value);
86
- }
87
- }
88
- destination.statusCode = response.statusCode;
89
- }
90
- proxy.emit('response', response);
91
- });
92
- request_as_event_emitter_1.proxyEvents(proxy, emitter);
93
- emitter.on('error', (error) => proxy.emit('error', error));
94
- const pipe = proxy.pipe.bind(proxy);
95
- const unpipe = proxy.unpipe.bind(proxy);
96
- proxy.pipe = (destination, options) => {
97
- if (isFinished) {
98
- throw new Error('Failed to pipe. The response has been emitted already.');
99
- }
100
- pipe(destination, options);
101
- if (destination instanceof http_1.ServerResponse) {
102
- piped.add(destination);
103
- }
104
- return destination;
105
- };
106
- proxy.unpipe = stream => {
107
- piped.delete(stream);
108
- return unpipe(stream);
109
- };
110
- proxy.on('pipe', source => {
111
- if (source instanceof http_1.IncomingMessage) {
112
- options.headers = {
113
- ...source.headers,
114
- ...options.headers
115
- };
116
- }
117
- });
118
- proxy.isFromCache = undefined;
119
- return proxy;
120
- }
121
- exports.default = asStream;
@@ -1,41 +0,0 @@
1
- import { Timings } from '@szmarczak/http-timer';
2
- import { TimeoutError as TimedOutError } from './utils/timed-out';
3
- import { Response, NormalizedOptions } from './types';
4
- export declare class GotError extends Error {
5
- code?: string;
6
- stack: string;
7
- readonly options: NormalizedOptions;
8
- constructor(message: string, error: Partial<Error & {
9
- code?: string;
10
- }>, options: NormalizedOptions);
11
- }
12
- export declare class CacheError extends GotError {
13
- constructor(error: Error, options: NormalizedOptions);
14
- }
15
- export declare class RequestError extends GotError {
16
- constructor(error: Error, options: NormalizedOptions);
17
- }
18
- export declare class ReadError extends GotError {
19
- constructor(error: Error, options: NormalizedOptions);
20
- }
21
- export declare class ParseError extends GotError {
22
- readonly response: Response;
23
- constructor(error: Error, response: Response, options: NormalizedOptions);
24
- }
25
- export declare class HTTPError extends GotError {
26
- readonly response: Response;
27
- constructor(response: Response, options: NormalizedOptions);
28
- }
29
- export declare class MaxRedirectsError extends GotError {
30
- readonly response: Response;
31
- constructor(response: Response, maxRedirects: number, options: NormalizedOptions);
32
- }
33
- export declare class UnsupportedProtocolError extends GotError {
34
- constructor(options: NormalizedOptions);
35
- }
36
- export declare class TimeoutError extends GotError {
37
- timings: Timings;
38
- event: string;
39
- constructor(error: TimedOutError, timings: Timings, options: NormalizedOptions);
40
- }
41
- export { CancelError } from 'p-cancelable';
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const is_1 = require("@sindresorhus/is");
4
- class GotError extends Error {
5
- constructor(message, error, options) {
6
- super(message);
7
- Error.captureStackTrace(this, this.constructor);
8
- this.name = 'GotError';
9
- if (!is_1.default.undefined(error.code)) {
10
- this.code = error.code;
11
- }
12
- Object.defineProperty(this, 'options', {
13
- // This fails because of TS 3.7.2 useDefineForClassFields
14
- // Ref: https://github.com/microsoft/TypeScript/issues/34972
15
- enumerable: false,
16
- value: options
17
- });
18
- // Recover the original stacktrace
19
- if (!is_1.default.undefined(error.stack)) {
20
- const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
21
- const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').reverse();
22
- const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').reverse();
23
- // Remove duplicated traces
24
- while (errorStackTrace.length !== 0 && errorStackTrace[0] === thisStackTrace[0]) {
25
- thisStackTrace.shift();
26
- }
27
- this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.reverse().join('\n')}${errorStackTrace.reverse().join('\n')}`;
28
- }
29
- }
30
- }
31
- exports.GotError = GotError;
32
- class CacheError extends GotError {
33
- constructor(error, options) {
34
- super(error.message, error, options);
35
- this.name = 'CacheError';
36
- }
37
- }
38
- exports.CacheError = CacheError;
39
- class RequestError extends GotError {
40
- constructor(error, options) {
41
- super(error.message, error, options);
42
- this.name = 'RequestError';
43
- }
44
- }
45
- exports.RequestError = RequestError;
46
- class ReadError extends GotError {
47
- constructor(error, options) {
48
- super(error.message, error, options);
49
- this.name = 'ReadError';
50
- }
51
- }
52
- exports.ReadError = ReadError;
53
- class ParseError extends GotError {
54
- constructor(error, response, options) {
55
- super(`${error.message} in "${options.url.toString()}"`, error, options);
56
- this.name = 'ParseError';
57
- Object.defineProperty(this, 'response', {
58
- enumerable: false,
59
- value: response
60
- });
61
- }
62
- }
63
- exports.ParseError = ParseError;
64
- class HTTPError extends GotError {
65
- constructor(response, options) {
66
- super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, options);
67
- this.name = 'HTTPError';
68
- Object.defineProperty(this, 'response', {
69
- enumerable: false,
70
- value: response
71
- });
72
- }
73
- }
74
- exports.HTTPError = HTTPError;
75
- class MaxRedirectsError extends GotError {
76
- constructor(response, maxRedirects, options) {
77
- super(`Redirected ${maxRedirects} times. Aborting.`, {}, options);
78
- this.name = 'MaxRedirectsError';
79
- Object.defineProperty(this, 'response', {
80
- enumerable: false,
81
- value: response
82
- });
83
- }
84
- }
85
- exports.MaxRedirectsError = MaxRedirectsError;
86
- class UnsupportedProtocolError extends GotError {
87
- constructor(options) {
88
- super(`Unsupported protocol "${options.url.protocol}"`, {}, options);
89
- this.name = 'UnsupportedProtocolError';
90
- }
91
- }
92
- exports.UnsupportedProtocolError = UnsupportedProtocolError;
93
- class TimeoutError extends GotError {
94
- constructor(error, timings, options) {
95
- super(error.message, error, options);
96
- this.name = 'TimeoutError';
97
- this.event = error.event;
98
- this.timings = timings;
99
- }
100
- }
101
- exports.TimeoutError = TimeoutError;
102
- var p_cancelable_1 = require("p-cancelable");
103
- exports.CancelError = p_cancelable_1.CancelError;
@@ -1,6 +0,0 @@
1
- /// <reference types="node" />
2
- import EventEmitter = require('events');
3
- import { IncomingMessage } from 'http';
4
- import { NormalizedOptions } from './types';
5
- declare const _default: (response: IncomingMessage, options: NormalizedOptions, emitter: EventEmitter) => Promise<void>;
6
- export default _default;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const decompressResponse = require("decompress-response");
4
- const mimicResponse = require("mimic-response");
5
- const stream = require("stream");
6
- const util_1 = require("util");
7
- const progress_1 = require("./progress");
8
- const pipeline = util_1.promisify(stream.pipeline);
9
- exports.default = async (response, options, emitter) => {
10
- var _a;
11
- const downloadBodySize = Number(response.headers['content-length']) || undefined;
12
- const progressStream = progress_1.createProgressStream('downloadProgress', emitter, downloadBodySize);
13
- mimicResponse(response, progressStream);
14
- const newResponse = (options.decompress &&
15
- options.method !== 'HEAD' ? decompressResponse(progressStream) : progressStream);
16
- if (!options.decompress && ['gzip', 'deflate', 'br'].includes((_a = newResponse.headers['content-encoding'], (_a !== null && _a !== void 0 ? _a : '')))) {
17
- options.responseType = 'buffer';
18
- }
19
- emitter.emit('response', newResponse);
20
- return pipeline(response, progressStream).catch(error => {
21
- if (error.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
22
- throw error;
23
- }
24
- });
25
- };
@@ -1,88 +0,0 @@
1
- import { CancelableRequest, GeneralError, NormalizedOptions, Options, Response } from './types';
2
- /**
3
- Called with plain request options, right before their normalization. This is especially useful in conjunction with `got.extend()` when the input needs custom handling.
4
-
5
- **Note:** This hook must be synchronous.
6
-
7
- @see [Request migration guide](https://github.com/sindresorhus/got/blob/master/migration-guides.md#breaking-changes) for an example.
8
- */
9
- export declare type InitHook = (options: Options) => void;
10
- /**
11
- Called with normalized [request options](https://github.com/sindresorhus/got#options). Got will make no further changes to the request before it is sent (except the body serialization). This is especially useful in conjunction with [`got.extend()`](https://github.com/sindresorhus/got#instances) when you want to create an API client that, for example, uses HMAC-signing.
12
-
13
- @see [AWS section](https://github.com/sindresorhus/got#aws) for an example.
14
- */
15
- export declare type BeforeRequestHook = (options: NormalizedOptions) => void | Promise<void>;
16
- /**
17
- Called with normalized [request options](https://github.com/sindresorhus/got#options). Got will make no further changes to the request. This is especially useful when you want to avoid dead sites.
18
- */
19
- export declare type BeforeRedirectHook = (options: NormalizedOptions, response: Response) => void | Promise<void>;
20
- /**
21
- Called with normalized [request options](https://github.com/sindresorhus/got#options), the error and the retry count. Got will make no further changes to the request. This is especially useful when some extra work is required before the next try.
22
- */
23
- export declare type BeforeRetryHook = (options: NormalizedOptions, error?: GeneralError, retryCount?: number) => void | Promise<void>;
24
- /**
25
- Called with an `Error` instance. The error is passed to the hook right before it's thrown. This is especially useful when you want to have more detailed errors.
26
-
27
- **Note:** Errors thrown while normalizing input options are thrown directly and not part of this hook.
28
- */
29
- export declare type BeforeErrorHook = <ErrorLike extends GeneralError>(error: ErrorLike) => GeneralError | Promise<GeneralError>;
30
- /**
31
- Called with [response object](https://github.com/sindresorhus/got#response) and a retry function.
32
-
33
- Each function should return the response. This is especially useful when you want to refresh an access token.
34
- */
35
- export declare type AfterResponseHook = (response: Response, retryWithMergedOptions: (options: Options) => CancelableRequest<Response>) => Response | CancelableRequest<Response> | Promise<Response | CancelableRequest<Response>>;
36
- export declare type HookType = BeforeErrorHook | InitHook | BeforeRequestHook | BeforeRedirectHook | BeforeRetryHook | AfterResponseHook;
37
- /**
38
- Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.
39
- */
40
- export interface Hooks {
41
- /**
42
- Called with plain request options, right before their normalization. This is especially useful in conjunction with `got.extend()` when the input needs custom handling.
43
-
44
- **Note:** This hook must be synchronous.
45
-
46
- @see [Request migration guide](https://github.com/sindresorhus/got/blob/master/migration-guides.md#breaking-changes) for an example.
47
- @default []
48
- */
49
- init?: InitHook[];
50
- /**
51
- Called with normalized [request options](https://github.com/sindresorhus/got#options). Got will make no further changes to the request before it is sent (except the body serialization). This is especially useful in conjunction with [`got.extend()`](https://github.com/sindresorhus/got#instances) when you want to create an API client that, for example, uses HMAC-signing.
52
-
53
- @see [AWS section](https://github.com/sindresorhus/got#aws) for an example.
54
- @default []
55
- */
56
- beforeRequest?: BeforeRequestHook[];
57
- /**
58
- Called with normalized [request options](https://github.com/sindresorhus/got#options). Got will make no further changes to the request. This is especially useful when you want to avoid dead sites.
59
-
60
- @default []
61
- */
62
- beforeRedirect?: BeforeRedirectHook[];
63
- /**
64
- Called with normalized [request options](https://github.com/sindresorhus/got#options), the error and the retry count. Got will make no further changes to the request. This is especially useful when some extra work is required before the next try.
65
-
66
- @default []
67
- */
68
- beforeRetry?: BeforeRetryHook[];
69
- /**
70
- Called with an `Error` instance. The error is passed to the hook right before it's thrown. This is especially useful when you want to have more detailed errors.
71
-
72
- **Note:** Errors thrown while normalizing input options are thrown directly and not part of this hook.
73
-
74
- @default []
75
- */
76
- beforeError?: BeforeErrorHook[];
77
- /**
78
- Called with [response object](https://github.com/sindresorhus/got#response) and a retry function.
79
-
80
- Each function should return the response. This is especially useful when you want to refresh an access token.
81
-
82
- @default []
83
- */
84
- afterResponse?: AfterResponseHook[];
85
- }
86
- export declare type HookEvent = keyof Hooks;
87
- declare const knownHookEvents: readonly HookEvent[];
88
- export default knownHookEvents;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const knownHookEvents = [
4
- 'beforeError',
5
- 'init',
6
- 'beforeRequest',
7
- 'beforeRedirect',
8
- 'beforeRetry',
9
- 'afterResponse'
10
- ];
11
- exports.default = knownHookEvents;
@@ -1,19 +0,0 @@
1
- /// <reference types="node" />
2
- import http = require('http');
3
- import https = require('https');
4
- import stream = require('stream');
5
- import { Merge } from 'type-fest';
6
- import { Defaults, NormalizedOptions, RequestFunction, URLOrOptions, requestSymbol } from './types';
7
- export declare const preNormalizeArguments: (options: Merge<https.RequestOptions, Merge<import("./types").GotOptions, import("./utils/options-to-url").URLOptions>>, defaults?: NormalizedOptions | undefined) => NormalizedOptions;
8
- export declare const mergeOptions: (...sources: Merge<https.RequestOptions, Merge<import("./types").GotOptions, import("./utils/options-to-url").URLOptions>>[]) => NormalizedOptions;
9
- export declare const normalizeArguments: (url: URLOrOptions, options?: Merge<https.RequestOptions, Merge<import("./types").GotOptions, import("./utils/options-to-url").URLOptions>> | undefined, defaults?: Defaults | undefined) => NormalizedOptions;
10
- export declare type NormalizedRequestArguments = Merge<https.RequestOptions, {
11
- body?: stream.Readable;
12
- [requestSymbol]: RequestFunction;
13
- url: Pick<NormalizedOptions, 'url'>;
14
- }>;
15
- export declare const normalizeRequestArguments: (options: NormalizedOptions) => Promise<Merge<https.RequestOptions, {
16
- body?: stream.Readable | undefined;
17
- url: Pick<NormalizedOptions, "url">;
18
- [requestSymbol]: typeof http.request;
19
- }>>;