Skip to content

Commit cb894cc

Browse files
feat: Remote Config Management API (#845)
Added support for the Remote Config API. This API enables Firebase developers to programmatically manage the set of JSON-formatted parameters and conditions known as the Remote Config template.
1 parent aef1ade commit cb894cc

14 files changed

+2292
-1
lines changed

docgen/content-sources/node/toc.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,23 @@ toc:
255255
section:
256256
- title: "Storage"
257257
path: /docs/reference/admin/node/admin.storage.Storage
258+
259+
- title: "admin.remoteConfig"
260+
path: /docs/reference/admin/node/admin.remoteConfig
261+
section:
262+
- title: "RemoteConfig"
263+
path: /docs/reference/admin/node/admin.remoteConfig.RemoteConfig
264+
- title: "RemoteConfigTemplate"
265+
path: /docs/reference/admin/node/admin.remoteConfig.RemoteConfigTemplate
266+
- title: "RemoteConfigParameter"
267+
path: /docs/reference/admin/node/admin.remoteConfig.RemoteConfigParameter
268+
- title: "RemoteConfigParameterGroup"
269+
path: /docs/reference/admin/node/admin.remoteConfig.RemoteConfigParameterGroup
270+
- title: "RemoteConfigCondition"
271+
path: /docs/reference/admin/node/admin.remoteConfig.RemoteConfigCondition
272+
- title: "ExplicitParameterValue"
273+
path: /docs/reference/admin/node/admin.remoteConfig.ExplicitParameterValue
274+
- title: "InAppDefaultValue"
275+
path: /docs/reference/admin/node/admin.remoteConfig.InAppDefaultValue
276+
- title: "RemoteConfigParameterValue"
277+
path: /docs/reference/admin/node/admin.remoteConfig.RemoteConfigParameterValue

src/firebase-app.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {InstanceId} from './instance-id/instance-id';
3333

3434
import {ProjectManagement} from './project-management/project-management';
3535
import {SecurityRules} from './security-rules/security-rules';
36+
import { RemoteConfig } from './remote-config/remote-config';
3637

3738
import {Agent} from 'http';
3839

@@ -395,6 +396,18 @@ export class FirebaseApp {
395396
});
396397
}
397398

399+
/**
400+
* Returns the RemoteConfig service instance associated with this app.
401+
*
402+
* @return {RemoteConfig} The RemoteConfig service instance of this app.
403+
*/
404+
public remoteConfig(): RemoteConfig {
405+
return this.ensureService_('remoteConfig', () => {
406+
const remoteConfigService: typeof RemoteConfig = require('./remote-config/remote-config').RemoteConfig;
407+
return new remoteConfigService(this);
408+
});
409+
}
410+
398411
/**
399412
* Returns the name of the FirebaseApp instance.
400413
*

src/firebase-namespace.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {Firestore} from '@google-cloud/firestore';
3636
import {InstanceId} from './instance-id/instance-id';
3737
import {ProjectManagement} from './project-management/project-management';
3838
import { SecurityRules } from './security-rules/security-rules';
39+
import { RemoteConfig } from './remote-config/remote-config';
3940

4041
import * as validator from './utils/validator';
4142

@@ -451,6 +452,18 @@ export class FirebaseNamespace {
451452
return Object.assign(fn, {SecurityRules: securityRules});
452453
}
453454

455+
/**
456+
* Gets the `RemoteConfig` service namespace. The returned namespace can be used to get the
457+
* `RemoteConfig` service for the default app or an explicitly specified app.
458+
*/
459+
get remoteConfig(): FirebaseServiceNamespace<RemoteConfig> {
460+
const fn: FirebaseServiceNamespace<RemoteConfig> = (app?: FirebaseApp) => {
461+
return this.ensureApp(app).remoteConfig();
462+
};
463+
const remoteConfig = require('./remote-config/remote-config').RemoteConfig;
464+
return Object.assign(fn, { RemoteConfig: remoteConfig });
465+
}
466+
454467
/**
455468
* Initializes the FirebaseApp instance.
456469
*

src/index.d.ts

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,37 @@ declare namespace admin {
374374
*/
375375
function projectManagement(app?: admin.app.App): admin.projectManagement.ProjectManagement;
376376

377+
/**
378+
* Gets the {@link admin.remoteConfig.RemoteConfig `RemoteConfig`} service for the
379+
* default app or a given app.
380+
*
381+
* `admin.remoteConfig()` can be called with no arguments to access the default
382+
* app's {@link admin.remoteConfig.RemoteConfig `RemoteConfig`} service or as
383+
* `admin.remoteConfig(app)` to access the
384+
* {@link admin.remoteConfig.RemoteConfig `RemoteConfig`} service associated with a
385+
* specific app.
386+
*
387+
* @example
388+
* ```javascript
389+
* // Get the `RemoteConfig` service for the default app
390+
* var defaultRemoteConfig = admin.remoteConfig();
391+
* ```
392+
*
393+
* @example
394+
* ```javascript
395+
* // Get the `RemoteConfig` service for a given app
396+
* var otherRemoteConfig = admin.remoteConfig(otherApp);
397+
* ```
398+
*
399+
* @param app Optional app for which to return the `RemoteConfig` service.
400+
* If not provided, the default `RemoteConfig` service is returned.
401+
*
402+
* @return The default `RemoteConfig` service if no
403+
* app is provided, or the `RemoteConfig` service associated with the provided
404+
* app.
405+
*/
406+
function remoteConfig(app?: admin.app.App): admin.remoteConfig.RemoteConfig;
407+
377408
/**
378409
* Gets the {@link admin.securityRules.SecurityRules
379410
* `SecurityRules`} service for the default app or a given app.
@@ -496,6 +527,7 @@ declare namespace admin.app {
496527
machineLearning(): admin.machineLearning.MachineLearning;
497528
messaging(): admin.messaging.Messaging;
498529
projectManagement(): admin.projectManagement.ProjectManagement;
530+
remoteConfig(): admin.remoteConfig.RemoteConfig;
499531
securityRules(): admin.securityRules.SecurityRules;
500532
storage(): admin.storage.Storage;
501533

@@ -812,6 +844,196 @@ declare namespace admin.projectManagement {
812844
export import ProjectManagement = _projectManagement.admin.projectManagement.ProjectManagement;
813845
}
814846

847+
declare namespace admin.remoteConfig {
848+
849+
/**
850+
* Colors that are associated with conditions for display purposes.
851+
*/
852+
type TagColor = 'BLUE' | 'BROWN' | 'CYAN' | 'DEEP_ORANGE' | 'GREEN' |
853+
'INDIGO' | 'LIME' | 'ORANGE' | 'PINK' | 'PURPLE' | 'TEAL';
854+
855+
/**
856+
* Interface representing a Remote Config template.
857+
*/
858+
interface RemoteConfigTemplate {
859+
/**
860+
* A list of conditions in descending order by priority.
861+
*/
862+
conditions: RemoteConfigCondition[];
863+
864+
/**
865+
* Map of parameter keys to their optional default values and optional conditional values.
866+
*/
867+
parameters: { [key: string]: RemoteConfigParameter };
868+
869+
/**
870+
* Map of parameter group names to their parameter group objects.
871+
* A group's name is mutable but must be unique among groups in the Remote Config template.
872+
* The name is limited to 256 characters and intended to be human-readable. Any Unicode
873+
* characters are allowed.
874+
*/
875+
parameterGroups: { [key: string]: RemoteConfigParameterGroup };
876+
877+
/**
878+
* ETag of the current Remote Config template (readonly).
879+
*/
880+
readonly etag: string;
881+
}
882+
883+
/**
884+
* Interface representing a Remote Config parameter.
885+
* At minimum, a `defaultValue` or a `conditionalValues` entry must be present for the
886+
* parameter to have any effect.
887+
*/
888+
interface RemoteConfigParameter {
889+
890+
/**
891+
* The value to set the parameter to, when none of the named conditions evaluate to `true`.
892+
*/
893+
defaultValue?: RemoteConfigParameterValue;
894+
895+
/**
896+
* A `(condition name, value)` map. The condition name of the highest priority
897+
* (the one listed first in the Remote Config template's conditions list) determines the value of
898+
* this parameter.
899+
*/
900+
conditionalValues?: { [key: string]: RemoteConfigParameterValue };
901+
902+
/**
903+
* A description for this parameter. Should not be over 100 characters and may contain any
904+
* Unicode characters.
905+
*/
906+
description?: string;
907+
}
908+
909+
/**
910+
* Interface representing a Remote Config parameter group.
911+
* Grouping parameters is only for management purposes and does not affect client-side
912+
* fetching of parameter values.
913+
*/
914+
export interface RemoteConfigParameterGroup {
915+
/**
916+
* A description for the group. Its length must be less than or equal to 256 characters.
917+
* A description may contain any Unicode characters.
918+
*/
919+
description?: string;
920+
921+
/**
922+
* Map of parameter keys to their optional default values and optional conditional values for
923+
* parameters that belong to this group. A parameter only appears once per
924+
* Remote Config template. An ungrouped parameter appears at the top level, whereas a
925+
* parameter organized within a group appears within its group's map of parameters.
926+
*/
927+
parameters: { [key: string]: RemoteConfigParameter };
928+
}
929+
930+
/**
931+
* Interface representing a Remote Config condition.
932+
* A condition targets a specific group of users. A list of these conditions make up
933+
* part of a Remote Config template.
934+
*/
935+
interface RemoteConfigCondition {
936+
937+
/**
938+
* A non-empty and unique name of this condition.
939+
*/
940+
name: string;
941+
942+
/**
943+
* The logic of this condition.
944+
* See the documentation on
945+
* {@link https://firebase.google.com/docs/remote-config/condition-reference condition expressions}
946+
* for the expected syntax of this field.
947+
*/
948+
expression: string;
949+
950+
/**
951+
* The color associated with this condition for display purposes in the Firebase Console.
952+
* Not specifying this value results in the console picking an arbitrary color to associate
953+
* with the condition.
954+
*/
955+
tagColor?: TagColor;
956+
}
957+
958+
/**
959+
* Interface representing an explicit parameter value.
960+
*/
961+
interface ExplicitParameterValue {
962+
/**
963+
* The `string` value that the parameter is set to.
964+
*/
965+
value: string;
966+
}
967+
968+
/**
969+
* Interface representing an in-app-default value.
970+
*/
971+
interface InAppDefaultValue {
972+
/**
973+
* If `true`, the parameter is omitted from the parameter values returned to a client.
974+
*/
975+
useInAppDefault: boolean;
976+
}
977+
978+
/**
979+
* Type representing a Remote Config parameter value.
980+
* A `RemoteConfigParameterValue` could be either an `ExplicitParameterValue` or
981+
* an `InAppDefaultValue`.
982+
*/
983+
type RemoteConfigParameterValue = ExplicitParameterValue | InAppDefaultValue;
984+
985+
/**
986+
* The Firebase `RemoteConfig` service interface.
987+
*
988+
* Do not call this constructor directly. Instead, use
989+
* [`admin.remoteConfig()`](admin.remoteConfig#remoteConfig).
990+
*/
991+
interface RemoteConfig {
992+
app: admin.app.App;
993+
994+
/**
995+
* Gets the current active version of the {@link admin.remoteConfig.RemoteConfigTemplate
996+
* `RemoteConfigTemplate`} of the project.
997+
*
998+
* @return A promise that fulfills with a `RemoteConfigTemplate`.
999+
*/
1000+
getTemplate(): Promise<RemoteConfigTemplate>;
1001+
1002+
/**
1003+
* Validates a {@link admin.remoteConfig.RemoteConfigTemplate `RemoteConfigTemplate`}.
1004+
*
1005+
* @param template The Remote Config template to be validated.
1006+
* @returns A promise that fulfills with the validated `RemoteConfigTemplate`.
1007+
*/
1008+
validateTemplate(template: RemoteConfigTemplate): Promise<RemoteConfigTemplate>;
1009+
1010+
/**
1011+
* Publishes a Remote Config template.
1012+
*
1013+
* @param template The Remote Config template to be published.
1014+
* @param options Optional options object when publishing a Remote Config template:
1015+
* - {boolean} `force` Setting this to `true` forces the Remote Config template to
1016+
* be updated and circumvent the ETag. This approach is not recommended
1017+
* because it risks causing the loss of updates to your Remote Config
1018+
* template if multiple clients are updating the Remote Config template.
1019+
* See {@link https://firebase.google.com/docs/remote-config/use-config-rest#etag_usage_and_forced_updates
1020+
* ETag usage and forced updates}.
1021+
*
1022+
* @return A Promise that fulfills with the published `RemoteConfigTemplate`.
1023+
*/
1024+
publishTemplate(template: RemoteConfigTemplate, options?: { force: boolean }): Promise<RemoteConfigTemplate>;
1025+
1026+
/**
1027+
* Creates and returns a new Remote Config template from a JSON string.
1028+
*
1029+
* @param json The JSON string to populate a Remote Config template.
1030+
*
1031+
* @return A new template instance.
1032+
*/
1033+
createTemplateFromJSON(json: string): RemoteConfigTemplate;
1034+
}
1035+
}
1036+
8151037
declare namespace admin.securityRules {
8161038
export import RulesFile = _securityRules.admin.securityRules.RulesFile;
8171039
export import RulesetMetadata = _securityRules.admin.securityRules.RulesetMetadata;

0 commit comments

Comments
 (0)