@eppo/js-client-sdk-common
Advanced tools
Comparing version 3.2.2 to 3.3.0
@@ -1,3 +0,3 @@ | ||
import { AssignmentCache, Cacheable } from '../assignment-cache'; | ||
import { IAssignmentLogger } from '../assignment-logger'; | ||
import { AssignmentCache } from '../cache/assignment-cache'; | ||
import { IConfigurationStore } from '../configuration-store/configuration-store'; | ||
@@ -70,3 +70,3 @@ import { FlagEvaluation } from '../evaluator'; | ||
useLRUInMemoryAssignmentCache(maxSize: number): void; | ||
useCustomAssignmentCache(cache: AssignmentCache<Cacheable>): void; | ||
useCustomAssignmentCache(cache: AssignmentCache): void; | ||
setConfigurationRequestParameters(configurationRequestParameters: FlagConfigurationRequestParameters): void; | ||
@@ -94,12 +94,12 @@ setConfigurationStore(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>): void; | ||
export default class EppoClient implements IEppoClient { | ||
private configurationStore; | ||
private configurationRequestParameters?; | ||
private readonly isObfuscated; | ||
private queuedEvents; | ||
private assignmentLogger; | ||
private assignmentLogger?; | ||
private isGracefulFailureMode; | ||
private assignmentCache; | ||
private configurationStore; | ||
private configurationRequestParameters; | ||
private requestPoller; | ||
private assignmentCache?; | ||
private requestPoller?; | ||
private evaluator; | ||
constructor(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>, configurationRequestParameters?: FlagConfigurationRequestParameters, isObfuscated?: boolean); | ||
constructor(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>, configurationRequestParameters?: FlagConfigurationRequestParameters | undefined, isObfuscated?: boolean); | ||
setConfigurationRequestParameters(configurationRequestParameters: FlagConfigurationRequestParameters): void; | ||
@@ -141,3 +141,3 @@ setConfigurationStore(configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>): void; | ||
useLRUInMemoryAssignmentCache(maxSize: number): void; | ||
useCustomAssignmentCache(cache: AssignmentCache<Cacheable>): void; | ||
useCustomAssignmentCache(cache: AssignmentCache): void; | ||
setIsGracefulFailureMode(gracefulFailureMode: boolean): void; | ||
@@ -144,0 +144,0 @@ private flushQueuedEvents; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const application_logger_1 = require("../application-logger"); | ||
const assignment_cache_1 = require("../assignment-cache"); | ||
const assignment_cache_1 = require("../cache/assignment-cache"); | ||
const constants_1 = require("../constants"); | ||
@@ -21,2 +21,4 @@ const decoding_1 = require("../decoding"); | ||
constructor(configurationStore, configurationRequestParameters, isObfuscated = false) { | ||
this.configurationStore = configurationStore; | ||
this.configurationRequestParameters = configurationRequestParameters; | ||
this.isObfuscated = isObfuscated; | ||
@@ -26,4 +28,2 @@ this.queuedEvents = []; | ||
this.evaluator = new evaluator_1.Evaluator(); | ||
this.configurationStore = configurationStore; | ||
this.configurationRequestParameters = configurationRequestParameters; | ||
} | ||
@@ -216,4 +216,5 @@ setConfigurationRequestParameters(configurationRequestParameters) { | ||
logAssignment(result) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
const event = Object.assign(Object.assign({}, ((_a = result.extraLogging) !== null && _a !== void 0 ? _a : {})), { allocation: (_b = result.allocationKey) !== null && _b !== void 0 ? _b : null, experiment: result.allocationKey ? `${result.flagKey}-${result.allocationKey}` : null, featureFlag: result.flagKey, variation: (_d = (_c = result.variation) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : null, subject: result.subjectKey, timestamp: new Date().toISOString(), subjectAttributes: result.subjectAttributes, metaData: { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const { flagKey, subjectKey, allocationKey, subjectAttributes, variation } = result; | ||
const event = Object.assign(Object.assign({}, ((_a = result.extraLogging) !== null && _a !== void 0 ? _a : {})), { allocation: allocationKey !== null && allocationKey !== void 0 ? allocationKey : null, experiment: allocationKey ? `${flagKey}-${allocationKey}` : null, featureFlag: flagKey, variation: (_b = variation === null || variation === void 0 ? void 0 : variation.key) !== null && _b !== void 0 ? _b : null, subject: subjectKey, timestamp: new Date().toISOString(), subjectAttributes, metaData: { | ||
obfuscated: this.isObfuscated, | ||
@@ -223,11 +224,12 @@ sdkLanguage: 'javascript', | ||
} }); | ||
if (result.variation && | ||
result.allocationKey && | ||
((_e = this.assignmentCache) === null || _e === void 0 ? void 0 : _e.hasLoggedAssignment({ | ||
flagKey: result.flagKey, | ||
subjectKey: result.subjectKey, | ||
allocationKey: result.allocationKey, | ||
variationKey: result.variation.key, | ||
}))) { | ||
return; | ||
if (variation && allocationKey) { | ||
const hasLoggedAssignment = (_c = this.assignmentCache) === null || _c === void 0 ? void 0 : _c.has({ | ||
flagKey, | ||
subjectKey, | ||
allocationKey, | ||
variationKey: variation.key, | ||
}); | ||
if (hasLoggedAssignment) { | ||
return; | ||
} | ||
} | ||
@@ -241,7 +243,7 @@ // assignment logger may be null while waiting for initialization | ||
this.assignmentLogger.logAssignment(event); | ||
(_f = this.assignmentCache) === null || _f === void 0 ? void 0 : _f.setLastLoggedAssignment({ | ||
flagKey: result.flagKey, | ||
(_d = this.assignmentCache) === null || _d === void 0 ? void 0 : _d.set({ | ||
flagKey: flagKey, | ||
subjectKey: result.subjectKey, | ||
allocationKey: (_g = result.allocationKey) !== null && _g !== void 0 ? _g : '__eppo_no_allocation', | ||
variationKey: (_j = (_h = result.variation) === null || _h === void 0 ? void 0 : _h.key) !== null && _j !== void 0 ? _j : '__eppo_no_variation', | ||
allocationKey: (_e = result.allocationKey) !== null && _e !== void 0 ? _e : '__eppo_no_allocation', | ||
variationKey: (_g = (_f = result.variation) === null || _f === void 0 ? void 0 : _f.key) !== null && _g !== void 0 ? _g : '__eppo_no_variation', | ||
}); | ||
@@ -248,0 +250,0 @@ } |
@@ -24,4 +24,2 @@ /** | ||
export interface IConfigurationStore<T> { | ||
servingStore: ISyncStore<T>; | ||
persistentStore: IAsyncStore<T> | null; | ||
init(): Promise<void>; | ||
@@ -28,0 +26,0 @@ get(key: string): T | null; |
import { IAsyncStore, IConfigurationStore, ISyncStore } from './configuration-store'; | ||
export declare class HybridConfigurationStore<T> implements IConfigurationStore<T> { | ||
servingStore: ISyncStore<T>; | ||
persistentStore: IAsyncStore<T> | null; | ||
private readonly servingStore; | ||
private readonly persistentStore; | ||
constructor(servingStore: ISyncStore<T>, persistentStore: IAsyncStore<T> | null); | ||
@@ -6,0 +6,0 @@ /** |
@@ -35,5 +35,5 @@ "use strict"; | ||
async isExpired() { | ||
var _a, _b; | ||
const isExpired = (_b = (await ((_a = this.persistentStore) === null || _a === void 0 ? void 0 : _a.isExpired()))) !== null && _b !== void 0 ? _b : true; | ||
return isExpired; | ||
var _a; | ||
const isExpired = await ((_a = this.persistentStore) === null || _a === void 0 ? void 0 : _a.isExpired()); | ||
return isExpired !== null && isExpired !== void 0 ? isExpired : true; | ||
} | ||
@@ -40,0 +40,0 @@ get(key) { |
@@ -1,2 +0,2 @@ | ||
import { IAsyncStore, IConfigurationStore, ISyncStore } from './configuration-store'; | ||
import { IConfigurationStore, ISyncStore } from './configuration-store'; | ||
export declare class MemoryStore<T> implements ISyncStore<T> { | ||
@@ -11,6 +11,4 @@ private store; | ||
export declare class MemoryOnlyConfigurationStore<T> implements IConfigurationStore<T> { | ||
servingStore: ISyncStore<T>; | ||
persistentStore: IAsyncStore<T> | null; | ||
private readonly servingStore; | ||
private initialized; | ||
constructor(); | ||
init(): Promise<void>; | ||
@@ -17,0 +15,0 @@ get(key: string): T | null; |
@@ -28,3 +28,2 @@ "use strict"; | ||
this.servingStore = new MemoryStore(); | ||
this.persistentStore = null; | ||
this.initialized = false; | ||
@@ -31,0 +30,0 @@ } |
import { logger } from './application-logger'; | ||
import { Cacheable, AssignmentCache, NonExpiringInMemoryAssignmentCache, LRUInMemoryAssignmentCache } from './assignment-cache'; | ||
import { IAssignmentHooks } from './assignment-hooks'; | ||
import { IAssignmentLogger, IAssignmentEvent } from './assignment-logger'; | ||
import { AbstractAssignmentCache, AssignmentCache, NonExpiringInMemoryAssignmentCache, LRUInMemoryAssignmentCache, AsyncMap } from './cache/assignment-cache'; | ||
import EppoClient, { FlagConfigurationRequestParameters, IEppoClient } from './client/eppo-client'; | ||
@@ -15,3 +15,3 @@ import { IConfigurationStore, IAsyncStore, ISyncStore } from './configuration-store/configuration-store'; | ||
import * as validation from './validation'; | ||
export { logger as applicationLogger, IAssignmentHooks, IAssignmentLogger, IAssignmentEvent, EppoClient, IEppoClient, constants, FlagConfigRequestor, HttpClient, validation, IConfigurationStore, IAsyncStore, ISyncStore, MemoryStore, HybridConfigurationStore, MemoryOnlyConfigurationStore, AssignmentCache, Cacheable, NonExpiringInMemoryAssignmentCache, LRUInMemoryAssignmentCache, FlagConfigurationRequestParameters, Flag, VariationType, AttributeType, SubjectAttributes, }; | ||
export { logger as applicationLogger, AbstractAssignmentCache, IAssignmentHooks, IAssignmentLogger, IAssignmentEvent, EppoClient, IEppoClient, constants, FlagConfigRequestor, HttpClient, validation, IConfigurationStore, IAsyncStore, ISyncStore, MemoryStore, HybridConfigurationStore, MemoryOnlyConfigurationStore, AssignmentCache, AsyncMap, NonExpiringInMemoryAssignmentCache, LRUInMemoryAssignmentCache, FlagConfigurationRequestParameters, Flag, VariationType, AttributeType, SubjectAttributes, }; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VariationType = exports.LRUInMemoryAssignmentCache = exports.NonExpiringInMemoryAssignmentCache = exports.AssignmentCache = exports.MemoryOnlyConfigurationStore = exports.HybridConfigurationStore = exports.MemoryStore = exports.validation = exports.HttpClient = exports.FlagConfigRequestor = exports.constants = exports.EppoClient = exports.applicationLogger = void 0; | ||
exports.VariationType = exports.LRUInMemoryAssignmentCache = exports.NonExpiringInMemoryAssignmentCache = exports.MemoryOnlyConfigurationStore = exports.HybridConfigurationStore = exports.MemoryStore = exports.validation = exports.HttpClient = exports.FlagConfigRequestor = exports.constants = exports.EppoClient = exports.AbstractAssignmentCache = exports.applicationLogger = void 0; | ||
const application_logger_1 = require("./application-logger"); | ||
Object.defineProperty(exports, "applicationLogger", { enumerable: true, get: function () { return application_logger_1.logger; } }); | ||
const assignment_cache_1 = require("./assignment-cache"); | ||
Object.defineProperty(exports, "AssignmentCache", { enumerable: true, get: function () { return assignment_cache_1.AssignmentCache; } }); | ||
const assignment_cache_1 = require("./cache/assignment-cache"); | ||
Object.defineProperty(exports, "AbstractAssignmentCache", { enumerable: true, get: function () { return assignment_cache_1.AbstractAssignmentCache; } }); | ||
Object.defineProperty(exports, "NonExpiringInMemoryAssignmentCache", { enumerable: true, get: function () { return assignment_cache_1.NonExpiringInMemoryAssignmentCache; } }); | ||
@@ -9,0 +9,0 @@ Object.defineProperty(exports, "LRUInMemoryAssignmentCache", { enumerable: true, get: function () { return assignment_cache_1.LRUInMemoryAssignmentCache; } }); |
@@ -5,2 +5,3 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const util_1 = require("./util"); | ||
// TODO: change this to a class with methods instead of something that returns a function | ||
@@ -36,3 +37,3 @@ function initPoller(intervalMs, | ||
application_logger_1.logger.warn(`Eppo SDK will retry the initial poll again in ${jitterMs} ms (${startAttemptsRemaining} attempts remaining)`); | ||
await new Promise((resolve) => setTimeout(resolve, jitterMs)); | ||
await (0, util_1.waitForMs)(jitterMs); | ||
} | ||
@@ -39,0 +40,0 @@ else { |
{ | ||
"name": "@eppo/js-client-sdk-common", | ||
"version": "3.2.2", | ||
"version": "3.3.0", | ||
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)", | ||
@@ -46,2 +46,3 @@ "main": "dist/index.js", | ||
"@types/js-base64": "^3.3.1", | ||
"@types/lodash": "^4.17.5", | ||
"@types/md5": "^2.3.2", | ||
@@ -59,2 +60,3 @@ "@types/semver": "^7.5.6", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"lodash": "^4.17.21", | ||
"prettier": "^2.7.1", | ||
@@ -61,0 +63,0 @@ "terser-webpack-plugin": "^5.3.3", |
import ApiEndpoints from '../api-endpoints'; | ||
import { logger } from '../application-logger'; | ||
import { IAssignmentEvent, IAssignmentLogger } from '../assignment-logger'; | ||
import { | ||
AssignmentCache, | ||
Cacheable, | ||
LRUInMemoryAssignmentCache, | ||
NonExpiringInMemoryAssignmentCache, | ||
} from '../assignment-cache'; | ||
import { IAssignmentEvent, IAssignmentLogger } from '../assignment-logger'; | ||
} from '../cache/assignment-cache'; | ||
import { IConfigurationStore } from '../configuration-store/configuration-store'; | ||
@@ -132,3 +131,3 @@ import { | ||
useCustomAssignmentCache(cache: AssignmentCache<Cacheable>): void; | ||
useCustomAssignmentCache(cache: AssignmentCache): void; | ||
@@ -168,19 +167,13 @@ setConfigurationRequestParameters( | ||
private queuedEvents: IAssignmentEvent[] = []; | ||
private assignmentLogger: IAssignmentLogger | undefined; | ||
private assignmentLogger?: IAssignmentLogger; | ||
private isGracefulFailureMode = true; | ||
private assignmentCache: AssignmentCache<Cacheable> | undefined; | ||
private configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>; | ||
private configurationRequestParameters: FlagConfigurationRequestParameters | undefined; | ||
private requestPoller: IPoller | undefined; | ||
private evaluator: Evaluator; | ||
private assignmentCache?: AssignmentCache; | ||
private requestPoller?: IPoller; | ||
private evaluator = new Evaluator(); | ||
constructor( | ||
configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>, | ||
configurationRequestParameters?: FlagConfigurationRequestParameters, | ||
private configurationStore: IConfigurationStore<Flag | ObfuscatedFlag>, | ||
private configurationRequestParameters?: FlagConfigurationRequestParameters, | ||
private readonly isObfuscated = false, | ||
) { | ||
this.evaluator = new Evaluator(); | ||
this.configurationStore = configurationStore; | ||
this.configurationRequestParameters = configurationRequestParameters; | ||
} | ||
) {} | ||
@@ -501,3 +494,3 @@ public setConfigurationRequestParameters( | ||
public useCustomAssignmentCache(cache: AssignmentCache<Cacheable>) { | ||
public useCustomAssignmentCache(cache: AssignmentCache) { | ||
this.assignmentCache = cache; | ||
@@ -523,11 +516,12 @@ } | ||
private logAssignment(result: FlagEvaluation) { | ||
const { flagKey, subjectKey, allocationKey, subjectAttributes, variation } = result; | ||
const event: IAssignmentEvent = { | ||
...(result.extraLogging ?? {}), | ||
allocation: result.allocationKey ?? null, | ||
experiment: result.allocationKey ? `${result.flagKey}-${result.allocationKey}` : null, | ||
featureFlag: result.flagKey, | ||
variation: result.variation?.key ?? null, | ||
subject: result.subjectKey, | ||
allocation: allocationKey ?? null, | ||
experiment: allocationKey ? `${flagKey}-${allocationKey}` : null, | ||
featureFlag: flagKey, | ||
variation: variation?.key ?? null, | ||
subject: subjectKey, | ||
timestamp: new Date().toISOString(), | ||
subjectAttributes: result.subjectAttributes, | ||
subjectAttributes, | ||
metaData: { | ||
@@ -540,13 +534,12 @@ obfuscated: this.isObfuscated, | ||
if ( | ||
result.variation && | ||
result.allocationKey && | ||
this.assignmentCache?.hasLoggedAssignment({ | ||
flagKey: result.flagKey, | ||
subjectKey: result.subjectKey, | ||
allocationKey: result.allocationKey, | ||
variationKey: result.variation.key, | ||
}) | ||
) { | ||
return; | ||
if (variation && allocationKey) { | ||
const hasLoggedAssignment = this.assignmentCache?.has({ | ||
flagKey, | ||
subjectKey, | ||
allocationKey, | ||
variationKey: variation.key, | ||
}); | ||
if (hasLoggedAssignment) { | ||
return; | ||
} | ||
} | ||
@@ -561,4 +554,4 @@ | ||
this.assignmentLogger.logAssignment(event); | ||
this.assignmentCache?.setLastLoggedAssignment({ | ||
flagKey: result.flagKey, | ||
this.assignmentCache?.set({ | ||
flagKey: flagKey, | ||
subjectKey: result.subjectKey, | ||
@@ -565,0 +558,0 @@ allocationKey: result.allocationKey ?? '__eppo_no_allocation', |
@@ -24,5 +24,2 @@ /** | ||
export interface IConfigurationStore<T> { | ||
servingStore: ISyncStore<T>; | ||
persistentStore: IAsyncStore<T> | null; | ||
init(): Promise<void>; | ||
@@ -29,0 +26,0 @@ get(key: string): T | null; |
@@ -6,10 +6,7 @@ import { logger, loggerPrefix } from '../application-logger'; | ||
export class HybridConfigurationStore<T> implements IConfigurationStore<T> { | ||
servingStore: ISyncStore<T>; | ||
persistentStore: IAsyncStore<T> | null; | ||
constructor( | ||
private readonly servingStore: ISyncStore<T>, | ||
private readonly persistentStore: IAsyncStore<T> | null, | ||
) {} | ||
constructor(servingStore: ISyncStore<T>, persistentStore: IAsyncStore<T> | null) { | ||
this.servingStore = servingStore; | ||
this.persistentStore = persistentStore; | ||
} | ||
/** | ||
@@ -45,4 +42,4 @@ * Initialize the configuration store by loading the entries from the persistent store into the serving store. | ||
public async isExpired(): Promise<boolean> { | ||
const isExpired = (await this.persistentStore?.isExpired()) ?? true; | ||
return isExpired; | ||
const isExpired = await this.persistentStore?.isExpired(); | ||
return isExpired ?? true; | ||
} | ||
@@ -49,0 +46,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { IAsyncStore, IConfigurationStore, ISyncStore } from './configuration-store'; | ||
import { IConfigurationStore, ISyncStore } from './configuration-store'; | ||
@@ -26,12 +26,5 @@ export class MemoryStore<T> implements ISyncStore<T> { | ||
export class MemoryOnlyConfigurationStore<T> implements IConfigurationStore<T> { | ||
servingStore: ISyncStore<T>; | ||
persistentStore: IAsyncStore<T> | null; | ||
private initialized: boolean; | ||
private readonly servingStore: ISyncStore<T> = new MemoryStore<T>(); | ||
private initialized = false; | ||
constructor() { | ||
this.servingStore = new MemoryStore<T>(); | ||
this.persistentStore = null; | ||
this.initialized = false; | ||
} | ||
init(): Promise<void> { | ||
@@ -38,0 +31,0 @@ this.initialized = true; |
import { logger } from './application-logger'; | ||
import { IAssignmentHooks } from './assignment-hooks'; | ||
import { IAssignmentLogger, IAssignmentEvent } from './assignment-logger'; | ||
import { | ||
Cacheable, | ||
AbstractAssignmentCache, | ||
AssignmentCache, | ||
NonExpiringInMemoryAssignmentCache, | ||
LRUInMemoryAssignmentCache, | ||
} from './assignment-cache'; | ||
import { IAssignmentHooks } from './assignment-hooks'; | ||
import { IAssignmentLogger, IAssignmentEvent } from './assignment-logger'; | ||
AsyncMap, | ||
} from './cache/assignment-cache'; | ||
import EppoClient, { FlagConfigurationRequestParameters, IEppoClient } from './client/eppo-client'; | ||
@@ -27,2 +28,3 @@ import { | ||
logger as applicationLogger, | ||
AbstractAssignmentCache, | ||
IAssignmentHooks, | ||
@@ -48,3 +50,3 @@ IAssignmentLogger, | ||
AssignmentCache, | ||
Cacheable, | ||
AsyncMap, | ||
NonExpiringInMemoryAssignmentCache, | ||
@@ -51,0 +53,0 @@ LRUInMemoryAssignmentCache, |
@@ -7,2 +7,3 @@ import { logger } from './application-logger'; | ||
} from './constants'; | ||
import { waitForMs } from './util'; | ||
@@ -61,3 +62,3 @@ export interface IPoller { | ||
); | ||
await new Promise((resolve) => setTimeout(resolve, jitterMs)); | ||
await waitForMs(jitterMs); | ||
} else { | ||
@@ -64,0 +65,0 @@ if (options?.pollAfterFailedStart) { |
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 too big to display
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
582683
136
4097
25