From 2518e1a92e4b3fd68be1eb44b9534ad6dfdf5e89 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sun, 1 Mar 2026 21:17:38 -0800 Subject: [PATCH] fix(ts-clients): add x-request-id header to feature-flag-client and kill-switch-client --- packages/feature-flag-client/src/client.ts | 7 ++++++- packages/kill-switch-client/src/index.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/feature-flag-client/src/client.ts b/packages/feature-flag-client/src/client.ts index 7de5b93c..360021d1 100644 --- a/packages/feature-flag-client/src/client.ts +++ b/packages/feature-flag-client/src/client.ts @@ -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; diff --git a/packages/kill-switch-client/src/index.ts b/packages/kill-switch-client/src/index.ts index c8ebd2f3..e41339d5 100644 --- a/packages/kill-switch-client/src/index.ts +++ b/packages/kill-switch-client/src/index.ts @@ -44,10 +44,15 @@ export function createKillSwitchClient(config: KillSwitchClientConfig): KillSwit async function check(): Promise { 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 }, } );