Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions src/api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
UFC_ENDPOINT,
BANDIT_ENDPOINT,
PRECOMPUTED_FLAGS_ENDPOINT,
FLAG_OVERRIDES_KEY_VALIDATION_URL,
} from './constants';
import { IQueryParams, IQueryParamsWithSubject } from './http-client';

Expand Down Expand Up @@ -37,8 +36,4 @@ export default class ApiEndpoints {
precomputedFlagsEndpoint(): URL {
return this.endpoint(PRECOMPUTED_FLAGS_ENDPOINT);
}

flagOverridesKeyValidationEndpoint(): URL {
return this.endpoint(FLAG_OVERRIDES_KEY_VALIDATION_URL);
}
}
3 changes: 1 addition & 2 deletions src/client/eppo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ export default class EppoClient {
return undefined;
}
const payload: OverridePayload = this.overrideValidator.parseOverridePayload(overridePayload);
const baseUrl = this.configurationRequestParameters?.baseUrl;
await this.overrideValidator.validateKey(payload.browserExtensionKey, baseUrl);
await this.overrideValidator.validateKey(payload.browserExtensionKey);
return payload.overrides;
}

Expand Down
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const DEFAULT_POLL_CONFIG_REQUEST_RETRIES = 7;
export const BASE_URL = 'https://fscdn.eppo.cloud/api';
export const UFC_ENDPOINT = '/flag-config/v1/config';
export const BANDIT_ENDPOINT = '/flag-config/v1/bandits';
export const FLAG_OVERRIDES_KEY_VALIDATION_URL = '/flag-overrides/v1/validate-key';
export const PRECOMPUTED_BASE_URL = 'https://fs-edge-assignment.eppo.cloud';
export const PRECOMPUTED_FLAGS_ENDPOINT = '/assignments';
export const SESSION_ASSIGNMENT_CONFIG_LOADED = 'eppo-session-assignment-config-loaded';
Expand Down
14 changes: 5 additions & 9 deletions src/override-validator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import ApiEndpoints from './api-endpoints';
import { TLRUCache } from './cache/tlru-cache';
import { Variation } from './interfaces';
import { FlagKey } from './types';

const FIVE_MINUTES_IN_MS = 5 * 3600 * 1000;
const KEY_VALIDATION_URL = 'https://eppo.cloud/api/flag-overrides/v1/validate-key';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FLAG_OVERRIDES_KEY_VALIDATION_URL is still in src/constants.ts and now unused anywhere in the code.

Would suggest either deleting it in src/constants.ts, or replacing it with this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch -- will do!


export interface OverridePayload {
browserExtensionKey: string;
overrides: Record<FlagKey, Variation>;
}

export const sendValidationRequest = async (
browserExtensionKey: string,
validationEndpoint: string,
) => {
const response = await fetch(validationEndpoint, {
export const sendValidationRequest = async (browserExtensionKey: string) => {
const response = await fetch(KEY_VALIDATION_URL, {
method: 'POST',
body: JSON.stringify({
key: browserExtensionKey,
Expand Down Expand Up @@ -66,12 +63,11 @@ export class OverrideValidator {
}
}

async validateKey(browserExtensionKey: string, baseUrl: string | undefined) {
async validateKey(browserExtensionKey: string) {
if (this.validKeyCache.get(browserExtensionKey) === 'true') {
return true;
}
const endpoint = new ApiEndpoints({ baseUrl }).flagOverridesKeyValidationEndpoint().toString();
await sendValidationRequest(browserExtensionKey, endpoint);
await sendValidationRequest(browserExtensionKey);
this.validKeyCache.set(browserExtensionKey, 'true');
}
}
Loading