✨ Add build number and RFC 7231 formatting to user agent#26
✨ Add build number and RFC 7231 formatting to user agent#26williamchong merged 2 commits intolikecoin:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the WebView user agent string to include native app version/build metadata (via expo-application) and formats the UA string closer to RFC-style product tokens + comment, improving server-side identification of app clients.
Changes:
- Add
expo-applicationusage to fetch native app version and build number with a fallback topackage.jsonversion. - Normalize OS name casing and formatting in the UA comment.
- Replace inline
userAgenttemplate with a sharedUSER_AGENTconstant.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const USER_AGENT = (() => { | ||
| const appVersion = Application.nativeApplicationVersion ?? packageJson.version; | ||
| const buildNumber = Application.nativeBuildVersion ?? '0'; | ||
| const osName = Platform.OS === 'ios' ? 'iOS' : 'Android'; |
There was a problem hiding this comment.
osName falls back to 'Android' for any non-iOS platform. If this file ever runs on web (or other RN platforms), the UA will be incorrect. Prefer explicitly handling android (and optionally web) or deriving from Platform.OS with proper casing.
| const osName = Platform.OS === 'ios' ? 'iOS' : 'Android'; | |
| const osNameMap: Record<string, string> = { ios: 'iOS', android: 'Android', web: 'Web' }; | |
| const osName = osNameMap[Platform.OS] ?? Platform.OS; |
app/index.tsx
Outdated
| const buildNumber = Application.nativeBuildVersion ?? '0'; | ||
| const osName = Platform.OS === 'ios' ? 'iOS' : 'Android'; | ||
| return `3ook-com-app/${appVersion} (${osName}; ${Platform.Version}) Build/${buildNumber}`; |
There was a problem hiding this comment.
Defaulting nativeBuildVersion to '0' means the app will always send Build/0 when the build number isn't available (e.g., certain dev/web contexts). That can be misleading for server-side logging/feature flags; consider omitting the Build/... product token entirely when nativeBuildVersion is null/undefined.
| const buildNumber = Application.nativeBuildVersion ?? '0'; | |
| const osName = Platform.OS === 'ios' ? 'iOS' : 'Android'; | |
| return `3ook-com-app/${appVersion} (${osName}; ${Platform.Version}) Build/${buildNumber}`; | |
| const buildNumber = Application.nativeBuildVersion; | |
| const buildToken = buildNumber ? ` Build/${buildNumber}` : ''; | |
| const osName = Platform.OS === 'ios' ? 'iOS' : 'Android'; | |
| return `3ook-com-app/${appVersion} (${osName}; ${Platform.Version})${buildToken}`; |
Use expo-application for native version and build number instead of package.json alone. Properly case OS name and semicolon-separate fields. Before: 3ook-com-app/1.1.0 (ios 18.0) After: 3ook-com-app/1.1.0 (iOS; 18.0) Build/42
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Align with standard UA convention where OS name and version form a single token (e.g. "iOS 18.0"), not separate semicolon-delimited fields.
Use expo-application for native version and build number instead of package.json alone. Properly case OS name and semicolon-separate fields.
Before: 3ook-com-app/1.1.0 (ios 18.0)
After: 3ook-com-app/1.1.0 (iOS; 18.0) Build/42