Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
81c90c3
Get And condition passing
erikeldridge Feb 29, 2024
fc7deeb
Support and.or condition
erikeldridge Feb 29, 2024
bd12f0d
Support true condition
erikeldridge Feb 29, 2024
43e479e
Support false condition, and fix tests
erikeldridge Feb 29, 2024
64c71d7
Use or.and, not the other way around
erikeldridge Feb 29, 2024
dd3af1d
Integrate conditional values into evaluate method
erikeldridge Mar 5, 2024
14f5339
Test handling for multiple conditions
erikeldridge Mar 5, 2024
1754fb5
Clean up logs
erikeldridge Mar 5, 2024
0283dbf
Extract condition evaluation to class for testing
erikeldridge Mar 5, 2024
264c75f
Namespace condition names
erikeldridge Mar 5, 2024
fcbcd6d
Iterate over ordered condition list
erikeldridge Mar 5, 2024
ef07c33
Test condition ordering
erikeldridge Mar 5, 2024
9179a0f
Differentiate named conditions
erikeldridge Mar 5, 2024
816f38a
Document condition types
erikeldridge Mar 5, 2024
307ec9d
Generalize condition eval test and fix styling
erikeldridge Mar 5, 2024
f87e605
Replace log statement with todo
erikeldridge Mar 5, 2024
4599ec5
Implement evaluate percent condition for RC server-side
trekforever Mar 6, 2024
559d8aa
Apply lint fixes
trekforever Mar 6, 2024
31d6c9a
Add context param to evaluate method
erikeldridge Mar 7, 2024
4e6a1c9
Add tests for percent condition eval
trekforever Mar 8, 2024
6e86cba
Update evaluator tests to use context
erikeldridge Mar 8, 2024
b669472
Increase threshold to +/- 500 for percent condition eval tests
trekforever Mar 8, 2024
687daa3
Clean up percentCondition tests a bit and add note on the tolerance used
trekforever Mar 8, 2024
12101f1
Apply suggestions from code review
erikeldridge Mar 9, 2024
89efaa7
Update copyright date and remove stray log statement
erikeldridge Mar 9, 2024
d161bd6
Mock farmhash in tests
erikeldridge Mar 11, 2024
9e0bc5d
Add Math.abs for farmhash - to be consistent with the internal implem…
trekforever Mar 12, 2024
bdc14d3
Regenerate package-lock to fix Node 14 CI error re busboy
erikeldridge Mar 13, 2024
0a3408f
Fix lint errors
erikeldridge Mar 13, 2024
347f07b
Rename "id" to "randomizationId" per discussion
erikeldridge Mar 14, 2024
6e245e2
Extract API
erikeldridge Mar 14, 2024
f7dbf1d
Only return false in cases of uknown template evaluation
erikeldridge Mar 14, 2024
0cab5d1
Remove product prefix from type names
erikeldridge Mar 14, 2024
53c2145
Remove product prefix from exported types
erikeldridge Mar 15, 2024
ee675fb
Remove unused "expression" field from server condition
erikeldridge Mar 15, 2024
c9701eb
Extract API
erikeldridge Mar 15, 2024
2f2fa2f
Merge branch 'ssrc-prefix' into ssrc-percent
erikeldridge Mar 15, 2024
fa21a91
Remove prefix from impl classes, for consistency
erikeldridge Mar 15, 2024
caddabe
Merge branch 'ssrc-prefix' into ssrc-percent
erikeldridge Mar 15, 2024
530ae21
Remove prefix from new internal classes
erikeldridge Mar 15, 2024
97876df
Remove "server" prefix
erikeldridge Mar 19, 2024
689c6aa
Remove prefix from NamedCondition
erikeldridge Mar 19, 2024
9c79eea
Merge branch 'ssrc-prefix' into ssrc-percent
erikeldridge Mar 19, 2024
0202ac7
Rename "or" and "and" fields to match API
erikeldridge Mar 20, 2024
14fdd8e
Rename "operator" field to "percentOperator" to match API
erikeldridge Mar 20, 2024
117eae9
Extract API after "and" and "or" rename
erikeldridge Mar 20, 2024
e99c489
Merge remote-tracking branch 'gh-public/ssrc' into ssrc-percent
erikeldridge Mar 21, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 62 additions & 62 deletions etc/firebase-admin.remote-config.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

import { Agent } from 'http';

// @public
export interface AndServerCondition {
conditions?: Array<ServerCondition>;
}

// @public
export type EvaluationContext = {
randomizationId?: string;
};

// @public
export interface ExplicitParameterValue {
value: string;
Expand Down Expand Up @@ -44,6 +54,17 @@ export interface MicroPercentRange {
microPercentUpperBound?: number;
}

// @public
export interface NamedServerCondition {
condition: ServerCondition;
name: string;
}

// @public
export interface OrServerCondition {
conditions?: Array<ServerCondition>;
}

// @public
export type ParameterValueType = 'STRING' | 'BOOLEAN' | 'NUMBER' | 'JSON';

Expand All @@ -55,15 +76,23 @@ export enum PercentConditionOperator {
UNKNOWN = "UNKNOWN"
}

// @public
export interface PercentServerCondition {
microPercent?: number;
microPercentRange?: MicroPercentRange;
operator?: PercentConditionOperator;
seed?: string;
}

// @public
export class RemoteConfig {
// (undocumented)
readonly app: App;
createTemplateFromJSON(json: string): RemoteConfigTemplate;
getServerTemplate(options?: RemoteConfigServerTemplateOptions): Promise<RemoteConfigServerTemplate>;
getServerTemplate(options?: ServerTemplateOptions): Promise<ServerTemplate>;
getTemplate(): Promise<RemoteConfigTemplate>;
getTemplateAtVersion(versionNumber: number | string): Promise<RemoteConfigTemplate>;
initServerTemplate(options?: RemoteConfigServerTemplateOptions): RemoteConfigServerTemplate;
initServerTemplate(options?: ServerTemplateOptions): ServerTemplate;
listVersions(options?: ListVersionsOptions): Promise<ListVersionsResult>;
publishTemplate(template: RemoteConfigTemplate, options?: {
force: boolean;
Expand Down Expand Up @@ -101,90 +130,61 @@ export interface RemoteConfigParameterGroup {
export type RemoteConfigParameterValue = ExplicitParameterValue | InAppDefaultValue;

// @public
export interface RemoteConfigServerAndCondition {
conditions?: Array<RemoteConfigServerCondition>;
export interface RemoteConfigTemplate {
conditions: RemoteConfigCondition[];
readonly etag: string;
parameterGroups: {
[key: string]: RemoteConfigParameterGroup;
};
parameters: {
[key: string]: RemoteConfigParameter;
};
version?: Version;
}

// @public
export interface RemoteConfigUser {
email: string;
imageUrl?: string;
name?: string;
}

// @public
export interface RemoteConfigServerCondition {
and?: RemoteConfigServerAndCondition;
export interface ServerCondition {
and?: AndServerCondition;
false?: Record<string, never>;
or?: RemoteConfigServerOrCondition;
percent?: RemoteConfigServerPercentCondition;
or?: OrServerCondition;
percent?: PercentServerCondition;
true?: Record<string, never>;
}

// @public
export type RemoteConfigServerConfig = {
export type ServerConfig = {
[key: string]: string | boolean | number;
};

// @public
export type RemoteConfigServerContext = {
randomizationId?: string;
};

// @public
export interface RemoteConfigServerNamedCondition {
condition: RemoteConfigServerCondition;
name: string;
}

// @public
export interface RemoteConfigServerOrCondition {
conditions?: Array<RemoteConfigServerCondition>;
}

// @public
export interface RemoteConfigServerPercentCondition {
microPercent?: number;
microPercentRange?: MicroPercentRange;
operator?: PercentConditionOperator;
seed?: string;
}

// @public
export interface RemoteConfigServerTemplate {
cache: RemoteConfigServerTemplateData;
defaultConfig: RemoteConfigServerConfig;
evaluate(context?: RemoteConfigServerContext): RemoteConfigServerConfig;
export interface ServerTemplate {
cache: ServerTemplateData;
defaultConfig: ServerConfig;
evaluate(context?: EvaluationContext): ServerConfig;
load(): Promise<void>;
}

// @public
export interface RemoteConfigServerTemplateData {
conditions: RemoteConfigServerNamedCondition[];
readonly etag: string;
parameters: {
[key: string]: RemoteConfigParameter;
};
version?: Version;
}

// @public
export interface RemoteConfigServerTemplateOptions {
defaultConfig?: RemoteConfigServerConfig;
template?: RemoteConfigServerTemplateData;
}

// @public
export interface RemoteConfigTemplate {
conditions: RemoteConfigCondition[];
export interface ServerTemplateData {
conditions: NamedServerCondition[];
readonly etag: string;
parameterGroups: {
[key: string]: RemoteConfigParameterGroup;
};
parameters: {
[key: string]: RemoteConfigParameter;
};
version?: Version;
}

// @public
export interface RemoteConfigUser {
email: string;
imageUrl?: string;
name?: string;
export interface ServerTemplateOptions {
defaultConfig?: ServerConfig;
template?: ServerTemplateData;
}

// @public
Expand Down
18 changes: 9 additions & 9 deletions src/remote-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ import { FirebaseApp } from '../app/firebase-app';
import { RemoteConfig } from './remote-config';

export {
AndServerCondition,
EvaluationContext,
ExplicitParameterValue,
InAppDefaultValue,
ListVersionsOptions,
ListVersionsResult,
MicroPercentRange,
NamedServerCondition,
OrServerCondition,
ParameterValueType,
PercentConditionOperator,
PercentServerCondition,
RemoteConfigCondition,
RemoteConfigParameter,
RemoteConfigParameterGroup,
RemoteConfigParameterValue,
RemoteConfigTemplate,
RemoteConfigUser,
ServerCondition,
EvaluationContext,
AndServerCondition,
NamedServerCondition,
OrServerCondition,
PercentServerCondition,
ServerConfig,
RemoteConfigServerTemplate,
RemoteConfigServerTemplateData,
RemoteConfigServerTemplateOptions,
RemoteConfigUser,
ServerTemplate,
ServerTemplateData,
ServerTemplateOptions,
TagColor,
Version,
} from './remote-config-api';
Expand Down
6 changes: 3 additions & 3 deletions src/remote-config/remote-config-api-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
ListVersionsOptions,
ListVersionsResult,
RemoteConfigTemplate,
RemoteConfigServerTemplateData
ServerTemplateData
} from './remote-config-api';

// Remote Config backend constants
Expand Down Expand Up @@ -175,7 +175,7 @@ export class RemoteConfigApiClient {
});
}

public getServerTemplate(): Promise<RemoteConfigServerTemplateData> {
public getServerTemplate(): Promise<ServerTemplateData> {
return this.getUrl()
.then((url) => {
const request: HttpRequestConfig = {
Expand Down Expand Up @@ -289,7 +289,7 @@ export class RemoteConfigApiClient {
* @param {HttpResponse} resp API response object.
* @param {string} customEtag A custom etag to replace the etag fom the API response (Optional).
*/
private toRemoteConfigServerTemplate(resp: HttpResponse, customEtag?: string): RemoteConfigServerTemplateData {
private toRemoteConfigServerTemplate(resp: HttpResponse, customEtag?: string): ServerTemplateData {
const etag = (typeof customEtag === 'undefined') ? resp.headers['etag'] : customEtag;
this.validateEtag(etag);
return {
Expand Down
16 changes: 8 additions & 8 deletions src/remote-config/remote-config-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export interface RemoteConfigTemplate {
/**
* Represents the data in a Remote Config server template.
*/
export interface RemoteConfigServerTemplateData {
export interface ServerTemplateData {
/**
* A list of conditions in descending order by priority.
*/
Expand All @@ -352,9 +352,9 @@ export interface RemoteConfigServerTemplateData {
}

/**
* Represents optional arguments that can be used when instantiating {@link RemoteConfigServerTemplate}.
* Represents optional arguments that can be used when instantiating {@link ServerTemplate}.
*/
export interface RemoteConfigServerTemplateOptions {
export interface ServerTemplateOptions {

/**
* Defines in-app default parameter values, so that your app behaves as
Expand All @@ -369,18 +369,18 @@ export interface RemoteConfigServerTemplateOptions {
* caching template data and then using this option to initialize the SDK with
* that data.
*/
template?: RemoteConfigServerTemplateData,
template?: ServerTemplateData,
}

/**
* Represents a stateful abstraction for a Remote Config server template.
*/
export interface RemoteConfigServerTemplate {
export interface ServerTemplate {

/**
* Cached {@link RemoteConfigServerTemplateData}.
* Cached {@link ServerTemplateData}.
*/
cache: RemoteConfigServerTemplateData;
cache: ServerTemplateData;

/**
* A {@link ServerConfig} that contains default Config values.
Expand All @@ -394,7 +394,7 @@ export interface RemoteConfigServerTemplate {

/**
* Fetches and caches the current active version of the
* project's {@link RemoteConfigServerTemplate}.
* project's {@link ServerTemplate}.
*/
load(): Promise<void>;
}
Expand Down
26 changes: 13 additions & 13 deletions src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import {
RemoteConfigCondition,
RemoteConfigParameter,
RemoteConfigParameterGroup,
RemoteConfigServerTemplate,
ServerTemplate,
RemoteConfigTemplate,
RemoteConfigUser,
Version,
ExplicitParameterValue,
InAppDefaultValue,
ParameterValueType,
ServerConfig,
RemoteConfigServerTemplateData,
RemoteConfigServerTemplateOptions,
RemoteConfigParameterValue,
NamedServerCondition,
EvaluationContext,
ServerTemplateData,
ServerTemplateOptions,
NamedServerCondition,
} from './remote-config-api';

/**
Expand Down Expand Up @@ -181,19 +181,19 @@ export class RemoteConfig {
}

/**
* Instantiates {@link RemoteConfigServerTemplate} and then fetches and caches the latest
* Instantiates {@link ServerTemplate} and then fetches and caches the latest
* template version of the project.
*/
public async getServerTemplate(options?: RemoteConfigServerTemplateOptions): Promise<RemoteConfigServerTemplate> {
public async getServerTemplate(options?: ServerTemplateOptions): Promise<ServerTemplate> {
const template = this.initServerTemplate(options);
await template.load();
return template;
}

/**
* Synchronously instantiates {@link RemoteConfigServerTemplate}.
* Synchronously instantiates {@link ServerTemplate}.
*/
public initServerTemplate(options?: RemoteConfigServerTemplateOptions): RemoteConfigServerTemplate {
public initServerTemplate(options?: ServerTemplateOptions): ServerTemplate {
const template = new RemoteConfigServerTemplateImpl(
this.client, new RemoteConfigConditionEvaluator(), options?.defaultConfig);
if (options?.template) {
Expand Down Expand Up @@ -290,8 +290,8 @@ class RemoteConfigTemplateImpl implements RemoteConfigTemplate {
/**
* Remote Config dataplane template data implementation.
*/
class RemoteConfigServerTemplateImpl implements RemoteConfigServerTemplate {
public cache: RemoteConfigServerTemplateData;
class RemoteConfigServerTemplateImpl implements ServerTemplate {
public cache: ServerTemplateData;

constructor(
private readonly apiClient: RemoteConfigApiClient,
Expand All @@ -300,7 +300,7 @@ class RemoteConfigServerTemplateImpl implements RemoteConfigServerTemplate {
) { }

/**
* Fetches and caches the current active version of the project's {@link RemoteConfigServerTemplate}.
* Fetches and caches the current active version of the project's {@link ServerTemplate}.
*/
public load(): Promise<void> {
return this.apiClient.getServerTemplate()
Expand Down Expand Up @@ -411,14 +411,14 @@ class RemoteConfigServerTemplateImpl implements RemoteConfigServerTemplate {
/**
* Remote Config dataplane template data implementation.
*/
class RemoteConfigServerTemplateDataImpl implements RemoteConfigServerTemplateData {
class RemoteConfigServerTemplateDataImpl implements ServerTemplateData {
public parameters: { [key: string]: RemoteConfigParameter };
public parameterGroups: { [key: string]: RemoteConfigParameterGroup };
public conditions: NamedServerCondition[];
public readonly etag: string;
public version?: Version;

constructor(template: RemoteConfigServerTemplateData) {
constructor(template: ServerTemplateData) {
if (!validator.isNonNullObject(template) ||
!validator.isNonEmptyString(template.etag)) {
throw new FirebaseRemoteConfigError(
Expand Down
Loading