Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "1.6.2-rc.0",
"version": "1.6.2-rc.4",
"description": "Split Javascript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
"types": "types",
"types": "src/types.d.ts",
"files": [
"README.md",
"CONTRIBUTORS-GUIDE.md",
"LICENSE",
"CHANGES.txt",
"cjs",
"esm",
"src",
"types"
"src"
],
"scripts": {
"check": "npm run check:lint && npm run check:types",
"check:lint": "eslint src --ext .js,.ts",
"check:types": "tsc --noEmit",
"build": "npm run build:cjs && npm run build:esm",
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
"build:esm": "rimraf esm types && tsc -m es2015 --outDir esm",
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
"test": "jest",
"test:coverage": "jest --coverage",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/mocks/fetchSpecificSplits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SplitIO } from '../../types';
import { SplitFilter } from '../../types';

const valuesExamples = [
['\u0223abc', 'abc\u0223asd', 'abc\u0223', 'abcȣ'],
Expand All @@ -12,7 +12,7 @@ const valuesExamples = [
['%', '%25', '__a', '__ш'], // [7] ordered and deduplicated
];

export const splitFilters: SplitIO.SplitFilter[][] = [
export const splitFilters: SplitFilter[][] = [
[
{ type: 'byName', values: valuesExamples[0] },
{ type: 'byName', values: valuesExamples[1] },
Expand Down
8 changes: 4 additions & 4 deletions src/consent/__tests__/sdkUserConsent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ test('createUserConsentAPI', () => {
expect(storage.events.clear).toBeCalledTimes(1); // storage tracked data dropped
expect(storage.impressions.clear).toBeCalledTimes(1);

// Invalid values have no effect
expect(props.setStatus('DECLINED')).toBe(false); // strings are not valid
expect(props.setStatus('GRANTED')).toBe(false);
expect(props.setStatus(undefined)).toBe(false);
// @ts-ignore Invalid values have no effect
expect(props.setStatus('DECLINED')).toBe(false); // @ts-ignore strings are not valid
expect(props.setStatus('GRANTED')).toBe(false); // @ts-ignore
expect(props.setStatus(undefined)).toBe(false); // @ts-ignore
expect(props.setStatus({})).toBe(false);

expect(syncManager.submitterManager.start).toBeCalledTimes(1);
Expand Down
7 changes: 4 additions & 3 deletions src/consent/sdkUserConsent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { isConsentGranted } from './index';
import { CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../utils/constants';
import { isBoolean } from '../utils/lang';
import { ISdkFactoryContext } from '../sdkFactory/types';
import { IUserConsentAPI } from '../types';

// User consent enum
const ConsentStatus = {
const ConsentStatus: IUserConsentAPI['Status'] = {
GRANTED: CONSENT_GRANTED,
DECLINED: CONSENT_DECLINED,
UNKNOWN: CONSENT_UNKNOWN,
Expand All @@ -14,7 +15,7 @@ const ConsentStatus = {
/**
* The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
*/
export function createUserConsentAPI(params: ISdkFactoryContext) {
export function createUserConsentAPI(params: ISdkFactoryContext): IUserConsentAPI {
const { settings, settings: { log }, syncManager, storage: { events, impressions, impressionCounts } } = params;

if (!isConsentGranted(settings)) log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
Expand Down Expand Up @@ -51,7 +52,7 @@ export function createUserConsentAPI(params: ISdkFactoryContext) {
},

getStatus() {
return settings.userConsent;
return settings.userConsent!;
},

Status: ConsentStatus
Expand Down
8 changes: 0 additions & 8 deletions src/dtos/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { SplitIO } from '../types';

export type MaybeThenable<T> = T | Promise<T>

/** Split Matchers */
Expand Down Expand Up @@ -204,9 +202,3 @@ export interface IMetadata {
/** host name */
n: string
}

export type ISplitFiltersValidation = {
queryString: string | null,
groupedFilters: Record<SplitIO.SplitFilterType, string[]>,
validFilters: SplitIO.SplitFilter[]
};
6 changes: 3 additions & 3 deletions src/evaluator/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { thenable } from '../utils/promise/thenable';
import * as LabelsConstants from '../utils/labels';
import { CONTROL } from '../utils/constants';
import { ISplit, MaybeThenable } from '../dtos/types';
import { SplitIO } from '../types';
import { SplitKey, Attributes } from '../types';
import { IStorageAsync, IStorageSync } from '../storages/types';
import { IEvaluation, IEvaluationResult, IEvaluator, ISplitEvaluator } from './types';
import { ILogger } from '../logger/types';
import { ILogger } from '../types';

function evaluationResult(result: IEvaluation | undefined, defaultTreatment: string): IEvaluationResult {
return {
Expand Down Expand Up @@ -38,7 +38,7 @@ export class Engine {
return this.baseInfo.name;
}

getTreatment(key: SplitIO.SplitKey, attributes: SplitIO.Attributes | undefined, splitEvaluator: ISplitEvaluator): MaybeThenable<IEvaluationResult> {
getTreatment(key: SplitKey, attributes: Attributes | undefined, splitEvaluator: ISplitEvaluator): MaybeThenable<IEvaluationResult> {
const {
killed,
seed,
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/combiners/and.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findIndex } from '../../utils/lang';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { thenable } from '../../utils/promise/thenable';
import { MaybeThenable } from '../../dtos/types';
import { IMatcher } from '../types';
Expand Down
6 changes: 3 additions & 3 deletions src/evaluator/combiners/ifelseif.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { findIndex } from '../../utils/lang';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { thenable } from '../../utils/promise/thenable';
import * as LabelsConstants from '../../utils/labels';
import { CONTROL } from '../../utils/constants';
import { SplitIO } from '../../types';
import { SplitKey, Attributes } from '../../types';
import { IEvaluation, IEvaluator, ISplitEvaluator } from '../types';
import { ENGINE_COMBINER_IFELSEIF, ENGINE_COMBINER_IFELSEIF_NO_TREATMENT, ERROR_ENGINE_COMBINER_IFELSEIF } from '../../logger/constants';

Expand Down Expand Up @@ -35,7 +35,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
return undefined;
}

function ifElseIfCombiner(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
function ifElseIfCombiner(key: SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: Attributes, splitEvaluator?: ISplitEvaluator) {
// In Async environments we are going to have async predicates. There is none way to know
// before hand so we need to evaluate all the predicates, verify for thenables, and finally,
// define how to return the treatment (wrap result into a Promise or not).
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/condition/engineUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_BUCKET } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { bucket } from '../../utils/murmur3/murmur3';

/**
Expand Down
12 changes: 6 additions & 6 deletions src/evaluator/condition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { thenable } from '../../utils/promise/thenable';
import * as LabelsConstants from '../../utils/labels';
import { MaybeThenable } from '../../dtos/types';
import { IEvaluation, IEvaluator, ISplitEvaluator } from '../types';
import { SplitIO } from '../../types';
import { ILogger } from '../../logger/types';
import { SplitKey, SplitKeyObject, Attributes } from '../../types';
import { ILogger } from '../../types';

// Build Evaluation object if and only if matchingResult is true
function match(log: ILogger, matchingResult: boolean, bucketingKey: string | undefined, seed: number, treatments: { getTreatmentFor: (x: number) => string }, label: string): IEvaluation | undefined {
Expand All @@ -24,10 +24,10 @@ function match(log: ILogger, matchingResult: boolean, bucketingKey: string | und
// Condition factory
export function conditionContext(log: ILogger, matcherEvaluator: (...args: any) => MaybeThenable<boolean>, treatments: { getTreatmentFor: (x: number) => string }, label: string, conditionType: 'ROLLOUT' | 'WHITELIST'): IEvaluator {

return function conditionEvaluator(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
return function conditionEvaluator(key: SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: Attributes, splitEvaluator?: ISplitEvaluator) {

// Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation as number, (key as SplitIO.SplitKeyObject).bucketingKey as string, trafficAllocationSeed as number)) {
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation as number, (key as SplitKeyObject).bucketingKey as string, trafficAllocationSeed as number)) {
return {
treatment: undefined, // treatment value is assigned later
label: LabelsConstants.NOT_IN_SPLIT
Expand All @@ -41,10 +41,10 @@ export function conditionContext(log: ILogger, matcherEvaluator: (...args: any)
const matches = matcherEvaluator(key, attributes, splitEvaluator);

if (thenable(matches)) {
return matches.then(result => match(log, result, (key as SplitIO.SplitKeyObject).bucketingKey, seed, treatments, label));
return matches.then(result => match(log, result, (key as SplitKeyObject).bucketingKey, seed, treatments, label));
}

return match(log, matches, (key as SplitIO.SplitKeyObject).bucketingKey, seed, treatments, label);
return match(log, matches, (key as SplitKeyObject).bucketingKey, seed, treatments, label);
};

}
20 changes: 10 additions & 10 deletions src/evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { CONTROL } from '../utils/constants';
import { ISplit, MaybeThenable } from '../dtos/types';
import { IStorageAsync, IStorageSync } from '../storages/types';
import { IEvaluationResult } from './types';
import { SplitIO } from '../types';
import { ILogger } from '../logger/types';
import { SplitKey, Attributes } from '../types';
import { ILogger } from '../types';

const treatmentException = {
treatment: CONTROL,
Expand All @@ -24,9 +24,9 @@ function treatmentsException(splitNames: string[]) {

export function evaluateFeature(
log: ILogger,
key: SplitIO.SplitKey,
key: SplitKey,
splitName: string,
attributes: SplitIO.Attributes | undefined,
attributes: Attributes | undefined,
storage: IStorageSync | IStorageAsync,
): MaybeThenable<IEvaluationResult> {
let stringifiedSplit;
Expand Down Expand Up @@ -63,9 +63,9 @@ export function evaluateFeature(

export function evaluateFeatures(
log: ILogger,
key: SplitIO.SplitKey,
key: SplitKey,
splitNames: string[],
attributes: SplitIO.Attributes | undefined,
attributes: Attributes | undefined,
storage: IStorageSync | IStorageAsync,
): MaybeThenable<Record<string, IEvaluationResult>> {
let stringifiedSplits;
Expand All @@ -90,8 +90,8 @@ export function evaluateFeatures(
function getEvaluation(
log: ILogger,
stringifiedSplit: string | null,
key: SplitIO.SplitKey,
attributes: SplitIO.Attributes | undefined,
key: SplitKey,
attributes: Attributes | undefined,
storage: IStorageSync | IStorageAsync,
): MaybeThenable<IEvaluationResult> {
let evaluation: MaybeThenable<IEvaluationResult> = {
Expand Down Expand Up @@ -126,8 +126,8 @@ function getEvaluations(
log: ILogger,
splitNames: string[],
splits: Record<string, string | null>,
key: SplitIO.SplitKey,
attributes: SplitIO.Attributes | undefined,
key: SplitKey,
attributes: Attributes | undefined,
storage: IStorageSync | IStorageAsync,
): MaybeThenable<Record<string, IEvaluationResult>> {
const result: Record<string, IEvaluationResult> = {};
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_ALL } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function allMatcherContext(log: ILogger) {
return function allMatcher(runtimeAttr: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/between.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IBetweenMatcherData } from '../../dtos/types';
import { ENGINE_MATCHER_BETWEEN } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function betweenMatcherContext(log: ILogger, ruleVO: IBetweenMatcherData) /*: Function */ {
return function betweenMatcher(runtimeAttr: number): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_BOOLEAN } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function booleanMatcherContext(log: ILogger, ruleAttr: boolean) /*: Function */ {
return function booleanMatcher(runtimeAttr: boolean): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/cont_all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_CONTAINS_ALL } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { findIndex } from '../../utils/lang';

export function containsAllSetMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/cont_any.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_CONTAINS_ANY } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { findIndex } from '../../utils/lang';

export function containsAnySetMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/cont_str.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isString } from '../../utils/lang';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { ENGINE_MATCHER_CONTAINS_STRING } from '../../logger/constants';

export function containsStringMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/dependency.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDependencyMatcherData, MaybeThenable } from '../../dtos/types';
import { IStorageAsync, IStorageSync } from '../../storages/types';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { thenable } from '../../utils/promise/thenable';
import { IDependencyMatcherValue, IEvaluation, ISplitEvaluator } from '../types';
import { ENGINE_MATCHER_DEPENDENCY, ENGINE_MATCHER_DEPENDENCY_PRE } from '../../logger/constants';
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/eq.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_EQUAL } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function equalToMatcherContext(log: ILogger, ruleAttr: number) /*: Function */ {
return function equalToMatcher(runtimeAttr: number): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/eq_set.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_EQUAL_TO_SET } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { findIndex } from '../../utils/lang';

export function equalToSetMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/ew.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_ENDS_WITH } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { endsWith } from '../../utils/lang';

export function endsWithMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/gte.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_GREATER } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function greaterThanEqualMatcherContext(log: ILogger, ruleAttr: number) /*: Function */ {
return function greaterThanEqualMatcher(runtimeAttr: number): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { booleanMatcherContext } from './boolean';
import { stringMatcherContext } from './string';
import { IStorageAsync, IStorageSync } from '../../storages/types';
import { IMatcher, IMatcherDto } from '../types';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

const matchers = [
undefined, // UNDEFINED: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/lte.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_LESS } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function lessThanEqualMatcherContext(log: ILogger, ruleAttr: number) /*: function */ {
return function lessThanEqualMatcher(runtimeAttr: number): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/part_of.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findIndex } from '../../utils/lang';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { ENGINE_MATCHER_PART_OF } from '../../logger/constants';

export function partOfSetMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/segment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MaybeThenable } from '../../dtos/types';
import { ISegmentsCacheBase } from '../../storages/types';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { thenable } from '../../utils/promise/thenable';
import { ENGINE_MATCHER_SEGMENT } from '../../logger/constants';

Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/string.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_STRING_INVALID, ENGINE_MATCHER_STRING } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';

export function stringMatcherContext(log: ILogger, ruleAttr: string) /*: Function */ {
return function stringMatcher(runtimeAttr: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/sw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ENGINE_MATCHER_STARTS_WITH } from '../../logger/constants';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { startsWith } from '../../utils/lang';

export function startsWithMatcherContext(log: ILogger, ruleAttr: string[]) /*: Function */ {
Expand Down
2 changes: 1 addition & 1 deletion src/evaluator/matchers/whitelist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setToArray, ISet } from '../../utils/lang/sets';
import { ILogger } from '../../logger/types';
import { ILogger } from '../../types';
import { ENGINE_MATCHER_WHITELIST } from '../../logger/constants';

export function whitelistMatcherContext(log: ILogger, ruleAttr: ISet<string>) /*: Function */ {
Expand Down
Loading