-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Add experimental debug override functionality. #132
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
pranjal-jately-ld
merged 15 commits into
launchdarkly:main
from
pranjal-jately-ld:add-flag-override-capability
Sep 5, 2025
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
97ea230
feat: Add debug override capabilities for plugins
pranjal-jately-ld 3cf00c0
feat: Enhance debug override functionality with removal and clearing …
pranjal-jately-ld 9441c92
feat: Implement getAllOverrides method and enhance flag handling
pranjal-jately-ld 697798a
Add flag store facade for centralized flag access
zubhav 8a7f2ff
Refactor setOverride to use flagStore.get method
zubhav bfbc9a9
fix: add objectHasOwnProperty checks to flagStore
pranjal-jately-ld 3086a44
Refactor flag handling for better readability
zubhav 28e6e42
Remove unnecessary comments and code in initialize function
zubhav 74f44ed
Update handling of flag changes to not wait for Promise
zubhav dd1a828
test: add tests for debug override functionality
pranjal-jately-ld ce4a44f
style: revert code formatting changes
pranjal-jately-ld c40f020
fix: restore missing allFlags implementation logic
pranjal-jately-ld 2cbe74c
refactor: add lazy initialization for flagOverrides with optimizations
pranjal-jately-ld 40a34b9
feat: implement FlagStore for centralized flag management
pranjal-jately-ld 5d306fc
docs: enhance typings and FlagStore documentation
pranjal-jately-ld 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| const utils = require('./utils'); | ||
|
|
||
| /** | ||
| * FlagStore - Centralized flag store and access point for all feature flags | ||
| * | ||
| * This module manages two types of feature flags: | ||
| * 1. Regular flags - Retrieved from LaunchDarkly servers or bootstrap data | ||
| * 2. Override flags - Local overrides for debugging/testing | ||
| * | ||
| * When a flag is requested: | ||
| * - If an override exists for that flag, the override value is returned | ||
| * - Otherwise, the regular flag value is returned | ||
| */ | ||
| function FlagStore() { | ||
| let flags = {}; | ||
| // The flag overrides are set lazily to allow bypassing property checks when no overrides are present. | ||
| let flagOverrides; | ||
pranjal-jately-ld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Gets a single flag by key, with overrides taking precedence over regular flags | ||
| * @param {string} key The flag key to retrieve | ||
| * @returns {Object|null} The flag object or null if not found | ||
| */ | ||
| function get(key) { | ||
| // Check overrides first, then real flags | ||
| if (flagOverrides && utils.objectHasOwnProperty(flagOverrides, key) && flagOverrides[key]) { | ||
| return flagOverrides[key]; | ||
| } | ||
|
|
||
| if (flags && utils.objectHasOwnProperty(flags, key) && flags[key] && !flags[key].deleted) { | ||
| return flags[key]; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Gets all flags with overrides applied | ||
| * @returns {Object} Object containing all flags with any overrides applied | ||
| */ | ||
| function getFlagsWithOverrides() { | ||
| const result = {}; | ||
|
|
||
| // Add all flags first | ||
| for (const key in flags) { | ||
| const flag = get(key); | ||
| if (flag) { | ||
| result[key] = flag; | ||
| } | ||
| } | ||
|
|
||
| // Override with any flagOverrides (they take precedence) | ||
| if (flagOverrides) { | ||
| for (const key in flagOverrides) { | ||
| const override = get(key); | ||
| if (override) { | ||
| result[key] = override; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Replaces all flags with new flag data | ||
| * @param {Object} newFlags - Object containing the new flag data | ||
| */ | ||
| function setFlags(newFlags) { | ||
| flags = { ...newFlags }; | ||
| } | ||
|
|
||
| /** | ||
| * Sets an override value for a specific flag | ||
| * @param {string} key The flag key to override | ||
| * @param {*} value The override value for the flag | ||
| */ | ||
| function setOverride(key, value) { | ||
| if (!flagOverrides) { | ||
| flagOverrides = {}; | ||
| } | ||
| flagOverrides[key] = { value }; | ||
| } | ||
|
|
||
| /** | ||
| * Removes an override for a specific flag | ||
| * @param {string} key The flag key to remove the override for | ||
| */ | ||
| function removeOverride(key) { | ||
| if (!flagOverrides || !flagOverrides[key]) { | ||
| return; // No override to remove | ||
| } | ||
|
|
||
| delete flagOverrides[key]; | ||
|
|
||
| // If no more overrides, reset to undefined for performance | ||
| if (Object.keys(flagOverrides).length === 0) { | ||
| flagOverrides = undefined; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Clears all flag overrides and returns the cleared overrides | ||
| * @returns {Object} The overrides that were cleared, useful for tracking what was removed | ||
| */ | ||
| function clearAllOverrides() { | ||
kinyoklion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!flagOverrides) { | ||
| return {}; // No overrides to clear, return empty object for consistency | ||
| } | ||
|
|
||
| const clearedOverrides = { ...flagOverrides }; | ||
| flagOverrides = undefined; // Reset to undefined | ||
| return clearedOverrides; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the internal flag state without overrides applied | ||
| * @returns {Object} The internal flag data structure | ||
| */ | ||
| function getFlags() { | ||
| return flags; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the flag overrides data | ||
| * @returns {Object} The flag overrides object, or empty object if no overrides exist | ||
| */ | ||
| function getFlagOverrides() { | ||
| return flagOverrides || {}; | ||
| } | ||
|
|
||
| return { | ||
| clearAllOverrides, | ||
| get, | ||
| getFlagOverrides, | ||
| getFlags, | ||
| getFlagsWithOverrides, | ||
| removeOverride, | ||
| setFlags, | ||
| setOverride, | ||
| }; | ||
| } | ||
|
|
||
| module.exports = FlagStore; | ||
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.