-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Add support for client-side prerequisite events. #112
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
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
39a1155
feat: Add support for client-side prerequisite events.
kinyoklion 6458672
Fix link in docs.
kinyoklion d396df6
Merge branch 'main' into rlamb/sdk-685/client-side-prerequisites
kinyoklion f7efc4c
Do not run inspections for prerequisites.
kinyoklion 2b68e5e
Merge branch 'rlamb/sdk-685/client-side-prerequisites' of github.com:…
kinyoklion 6387ebb
Refactoring.
kinyoklion 0a8f078
Lint index.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,14 +50,14 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| const diagnosticsAccumulator = diagnosticsEnabled ? diagnostics.DiagnosticsAccumulator(new Date().getTime()) : null; | ||
| const diagnosticsManager = diagnosticsEnabled | ||
| ? diagnostics.DiagnosticsManager( | ||
| platform, | ||
| persistentStorage, | ||
| diagnosticsAccumulator, | ||
| eventSender, | ||
| environment, | ||
| options, | ||
| diagnosticId | ||
| ) | ||
| platform, | ||
|
||
| persistentStorage, | ||
| diagnosticsAccumulator, | ||
| eventSender, | ||
| environment, | ||
| options, | ||
| diagnosticId | ||
| ) | ||
| : null; | ||
|
|
||
| const stream = Stream(platform, options, environment, diagnosticsAccumulator); | ||
|
|
@@ -299,18 +299,19 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| } | ||
|
|
||
| function variation(key, defaultValue) { | ||
| return variationDetailInternal(key, defaultValue, true, false, false).value; | ||
| return variationDetailInternal(key, defaultValue, true, false, false, true).value; | ||
| } | ||
|
|
||
| function variationDetail(key, defaultValue) { | ||
| return variationDetailInternal(key, defaultValue, true, true, false); | ||
| return variationDetailInternal(key, defaultValue, true, true, false, true); | ||
| } | ||
|
|
||
| function variationDetailInternal(key, defaultValue, sendEvent, includeReasonInEvent, isAllFlags) { | ||
| function variationDetailInternal(key, defaultValue, sendEvent, includeReasonInEvent, isAllFlags, notifyInspection) { | ||
| let detail; | ||
| let flag; | ||
|
|
||
| if (flags && utils.objectHasOwnProperty(flags, key) && flags[key] && !flags[key].deleted) { | ||
| const flag = flags[key]; | ||
| flag = flags[key]; | ||
| detail = getFlagDetail(flag); | ||
| if (flag.value === null || flag.value === undefined) { | ||
| detail.value = defaultValue; | ||
|
|
@@ -320,11 +321,18 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| } | ||
|
|
||
| if (sendEvent) { | ||
| // For an all-flags evaluation, with events enabled, each flag will get an event, so we do not | ||
| // need to duplicate the prerequisites. | ||
| if (!isAllFlags) { | ||
| flag?.prerequisites?.forEach(key => { | ||
| variationDetailInternal(key, undefined, sendEvent, false, false, false); | ||
| }); | ||
| } | ||
| sendFlagEvent(key, detail, defaultValue, includeReasonInEvent); | ||
| } | ||
|
|
||
| // For the all flags case `onFlags` will be called instead. | ||
| if (!isAllFlags) { | ||
| if (!isAllFlags && notifyInspection) { | ||
| notifyInspectionFlagUsed(key, detail); | ||
| } | ||
|
|
||
|
|
@@ -351,7 +359,14 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
|
|
||
| for (const key in flags) { | ||
| if (utils.objectHasOwnProperty(flags, key) && !flags[key].deleted) { | ||
| results[key] = variationDetailInternal(key, null, !options.sendEventsOnlyForVariation, false, true).value; | ||
| results[key] = variationDetailInternal( | ||
| key, | ||
| null, | ||
| !options.sendEventsOnlyForVariation, | ||
| false, | ||
| true, | ||
| false | ||
| ).value; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -415,7 +430,7 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| } | ||
| }; | ||
| stream.connect(ident.getContext(), hash, { | ||
| ping: function() { | ||
| ping: function () { | ||
| logger.debug(messages.debugStreamPing()); | ||
| const contextAtTimeOfPingEvent = ident.getContext(); | ||
| requestor | ||
|
|
@@ -431,7 +446,7 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| emitter.maybeReportError(new errors.LDFlagFetchError(messages.errorFetchingFlags(err))); | ||
| }); | ||
| }, | ||
| put: function(e) { | ||
| put: function (e) { | ||
| const data = tryParseData(e.data); | ||
| if (!data) { | ||
| return; | ||
|
|
@@ -441,7 +456,7 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| // Don't wait for this Promise to be resolved; note that replaceAllFlags is guaranteed | ||
| // never to have an unhandled rejection | ||
| }, | ||
| patch: function(e) { | ||
| patch: function (e) { | ||
| const data = tryParseData(e.data); | ||
| if (!data) { | ||
| return; | ||
|
|
@@ -468,7 +483,7 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| logger.debug(messages.debugStreamPatchIgnored(data.key)); | ||
| } | ||
| }, | ||
| delete: function(e) { | ||
| delete: function (e) { | ||
| const data = tryParseData(e.data); | ||
| if (!data) { | ||
| return; | ||
|
|
@@ -525,7 +540,7 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
|
|
||
| notifyInspectionFlagsChanged(); | ||
|
|
||
| return handleFlagChanges(changes).catch(() => {}); // swallow any exceptions from this Promise | ||
| return handleFlagChanges(changes).catch(() => { }); // swallow any exceptions from this Promise | ||
| } | ||
|
|
||
| // Returns a Promise which will be resolved when we have dispatched all change events and updated | ||
|
|
@@ -781,8 +796,8 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| if (timeout > highTimeoutThreshold) { | ||
| logger.warn( | ||
| 'The waitForInitialization function was called with a timeout greater than ' + | ||
| `${highTimeoutThreshold} seconds. We recommend a timeout of ` + | ||
| `${highTimeoutThreshold} seconds or less.` | ||
| `${highTimeoutThreshold} seconds. We recommend a timeout of ` + | ||
| `${highTimeoutThreshold} seconds or less.` | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -806,7 +821,7 @@ function initialize(env, context, specifiedOptions, platform, extraOptionDefs) { | |
| } | ||
| logger.warn( | ||
| 'The waitForInitialization function was called without a timeout specified.' + | ||
| ' In a future version a default timeout will be applied.' | ||
| ' In a future version a default timeout will be applied.' | ||
| ); | ||
| return initializationStateTracker.getInitializationPromise(); | ||
| } | ||
|
|
||
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.
Added this ts-nocheck as typescript checking in eslint isn't happy in this file. Nothing changed, but the typescript version was updated. Basically just affects the IDE.