Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
"homepage": "https://github.com/theupdateframework/tuf-js/tree/main/packages/client#readme",
"devDependencies": {
"@tufjs/repo-mock": "3.0.1",
"@types/debug": "^4.1.12",
"@types/make-fetch-happen": "^10.0.4"
"@types/debug": "^4.1.12"
},
"dependencies": {
"@tufjs/models": "3.0.1",
"debug": "^4.3.6",
"make-fetch-happen": "^14.0.2"
"debug": "^4.3.6"
},
"engines": {
"node": "^18.17.0 || >=20.5.0"
Expand Down
7 changes: 0 additions & 7 deletions packages/client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { MakeFetchHappenOptions } from 'make-fetch-happen';

export type Config = {
maxRootRotations: number;
maxDelegations: number;
Expand All @@ -9,9 +7,6 @@ export type Config = {
targetsMaxLength: number;
prefixTargetsWithHash: boolean;
fetchTimeout: number;
// deprecated use fetchRetry instead
fetchRetries: number | undefined;
fetchRetry: MakeFetchHappenOptions['retry'];
};

export const defaultConfig: Config = {
Expand All @@ -23,6 +18,4 @@ export const defaultConfig: Config = {
targetsMaxLength: 5000000, // bytes
prefixTargetsWithHash: true,
fetchTimeout: 100000, // milliseconds
fetchRetries: undefined,
fetchRetry: 2,
};
14 changes: 3 additions & 11 deletions packages/client/src/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import debug from 'debug';
import fs from 'fs';
import fetch from 'make-fetch-happen';
import stream from 'stream';
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<T> = (file: string) => Promise<T>;
Expand Down Expand Up @@ -77,35 +75,29 @@ export abstract class BaseFetcher implements Fetcher {
}
}

type Retry = MakeFetchHappenOptions['retry'];

interface FetcherOptions {
timeout?: number;
retry?: Retry;
}

export class DefaultFetcher extends BaseFetcher {
private timeout?: number;
private retry?: Retry;

constructor(options: FetcherOptions = {}) {
super();
this.timeout = options.timeout;
this.retry = options.retry;
}

public override async fetch(url: string): Promise<NodeJS.ReadableStream> {
log('GET %s', url);
const response = await fetch(url, {
timeout: this.timeout,
retry: this.retry,
signal: this.timeout && AbortSignal.timeout(this.timeout),
});

if (!response.ok || !response?.body) {
throw new DownloadHTTPError('Failed to download', response.status);
}

return response.body;
return stream.Readable.fromWeb(response.body);
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/client/src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class Updater {
fetcher ||
new DefaultFetcher({
timeout: this.config.fetchTimeout,
retry: this.config.fetchRetries ?? this.config.fetchRetry,
});
}

Expand Down
1 change: 0 additions & 1 deletion packages/client/tests/updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Updater', () => {
metadataBaseUrl: `${baseURL}/metadata`,
targetBaseUrl: `${baseURL}/targets`,
config: {
fetchRetry: 0,
fetchTimeout: 1000,
},
};
Expand Down