Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
prepare 5.5.0 release (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly authored Oct 8, 2018
1 parent a4dc34f commit d273e60
Show file tree
Hide file tree
Showing 10 changed files with 1,207 additions and 553 deletions.
2 changes: 1 addition & 1 deletion feature_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function InMemoryFeatureStore() {
var items = this.allData[kind.namespace];
if (!items) {
items = {};
this.allData[kind] = items;
this.allData[kind.namespace] = items;
}

if (Object.hasOwnProperty.call(items, key)) {
Expand Down
19 changes: 11 additions & 8 deletions flags_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ function FlagsStateBuilder(valid) {
var flagValues = {};
var flagMetadata = {};

builder.addFlag = function(flag, value, variation, reason) {
builder.addFlag = function(flag, value, variation, reason, detailsOnlyIfTracked) {
flagValues[flag.key] = value;
var meta = {
version: flag.version,
trackEvents: flag.trackEvents
};
var meta = {};
if (!detailsOnlyIfTracked || flag.trackEvents || flag.debugEventsUntilDate) {
meta.version = flag.version;
if (reason) {
meta.reason = reason;
}
}
if (variation !== undefined && variation !== null) {
meta.variation = variation;
}
if (flag.trackEvents) {
meta.trackEvents = true;
}
if (flag.debugEventsUntilDate !== undefined && flag.debugEventsUntilDate !== null) {
meta.debugEventsUntilDate = flag.debugEventsUntilDate;
}
if (reason) {
meta.reason = reason;
}
flagMetadata[flag.key] = meta;
};

Expand Down
11 changes: 11 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,17 @@ declare module 'ldclient-node' {
* client-side SDK. By default, all flags are included.
*/
clientSideOnly?: boolean;
/**
* True if evaluation reason data should be captured in the state object (see LDClient.variationDetail).
* By default, it is not.
*/
withReasons?: boolean;
/**
* True if any flag metadata that is normally only used for event generation - such as flag versions and
* evaluation reasons - should be omitted for any flag that does not have event tracking or debugging turned on.
* This reduces the size of the JSON data if you are passing the flag state to the front end.
*/
detailsOnlyForTrackedFlags?: boolean;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ var newClient = function(sdkKey, config) {
var builder = FlagsStateBuilder(true);
var clientOnly = options.clientSideOnly;
var withReasons = options.withReasons;
var detailsOnlyIfTracked = options.detailsOnlyForTrackedFlags;
config.featureStore.all(dataKind.features, function(flags) {
async.forEachOf(flags, function(flag, key, iterateeCb) {
if (clientOnly && !flag.clientSide) {
Expand All @@ -299,7 +300,7 @@ var newClient = function(sdkKey, config) {
if (err != null) {
maybeReportError(new Error('Error for feature flag "' + flag.key + '" while evaluating all flags: ' + err));
}
builder.addFlag(flag, detail.value, detail.variationIndex, withReasons ? detail.reason : null);
builder.addFlag(flag, detail.value, detail.variationIndex, withReasons ? detail.reason : null, detailsOnlyIfTracked);
setImmediate(iterateeCb);
});
}
Expand Down
40 changes: 33 additions & 7 deletions streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ var errors = require('./errors');
var EventSource = require('./eventsource');
var dataKind = require('./versioned_data_kind');

function StreamProcessor(sdkKey, config, requestor) {
function StreamProcessor(sdkKey, config, requestor, eventSourceFactory) {
var processor = {},
featureStore = config.featureStore,
es;

eventSourceFactory = eventSourceFactory || EventSource;

function getKeyFromPath(kind, path) {
return path.startsWith(kind.streamApiPath) ? path.substring(kind.streamApiPath.length) : null;
}

processor.start = function(fn) {
var cb = fn || function(){};
es = new EventSource(config.streamUri + "/all",
es = new eventSourceFactory(config.streamUri + "/all",
{
agent: config.proxyAgent,
headers: {'Authorization': sdkKey,'User-Agent': config.userAgent}
Expand All @@ -24,10 +26,22 @@ function StreamProcessor(sdkKey, config, requestor) {
cb(new errors.LDStreamingError(err.message, err.code));
};

function reportJsonError(type, data) {
config.logger.error('Stream received invalid data in "' + type + '" message');
config.logger.debug('Invalid JSON follows: ' + data);
cb(new errors.LDStreamingError('Malformed JSON data in event stream'));
}

es.addEventListener('put', function(e) {
config.logger.debug('Received put event');
if (e && e.data) {
var all = JSON.parse(e.data);
var all;
try {
all = JSON.parse(e.data);
} catch (err) {
reportJsonError('put', e.data);
return;
}
var initData = {};
initData[dataKind.features.namespace] = all.data.flags;
initData[dataKind.segments.namespace] = all.data.segments;
Expand All @@ -42,7 +56,13 @@ function StreamProcessor(sdkKey, config, requestor) {
es.addEventListener('patch', function(e) {
config.logger.debug('Received patch event');
if (e && e.data) {
var patch = JSON.parse(e.data);
var patch;
try {
patch = JSON.parse(e.data);
} catch (err) {
reportJsonError('patch', e.data);
return;
}
for (var k in dataKind) {
var kind = dataKind[k];
var key = getKeyFromPath(kind, patch.path);
Expand All @@ -60,8 +80,14 @@ function StreamProcessor(sdkKey, config, requestor) {
es.addEventListener('delete', function(e) {
config.logger.debug('Received delete event');
if (e && e.data) {
var data = JSON.parse(e.data),
version = data.version;
var data, version;
try {
data = JSON.parse(e.data);
} catch (err) {
reportJsonError('delete', e.data);
return;
}
version = data.version;
for (var k in dataKind) {
var kind = dataKind[k];
var key = getKeyFromPath(kind, data.path);
Expand All @@ -78,7 +104,7 @@ function StreamProcessor(sdkKey, config, requestor) {

es.addEventListener('indirect/put', function(e) {
config.logger.debug('Received indirect put event')
requestor.requestAllFlags(function (err, resp) {
requestor.requestAllData(function (err, resp) {
if (err) {
cb(err);
} else {
Expand Down
Loading

0 comments on commit d273e60

Please sign in to comment.