Skip to content

Commit

Permalink
feat: gotOptions to override default Got configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Jul 17, 2024
1 parent 0be1e0c commit a1b736b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
MaxRedirectsError,
UnsupportedProtocolError,
RequiredRetryOptions,
Options as GotOptions,
} from 'got';
import { RateLimiterConfig } from '../utils/limiter';

Expand Down Expand Up @@ -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) &
Expand All @@ -61,6 +63,7 @@ export interface ValidatedOptions {
projectId?: string;
network?: BlockfrostNetwork;
retrySettings?: RequiredRetryOptions;
gotOptions?: GotOptions;
}

export type HashOrNumber = string | number;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/got.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ export const getInstance = (
timeout: {
request: options.requestTimeout,
},
// https://github.com/sindresorhus/got/blob/main/documentation/2-options.md
...options.gotOptions,
});
};
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? {
Expand Down

0 comments on commit a1b736b

Please sign in to comment.