Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unleash-client

Package Overview
Dependencies
Maintainers
0
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unleash-client - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0-alpha.0

examples/streaming.js

2

lib/details.json

@@ -1,1 +0,1 @@

{ "name": "unleash-client-node", "version": "6.2.0", "sdkVersion": "unleash-client-node:6.2.0" }
{ "name": "unleash-client-node", "version": "6.3.0-alpha.0", "sdkVersion": "unleash-client-node:6.3.0-alpha.0" }

@@ -9,2 +9,3 @@ import { EventEmitter } from 'events';

import { Segment } from '../strategy/strategy';
import { EventSource } from 'launchdarkly-eventsource';
export declare const SUPPORTED_SPEC_VERSION = "4.3.0";

@@ -34,2 +35,3 @@ export interface RepositoryInterface extends EventEmitter {

storageProvider: StorageProvider<ClientFeaturesResponse>;
eventSource?: EventSource;
}

@@ -59,3 +61,4 @@ export default class Repository extends EventEmitter implements EventEmitter {

private segments;
constructor({ url, appName, instanceId, projectName, refreshInterval, timeout, headers, customHeadersFunction, httpOptions, namePrefix, tags, bootstrapProvider, bootstrapOverride, storageProvider, }: RepositoryOptions);
private eventSource;
constructor({ url, appName, instanceId, projectName, refreshInterval, timeout, headers, customHeadersFunction, httpOptions, namePrefix, tags, bootstrapProvider, bootstrapOverride, storageProvider, eventSource, }: RepositoryOptions);
timedFetch(interval: number): void;

@@ -62,0 +65,0 @@ validateFeature(feature: FeatureInterface): void;

@@ -10,3 +10,3 @@ "use strict";

class Repository extends events_1.EventEmitter {
constructor({ url, appName, instanceId, projectName, refreshInterval = 15000, timeout, headers, customHeadersFunction, httpOptions, namePrefix, tags, bootstrapProvider, bootstrapOverride = true, storageProvider, }) {
constructor({ url, appName, instanceId, projectName, refreshInterval = 15000, timeout, headers, customHeadersFunction, httpOptions, namePrefix, tags, bootstrapProvider, bootstrapOverride = true, storageProvider, eventSource, }) {
super();

@@ -40,5 +40,27 @@ this.failures = 0;

this.segments = new Map();
this.eventSource = eventSource;
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);
}
catch (err) {
this.emit(events_2.UnleashEvents.Error, err);
}
});
this.eventSource.addEventListener('error', (error) => {
this.emit(events_2.UnleashEvents.Warn, error);
});
}
}
timedFetch(interval) {
if (interval > 0) {
if (interval > 0 && !this.eventSource) {
this.timer = setTimeout(() => this.fetch(), interval);

@@ -282,2 +304,5 @@ if (process.env.NODE_ENV !== 'test' && typeof this.timer.unref === 'function') {

this.removeAllListeners();
if (this.eventSource) {
this.eventSource.close();
}
}

@@ -284,0 +309,0 @@ getSegment(segmentId) {

@@ -9,2 +9,7 @@ import { CustomHeaders, CustomHeadersFunction } from './headers';

import { RepositoryInterface } from './repository';
export type Mode = {
type: 'polling';
} | {
type: 'streaming';
};
export interface UnleashConfig {

@@ -34,3 +39,4 @@ appName: string;

skipInstanceCountWarning?: boolean;
experimentalMode?: Mode;
}
//# sourceMappingURL=unleash-config.d.ts.map

@@ -25,3 +25,3 @@ import { EventEmitter } from 'events';

private started;
constructor({ appName, environment, projectName, instanceId, url, refreshInterval, metricsInterval, metricsJitter, disableMetrics, backupPath, strategies, repository, namePrefix, customHeaders, customHeadersFunction, timeout, httpOptions, tags, bootstrap, bootstrapOverride, storageProvider, disableAutoStart, skipInstanceCountWarning, }: UnleashConfig);
constructor({ appName, environment, projectName, instanceId, url, refreshInterval, metricsInterval, metricsJitter, disableMetrics, backupPath, strategies, repository, namePrefix, customHeaders, customHeadersFunction, timeout, httpOptions, tags, bootstrap, bootstrapOverride, storageProvider, disableAutoStart, skipInstanceCountWarning, experimentalMode, }: UnleashConfig);
/**

@@ -28,0 +28,0 @@ * Will only give you an instance the first time you call the method,

@@ -17,5 +17,8 @@ "use strict";

const storage_provider_file_1 = require("./repository/storage-provider-file");
const url_utils_1 = require("./url-utils");
// @ts-expect-error
const launchdarkly_eventsource_1 = require("launchdarkly-eventsource");
const BACKUP_PATH = (0, os_1.tmpdir)();
class Unleash extends events_1.EventEmitter {
constructor({ appName, environment = 'default', projectName, instanceId, url, refreshInterval = 15 * 1000, metricsInterval = 60 * 1000, metricsJitter = 0, disableMetrics = false, backupPath = BACKUP_PATH, strategies = [], repository, namePrefix, customHeaders, customHeadersFunction, timeout, httpOptions, tags, bootstrap = {}, bootstrapOverride, storageProvider, disableAutoStart = false, skipInstanceCountWarning = false, }) {
constructor({ appName, environment = 'default', projectName, instanceId, url, refreshInterval = 15 * 1000, metricsInterval = 60 * 1000, metricsJitter = 0, disableMetrics = false, backupPath = BACKUP_PATH, strategies = [], repository, namePrefix, customHeaders, customHeadersFunction, timeout, httpOptions, tags, bootstrap = {}, bootstrapOverride, storageProvider, disableAutoStart = false, skipInstanceCountWarning = false, experimentalMode = { type: 'polling' }, }) {
super();

@@ -64,2 +67,12 @@ this.synchronized = false;

bootstrapOverride,
eventSource: (experimentalMode === null || experimentalMode === void 0 ? void 0 : experimentalMode.type) === 'streaming'
? new launchdarkly_eventsource_1.EventSource((0, url_utils_1.resolveUrl)(unleashUrl, './client/streaming'), {
headers: customHeaders,
readTimeoutMillis: 60000, // start a new SSE connection when no heartbeat received in 1 minute
initialRetryDelayMillis: 2000,
maxBackoffMillis: 30000,
retryResetIntervalMillis: 60000,
jitterRatio: 0.5,
})
: undefined,
storageProvider: storageProvider || new storage_provider_file_1.default(backupPath),

@@ -66,0 +79,0 @@ });

{
"name": "unleash-client",
"version": "6.2.0",
"version": "6.3.0-alpha.0",
"description": "Unleash Client for Node",

@@ -36,2 +36,3 @@ "license": "Apache-2.0",

"ip-address": "^9.0.5",
"launchdarkly-eventsource": "2.0.3",
"make-fetch-happen": "^13.0.1",

@@ -54,2 +55,3 @@ "murmurhash3js": "^3.0.1",

"@tsconfig/node12": "^12.0.0",
"@types/eventsource": "^1.1.15",
"@types/express": "^4.17.17",

@@ -56,0 +58,0 @@ "@types/jsbn": "^1.2.33",

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc