-
Notifications
You must be signed in to change notification settings - Fork 3
Add X-YVP-Sdk header and additionalHeaders override #237
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
Merged
Kyleasmth
merged 6 commits into
main
from
ks/YPE-2295-react-sdk-add-x-yvp-sdk-http-header-for-version
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b950e95
Add X-YVP-Sdk header and additionalHeaders override
Kyleasmth 8e30127
YPE-2295: Wire release stamp + address Greptile review
Kyleasmth 73a10a5
YPE-2295: Switch to tsup define for SDK version injection
Kyleasmth 41c33ec
YPE-2295: Import SDK version from package.json directly
Kyleasmth e1950d8
YPE-2295: Fix useBibleClient test after main refactor
Kyleasmth a9f19de
YPE-2295: Test additionalHeaders pass-through in UI YouVersionProvider
Kyleasmth 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| "@youversion/platform-core": minor | ||
| "@youversion/platform-react-hooks": minor | ||
| "@youversion/platform-react-ui": minor | ||
| --- | ||
|
|
||
| Add `X-YVP-Sdk` header to every API call and let consumers override headers | ||
|
|
||
| - New `X-YVP-Sdk: ReactSDK={version}` header sent on every request alongside `X-YVP-App-Key`. The version is imported directly from `packages/core/package.json` and inlined by the bundler at build time. | ||
| - `SDK_VERSION`, `SDK_NAME`, and `SDK_VERSION_HEADER_NAME` exported from `@youversion/platform-core`. | ||
| - `ApiConfig` gains an optional `additionalHeaders` map that is merged into every request. Keys here override the SDK's built-in headers, so wrappers (e.g. the React Native Expo SDK) can replace `X-YVP-Sdk` with their own identifier. | ||
| - `YouVersionProvider` gains an `additionalHeaders` prop that flows through context to every hook-built `ApiClient`. |
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
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import pkg from '../package.json' with { type: 'json' }; | ||
|
|
||
| export const SDK_VERSION = pkg.version; | ||
|
|
||
| export const SDK_NAME = 'ReactSDK'; | ||
|
|
||
| export const SDK_VERSION_HEADER_NAME = 'X-YVP-Sdk'; | ||
|
|
||
| export function buildSdkVersionHeaderValue(): string { | ||
| return `${SDK_NAME}=${SDK_VERSION}`; | ||
| } |
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
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
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,48 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { render } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { YouVersionProvider } from '@/components/YouVersionProvider'; | ||
|
|
||
| const baseProviderMock = | ||
| vi.fn<(props: Record<string, unknown> & { children?: React.ReactNode }) => React.ReactElement>(); | ||
| baseProviderMock.mockImplementation(({ children }) => <>{children}</>); | ||
|
|
||
| vi.mock('@youversion/platform-react-hooks', () => ({ | ||
| YouVersionProvider: (props: Record<string, unknown> & { children?: React.ReactNode }) => | ||
| baseProviderMock(props), | ||
| useYVAuth: vi.fn(), | ||
| })); | ||
|
|
||
| describe('UI YouVersionProvider', () => { | ||
| it('forwards additionalHeaders to the underlying hooks provider', () => { | ||
| const additionalHeaders = { 'X-YVP-Sdk': 'ReactNativeSDK=1.2.3' }; | ||
|
|
||
| render( | ||
| <YouVersionProvider appKey="test-key" additionalHeaders={additionalHeaders}> | ||
| <div data-testid="child">hello</div> | ||
| </YouVersionProvider>, | ||
| ); | ||
|
|
||
| expect(baseProviderMock).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| appKey: 'test-key', | ||
| additionalHeaders, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('omits additionalHeaders when not provided', () => { | ||
| render( | ||
| <YouVersionProvider appKey="test-key"> | ||
| <div data-testid="child">hello</div> | ||
| </YouVersionProvider>, | ||
| ); | ||
|
|
||
| const lastCall = baseProviderMock.mock.calls.at(-1)?.[0] as Record<string, unknown>; | ||
| expect(lastCall?.appKey).toBe('test-key'); | ||
| expect(lastCall?.additionalHeaders).toBeUndefined(); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.