@launchdarkly/js-server-sdk-common
Advanced tools
Comparing version 1.4.0-alpha.5 to 2.0.0-alpha.1
@@ -5,2 +5,9 @@ # Changelog | ||
## [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) | ||
### Bug Fixes | ||
* Use clientSideAvailability instead of clientSide for filtering client side flags. ([#270](https://github.com/launchdarkly/js-core/issues/270)) ([2702342](https://github.com/launchdarkly/js-core/commit/27023429d36986466cda46aa4d95eb01c10cd455)) | ||
## [1.2.2](https://github.com/launchdarkly/js-core/compare/js-server-sdk-common-v1.2.1...js-server-sdk-common-v1.2.2) (2023-08-28) | ||
@@ -7,0 +14,0 @@ |
@@ -6,3 +6,2 @@ export * from './data'; | ||
export * from './subsystems/LDFeatureStore'; | ||
export * from './subsystems/LDStreamProcessor'; | ||
export * as integrations from './integrations'; | ||
@@ -9,0 +8,0 @@ export * as interfaces from './interfaces'; |
@@ -23,3 +23,2 @@ "use strict"; | ||
__exportStar(require("./subsystems/LDFeatureStore"), exports); | ||
__exportStar(require("./subsystems/LDStreamProcessor"), exports); | ||
// These are items that should be less frequently used, and therefore they | ||
@@ -26,0 +25,0 @@ // are namespaced to reduce clutter amongst the top level exports. |
@@ -1,4 +0,3 @@ | ||
import { LDClientContext, LDLogger } from '@launchdarkly/js-sdk-common'; | ||
import { LDDataSourceUpdates, LDStreamProcessor } from '../subsystems'; | ||
import { LDFeatureStore } from '../subsystems/LDFeatureStore'; | ||
import { LDClientContext, LDLogger, subsystem, VoidFunction } from '@launchdarkly/js-sdk-common'; | ||
import { LDDataSourceUpdates, LDFeatureStore } from '../subsystems'; | ||
import { LDBigSegmentsOptions } from './LDBigSegmentsOptions'; | ||
@@ -81,3 +80,3 @@ import { LDProxyOptions } from './LDProxyOptions'; | ||
*/ | ||
updateProcessor?: object | ((clientContext: LDClientContext, dataSourceUpdates: LDDataSourceUpdates) => LDStreamProcessor); | ||
updateProcessor?: object | ((clientContext: LDClientContext, dataSourceUpdates: LDDataSourceUpdates, initSuccessHandler: VoidFunction, errorHandler?: (e: Error) => void) => subsystem.LDStreamProcessor); | ||
/** | ||
@@ -84,0 +83,0 @@ * The interval in between flushes of the analytics events queue, in seconds. |
export * from './LDFeatureRequestor'; | ||
export * from './LDFeatureStore'; | ||
export * from './LDStreamProcessor'; | ||
export * from './LDDataSourceUpdates'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -19,4 +19,3 @@ "use strict"; | ||
__exportStar(require("./LDFeatureStore"), exports); | ||
__exportStar(require("./LDStreamProcessor"), exports); | ||
__exportStar(require("./LDDataSourceUpdates"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,7 @@ | ||
import { LDStreamProcessor } from '../api'; | ||
export default class FileDataSource implements LDStreamProcessor { | ||
import { LDFileDataSourceError, subsystem } from '@launchdarkly/js-sdk-common'; | ||
export type FileDataSourceErrorHandler = (err: LDFileDataSourceError) => void; | ||
export default class FileDataSource implements subsystem.LDStreamProcessor { | ||
private readonly featureStore; | ||
private initSuccessHandler; | ||
private readonly errorHandler?; | ||
private logger?; | ||
@@ -8,4 +11,3 @@ private yamlParser?; | ||
private allData; | ||
private initCallback?; | ||
start(fn?: ((err?: any) => void) | undefined): void; | ||
start(): void; | ||
stop(): void; | ||
@@ -12,0 +14,0 @@ close(): void; |
@@ -21,5 +21,7 @@ "use strict"; | ||
*/ | ||
constructor(options, filesystem, featureStore) { | ||
constructor(options, filesystem, featureStore, initSuccessHandler = () => { }, errorHandler) { | ||
var _a; | ||
this.featureStore = featureStore; | ||
this.initSuccessHandler = initSuccessHandler; | ||
this.errorHandler = errorHandler; | ||
this.allData = {}; | ||
@@ -35,3 +37,3 @@ this.fileLoader = new FileLoader_1.default(filesystem, options.paths, (_a = options.autoUpdate) !== null && _a !== void 0 ? _a : false, (results) => { | ||
// If this was during start, then the initCallback will be present. | ||
(_a = this.initCallback) === null || _a === void 0 ? void 0 : _a.call(this, err); | ||
(_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.call(this, err); | ||
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error(`Error processing files: ${err}`); | ||
@@ -43,7 +45,7 @@ } | ||
} | ||
start(fn) { | ||
this.initCallback = fn; | ||
start() { | ||
// Use an immediately invoked function expression to allow handling of the | ||
// async loading without making start async itself. | ||
(async () => { | ||
var _a; | ||
try { | ||
@@ -55,3 +57,3 @@ await this.fileLoader.loadAndWatch(); | ||
// Report back to the caller. | ||
fn === null || fn === void 0 ? void 0 : fn(err); | ||
(_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.call(this, err); | ||
} | ||
@@ -97,7 +99,6 @@ })(); | ||
this.featureStore.init(this.allData, () => { | ||
var _a; | ||
// Call the init callback if present. | ||
// Then clear the callback so we cannot call it again. | ||
(_a = this.initCallback) === null || _a === void 0 ? void 0 : _a.call(this); | ||
this.initCallback = undefined; | ||
this.initSuccessHandler(); | ||
this.initSuccessHandler = () => { }; | ||
}); | ||
@@ -119,8 +120,2 @@ } | ||
}); | ||
Object.keys(parsed.configurationOverrides || {}).forEach((key) => { | ||
this.addItem(VersionedDataKinds_1.default.ConfigurationOverrides, parsed.configurationOverrides[key]); | ||
}); | ||
Object.keys(parsed.metrics || {}).forEach((key) => { | ||
this.addItem(VersionedDataKinds_1.default.Metrics, parsed.metrics[key]); | ||
}); | ||
} | ||
@@ -127,0 +122,0 @@ } |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
import { LDPollingError } from '@launchdarkly/js-sdk-common'; | ||
export type PollingErrorHandler = (err: LDPollingError) => void; | ||
//# sourceMappingURL=PollingProcessor.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errors_1 = require("../errors"); | ||
const serialization_1 = require("../store/serialization"); | ||
const js_sdk_common_1 = require("@launchdarkly/js-sdk-common"); | ||
const store_1 = require("../store"); | ||
const VersionedDataKinds_1 = require("../store/VersionedDataKinds"); | ||
const httpErrorMessage_1 = require("./httpErrorMessage"); | ||
/** | ||
@@ -11,11 +10,12 @@ * @internal | ||
class PollingProcessor { | ||
constructor(config, requestor, featureStore) { | ||
constructor(config, requestor, featureStore, initSuccessHandler = () => { }, errorHandler) { | ||
this.requestor = requestor; | ||
this.featureStore = featureStore; | ||
this.initSuccessHandler = initSuccessHandler; | ||
this.errorHandler = errorHandler; | ||
this.stopped = false; | ||
this.logger = config.logger; | ||
this.pollInterval = config.pollInterval; | ||
this.featureStore = featureStore; | ||
} | ||
poll(fn) { | ||
poll() { | ||
var _a; | ||
@@ -26,6 +26,6 @@ if (this.stopped) { | ||
const reportJsonError = (data) => { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error('Polling received invalid data'); | ||
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.debug(`Invalid JSON follows: ${data}`); | ||
fn === null || fn === void 0 ? void 0 : fn(new errors_1.LDPollingError('Malformed JSON data in polling response')); | ||
(_c = this.errorHandler) === null || _c === void 0 ? void 0 : _c.call(this, new js_sdk_common_1.LDPollingError('Malformed JSON data in polling response')); | ||
}; | ||
@@ -35,3 +35,3 @@ const startTime = Date.now(); | ||
this.requestor.requestAllData((err, body) => { | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
const elapsed = Date.now() - startTime; | ||
@@ -41,6 +41,7 @@ const sleepFor = Math.max(this.pollInterval * 1000 - elapsed, 0); | ||
if (err) { | ||
if (err.status && !(0, errors_1.isHttpRecoverable)(err.status)) { | ||
const message = (0, httpErrorMessage_1.default)(err, 'polling request'); | ||
const { status } = err; | ||
if (status && !(0, js_sdk_common_1.isHttpRecoverable)(status)) { | ||
const message = (0, js_sdk_common_1.httpErrorMessage)(err, 'polling request'); | ||
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error(message); | ||
fn === null || fn === void 0 ? void 0 : fn(new errors_1.LDPollingError(message)); | ||
(_c = this.errorHandler) === null || _c === void 0 ? void 0 : _c.call(this, new js_sdk_common_1.LDPollingError(message, status)); | ||
// It is not recoverable, return and do not trigger another | ||
@@ -50,6 +51,6 @@ // poll. | ||
} | ||
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.warn((0, httpErrorMessage_1.default)(err, 'polling request', 'will retry')); | ||
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.warn((0, js_sdk_common_1.httpErrorMessage)(err, 'polling request', 'will retry')); | ||
} | ||
else if (body) { | ||
const parsed = (0, serialization_1.deserializePoll)(body); | ||
const parsed = (0, store_1.deserializePoll)(body); | ||
if (!parsed) { | ||
@@ -64,10 +65,8 @@ // We could not parse this JSON. Report the problem and fallthrough to | ||
[VersionedDataKinds_1.default.Segments.namespace]: parsed.segments, | ||
[VersionedDataKinds_1.default.ConfigurationOverrides.namespace]: parsed.configurationOverrides || {}, | ||
[VersionedDataKinds_1.default.Metrics.namespace]: parsed.metrics || {}, | ||
}; | ||
this.featureStore.init(initData, () => { | ||
fn === null || fn === void 0 ? void 0 : fn(); | ||
this.initSuccessHandler(); | ||
// Triggering the next poll after the init has completed. | ||
this.timeoutHandle = setTimeout(() => { | ||
this.poll(fn); | ||
this.poll(); | ||
}, sleepFor); | ||
@@ -83,8 +82,8 @@ }); | ||
this.timeoutHandle = setTimeout(() => { | ||
this.poll(fn); | ||
this.poll(); | ||
}, sleepFor); | ||
}); | ||
} | ||
start(fn) { | ||
this.poll(fn); | ||
start() { | ||
this.poll(); | ||
} | ||
@@ -91,0 +90,0 @@ stop() { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const errors_1 = require("../errors"); | ||
const defaultHeaders_1 = require("./defaultHeaders"); | ||
const js_sdk_common_1 = require("@launchdarkly/js-sdk-common"); | ||
/** | ||
@@ -12,3 +11,3 @@ * @internal | ||
this.eTagCache = {}; | ||
this.headers = (0, defaultHeaders_1.default)(sdkKey, config, info); | ||
this.headers = (0, js_sdk_common_1.defaultHeaders)(sdkKey, info, config.tags); | ||
this.uri = `${config.serviceEndpoints.polling}/sdk/latest-all`; | ||
@@ -44,3 +43,3 @@ } | ||
if (res.status !== 200 && res.status !== 304) { | ||
const err = new errors_1.LDStreamingError(`Unexpected status code: ${res.status}`, res.status); | ||
const err = new js_sdk_common_1.LDStreamingError(`Unexpected status code: ${res.status}`, res.status); | ||
return cb(err, undefined); | ||
@@ -47,0 +46,0 @@ } |
@@ -83,5 +83,3 @@ "use strict"; | ||
*/ | ||
evaluateInternal(flag, context, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
state, visitedFlags, cb, eventFactory) { | ||
evaluateInternal(flag, context, state, visitedFlags, cb, eventFactory) { | ||
if (!flag.on) { | ||
@@ -348,7 +346,3 @@ cb((0, variations_1.getOffVariation)(flag, Reasons_1.default.Off)); | ||
} | ||
segmentMatchContext(segment, context, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
state, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
segmentsVisited, cb) { | ||
segmentMatchContext(segment, context, state, segmentsVisited, cb) { | ||
if (!segment.unbounded) { | ||
@@ -355,0 +349,0 @@ this.simpleSegmentMatchContext(segment, context, state, segmentsVisited, cb); |
@@ -12,3 +12,3 @@ "use strict"; | ||
} | ||
evalEvent(flag, context, detail, defaultVal, prereqOfFlag, indexEventSamplingRatio) { | ||
evalEvent(flag, context, detail, defaultVal, prereqOfFlag) { | ||
var _a; | ||
@@ -18,5 +18,5 @@ const addExperimentData = (0, isExperiment_1.default)(flag, detail.reason); | ||
// 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, indexEventSamplingRatio !== null && indexEventSamplingRatio !== void 0 ? indexEventSamplingRatio : 1); | ||
(_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); | ||
} | ||
unknownFlagEvent(key, context, detail, indexEventSamplingRatio) { | ||
unknownFlagEvent(key, context, detail) { | ||
return new js_sdk_common_1.internal.InputEvalEvent(this.withReasons, context, key, detail.value, detail, | ||
@@ -32,4 +32,3 @@ // This isn't ideal, but the purpose of the factory is to at least | ||
undefined, // exclude from summaries | ||
undefined, // sampling ratio | ||
indexEventSamplingRatio); | ||
undefined); | ||
} | ||
@@ -42,4 +41,4 @@ /* eslint-disable-next-line class-methods-use-this */ | ||
/* eslint-disable-next-line class-methods-use-this */ | ||
customEvent(key, context, data, metricValue, samplingRatio = 1, indexSamplingRatio = 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, indexSamplingRatio); | ||
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); | ||
} | ||
@@ -46,0 +45,0 @@ } |
@@ -1,4 +0,5 @@ | ||
import { LDClientContext, LDLogger } from '@launchdarkly/js-sdk-common'; | ||
import { LDClientContext, LDLogger, subsystem, VoidFunction } from '@launchdarkly/js-sdk-common'; | ||
import { FileDataSourceOptions } from '../api/integrations'; | ||
import { LDFeatureStore, LDStreamProcessor } from '../api/subsystems'; | ||
import { LDFeatureStore } from '../api/subsystems'; | ||
import { FileDataSourceErrorHandler } from '../data_sources/FileDataSource'; | ||
/** | ||
@@ -18,4 +19,4 @@ * Components of the SDK runtime configuration which are required | ||
constructor(options: FileDataSourceOptions); | ||
getFactory(): (ldClientContext: LDClientContext, featureStore: LDFeatureStore) => LDStreamProcessor; | ||
getFactory(): (ldClientContext: LDClientContext, featureStore: LDFeatureStore, initSuccessHandler?: VoidFunction, errorHandler?: FileDataSourceErrorHandler) => subsystem.LDStreamProcessor; | ||
} | ||
//# sourceMappingURL=FileDataSourceFactory.d.ts.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
*/ | ||
create(ldClientContext, featureStore) { | ||
create(ldClientContext, featureStore, initSuccessHandler, errorHandler) { | ||
const updatedOptions = { | ||
@@ -29,6 +29,6 @@ paths: this.options.paths, | ||
}; | ||
return new FileDataSource_1.default(updatedOptions, ldClientContext.platform.fileSystem, featureStore); | ||
return new FileDataSource_1.default(updatedOptions, ldClientContext.platform.fileSystem, featureStore, initSuccessHandler, errorHandler); | ||
} | ||
getFactory() { | ||
return (ldClientContext, featureStore) => this.create(ldClientContext, featureStore); | ||
return (ldClientContext, featureStore, initSuccessHandler, errorHandler) => this.create(ldClientContext, featureStore, initSuccessHandler, errorHandler); | ||
} | ||
@@ -35,0 +35,0 @@ } |
@@ -1,4 +0,3 @@ | ||
import { LDClientContext } from '@launchdarkly/js-sdk-common'; | ||
import { LDStreamProcessor } from '../../api'; | ||
import { LDFeatureStore } from '../../api/subsystems'; | ||
import { LDClientContext, subsystem, VoidFunction } from '@launchdarkly/js-sdk-common'; | ||
import { LDFeatureStore } from '../../api'; | ||
import TestDataFlagBuilder from './TestDataFlagBuilder'; | ||
@@ -46,3 +45,3 @@ /** | ||
*/ | ||
getFactory(): (clientContext: LDClientContext, featureStore: LDFeatureStore) => LDStreamProcessor; | ||
getFactory(): (clientContext: LDClientContext, featureStore: LDFeatureStore, initSuccessHandler: VoidFunction, errorHandler?: (e: Error) => void) => subsystem.LDStreamProcessor; | ||
/** | ||
@@ -49,0 +48,0 @@ * Creates or copies a {@link TestDataFlagBuilder} for building a test flag configuration. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const createStreamListeners_1 = require("../../data_sources/createStreamListeners"); | ||
const AsyncStoreFacade_1 = require("../../store/AsyncStoreFacade"); | ||
@@ -54,8 +55,9 @@ const serialization_1 = require("../../store/serialization"); | ||
// maintain `this`. | ||
return ( | ||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ | ||
clientContext, featureStore) => { | ||
return (clientContext, featureStore, initSuccessHandler, _errorHandler) => { | ||
const listeners = (0, createStreamListeners_1.createStreamListeners)(featureStore, clientContext.basicConfiguration.logger, { | ||
put: initSuccessHandler, | ||
}); | ||
const newSource = new TestDataSource_1.default(new AsyncStoreFacade_1.default(featureStore), this.currentFlags, this.currentSegments, (tds) => { | ||
this.dataSources.splice(this.dataSources.indexOf(tds)); | ||
}); | ||
}, listeners); | ||
this.dataSources.push(newSource); | ||
@@ -62,0 +64,0 @@ return newSource; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const VersionedDataKinds_1 = require("../../store/VersionedDataKinds"); | ||
/** | ||
@@ -8,14 +7,16 @@ * @internal | ||
class TestDataSource { | ||
constructor(featureStore, flags, segments, onStop) { | ||
constructor(featureStore, initialFlags, initialSegments, onStop, listeners) { | ||
this.featureStore = featureStore; | ||
this.flags = flags; | ||
this.segments = segments; | ||
this.onStop = onStop; | ||
this.listeners = listeners; | ||
// make copies of these objects to decouple them from the originals | ||
// so updates made to the originals don't affect these internal data. | ||
this.flags = Object.assign({}, initialFlags); | ||
this.segments = Object.assign({}, initialSegments); | ||
} | ||
async start(fn) { | ||
await this.featureStore.init({ | ||
[VersionedDataKinds_1.default.Features.namespace]: Object.assign({}, this.flags), | ||
[VersionedDataKinds_1.default.Segments.namespace]: Object.assign({}, this.segments), | ||
async start() { | ||
this.listeners.forEach(({ processJson }) => { | ||
const dataJson = { data: { flags: this.flags, segments: this.segments } }; | ||
processJson(dataJson); | ||
}); | ||
fn === null || fn === void 0 ? void 0 : fn(); | ||
} | ||
@@ -22,0 +23,0 @@ stop() { |
@@ -20,3 +20,3 @@ import { LDContext, LDEvaluationDetail, LDEvaluationDetailTyped, Platform } from '@launchdarkly/js-sdk-common'; | ||
private asyncFeatureStore; | ||
private updateProcessor; | ||
private updateProcessor?; | ||
private eventFactoryDefault; | ||
@@ -36,3 +36,2 @@ private eventFactoryWithReasons; | ||
private diagnosticsManager?; | ||
private eventConfig; | ||
/** | ||
@@ -72,3 +71,5 @@ * Intended for use by platform specific client implementations. | ||
private evaluateIfPossible; | ||
private dataSourceErrorHandler; | ||
private initSuccess; | ||
} | ||
//# sourceMappingURL=LDClientImpl.d.ts.map |
"use strict"; | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,8 +8,7 @@ /* eslint-disable class-methods-use-this */ | ||
const ClientMessages_1 = require("./ClientMessages"); | ||
const createStreamListeners_1 = require("./data_sources/createStreamListeners"); | ||
const DataSourceUpdates_1 = require("./data_sources/DataSourceUpdates"); | ||
const NullUpdateProcessor_1 = require("./data_sources/NullUpdateProcessor"); | ||
const PollingProcessor_1 = require("./data_sources/PollingProcessor"); | ||
const Requestor_1 = require("./data_sources/Requestor"); | ||
const StreamingProcessor_1 = require("./data_sources/StreamingProcessor"); | ||
const errors_1 = require("./errors"); | ||
const createDiagnosticsInitConfig_1 = require("./diagnostics/createDiagnosticsInitConfig"); | ||
const collection_1 = require("./evaluation/collection"); | ||
@@ -21,7 +19,4 @@ const ErrorKinds_1 = require("./evaluation/ErrorKinds"); | ||
const ContextDeduplicator_1 = require("./events/ContextDeduplicator"); | ||
const DiagnosticsManager_1 = require("./events/DiagnosticsManager"); | ||
const EventFactory_1 = require("./events/EventFactory"); | ||
const EventSender_1 = require("./events/EventSender"); | ||
const isExperiment_1 = require("./events/isExperiment"); | ||
const NullEventProcessor_1 = require("./events/NullEventProcessor"); | ||
const FlagsStateBuilder_1 = require("./FlagsStateBuilder"); | ||
@@ -33,2 +28,3 @@ const MigrationOpEventConversion_1 = require("./MigrationOpEventConversion"); | ||
const VersionedDataKinds_1 = require("./store/VersionedDataKinds"); | ||
const { NullEventProcessor } = js_sdk_common_1.internal; | ||
var InitState; | ||
@@ -66,22 +62,12 @@ (function (InitState) { | ||
if (config.sendEvents && !config.offline && !config.diagnosticOptOut) { | ||
this.diagnosticsManager = new DiagnosticsManager_1.default(sdkKey, config, platform, featureStore); | ||
this.diagnosticsManager = new js_sdk_common_1.internal.DiagnosticsManager(sdkKey, platform, (0, createDiagnosticsInitConfig_1.default)(config, platform, featureStore)); | ||
} | ||
const makeDefaultProcessor = () => config.stream | ||
? new StreamingProcessor_1.default(sdkKey, config, this.platform.requests, this.platform.info, dataSourceUpdates, this.diagnosticsManager) | ||
: new PollingProcessor_1.default(config, new Requestor_1.default(sdkKey, config, this.platform.info, this.platform.requests), dataSourceUpdates); | ||
if (config.offline || config.useLdd) { | ||
this.updateProcessor = new NullUpdateProcessor_1.default(); | ||
} | ||
else { | ||
this.updateProcessor = | ||
(_b = (_a = config.updateProcessorFactory) === null || _a === void 0 ? void 0 : _a.call(config, clientContext, dataSourceUpdates)) !== null && _b !== void 0 ? _b : makeDefaultProcessor(); | ||
} | ||
if (!config.sendEvents || config.offline) { | ||
this.eventProcessor = new NullEventProcessor_1.default(); | ||
this.eventProcessor = new NullEventProcessor(); | ||
} | ||
else { | ||
this.eventProcessor = new js_sdk_common_1.internal.EventProcessor(config, clientContext, new EventSender_1.default(config, clientContext), new ContextDeduplicator_1.default(config), this.diagnosticsManager); | ||
this.eventProcessor = new js_sdk_common_1.internal.EventProcessor(config, clientContext, new ContextDeduplicator_1.default(config), this.diagnosticsManager); | ||
} | ||
this.featureStore = featureStore; | ||
const manager = new BigSegmentsManager_1.default((_d = (_c = config.bigSegments) === null || _c === void 0 ? void 0 : _c.store) === null || _d === void 0 ? void 0 : _d.call(_c, clientContext), (_e = config.bigSegments) !== null && _e !== void 0 ? _e : {}, config.logger, this.platform.crypto); | ||
const manager = new BigSegmentsManager_1.default((_b = (_a = config.bigSegments) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.call(_a, clientContext), (_c = config.bigSegments) !== null && _c !== void 0 ? _c : {}, config.logger, this.platform.crypto); | ||
this.bigSegmentsManager = manager; | ||
@@ -101,43 +87,20 @@ this.bigSegmentStatusProviderInternal = manager.statusProvider; | ||
this.evaluator = new Evaluator_1.default(this.platform, queries); | ||
this.updateProcessor.start((err) => { | ||
var _a, _b; | ||
if (err) { | ||
let error; | ||
if ((err.status && err.status === 401) || (err.code && err.code === 401)) { | ||
error = new Error('Authentication failed. Double check your SDK key.'); | ||
} | ||
else { | ||
error = err; | ||
} | ||
this.onError(error); | ||
this.onFailed(error); | ||
if (!this.initialized()) { | ||
this.initState = InitState.Failed; | ||
(_a = this.initReject) === null || _a === void 0 ? void 0 : _a.call(this, error); | ||
} | ||
} | ||
else if (!this.initialized()) { | ||
this.initState = InitState.Initialized; | ||
(_b = this.initResolve) === null || _b === void 0 ? void 0 : _b.call(this, this); | ||
this.onReady(); | ||
} | ||
const listeners = (0, createStreamListeners_1.createStreamListeners)(dataSourceUpdates, this.logger, { | ||
put: () => this.initSuccess(), | ||
}); | ||
this.eventConfig = { | ||
samplingRatio: async (key) => { | ||
var _a; | ||
const ratioItem = await this.asyncFeatureStore.get(VersionedDataKinds_1.default.Metrics, key); | ||
if (ratioItem && !ratioItem.deleted) { | ||
return (_a = ratioItem.samplingRatio) !== null && _a !== void 0 ? _a : 1; | ||
} | ||
return 1; | ||
}, | ||
indexEventSamplingRatio: async () => { | ||
var _a; | ||
const indexSampling = await this.asyncFeatureStore.get(VersionedDataKinds_1.default.ConfigurationOverrides, 'indexSamplingRatio'); | ||
if (indexSampling && !indexSampling.deleted) { | ||
return (_a = indexSampling.value) !== null && _a !== void 0 ? _a : 1; | ||
} | ||
return 1; | ||
}, | ||
}; | ||
const makeDefaultProcessor = () => config.stream | ||
? new js_sdk_common_1.internal.StreamingProcessor(sdkKey, clientContext, 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)); | ||
if (!(config.offline || config.useLdd)) { | ||
this.updateProcessor = | ||
(_e = (_d = config.updateProcessorFactory) === null || _d === void 0 ? void 0 : _d.call(config, clientContext, dataSourceUpdates, () => this.initSuccess(), (e) => this.dataSourceErrorHandler(e))) !== null && _e !== void 0 ? _e : makeDefaultProcessor(); | ||
} | ||
if (this.updateProcessor) { | ||
this.updateProcessor.start(); | ||
} | ||
else { | ||
// Deferring the start callback should allow client construction to complete before we start | ||
// emitting events. Allowing the client an opportunity to register events. | ||
setTimeout(() => this.initSuccess(), 0); | ||
} | ||
} | ||
@@ -242,7 +205,7 @@ initialized() { | ||
kind: 'ERROR', | ||
errorKind: 'WRONG_TYPE', | ||
errorKind: ErrorKinds_1.default.WrongType, | ||
}; | ||
resolve({ | ||
value: defaultValue, | ||
tracker: new MigrationOpTracker_1.default(key, contextKeys, defaultValue, defaultValue, reason, checkRatio, undefined, undefined, samplingRatio), | ||
tracker: new MigrationOpTracker_1.default(key, contextKeys, defaultValue, defaultValue, reason, checkRatio, undefined, flag === null || flag === void 0 ? void 0 : flag.version, samplingRatio, this.logger), | ||
}); | ||
@@ -255,3 +218,3 @@ return; | ||
// Can be null for compatibility reasons. | ||
detail.variationIndex === null ? undefined : detail.variationIndex, flag === null || flag === void 0 ? void 0 : flag.version, samplingRatio), | ||
detail.variationIndex === null ? undefined : detail.variationIndex, flag === null || flag === void 0 ? void 0 : flag.version, samplingRatio, this.logger), | ||
}); | ||
@@ -280,4 +243,5 @@ }); | ||
(0, collection_1.allAsync)(Object.values(allFlags), (storeItem, iterCb) => { | ||
var _a; | ||
const flag = storeItem; | ||
if (clientOnly && !flag.clientSide) { | ||
if (clientOnly && !((_a = flag.clientSideAvailability) === null || _a === void 0 ? void 0 : _a.usingEnvironmentId)) { | ||
iterCb(true); | ||
@@ -327,3 +291,3 @@ return; | ||
if (key === undefined) { | ||
throw new errors_1.LDClientError('Could not generate secure mode hash for invalid context'); | ||
throw new js_sdk_common_1.LDClientError('Could not generate secure mode hash for invalid context'); | ||
} | ||
@@ -334,4 +298,5 @@ hmac.update(key); | ||
close() { | ||
var _a; | ||
this.eventProcessor.close(); | ||
this.updateProcessor.close(); | ||
(_a = this.updateProcessor) === null || _a === void 0 ? void 0 : _a.close(); | ||
this.featureStore.close(); | ||
@@ -350,7 +315,3 @@ this.bigSegmentsManager.close(); | ||
} | ||
// Async immediately invoking function expression to get the flag from the store | ||
// without requiring track to be async. | ||
(async () => { | ||
this.eventProcessor.sendEvent(this.eventFactoryDefault.customEvent(key, checkedContext, data, metricValue, await this.eventConfig.samplingRatio(key), await this.eventConfig.indexEventSamplingRatio())); | ||
})(); | ||
this.eventProcessor.sendEvent(this.eventFactoryDefault.customEvent(key, checkedContext, data, metricValue)); | ||
} | ||
@@ -391,3 +352,3 @@ trackMigration(event) { | ||
if (!evalContext.valid) { | ||
this.onError(new errors_1.LDClientError(`${(_b = evalContext.message) !== null && _b !== void 0 ? _b : 'Context not valid;'} returning default value.`)); | ||
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)); | ||
@@ -399,9 +360,6 @@ return; | ||
if (!flag) { | ||
const error = new errors_1.LDClientError(`Unknown feature flag "${flagKey}"; returning default value`); | ||
const error = new js_sdk_common_1.LDClientError(`Unknown feature flag "${flagKey}"; returning default value`); | ||
this.onError(error); | ||
const result = EvalResult_1.default.forError(ErrorKinds_1.default.FlagNotFound, undefined, defaultValue); | ||
(async () => { | ||
const indexSamplingRatio = await this.eventConfig.indexEventSamplingRatio(); | ||
this.eventProcessor.sendEvent(this.eventFactoryDefault.unknownFlagEvent(flagKey, evalContext, result.detail, indexSamplingRatio)); | ||
})(); | ||
this.eventProcessor.sendEvent(this.eventFactoryDefault.unknownFlagEvent(flagKey, evalContext, result.detail)); | ||
cb(result); | ||
@@ -421,3 +379,2 @@ return; | ||
const errorRes = EvalResult_1.default.forError(ErrorKinds_1.default.WrongType, `Did not receive expected type (${type}) evaluating feature flag "${flagKey}"`, defaultValue); | ||
// Method intentionally not awaited, puts event processing outside hot path. | ||
this.sendEvalEvent(evalRes, eventFactory, flag, evalContext, defaultValue); | ||
@@ -428,3 +385,2 @@ cb(errorRes, flag); | ||
} | ||
// Method intentionally not awaited, puts event processing outside hot path. | ||
this.sendEvalEvent(evalRes, eventFactory, flag, evalContext, defaultValue); | ||
@@ -435,9 +391,8 @@ cb(evalRes, flag); | ||
} | ||
async sendEvalEvent(evalRes, eventFactory, flag, evalContext, defaultValue) { | ||
sendEvalEvent(evalRes, eventFactory, flag, evalContext, defaultValue) { | ||
var _a; | ||
const indexSamplingRatio = await this.eventConfig.indexEventSamplingRatio(); | ||
(_a = evalRes.events) === null || _a === void 0 ? void 0 : _a.forEach((event) => { | ||
this.eventProcessor.sendEvent(Object.assign(Object.assign({}, event), { indexSamplingRatio })); | ||
this.eventProcessor.sendEvent(Object.assign({}, event)); | ||
}); | ||
this.eventProcessor.sendEvent(eventFactory.evalEvent(flag, evalContext, evalRes.detail, defaultValue, undefined, indexSamplingRatio)); | ||
this.eventProcessor.sendEvent(eventFactory.evalEvent(flag, evalContext, evalRes.detail, defaultValue, undefined)); | ||
} | ||
@@ -462,4 +417,22 @@ evaluateIfPossible(flagKey, context, defaultValue, eventFactory, cb, typeChecker) { | ||
} | ||
dataSourceErrorHandler(e) { | ||
var _a; | ||
const error = e.code === 401 ? new Error('Authentication failed. Double check your SDK key.') : e; | ||
this.onError(error); | ||
this.onFailed(error); | ||
if (!this.initialized()) { | ||
this.initState = InitState.Failed; | ||
(_a = this.initReject) === null || _a === void 0 ? void 0 : _a.call(this, error); | ||
} | ||
} | ||
initSuccess() { | ||
var _a; | ||
if (!this.initialized()) { | ||
this.initState = InitState.Initialized; | ||
(_a = this.initResolve) === null || _a === void 0 ? void 0 : _a.call(this, this); | ||
this.onReady(); | ||
} | ||
} | ||
} | ||
exports.default = LDClientImpl; | ||
//# sourceMappingURL=LDClientImpl.js.map |
@@ -49,3 +49,3 @@ "use strict"; | ||
streamUri: 'https://stream.launchdarkly.com', | ||
eventsUri: 'https://events.launchdarkly.com', | ||
eventsUri: js_sdk_common_1.ServiceEndpoints.DEFAULT_EVENTS, | ||
stream: true, | ||
@@ -52,0 +52,0 @@ streamInitialReconnectDelay: 1, |
@@ -0,6 +1,6 @@ | ||
import { VersionedData } from '../api/interfaces'; | ||
import { Flag } from '../evaluation/data/Flag'; | ||
import { Segment } from '../evaluation/data/Segment'; | ||
import { Metric } from './Metric'; | ||
import { Override } from './Override'; | ||
interface AllData { | ||
import { VersionedDataKind } from './VersionedDataKinds'; | ||
export interface FlagsAndSegments { | ||
flags: { | ||
@@ -12,9 +12,17 @@ [name: string]: Flag; | ||
}; | ||
configurationOverrides?: { | ||
[name: string]: Override; | ||
}; | ||
metrics?: { | ||
[name: string]: Metric; | ||
}; | ||
} | ||
export interface AllData { | ||
data: FlagsAndSegments; | ||
} | ||
export interface DeleteData extends Omit<VersionedData, 'key'> { | ||
path: string; | ||
kind?: VersionedDataKind; | ||
} | ||
type VersionedFlag = VersionedData & Flag; | ||
type VersionedSegment = VersionedData & Segment; | ||
export interface PatchData { | ||
path: string; | ||
data: VersionedFlag | VersionedSegment; | ||
kind?: VersionedDataKind; | ||
} | ||
/** | ||
@@ -28,4 +36,4 @@ * This function is intended for usage inside LaunchDarkly SDKs. | ||
*/ | ||
export declare function deserializePoll(data: string): AllData | undefined; | ||
export declare function deserializePoll(data: string): FlagsAndSegments | undefined; | ||
export {}; | ||
//# sourceMappingURL=serialization.d.ts.map |
@@ -222,8 +222,2 @@ "use strict"; | ||
} | ||
else if (parsed.path.startsWith(VersionedDataKinds_1.default.ConfigurationOverrides.streamApiPath)) { | ||
parsed.kind = VersionedDataKinds_1.default.ConfigurationOverrides; | ||
} | ||
else if (parsed.path.startsWith(VersionedDataKinds_1.default.Metrics.streamApiPath)) { | ||
parsed.kind = VersionedDataKinds_1.default.Metrics; | ||
} | ||
return parsed; | ||
@@ -246,8 +240,2 @@ } | ||
} | ||
else if (parsed.path.startsWith(VersionedDataKinds_1.default.ConfigurationOverrides.streamApiPath)) { | ||
parsed.kind = VersionedDataKinds_1.default.ConfigurationOverrides; | ||
} | ||
else if (parsed.path.startsWith(VersionedDataKinds_1.default.Metrics.streamApiPath)) { | ||
parsed.kind = VersionedDataKinds_1.default.Metrics; | ||
} | ||
return parsed; | ||
@@ -254,0 +242,0 @@ } |
@@ -10,5 +10,4 @@ import { DataKind } from '../api/interfaces'; | ||
static readonly Segments: VersionedDataKind; | ||
static readonly ConfigurationOverrides: VersionedDataKind; | ||
static readonly Metrics: VersionedDataKind; | ||
static getKeyFromPath(kind: VersionedDataKind, path: string): string | undefined; | ||
} | ||
//# sourceMappingURL=VersionedDataKinds.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class VersionedDataKinds { | ||
static getKeyFromPath(kind, path) { | ||
return path.startsWith(kind.streamApiPath) | ||
? path.substring(kind.streamApiPath.length) | ||
: undefined; | ||
} | ||
} | ||
@@ -13,11 +18,3 @@ VersionedDataKinds.Features = { | ||
}; | ||
VersionedDataKinds.ConfigurationOverrides = { | ||
namespace: 'configurationOverrides', | ||
streamApiPath: '/configurationOverrides/', | ||
}; | ||
VersionedDataKinds.Metrics = { | ||
namespace: 'metrics', | ||
streamApiPath: '/metrics/', | ||
}; | ||
exports.default = VersionedDataKinds; | ||
//# sourceMappingURL=VersionedDataKinds.js.map |
{ | ||
"name": "@launchdarkly/js-server-sdk-common", | ||
"version": "1.4.0-alpha.5", | ||
"version": "2.0.0-alpha.1", | ||
"type": "commonjs", | ||
@@ -30,6 +30,7 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@launchdarkly/js-sdk-common": "1.3.0-alpha.2", | ||
"@launchdarkly/js-sdk-common": "2.0.0-alpha.1", | ||
"semver": "7.5.4" | ||
}, | ||
"devDependencies": { | ||
"@launchdarkly/private-js-mocks": "0.0.1", | ||
"@trivago/prettier-plugin-sort-imports": "^4.1.1", | ||
@@ -36,0 +37,0 @@ "@types/jest": "^29.4.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
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
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
584019
19
440
8293
+ Added@launchdarkly/js-sdk-common@2.0.0-alpha.1(transitive)
- Removed@launchdarkly/js-sdk-common@1.3.0-alpha.2(transitive)