@launchdarkly/js-sdk-common
Advanced tools
Comparing version 1.2.0-alpha to 1.3.0-alpha.1
@@ -14,4 +14,2 @@ "use strict"; | ||
// cloning of the context will be done. | ||
// Validates a kind excluding check that it isn't "kind". | ||
const KindValidator = validators_1.TypeValidators.stringMatchingRegex(/^(\w|\.|-)+$/); | ||
// When no kind is specified, then this kind will be used. | ||
@@ -88,3 +86,3 @@ const DEFAULT_KIND = 'user'; | ||
function validKind(kind) { | ||
return KindValidator.is(kind) && kind !== 'kind'; | ||
return validators_1.TypeValidators.Kind.is(kind); | ||
} | ||
@@ -91,0 +89,0 @@ /** |
@@ -9,2 +9,3 @@ "use strict"; | ||
const LDInvalidSDKKeyError_1 = require("./LDInvalidSDKKeyError"); | ||
const sampling_1 = require("./sampling"); | ||
class EventProcessor { | ||
@@ -86,2 +87,15 @@ constructor(config, clientContext, eventSender, contextDeduplicator, diagnosticsManager) { | ||
} | ||
if ((0, guards_1.isMigration)(inputEvent)) { | ||
// These conditions are not combined, because we always want to stop | ||
// processing at this point for a migration event. It cannot generate | ||
// an index event or debug event. | ||
if ((0, sampling_1.default)(inputEvent.samplingRatio)) { | ||
const migrationEvent = Object.assign({}, inputEvent); | ||
if (migrationEvent.samplingRatio === 1) { | ||
delete migrationEvent.samplingRatio; | ||
} | ||
this.enqueue(migrationEvent); | ||
} | ||
return; | ||
} | ||
this.summarizer.summarizeEvent(inputEvent); | ||
@@ -92,2 +106,4 @@ const isFeatureEvent = (0, guards_1.isFeature)(inputEvent); | ||
const isIdentifyEvent = (0, guards_1.isIdentify)(inputEvent); | ||
// We only want to notify the de-duplicator if we would sample the index event. | ||
// Otherwise we could deduplicate and then not send the event. | ||
const shouldNotDeduplicate = this.contextDeduplicator.processContext(inputEvent.context); | ||
@@ -101,13 +117,14 @@ // If there is no cache, then it will never be in the cache. | ||
const addIndexEvent = shouldNotDeduplicate && !isIdentifyEvent; | ||
if (addIndexEvent) { | ||
this.enqueue({ | ||
if (addIndexEvent && (0, sampling_1.default)(inputEvent.indexSamplingRatio)) { | ||
this.enqueue(this.makeOutputEvent({ | ||
kind: 'index', | ||
creationDate: inputEvent.creationDate, | ||
context: this.contextFilter.filter(inputEvent.context), | ||
}); | ||
context: inputEvent.context, | ||
samplingRatio: inputEvent.indexSamplingRatio, | ||
}, false)); | ||
} | ||
if (addFullEvent) { | ||
if (addFullEvent && (0, sampling_1.default)(inputEvent.samplingRatio)) { | ||
this.enqueue(this.makeOutputEvent(inputEvent, false)); | ||
} | ||
if (addDebugEvent) { | ||
if (addDebugEvent && (0, sampling_1.default)(inputEvent.samplingRatio)) { | ||
this.enqueue(this.makeOutputEvent(inputEvent, true)); | ||
@@ -125,4 +142,9 @@ } | ||
default: event.default, | ||
prereqOf: event.prereqOf, | ||
}; | ||
if (event.samplingRatio !== 1) { | ||
out.samplingRatio = event.samplingRatio; | ||
} | ||
if (event.prereqOf) { | ||
out.prereqOf = event.prereqOf; | ||
} | ||
if (event.variation !== undefined) { | ||
@@ -145,8 +167,13 @@ out.variation = event.variation; | ||
} | ||
case 'index': // Intentional fallthrough. | ||
case 'identify': { | ||
return { | ||
kind: 'identify', | ||
const out = { | ||
kind: event.kind, | ||
creationDate: event.creationDate, | ||
context: this.contextFilter.filter(event.context), | ||
}; | ||
if (event.samplingRatio !== 1) { | ||
out.samplingRatio = event.samplingRatio; | ||
} | ||
return out; | ||
} | ||
@@ -160,2 +187,5 @@ case 'custom': { | ||
}; | ||
if (event.samplingRatio !== 1) { | ||
out.samplingRatio = event.samplingRatio; | ||
} | ||
if (event.data !== undefined) { | ||
@@ -162,0 +192,0 @@ out.data = event.data; |
@@ -19,3 +19,3 @@ "use strict"; | ||
summarizeEvent(event) { | ||
if ((0, guards_1.isFeature)(event)) { | ||
if ((0, guards_1.isFeature)(event) && !event.excludeFromSummaries) { | ||
const countKey = counterKey(event); | ||
@@ -22,0 +22,0 @@ const counter = this.counters[countKey]; |
import InputCustomEvent from './InputCustomEvent'; | ||
import InputEvalEvent from './InputEvalEvent'; | ||
import InputIdentifyEvent from './InputIdentifyEvent'; | ||
import InputMigrationEvent from './InputMigrationEvent'; | ||
export declare function isFeature(u: any): u is InputEvalEvent; | ||
export declare function isCustom(u: any): u is InputCustomEvent; | ||
export declare function isIdentify(u: any): u is InputIdentifyEvent; | ||
export declare function isMigration(u: any): u is InputMigrationEvent; | ||
//# sourceMappingURL=guards.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isIdentify = exports.isCustom = exports.isFeature = void 0; | ||
exports.isMigration = exports.isIdentify = exports.isCustom = exports.isFeature = void 0; | ||
function isFeature(u) { | ||
@@ -16,2 +16,6 @@ return u.kind === 'feature'; | ||
exports.isIdentify = isIdentify; | ||
function isMigration(u) { | ||
return u.kind === 'migration_op'; | ||
} | ||
exports.isMigration = isMigration; | ||
//# sourceMappingURL=guards.js.map |
@@ -6,4 +6,6 @@ import EventProcessor from './EventProcessor'; | ||
import InputIdentifyEvent from './InputIdentifyEvent'; | ||
import type { LDInternalOptions } from './LDInternalOptions'; | ||
export { EventProcessor, InputCustomEvent, InputEvalEvent, InputEvent, InputIdentifyEvent, LDInternalOptions, }; | ||
import InputMigrationEvent from './InputMigrationEvent'; | ||
import { LDEventOverrides } from './LDEventOverrides'; | ||
import shouldSample from './sampling'; | ||
export { InputCustomEvent, InputEvalEvent, InputEvent, InputIdentifyEvent, InputMigrationEvent, EventProcessor, LDEventOverrides, shouldSample, }; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InputIdentifyEvent = exports.InputEvalEvent = exports.InputCustomEvent = exports.EventProcessor = void 0; | ||
exports.shouldSample = exports.EventProcessor = exports.InputIdentifyEvent = exports.InputEvalEvent = exports.InputCustomEvent = void 0; | ||
const EventProcessor_1 = require("./EventProcessor"); | ||
@@ -12,2 +12,4 @@ exports.EventProcessor = EventProcessor_1.default; | ||
exports.InputIdentifyEvent = InputIdentifyEvent_1.default; | ||
const sampling_1 = require("./sampling"); | ||
exports.shouldSample = sampling_1.default; | ||
//# sourceMappingURL=index.js.map |
import Context from '../../Context'; | ||
export default class InputCustomEvent { | ||
readonly context: Context; | ||
readonly key: string; | ||
readonly data?: any; | ||
readonly metricValue?: number | undefined; | ||
readonly samplingRatio: number; | ||
readonly indexSamplingRatio: number; | ||
readonly kind = "custom"; | ||
readonly creationDate: number; | ||
readonly context: Context; | ||
constructor(context: Context, key: string, data?: any, metricValue?: number | undefined); | ||
constructor(context: Context, key: string, data?: any, metricValue?: number | undefined, samplingRatio?: number, indexSamplingRatio?: number); | ||
} | ||
//# sourceMappingURL=InputCustomEvent.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class InputCustomEvent { | ||
constructor(context, key, data, metricValue) { | ||
constructor(context, key, data, metricValue, samplingRatio = 1, indexSamplingRatio = 1) { | ||
this.context = context; | ||
this.key = key; | ||
this.data = data; | ||
this.metricValue = metricValue; | ||
this.samplingRatio = samplingRatio; | ||
this.indexSamplingRatio = indexSamplingRatio; | ||
this.kind = 'custom'; | ||
@@ -9,0 +12,0 @@ this.creationDate = Date.now(); |
import { LDEvaluationDetail, LDEvaluationReason } from '../../api/data'; | ||
import Context from '../../Context'; | ||
export default class InputEvalEvent { | ||
readonly withReasons: boolean; | ||
readonly context: Context; | ||
readonly key: string; | ||
readonly samplingRatio: number; | ||
readonly indexSamplingRatio: number; | ||
readonly kind = "feature"; | ||
readonly creationDate: number; | ||
readonly context: Context; | ||
readonly default: any; | ||
@@ -16,5 +19,6 @@ readonly trackEvents?: boolean; | ||
readonly version?: number; | ||
readonly excludeFromSummaries?: boolean; | ||
constructor(withReasons: boolean, context: Context, key: string, defValue: any, // default is a reserved keyword in this context. | ||
detail: LDEvaluationDetail, version?: number, variation?: number, trackEvents?: boolean, prereqOf?: string, reason?: LDEvaluationReason, debugEventsUntilDate?: number); | ||
detail: LDEvaluationDetail, version?: number, variation?: number, trackEvents?: boolean, prereqOf?: string, reason?: LDEvaluationReason, debugEventsUntilDate?: number, excludeFromSummaries?: boolean, samplingRatio?: number, indexSamplingRatio?: number); | ||
} | ||
//# sourceMappingURL=InputEvalEvent.d.ts.map |
@@ -5,8 +5,11 @@ "use strict"; | ||
constructor(withReasons, context, key, defValue, // default is a reserved keyword in this context. | ||
detail, version, variation, trackEvents, prereqOf, reason, debugEventsUntilDate) { | ||
detail, version, variation, trackEvents, prereqOf, reason, debugEventsUntilDate, excludeFromSummaries, samplingRatio = 1, indexSamplingRatio = 1) { | ||
var _a; | ||
this.withReasons = withReasons; | ||
this.context = context; | ||
this.key = key; | ||
this.samplingRatio = samplingRatio; | ||
this.indexSamplingRatio = indexSamplingRatio; | ||
this.kind = 'feature'; | ||
this.creationDate = Date.now(); | ||
this.context = context; | ||
this.default = defValue; | ||
@@ -33,2 +36,5 @@ this.variation = (_a = detail.variationIndex) !== null && _a !== void 0 ? _a : undefined; | ||
} | ||
if (excludeFromSummaries !== undefined) { | ||
this.excludeFromSummaries = excludeFromSummaries; | ||
} | ||
} | ||
@@ -35,0 +41,0 @@ } |
import InputCustomEvent from './InputCustomEvent'; | ||
import InputEvalEvent from './InputEvalEvent'; | ||
import InputIdentifyEvent from './InputIdentifyEvent'; | ||
type InputEvent = InputEvalEvent | InputCustomEvent | InputIdentifyEvent; | ||
import InputMigrationEvent from './InputMigrationEvent'; | ||
type InputEvent = InputEvalEvent | InputCustomEvent | InputIdentifyEvent | InputMigrationEvent; | ||
export default InputEvent; | ||
//# sourceMappingURL=InputEvent.d.ts.map |
import Context from '../../Context'; | ||
export default class InputIdentifyEvent { | ||
readonly context: Context; | ||
readonly samplingRatio: number; | ||
readonly kind = "identify"; | ||
readonly creationDate: number; | ||
readonly context: Context; | ||
constructor(context: Context); | ||
constructor(context: Context, samplingRatio?: number); | ||
} | ||
//# sourceMappingURL=InputIdentifyEvent.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class InputIdentifyEvent { | ||
constructor(context) { | ||
constructor(context, samplingRatio = 1) { | ||
this.context = context; | ||
this.samplingRatio = samplingRatio; | ||
this.kind = 'identify'; | ||
this.creationDate = Date.now(); | ||
this.context = context; | ||
} | ||
@@ -9,0 +10,0 @@ } |
@@ -8,17 +8,4 @@ /** | ||
readonly events: string; | ||
/** Valid paths are: | ||
* /bulk | ||
* /events/bulk/envId | ||
* /mobile | ||
*/ | ||
readonly analyticsEventPath: string; | ||
/** Valid paths are: | ||
* /diagnostic | ||
* /events/diagnostic/envId | ||
* /mobile/events/diagnostic | ||
*/ | ||
readonly diagnosticEventPath: string; | ||
readonly includeAuthorizationHeader: boolean; | ||
constructor(streaming: string, polling: string, events: string, analyticsEventPath?: string, diagnosticEventPath?: string, includeAuthorizationHeader?: boolean); | ||
constructor(streaming: string, polling: string, events: string); | ||
} | ||
//# sourceMappingURL=ServiceEndpoints.d.ts.map |
@@ -10,9 +10,6 @@ "use strict"; | ||
class ServiceEndpoints { | ||
constructor(streaming, polling, events, analyticsEventPath = '/bulk', diagnosticEventPath = '/diagnostic', includeAuthorizationHeader = true) { | ||
constructor(streaming, polling, events) { | ||
this.streaming = canonicalizeUri(streaming); | ||
this.polling = canonicalizeUri(polling); | ||
this.events = canonicalizeUri(events); | ||
this.analyticsEventPath = analyticsEventPath; | ||
this.diagnosticEventPath = diagnosticEventPath; | ||
this.includeAuthorizationHeader = includeAuthorizationHeader; | ||
} | ||
@@ -19,0 +16,0 @@ } |
@@ -70,2 +70,9 @@ /** | ||
/** | ||
* Validates that a string is a valid kind. | ||
*/ | ||
export declare class KindValidator extends StringMatchingRegex { | ||
constructor(); | ||
is(u: unknown): u is string; | ||
} | ||
/** | ||
* A set of standard type validators. | ||
@@ -84,3 +91,4 @@ */ | ||
static readonly Date: DateValidator; | ||
static readonly Kind: KindValidator; | ||
} | ||
//# sourceMappingURL=validators.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TypeValidators = exports.DateValidator = exports.Function = exports.StringMatchingRegex = exports.NumberWithMinimum = exports.TypeArray = exports.Type = exports.FactoryOrInstance = void 0; | ||
exports.TypeValidators = exports.KindValidator = exports.DateValidator = exports.Function = exports.StringMatchingRegex = exports.NumberWithMinimum = exports.TypeArray = exports.Type = exports.FactoryOrInstance = void 0; | ||
/** | ||
@@ -131,2 +131,14 @@ * Validate a factory or instance. | ||
/** | ||
* Validates that a string is a valid kind. | ||
*/ | ||
class KindValidator extends StringMatchingRegex { | ||
constructor() { | ||
super(/^(\w|\.|-)+$/); | ||
} | ||
is(u) { | ||
return super.is(u) && u !== 'kind'; | ||
} | ||
} | ||
exports.KindValidator = KindValidator; | ||
/** | ||
* A set of standard type validators. | ||
@@ -151,2 +163,3 @@ */ | ||
TypeValidators.Date = new DateValidator(); | ||
TypeValidators.Kind = new KindValidator(); | ||
//# sourceMappingURL=validators.js.map |
{ | ||
"name": "@launchdarkly/js-sdk-common", | ||
"version": "1.2.0-alpha", | ||
"version": "1.3.0-alpha.1", | ||
"type": "commonjs", | ||
@@ -26,3 +26,3 @@ "main": "./dist/index.js", | ||
"lint": "npx eslint . --ext .ts", | ||
"lint:fix": "yarn run lint -- --fix" | ||
"lint:fix": "yarn run lint --fix" | ||
}, | ||
@@ -29,0 +29,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
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
210607
248
3287