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

@launchdarkly/js-server-sdk-common

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@launchdarkly/js-server-sdk-common - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0

18

CHANGELOG.md

@@ -5,2 +5,20 @@ # Changelog

## [2.0.0](https://github.com/launchdarkly/js-core/compare/js-server-sdk-common-v1.2.3...js-server-sdk-common-v2.0.0) (2023-10-16)
### ⚠ BREAKING CHANGES
* Implement Migrations. Refactor for client SDKs. ([#293](https://github.com/launchdarkly/js-core/issues/293))
### Features
* Implement Migrations. Refactor for client SDKs. ([#293](https://github.com/launchdarkly/js-core/issues/293)) ([c66aa6e](https://github.com/launchdarkly/js-core/commit/c66aa6ea0d12e1e4e565cb8378d367c31fab9c1b))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @launchdarkly/js-sdk-common bumped from 1.1.0 to 2.0.0
## [1.2.3](https://github.com/launchdarkly/js-core/compare/js-server-sdk-common-v1.2.2...js-server-sdk-common-v1.2.3) (2023-09-06)

@@ -7,0 +25,0 @@

15

dist/evaluation/EvalResult.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const js_sdk_common_1 = require("@launchdarkly/js-sdk-common");
const Reasons_1 = require("./Reasons");
const { createErrorEvaluationDetail, createSuccessEvaluationDetail } = js_sdk_common_1.internal;
/**

@@ -26,14 +28,7 @@ * A class which encapsulates the result of an evaluation. It allows for differentiating between

static forError(errorKind, message, def) {
return new EvalResult(true, {
value: def !== null && def !== void 0 ? def : null,
variationIndex: null,
reason: { kind: 'ERROR', errorKind },
}, message);
return new EvalResult(true, createErrorEvaluationDetail(errorKind, def), message);
}
static forSuccess(value, reason, variationIndex) {
return new EvalResult(false, {
value,
variationIndex: variationIndex === undefined ? null : variationIndex,
reason,
});
const successDetail = createSuccessEvaluationDetail(value, variationIndex, reason);
return new EvalResult(false, successDetail);
}

@@ -40,0 +35,0 @@ }

"use strict";
/* eslint-disable class-methods-use-this */
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable max-classes-per-file */
const js_sdk_common_1 = require("@launchdarkly/js-sdk-common");
const Bucketer_1 = require("./Bucketer");
const collection_1 = require("./collection");
const ErrorKinds_1 = require("./ErrorKinds");
const EvalResult_1 = require("./EvalResult");

@@ -14,2 +15,3 @@ const evalTargets_1 = require("./evalTargets");

const variations_1 = require("./variations");
const { ErrorKinds } = js_sdk_common_1.internal;
const bigSegmentsStatusPriority = {

@@ -130,3 +132,3 @@ HEALTHY: 1,

if (visitedFlags.indexOf(prereq.key) !== -1) {
prereqResult = EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, `Prerequisite of ${flag.key} causing a circular reference.` +
prereqResult = EvalResult_1.default.forError(ErrorKinds.MalformedFlag, `Prerequisite of ${flag.key} causing a circular reference.` +
' This is probably a temporary condition due to an incomplete update.');

@@ -146,5 +148,5 @@ iterCb(true);

// eslint-disable-next-line no-param-reassign
state.events = (_a = state.events) !== null && _a !== void 0 ? _a : [];
(_a = state.events) !== null && _a !== void 0 ? _a : (state.events = []);
if (eventFactory) {
state.events.push(eventFactory.evalEvent(prereqFlag, context, res.detail, null, flag));
state.events.push(eventFactory.evalEventServer(prereqFlag, context, res.detail, null, flag));
}

@@ -191,3 +193,3 @@ if (res.isError) {

if (segmentsVisited.includes(segment.key)) {
errorResult = EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, `Segment rule referencing segment ${segment.key} caused a circular reference. ` +
errorResult = EvalResult_1.default.forError(ErrorKinds.MalformedFlag, `Segment rule referencing segment ${segment.key} caused a circular reference. ` +
'This is probably a temporary condition due to an incomplete update');

@@ -220,3 +222,3 @@ // There was an error, so stop checking further segments.

if (!clause.attributeReference.isValid) {
cb(makeError(EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, 'Invalid attribute reference in clause')));
cb(makeError(EvalResult_1.default.forError(ErrorKinds.MalformedFlag, 'Invalid attribute reference in clause')));
return;

@@ -259,3 +261,3 @@ }

// By spec this field should be defined, but better to be overly cautious.
return EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, 'Fallthrough variation undefined');
return EvalResult_1.default.forError(ErrorKinds.MalformedFlag, 'Fallthrough variation undefined');
}

@@ -273,3 +275,3 @@ if (varOrRollout.variation !== undefined) {

if (!bucketBy.isValid) {
return EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, 'Invalid attribute reference for bucketBy in rollout');
return EvalResult_1.default.forError(ErrorKinds.MalformedFlag, 'Invalid attribute reference for bucketBy in rollout');
}

@@ -303,3 +305,3 @@ const [bucket, hadContext] = this.bucketer.bucket(context, flag.key, bucketBy, flag.salt || '', rollout.contextKind, rollout.seed);

}
return EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, 'Variation/rollout object with no variation or rollout');
return EvalResult_1.default.forError(ErrorKinds.MalformedFlag, 'Variation/rollout object with no variation or rollout');
}

@@ -323,3 +325,3 @@ segmentRuleMatchContext(segment, rule, context, state, segmentsVisited, cb) {

if (!bucketBy.isValid) {
return cb(makeError(EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, 'Invalid attribute reference in clause')));
return cb(makeError(EvalResult_1.default.forError(ErrorKinds.MalformedFlag, 'Invalid attribute reference in clause')));
}

@@ -326,0 +328,0 @@ const [bucket] = this.bucketer.bucket(context, segment.key, bucketBy, segment.salt || '', rule.rolloutContextKind);

@@ -5,4 +5,4 @@ "use strict";

const js_sdk_common_1 = require("@launchdarkly/js-sdk-common");
const ErrorKinds_1 = require("./ErrorKinds");
const EvalResult_1 = require("./EvalResult");
const { ErrorKinds } = js_sdk_common_1.internal;
const KEY_ATTR_REF = new js_sdk_common_1.AttributeReference('key');

@@ -24,3 +24,3 @@ /**

}
return EvalResult_1.default.forError(ErrorKinds_1.default.MalformedFlag, 'Invalid variation index in flag');
return EvalResult_1.default.forError(ErrorKinds.MalformedFlag, 'Invalid variation index in flag');
}

@@ -27,0 +27,0 @@ exports.getVariation = getVariation;

@@ -8,37 +8,24 @@ "use strict";

*/
class EventFactory {
constructor(withReasons) {
this.withReasons = withReasons;
}
evalEvent(flag, context, detail, defaultVal, prereqOfFlag) {
class EventFactory extends js_sdk_common_1.internal.EventFactoryBase {
evalEventServer(flag, context, detail, defaultVal, prereqOfFlag) {
var _a;
const addExperimentData = (0, isExperiment_1.default)(flag, detail.reason);
return new js_sdk_common_1.internal.InputEvalEvent(this.withReasons, context, flag.key, defaultVal, detail, flag.version,
// Exclude null as a possibility.
(_a = detail.variationIndex) !== null && _a !== void 0 ? _a : undefined, flag.trackEvents || addExperimentData, prereqOfFlag === null || prereqOfFlag === void 0 ? void 0 : prereqOfFlag.key, this.withReasons || addExperimentData ? detail.reason : undefined, flag.debugEventsUntilDate, flag.excludeFromSummaries, flag.samplingRatio);
return super.evalEvent({
addExperimentData,
context,
debugEventsUntilDate: flag.debugEventsUntilDate,
defaultVal,
excludeFromSummaries: flag.excludeFromSummaries,
flagKey: flag.key,
prereqOfFlagKey: prereqOfFlag === null || prereqOfFlag === void 0 ? void 0 : prereqOfFlag.key,
reason: detail.reason,
samplingRatio: flag.samplingRatio,
trackEvents: flag.trackEvents || addExperimentData,
value: detail.value,
variation: (_a = detail.variationIndex) !== null && _a !== void 0 ? _a : undefined,
version: flag.version,
});
}
unknownFlagEvent(key, context, detail) {
return new js_sdk_common_1.internal.InputEvalEvent(this.withReasons, context, key, detail.value, detail,
// This isn't ideal, but the purpose of the factory is to at least
// handle this situation.
undefined, // version
undefined, // variation index
undefined, // track events
undefined, // prereqOf
undefined, // reason
undefined, // debugEventsUntilDate
undefined, // exclude from summaries
undefined);
}
/* eslint-disable-next-line class-methods-use-this */
identifyEvent(context) {
// Currently sampling for identify events is always 1.
return new js_sdk_common_1.internal.InputIdentifyEvent(context, 1);
}
/* eslint-disable-next-line class-methods-use-this */
customEvent(key, context, data, metricValue, samplingRatio = 1) {
return new js_sdk_common_1.internal.InputCustomEvent(context, key, data !== null && data !== void 0 ? data : undefined, metricValue !== null && metricValue !== void 0 ? metricValue : undefined, samplingRatio);
}
}
exports.default = EventFactory;
//# sourceMappingURL=EventFactory.js.map

@@ -7,3 +7,2 @@ "use strict";

const BigSegmentsManager_1 = require("./BigSegmentsManager");
const ClientMessages_1 = require("./ClientMessages");
const createStreamListeners_1 = require("./data_sources/createStreamListeners");

@@ -15,3 +14,2 @@ const DataSourceUpdates_1 = require("./data_sources/DataSourceUpdates");

const collection_1 = require("./evaluation/collection");
const ErrorKinds_1 = require("./evaluation/ErrorKinds");
const EvalResult_1 = require("./evaluation/EvalResult");

@@ -28,3 +26,3 @@ const Evaluator_1 = require("./evaluation/Evaluator");

const VersionedDataKinds_1 = require("./store/VersionedDataKinds");
const { NullEventProcessor } = js_sdk_common_1.internal;
const { ClientMessages, ErrorKinds, NullEventProcessor } = js_sdk_common_1.internal;
var InitState;

@@ -90,3 +88,3 @@ (function (InitState) {

const makeDefaultProcessor = () => config.stream
? new js_sdk_common_1.internal.StreamingProcessor(sdkKey, clientContext, listeners, this.diagnosticsManager, (e) => this.dataSourceErrorHandler(e), this.config.streamInitialReconnectDelay)
? new js_sdk_common_1.internal.StreamingProcessor(sdkKey, clientContext, '/all', listeners, this.diagnosticsManager, (e) => this.dataSourceErrorHandler(e), this.config.streamInitialReconnectDelay)
: new PollingProcessor_1.default(config, new Requestor_1.default(sdkKey, config, this.platform.info, this.platform.requests), dataSourceUpdates, () => this.initSuccess(), (e) => this.dataSourceErrorHandler(e));

@@ -204,3 +202,3 @@ if (!(config.offline || config.useLdd)) {

kind: 'ERROR',
errorKind: ErrorKinds_1.default.WrongType,
errorKind: ErrorKinds.WrongType,
};

@@ -307,3 +305,3 @@ resolve({

if (!checkedContext.valid) {
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(ClientMessages_1.default.missingContextKeyNoEvent);
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(ClientMessages.missingContextKeyNoEvent);
return;

@@ -324,3 +322,3 @@ }

if (!checkedContext.valid) {
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(ClientMessages_1.default.missingContextKeyNoEvent);
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(ClientMessages.missingContextKeyNoEvent);
return;

@@ -343,3 +341,3 @@ }

(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info('Variation called in offline mode. Returning default value.');
cb(EvalResult_1.default.forError(ErrorKinds_1.default.ClientNotReady, undefined, defaultValue));
cb(EvalResult_1.default.forError(ErrorKinds.ClientNotReady, undefined, defaultValue));
return;

@@ -350,3 +348,3 @@ }

this.onError(new js_sdk_common_1.LDClientError(`${(_b = evalContext.message) !== null && _b !== void 0 ? _b : 'Context not valid;'} returning default value.`));
cb(EvalResult_1.default.forError(ErrorKinds_1.default.UserNotSpecified, undefined, defaultValue));
cb(EvalResult_1.default.forError(ErrorKinds.UserNotSpecified, undefined, defaultValue));
return;

@@ -359,4 +357,4 @@ }

this.onError(error);
const result = EvalResult_1.default.forError(ErrorKinds_1.default.FlagNotFound, undefined, defaultValue);
this.eventProcessor.sendEvent(this.eventFactoryDefault.unknownFlagEvent(flagKey, evalContext, result.detail));
const result = EvalResult_1.default.forError(ErrorKinds.FlagNotFound, undefined, defaultValue);
this.eventProcessor.sendEvent(this.eventFactoryDefault.unknownFlagEvent(flagKey, defaultValue, evalContext));
cb(result);

@@ -375,4 +373,4 @@ return;

if (!matched) {
const errorRes = EvalResult_1.default.forError(ErrorKinds_1.default.WrongType, `Did not receive expected type (${type}) evaluating feature flag "${flagKey}"`, defaultValue);
this.sendEvalEvent(evalRes, eventFactory, flag, evalContext, defaultValue);
const errorRes = EvalResult_1.default.forError(ErrorKinds.WrongType, `Did not receive expected type (${type}) evaluating feature flag "${flagKey}"`, defaultValue);
this.sendEvalEvent(errorRes, eventFactory, flag, evalContext, defaultValue);
cb(errorRes, flag);

@@ -392,3 +390,3 @@ return;

});
this.eventProcessor.sendEvent(eventFactory.evalEvent(flag, evalContext, evalRes.detail, defaultValue, undefined));
this.eventProcessor.sendEvent(eventFactory.evalEventServer(flag, evalContext, evalRes.detail, defaultValue, undefined));
}

@@ -407,3 +405,3 @@ evaluateIfPossible(flagKey, context, defaultValue, eventFactory, cb, typeChecker) {

"'ready' event?) - using default value");
cb(EvalResult_1.default.forError(ErrorKinds_1.default.ClientNotReady, undefined, defaultValue));
cb(EvalResult_1.default.forError(ErrorKinds.ClientNotReady, undefined, defaultValue));
});

@@ -410,0 +408,0 @@ return;

{
"name": "@launchdarkly/js-server-sdk-common",
"version": "2.0.0-alpha.1",
"version": "2.0.0",
"type": "commonjs",

@@ -30,3 +30,3 @@ "main": "./dist/index.js",

"dependencies": {
"@launchdarkly/js-sdk-common": "2.0.0-alpha.1",
"@launchdarkly/js-sdk-common": "2.0.0",
"semver": "7.5.4"

@@ -33,0 +33,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

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