feat(client): add AppIdentifier for app/app_version in the user agent#1791
Merged
Conversation
Backport of #1789 to the v8 release line. Introduce an `AppIdentifier` ({ name, version }) that downstream SDKs can set via `client.appIdentifier` to report the host application as `app` / `app_version` segments in the `X-Stream-Client` user agent, alongside the existing SDK and device identifiers. Also refactor `getUserAgent` to an arrow-function class field and memoize the result for the client's lifetime. The `stream-chat-...` output format is unchanged; app segments are emitted after the head, before os/device_model/client_bundle, and only when set. Note: memoization is permanent, so identifiers must be set before the first getUserAgent() call (previously the string was recomputed on each call).
Contributor
|
Size Change: +868 B (+0.16%) Total Size: 536 kB 📦 View Changed
|
arnautov-anton
approved these changes
Jul 2, 2026
|
🎉 This PR is included in version 8.61.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
What
Backport of #1789 to the v8 release line (
release-v8).Adds a new
AppIdentifierso downstream SDKs can report the host application in theX-Stream-Clientuser agent, and refactorsgetUserAgentto a memoized arrow-function class field, matching the v9 implementation exactly (full parity).Why
The user agent already identifies the SDK (
SdkIdentifier) and the device (DeviceIdentifier), but had no way to report the integrating application.AppIdentifierfills that gap as a distinct, third category.Changes
AppIdentifiertype (src/types.ts):{ name: string; version?: string }.namemaps to wire keyapp,versiontoapp_version(mirroring howDeviceIdentifier.modelmaps todevice_model).client.appIdentifier(src/client.ts): new optional field, set by downstream SDKs via direct assignment likesdkIdentifier/deviceIdentifier.getUserAgentrefactor: now an arrow-function class field with permanent memoization (computed once on first call). Thestream-chat-...output format is unchanged; the newapp/app_versionsegments are emitted right after the head, beforeos/device_model/client_bundle, and only when present.Example (everything set):
Parity note vs v9
This is the same change as #1789. The only differences are mechanical adaptations to the v8 codebase: the tests are written in v8's Mocha + chai style (
test/unit/client.js) rather than Vitest, and code is formatted for v8's Prettier config.Behavior note
Memoization is permanent: the user agent is computed once and cached for the client's lifetime. Identifiers (
sdkIdentifier/deviceIdentifier/appIdentifier) must therefore be set before the firstgetUserAgent()call; previously the string was recomputed on every call. In practice downstream SDKs set these at init, before any request, so this is not expected to affect real integrations.Semver
Additive and non-breaking: new optional type and field, no existing public behavior changed (
feat, so a minor release on the8.xline).Testing
test/unit/client.jsfor app + app_version ordering, the name-only case (omitsapp_version), and permanent memoization.X-Stream-Client headertests are unchanged and still pass.yarn prettier(check),yarn eslint(src),yarn types, and the full unit suite (1457 passing) are green.