Skip to content

Commit a833f4e

Browse files
authored
feat(rc): Add server side Remote Config support (#2529)
Currently, Remote Config doesn't provide a way for servers to obtain configuration, and the Admin SDK has historically been used only for managing Remote Config. This change updates the Admin SDK with functionality for evaluating a template to produce configuration for a given context.
1 parent a00de0c commit a833f4e

14 files changed

+4253
-1297
lines changed

etc/firebase-admin.remote-config.api.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
import { Agent } from 'http';
1010

11+
// @public
12+
export interface AndCondition {
13+
conditions?: Array<OneOfCondition>;
14+
}
15+
16+
// @public
17+
export type DefaultConfig = {
18+
[key: string]: string | number | boolean;
19+
};
20+
21+
// @public
22+
export type EvaluationContext = {
23+
randomizationId?: string;
24+
};
25+
1126
// @public
1227
export interface ExplicitParameterValue {
1328
value: string;
@@ -18,11 +33,21 @@ export interface ExplicitParameterValue {
1833
// @public
1934
export function getRemoteConfig(app?: App): RemoteConfig;
2035

36+
// @public
37+
export interface GetServerTemplateOptions {
38+
defaultConfig?: DefaultConfig;
39+
}
40+
2141
// @public
2242
export interface InAppDefaultValue {
2343
useInAppDefault: boolean;
2444
}
2545

46+
// @public
47+
export interface InitServerTemplateOptions extends GetServerTemplateOptions {
48+
template?: ServerTemplateDataType;
49+
}
50+
2651
// @public
2752
export interface ListVersionsOptions {
2853
endTime?: Date | string;
@@ -38,16 +63,60 @@ export interface ListVersionsResult {
3863
versions: Version[];
3964
}
4065

66+
// @public
67+
export interface MicroPercentRange {
68+
microPercentLowerBound?: number;
69+
microPercentUpperBound?: number;
70+
}
71+
72+
// @public
73+
export interface NamedCondition {
74+
condition: OneOfCondition;
75+
name: string;
76+
}
77+
78+
// @public
79+
export interface OneOfCondition {
80+
andCondition?: AndCondition;
81+
false?: Record<string, never>;
82+
orCondition?: OrCondition;
83+
percent?: PercentCondition;
84+
true?: Record<string, never>;
85+
}
86+
87+
// @public
88+
export interface OrCondition {
89+
conditions?: Array<OneOfCondition>;
90+
}
91+
4192
// @public
4293
export type ParameterValueType = 'STRING' | 'BOOLEAN' | 'NUMBER' | 'JSON';
4394

95+
// @public
96+
export interface PercentCondition {
97+
microPercent?: number;
98+
microPercentRange?: MicroPercentRange;
99+
percentOperator?: PercentConditionOperator;
100+
seed?: string;
101+
}
102+
103+
// @public
104+
export enum PercentConditionOperator {
105+
BETWEEN = "BETWEEN",
106+
GREATER_THAN = "GREATER_THAN",
107+
LESS_OR_EQUAL = "LESS_OR_EQUAL",
108+
UNKNOWN = "UNKNOWN"
109+
}
110+
44111
// @public
45112
export class RemoteConfig {
46113
// (undocumented)
47114
readonly app: App;
48115
createTemplateFromJSON(json: string): RemoteConfigTemplate;
116+
getServerTemplate(options?: GetServerTemplateOptions): Promise<ServerTemplate>;
49117
getTemplate(): Promise<RemoteConfigTemplate>;
50118
getTemplateAtVersion(versionNumber: number | string): Promise<RemoteConfigTemplate>;
119+
initServerTemplate(options?: InitServerTemplateOptions): ServerTemplate;
51120
listVersions(options?: ListVersionsOptions): Promise<ListVersionsResult>;
52121
publishTemplate(template: RemoteConfigTemplate, options?: {
53122
force: boolean;
@@ -104,9 +173,49 @@ export interface RemoteConfigUser {
104173
name?: string;
105174
}
106175

176+
// @public
177+
export interface ServerConfig {
178+
getBoolean(key: string): boolean;
179+
getNumber(key: string): number;
180+
getString(key: string): string;
181+
getValue(key: string): Value;
182+
}
183+
184+
// @public
185+
export interface ServerTemplate {
186+
evaluate(context?: EvaluationContext): ServerConfig;
187+
load(): Promise<void>;
188+
set(template: ServerTemplateDataType): void;
189+
toJSON(): ServerTemplateData;
190+
}
191+
192+
// @public
193+
export interface ServerTemplateData {
194+
conditions: NamedCondition[];
195+
readonly etag: string;
196+
parameters: {
197+
[key: string]: RemoteConfigParameter;
198+
};
199+
version?: Version;
200+
}
201+
202+
// @public
203+
export type ServerTemplateDataType = ServerTemplateData | string;
204+
107205
// @public
108206
export type TagColor = 'BLUE' | 'BROWN' | 'CYAN' | 'DEEP_ORANGE' | 'GREEN' | 'INDIGO' | 'LIME' | 'ORANGE' | 'PINK' | 'PURPLE' | 'TEAL';
109207

208+
// @public
209+
export interface Value {
210+
asBoolean(): boolean;
211+
asNumber(): number;
212+
asString(): string;
213+
getSource(): ValueSource;
214+
}
215+
216+
// @public
217+
export type ValueSource = 'static' | 'default' | 'remote';
218+
110219
// @public
111220
export interface Version {
112221
description?: string;

0 commit comments

Comments
 (0)