Skip to content

Make remote config version available through API #9176

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

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 .changeset/selfish-jokes-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/remote-config': patch
---

Make remote config version available through API
1 change: 1 addition & 0 deletions common/api-review/remote-config.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface FetchResponse {
config?: FirebaseRemoteConfigObject;
eTag?: string;
status: number;
version?: string;
}

// @public
Expand Down
13 changes: 12 additions & 1 deletion docs-devsite/remote-config.fetchresponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Defines a successful response (200 or 304).
<b>Signature:</b>

```typescript
export interface FetchResponse
export interface FetchResponse
```

## Properties
Expand All @@ -27,6 +27,7 @@ export interface FetchResponse
| [config](./remote-config.fetchresponse.md#fetchresponseconfig) | [FirebaseRemoteConfigObject](./remote-config.firebaseremoteconfigobject.md#firebaseremoteconfigobject_interface) | Defines the map of parameters returned as "entries" in the fetch response body.<p>Only defined for 200 responses. |
| [eTag](./remote-config.fetchresponse.md#fetchresponseetag) | string | Defines the ETag response header value.<p>Only defined for 200 and 304 responses. |
| [status](./remote-config.fetchresponse.md#fetchresponsestatus) | number | The HTTP status, which is useful for differentiating success responses with data from those without.<p>The Remote Config client is modeled after the native <code>Fetch</code> interface, so HTTP status is first-class.<p>Disambiguation: the fetch response returns a legacy "state" value that is redundant with the HTTP status code. The former is normalized into the latter. |
| [version](./remote-config.fetchresponse.md#version) | string | Remote config version. |

## FetchResponse.config

Expand Down Expand Up @@ -65,3 +66,13 @@ The HTTP status, which is useful for differentiating success responses with data
```typescript
status: number;
```

## FetchResponse.version

Remote config version.

<b>Signature:</b>

```typescript
version?: string;
```
4 changes: 3 additions & 1 deletion packages/remote-config/src/client/rest_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class RestClient implements RemoteConfigFetchClient {

let config: FirebaseRemoteConfigObject | undefined;
let state: string | undefined;
let version: string | undefined;

// JSON parsing throws SyntaxError if the response body isn't a JSON string.
// Requesting application/json and checking for a 200 ensures there's JSON data.
Expand All @@ -154,6 +155,7 @@ export class RestClient implements RemoteConfigFetchClient {
}
config = responseBody['entries'];
state = responseBody['state'];
version = responseBody['templateVersion'];
}

// Normalizes based on legacy state.
Expand All @@ -176,6 +178,6 @@ export class RestClient implements RemoteConfigFetchClient {
});
}

return { status, eTag: responseEtag, config };
return { status, eTag: responseEtag, config, version } as FetchResponse;
}
}
5 changes: 5 additions & 0 deletions packages/remote-config/src/public_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export interface FetchResponse {
*/
config?: FirebaseRemoteConfigObject;

/**
* Defines remote config version.
*/
version?: string;

// Note: we're not extracting experiment metadata until
// ABT and Analytics have Web SDKs.
}
Expand Down
12 changes: 8 additions & 4 deletions packages/remote-config/test/client/rest_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ describe('RestClient', () => {
expect(response).to.deep.eq({
status: expectedResponse.status,
eTag: expectedResponse.eTag,
config: expectedResponse.entries
config: expectedResponse.entries,
version: undefined
});
});

Expand Down Expand Up @@ -184,7 +185,8 @@ describe('RestClient', () => {
expect(response).to.deep.eq({
status: 304,
eTag: 'response-etag',
config: undefined
config: undefined,
version: undefined
});
});

Expand Down Expand Up @@ -222,7 +224,8 @@ describe('RestClient', () => {
expect(response).to.deep.eq({
status: 304,
eTag: 'etag',
config: undefined
config: undefined,
version: undefined
});
});

Expand All @@ -239,7 +242,8 @@ describe('RestClient', () => {
await expect(client.fetch(DEFAULT_REQUEST)).to.eventually.be.deep.eq({
status: 200,
eTag: 'etag',
config: {}
config: {},
version: undefined
});
}
});
Expand Down