diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 44aaea64..9d5d14e3 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- added the `gotOptions` property to the `BlockFrostAPI` class. This property can be passed during the initialization of the `BlockFrostAPI` object. For more details, refer to the [Got Options documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md). + ## [5.5.0] - 2023-12-20 diff --git a/README.md b/README.md index 3f3ddfdd..d55ca40a 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ const API = new Blockfrost.BlockFrostAPI({ - `debug` - `boolean`, whether to enable debug logging. It is also possible to enable it by setting environment variable `DEBUG` to `true` (optional, default `false`). - `customBackend` - `string`, option to set URL to a non-official backend (optional) - `version` - `number`, version of the Blockfrost API (optional, default `0`) +- `gotOptions` - Additional options to be passed to Got instance. For more details, refer to the [Got Options documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md). + ## Error handling diff --git a/src/types/index.ts b/src/types/index.ts index 4ce118ad..6c197cfd 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -10,6 +10,7 @@ import { MaxRedirectsError, UnsupportedProtocolError, RequiredRetryOptions, + Options as GotOptions, } from 'got'; import { RateLimiterConfig } from '../utils/limiter'; @@ -44,6 +45,7 @@ type AdditionalOptions = { userAgent?: string; requestTimeout?: number; retrySettings?: RequiredRetryOptions; + gotOptions?: GotOptions; // https://github.com/sindresorhus/got/blob/main/documentation/2-options.md }; export type Options = (OptionCombination1 | OptionCombination2) & @@ -61,6 +63,7 @@ export interface ValidatedOptions { projectId?: string; network?: BlockfrostNetwork; retrySettings?: RequiredRetryOptions; + gotOptions?: GotOptions; } export type HashOrNumber = string | number; diff --git a/src/utils/got.ts b/src/utils/got.ts index 103a9173..47e2e5b5 100644 --- a/src/utils/got.ts +++ b/src/utils/got.ts @@ -41,5 +41,7 @@ export const getInstance = ( timeout: { request: options.requestTimeout, }, + // https://github.com/sindresorhus/got/blob/main/documentation/2-options.md + ...options.gotOptions, }); }; diff --git a/src/utils/index.ts b/src/utils/index.ts index 6e941adf..318f55b4 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -60,6 +60,7 @@ export const validateOptions = (options?: Options): ValidatedOptions => { version: options.version || DEFAULT_API_VERSION, debug, http2: options.http2 ?? false, + gotOptions: options.gotOptions || undefined, requestTimeout: options.requestTimeout ?? 20000, // 20 seconds // see: https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md#retry retrySettings: options.retrySettings ?? {