Skip to content

Commit

Permalink
Merge branch 'main' into lr/bandits
Browse files Browse the repository at this point in the history
  • Loading branch information
leoromanovsky committed Jan 17, 2025
2 parents cc27204 + 34a1d8b commit b2d4405
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.2.1",
"husky": "^8.0.1",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^12.3.5",
Expand Down
14 changes: 14 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
EppoPrecomputedJSClient,
getConfigUrl,
getInstance,
getPrecomputedInstance,
IAssignmentLogger,
init,
offlineInit,
Expand Down Expand Up @@ -1278,6 +1279,19 @@ describe('offlinePrecomputedInit', () => {
});
});

describe('getPrecomputedInstance', () => {
it('returns an instance that safely returns defaults without logging', () => {
const mockLogger = td.object<IAssignmentLogger>();
const instance = getPrecomputedInstance();
instance.setAssignmentLogger(mockLogger);

const result = instance.getStringAssignment('any-flag', 'default-value');

expect(result).toBe('default-value');
td.verify(mockLogger.logAssignment(td.matchers.anything()), { times: 0 });
});
});

it('initializes without an assignment logger', () => {
const client = offlinePrecomputedInit({ precomputedConfiguration });

Expand Down
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,13 @@ export function getConfigUrl(apiKey: string, baseUrl?: string): URL {
* @public
*/
export class EppoPrecomputedJSClient extends EppoPrecomputedClient {
public static instance: EppoPrecomputedJSClient;
public static instance = new EppoPrecomputedJSClient({
precomputedFlagStore: memoryOnlyPrecomputedFlagsStore,
subject: {
subjectKey: '',
subjectAttributes: {},
},
});
public static initialized = false;

public getStringAssignment(flagKey: string, defaultValue: string): string {
Expand Down Expand Up @@ -609,7 +615,7 @@ export class EppoPrecomputedJSClient extends EppoPrecomputedClient {
export async function precomputedInit(
config: IPrecomputedClientConfig,
): Promise<EppoPrecomputedClient> {
if (EppoPrecomputedJSClient.instance) {
if (EppoPrecomputedJSClient.initialized) {
return EppoPrecomputedJSClient.instance;
}

Expand Down Expand Up @@ -764,7 +770,7 @@ export function offlinePrecomputedInit(
}

function shutdownEppoPrecomputedClient() {
if (EppoPrecomputedJSClient.instance && EppoPrecomputedJSClient.initialized) {
if (EppoPrecomputedJSClient.initialized) {
EppoPrecomputedJSClient.instance.stopPolling();
EppoPrecomputedJSClient.initialized = false;
applicationLogger.warn('[Eppo SDK] Precomputed client is being re-initialized.');
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2695,10 +2695,10 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

husky@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.1.tgz#511cb3e57de3e3190514ae49ed50f6bc3f50b3e9"
integrity sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw==
husky@^9.1.7:
version "9.1.7"
resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.7.tgz#d46a38035d101b46a70456a850ff4201344c0b2d"
integrity sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==

iconv-lite@0.6.3:
version "0.6.3"
Expand Down

0 comments on commit b2d4405

Please sign in to comment.