-
Notifications
You must be signed in to change notification settings - Fork 71
feat!: replace make-fetch-happen with ky and refresh tests/deps #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gastonfournier
wants to merge
22
commits into
main
Choose a base branch
from
ky-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0048dc6
feat: replace make-fetch-happen with ky and refresh tests/deps
gastonfournier 7e5149b
Revert unnecessary changes
gastonfournier 09c2cf5
chore: break support with node 16 and include node LTS: 24
gastonfournier 4b527b2
feat: replace make-fetch-happen with ky and refresh tests/deps
gastonfournier dd74dcb
Revert unnecessary changes
gastonfournier 15b82cd
fix: missing linting after rebasing from main
chriswk cb6875f
Merged from main
gastonfournier 6ffc01c
Fixes after merge
gastonfournier b5882b0
Keep node 18
gastonfournier 58eea3c
Revert "Keep node 18"
gastonfournier 7b59ffe
Test fix
gastonfournier 3ff32ad
Some improvements suggested by copilot
gastonfournier f2864c6
Remove behavior test
gastonfournier f102c22
fix: keep per-request TLS/proxy handling with ky on Node fetch
gastonfournier 4a71bc6
Refactor types
gastonfournier b21b89a
Refactor to reduce verbosity and param handling
gastonfournier cd8d6e3
Standardize headers param
gastonfournier c7371ae
Set max retries configurable to use it in tests
gastonfournier ddb41ac
Use dispatcher instead of agent
gastonfournier 2c2f517
Attempt to fix tests by avoiding override retries
gastonfournier 6ce22fe
Keep CommonJS compatibility
gastonfournier 6d06858
WIP
gastonfournier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import semver from 'semver'; | ||
|
|
||
| const packageJsonPath = join(__dirname, '..', 'package.json'); | ||
|
|
||
| const resolveSpecVersion = (): string | undefined => { | ||
| try { | ||
| const raw = readFileSync(packageJsonPath, 'utf8'); | ||
| const packageJson = JSON.parse(raw) as { | ||
| dependencies?: Record<string, string>; | ||
| devDependencies?: Record<string, string>; | ||
| }; | ||
|
|
||
| const specDependencyVersion = | ||
| packageJson.dependencies?.['@unleash/client-specification'] ?? | ||
| packageJson.devDependencies?.['@unleash/client-specification']; | ||
|
|
||
| if (!specDependencyVersion) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (semver.valid(specDependencyVersion)) { | ||
| return specDependencyVersion; | ||
| } | ||
|
|
||
| if (semver.validRange(specDependencyVersion)) { | ||
| return semver.minVersion(specDependencyVersion)?.version; | ||
| } | ||
|
|
||
| return semver.coerce(specDependencyVersion)?.version; | ||
| } catch (_err: unknown) { | ||
| // Ignore filesystem/parse errors and fall back to undefined. | ||
| return undefined; | ||
| } | ||
| }; | ||
|
|
||
| export const supportedClientSpecVersion = resolveSpecVersion(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import { promises } from 'node:fs'; | ||
| import fetch from 'make-fetch-happen'; | ||
| import type { ClientFeaturesResponse, FeatureInterface } from '../feature'; | ||
| import type { CustomHeaders } from '../headers'; | ||
| import { buildHeaders } from '../request'; | ||
| import { createHttpClient } from '../request'; | ||
| import type { Segment } from '../strategy/strategy'; | ||
|
|
||
| export interface BootstrapProvider { | ||
|
|
@@ -29,11 +28,12 @@ export class DefaultBootstrapProvider implements BootstrapProvider { | |
|
|
||
| private segments?: Segment[]; | ||
|
|
||
| private appName: string; | ||
|
|
||
| private instanceId: string; | ||
|
|
||
| constructor(options: BootstrapOptions, appName: string, instanceId: string) { | ||
| constructor( | ||
| options: BootstrapOptions, | ||
| readonly appName: string, | ||
| readonly instanceId: string, | ||
| readonly connectionId: string, | ||
| ) { | ||
| this.url = options.url; | ||
| this.urlHeaders = options.urlHeaders; | ||
| this.filePath = options.filePath; | ||
|
|
@@ -45,21 +45,13 @@ export class DefaultBootstrapProvider implements BootstrapProvider { | |
| } | ||
|
|
||
| private async loadFromUrl(bootstrapUrl: string): Promise<ClientFeaturesResponse | undefined> { | ||
| const response = await fetch(bootstrapUrl, { | ||
| method: 'GET', | ||
| const httpClient = await createHttpClient({ | ||
| appName: this.appName, | ||
| instanceId: this.instanceId, | ||
| connectionId: this.connectionId, | ||
| timeout: 10_000, | ||
| headers: buildHeaders({ | ||
| appName: this.appName, | ||
| instanceId: this.instanceId, | ||
| etag: undefined, | ||
| contentType: undefined, | ||
| custom: this.urlHeaders, | ||
| }), | ||
| retry: { | ||
| retries: 2, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 is default retry |
||
| maxTimeout: 10_000, | ||
| }, | ||
| }); | ||
| const response = await httpClient.get({ url: bootstrapUrl, headers: this.urlHeaders }); | ||
| if (response.ok) { | ||
| return response.json(); | ||
| } | ||
|
|
@@ -90,6 +82,10 @@ export function resolveBootstrapProvider( | |
| options: BootstrapOptions, | ||
| appName: string, | ||
| instanceId: string, | ||
| connectionId: string, | ||
| ): BootstrapProvider { | ||
| return options.bootstrapProvider || new DefaultBootstrapProvider(options, appName, instanceId); | ||
| return ( | ||
| options.bootstrapProvider || | ||
| new DefaultBootstrapProvider(options, appName, instanceId, connectionId) | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ export class StreamingFetcher extends EventEmitter implements FetcherInterface { | |
|
|
||
| private readonly headers?: Record<string, string>; | ||
|
|
||
| private readonly connectionId?: string; | ||
| private readonly connectionId: string; | ||
|
|
||
| private readonly onSave: StreamingFetchingOptions['onSave']; | ||
|
|
||
|
|
@@ -30,8 +30,8 @@ export class StreamingFetcher extends EventEmitter implements FetcherInterface { | |
| url, | ||
| appName, | ||
| instanceId, | ||
| headers, | ||
| connectionId, | ||
| headers, | ||
| eventSource, | ||
| maxFailuresUntilFailover = 5, | ||
| failureWindowMs = 60_000, | ||
|
|
@@ -179,7 +179,6 @@ export class StreamingFetcher extends EventEmitter implements FetcherInterface { | |
| etag: undefined, | ||
| contentType: undefined, | ||
| custom: this.headers, | ||
| specVersionSupported: '5.2.0', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was always out of sync so I added client-spec-version.ts helper (please review it) |
||
| connectionId: this.connectionId, | ||
| }), | ||
| readTimeoutMillis: 60000, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned this into an immutable configuration per client. Maybe we should still enable different timeouts per request, and perhaps some httpOptions, but I also don't think we need them