|
| 1 | +import ApiEndpoints from './api-endpoints'; |
1 | 2 | import { TLRUCache } from './cache/tlru-cache';
|
2 | 3 | import { Variation } from './interfaces';
|
3 | 4 | import { FlagKey } from './types';
|
4 | 5 |
|
5 | 6 | const FIVE_MINUTES_IN_MS = 5 * 3600 * 1000;
|
6 |
| -const KEY_VALIDATION_URL = 'https://eppo.cloud/api/flag-overrides/v1/validate-key'; |
7 | 7 |
|
8 | 8 | export interface OverridePayload {
|
9 | 9 | browserExtensionKey: string;
|
10 | 10 | overrides: Record<FlagKey, Variation>;
|
11 | 11 | }
|
12 | 12 |
|
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, { |
15 | 18 | method: 'POST',
|
16 | 19 | body: JSON.stringify({
|
17 | 20 | key: browserExtensionKey,
|
@@ -63,11 +66,12 @@ export class OverrideValidator {
|
63 | 66 | }
|
64 | 67 | }
|
65 | 68 |
|
66 |
| - async validateKey(browserExtensionKey: string) { |
| 69 | + async validateKey(browserExtensionKey: string, baseUrl: string | undefined) { |
67 | 70 | if (this.validKeyCache.get(browserExtensionKey) === 'true') {
|
68 | 71 | return true;
|
69 | 72 | }
|
70 |
| - await sendValidationRequest(browserExtensionKey); |
| 73 | + const endpoint = new ApiEndpoints({ baseUrl }).flagOverridesKeyValidationEndpoint().toString(); |
| 74 | + await sendValidationRequest(browserExtensionKey, endpoint); |
71 | 75 | this.validKeyCache.set(browserExtensionKey, 'true');
|
72 | 76 | }
|
73 | 77 | }
|
0 commit comments