From e5937be57c480bdf88128e9fa4a59c3b4d97d197 Mon Sep 17 00:00:00 2001 From: Junjie Wang Date: Fri, 6 Dec 2024 14:17:41 -0800 Subject: [PATCH] feat(analytics-remote-config): support custom session id --- packages/analytics-remote-config/src/remote-config.ts | 10 +++++----- packages/analytics-remote-config/src/types.ts | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/analytics-remote-config/src/remote-config.ts b/packages/analytics-remote-config/src/remote-config.ts index c6ee48c07..02fc0bd9c 100644 --- a/packages/analytics-remote-config/src/remote-config.ts +++ b/packages/analytics-remote-config/src/remote-config.ts @@ -23,7 +23,7 @@ export class RemoteConfigFetch localConfig: Config; retryTimeout = 1000; attempts = 0; - lastFetchedSessionId: number | undefined; + lastFetchedSessionId: number | string | undefined; sessionTargetingMatch = false; configKeys: string[]; metrics: RemoteConfigMetric = {}; @@ -36,7 +36,7 @@ export class RemoteConfigFetch getRemoteConfig = async ( configNamespace: string, key: K, - sessionId?: number, + sessionId?: number | string, ): Promise => { const fetchStartTime = Date.now(); // Finally fetch via API @@ -64,7 +64,7 @@ export class RemoteConfigFetch return REMOTE_CONFIG_SERVER_URL; } - fetchWithTimeout = async (sessionId?: number): Promise | void> => { + fetchWithTimeout = async (sessionId?: number | string): Promise | void> => { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 5000); const remoteConfig = await this.fetchRemoteConfig(controller.signal, sessionId); @@ -74,7 +74,7 @@ export class RemoteConfigFetch fetchRemoteConfig = async ( signal: AbortController['signal'], - sessionId?: number, + sessionId?: number | string, ): Promise | void> => { if (sessionId === this.lastFetchedSessionId && this.attempts >= this.localConfig.flushMaxRetries) { return this.completeRequest({ err: MAX_RETRIES_EXCEEDED_MESSAGE }); @@ -128,7 +128,7 @@ export class RemoteConfigFetch retryFetch = async ( signal: AbortController['signal'], - sessionId?: number, + sessionId?: number | string, ): Promise | void> => { await new Promise((resolve) => setTimeout(resolve, this.attempts * this.retryTimeout)); return this.fetchRemoteConfig(signal, sessionId); diff --git a/packages/analytics-remote-config/src/types.ts b/packages/analytics-remote-config/src/types.ts index 4e7e841e0..8740765ac 100644 --- a/packages/analytics-remote-config/src/types.ts +++ b/packages/analytics-remote-config/src/types.ts @@ -10,7 +10,7 @@ export interface BaseRemoteConfigFetch { getRemoteConfig: ( configNamespace: string, key: K, - sessionId?: number, + sessionId?: number | string, ) => Promise; } @@ -31,7 +31,10 @@ export interface RemoteConfigMetric { export interface RemoteConfigIDBStore extends BaseRemoteConfigFetch { - storeRemoteConfig: (remoteConfig: RemoteConfigAPIResponse, sessionId?: number) => Promise; + storeRemoteConfig: ( + remoteConfig: RemoteConfigAPIResponse, + sessionId?: number | string, + ) => Promise; getLastFetchedSessionId: () => Promise; remoteConfigHasValues: (configNamespace: string) => Promise; }