diff --git a/.changeset/heavy-chairs-wash.md b/.changeset/heavy-chairs-wash.md new file mode 100644 index 00000000..9395f8a3 --- /dev/null +++ b/.changeset/heavy-chairs-wash.md @@ -0,0 +1,5 @@ +--- +'tuf-js': minor +--- + +Deprecates in `fetchRetries` config option in the `UpdaterOptions` interface in favor of the new `fetchRetry` option. diff --git a/packages/client/src/__tests__/updater.test.ts b/packages/client/src/__tests__/updater.test.ts index 5180eb49..2a253fe3 100644 --- a/packages/client/src/__tests__/updater.test.ts +++ b/packages/client/src/__tests__/updater.test.ts @@ -21,7 +21,7 @@ describe('Updater', () => { metadataBaseUrl: `${baseURL}/metadata`, targetBaseUrl: `${baseURL}/targets`, config: { - fetchRetries: 0, + fetchRetry: 0, fetchTimeout: 1000, }, }; diff --git a/packages/client/src/config.ts b/packages/client/src/config.ts index 6ed4deba..3946e9be 100644 --- a/packages/client/src/config.ts +++ b/packages/client/src/config.ts @@ -1,4 +1,20 @@ -export const defaultConfig = { +import type { MakeFetchHappenOptions } from 'make-fetch-happen'; + +export type Config = { + maxRootRotations: number; + maxDelegations: number; + rootMaxLength: number; + timestampMaxLength: number; + snapshotMaxLength: number; + targetsMaxLength: number; + prefixTargetsWithHash: boolean; + fetchTimeout: number; + // deprecated use fetchRetry instead + fetchRetries: number | undefined; + fetchRetry: MakeFetchHappenOptions['retry']; +}; + +export const defaultConfig: Config = { maxRootRotations: 32, maxDelegations: 32, rootMaxLength: 512000, //bytes @@ -7,7 +23,6 @@ export const defaultConfig = { targetsMaxLength: 5000000, // bytes prefixTargetsWithHash: true, fetchTimeout: 100000, // milliseconds - fetchRetries: 2, + fetchRetries: undefined, + fetchRetry: 2, }; - -export type Config = typeof defaultConfig; diff --git a/packages/client/src/fetcher.ts b/packages/client/src/fetcher.ts index 8b05aa35..3cd62dd2 100644 --- a/packages/client/src/fetcher.ts +++ b/packages/client/src/fetcher.ts @@ -6,6 +6,8 @@ import util from 'util'; import { DownloadHTTPError, DownloadLengthMismatchError } from './error'; import { withTempFile } from './utils/tmpfile'; +import type { MakeFetchHappenOptions } from 'make-fetch-happen'; + const log = debug('tuf:fetch'); type DownloadFileHandler = (file: string) => Promise; @@ -74,26 +76,28 @@ export abstract class BaseFetcher implements Fetcher { } } +type Retry = MakeFetchHappenOptions['retry']; + interface FetcherOptions { timeout?: number; - retries?: number; + retry?: Retry; } export class DefaultFetcher extends BaseFetcher { private timeout?: number; - private retries?: number; + private retry?: Retry; constructor(options: FetcherOptions = {}) { super(); this.timeout = options.timeout; - this.retries = options.retries; + this.retry = options.retry; } public override async fetch(url: string): Promise { log('GET %s', url); const response = await fetch(url, { timeout: this.timeout, - retry: this.retries, + retry: this.retry, }); if (!response.ok || !response?.body) { diff --git a/packages/client/src/updater.ts b/packages/client/src/updater.ts index f72a9db7..fe578c20 100644 --- a/packages/client/src/updater.ts +++ b/packages/client/src/updater.ts @@ -62,7 +62,7 @@ export class Updater { fetcher || new DefaultFetcher({ timeout: this.config.fetchTimeout, - retries: this.config.fetchRetries, + retry: this.config.fetchRetries ?? this.config.fetchRetry, }); }