Initial commit
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Firebase Remote Config.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { RemoteConfig } from './remote-config';
|
||||
export { ExplicitParameterValue, InAppDefaultValue, ListVersionsOptions, ListVersionsResult, ParameterValueType, RemoteConfigCondition, RemoteConfigParameter, RemoteConfigParameterGroup, RemoteConfigParameterValue, RemoteConfigTemplate, RemoteConfigUser, TagColor, Version, } from './remote-config-api';
|
||||
export { RemoteConfig } from './remote-config';
|
||||
/**
|
||||
* Gets the {@link RemoteConfig} service for the default app or a given app.
|
||||
*
|
||||
* `getRemoteConfig()` can be called with no arguments to access the default
|
||||
* app's `RemoteConfig` service or as `getRemoteConfig(app)` to access the
|
||||
* `RemoteConfig` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the `RemoteConfig` service for the default app
|
||||
* const defaultRemoteConfig = getRemoteConfig();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the `RemoteConfig` service for a given app
|
||||
* const otherRemoteConfig = getRemoteConfig(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app for which to return the `RemoteConfig` service.
|
||||
* If not provided, the default `RemoteConfig` service is returned.
|
||||
*
|
||||
* @returns The default `RemoteConfig` service if no
|
||||
* app is provided, or the `RemoteConfig` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
export declare function getRemoteConfig(app?: App): RemoteConfig;
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getRemoteConfig = void 0;
|
||||
/**
|
||||
* Firebase Remote Config.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
var app_1 = require("../app");
|
||||
var remote_config_1 = require("./remote-config");
|
||||
var remote_config_2 = require("./remote-config");
|
||||
Object.defineProperty(exports, "RemoteConfig", { enumerable: true, get: function () { return remote_config_2.RemoteConfig; } });
|
||||
/**
|
||||
* Gets the {@link RemoteConfig} service for the default app or a given app.
|
||||
*
|
||||
* `getRemoteConfig()` can be called with no arguments to access the default
|
||||
* app's `RemoteConfig` service or as `getRemoteConfig(app)` to access the
|
||||
* `RemoteConfig` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the `RemoteConfig` service for the default app
|
||||
* const defaultRemoteConfig = getRemoteConfig();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the `RemoteConfig` service for a given app
|
||||
* const otherRemoteConfig = getRemoteConfig(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app for which to return the `RemoteConfig` service.
|
||||
* If not provided, the default `RemoteConfig` service is returned.
|
||||
*
|
||||
* @returns The default `RemoteConfig` service if no
|
||||
* app is provided, or the `RemoteConfig` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
function getRemoteConfig(app) {
|
||||
if (typeof app === 'undefined') {
|
||||
app = app_1.getApp();
|
||||
}
|
||||
var firebaseApp = app;
|
||||
return firebaseApp.getOrInitService('remoteConfig', function (app) { return new remote_config_1.RemoteConfig(app); });
|
||||
}
|
||||
exports.getRemoteConfig = getRemoteConfig;
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { PrefixedFirebaseError } from '../utils/error';
|
||||
export declare type RemoteConfigErrorCode = 'aborted' | 'already-exists' | 'failed-precondition' | 'internal-error' | 'invalid-argument' | 'not-found' | 'out-of-range' | 'permission-denied' | 'resource-exhausted' | 'unauthenticated' | 'unknown-error';
|
||||
/**
|
||||
* Firebase Remote Config error code structure. This extends PrefixedFirebaseError.
|
||||
*
|
||||
* @param {RemoteConfigErrorCode} code The error code.
|
||||
* @param {string} message The error message.
|
||||
* @constructor
|
||||
*/
|
||||
export declare class FirebaseRemoteConfigError extends PrefixedFirebaseError {
|
||||
constructor(code: RemoteConfigErrorCode, message: string);
|
||||
}
|
||||
Generated
Vendored
+407
@@ -0,0 +1,407 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FirebaseRemoteConfigError = exports.RemoteConfigApiClient = void 0;
|
||||
var api_request_1 = require("../utils/api-request");
|
||||
var error_1 = require("../utils/error");
|
||||
var utils = require("../utils/index");
|
||||
var validator = require("../utils/validator");
|
||||
var deep_copy_1 = require("../utils/deep-copy");
|
||||
// Remote Config backend constants
|
||||
var FIREBASE_REMOTE_CONFIG_V1_API = 'https://firebaseremoteconfig.googleapis.com/v1';
|
||||
var FIREBASE_REMOTE_CONFIG_HEADERS = {
|
||||
'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion(),
|
||||
// There is a known issue in which the ETag is not properly returned in cases where the request
|
||||
// does not specify a compression type. Currently, it is required to include the header
|
||||
// `Accept-Encoding: gzip` or equivalent in all requests.
|
||||
// https://firebase.google.com/docs/remote-config/use-config-rest#etag_usage_and_forced_updates
|
||||
'Accept-Encoding': 'gzip',
|
||||
};
|
||||
/**
|
||||
* Class that facilitates sending requests to the Firebase Remote Config backend API.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
var RemoteConfigApiClient = /** @class */ (function () {
|
||||
function RemoteConfigApiClient(app) {
|
||||
this.app = app;
|
||||
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'First argument passed to admin.remoteConfig() must be a valid Firebase app instance.');
|
||||
}
|
||||
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
||||
}
|
||||
RemoteConfigApiClient.prototype.getTemplate = function () {
|
||||
var _this = this;
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'GET',
|
||||
url: url + "/remoteConfig",
|
||||
headers: FIREBASE_REMOTE_CONFIG_HEADERS
|
||||
};
|
||||
return _this.httpClient.send(request);
|
||||
})
|
||||
.then(function (resp) {
|
||||
return _this.toRemoteConfigTemplate(resp);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.getTemplateAtVersion = function (versionNumber) {
|
||||
var _this = this;
|
||||
var data = { versionNumber: this.validateVersionNumber(versionNumber) };
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'GET',
|
||||
url: url + "/remoteConfig",
|
||||
headers: FIREBASE_REMOTE_CONFIG_HEADERS,
|
||||
data: data
|
||||
};
|
||||
return _this.httpClient.send(request);
|
||||
})
|
||||
.then(function (resp) {
|
||||
return _this.toRemoteConfigTemplate(resp);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.validateTemplate = function (template) {
|
||||
var _this = this;
|
||||
template = this.validateInputRemoteConfigTemplate(template);
|
||||
return this.sendPutRequest(template, template.etag, true)
|
||||
.then(function (resp) {
|
||||
// validating a template returns an etag with the suffix -0 means that your update
|
||||
// was successfully validated. We set the etag back to the original etag of the template
|
||||
// to allow future operations.
|
||||
_this.validateEtag(resp.headers['etag']);
|
||||
return _this.toRemoteConfigTemplate(resp, template.etag);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.publishTemplate = function (template, options) {
|
||||
var _this = this;
|
||||
template = this.validateInputRemoteConfigTemplate(template);
|
||||
var ifMatch = template.etag;
|
||||
if (options && options.force == true) {
|
||||
// setting `If-Match: *` forces the Remote Config template to be updated
|
||||
// and circumvent the ETag, and the protection from that it provides.
|
||||
ifMatch = '*';
|
||||
}
|
||||
return this.sendPutRequest(template, ifMatch)
|
||||
.then(function (resp) {
|
||||
return _this.toRemoteConfigTemplate(resp);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.rollback = function (versionNumber) {
|
||||
var _this = this;
|
||||
var data = { versionNumber: this.validateVersionNumber(versionNumber) };
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'POST',
|
||||
url: url + "/remoteConfig:rollback",
|
||||
headers: FIREBASE_REMOTE_CONFIG_HEADERS,
|
||||
data: data
|
||||
};
|
||||
return _this.httpClient.send(request);
|
||||
})
|
||||
.then(function (resp) {
|
||||
return _this.toRemoteConfigTemplate(resp);
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.listVersions = function (options) {
|
||||
var _this = this;
|
||||
if (typeof options !== 'undefined') {
|
||||
options = this.validateListVersionsOptions(options);
|
||||
}
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'GET',
|
||||
url: url + "/remoteConfig:listVersions",
|
||||
headers: FIREBASE_REMOTE_CONFIG_HEADERS,
|
||||
data: options
|
||||
};
|
||||
return _this.httpClient.send(request);
|
||||
})
|
||||
.then(function (resp) {
|
||||
return resp.data;
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.sendPutRequest = function (template, etag, validateOnly) {
|
||||
var _this = this;
|
||||
var path = 'remoteConfig';
|
||||
if (validateOnly) {
|
||||
path += '?validate_only=true';
|
||||
}
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'PUT',
|
||||
url: url + "/" + path,
|
||||
headers: __assign(__assign({}, FIREBASE_REMOTE_CONFIG_HEADERS), { 'If-Match': etag }),
|
||||
data: {
|
||||
conditions: template.conditions,
|
||||
parameters: template.parameters,
|
||||
parameterGroups: template.parameterGroups,
|
||||
version: template.version,
|
||||
}
|
||||
};
|
||||
return _this.httpClient.send(request);
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.getUrl = function () {
|
||||
return this.getProjectIdPrefix()
|
||||
.then(function (projectIdPrefix) {
|
||||
return FIREBASE_REMOTE_CONFIG_V1_API + "/" + projectIdPrefix;
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.getProjectIdPrefix = function () {
|
||||
var _this = this;
|
||||
if (this.projectIdPrefix) {
|
||||
return Promise.resolve(this.projectIdPrefix);
|
||||
}
|
||||
return utils.findProjectId(this.app)
|
||||
.then(function (projectId) {
|
||||
if (!validator.isNonEmptyString(projectId)) {
|
||||
throw new FirebaseRemoteConfigError('unknown-error', 'Failed to determine project ID. Initialize the SDK with service account credentials, or '
|
||||
+ 'set project ID as an app option. Alternatively, set the GOOGLE_CLOUD_PROJECT '
|
||||
+ 'environment variable.');
|
||||
}
|
||||
_this.projectIdPrefix = "projects/" + projectId;
|
||||
return _this.projectIdPrefix;
|
||||
});
|
||||
};
|
||||
RemoteConfigApiClient.prototype.toFirebaseError = function (err) {
|
||||
if (err instanceof error_1.PrefixedFirebaseError) {
|
||||
return err;
|
||||
}
|
||||
var response = err.response;
|
||||
if (!response.isJson()) {
|
||||
return new FirebaseRemoteConfigError('unknown-error', "Unexpected response with status: " + response.status + " and body: " + response.text);
|
||||
}
|
||||
var error = response.data.error || {};
|
||||
var code = 'unknown-error';
|
||||
if (error.status && error.status in ERROR_CODE_MAPPING) {
|
||||
code = ERROR_CODE_MAPPING[error.status];
|
||||
}
|
||||
var message = error.message || "Unknown server error: " + response.text;
|
||||
return new FirebaseRemoteConfigError(code, message);
|
||||
};
|
||||
/**
|
||||
* Creates a RemoteConfigTemplate from the API response.
|
||||
* If provided, customEtag is used instead of the etag returned in the API response.
|
||||
*
|
||||
* @param {HttpResponse} resp API response object.
|
||||
* @param {string} customEtag A custom etag to replace the etag fom the API response (Optional).
|
||||
*/
|
||||
RemoteConfigApiClient.prototype.toRemoteConfigTemplate = function (resp, customEtag) {
|
||||
var etag = (typeof customEtag == 'undefined') ? resp.headers['etag'] : customEtag;
|
||||
this.validateEtag(etag);
|
||||
return {
|
||||
conditions: resp.data.conditions,
|
||||
parameters: resp.data.parameters,
|
||||
parameterGroups: resp.data.parameterGroups,
|
||||
etag: etag,
|
||||
version: resp.data.version,
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Checks if the given RemoteConfigTemplate object is valid.
|
||||
* The object must have valid parameters, parameter groups, conditions, and an etag.
|
||||
* Removes output only properties from version metadata.
|
||||
*
|
||||
* @param {RemoteConfigTemplate} template A RemoteConfigTemplate object to be validated.
|
||||
*
|
||||
* @returns {RemoteConfigTemplate} The validated RemoteConfigTemplate object.
|
||||
*/
|
||||
RemoteConfigApiClient.prototype.validateInputRemoteConfigTemplate = function (template) {
|
||||
var templateCopy = deep_copy_1.deepCopy(template);
|
||||
if (!validator.isNonNullObject(templateCopy)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', "Invalid Remote Config template: " + JSON.stringify(templateCopy));
|
||||
}
|
||||
if (!validator.isNonEmptyString(templateCopy.etag)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'ETag must be a non-empty string.');
|
||||
}
|
||||
if (!validator.isNonNullObject(templateCopy.parameters)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'Remote Config parameters must be a non-null object');
|
||||
}
|
||||
if (!validator.isNonNullObject(templateCopy.parameterGroups)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'Remote Config parameter groups must be a non-null object');
|
||||
}
|
||||
if (!validator.isArray(templateCopy.conditions)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'Remote Config conditions must be an array');
|
||||
}
|
||||
if (typeof templateCopy.version !== 'undefined') {
|
||||
// exclude output only properties and keep the only input property: description
|
||||
templateCopy.version = { description: templateCopy.version.description };
|
||||
}
|
||||
return templateCopy;
|
||||
};
|
||||
/**
|
||||
* Checks if a given version number is valid.
|
||||
* A version number must be an integer or a string in int64 format.
|
||||
* If valid, returns the string representation of the provided version number.
|
||||
*
|
||||
* @param {string|number} versionNumber A version number to be validated.
|
||||
*
|
||||
* @returns {string} The validated version number as a string.
|
||||
*/
|
||||
RemoteConfigApiClient.prototype.validateVersionNumber = function (versionNumber, propertyName) {
|
||||
if (propertyName === void 0) { propertyName = 'versionNumber'; }
|
||||
if (!validator.isNonEmptyString(versionNumber) &&
|
||||
!validator.isNumber(versionNumber)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', propertyName + " must be a non-empty string in int64 format or a number");
|
||||
}
|
||||
if (!Number.isInteger(Number(versionNumber))) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', propertyName + " must be an integer or a string in int64 format");
|
||||
}
|
||||
return versionNumber.toString();
|
||||
};
|
||||
RemoteConfigApiClient.prototype.validateEtag = function (etag) {
|
||||
if (!validator.isNonEmptyString(etag)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'ETag header is not present in the server response.');
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Checks if a given `ListVersionsOptions` object is valid. If successful, creates a copy of the
|
||||
* options object and convert `startTime` and `endTime` to RFC3339 UTC "Zulu" format, if present.
|
||||
*
|
||||
* @param {ListVersionsOptions} options An options object to be validated.
|
||||
*
|
||||
* @returns {ListVersionsOptions} A copy of the provided options object with timestamps converted
|
||||
* to UTC Zulu format.
|
||||
*/
|
||||
RemoteConfigApiClient.prototype.validateListVersionsOptions = function (options) {
|
||||
var optionsCopy = deep_copy_1.deepCopy(options);
|
||||
if (!validator.isNonNullObject(optionsCopy)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'ListVersionsOptions must be a non-null object.');
|
||||
}
|
||||
if (typeof optionsCopy.pageSize !== 'undefined') {
|
||||
if (!validator.isNumber(optionsCopy.pageSize)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'pageSize must be a number.');
|
||||
}
|
||||
if (optionsCopy.pageSize < 1 || optionsCopy.pageSize > 300) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'pageSize must be a number between 1 and 300 (inclusive).');
|
||||
}
|
||||
}
|
||||
if (typeof optionsCopy.pageToken !== 'undefined' && !validator.isNonEmptyString(optionsCopy.pageToken)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'pageToken must be a string value.');
|
||||
}
|
||||
if (typeof optionsCopy.endVersionNumber !== 'undefined') {
|
||||
optionsCopy.endVersionNumber = this.validateVersionNumber(optionsCopy.endVersionNumber, 'endVersionNumber');
|
||||
}
|
||||
if (typeof optionsCopy.startTime !== 'undefined') {
|
||||
if (!(optionsCopy.startTime instanceof Date) && !validator.isUTCDateString(optionsCopy.startTime)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'startTime must be a valid Date object or a UTC date string.');
|
||||
}
|
||||
// Convert startTime to RFC3339 UTC "Zulu" format.
|
||||
if (optionsCopy.startTime instanceof Date) {
|
||||
optionsCopy.startTime = optionsCopy.startTime.toISOString();
|
||||
}
|
||||
else {
|
||||
optionsCopy.startTime = new Date(optionsCopy.startTime).toISOString();
|
||||
}
|
||||
}
|
||||
if (typeof optionsCopy.endTime !== 'undefined') {
|
||||
if (!(optionsCopy.endTime instanceof Date) && !validator.isUTCDateString(optionsCopy.endTime)) {
|
||||
throw new FirebaseRemoteConfigError('invalid-argument', 'endTime must be a valid Date object or a UTC date string.');
|
||||
}
|
||||
// Convert endTime to RFC3339 UTC "Zulu" format.
|
||||
if (optionsCopy.endTime instanceof Date) {
|
||||
optionsCopy.endTime = optionsCopy.endTime.toISOString();
|
||||
}
|
||||
else {
|
||||
optionsCopy.endTime = new Date(optionsCopy.endTime).toISOString();
|
||||
}
|
||||
}
|
||||
// Remove undefined fields from optionsCopy
|
||||
Object.keys(optionsCopy).forEach(function (key) {
|
||||
return (typeof optionsCopy[key] === 'undefined') && delete optionsCopy[key];
|
||||
});
|
||||
return optionsCopy;
|
||||
};
|
||||
return RemoteConfigApiClient;
|
||||
}());
|
||||
exports.RemoteConfigApiClient = RemoteConfigApiClient;
|
||||
var ERROR_CODE_MAPPING = {
|
||||
ABORTED: 'aborted',
|
||||
ALREADY_EXISTS: 'already-exists',
|
||||
INVALID_ARGUMENT: 'invalid-argument',
|
||||
INTERNAL: 'internal-error',
|
||||
FAILED_PRECONDITION: 'failed-precondition',
|
||||
NOT_FOUND: 'not-found',
|
||||
OUT_OF_RANGE: 'out-of-range',
|
||||
PERMISSION_DENIED: 'permission-denied',
|
||||
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
||||
UNAUTHENTICATED: 'unauthenticated',
|
||||
UNKNOWN: 'unknown-error',
|
||||
};
|
||||
/**
|
||||
* Firebase Remote Config error code structure. This extends PrefixedFirebaseError.
|
||||
*
|
||||
* @param {RemoteConfigErrorCode} code The error code.
|
||||
* @param {string} message The error message.
|
||||
* @constructor
|
||||
*/
|
||||
var FirebaseRemoteConfigError = /** @class */ (function (_super) {
|
||||
__extends(FirebaseRemoteConfigError, _super);
|
||||
function FirebaseRemoteConfigError(code, message) {
|
||||
return _super.call(this, 'remote-config', code, message) || this;
|
||||
}
|
||||
return FirebaseRemoteConfigError;
|
||||
}(error_1.PrefixedFirebaseError));
|
||||
exports.FirebaseRemoteConfigError = FirebaseRemoteConfigError;
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* Colors that are associated with conditions for display purposes.
|
||||
*/
|
||||
export declare type TagColor = 'BLUE' | 'BROWN' | 'CYAN' | 'DEEP_ORANGE' | 'GREEN' | 'INDIGO' | 'LIME' | 'ORANGE' | 'PINK' | 'PURPLE' | 'TEAL';
|
||||
/**
|
||||
* Type representing a Remote Config parameter value data type.
|
||||
* Defaults to `STRING` if unspecified.
|
||||
*/
|
||||
export declare type ParameterValueType = 'STRING' | 'BOOLEAN' | 'NUMBER' | 'JSON';
|
||||
/**
|
||||
* Interface representing a Remote Config condition.
|
||||
* A condition targets a specific group of users. A list of these conditions make up
|
||||
* part of a Remote Config template.
|
||||
*/
|
||||
export interface RemoteConfigCondition {
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* The color associated with this condition for display purposes in the Firebase Console.
|
||||
* Not specifying this value results in the console picking an arbitrary color to associate
|
||||
* with the condition.
|
||||
*/
|
||||
tagColor?: TagColor;
|
||||
}
|
||||
/**
|
||||
* Interface representing an explicit parameter value.
|
||||
*/
|
||||
export interface ExplicitParameterValue {
|
||||
/**
|
||||
* The `string` value that the parameter is set to.
|
||||
*/
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* Interface representing an in-app-default value.
|
||||
*/
|
||||
export interface InAppDefaultValue {
|
||||
/**
|
||||
* If `true`, the parameter is omitted from the parameter values returned to a client.
|
||||
*/
|
||||
useInAppDefault: boolean;
|
||||
}
|
||||
/**
|
||||
* Type representing a Remote Config parameter value.
|
||||
* A `RemoteConfigParameterValue` could be either an `ExplicitParameterValue` or
|
||||
* an `InAppDefaultValue`.
|
||||
*/
|
||||
export declare type RemoteConfigParameterValue = ExplicitParameterValue | InAppDefaultValue;
|
||||
/**
|
||||
* Interface representing a Remote Config parameter.
|
||||
* At minimum, a `defaultValue` or a `conditionalValues` entry must be present for the
|
||||
* parameter to have any effect.
|
||||
*/
|
||||
export interface RemoteConfigParameter {
|
||||
/**
|
||||
* The value to set the parameter to, when none of the named conditions evaluate to `true`.
|
||||
*/
|
||||
defaultValue?: RemoteConfigParameterValue;
|
||||
/**
|
||||
* A `(condition name, value)` map. The condition name of the highest priority
|
||||
* (the one listed first in the Remote Config template's conditions list) determines the value of
|
||||
* this parameter.
|
||||
*/
|
||||
conditionalValues?: {
|
||||
[key: string]: RemoteConfigParameterValue;
|
||||
};
|
||||
/**
|
||||
* A description for this parameter. Should not be over 100 characters and may contain any
|
||||
* Unicode characters.
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* The data type for all values of this parameter in the current version of the template.
|
||||
* Defaults to `ParameterValueType.STRING` if unspecified.
|
||||
*/
|
||||
valueType?: ParameterValueType;
|
||||
}
|
||||
/**
|
||||
* Interface representing a Remote Config parameter group.
|
||||
* Grouping parameters is only for management purposes and does not affect client-side
|
||||
* fetching of parameter values.
|
||||
*/
|
||||
export interface RemoteConfigParameterGroup {
|
||||
/**
|
||||
* A description for the group. Its length must be less than or equal to 256 characters.
|
||||
* A description may contain any Unicode characters.
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* Map of parameter keys to their optional default values and optional conditional values for
|
||||
* parameters that belong to this group. A parameter only appears once per
|
||||
* Remote Config template. An ungrouped parameter appears at the top level, whereas a
|
||||
* parameter organized within a group appears within its group's map of parameters.
|
||||
*/
|
||||
parameters: {
|
||||
[key: string]: RemoteConfigParameter;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Interface representing a Remote Config template.
|
||||
*/
|
||||
export interface RemoteConfigTemplate {
|
||||
/**
|
||||
* A list of conditions in descending order by priority.
|
||||
*/
|
||||
conditions: RemoteConfigCondition[];
|
||||
/**
|
||||
* Map of parameter keys to their optional default values and optional conditional values.
|
||||
*/
|
||||
parameters: {
|
||||
[key: string]: RemoteConfigParameter;
|
||||
};
|
||||
/**
|
||||
* Map of parameter group names to their parameter group objects.
|
||||
* A group's name is mutable but must be unique among groups in the Remote Config template.
|
||||
* The name is limited to 256 characters and intended to be human-readable. Any Unicode
|
||||
* characters are allowed.
|
||||
*/
|
||||
parameterGroups: {
|
||||
[key: string]: RemoteConfigParameterGroup;
|
||||
};
|
||||
/**
|
||||
* ETag of the current Remote Config template (readonly).
|
||||
*/
|
||||
readonly etag: string;
|
||||
/**
|
||||
* Version information for the current Remote Config template.
|
||||
*/
|
||||
version?: Version;
|
||||
}
|
||||
/**
|
||||
* Interface representing a Remote Config user.
|
||||
*/
|
||||
export interface RemoteConfigUser {
|
||||
/**
|
||||
* Email address. Output only.
|
||||
*/
|
||||
email: string;
|
||||
/**
|
||||
* Display name. Output only.
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* Image URL. Output only.
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
/**
|
||||
* Interface representing a Remote Config template version.
|
||||
* Output only, except for the version description. Contains metadata about a particular
|
||||
* version of the Remote Config template. All fields are set at the time the specified Remote
|
||||
* Config template is published. A version's description field may be specified in
|
||||
* `publishTemplate` calls.
|
||||
*/
|
||||
export interface Version {
|
||||
/**
|
||||
* The version number of a Remote Config template.
|
||||
*/
|
||||
versionNumber?: string;
|
||||
/**
|
||||
* The timestamp of when this version of the Remote Config template was written to the
|
||||
* Remote Config backend.
|
||||
*/
|
||||
updateTime?: string;
|
||||
/**
|
||||
* The origin of the template update action.
|
||||
*/
|
||||
updateOrigin?: ('REMOTE_CONFIG_UPDATE_ORIGIN_UNSPECIFIED' | 'CONSOLE' | 'REST_API' | 'ADMIN_SDK_NODE');
|
||||
/**
|
||||
* The type of the template update action.
|
||||
*/
|
||||
updateType?: ('REMOTE_CONFIG_UPDATE_TYPE_UNSPECIFIED' | 'INCREMENTAL_UPDATE' | 'FORCED_UPDATE' | 'ROLLBACK');
|
||||
/**
|
||||
* Aggregation of all metadata fields about the account that performed the update.
|
||||
*/
|
||||
updateUser?: RemoteConfigUser;
|
||||
/**
|
||||
* The user-provided description of the corresponding Remote Config template.
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* The version number of the Remote Config template that has become the current version
|
||||
* due to a rollback. Only present if this version is the result of a rollback.
|
||||
*/
|
||||
rollbackSource?: string;
|
||||
/**
|
||||
* Indicates whether this Remote Config template was published before version history was
|
||||
* supported.
|
||||
*/
|
||||
isLegacy?: boolean;
|
||||
}
|
||||
/**
|
||||
* Interface representing a list of Remote Config template versions.
|
||||
*/
|
||||
export interface ListVersionsResult {
|
||||
/**
|
||||
* A list of version metadata objects, sorted in reverse chronological order.
|
||||
*/
|
||||
versions: Version[];
|
||||
/**
|
||||
* Token to retrieve the next page of results, or empty if there are no more results
|
||||
* in the list.
|
||||
*/
|
||||
nextPageToken?: string;
|
||||
}
|
||||
/**
|
||||
* Interface representing options for Remote Config list versions operation.
|
||||
*/
|
||||
export interface ListVersionsOptions {
|
||||
/**
|
||||
* The maximum number of items to return per page.
|
||||
*/
|
||||
pageSize?: number;
|
||||
/**
|
||||
* The `nextPageToken` value returned from a previous list versions request, if any.
|
||||
*/
|
||||
pageToken?: string;
|
||||
/**
|
||||
* Specifies the newest version number to include in the results.
|
||||
* If specified, must be greater than zero. Defaults to the newest version.
|
||||
*/
|
||||
endVersionNumber?: string | number;
|
||||
/**
|
||||
* Specifies the earliest update time to include in the results. Any entries updated before this
|
||||
* time are omitted.
|
||||
*/
|
||||
startTime?: Date | string;
|
||||
/**
|
||||
* Specifies the latest update time to include in the results. Any entries updated on or after
|
||||
* this time are omitted.
|
||||
*/
|
||||
endTime?: Date | string;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { ExplicitParameterValue as TExplicitParameterValue, InAppDefaultValue as TInAppDefaultValue, ListVersionsOptions as TListVersionsOptions, ListVersionsResult as TListVersionsResult, ParameterValueType as TParameterValueType, RemoteConfigCondition as TRemoteConfigCondition, RemoteConfigParameter as TRemoteConfigParameter, RemoteConfigParameterGroup as TRemoteConfigParameterGroup, RemoteConfigParameterValue as TRemoteConfigParameterValue, RemoteConfigTemplate as TRemoteConfigTemplate, RemoteConfigUser as TRemoteConfigUser, TagColor as TTagColor, Version as TVersion } from './remote-config-api';
|
||||
import { RemoteConfig as TRemoteConfig } from './remote-config';
|
||||
/**
|
||||
* Gets the {@link firebase-admin.remote-config#RemoteConfig} service for the
|
||||
* default app or a given app.
|
||||
*
|
||||
* `admin.remoteConfig()` can be called with no arguments to access the default
|
||||
* app's `RemoteConfig` service or as `admin.remoteConfig(app)` to access the
|
||||
* `RemoteConfig` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the `RemoteConfig` service for the default app
|
||||
* var defaultRemoteConfig = admin.remoteConfig();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the `RemoteConfig` service for a given app
|
||||
* var otherRemoteConfig = admin.remoteConfig(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app for which to return the `RemoteConfig` service.
|
||||
* If not provided, the default `RemoteConfig` service is returned.
|
||||
*
|
||||
* @returns The default `RemoteConfig` service if no
|
||||
* app is provided, or the `RemoteConfig` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
export declare function remoteConfig(app?: App): remoteConfig.RemoteConfig;
|
||||
export declare namespace remoteConfig {
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#ExplicitParameterValue}.
|
||||
*/
|
||||
type ExplicitParameterValue = TExplicitParameterValue;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#InAppDefaultValue}.
|
||||
*/
|
||||
type InAppDefaultValue = TInAppDefaultValue;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#ListVersionsOptions}.
|
||||
*/
|
||||
type ListVersionsOptions = TListVersionsOptions;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#ListVersionsResult}.
|
||||
*/
|
||||
type ListVersionsResult = TListVersionsResult;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#ParameterValueType}.
|
||||
*/
|
||||
type ParameterValueType = TParameterValueType;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfig}.
|
||||
*/
|
||||
type RemoteConfig = TRemoteConfig;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfigCondition}.
|
||||
*/
|
||||
type RemoteConfigCondition = TRemoteConfigCondition;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfigParameter}.
|
||||
*/
|
||||
type RemoteConfigParameter = TRemoteConfigParameter;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfigParameterGroup}.
|
||||
*/
|
||||
type RemoteConfigParameterGroup = TRemoteConfigParameterGroup;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfigParameterValue}.
|
||||
*/
|
||||
type RemoteConfigParameterValue = TRemoteConfigParameterValue;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfigTemplate}.
|
||||
*/
|
||||
type RemoteConfigTemplate = TRemoteConfigTemplate;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#RemoteConfigUser}.
|
||||
*/
|
||||
type RemoteConfigUser = TRemoteConfigUser;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#TagColor}.
|
||||
*/
|
||||
type TagColor = TTagColor;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.remote-config#Version}.
|
||||
*/
|
||||
type Version = TVersion;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2021 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { ListVersionsOptions, ListVersionsResult, RemoteConfigTemplate } from './remote-config-api';
|
||||
/**
|
||||
* The Firebase `RemoteConfig` service interface.
|
||||
*/
|
||||
export declare class RemoteConfig {
|
||||
readonly app: App;
|
||||
private readonly client;
|
||||
/**
|
||||
* Gets the current active version of the {@link RemoteConfigTemplate} of the project.
|
||||
*
|
||||
* @returns A promise that fulfills with a `RemoteConfigTemplate`.
|
||||
*/
|
||||
getTemplate(): Promise<RemoteConfigTemplate>;
|
||||
/**
|
||||
* Gets the requested version of the {@link RemoteConfigTemplate} of the project.
|
||||
*
|
||||
* @param versionNumber - Version number of the Remote Config template to look up.
|
||||
*
|
||||
* @returns A promise that fulfills with a `RemoteConfigTemplate`.
|
||||
*/
|
||||
getTemplateAtVersion(versionNumber: number | string): Promise<RemoteConfigTemplate>;
|
||||
/**
|
||||
* Validates a {@link RemoteConfigTemplate}.
|
||||
*
|
||||
* @param template - The Remote Config template to be validated.
|
||||
* @returns A promise that fulfills with the validated `RemoteConfigTemplate`.
|
||||
*/
|
||||
validateTemplate(template: RemoteConfigTemplate): Promise<RemoteConfigTemplate>;
|
||||
/**
|
||||
* Publishes a Remote Config template.
|
||||
*
|
||||
* @param template - The Remote Config template to be published.
|
||||
* @param options - Optional options object when publishing a Remote Config template:
|
||||
* - `force`: Setting this to `true` forces the Remote Config template to
|
||||
* be updated and circumvent the ETag. This approach is not recommended
|
||||
* because it risks causing the loss of updates to your Remote Config
|
||||
* template if multiple clients are updating the Remote Config template.
|
||||
* See {@link https://firebase.google.com/docs/remote-config/use-config-rest#etag_usage_and_forced_updates |
|
||||
* ETag usage and forced updates}.
|
||||
*
|
||||
* @returns A Promise that fulfills with the published `RemoteConfigTemplate`.
|
||||
*/
|
||||
publishTemplate(template: RemoteConfigTemplate, options?: {
|
||||
force: boolean;
|
||||
}): Promise<RemoteConfigTemplate>;
|
||||
/**
|
||||
* Rolls back a project's published Remote Config template to the specified version.
|
||||
* A rollback is equivalent to getting a previously published Remote Config
|
||||
* template and re-publishing it using a force update.
|
||||
*
|
||||
* @param versionNumber - The version number of the Remote Config template to roll back to.
|
||||
* The specified version number must be lower than the current version number, and not have
|
||||
* been deleted due to staleness. Only the last 300 versions are stored.
|
||||
* All versions that correspond to non-active Remote Config templates (that is, all except the
|
||||
* template that is being fetched by clients) are also deleted if they are more than 90 days old.
|
||||
* @returns A promise that fulfills with the published `RemoteConfigTemplate`.
|
||||
*/
|
||||
rollback(versionNumber: number | string): Promise<RemoteConfigTemplate>;
|
||||
/**
|
||||
* Gets a list of Remote Config template versions that have been published, sorted in reverse
|
||||
* chronological order. Only the last 300 versions are stored.
|
||||
* All versions that correspond to non-active Remote Config templates (i.e., all except the
|
||||
* template that is being fetched by clients) are also deleted if they are older than 90 days.
|
||||
*
|
||||
* @param options - Optional options object for getting a list of versions.
|
||||
* @returns A promise that fulfills with a `ListVersionsResult`.
|
||||
*/
|
||||
listVersions(options?: ListVersionsOptions): Promise<ListVersionsResult>;
|
||||
/**
|
||||
* Creates and returns a new Remote Config template from a JSON string.
|
||||
*
|
||||
* @param json - The JSON string to populate a Remote Config template.
|
||||
*
|
||||
* @returns A new template instance.
|
||||
*/
|
||||
createTemplateFromJSON(json: string): RemoteConfigTemplate;
|
||||
}
|
||||
+305
@@ -0,0 +1,305 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RemoteConfig = void 0;
|
||||
var validator = require("../utils/validator");
|
||||
var remote_config_api_client_internal_1 = require("./remote-config-api-client-internal");
|
||||
/**
|
||||
* The Firebase `RemoteConfig` service interface.
|
||||
*/
|
||||
var RemoteConfig = /** @class */ (function () {
|
||||
/**
|
||||
* @param app - The app for this RemoteConfig service.
|
||||
* @constructor
|
||||
* @internal
|
||||
*/
|
||||
function RemoteConfig(app) {
|
||||
this.app = app;
|
||||
this.client = new remote_config_api_client_internal_1.RemoteConfigApiClient(app);
|
||||
}
|
||||
/**
|
||||
* Gets the current active version of the {@link RemoteConfigTemplate} of the project.
|
||||
*
|
||||
* @returns A promise that fulfills with a `RemoteConfigTemplate`.
|
||||
*/
|
||||
RemoteConfig.prototype.getTemplate = function () {
|
||||
return this.client.getTemplate()
|
||||
.then(function (templateResponse) {
|
||||
return new RemoteConfigTemplateImpl(templateResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the requested version of the {@link RemoteConfigTemplate} of the project.
|
||||
*
|
||||
* @param versionNumber - Version number of the Remote Config template to look up.
|
||||
*
|
||||
* @returns A promise that fulfills with a `RemoteConfigTemplate`.
|
||||
*/
|
||||
RemoteConfig.prototype.getTemplateAtVersion = function (versionNumber) {
|
||||
return this.client.getTemplateAtVersion(versionNumber)
|
||||
.then(function (templateResponse) {
|
||||
return new RemoteConfigTemplateImpl(templateResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Validates a {@link RemoteConfigTemplate}.
|
||||
*
|
||||
* @param template - The Remote Config template to be validated.
|
||||
* @returns A promise that fulfills with the validated `RemoteConfigTemplate`.
|
||||
*/
|
||||
RemoteConfig.prototype.validateTemplate = function (template) {
|
||||
return this.client.validateTemplate(template)
|
||||
.then(function (templateResponse) {
|
||||
return new RemoteConfigTemplateImpl(templateResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Publishes a Remote Config template.
|
||||
*
|
||||
* @param template - The Remote Config template to be published.
|
||||
* @param options - Optional options object when publishing a Remote Config template:
|
||||
* - `force`: Setting this to `true` forces the Remote Config template to
|
||||
* be updated and circumvent the ETag. This approach is not recommended
|
||||
* because it risks causing the loss of updates to your Remote Config
|
||||
* template if multiple clients are updating the Remote Config template.
|
||||
* See {@link https://firebase.google.com/docs/remote-config/use-config-rest#etag_usage_and_forced_updates |
|
||||
* ETag usage and forced updates}.
|
||||
*
|
||||
* @returns A Promise that fulfills with the published `RemoteConfigTemplate`.
|
||||
*/
|
||||
RemoteConfig.prototype.publishTemplate = function (template, options) {
|
||||
return this.client.publishTemplate(template, options)
|
||||
.then(function (templateResponse) {
|
||||
return new RemoteConfigTemplateImpl(templateResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Rolls back a project's published Remote Config template to the specified version.
|
||||
* A rollback is equivalent to getting a previously published Remote Config
|
||||
* template and re-publishing it using a force update.
|
||||
*
|
||||
* @param versionNumber - The version number of the Remote Config template to roll back to.
|
||||
* The specified version number must be lower than the current version number, and not have
|
||||
* been deleted due to staleness. Only the last 300 versions are stored.
|
||||
* All versions that correspond to non-active Remote Config templates (that is, all except the
|
||||
* template that is being fetched by clients) are also deleted if they are more than 90 days old.
|
||||
* @returns A promise that fulfills with the published `RemoteConfigTemplate`.
|
||||
*/
|
||||
RemoteConfig.prototype.rollback = function (versionNumber) {
|
||||
return this.client.rollback(versionNumber)
|
||||
.then(function (templateResponse) {
|
||||
return new RemoteConfigTemplateImpl(templateResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets a list of Remote Config template versions that have been published, sorted in reverse
|
||||
* chronological order. Only the last 300 versions are stored.
|
||||
* All versions that correspond to non-active Remote Config templates (i.e., all except the
|
||||
* template that is being fetched by clients) are also deleted if they are older than 90 days.
|
||||
*
|
||||
* @param options - Optional options object for getting a list of versions.
|
||||
* @returns A promise that fulfills with a `ListVersionsResult`.
|
||||
*/
|
||||
RemoteConfig.prototype.listVersions = function (options) {
|
||||
return this.client.listVersions(options)
|
||||
.then(function (listVersionsResponse) {
|
||||
var _a, _b;
|
||||
return {
|
||||
versions: (_b = (_a = listVersionsResponse.versions) === null || _a === void 0 ? void 0 : _a.map(function (version) { return new VersionImpl(version); })) !== null && _b !== void 0 ? _b : [],
|
||||
nextPageToken: listVersionsResponse.nextPageToken,
|
||||
};
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Creates and returns a new Remote Config template from a JSON string.
|
||||
*
|
||||
* @param json - The JSON string to populate a Remote Config template.
|
||||
*
|
||||
* @returns A new template instance.
|
||||
*/
|
||||
RemoteConfig.prototype.createTemplateFromJSON = function (json) {
|
||||
if (!validator.isNonEmptyString(json)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'JSON string must be a valid non-empty string');
|
||||
}
|
||||
var template;
|
||||
try {
|
||||
template = JSON.parse(json);
|
||||
}
|
||||
catch (e) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', "Failed to parse the JSON string: " + json + ". " + e);
|
||||
}
|
||||
return new RemoteConfigTemplateImpl(template);
|
||||
};
|
||||
return RemoteConfig;
|
||||
}());
|
||||
exports.RemoteConfig = RemoteConfig;
|
||||
/**
|
||||
* Remote Config template internal implementation.
|
||||
*/
|
||||
var RemoteConfigTemplateImpl = /** @class */ (function () {
|
||||
function RemoteConfigTemplateImpl(config) {
|
||||
if (!validator.isNonNullObject(config) ||
|
||||
!validator.isNonEmptyString(config.etag)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', "Invalid Remote Config template: " + JSON.stringify(config));
|
||||
}
|
||||
this.etagInternal = config.etag;
|
||||
if (typeof config.parameters !== 'undefined') {
|
||||
if (!validator.isNonNullObject(config.parameters)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Remote Config parameters must be a non-null object');
|
||||
}
|
||||
this.parameters = config.parameters;
|
||||
}
|
||||
else {
|
||||
this.parameters = {};
|
||||
}
|
||||
if (typeof config.parameterGroups !== 'undefined') {
|
||||
if (!validator.isNonNullObject(config.parameterGroups)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Remote Config parameter groups must be a non-null object');
|
||||
}
|
||||
this.parameterGroups = config.parameterGroups;
|
||||
}
|
||||
else {
|
||||
this.parameterGroups = {};
|
||||
}
|
||||
if (typeof config.conditions !== 'undefined') {
|
||||
if (!validator.isArray(config.conditions)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Remote Config conditions must be an array');
|
||||
}
|
||||
this.conditions = config.conditions;
|
||||
}
|
||||
else {
|
||||
this.conditions = [];
|
||||
}
|
||||
if (typeof config.version !== 'undefined') {
|
||||
this.version = new VersionImpl(config.version);
|
||||
}
|
||||
}
|
||||
Object.defineProperty(RemoteConfigTemplateImpl.prototype, "etag", {
|
||||
/**
|
||||
* Gets the ETag of the template.
|
||||
*
|
||||
* @returns The ETag of the Remote Config template.
|
||||
*/
|
||||
get: function () {
|
||||
return this.etagInternal;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* Returns a JSON-serializable representation of this object.
|
||||
*
|
||||
* @returns A JSON-serializable representation of this object.
|
||||
*/
|
||||
RemoteConfigTemplateImpl.prototype.toJSON = function () {
|
||||
return {
|
||||
conditions: this.conditions,
|
||||
parameters: this.parameters,
|
||||
parameterGroups: this.parameterGroups,
|
||||
etag: this.etag,
|
||||
version: this.version,
|
||||
};
|
||||
};
|
||||
return RemoteConfigTemplateImpl;
|
||||
}());
|
||||
/**
|
||||
* Remote Config Version internal implementation.
|
||||
*/
|
||||
var VersionImpl = /** @class */ (function () {
|
||||
function VersionImpl(version) {
|
||||
if (!validator.isNonNullObject(version)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', "Invalid Remote Config version instance: " + JSON.stringify(version));
|
||||
}
|
||||
if (typeof version.versionNumber !== 'undefined') {
|
||||
if (!validator.isNonEmptyString(version.versionNumber) &&
|
||||
!validator.isNumber(version.versionNumber)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version number must be a non-empty string in int64 format or a number');
|
||||
}
|
||||
if (!Number.isInteger(Number(version.versionNumber))) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version number must be an integer or a string in int64 format');
|
||||
}
|
||||
this.versionNumber = version.versionNumber;
|
||||
}
|
||||
if (typeof version.updateOrigin !== 'undefined') {
|
||||
if (!validator.isNonEmptyString(version.updateOrigin)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version update origin must be a non-empty string');
|
||||
}
|
||||
this.updateOrigin = version.updateOrigin;
|
||||
}
|
||||
if (typeof version.updateType !== 'undefined') {
|
||||
if (!validator.isNonEmptyString(version.updateType)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version update type must be a non-empty string');
|
||||
}
|
||||
this.updateType = version.updateType;
|
||||
}
|
||||
if (typeof version.updateUser !== 'undefined') {
|
||||
if (!validator.isNonNullObject(version.updateUser)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version update user must be a non-null object');
|
||||
}
|
||||
this.updateUser = version.updateUser;
|
||||
}
|
||||
if (typeof version.description !== 'undefined') {
|
||||
if (!validator.isNonEmptyString(version.description)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version description must be a non-empty string');
|
||||
}
|
||||
this.description = version.description;
|
||||
}
|
||||
if (typeof version.rollbackSource !== 'undefined') {
|
||||
if (!validator.isNonEmptyString(version.rollbackSource)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version rollback source must be a non-empty string');
|
||||
}
|
||||
this.rollbackSource = version.rollbackSource;
|
||||
}
|
||||
if (typeof version.isLegacy !== 'undefined') {
|
||||
if (!validator.isBoolean(version.isLegacy)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version.isLegacy must be a boolean');
|
||||
}
|
||||
this.isLegacy = version.isLegacy;
|
||||
}
|
||||
// The backend API provides timestamps in ISO date strings. The Admin SDK exposes timestamps
|
||||
// in UTC date strings. If a developer uses a previously obtained template with UTC timestamps
|
||||
// we could still validate it below.
|
||||
if (typeof version.updateTime !== 'undefined') {
|
||||
if (!this.isValidTimestamp(version.updateTime)) {
|
||||
throw new remote_config_api_client_internal_1.FirebaseRemoteConfigError('invalid-argument', 'Version update time must be a valid date string');
|
||||
}
|
||||
this.updateTime = new Date(version.updateTime).toUTCString();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @returns A JSON-serializable representation of this object.
|
||||
*/
|
||||
VersionImpl.prototype.toJSON = function () {
|
||||
return {
|
||||
versionNumber: this.versionNumber,
|
||||
updateOrigin: this.updateOrigin,
|
||||
updateType: this.updateType,
|
||||
updateUser: this.updateUser,
|
||||
description: this.description,
|
||||
rollbackSource: this.rollbackSource,
|
||||
isLegacy: this.isLegacy,
|
||||
updateTime: this.updateTime,
|
||||
};
|
||||
};
|
||||
VersionImpl.prototype.isValidTimestamp = function (timestamp) {
|
||||
// This validation fails for timestamps earlier than January 1, 1970 and considers strings
|
||||
// such as "1.2" as valid timestamps.
|
||||
return validator.isNonEmptyString(timestamp) && (new Date(timestamp)).getTime() > 0;
|
||||
};
|
||||
return VersionImpl;
|
||||
}());
|
||||
Reference in New Issue
Block a user