feat: add client and client version to request headers#412
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds client and client version information to the request headers to support enhanced tracking and versioning. Key changes include:
- Adding "X-Client" and "X-Client-Version" headers in the auth request (auth.ts).
- Reading the client version from package.json and exposing it via a getter in the configuration store (config.ts).
- Bumping the CLI package version (package.json).
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/cli/utils/auth.ts | Adds client and client version headers to outgoing requests. |
| packages/cli/stores/config.ts | Reads and stores the client version from package.json. |
| packages/cli/package.json | Increments the version to reflect the new changes. |
|
The SDKs are using |
|
removing from queue to ensure we get this discussion in ^^ |
Good.
Hmm, good point. |
Out of curiosity, is there a reason we didn't go for an |
|
AFAIR we investigated and found that there was no additional benefit of prefixing "x-". E.g. the pattern was recommended against as outdated. But I admit it's all from hazy memory. |
Fair enough. I'll update the code to use |
We've sending both in the same header following this pattern today: |
Done :) |
|
thanks @Swiftwork. I just realized the CLI is of course talking to the REST API, not the front facing API, so there's no actual requirement to follow what the SDKs do - apologies for the turkey chase. I'm OK to go with |
- Introduced a `moduleRoot` constant to simplify path calculations for the schema and package.json files. - Updated the `createValidator` method to use `moduleRoot` for resolving the schema path and loading the client version from package.json, enhancing code clarity and maintainability. - Removed redundant code related to package.json path handling, improving overall efficiency.
| const moduleMetadata = await readFile( | ||
| join(moduleRoot, "package.json"), | ||
| "utf-8", | ||
| ); | ||
| const moduleMetadataParsed = parseJSON(moduleMetadata) as unknown as { | ||
| version: string; | ||
| }; | ||
| this.clientVersion = moduleMetadataParsed.version; |
There was a problem hiding this comment.
this is probably fine, but as a point of reference this is what the SDKs do: https://github.com/bucketco/bucket-javascript-sdk/blob/main/packages/browser-sdk/src/config.ts#L1
There was a problem hiding this comment.
We can't unfortunately do that without getting the "importing json is experimental warning" because the package uses type "module"
No description provided.