Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remoteConfig.fetchConfig can specify analyticsUserProperties #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 6 additions & 2 deletions common/api-review/remote-config.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export function activate(remoteConfig: RemoteConfig): Promise<boolean>;
export function ensureInitialized(remoteConfig: RemoteConfig): Promise<void>;

// @public
export function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;
export function fetchAndActivate(remoteConfig: RemoteConfig, options?: {
analyticsUserProperties?: Record<string, unknown>;
}): Promise<boolean>;

// @public
export function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
export function fetchConfig(remoteConfig: RemoteConfig, options?: {
analyticsUserProperties?: Record<string, unknown>;
}): Promise<void>;

// @public
export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
Expand Down
2 changes: 1 addition & 1 deletion packages/remote-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions packages/remote-config/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ export function ensureInitialized(remoteConfig: RemoteConfig): Promise<void> {
/**
* 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<void> {
export async function fetchConfig(
remoteConfig: RemoteConfig,
options?: { analyticsUserProperties?: Record<string, unknown> }
): Promise<void> {
const rc = getModularInstance(remoteConfig) as RemoteConfigImpl;
// Aborts the request after the given timeout, causing the fetch call to
// reject with an `AbortError`.
Expand All @@ -118,7 +122,8 @@ export async function fetchConfig(remoteConfig: RemoteConfig): Promise<void> {
try {
await rc._client.fetch({
cacheMaxAgeMillis: rc.settings.minimumFetchIntervalMillis,
signal: abortSignal
signal: abortSignal,
body: { analyticsUserProperties: options?.analyticsUserProperties }
});

await rc._storageCache.setLastFetchStatus('success');
Expand Down
5 changes: 3 additions & 2 deletions packages/remote-config/src/api2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ import {
* @public
*/
export async function fetchAndActivate(
remoteConfig: RemoteConfig
remoteConfig: RemoteConfig,
options?: { analyticsUserProperties?: Record<string, unknown> }
): Promise<boolean> {
remoteConfig = getModularInstance(remoteConfig);
await fetchConfig(remoteConfig);
await fetchConfig(remoteConfig, options);
return activate(remoteConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export interface FetchRequest {
* <p>Comparable to passing `headers = { 'If-None-Match': <eTag> }` to the native Fetch API.
*/
eTag?: string;

/**
* Appends the request body with any key-value pairs you define
*/
body?: Record<string, unknown>;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/remote-config/src/client/rest_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down