@launchdarkly/js-sdk-common 2.30.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/cjs/api/data/LDEvaluationReason.d.ts +11 -0
- package/dist/cjs/api/data/LDEvaluationReason.d.ts.map +1 -1
- package/dist/cjs/api/platform/Filesystem.d.ts +31 -1
- package/dist/cjs/api/platform/Filesystem.d.ts.map +1 -1
- package/dist/cjs/index.cjs +105 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/internal/evaluation/EventFactoryBase.d.ts +1 -0
- package/dist/cjs/internal/evaluation/EventFactoryBase.d.ts.map +1 -1
- package/dist/cjs/internal/events/EventProcessor.d.ts.map +1 -1
- package/dist/cjs/internal/events/InputEvalEvent.d.ts +7 -1
- package/dist/cjs/internal/events/InputEvalEvent.d.ts.map +1 -1
- package/dist/cjs/internal/events/LDEventSummarizer.d.ts.map +1 -1
- package/dist/cjs/internal/fdv2/protocolHandler.d.ts.map +1 -1
- package/dist/cjs/internal/fetch/followRedirects.d.ts +34 -0
- package/dist/cjs/internal/fetch/followRedirects.d.ts.map +1 -0
- package/dist/cjs/internal/fetch/index.d.ts +1 -0
- package/dist/cjs/internal/fetch/index.d.ts.map +1 -1
- package/dist/esm/AttributeReference.d.ts +1 -1
- package/dist/esm/Context.d.ts +2 -2
- package/dist/esm/ContextFilter.d.ts +2 -2
- package/dist/esm/api/context/LDContext.d.ts +3 -3
- package/dist/esm/api/context/LDContextCommon.d.ts +1 -1
- package/dist/esm/api/context/LDMultiKindContext.d.ts +1 -1
- package/dist/esm/api/context/LDSingleKindContext.d.ts +1 -1
- package/dist/esm/api/context/index.d.ts +6 -6
- package/dist/esm/api/data/LDEvaluationDetail.d.ts +2 -2
- package/dist/esm/api/data/LDEvaluationReason.d.ts +11 -0
- package/dist/esm/api/data/LDEvaluationReason.d.ts.map +1 -1
- package/dist/esm/api/data/LDFlagSet.d.ts +1 -1
- package/dist/esm/api/data/index.d.ts +4 -4
- package/dist/esm/api/index.d.ts +7 -7
- package/dist/esm/api/integrations/index.d.ts +1 -1
- package/dist/esm/api/logging/BasicLoggerOptions.d.ts +1 -1
- package/dist/esm/api/logging/index.d.ts +3 -3
- package/dist/esm/api/options/LDClientContext.d.ts +2 -2
- package/dist/esm/api/options/index.d.ts +1 -1
- package/dist/esm/api/platform/EventSource.d.ts +1 -1
- package/dist/esm/api/platform/Filesystem.d.ts +31 -1
- package/dist/esm/api/platform/Filesystem.d.ts.map +1 -1
- package/dist/esm/api/platform/Info.d.ts +1 -1
- package/dist/esm/api/platform/Platform.d.ts +6 -6
- package/dist/esm/api/platform/Requests.d.ts +1 -1
- package/dist/esm/api/platform/index.d.ts +9 -9
- package/dist/esm/api/subsystem/DataSystem/CallbackHandler.d.ts +1 -1
- package/dist/esm/api/subsystem/DataSystem/index.d.ts +1 -1
- package/dist/esm/api/subsystem/LDContextDeduplicator.d.ts +1 -1
- package/dist/esm/api/subsystem/LDEventProcessor.d.ts +1 -1
- package/dist/esm/api/subsystem/index.d.ts +5 -5
- package/dist/esm/datasource/CompositeDataSource.d.ts +3 -3
- package/dist/esm/datasource/errors.d.ts +1 -1
- package/dist/esm/datasource/index.d.ts +5 -5
- package/dist/esm/datasource/retry/RetryState.d.ts +3 -3
- package/dist/esm/datasource/retry/index.d.ts +2 -2
- package/dist/esm/index.d.ts +11 -11
- package/dist/esm/index.mjs +105 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internal/context/index.d.ts +1 -1
- package/dist/esm/internal/diagnostics/DiagnosticsManager.d.ts +2 -2
- package/dist/esm/internal/diagnostics/index.d.ts +1 -1
- package/dist/esm/internal/evaluation/EventFactoryBase.d.ts +4 -3
- package/dist/esm/internal/evaluation/EventFactoryBase.d.ts.map +1 -1
- package/dist/esm/internal/evaluation/index.d.ts +2 -2
- package/dist/esm/internal/events/EventProcessor.d.ts +6 -6
- package/dist/esm/internal/events/EventProcessor.d.ts.map +1 -1
- package/dist/esm/internal/events/EventSender.d.ts +3 -3
- package/dist/esm/internal/events/InputClickEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputCustomEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputEvalEvent.d.ts +9 -3
- package/dist/esm/internal/events/InputEvalEvent.d.ts.map +1 -1
- package/dist/esm/internal/events/InputEvent.d.ts +6 -6
- package/dist/esm/internal/events/InputEventBase.d.ts +1 -1
- package/dist/esm/internal/events/InputIdentifyEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputMigrationEvent.d.ts +1 -1
- package/dist/esm/internal/events/InputPageViewEvent.d.ts +1 -1
- package/dist/esm/internal/events/LDEventSummarizer.d.ts +1 -1
- package/dist/esm/internal/events/LDEventSummarizer.d.ts.map +1 -1
- package/dist/esm/internal/events/MultiEventSummarizer.d.ts +4 -4
- package/dist/esm/internal/events/NullEventProcessor.d.ts +1 -1
- package/dist/esm/internal/events/guards.d.ts +4 -4
- package/dist/esm/internal/events/index.d.ts +10 -10
- package/dist/esm/internal/fdv2/FDv1PayloadAdaptor.d.ts +1 -1
- package/dist/esm/internal/fdv2/index.d.ts +8 -8
- package/dist/esm/internal/fdv2/payloadProcessor.d.ts +4 -4
- package/dist/esm/internal/fdv2/payloadStreamReader.d.ts +3 -3
- package/dist/esm/internal/fdv2/protocolHandler.d.ts +2 -2
- package/dist/esm/internal/fdv2/protocolHandler.d.ts.map +1 -1
- package/dist/esm/internal/fetch/StreamingResponse.d.ts +1 -1
- package/dist/esm/internal/fetch/followRedirects.d.ts +34 -0
- package/dist/esm/internal/fetch/followRedirects.d.ts.map +1 -0
- package/dist/esm/internal/fetch/index.d.ts +3 -2
- package/dist/esm/internal/fetch/index.d.ts.map +1 -1
- package/dist/esm/internal/fetch/toRequestInit.d.ts +1 -1
- package/dist/esm/internal/index.d.ts +9 -9
- package/dist/esm/internal/json/index.d.ts +1 -1
- package/dist/esm/internal/metadata/index.d.ts +1 -1
- package/dist/esm/internal/plugins/index.d.ts +3 -3
- package/dist/esm/internal/plugins/safeGetHooks.d.ts +2 -2
- package/dist/esm/internal/plugins/safeGetName.d.ts +2 -2
- package/dist/esm/internal/plugins/safeRegisterPlugins.d.ts +2 -2
- package/dist/esm/logging/BasicLogger.d.ts +1 -1
- package/dist/esm/logging/SafeLogger.d.ts +1 -1
- package/dist/esm/logging/createSafeLogger.d.ts +3 -3
- package/dist/esm/logging/index.d.ts +3 -3
- package/dist/esm/options/ApplicationTags.d.ts +1 -1
- package/dist/esm/options/ClientContext.d.ts +3 -3
- package/dist/esm/options/index.d.ts +4 -4
- package/dist/esm/utils/cancelableTimedPromise.d.ts +1 -1
- package/dist/esm/utils/http.d.ts +2 -2
- package/dist/esm/utils/index.d.ts +12 -12
- package/package.json +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -2738,12 +2738,13 @@ function isMigration(u) {
|
|
|
2738
2738
|
* @internal
|
|
2739
2739
|
*/
|
|
2740
2740
|
class SummaryCounter {
|
|
2741
|
-
constructor(count, key, value, defValue, version, variation) {
|
|
2741
|
+
constructor(count, key, value, defValue, version, variation, overrideAffected) {
|
|
2742
2742
|
this.count = count;
|
|
2743
2743
|
this.key = key;
|
|
2744
2744
|
this.value = value;
|
|
2745
2745
|
this.version = version;
|
|
2746
2746
|
this.variation = variation;
|
|
2747
|
+
this.overrideAffected = overrideAffected;
|
|
2747
2748
|
this.default = defValue;
|
|
2748
2749
|
}
|
|
2749
2750
|
increment() {
|
|
@@ -2751,8 +2752,10 @@ class SummaryCounter {
|
|
|
2751
2752
|
}
|
|
2752
2753
|
}
|
|
2753
2754
|
|
|
2755
|
+
// The override marker is part of the key, so override-affected and other evaluations of the same
|
|
2756
|
+
// flag, variation, and version accumulate into separate counters.
|
|
2754
2757
|
function counterKey(event) {
|
|
2755
|
-
return `${event.key}:${event.variation !== null && event.variation !== undefined ? event.variation : ''}:${event.version !== null && event.version !== undefined ? event.version : ''}`;
|
|
2758
|
+
return `${event.key}:${event.variation !== null && event.variation !== undefined ? event.variation : ''}:${event.version !== null && event.version !== undefined ? event.version : ''}:${event.overrideAffected ? 'overrideAffected' : ''}`;
|
|
2756
2759
|
}
|
|
2757
2760
|
/**
|
|
2758
2761
|
* @internal
|
|
@@ -2783,7 +2786,7 @@ class EventSummarizer {
|
|
|
2783
2786
|
counter.increment();
|
|
2784
2787
|
}
|
|
2785
2788
|
else {
|
|
2786
|
-
this._counters[countKey] = new SummaryCounter(1, event.key, event.value, event.default, event.version, event.variation);
|
|
2789
|
+
this._counters[countKey] = new SummaryCounter(1, event.key, event.value, event.default, event.version, event.variation, event.overrideAffected);
|
|
2787
2790
|
}
|
|
2788
2791
|
if (this._startDate === 0 || event.creationDate < this._startDate) {
|
|
2789
2792
|
this._startDate = event.creationDate;
|
|
@@ -2817,6 +2820,10 @@ class EventSummarizer {
|
|
|
2817
2820
|
else {
|
|
2818
2821
|
counterOut.unknown = true;
|
|
2819
2822
|
}
|
|
2823
|
+
if (counter.overrideAffected) {
|
|
2824
|
+
// The marker is present only when true, like the unknown marker.
|
|
2825
|
+
counterOut.overrideAffected = true;
|
|
2826
|
+
}
|
|
2820
2827
|
flagSummary.counters.push(counterOut);
|
|
2821
2828
|
return acc;
|
|
2822
2829
|
}, {});
|
|
@@ -3021,8 +3028,11 @@ class EventProcessor {
|
|
|
3021
3028
|
}
|
|
3022
3029
|
this._summarizer.summarizeEvent(inputEvent);
|
|
3023
3030
|
const isFeatureEvent = isFeature(inputEvent);
|
|
3024
|
-
|
|
3025
|
-
|
|
3031
|
+
// An override-affected evaluation appears only in the summary counters. It produces no
|
|
3032
|
+
// individual feature event and no debug event, even when the flag requests them.
|
|
3033
|
+
const overrideAffected = isFeatureEvent && !!inputEvent.overrideAffected;
|
|
3034
|
+
const addFullEvent = (isFeatureEvent && inputEvent.trackEvents && !overrideAffected) || !isFeatureEvent;
|
|
3035
|
+
const addDebugEvent = !overrideAffected && this._shouldDebugEvent(inputEvent);
|
|
3026
3036
|
const isIdentifyEvent = isIdentify(inputEvent);
|
|
3027
3037
|
const shouldNotDeduplicate = this._contextDeduplicator?.processContext(inputEvent.context);
|
|
3028
3038
|
// If there is no cache, then it will never be in the cache.
|
|
@@ -3188,7 +3198,7 @@ class InputCustomEvent {
|
|
|
3188
3198
|
|
|
3189
3199
|
class InputEvalEvent {
|
|
3190
3200
|
constructor(withReasons, context, key, value, defValue, // default is a reserved keyword in this context.
|
|
3191
|
-
version, variation, trackEvents, prereqOf, reason, debugEventsUntilDate, excludeFromSummaries, samplingRatio = 1) {
|
|
3201
|
+
version, variation, trackEvents, prereqOf, reason, debugEventsUntilDate, excludeFromSummaries, samplingRatio = 1, overrideAffected) {
|
|
3192
3202
|
this.withReasons = withReasons;
|
|
3193
3203
|
this.context = context;
|
|
3194
3204
|
this.key = key;
|
|
@@ -3218,6 +3228,9 @@ class InputEvalEvent {
|
|
|
3218
3228
|
if (excludeFromSummaries !== undefined) {
|
|
3219
3229
|
this.excludeFromSummaries = excludeFromSummaries;
|
|
3220
3230
|
}
|
|
3231
|
+
if (overrideAffected !== undefined) {
|
|
3232
|
+
this.overrideAffected = overrideAffected;
|
|
3233
|
+
}
|
|
3221
3234
|
}
|
|
3222
3235
|
}
|
|
3223
3236
|
|
|
@@ -3245,7 +3258,7 @@ class EventFactoryBase {
|
|
|
3245
3258
|
evalEvent(e) {
|
|
3246
3259
|
return new InputEvalEvent(this._withReasons, e.context, e.flagKey, e.value, e.defaultVal, e.version,
|
|
3247
3260
|
// Exclude null as a possibility.
|
|
3248
|
-
e.variation ?? undefined, e.trackEvents || e.addExperimentData, e.prereqOfFlagKey, this._withReasons || e.addExperimentData ? e.reason : undefined, e.debugEventsUntilDate, e.excludeFromSummaries, e.samplingRatio);
|
|
3261
|
+
e.variation ?? undefined, e.trackEvents || e.addExperimentData, e.prereqOfFlagKey, this._withReasons || e.addExperimentData ? e.reason : undefined, e.debugEventsUntilDate, e.excludeFromSummaries, e.samplingRatio, e.overrideAffected);
|
|
3249
3262
|
}
|
|
3250
3263
|
unknownFlagEvent(key, defVal, context) {
|
|
3251
3264
|
return new InputEvalEvent(this._withReasons, context, key, defVal, defVal,
|
|
@@ -3385,6 +3398,11 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3385
3398
|
let protocolState = 'inactive';
|
|
3386
3399
|
let tempType = 'partial';
|
|
3387
3400
|
let tempUpdates = [];
|
|
3401
|
+
// Only kinds with a registered processor are supported. An own-property check keeps
|
|
3402
|
+
// kinds such as 'constructor' from resolving to inherited members.
|
|
3403
|
+
function isSupportedKind(kind) {
|
|
3404
|
+
return Object.prototype.hasOwnProperty.call(objProcessors, kind);
|
|
3405
|
+
}
|
|
3388
3406
|
function processObj(kind, jsonObj) {
|
|
3389
3407
|
return objProcessors[kind]?.(jsonObj);
|
|
3390
3408
|
}
|
|
@@ -3455,6 +3473,12 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3455
3473
|
logger?.warn(`Ignoring put-object with missing fields: kind=${data.kind}, key=${data.key}, version=${data.version}`);
|
|
3456
3474
|
return ACTION_NONE;
|
|
3457
3475
|
}
|
|
3476
|
+
// Objects of unsupported kinds are dropped silently so the protocol can add new kinds
|
|
3477
|
+
// without disrupting older SDKs.
|
|
3478
|
+
if (!isSupportedKind(data.kind)) {
|
|
3479
|
+
logger?.debug(`Ignoring put-object with unsupported kind: '${data.kind}'`);
|
|
3480
|
+
return ACTION_NONE;
|
|
3481
|
+
}
|
|
3458
3482
|
const obj = processObj(data.kind, data.object);
|
|
3459
3483
|
if (!obj) {
|
|
3460
3484
|
logger?.warn(`Unable to process object for kind: '${data.kind}'`);
|
|
@@ -3477,6 +3501,10 @@ function createProtocolHandler(objProcessors, logger) {
|
|
|
3477
3501
|
logger?.warn(`Ignoring delete-object with missing fields: kind=${data.kind}, key=${data.key}, version=${data.version}`);
|
|
3478
3502
|
return ACTION_NONE;
|
|
3479
3503
|
}
|
|
3504
|
+
if (!isSupportedKind(data.kind)) {
|
|
3505
|
+
logger?.debug(`Ignoring delete-object with unsupported kind: '${data.kind}'`);
|
|
3506
|
+
return ACTION_NONE;
|
|
3507
|
+
}
|
|
3480
3508
|
tempUpdates.push({
|
|
3481
3509
|
kind: data.kind,
|
|
3482
3510
|
key: data.key,
|
|
@@ -3659,6 +3687,74 @@ class PayloadStreamReader {
|
|
|
3659
3687
|
}
|
|
3660
3688
|
}
|
|
3661
3689
|
|
|
3690
|
+
/**
|
|
3691
|
+
* The most redirect hops one streaming request follows. When a chain exceeds the cap, the last
|
|
3692
|
+
* redirect response goes to the caller as an ordinary non-200 response. The caller's error
|
|
3693
|
+
* handling decides whether to retry.
|
|
3694
|
+
*/
|
|
3695
|
+
const MAX_STREAMING_REDIRECT_HOPS = 5;
|
|
3696
|
+
/**
|
|
3697
|
+
* Resolves the target of a redirect response. The target can be relative, and it resolves
|
|
3698
|
+
* against the URL of the redirected request. Only an `http:` or `https:` target can carry
|
|
3699
|
+
* the stream; any other scheme, a missing or empty `Location`, and an unparsable value all
|
|
3700
|
+
* resolve to `undefined`, and the redirect response then goes to the caller unfollowed.
|
|
3701
|
+
*/
|
|
3702
|
+
function redirectTarget(headers, baseUrl) {
|
|
3703
|
+
const raw = headers.location;
|
|
3704
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
3705
|
+
if (typeof value !== 'string' || value === '') {
|
|
3706
|
+
return undefined;
|
|
3707
|
+
}
|
|
3708
|
+
try {
|
|
3709
|
+
const resolved = new URL(value, baseUrl);
|
|
3710
|
+
if (resolved.protocol !== 'http:' && resolved.protocol !== 'https:') {
|
|
3711
|
+
return undefined;
|
|
3712
|
+
}
|
|
3713
|
+
return resolved.href;
|
|
3714
|
+
}
|
|
3715
|
+
catch {
|
|
3716
|
+
return undefined;
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
/**
|
|
3720
|
+
* Issues a streaming request and follows up to {@link MAX_STREAMING_REDIRECT_HOPS} hops of
|
|
3721
|
+
* `301` and `307` redirects. Each hop calls `doRequest` again with the target URL, so the
|
|
3722
|
+
* request carries the same method, body, and headers to each target, the `Authorization`
|
|
3723
|
+
* header included. A `302` and every other status return to the caller unfollowed.
|
|
3724
|
+
*
|
|
3725
|
+
* The loop holds no state across calls. A reconnect starts from the original URL again and
|
|
3726
|
+
* re-follows the chain.
|
|
3727
|
+
*
|
|
3728
|
+
* @param url The URL of the initial request.
|
|
3729
|
+
* @param doRequest Issues one request and resolves with its response. The caller builds the
|
|
3730
|
+
* options inside it from the given URL, so each hop gets options for its own target.
|
|
3731
|
+
*/
|
|
3732
|
+
async function followStreamingRedirects(url, doRequest) {
|
|
3733
|
+
let currentUrl = url;
|
|
3734
|
+
let res = await doRequest(currentUrl);
|
|
3735
|
+
let hops = 0;
|
|
3736
|
+
while ((res.statusCode === 301 || res.statusCode === 307) && hops < MAX_STREAMING_REDIRECT_HOPS) {
|
|
3737
|
+
const target = redirectTarget(res.headers, currentUrl);
|
|
3738
|
+
if (target === undefined) {
|
|
3739
|
+
return res;
|
|
3740
|
+
}
|
|
3741
|
+
hops += 1;
|
|
3742
|
+
// The destroy releases the skipped redirect response and its connection at once, so a
|
|
3743
|
+
// redirect body that never ends cannot hold a socket for the life of the attempt.
|
|
3744
|
+
try {
|
|
3745
|
+
res.destroy?.();
|
|
3746
|
+
}
|
|
3747
|
+
catch {
|
|
3748
|
+
// A throwing destroy has nothing left to release.
|
|
3749
|
+
}
|
|
3750
|
+
currentUrl = target;
|
|
3751
|
+
// The hops are sequential. The next request cannot start until this response arrives.
|
|
3752
|
+
// eslint-disable-next-line no-await-in-loop
|
|
3753
|
+
res = await doRequest(currentUrl);
|
|
3754
|
+
}
|
|
3755
|
+
return res;
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3662
3758
|
/**
|
|
3663
3759
|
* Wraps the raw headers in the fetch `Headers` shape. Lookups are case-insensitive.
|
|
3664
3760
|
* Multi-value headers are joined with ", ", names that differ only by case merge into one
|
|
@@ -3859,12 +3955,14 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
3859
3955
|
InputCustomEvent: InputCustomEvent,
|
|
3860
3956
|
InputEvalEvent: InputEvalEvent,
|
|
3861
3957
|
InputIdentifyEvent: InputIdentifyEvent,
|
|
3958
|
+
MAX_STREAMING_REDIRECT_HOPS: MAX_STREAMING_REDIRECT_HOPS,
|
|
3862
3959
|
NullEventProcessor: NullEventProcessor,
|
|
3863
3960
|
PayloadProcessor: PayloadProcessor,
|
|
3864
3961
|
PayloadStreamReader: PayloadStreamReader,
|
|
3865
3962
|
canonicalize: canonicalize,
|
|
3866
3963
|
createProtocolHandler: createProtocolHandler,
|
|
3867
3964
|
createStreamingResponse: createStreamingResponse,
|
|
3965
|
+
followStreamingRedirects: followStreamingRedirects,
|
|
3868
3966
|
initMetadataFromHeaders: initMetadataFromHeaders,
|
|
3869
3967
|
isLegacyUser: isLegacyUser,
|
|
3870
3968
|
isMultiKind: isMultiKind,
|