Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 src/application-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const loggerPrefix = '[Eppo SDK]';

// Create a Pino logger instance
export const logger = pino({
level: process.env.NODE_ENV === 'production' ? 'warn' : 'info',
level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === 'production' ? 'warn' : 'info'),
// https://getpino.io/#/docs/browser
browser: { disabled: true },
});
15 changes: 8 additions & 7 deletions src/client/eppo-client-assignment-details.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
readMockUFCResponse,
} from '../../test/testHelpers';
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store';
import ArrayBackedNamedEventQueue from '../events/array-backed-named-event-queue';

Check warning on line 9 in src/client/eppo-client-assignment-details.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (23)

'ArrayBackedNamedEventQueue' is defined but never used

Check warning on line 9 in src/client/eppo-client-assignment-details.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (20)

'ArrayBackedNamedEventQueue' is defined but never used

Check warning on line 9 in src/client/eppo-client-assignment-details.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (18)

'ArrayBackedNamedEventQueue' is defined but never used

Check warning on line 9 in src/client/eppo-client-assignment-details.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (22)

'ArrayBackedNamedEventQueue' is defined but never used
import { AllocationEvaluationCode } from '../flag-evaluation-details-builder';
import { Flag, ObfuscatedFlag, Variation, VariationType } from '../interfaces';
import { OperatorType } from '../rules';
Expand Down Expand Up @@ -33,7 +34,7 @@
});

it('should set the details for a matched rule', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const subjectAttributes = { email: '[email protected]', country: 'US' };
const result = client.getIntegerAssignmentDetails(
Expand Down Expand Up @@ -85,7 +86,7 @@
});

it('should set the details for a matched split', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const subjectAttributes = { email: '[email protected]', country: 'Brazil' };
const result = client.getIntegerAssignmentDetails(
Expand Down Expand Up @@ -128,7 +129,7 @@
});

it('should handle matching a split allocation with a matched rule', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const subjectAttributes = { id: 'alice', email: '[email protected]', country: 'Brazil' };
const result = client.getStringAssignmentDetails(
Expand Down Expand Up @@ -190,7 +191,7 @@
});

it('should handle unrecognized flags', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
const result = client.getIntegerAssignmentDetails('asdf', 'alice', {}, 0);
expect(result).toEqual({
Expand All @@ -215,7 +216,7 @@
});

it('should handle type mismatches with graceful failure mode enabled', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(true);
const result = client.getBooleanAssignmentDetails('integer-flag', 'alice', {}, true);
expect(result).toEqual({
Expand Down Expand Up @@ -252,7 +253,7 @@
});

it('should throw an error for type mismatches with graceful failure mode disabled', () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);
expect(() => client.getBooleanAssignmentDetails('integer-flag', 'alice', {}, true)).toThrow();
});
Expand Down Expand Up @@ -302,7 +303,7 @@
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const subject = subjects.find((subject) => subject.subjectKey === subjectKey)!;

const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);

const focusOn = {
Expand Down
2 changes: 1 addition & 1 deletion src/client/eppo-client-experiment-container.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('getExperimentContainerEntry', () => {
beforeEach(async () => {
const storage = new MemoryOnlyConfigurationStore<Flag | ObfuscatedFlag>();
await initConfiguration(storage);
client = new EppoClient(storage);
client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(true);
flagExperiment = {
flagKey: 'my-key',
Expand Down
7 changes: 6 additions & 1 deletion src/client/eppo-client-with-bandits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ describe('EppoClient Bandits E2E test', () => {
});

beforeEach(() => {
client = new EppoClient(flagStore, banditVariationStore, banditModelStore, undefined, false);
client = new EppoClient({
flagConfigurationStore: flagStore,
banditVariationConfigurationStore: banditVariationStore,
banditModelConfigurationStore: banditModelStore,
isObfuscated: false,
});
client.setIsGracefulFailureMode(false);
client.setAssignmentLogger({ logAssignment: mockLogAssignment });
client.setBanditLogger({ logBanditAction: mockLogBanditAction });
Expand Down
58 changes: 38 additions & 20 deletions src/client/eppo-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { IConfigurationStore } from '../configuration-store/configuration-store';
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store';
import { MAX_EVENT_QUEUE_SIZE, DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } from '../constants';
import ArrayBackedNamedEventQueue from '../events/array-backed-named-event-queue';

Check warning on line 19 in src/client/eppo-client.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (23)

'ArrayBackedNamedEventQueue' is defined but never used

Check warning on line 19 in src/client/eppo-client.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (20)

'ArrayBackedNamedEventQueue' is defined but never used

Check warning on line 19 in src/client/eppo-client.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (18)

'ArrayBackedNamedEventQueue' is defined but never used

Check warning on line 19 in src/client/eppo-client.spec.ts

View workflow job for this annotation

GitHub Actions / lint-test-sdk (22)

'ArrayBackedNamedEventQueue' is defined but never used
import { Flag, ObfuscatedFlag, VariationType } from '../interfaces';
import { AttributeType } from '../types';

Expand Down Expand Up @@ -76,7 +77,7 @@

beforeAll(() => {
storage.setEntries({ [flagKey]: mockFlag });
client = new EppoClient(storage);
client = new EppoClient({ flagConfigurationStore: storage });

td.replace(EppoClient.prototype, 'getAssignmentDetail', function () {
throw new Error('Mock test error');
Expand Down Expand Up @@ -137,7 +138,7 @@
it('Invokes logger for queued events', () => {
const mockLogger = td.object<IAssignmentLogger>();

const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.getStringAssignment(flagKey, 'subject-to-be-logged', {}, 'default-value');
client.setAssignmentLogger(mockLogger);

Expand All @@ -150,7 +151,7 @@
it('Does not log same queued event twice', () => {
const mockLogger = td.object<IAssignmentLogger>();

const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });

client.getStringAssignment(flagKey, 'subject-to-be-logged', {}, 'default-value');
client.setAssignmentLogger(mockLogger);
Expand All @@ -161,7 +162,7 @@

it('Does not invoke logger for events that exceed queue size', () => {
const mockLogger = td.object<IAssignmentLogger>();
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });

times(MAX_EVENT_QUEUE_SIZE + 100, (i) =>
client.getStringAssignment(flagKey, `subject-to-be-logged-${i}`, {}, 'default-value'),
Expand Down Expand Up @@ -199,7 +200,7 @@

it.each(Object.keys(testCases))('test variation assignment splits - %s', async (fileName) => {
const { flag, variationType, defaultValue, subjects } = testCases[fileName];
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setIsGracefulFailureMode(false);

let assignments: {
Expand Down Expand Up @@ -253,7 +254,7 @@

it.each(Object.keys(testCases))('test variation assignment splits - %s', async (fileName) => {
const { flag, variationType, defaultValue, subjects } = testCases[fileName];
const client = new EppoClient(storage, undefined, undefined, undefined, true);
const client = new EppoClient({ flagConfigurationStore: storage, isObfuscated: true });
client.setIsGracefulFailureMode(false);

const typeAssignmentFunctions = {
Expand Down Expand Up @@ -285,15 +286,17 @@
});

it('returns null if getStringAssignment was called for the subject before any UFC was loaded', () => {
const localClient = new EppoClient(new MemoryOnlyConfigurationStore());
const localClient = new EppoClient({
flagConfigurationStore: new MemoryOnlyConfigurationStore(),
});
expect(localClient.getStringAssignment(flagKey, 'subject-1', {}, 'hello world')).toEqual(
'hello world',
);
expect(localClient.isInitialized()).toBe(false);
});

it('returns default value when key does not exist', async () => {
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });

const nonExistentFlag = 'non-existent-flag';

Expand All @@ -310,7 +313,7 @@
const mockLogger = td.object<IAssignmentLogger>();

storage.setEntries({ [flagKey]: mockFlag });
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setAssignmentLogger(mockLogger);

const subjectAttributes = { foo: 3 };
Expand All @@ -336,7 +339,7 @@
td.when(mockLogger.logAssignment(td.matchers.anything())).thenThrow(new Error('logging error'));

storage.setEntries({ [flagKey]: mockFlag });
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
client.setAssignmentLogger(mockLogger);

const subjectAttributes = { foo: 3 };
Expand All @@ -352,7 +355,7 @@

it('exports flag configuration', () => {
storage.setEntries({ [flagKey]: mockFlag });
const client = new EppoClient(storage);
const client = new EppoClient({ flagConfigurationStore: storage });
expect(client.getFlagConfigurations()).toEqual({ [flagKey]: mockFlag });
});

Expand All @@ -364,7 +367,7 @@
mockLogger = td.object<IAssignmentLogger>();

storage.setEntries({ [flagKey]: mockFlag });
client = new EppoClient(storage);
client = new EppoClient({ flagConfigurationStore: storage });
client.setAssignmentLogger(mockLogger);
});

Expand Down Expand Up @@ -617,7 +620,10 @@
});

it('Fetches initial configuration with parameters in constructor', async () => {
client = new EppoClient(thisFlagStorage, undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: thisFlagStorage,
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
let variation = client.getNumericAssignment(flagKey, subject, {}, 123.4);
Expand All @@ -629,7 +635,7 @@
});

it('Fetches initial configuration with parameters provided later', async () => {
client = new EppoClient(thisFlagStorage);
client = new EppoClient({ flagConfigurationStore: thisFlagStorage });
client.setIsGracefulFailureMode(false);
client.setConfigurationRequestParameters(requestConfiguration);
// no configuration loaded
Expand All @@ -651,9 +657,12 @@
}
}

client = new EppoClient(new MockStore(), undefined, undefined, {
...requestConfiguration,
pollAfterSuccessfulInitialization: true,
client = new EppoClient({
flagConfigurationStore: new MockStore(),
configurationRequestParameters: {
...requestConfiguration,
pollAfterSuccessfulInitialization: true,
},
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
Expand All @@ -680,7 +689,10 @@
}
}

client = new EppoClient(new MockStore(), undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: new MockStore(),
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
let variation = client.getNumericAssignment(flagKey, subject, {}, 0.0);
Expand Down Expand Up @@ -722,7 +734,10 @@
...requestConfiguration,
pollAfterSuccessfulInitialization,
};
client = new EppoClient(thisFlagStorage, undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: thisFlagStorage,
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
let variation = client.getNumericAssignment(flagKey, subject, {}, 0.0);
Expand Down Expand Up @@ -787,7 +802,10 @@
throwOnFailedInitialization,
pollAfterFailedInitialization,
};
client = new EppoClient(thisFlagStorage, undefined, undefined, requestConfiguration);
client = new EppoClient({
flagConfigurationStore: thisFlagStorage,
configurationRequestParameters: requestConfiguration,
});
client.setIsGracefulFailureMode(false);
// no configuration loaded
expect(client.getNumericAssignment(flagKey, subject, {}, 0.0)).toBe(0.0);
Expand Down
Loading
Loading