feat(hypihub): identify requests with the distribution version - #202
Merged
Merged
Conversation
Every HypiHub request now carries `user-agent: hypit/<version>`, read from the distribution's own package.json. Wrapping the fetcher in the HypiHubClient constructor covers the API calls, OAuth token refreshes, multipart uploads and asset downloads, since they all run through `client.fetcher`. A manifest that is absent, unreadable or belongs to another package yields `hypit/unknown` rather than failing the module import.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every request to HypiHub now carries
user-agent: hypit/<version>, where the version is the distribution's own npm version read from the rootpackage.json. Before this, Node's undici defaultuser-agent: nodewent out.How
HypiHubClientwraps its injected fetcher once in the constructor. All API calls, OAuth token refreshes, multipart uploads and asset downloads run throughclient.fetcher, so one wrap covers them.activation.ts,index.ts,mapping.tsandroutes.tsmake no network calls.The wrapper hands the underlying fetcher a plain header object, which is the shape the existing tests read.
Version lookup
../../../package.jsonresolves to the distribution root both in the repository and in an installed package, since npm shipspackages/*/src/**/*at the same depth. The manifest'snamemust be@hypit/hypitfor its version to be used; an absent, unreadable or foreign manifest yieldshypit/unknown, and the read is guarded so the module still imports.A checkout of
mainahead of the last Release reports that Release's version, because the rootpackage.jsononly advances when a version is committed for release.Checks
A full generation driven through a recording fetch showed the header on all 12 requests:
The same probe run from a layout whose manifest belongs to another package, and from one with no manifest at that depth, reported
hypit/unknown.node test/run.mjs: 854 tests, 844 pass, 10 skipped, 0 fail.The presigned upload PUT goes to S3 and also carries the header. S3 presigned URLs verify only the headers listed in
X-Amz-SignedHeaders, which does not includeuser-agent; that PUT succeeds in the probe above.