From 2f77e366621953d69f10853a7909f352fae16956 Mon Sep 17 00:00:00 2001 From: Derrick Beining Date: Wed, 11 Dec 2024 16:05:20 -0500 Subject: [PATCH] feat: remoteConfig.fetchConfig can specify analyticsUserProperties Fixes https://github.com/firebase/firebase-js-sdk/issues/8662 --- .yarnrc | 5 +++++ common/api-review/remote-config.api.md | 8 ++++++-- packages/remote-config/package.json | 2 +- packages/remote-config/src/api.ts | 9 +++++++-- packages/remote-config/src/api2.ts | 5 +++-- .../src/client/remote_config_fetch_client.ts | 5 +++++ packages/remote-config/src/client/rest_client.ts | 3 ++- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.yarnrc b/.yarnrc index f4481b2cd8c..bcb05d40a74 100644 --- a/.yarnrc +++ b/.yarnrc @@ -1,2 +1,7 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + registry "https://registry.npmjs.org/" save-prefix "" +yarn-path ".yarn/releases/yarn-1.22.11.cjs" diff --git a/common/api-review/remote-config.api.md b/common/api-review/remote-config.api.md index 980d8f3d287..58dda63bcf6 100644 --- a/common/api-review/remote-config.api.md +++ b/common/api-review/remote-config.api.md @@ -13,10 +13,14 @@ export function activate(remoteConfig: RemoteConfig): Promise; export function ensureInitialized(remoteConfig: RemoteConfig): Promise; // @public -export function fetchAndActivate(remoteConfig: RemoteConfig): Promise; +export function fetchAndActivate(remoteConfig: RemoteConfig, options?: { + analyticsUserProperties?: Record; +}): Promise; // @public -export function fetchConfig(remoteConfig: RemoteConfig): Promise; +export function fetchConfig(remoteConfig: RemoteConfig, options?: { + analyticsUserProperties?: Record; +}): Promise; // @public export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle'; diff --git a/packages/remote-config/package.json b/packages/remote-config/package.json index 75d856c7e11..cda28882ab7 100644 --- a/packages/remote-config/package.json +++ b/packages/remote-config/package.json @@ -61,7 +61,7 @@ "bugs": { "url": "https://github.com/firebase/firebase-js-sdk/issues" }, - "typings": "dist/src/index.d.ts", + "typings": "./dist/remote-config-public.d.ts", "nyc": { "extension": [ ".ts" diff --git a/packages/remote-config/src/api.ts b/packages/remote-config/src/api.ts index aeae67d450e..a5357aed13c 100644 --- a/packages/remote-config/src/api.ts +++ b/packages/remote-config/src/api.ts @@ -93,9 +93,13 @@ export function ensureInitialized(remoteConfig: RemoteConfig): Promise { /** * Fetches and caches configuration from the Remote Config service. * @param remoteConfig - The {@link RemoteConfig} instance. + * @param options - Additional configuration for the request * @public */ -export async function fetchConfig(remoteConfig: RemoteConfig): Promise { +export async function fetchConfig( + remoteConfig: RemoteConfig, + options?: { analyticsUserProperties?: Record } +): Promise { const rc = getModularInstance(remoteConfig) as RemoteConfigImpl; // Aborts the request after the given timeout, causing the fetch call to // reject with an `AbortError`. @@ -118,7 +122,8 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise { try { await rc._client.fetch({ cacheMaxAgeMillis: rc.settings.minimumFetchIntervalMillis, - signal: abortSignal + signal: abortSignal, + body: { analyticsUserProperties: options?.analyticsUserProperties } }); await rc._storageCache.setLastFetchStatus('success'); diff --git a/packages/remote-config/src/api2.ts b/packages/remote-config/src/api2.ts index 6bd67ffabb8..069da19fefa 100644 --- a/packages/remote-config/src/api2.ts +++ b/packages/remote-config/src/api2.ts @@ -37,10 +37,11 @@ import { * @public */ export async function fetchAndActivate( - remoteConfig: RemoteConfig + remoteConfig: RemoteConfig, + options?: { analyticsUserProperties?: Record } ): Promise { remoteConfig = getModularInstance(remoteConfig); - await fetchConfig(remoteConfig); + await fetchConfig(remoteConfig, options); return activate(remoteConfig); } diff --git a/packages/remote-config/src/client/remote_config_fetch_client.ts b/packages/remote-config/src/client/remote_config_fetch_client.ts index 25e00299855..0b02255026a 100644 --- a/packages/remote-config/src/client/remote_config_fetch_client.ts +++ b/packages/remote-config/src/client/remote_config_fetch_client.ts @@ -99,6 +99,11 @@ export interface FetchRequest { *

Comparable to passing `headers = { 'If-None-Match': }` to the native Fetch API. */ eTag?: string; + + /** + * Appends the request body with any key-value pairs you define + */ + body?: Record; } /** diff --git a/packages/remote-config/src/client/rest_client.ts b/packages/remote-config/src/client/rest_client.ts index 87fdae3c3d6..90a43e24e15 100644 --- a/packages/remote-config/src/client/rest_client.ts +++ b/packages/remote-config/src/client/rest_client.ts @@ -92,8 +92,9 @@ export class RestClient implements RemoteConfigFetchClient { app_instance_id: installationId, app_instance_id_token: installationToken, app_id: this.appId, - language_code: getUserLanguage() + language_code: getUserLanguage(), /* eslint-enable camelcase */ + ...(request.body || {}) }; const options = {