-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Add FDv2 DataManager and enable experimental FDv2 support. #1161
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
Closed
Closed
Changes from 19 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
cb14960
feat: Add experimental FDv2 configuration (unused)
kinyoklion 9f88376
refactor: Use compound validator for dataSystem with built-in defaults
kinyoklion a90b962
fix: Lint fixes for dataSystem configuration
kinyoklion fa111d5
Merge branch 'main' into rlamb/SDK-1935/FDv2-configuration
kinyoklion 73c6f2a
WIP: Example of this working together
keelerm84 109aeea
Fix interrupted state for non-status codes.
kinyoklion e7f5049
Tests
kinyoklion e2821cd
Fix basis.
kinyoklion a7413c0
rebase data system config
kinyoklion e40b0d5
Integrate mode switching and caching.
kinyoklion 7bfa7ac
Merge branch 'main' into mk/NOTICKET/testing-fdv2
kinyoklion e2b7d15
Streaming control interface
kinyoklion 9d242d4
Skip cache when bootstrap is available.
kinyoklion cee85ee
Add event flush on backgrounding.
kinyoklion 0d92a78
remove flag_eval support; use flag-eval only
keelerm84 5ee0469
Merge branch 'main' into mk/NOTICKET/testing-fdv2
kinyoklion cfc1207
Remove debug logging from FDv2DataSource.
kinyoklion ea3eb1d
Commonize stream control input between browser and RN for FDv2.
kinyoklion 67eff51
Merge branch 'main' into mk/NOTICKET/testing-fdv2
kinyoklion 4f59d39
Increase package size limits
kinyoklion c603f56
Don't export internals
kinyoklion 2a80fa7
Better type alignment
kinyoklion 4eb5a59
Stricter validation and logging.
kinyoklion 3e287df
Merge branch 'main' into mk/NOTICKET/testing-fdv2
kinyoklion bd80512
Remove browser specific data manager.
kinyoklion 4824560
Add cache comment
kinyoklion 304e5f3
Ensure streaming is off when setStreaming(false)
kinyoklion 0a03954
Fix mode switching.
kinyoklion 0d1b333
contract test changes - wip
tanderson-ld 88ab6a4
Additional handling.
kinyoklion 70bdf7d
Merge remote-tracking branch 'origin/mk/NOTICKET/testing-fdv2' into m…
kinyoklion 04d2644
Connect withReasons.
kinyoklion 6c1996d
Allow mode customization. Connect withReasons.
kinyoklion 266104a
Trim failing tests.
kinyoklion a542dc1
More testing, add data source updates sink.
kinyoklion 5759cef
No basis.
kinyoklion 79fe48c
Merge origin/main into mk/NOTICKET/testing-fdv2
kinyoklion 685aa67
Lint fix.
kinyoklion 0b44efd
Second example for FDv2.
kinyoklion 57525f3
Mock fix.
kinyoklion 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
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,123 @@ | ||
| import { | ||
| BROWSER_TRANSITION_TABLE, | ||
| browserFdv1Endpoints, | ||
| Configuration, | ||
| Context, | ||
| createDefaultSourceFactoryProvider, | ||
| createFDv2DataManagerBase, | ||
| DataManager, | ||
| FDv2ConnectionMode, | ||
| FDv2DataManagerControl, | ||
| FlagManager, | ||
| LDEmitter, | ||
| LDHeaders, | ||
| LDIdentifyOptions, | ||
| MODE_TABLE, | ||
| Platform, | ||
| } from '@launchdarkly/js-client-sdk-common'; | ||
|
|
||
| import { BrowserIdentifyOptions } from './BrowserIdentifyOptions'; | ||
|
|
||
| /** | ||
| * A DataManager that uses the FDv2 protocol for flag delivery with | ||
| * mode switching and debouncing support. | ||
| * | ||
| * Delegates to a shared {@link FDv2DataManagerControl} (from sdk-client) | ||
| * and adds browser-specific behavior: | ||
| * - Auth via query params (no Authorization header in browser) | ||
| * - Listener-driven streaming auto-promotion | ||
| * - Forced streaming via `setStreaming()` API | ||
| */ | ||
| export default class BrowserFDv2DataManager implements DataManager { | ||
| private readonly _base: FDv2DataManagerControl; | ||
|
|
||
| // If streaming is forced on or off, then we follow that setting. | ||
| // Otherwise we automatically manage streaming state. | ||
| private _forcedStreaming?: boolean = undefined; | ||
| private _automaticStreamingState: boolean = false; | ||
|
|
||
| // +-----------+-----------+------------------+ | ||
| // | forced | automatic | state | | ||
| // +-----------+-----------+------------------+ | ||
| // | true | false | streaming | | ||
| // | true | true | streaming | | ||
| // | false | true | not streaming | | ||
| // | false | false | not streaming | | ||
| // | undefined | true | streaming | | ||
| // | undefined | false | configured mode | | ||
| // +-----------+-----------+------------------+ | ||
|
|
||
| constructor( | ||
| platform: Platform, | ||
| flagManager: FlagManager, | ||
| credential: string, | ||
| config: Configuration, | ||
| baseHeaders: LDHeaders, | ||
| emitter: LDEmitter, | ||
| ) { | ||
| const initialForegroundMode: FDv2ConnectionMode = | ||
| (config.dataSystem?.initialConnectionMode as FDv2ConnectionMode) ?? 'one-shot'; | ||
|
|
||
| this._base = createFDv2DataManagerBase({ | ||
| platform, | ||
| flagManager, | ||
| credential, | ||
| config, | ||
| baseHeaders, | ||
| emitter, | ||
| transitionTable: BROWSER_TRANSITION_TABLE, | ||
| initialForegroundMode, | ||
| backgroundMode: undefined, | ||
| modeTable: MODE_TABLE, | ||
| sourceFactoryProvider: createDefaultSourceFactoryProvider(), | ||
| fdv1Endpoints: browserFdv1Endpoints(credential), | ||
| buildQueryParams: (identifyOptions?: LDIdentifyOptions) => { | ||
| const params: { key: string; value: string }[] = [{ key: 'auth', value: credential }]; | ||
| const browserOpts = identifyOptions as BrowserIdentifyOptions | undefined; | ||
| if (browserOpts?.hash) { | ||
| params.push({ key: 'h', value: browserOpts.hash }); | ||
| } | ||
| return params; | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| async identify( | ||
| identifyResolve: () => void, | ||
| identifyReject: (err: Error) => void, | ||
| context: Context, | ||
| identifyOptions?: LDIdentifyOptions, | ||
| ): Promise<void> { | ||
| return this._base.identify(identifyResolve, identifyReject, context, identifyOptions); | ||
| } | ||
|
|
||
| close(): void { | ||
| this._base.close(); | ||
| } | ||
|
|
||
| setFlushCallback(callback: () => void): void { | ||
| this._base.setFlushCallback(callback); | ||
| } | ||
|
|
||
| setForcedStreaming(streaming?: boolean): void { | ||
| this._forcedStreaming = streaming; | ||
| this._updateStreamingState(); | ||
| } | ||
|
|
||
| setAutomaticStreamingState(streaming: boolean): void { | ||
| this._automaticStreamingState = streaming; | ||
| this._updateStreamingState(); | ||
| } | ||
|
|
||
| private _updateStreamingState(): void { | ||
| const shouldBeStreaming = | ||
| this._forcedStreaming || | ||
| (this._automaticStreamingState && this._forcedStreaming === undefined); | ||
|
|
||
| if (shouldBeStreaming) { | ||
| this._base.setForegroundMode('streaming'); | ||
| } else { | ||
| this._base.setForegroundMode(this._base.configuredForegroundMode); | ||
| } | ||
kinyoklion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -53,6 +53,33 @@ export interface DataManager { | |
| * Closes the data manager. Any active connections are closed. | ||
| */ | ||
| close(): void; | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may change when we determine how we are going to handle setConnectionMode. |
||
| /** | ||
| * Force streaming on or off. When `true`, the data manager should | ||
| * maintain a streaming connection. When `false`, streaming is disabled. | ||
| * When `undefined`, the forced state is cleared and automatic behavior | ||
| * takes over. | ||
| * | ||
| * Optional — only browser data managers implement this. | ||
| */ | ||
| setForcedStreaming?(streaming?: boolean): void; | ||
|
|
||
| /** | ||
| * Update the automatic streaming state based on whether change listeners | ||
| * are registered. When `true` and forced streaming is not set, the data | ||
| * manager should activate streaming. | ||
| * | ||
| * Optional — only browser data managers implement this. | ||
| */ | ||
| setAutomaticStreamingState?(streaming: boolean): void; | ||
|
|
||
| /** | ||
| * Set a callback to flush pending analytics events. Called immediately | ||
| * (not debounced) when the lifecycle transitions to background. | ||
| * | ||
| * Optional — only FDv2 data managers implement this. | ||
| */ | ||
| setFlushCallback?(callback: () => void): void; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will want to remove this before we commit.