Skip to content

Commit badd643

Browse files
committed
refactor: fix lints
1 parent 6bea66d commit badd643

15 files changed

+59
-78
lines changed

src/client/eppo-client-with-bandits.spec.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import {
99
BANDIT_TEST_DATA_DIR,
1010
readMockBanditsConfiguration,
1111
} from '../../test/testHelpers';
12-
import ApiEndpoints from '../api-endpoints';
1312
import { IAssignmentEvent, IAssignmentLogger } from '../assignment-logger';
1413
import { BanditEvaluation, BanditEvaluator } from '../bandit-evaluator';
1514
import { IBanditEvent, IBanditLogger } from '../bandit-logger';
16-
import { Evaluator, FlagEvaluation } from '../evaluator';
15+
import { Evaluator } from '../evaluator';
1716
import {
1817
AllocationEvaluationCode,
1918
IFlagEvaluationDetails,
@@ -22,7 +21,6 @@ import { attributeEncodeBase64 } from '../obfuscation';
2221
import { Attributes, BanditActions, ContextAttributes } from '../types';
2322

2423
import EppoClient, { IAssignmentDetails } from './eppo-client';
25-
import { Configuration } from '../configuration';
2624

2725
const salt = base64.fromUint8Array(new Uint8Array([101, 112, 112, 111]));
2826
jest.mock('../salt', () => ({
@@ -675,15 +673,6 @@ describe('EppoClient Bandits E2E test', () => {
675673
},
676674
};
677675

678-
function getPrecomputedResults(
679-
client: EppoClient,
680-
subjectKey: string,
681-
subjectAttributes: ContextAttributes,
682-
banditActions: Record<string, BanditActions>,
683-
): Configuration {
684-
return client.getPrecomputedConfiguration(subjectKey, subjectAttributes, banditActions);
685-
}
686-
687676
describe('obfuscated results', () => {
688677
it('obfuscates precomputed bandits', () => {
689678
const bannerBanditFlagMd5 = '3ac89e06235484aa6f2aec8c33109a02';

src/client/eppo-client.precomputed.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
MOCK_PRECOMPUTED_WIRE_FILE,
3-
MOCK_DEOBFUSCATED_PRECOMPUTED_RESPONSE_FILE,
43
readMockConfigurationWireResponse,
54
} from '../../test/testHelpers';
65
import { IAssignmentLogger } from '../assignment-logger';

src/client/eppo-client.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import * as td from 'testdouble';
55
import { MOCK_UFC_RESPONSE_FILE, readMockUFCResponse } from '../../test/testHelpers';
66
import { IAssignmentLogger } from '../assignment-logger';
77
import { AssignmentCache } from '../cache/abstract-assignment-cache';
8+
import { Configuration } from '../configuration';
89
import {
910
MAX_EVENT_QUEUE_SIZE,
1011
DEFAULT_BASE_POLLING_INTERVAL_MS,
1112
POLL_JITTER_PCT,
1213
} from '../constants';
1314
import { decodePrecomputedFlag } from '../decoding';
1415
import { Flag, ObfuscatedFlag, VariationType, FormatEnum, Variation } from '../interfaces';
16+
import { KVStore, MemoryStore } from '../kvstore';
1517
import { getMD5Hash } from '../obfuscation';
1618

1719
import EppoClient, { checkTypeMatch } from './eppo-client';
18-
import { Configuration } from '../configuration';
19-
import { KVStore, MemoryStore } from '../kvstore';
2020

2121
// Use a known salt to produce deterministic hashes
2222
const salt = base64.fromUint8Array(new Uint8Array([7, 53, 17, 78]));

src/client/eppo-client.ts

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import {
1010
} from '../attributes';
1111
import { BanditEvaluation, BanditEvaluator } from '../bandit-evaluator';
1212
import { IBanditEvent, IBanditLogger } from '../bandit-logger';
13+
import { BroadcastChannel } from '../broadcast';
1314
import { AssignmentCache } from '../cache/abstract-assignment-cache';
1415
import { LRUInMemoryAssignmentCache } from '../cache/lru-in-memory-assignment-cache';
1516
import { NonExpiringInMemoryAssignmentCache } from '../cache/non-expiring-in-memory-cache-assignment';
1617
import { TLRUInMemoryAssignmentCache } from '../cache/tlru-in-memory-assignment-cache';
1718
import { Configuration, PrecomputedConfig } from '../configuration';
19+
import { ConfigurationSource } from '../configuration-feed';
20+
import { randomJitterMs, ConfigurationPoller } from '../configuration-poller';
1821
import ConfigurationRequestor from '../configuration-requestor';
1922
import { ConfigurationStore } from '../configuration-store';
20-
import { IObfuscatedPrecomputedConfigurationResponse } from '../precomputed-configuration';
2123
import {
2224
DEFAULT_BASE_POLLING_INTERVAL_MS,
2325
DEFAULT_MAX_POLLING_INTERVAL_MS,
@@ -30,6 +32,7 @@ import {
3032
DEFAULT_ENABLE_POLLING,
3133
DEFAULT_ENABLE_BANDITS,
3234
} from '../constants';
35+
import { decodePrecomputedBandit, decodePrecomputedFlag } from '../decoding';
3336
import { EppoValue } from '../eppo_value';
3437
import {
3538
AssignmentResult,
@@ -56,8 +59,19 @@ import {
5659
Variation,
5760
VariationType,
5861
} from '../interfaces';
62+
import { KVStore, MemoryStore } from '../kvstore';
63+
import {
64+
getMD5Hash,
65+
obfuscatePrecomputedBanditMap,
66+
obfuscatePrecomputedFlags,
67+
} from '../obfuscation';
5968
import { OverridePayload, OverrideValidator } from '../override-validator';
60-
import { randomJitterMs } from '../configuration-poller';
69+
import {
70+
PersistentConfigurationCache,
71+
PersistentConfigurationStorage,
72+
} from '../persistent-configuration-cache';
73+
import { IObfuscatedPrecomputedConfigurationResponse } from '../precomputed-configuration';
74+
import { generateSalt } from '../salt';
6175
import SdkTokenDecoder from '../sdk-token-decoder';
6276
import {
6377
Attributes,
@@ -71,22 +85,8 @@ import {
7185
import { shallowClone } from '../util';
7286
import { validateNotBlank } from '../validation';
7387
import { LIB_VERSION } from '../version';
74-
import {
75-
PersistentConfigurationCache,
76-
PersistentConfigurationStorage,
77-
} from '../persistent-configuration-cache';
78-
import { ConfigurationPoller } from '../configuration-poller';
79-
import { ConfigurationSource } from '../configuration-feed';
80-
import { BroadcastChannel } from '../broadcast';
81-
import {
82-
getMD5Hash,
83-
obfuscatePrecomputedBanditMap,
84-
obfuscatePrecomputedFlags,
85-
} from '../obfuscation';
86-
import { decodePrecomputedBandit, decodePrecomputedFlag } from '../decoding';
88+
8789
import { Subject } from './subject';
88-
import { generateSalt } from '../salt';
89-
import { KVStore, MemoryStore } from '../kvstore';
9090

9191
export interface IAssignmentDetails<T extends Variation['value'] | object> {
9292
variation: T;
@@ -264,16 +264,6 @@ export type EppoClientParameters = {
264264
};
265265
};
266266

267-
type VariationTypeMap = {
268-
[VariationType.STRING]: string;
269-
[VariationType.INTEGER]: number;
270-
[VariationType.NUMERIC]: number;
271-
[VariationType.BOOLEAN]: boolean;
272-
[VariationType.JSON]: object;
273-
};
274-
275-
type TypeFromVariationType<T extends VariationType> = VariationTypeMap[T];
276-
277267
/**
278268
* ## Initialization
279269
*
@@ -1018,8 +1008,6 @@ export default class EppoClient {
10181008
const precomputed = config.getPrecomputedConfiguration();
10191009
if (precomputed && precomputed.subjectKey === subjectKey) {
10201010
// Use precomputed results if available
1021-
const nonContextualSubjectAttributes =
1022-
ensureNonContextualSubjectAttributes(subjectAttributes);
10231011
const { flagEvaluation, banditAction, assignmentEvent, banditEvent } =
10241012
this.evaluatePrecomputedAssignment(precomputed, flagKey, VariationType.STRING);
10251013

@@ -1940,9 +1928,9 @@ class TimeoutError extends Error {
19401928
function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
19411929
let timer: NodeJS.Timeout;
19421930

1943-
const timeoutPromise = new Promise<never>((_, reject) => {
1931+
const timeoutPromise = new Promise<never>((_resolve, reject) => {
19441932
timer = setTimeout(() => reject(new TimeoutError()), ms);
19451933
});
19461934

1947-
return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timer!));
1935+
return Promise.race([promise, timeoutPromise]).finally(() => clearTimeout(timer));
19481936
}

src/client/subject.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import EppoClient, { IAssignmentDetails, IContainerExperiment } from './eppo-client';
2-
import { Attributes, BanditActions, ContextAttributes, FlagKey } from '../types';
31
import { ensureNonContextualSubjectAttributes } from '../attributes';
42
import { Configuration } from '../configuration';
3+
import { Attributes, BanditActions, ContextAttributes, FlagKey } from '../types';
4+
5+
import EppoClient, { IAssignmentDetails, IContainerExperiment } from './eppo-client';
56

67
/**
78
* A wrapper around EppoClient that automatically supplies subject key, attributes, and bandit

src/configuration-feed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Configuration } from './configuration';
21
import { BroadcastChannel } from './broadcast';
2+
import { Configuration } from './configuration';
33

44
/**
55
* Enumeration of possible configuration sources.

src/configuration-poller.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import ConfigurationRequestor from './configuration-requestor';
21
import { logger } from './application-logger';
3-
import { POLL_JITTER_PCT } from './constants';
42
import { ConfigurationFeed, ConfigurationSource } from './configuration-feed';
3+
import ConfigurationRequestor from './configuration-requestor';
4+
import { POLL_JITTER_PCT } from './constants';
55

66
/**
77
* Polls for new configurations from the Eppo server. When a new configuration is fetched,
@@ -64,11 +64,15 @@ export class ConfigurationPoller {
6464
if (!this.isRunning) {
6565
logger.debug('[Eppo SDK] starting configuration poller');
6666
this.isRunning = true;
67-
this.poll().finally(() => {
68-
// Just to be safe, reset isRunning if the poll() method throws an error or exits
69-
// unexpectedly (it shouldn't).
70-
this.isRunning = false;
71-
});
67+
this.poll()
68+
.finally(() => {
69+
// Just to be safe, reset isRunning if the poll() method throws an error or exits
70+
// unexpectedly (it shouldn't).
71+
this.isRunning = false;
72+
})
73+
.catch((err) => {
74+
logger.warn({ err }, '[Eppo SDK] unexpected error in poller');
75+
});
7276
}
7377
}
7478

src/configuration-requestor.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,18 @@ describe('ConfigurationRequestor', () => {
525525

526526
describe('fetchConfiguration', () => {
527527
it('should not fetch bandit parameters if model versions are already loaded', async () => {
528-
const ufcResponse = {
529-
flags: { test_flag: { key: 'test_flag', value: true } },
530-
banditReferences: {
531-
bandit: {
532-
modelVersion: 'v1',
533-
flagVariations: [{ flagKey: 'test_flag', variationId: '1' }],
534-
},
535-
},
536-
environment: 'test',
537-
createdAt: '2024-01-01',
538-
format: 'SERVER',
539-
};
528+
// const ufcResponse = {
529+
// flags: { test_flag: { key: 'test_flag', value: true } },
530+
// banditReferences: {
531+
// bandit: {
532+
// modelVersion: 'v1',
533+
// flagVariations: [{ flagKey: 'test_flag', variationId: '1' }],
534+
// },
535+
// },
536+
// environment: 'test',
537+
// createdAt: '2024-01-01',
538+
// format: 'SERVER',
539+
// };
540540

541541
await configurationRequestor.fetchConfiguration();
542542
// const initialFetchCount = fetchSpy.mock.calls.length;

src/configuration-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { logger } from './application-logger';
2+
import { BroadcastChannel } from './broadcast';
23
import { Configuration } from './configuration';
34
import { ConfigurationFeed } from './configuration-feed';
4-
import { BroadcastChannel } from './broadcast';
55

66
export type ActivationStrategy =
77
| {

src/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { IObfuscatedPrecomputedConfigurationResponse } from './precomputed-configuration';
21
import { decodeFlag } from './decoding';
32
import { IBanditParametersResponse, IUniversalFlagConfigResponse } from './http-client';
43
import { BanditParameters, BanditVariation, Flag, FormatEnum, ObfuscatedFlag } from './interfaces';
54
import { getMD5Hash } from './obfuscation';
5+
import { IObfuscatedPrecomputedConfigurationResponse } from './precomputed-configuration';
66
import { ContextAttributes, FlagKey, HashedFlagKey } from './types';
77

88
/** @internal for SDK use only */

0 commit comments

Comments
 (0)