launchdarkly-js-sdk-common
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -5,2 +5,9 @@ # Change log | ||
## [4.2.0] - 2022-10-03 | ||
### Removed: | ||
- Removed `seenRequests` cache. This cache was used to de-duplicate events, but it has been supplanted with summary events. | ||
### Deprecated: | ||
- The `allowFrequentDuplicateEvents` configuration has been deprecated because it controlled the behavior of the `seenRequests` cache. | ||
## [4.1.1] - 2022-06-07 | ||
@@ -7,0 +14,0 @@ ### Changed: |
{ | ||
"name": "launchdarkly-js-sdk-common", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "LaunchDarkly SDK for JavaScript - common code", | ||
@@ -5,0 +5,0 @@ "author": "LaunchDarkly <team@launchdarkly.com>", |
@@ -42,2 +42,3 @@ const errors = require('./errors'); | ||
application: { validator: applicationConfigValidator }, | ||
inspectors: { default: [] }, | ||
}; | ||
@@ -44,0 +45,0 @@ |
@@ -17,2 +17,3 @@ const EventProcessor = require('./EventProcessor'); | ||
const messages = require('./messages'); | ||
const { InspectorTypes, InspectorManager } = require('./InspectorManager'); | ||
@@ -36,2 +37,3 @@ const changeEvent = 'change'; | ||
const options = configuration.validate(specifiedOptions, emitter, extraOptionDefs, logger); | ||
const inspectorManager = InspectorManager(options.inspectors, logger); | ||
const sendEvents = options.sendEvents; | ||
@@ -159,2 +161,28 @@ let environment = env; | ||
function notifyInspectionIdentityChanged() { | ||
if (inspectorManager.hasListeners(InspectorTypes.clientIdentityChanged)) { | ||
inspectorManager.onIdentityChanged(ident.getUser()); | ||
} | ||
} | ||
function notifyInspectionFlagChanged(data, newFlag) { | ||
if (inspectorManager.hasListeners(InspectorTypes.flagDetailChanged)) { | ||
inspectorManager.onFlagChanged(data.key, getFlagDetail(newFlag)); | ||
} | ||
} | ||
function notifyInspectionFlagsChanged() { | ||
if (inspectorManager.hasListeners(InspectorTypes.flagDetailsChanged)) { | ||
inspectorManager.onFlags( | ||
Object.entries(flags) | ||
.map(([key, value]) => ({ key, detail: getFlagDetail(value) })) | ||
.reduce((acc, cur) => { | ||
// eslint-disable-next-line no-param-reassign | ||
acc[cur.key] = cur.detail; | ||
return acc; | ||
}, {}) | ||
); | ||
} | ||
} | ||
function onIdentifyChange(user, previousUser) { | ||
@@ -165,2 +193,3 @@ sendIdentifyEvent(user); | ||
} | ||
notifyInspectionIdentityChanged(); | ||
} | ||
@@ -264,10 +293,10 @@ | ||
function variation(key, defaultValue) { | ||
return variationDetailInternal(key, defaultValue, true, false).value; | ||
return variationDetailInternal(key, defaultValue, true, false, false).value; | ||
} | ||
function variationDetail(key, defaultValue) { | ||
return variationDetailInternal(key, defaultValue, true, true); | ||
return variationDetailInternal(key, defaultValue, true, true, false); | ||
} | ||
function variationDetailInternal(key, defaultValue, sendEvent, includeReasonInEvent) { | ||
function variationDetailInternal(key, defaultValue, sendEvent, includeReasonInEvent, isAllFlags) { | ||
let detail; | ||
@@ -289,2 +318,7 @@ | ||
// For the all flags case `onFlags` will be called instead. | ||
if (!isAllFlags) { | ||
notifyInspectionIdentityChanged(); | ||
} | ||
return detail; | ||
@@ -313,3 +347,3 @@ } | ||
if (utils.objectHasOwnProperty(flags, key) && !flags[key].deleted) { | ||
results[key] = variationDetailInternal(key, null, !options.sendEventsOnlyForVariation).value; | ||
results[key] = variationDetailInternal(key, null, !options.sendEventsOnlyForVariation, false, true).value; | ||
} | ||
@@ -443,2 +477,3 @@ } | ||
handleFlagChanges(mods); // don't wait for this Promise to be resolved | ||
notifyInspectionFlagChanged(data, newFlag); | ||
} else { | ||
@@ -460,2 +495,3 @@ logger.debug(messages.debugStreamPatchIgnored(data.key)); | ||
flags[data.key] = { version: data.version, deleted: true }; | ||
notifyInspectionFlagChanged(data, flags[data.key]); | ||
handleFlagChanges(mods); // don't wait for this Promise to be resolved | ||
@@ -502,2 +538,5 @@ } else { | ||
flags = { ...newFlags }; | ||
notifyInspectionFlagsChanged(); | ||
return handleFlagChanges(changes).catch(() => {}); // swallow any exceptions from this Promise | ||
@@ -676,2 +715,4 @@ } | ||
flags = requestedFlags || {}; | ||
notifyInspectionFlagsChanged(); | ||
// Note, we don't need to call updateSettings here because local storage and change events are not relevant | ||
@@ -678,0 +719,0 @@ signalSuccessfulInit(); |
@@ -183,2 +183,6 @@ const errors = require('./errors'); | ||
const invalidInspector = (type, name) => `an inspector: "${name}" of an invalid type (${type}) was configured`; | ||
const inspectorMethodError = (type, name) => `an inspector: "${name}" of type: "${type}" generated an exception`; | ||
const invalidTagValue = name => `Config option "${name}" must only contain letters, numbers, ., _ or -.`; | ||
@@ -212,4 +216,6 @@ | ||
identifyDisabled, | ||
inspectorMethodError, | ||
invalidContentType, | ||
invalidData, | ||
invalidInspector, | ||
invalidKey, | ||
@@ -216,0 +222,0 @@ invalidTagValue, |
106
typings.d.ts
@@ -290,2 +290,7 @@ /** | ||
} | ||
/** | ||
* Inspectors can be used for collecting information for monitoring, analytics, and debugging. | ||
*/ | ||
inspectors?: LDInspection[]; | ||
} | ||
@@ -825,2 +830,103 @@ | ||
export type LDLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none'; | ||
/** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* This interface is used to collect information about flag usage. | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
* flow. It is intended for monitoring, analytics, or debugging purposes. | ||
*/ | ||
interface LDInspectionFlagUsedHandler { | ||
type: 'flag-used', | ||
/** | ||
* Name of the inspector. Will be used for logging issues with the inspector. | ||
*/ | ||
name: string, | ||
/** | ||
* This method is called when a flag is accessed via a variation method, or it can be called based on actions in | ||
* wrapper SDKs which have different methods of tracking when a flag was accessed. It is not called when a call is made | ||
* to allFlags. | ||
*/ | ||
method: (flagKey: string, flagDetail: LDEvaluationDetail, user: LDUser) => void; | ||
} | ||
/** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* This interface is used to collect information about flag data. In order to understand the | ||
* current flag state it should be combined with {@link LDInspectionFlagValueChangedHandler}. | ||
* This interface will get the initial flag information, and | ||
* {@link LDInspectionFlagValueChangedHandler} will provide changes to individual flags. | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
* flow. It is intended for monitoring, analytics, or debugging purposes. | ||
*/ | ||
interface LDInspectionFlagDetailsChangedHandler { | ||
type: 'flag-details-changed', | ||
/** | ||
* Name of the inspector. Will be used for logging issues with the inspector. | ||
*/ | ||
name: string, | ||
/** | ||
* This method is called when the flags in the store are replaced with new flags. It will contain all flags | ||
* regardless of if they have been evaluated. | ||
*/ | ||
method: (details: Record<string, LDEvaluationDetail>) => void; | ||
} | ||
/** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* This interface is used to collect changes to flag data, but does not provide the initial | ||
* data. It can be combined with {@link LDInspectionFlagValuesChangedHandler} to track the | ||
* entire flag state. | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
* flow. It is intended for monitoring, analytics, or debugging purposes. | ||
*/ | ||
interface LDInspectionFlagDetailChangedHandler { | ||
type: 'flag-detail-changed', | ||
/** | ||
* Name of the inspector. Will be used for logging issues with the inspector. | ||
*/ | ||
name: string, | ||
/** | ||
* This method is called when a flag is updated. It will not be called | ||
* when all flags are updated. | ||
*/ | ||
method: (flagKey: string, detail: LDEvaluationDetail) => void; | ||
} | ||
/** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* This interface is used to track current identity state of the SDK. | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
* flow. It is intended for monitoring, analytics, or debugging purposes. | ||
*/ | ||
interface LDInspectionIdentifyHandler { | ||
type: 'client-identity-changed', | ||
/** | ||
* Name of the inspector. Will be used for logging issues with the inspector. | ||
*/ | ||
name: string, | ||
/** | ||
* This method will be called when an identify operation completes. | ||
*/ | ||
method: (user: LDUser) => void; | ||
} | ||
type LDInspection = LDInspectionFlagUsedHandler | LDInspectionFlagDetailsChangedHandler | ||
| LDInspectionFlagDetailChangedHandler | LDInspectionIdentifyHandler; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
396968
71
9075