unleash-client
Advanced tools
Comparing version 6.3.1 to 6.3.2
@@ -1,1 +0,1 @@ | ||
{ "name": "unleash-client-node", "version": "6.3.1", "sdkVersion": "unleash-client-node:6.3.1" } | ||
{ "name": "unleash-client-node", "version": "6.3.2", "sdkVersion": "unleash-client-node:6.3.2" } |
@@ -60,3 +60,5 @@ import { EventEmitter } from 'events'; | ||
private eventSource; | ||
private initialEventSourceConnected; | ||
constructor({ url, appName, instanceId, projectName, refreshInterval, timeout, headers, customHeadersFunction, httpOptions, namePrefix, tags, bootstrapProvider, bootstrapOverride, storageProvider, eventSource, }: RepositoryOptions); | ||
private handleFlagsFromStream; | ||
timedFetch(interval: number): void; | ||
@@ -63,0 +65,0 @@ validateFeature(feature: FeatureInterface): void; |
@@ -17,2 +17,3 @@ "use strict"; | ||
this.data = {}; | ||
this.initialEventSourceConnected = false; | ||
this.enhanceStrategies = (strategies) => { | ||
@@ -42,18 +43,13 @@ return strategies === null || strategies === void 0 ? void 0 : strategies.map((strategy) => { | ||
if (this.eventSource) { | ||
this.eventSource.addEventListener('unleash-updated', (event) => { | ||
try { | ||
const data = JSON.parse(event.data); | ||
const etag = data.meta.etag; | ||
if (etag !== null) { | ||
this.etag = etag; | ||
} | ||
else { | ||
this.etag = undefined; | ||
} | ||
this.save(data, true); | ||
// On re-connect it guarantees catching up with the latest state. | ||
this.eventSource.addEventListener('unleash-connected', (event) => { | ||
// reconnect | ||
if (this.initialEventSourceConnected) { | ||
this.handleFlagsFromStream(event); | ||
} | ||
catch (err) { | ||
this.emit(events_2.UnleashEvents.Error, err); | ||
else { | ||
this.initialEventSourceConnected = true; | ||
} | ||
}); | ||
this.eventSource.addEventListener('unleash-updated', this.handleFlagsFromStream.bind(this)); | ||
this.eventSource.addEventListener('error', (error) => { | ||
@@ -64,2 +60,18 @@ this.emit(events_2.UnleashEvents.Warn, error); | ||
} | ||
handleFlagsFromStream(event) { | ||
try { | ||
const data = JSON.parse(event.data); | ||
const etag = data.meta.etag; | ||
if (etag !== null) { | ||
this.etag = etag; | ||
} | ||
else { | ||
this.etag = undefined; | ||
} | ||
this.save(data, true); | ||
} | ||
catch (err) { | ||
this.emit(events_2.UnleashEvents.Error, err); | ||
} | ||
} | ||
timedFetch(interval) { | ||
@@ -90,2 +102,3 @@ if (interval > 0 && !this.eventSource) { | ||
async start() { | ||
// the first fetch is used as a fallback even when streaming is enabled | ||
await Promise.all([this.fetch(), this.loadBackup(), this.loadBootstrap()]); | ||
@@ -92,0 +105,0 @@ } |
@@ -75,2 +75,6 @@ "use strict"; | ||
jitterRatio: 0.5, | ||
errorFilter: function () { | ||
// retry all errors | ||
return true; | ||
}, | ||
}) | ||
@@ -77,0 +81,0 @@ : undefined, |
{ | ||
"name": "unleash-client", | ||
"version": "6.3.1", | ||
"version": "6.3.2", | ||
"description": "Unleash Client for Node", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
240300
3032