@eppo/js-client-sdk-common
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -38,5 +38,22 @@ import { AssignmentCache, Cacheable } from '../assignment-cache'; | ||
getParsedJSONAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks): object | null; | ||
setLogger(logger: IAssignmentLogger): void; | ||
useLRUInMemoryAssignmentCache(maxSize: number): void; | ||
useCustomAssignmentCache(cache: AssignmentCache<Cacheable>): void; | ||
fetchFlagConfigurations(): void; | ||
stopPolling(): void; | ||
setIsGracefulFailureMode(gracefulFailureMode: boolean): void; | ||
} | ||
export declare type ExperimentConfigurationRequestParameters = { | ||
apiKey: string; | ||
sdkVersion: string; | ||
sdkName: string; | ||
baseUrl?: string; | ||
requestTimeoutMs?: number; | ||
numInitialRequestRetries?: number; | ||
numPollRequestRetries?: number; | ||
pollAfterSuccessfulInitialization?: boolean; | ||
pollAfterFailedInitialization?: boolean; | ||
throwOnFailedInitialization?: boolean; | ||
}; | ||
export default class EppoClient implements IEppoClient { | ||
private configurationStore; | ||
private queuedEvents; | ||
@@ -46,3 +63,8 @@ private assignmentLogger; | ||
private assignmentCache; | ||
constructor(configurationStore: IConfigurationStore); | ||
private configurationStore; | ||
private configurationRequestConfig; | ||
private requestPoller; | ||
constructor(configurationStore: IConfigurationStore, configurationRequestConfig?: ExperimentConfigurationRequestParameters); | ||
fetchFlagConfigurations(): Promise<void>; | ||
stopPolling(): void; | ||
getAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks | undefined, obfuscated?: boolean): string | null; | ||
@@ -49,0 +71,0 @@ getStringAssignment(subjectKey: string, flagKey: string, subjectAttributes?: Record<string, any>, assignmentHooks?: IAssignmentHooks | undefined, obfuscated?: boolean): string | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const axios_1 = require("axios"); | ||
const md5 = require("md5"); | ||
@@ -8,3 +9,6 @@ const assignment_cache_1 = require("../assignment-cache"); | ||
const eppo_value_1 = require("../eppo_value"); | ||
const experiment_configuration_requestor_1 = require("../experiment-configuration-requestor"); | ||
const http_client_1 = require("../http-client"); | ||
const obfuscation_1 = require("../obfuscation"); | ||
const poller_1 = require("../poller"); | ||
const rule_evaluator_1 = require("../rule_evaluator"); | ||
@@ -14,7 +18,41 @@ const shard_1 = require("../shard"); | ||
class EppoClient { | ||
constructor(configurationStore) { | ||
this.configurationStore = configurationStore; | ||
constructor(configurationStore, configurationRequestConfig) { | ||
this.queuedEvents = []; | ||
this.isGracefulFailureMode = true; | ||
this.configurationStore = configurationStore; | ||
this.configurationRequestConfig = configurationRequestConfig; | ||
} | ||
async fetchFlagConfigurations() { | ||
var _a, _b, _c, _d, _e; | ||
if (!this.configurationRequestConfig) { | ||
throw new Error('Eppo SDK unable to fetch flag configurations without a request configuration'); | ||
} | ||
if (this.requestPoller) { | ||
// if fetchFlagConfigurations() was previously called, stop any polling process from that call | ||
this.requestPoller.stop(); | ||
} | ||
const axiosInstance = axios_1.default.create({ | ||
baseURL: this.configurationRequestConfig.baseUrl || constants_1.BASE_URL, | ||
timeout: this.configurationRequestConfig.requestTimeoutMs || constants_1.DEFAULT_REQUEST_TIMEOUT_MS, | ||
}); | ||
const httpClient = new http_client_1.default(axiosInstance, { | ||
apiKey: this.configurationRequestConfig.apiKey, | ||
sdkName: this.configurationRequestConfig.sdkName, | ||
sdkVersion: this.configurationRequestConfig.sdkVersion, | ||
}); | ||
const configurationRequestor = new experiment_configuration_requestor_1.default(this.configurationStore, httpClient); | ||
this.requestPoller = (0, poller_1.default)(constants_1.POLL_INTERVAL_MS, configurationRequestor.fetchAndStoreConfigurations.bind(configurationRequestor), { | ||
maxStartRetries: (_a = this.configurationRequestConfig.numInitialRequestRetries) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES, | ||
maxPollRetries: (_b = this.configurationRequestConfig.numPollRequestRetries) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_POLL_CONFIG_REQUEST_RETRIES, | ||
pollAfterSuccessfulStart: (_c = this.configurationRequestConfig.pollAfterSuccessfulInitialization) !== null && _c !== void 0 ? _c : false, | ||
pollAfterFailedStart: (_d = this.configurationRequestConfig.pollAfterFailedInitialization) !== null && _d !== void 0 ? _d : false, | ||
errorOnFailedStart: (_e = this.configurationRequestConfig.throwOnFailedInitialization) !== null && _e !== void 0 ? _e : false, | ||
}); | ||
await this.requestPoller.start(); | ||
} | ||
stopPolling() { | ||
if (this.requestPoller) { | ||
this.requestPoller.stop(); | ||
} | ||
} | ||
// @deprecated getAssignment is deprecated in favor of the typed get<Type>Assignment methods | ||
@@ -21,0 +59,0 @@ getAssignment(subjectKey, flagKey, |
@@ -0,2 +1,7 @@ | ||
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 5000; | ||
export declare const REQUEST_TIMEOUT_MILLIS = 5000; | ||
export declare const POLL_INTERVAL_MS = 30000; | ||
export declare const POLL_JITTER_PCT = 0.1; | ||
export declare const DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES = 1; | ||
export declare const DEFAULT_POLL_CONFIG_REQUEST_RETRIES = 7; | ||
export declare const BASE_URL = "https://fscdn.eppo.cloud/api"; | ||
@@ -3,0 +8,0 @@ export declare const SESSION_ASSIGNMENT_CONFIG_LOADED = "eppo-session-assignment-config-loaded"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MAX_EVENT_QUEUE_SIZE = exports.NULL_SENTINEL = exports.SESSION_ASSIGNMENT_CONFIG_LOADED = exports.BASE_URL = exports.REQUEST_TIMEOUT_MILLIS = void 0; | ||
exports.REQUEST_TIMEOUT_MILLIS = 5000; | ||
exports.MAX_EVENT_QUEUE_SIZE = exports.NULL_SENTINEL = exports.SESSION_ASSIGNMENT_CONFIG_LOADED = exports.BASE_URL = exports.DEFAULT_POLL_CONFIG_REQUEST_RETRIES = exports.DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES = exports.POLL_JITTER_PCT = exports.POLL_INTERVAL_MS = exports.REQUEST_TIMEOUT_MILLIS = exports.DEFAULT_REQUEST_TIMEOUT_MS = void 0; | ||
exports.DEFAULT_REQUEST_TIMEOUT_MS = 5000; | ||
exports.REQUEST_TIMEOUT_MILLIS = exports.DEFAULT_REQUEST_TIMEOUT_MS; // for backwards compatibility | ||
exports.POLL_INTERVAL_MS = 30000; | ||
exports.POLL_JITTER_PCT = 0.1; | ||
exports.DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES = 1; | ||
exports.DEFAULT_POLL_CONFIG_REQUEST_RETRIES = 7; | ||
exports.BASE_URL = 'https://fscdn.eppo.cloud/api'; | ||
@@ -6,0 +11,0 @@ exports.SESSION_ASSIGNMENT_CONFIG_LOADED = 'eppo-session-assignment-config-loaded'; |
import { AssignmentCache } from './assignment-cache'; | ||
import { IAssignmentHooks } from './assignment-hooks'; | ||
import { IAssignmentLogger, IAssignmentEvent } from './assignment-logger'; | ||
import EppoClient, { IEppoClient } from './client/eppo-client'; | ||
import EppoClient, { ExperimentConfigurationRequestParameters, IEppoClient } from './client/eppo-client'; | ||
import { IConfigurationStore } from './configuration-store'; | ||
@@ -10,3 +10,3 @@ import * as constants from './constants'; | ||
import * as validation from './validation'; | ||
export { IAssignmentHooks, IAssignmentLogger, IAssignmentEvent, EppoClient, IEppoClient, constants, ExperimentConfigurationRequestor, HttpClient, validation, IConfigurationStore, AssignmentCache, }; | ||
export { IAssignmentHooks, IAssignmentLogger, IAssignmentEvent, EppoClient, IEppoClient, constants, ExperimentConfigurationRequestor, HttpClient, validation, IConfigurationStore, AssignmentCache, ExperimentConfigurationRequestParameters, }; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@eppo/js-client-sdk-common", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)", | ||
@@ -42,3 +42,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@types/jest": "^28.1.1", | ||
"@types/jest": "^29.5.11", | ||
"@types/md5": "^2.3.2", | ||
@@ -53,8 +53,8 @@ "@typescript-eslint/eslint-plugin": "^5.13.0", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"jest": "^28.1.1", | ||
"jest-environment-jsdom": "^28.1.1", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"prettier": "^2.7.1", | ||
"terser-webpack-plugin": "^5.3.3", | ||
"testdouble": "^3.16.6", | ||
"ts-jest": "^28.0.5", | ||
"testdouble": "^3.20.1", | ||
"ts-jest": "^29.1.1", | ||
"ts-loader": "^9.3.1", | ||
@@ -61,0 +61,0 @@ "ts-node": "^10.9.1", |
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
552486
85
1469