Skip to content

Commit d3f5d9e

Browse files
authored
chore: allow for local testing for flag overrides (#228)
1 parent a92ad46 commit d3f5d9e

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.11.0",
3+
"version": "4.12.0",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/api-endpoints.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
UFC_ENDPOINT,
44
BANDIT_ENDPOINT,
55
PRECOMPUTED_FLAGS_ENDPOINT,
6+
FLAG_OVERRIDES_KEY_VALIDATION_URL,
67
} from './constants';
78
import { IQueryParams, IQueryParamsWithSubject } from './http-client';
89

@@ -36,4 +37,8 @@ export default class ApiEndpoints {
3637
precomputedFlagsEndpoint(): URL {
3738
return this.endpoint(PRECOMPUTED_FLAGS_ENDPOINT);
3839
}
40+
41+
flagOverridesKeyValidationEndpoint(): URL {
42+
return this.endpoint(FLAG_OVERRIDES_KEY_VALIDATION_URL);
43+
}
3944
}

src/client/eppo-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ export default class EppoClient {
213213
return undefined;
214214
}
215215
const payload: OverridePayload = this.overrideValidator.parseOverridePayload(overridePayload);
216-
await this.overrideValidator.validateKey(payload.browserExtensionKey);
216+
const baseUrl = this.configurationRequestParameters?.baseUrl;
217+
await this.overrideValidator.validateKey(payload.browserExtensionKey, baseUrl);
217218
return payload.overrides;
218219
}
219220

@@ -222,7 +223,7 @@ export default class EppoClient {
222223
* to it without affecting the original EppoClient singleton. Useful for
223224
* applying overrides in a shared Node instance, such as a web server.
224225
*/
225-
withOverrides(overrides: Record<FlagKey, Variation>): EppoClient {
226+
withOverrides(overrides: Record<FlagKey, Variation> | undefined): EppoClient {
226227
if (overrides && Object.keys(overrides).length) {
227228
const copy = shallowClone(this);
228229
copy.overrideStore = new MemoryOnlyConfigurationStore<Variation>();

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const DEFAULT_POLL_CONFIG_REQUEST_RETRIES = 7;
99
export const BASE_URL = 'https://fscdn.eppo.cloud/api';
1010
export const UFC_ENDPOINT = '/flag-config/v1/config';
1111
export const BANDIT_ENDPOINT = '/flag-config/v1/bandits';
12+
export const FLAG_OVERRIDES_KEY_VALIDATION_URL = '/flag-overrides/v1/validate-key';
1213
export const PRECOMPUTED_BASE_URL = 'https://fs-edge-assignment.eppo.cloud';
1314
export const PRECOMPUTED_FLAGS_ENDPOINT = '/assignments';
1415
export const SESSION_ASSIGNMENT_CONFIG_LOADED = 'eppo-session-assignment-config-loaded';

src/override-validator.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import ApiEndpoints from './api-endpoints';
12
import { TLRUCache } from './cache/tlru-cache';
23
import { Variation } from './interfaces';
34
import { FlagKey } from './types';
45

56
const FIVE_MINUTES_IN_MS = 5 * 3600 * 1000;
6-
const KEY_VALIDATION_URL = 'https://eppo.cloud/api/flag-overrides/v1/validate-key';
77

88
export interface OverridePayload {
99
browserExtensionKey: string;
1010
overrides: Record<FlagKey, Variation>;
1111
}
1212

13-
export const sendValidationRequest = async (browserExtensionKey: string) => {
14-
const response = await fetch(KEY_VALIDATION_URL, {
13+
export const sendValidationRequest = async (
14+
browserExtensionKey: string,
15+
validationEndpoint: string,
16+
) => {
17+
const response = await fetch(validationEndpoint, {
1518
method: 'POST',
1619
body: JSON.stringify({
1720
key: browserExtensionKey,
@@ -63,11 +66,12 @@ export class OverrideValidator {
6366
}
6467
}
6568

66-
async validateKey(browserExtensionKey: string) {
69+
async validateKey(browserExtensionKey: string, baseUrl: string | undefined) {
6770
if (this.validKeyCache.get(browserExtensionKey) === 'true') {
6871
return true;
6972
}
70-
await sendValidationRequest(browserExtensionKey);
73+
const endpoint = new ApiEndpoints({ baseUrl }).flagOverridesKeyValidationEndpoint().toString();
74+
await sendValidationRequest(browserExtensionKey, endpoint);
7175
this.validKeyCache.set(browserExtensionKey, 'true');
7276
}
7377
}

0 commit comments

Comments
 (0)