fix(ts-clients): add x-request-id header to feature-flag-client and kill-switch-client

This commit is contained in:
saravanakumardb1 2026-03-01 21:17:38 -08:00
parent f953c2b0bc
commit 2518e1a92e
2 changed files with 12 additions and 2 deletions

View File

@ -54,8 +54,13 @@ export function createFeatureFlagClient(config: FeatureFlagClientConfig): Featur
const parts = [`platform=${encodeURIComponent(platform)}`];
if (userId) parts.push(`userId=${encodeURIComponent(userId)}`);
const requestId =
typeof globalThis.crypto?.randomUUID === 'function'
? globalThis.crypto.randomUUID()
: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
const res = await globalThis.fetch(`${baseUrl}/flags/poll?${parts.join('&')}`, {
headers: { 'x-product-id': productId },
headers: { 'x-product-id': productId, 'x-request-id': requestId },
});
if (!res.ok) return;

View File

@ -44,10 +44,15 @@ export function createKillSwitchClient(config: KillSwitchClientConfig): KillSwit
async function check(): Promise<KillSwitchResult> {
try {
const requestId =
typeof globalThis.crypto?.randomUUID === 'function'
? globalThis.crypto.randomUUID()
: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
const res = await globalThis.fetch(
`${baseUrl}/flags/kill-switch?platform=${encodeURIComponent(platform)}`,
{
headers: { 'x-product-id': productId },
headers: { 'x-product-id': productId, 'x-request-id': requestId },
}
);