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

launchdarkly-js-sdk-common

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

launchdarkly-js-sdk-common - npm Package Compare versions

Comparing version 4.0.2 to 4.0.3

2

package.json
{
"name": "launchdarkly-js-sdk-common",
"version": "4.0.2",
"version": "4.0.3",
"description": "LaunchDarkly SDK for JavaScript - common code",

@@ -5,0 +5,0 @@ "author": "LaunchDarkly <team@launchdarkly.com>",

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

import * as messages from '../messages';
import * as utils from '../utils';

@@ -653,2 +654,34 @@

describe('emits error if malformed JSON is received', () => {
const doMalformedJsonEventTest = async (eventName, eventData) => {
// First, verify that there isn't an unhandled rejection if we're not listening for an error
await withClientAndServer({}, async client => {
await client.waitForInitialization();
client.setStreaming(true);
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
stream.eventSource.mockEmit(eventName, { data: eventData });
});
// Then, repeat the test using a listener to observe the error event
await withClientAndServer({}, async client => {
const errorEvents = new AsyncQueue();
client.on('error', e => errorEvents.add(e));
await client.waitForInitialization();
client.setStreaming(true);
const stream = await expectStreamConnecting(fullStreamUrlWithUser);
stream.eventSource.mockEmit(eventName, { data: eventData });
const e = await errorEvents.take();
expect(e.message).toEqual(messages.invalidData());
});
};
it('in put event', async () => doMalformedJsonEventTest('put', '{no'));
it('in patch event', async () => doMalformedJsonEventTest('patch', '{no'));
it('in delete event', async () => doMalformedJsonEventTest('delete', '{no'));
});
it('reconnects to stream if the user changes', async () => {

@@ -655,0 +688,0 @@ const user2 = { key: 'user2' };

@@ -21,2 +21,3 @@ function createCustomError(name) {

const LDFlagFetchError = createCustomError('LaunchDarklyFlagFetchError');
const LDInvalidDataError = createCustomError('LaunchDarklyInvalidDataError');

@@ -36,4 +37,5 @@ function isHttpErrorRecoverable(status) {

LDInvalidArgumentError,
LDInvalidDataError,
LDFlagFetchError,
isHttpErrorRecoverable,
};

@@ -389,2 +389,10 @@ const EventProcessor = require('./EventProcessor');

}
const tryParseData = jsonData => {
try {
return JSON.parse(jsonData);
} catch (err) {
emitter.maybeReportError(new errors.LDInvalidDataError(messages.invalidData()));
return undefined;
}
};
stream.connect(ident.getUser(), hash, {

@@ -408,8 +416,16 @@ ping: function() {

put: function(e) {
const data = JSON.parse(e.data);
const data = tryParseData(e.data);
if (!data) {
return;
}
logger.debug(messages.debugStreamPut());
replaceAllFlags(data); // don't wait for this Promise to be resolved
replaceAllFlags(data);
// Don't wait for this Promise to be resolved; note that replaceAllFlags is guaranteed
// never to have an unhandled rejection
},
patch: function(e) {
const data = JSON.parse(e.data);
const data = tryParseData(e.data);
if (!data) {
return;
}
// If both the flag and the patch have a version property, then the patch version must be

@@ -437,3 +453,6 @@ // greater than the flag version for us to accept the patch. If either one has no version

delete: function(e) {
const data = JSON.parse(e.data);
const data = tryParseData(e.data);
if (!data) {
return;
}
if (!flags[data.key] || flags[data.key].version < data.version) {

@@ -440,0 +459,0 @@ logger.debug(messages.debugStreamDelete(data.key));

@@ -71,2 +71,6 @@ const errors = require('./errors');

const invalidData = function() {
return 'Invalid data received from LaunchDarkly; connection may have been interrupted';
};
const bootstrapOldFormat = function() {

@@ -205,2 +209,3 @@ return (

invalidContentType,
invalidData,
invalidKey,

@@ -207,0 +212,0 @@ invalidUser,

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