Skip to content

Commit

Permalink
Remove product prefix from SSRC types (#2496)
Browse files Browse the repository at this point in the history
We have a Firebase AIP to avoid these prefixes.
  • Loading branch information
erikeldridge authored Mar 21, 2024
1 parent 5c9b649 commit f89632a
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 123 deletions.
69 changes: 34 additions & 35 deletions etc/firebase-admin.remote-config.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface ListVersionsResult {
versions: Version[];
}

// @public
export interface NamedCondition {
name: string;
}

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

Expand All @@ -46,10 +51,10 @@ 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 @@ -87,58 +92,52 @@ export interface RemoteConfigParameterGroup {
export type RemoteConfigParameterValue = ExplicitParameterValue | InAppDefaultValue;

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

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

// @public
export interface RemoteConfigServerTemplate {
cache: RemoteConfigServerTemplateData;
defaultConfig: RemoteConfigServerConfig;
evaluate(): RemoteConfigServerConfig;
load(): Promise<void>;
}

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

// @public
export interface RemoteConfigServerTemplateOptions {
defaultConfig?: RemoteConfigServerConfig;
template?: RemoteConfigServerTemplateData;
export interface RemoteConfigUser {
email: string;
imageUrl?: string;
name?: string;
}

// @public
export interface RemoteConfigTemplate {
conditions: RemoteConfigCondition[];
export type ServerConfig = {
[key: string]: string | boolean | number;
};

// @public
export interface ServerTemplate {
cache: ServerTemplateData;
defaultConfig: ServerConfig;
evaluate(): ServerConfig;
load(): Promise<void>;
}

// @public
export interface ServerTemplateData {
conditions: NamedCondition[];
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
10 changes: 5 additions & 5 deletions src/remote-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ export {
InAppDefaultValue,
ListVersionsOptions,
ListVersionsResult,
NamedCondition,
ParameterValueType,
RemoteConfigCondition,
RemoteConfigParameter,
RemoteConfigParameterGroup,
RemoteConfigParameterValue,
RemoteConfigTemplate,
RemoteConfigServerCondition,
RemoteConfigServerConfig,
RemoteConfigServerTemplate,
RemoteConfigServerTemplateData,
RemoteConfigServerTemplateOptions,
RemoteConfigUser,
ServerConfig,
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
40 changes: 16 additions & 24 deletions src/remote-config/remote-config-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,12 @@ export interface RemoteConfigCondition {
* A condition targets a specific group of users. A list of these conditions make up
* part of a Remote Config template.
*/
export interface RemoteConfigServerCondition {
export interface NamedCondition {

/**
* A non-empty and unique name of this condition.
*/
name: string;

/**
* The logic of this condition.
* See the documentation on
* {@link https://firebase.google.com/docs/remote-config/condition-reference | condition expressions}
* for the expected syntax of this field.
*/
expression: string;
}

/**
Expand Down Expand Up @@ -191,11 +183,11 @@ 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.
*/
conditions: RemoteConfigServerCondition[];
conditions: NamedCondition[];

/**
* Map of parameter keys to their optional default values and optional conditional values.
Expand All @@ -214,49 +206,49 @@ 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
* intended before it connects to the Remote Config backend, and so that
* default values are available if none are set on the backend.
*/
defaultConfig?: RemoteConfigServerConfig,
defaultConfig?: ServerConfig,

/**
* Enables integrations to use template data loaded independently. For
* example, customers can reduce initialization latency by pre-fetching and
* 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 RemoteConfigServerConfig} that contains default Config values.
* A {@link ServerConfig} that contains default Config values.
*/
defaultConfig: RemoteConfigServerConfig;
defaultConfig: ServerConfig;

/**
* Evaluates the current template to produce a {@link RemoteConfigServerConfig}.
* Evaluates the current template to produce a {@link ServerConfig}.
*/
evaluate(): RemoteConfigServerConfig;
evaluate(): ServerConfig;

/**
* Fetches and caches the current active version of the
* project's {@link RemoteConfigServerTemplate}.
* project's {@link ServerTemplate}.
*/
load(): Promise<void>;
}
Expand Down Expand Up @@ -387,4 +379,4 @@ export interface ListVersionsOptions {
/**
* Represents the configuration produced by evaluating a server template.
*/
export type RemoteConfigServerConfig = { [key: string]: string | boolean | number }
export type ServerConfig = { [key: string]: string | boolean | number }
43 changes: 22 additions & 21 deletions src/remote-config/remote-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ import {
RemoteConfigCondition,
RemoteConfigParameter,
RemoteConfigParameterGroup,
RemoteConfigServerTemplate,
ServerTemplate,
RemoteConfigTemplate,
RemoteConfigUser,
Version,
ExplicitParameterValue,
InAppDefaultValue,
ParameterValueType,
RemoteConfigServerConfig,
RemoteConfigServerTemplateData,
RemoteConfigServerTemplateOptions,
ServerConfig,
ServerTemplateData,
ServerTemplateOptions,
NamedCondition,
} from './remote-config-api';

/**
Expand Down Expand Up @@ -177,20 +178,20 @@ 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 {
const template = new RemoteConfigServerTemplateImpl(this.client, options?.defaultConfig);
public initServerTemplate(options?: ServerTemplateOptions): ServerTemplate {
const template = new ServerTemplateImpl(this.client, options?.defaultConfig);
if (options?.template) {
template.cache = options?.template;
}
Expand Down Expand Up @@ -285,35 +286,35 @@ class RemoteConfigTemplateImpl implements RemoteConfigTemplate {
/**
* Remote Config dataplane template data implementation.
*/
class RemoteConfigServerTemplateImpl implements RemoteConfigServerTemplate {
public cache: RemoteConfigServerTemplateData;
class ServerTemplateImpl implements ServerTemplate {
public cache: ServerTemplateData;

constructor(
private readonly apiClient: RemoteConfigApiClient,
public readonly defaultConfig: RemoteConfigServerConfig = {}
public readonly defaultConfig: ServerConfig = {}
) { }

/**
* 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()
.then((template) => {
this.cache = new RemoteConfigServerTemplateDataImpl(template);
this.cache = new ServerTemplateDataImpl(template);
});
}

/**
* Evaluates the current template in cache to produce a {@link RemoteConfigServerConfig}.
* Evaluates the current template in cache to produce a {@link ServerConfig}.
*/
public evaluate(): RemoteConfigServerConfig {
public evaluate(): ServerConfig {
if (!this.cache) {
throw new FirebaseRemoteConfigError(
'failed-precondition',
'No Remote Config Server template in cache. Call load() before calling evaluate().');
}

const evaluatedConfig: RemoteConfigServerConfig = {};
const evaluatedConfig: ServerConfig = {};

for (const [key, parameter] of Object.entries(this.cache.parameters)) {
const { defaultValue, valueType } = parameter;
Expand All @@ -339,7 +340,7 @@ class RemoteConfigServerTemplateImpl implements RemoteConfigServerTemplate {
// Enables config to be a convenient object, but with the ability to perform additional
// functionality when a value is retrieved.
const proxyHandler = {
get(target: RemoteConfigServerConfig, prop: string) {
get(target: ServerConfig, prop: string) {
return target[prop];
}
};
Expand Down Expand Up @@ -374,14 +375,14 @@ class RemoteConfigServerTemplateImpl implements RemoteConfigServerTemplate {
/**
* Remote Config dataplane template data implementation.
*/
class RemoteConfigServerTemplateDataImpl implements RemoteConfigServerTemplateData {
class ServerTemplateDataImpl implements ServerTemplateData {
public parameters: { [key: string]: RemoteConfigParameter };
public parameterGroups: { [key: string]: RemoteConfigParameterGroup };
public conditions: RemoteConfigCondition[];
public conditions: NamedCondition[];
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

0 comments on commit f89632a

Please sign in to comment.