Initial commit
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
/*! 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.
|
||||
*/
|
||||
/**
|
||||
* Security Rules for Cloud Firestore and Cloud Storage.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { SecurityRules } from './security-rules';
|
||||
export { RulesFile, Ruleset, RulesetMetadata, RulesetMetadataList, SecurityRules, } from './security-rules';
|
||||
/**
|
||||
* Gets the {@link SecurityRules} service for the default app or a given app.
|
||||
*
|
||||
* `admin.securityRules()` can be called with no arguments to access the
|
||||
* default app's `SecurityRules` service, or as `admin.securityRules(app)` to access
|
||||
* the `SecurityRules` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the SecurityRules service for the default app
|
||||
* const defaultSecurityRules = getSecurityRules();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the SecurityRules service for a given app
|
||||
* const otherSecurityRules = getSecurityRules(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app to return the `SecurityRules` service
|
||||
* for. If not provided, the default `SecurityRules` service
|
||||
* is returned.
|
||||
* @returns The default `SecurityRules` service if no app is provided, or the
|
||||
* `SecurityRules` service associated with the provided app.
|
||||
*/
|
||||
export declare function getSecurityRules(app?: App): SecurityRules;
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*! 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.getSecurityRules = void 0;
|
||||
/**
|
||||
* Security Rules for Cloud Firestore and Cloud Storage.
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
var app_1 = require("../app");
|
||||
var security_rules_1 = require("./security-rules");
|
||||
var security_rules_2 = require("./security-rules");
|
||||
Object.defineProperty(exports, "Ruleset", { enumerable: true, get: function () { return security_rules_2.Ruleset; } });
|
||||
Object.defineProperty(exports, "RulesetMetadataList", { enumerable: true, get: function () { return security_rules_2.RulesetMetadataList; } });
|
||||
Object.defineProperty(exports, "SecurityRules", { enumerable: true, get: function () { return security_rules_2.SecurityRules; } });
|
||||
/**
|
||||
* Gets the {@link SecurityRules} service for the default app or a given app.
|
||||
*
|
||||
* `admin.securityRules()` can be called with no arguments to access the
|
||||
* default app's `SecurityRules` service, or as `admin.securityRules(app)` to access
|
||||
* the `SecurityRules` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the SecurityRules service for the default app
|
||||
* const defaultSecurityRules = getSecurityRules();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the SecurityRules service for a given app
|
||||
* const otherSecurityRules = getSecurityRules(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app to return the `SecurityRules` service
|
||||
* for. If not provided, the default `SecurityRules` service
|
||||
* is returned.
|
||||
* @returns The default `SecurityRules` service if no app is provided, or the
|
||||
* `SecurityRules` service associated with the provided app.
|
||||
*/
|
||||
function getSecurityRules(app) {
|
||||
if (typeof app === 'undefined') {
|
||||
app = app_1.getApp();
|
||||
}
|
||||
var firebaseApp = app;
|
||||
return firebaseApp.getOrInitService('securityRules', function (app) { return new security_rules_1.SecurityRules(app); });
|
||||
}
|
||||
exports.getSecurityRules = getSecurityRules;
|
||||
Generated
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2019 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';
|
||||
export interface Release {
|
||||
readonly name: string;
|
||||
readonly rulesetName: string;
|
||||
readonly createTime?: string;
|
||||
readonly updateTime?: string;
|
||||
}
|
||||
export interface RulesetContent {
|
||||
readonly source: {
|
||||
readonly files: Array<{
|
||||
name: string;
|
||||
content: string;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
export interface RulesetResponse extends RulesetContent {
|
||||
readonly name: string;
|
||||
readonly createTime: string;
|
||||
}
|
||||
export interface ListRulesetsResponse {
|
||||
readonly rulesets: Array<{
|
||||
name: string;
|
||||
createTime: string;
|
||||
}>;
|
||||
readonly nextPageToken?: string;
|
||||
}
|
||||
/**
|
||||
* Class that facilitates sending requests to the Firebase security rules backend API.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
export declare class SecurityRulesApiClient {
|
||||
private readonly app;
|
||||
private readonly httpClient;
|
||||
private projectIdPrefix?;
|
||||
constructor(app: App);
|
||||
getRuleset(name: string): Promise<RulesetResponse>;
|
||||
createRuleset(ruleset: RulesetContent): Promise<RulesetResponse>;
|
||||
deleteRuleset(name: string): Promise<void>;
|
||||
listRulesets(pageSize?: number, pageToken?: string): Promise<ListRulesetsResponse>;
|
||||
getRelease(name: string): Promise<Release>;
|
||||
updateRelease(name: string, rulesetName: string): Promise<Release>;
|
||||
private getUrl;
|
||||
private getProjectIdPrefix;
|
||||
/**
|
||||
* Gets the specified resource from the rules API. Resource names must be the short names without project
|
||||
* ID prefix (e.g. `rulesets/ruleset-name`).
|
||||
*
|
||||
* @param {string} name Full qualified name of the resource to get.
|
||||
* @returns {Promise<T>} A promise that fulfills with the resource.
|
||||
*/
|
||||
private getResource;
|
||||
private getReleaseDescription;
|
||||
private getRulesetName;
|
||||
private sendRequest;
|
||||
private toFirebaseError;
|
||||
}
|
||||
Generated
Vendored
+237
@@ -0,0 +1,237 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2019 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.SecurityRulesApiClient = void 0;
|
||||
var api_request_1 = require("../utils/api-request");
|
||||
var error_1 = require("../utils/error");
|
||||
var security_rules_internal_1 = require("./security-rules-internal");
|
||||
var utils = require("../utils/index");
|
||||
var validator = require("../utils/validator");
|
||||
var RULES_V1_API = 'https://firebaserules.googleapis.com/v1';
|
||||
var FIREBASE_VERSION_HEADER = {
|
||||
'X-Firebase-Client': "fire-admin-node/" + utils.getSdkVersion(),
|
||||
};
|
||||
/**
|
||||
* Class that facilitates sending requests to the Firebase security rules backend API.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
var SecurityRulesApiClient = /** @class */ (function () {
|
||||
function SecurityRulesApiClient(app) {
|
||||
this.app = app;
|
||||
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'First argument passed to admin.securityRules() must be a valid Firebase app '
|
||||
+ 'instance.');
|
||||
}
|
||||
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
||||
}
|
||||
SecurityRulesApiClient.prototype.getRuleset = function (name) {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
return _this.getRulesetName(name);
|
||||
})
|
||||
.then(function (rulesetName) {
|
||||
return _this.getResource(rulesetName);
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.createRuleset = function (ruleset) {
|
||||
var _this = this;
|
||||
if (!validator.isNonNullObject(ruleset) ||
|
||||
!validator.isNonNullObject(ruleset.source) ||
|
||||
!validator.isNonEmptyArray(ruleset.source.files)) {
|
||||
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Invalid rules content.');
|
||||
return Promise.reject(err);
|
||||
}
|
||||
for (var _i = 0, _a = ruleset.source.files; _i < _a.length; _i++) {
|
||||
var rf = _a[_i];
|
||||
if (!validator.isNonNullObject(rf) ||
|
||||
!validator.isNonEmptyString(rf.name) ||
|
||||
!validator.isNonEmptyString(rf.content)) {
|
||||
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', "Invalid rules file argument: " + JSON.stringify(rf));
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'POST',
|
||||
url: url + "/rulesets",
|
||||
data: ruleset,
|
||||
};
|
||||
return _this.sendRequest(request);
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.deleteRuleset = function (name) {
|
||||
var _this = this;
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var rulesetName = _this.getRulesetName(name);
|
||||
var request = {
|
||||
method: 'DELETE',
|
||||
url: url + "/" + rulesetName,
|
||||
};
|
||||
return _this.sendRequest(request);
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.listRulesets = function (pageSize, pageToken) {
|
||||
var _this = this;
|
||||
if (pageSize === void 0) { pageSize = 100; }
|
||||
if (!validator.isNumber(pageSize)) {
|
||||
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Invalid page size.');
|
||||
return Promise.reject(err);
|
||||
}
|
||||
if (pageSize < 1 || pageSize > 100) {
|
||||
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Page size must be between 1 and 100.');
|
||||
return Promise.reject(err);
|
||||
}
|
||||
if (typeof pageToken !== 'undefined' && !validator.isNonEmptyString(pageToken)) {
|
||||
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Next page token must be a non-empty string.');
|
||||
return Promise.reject(err);
|
||||
}
|
||||
var data = {
|
||||
pageSize: pageSize,
|
||||
pageToken: pageToken,
|
||||
};
|
||||
if (!pageToken) {
|
||||
delete data.pageToken;
|
||||
}
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'GET',
|
||||
url: url + "/rulesets",
|
||||
data: data,
|
||||
};
|
||||
return _this.sendRequest(request);
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.getRelease = function (name) {
|
||||
return this.getResource("releases/" + name);
|
||||
};
|
||||
SecurityRulesApiClient.prototype.updateRelease = function (name, rulesetName) {
|
||||
var _this = this;
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
return _this.getReleaseDescription(name, rulesetName)
|
||||
.then(function (release) {
|
||||
var request = {
|
||||
method: 'PATCH',
|
||||
url: url + "/releases/" + name,
|
||||
data: { release: release },
|
||||
};
|
||||
return _this.sendRequest(request);
|
||||
});
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.getUrl = function () {
|
||||
return this.getProjectIdPrefix()
|
||||
.then(function (projectIdPrefix) {
|
||||
return RULES_V1_API + "/" + projectIdPrefix;
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.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 security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', '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;
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the specified resource from the rules API. Resource names must be the short names without project
|
||||
* ID prefix (e.g. `rulesets/ruleset-name`).
|
||||
*
|
||||
* @param {string} name Full qualified name of the resource to get.
|
||||
* @returns {Promise<T>} A promise that fulfills with the resource.
|
||||
*/
|
||||
SecurityRulesApiClient.prototype.getResource = function (name) {
|
||||
var _this = this;
|
||||
return this.getUrl()
|
||||
.then(function (url) {
|
||||
var request = {
|
||||
method: 'GET',
|
||||
url: url + "/" + name,
|
||||
};
|
||||
return _this.sendRequest(request);
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.getReleaseDescription = function (name, rulesetName) {
|
||||
var _this = this;
|
||||
return this.getProjectIdPrefix()
|
||||
.then(function (projectIdPrefix) {
|
||||
return {
|
||||
name: projectIdPrefix + "/releases/" + name,
|
||||
rulesetName: projectIdPrefix + "/" + _this.getRulesetName(rulesetName),
|
||||
};
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.getRulesetName = function (name) {
|
||||
if (!validator.isNonEmptyString(name)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Ruleset name must be a non-empty string.');
|
||||
}
|
||||
if (name.indexOf('/') !== -1) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Ruleset name must not contain any "/" characters.');
|
||||
}
|
||||
return "rulesets/" + name;
|
||||
};
|
||||
SecurityRulesApiClient.prototype.sendRequest = function (request) {
|
||||
var _this = this;
|
||||
request.headers = FIREBASE_VERSION_HEADER;
|
||||
return this.httpClient.send(request)
|
||||
.then(function (resp) {
|
||||
return resp.data;
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw _this.toFirebaseError(err);
|
||||
});
|
||||
};
|
||||
SecurityRulesApiClient.prototype.toFirebaseError = function (err) {
|
||||
if (err instanceof error_1.PrefixedFirebaseError) {
|
||||
return err;
|
||||
}
|
||||
var response = err.response;
|
||||
if (!response.isJson()) {
|
||||
return new security_rules_internal_1.FirebaseSecurityRulesError('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 security_rules_internal_1.FirebaseSecurityRulesError(code, message);
|
||||
};
|
||||
return SecurityRulesApiClient;
|
||||
}());
|
||||
exports.SecurityRulesApiClient = SecurityRulesApiClient;
|
||||
var ERROR_CODE_MAPPING = {
|
||||
INVALID_ARGUMENT: 'invalid-argument',
|
||||
NOT_FOUND: 'not-found',
|
||||
RESOURCE_EXHAUSTED: 'resource-exhausted',
|
||||
UNAUTHENTICATED: 'authentication-error',
|
||||
UNKNOWN: 'unknown-error',
|
||||
};
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2019 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 SecurityRulesErrorCode = 'already-exists' | 'authentication-error' | 'internal-error' | 'invalid-argument' | 'invalid-server-response' | 'not-found' | 'resource-exhausted' | 'service-unavailable' | 'unknown-error';
|
||||
export declare class FirebaseSecurityRulesError extends PrefixedFirebaseError {
|
||||
constructor(code: SecurityRulesErrorCode, message: string);
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2019 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 __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FirebaseSecurityRulesError = void 0;
|
||||
var error_1 = require("../utils/error");
|
||||
var FirebaseSecurityRulesError = /** @class */ (function (_super) {
|
||||
__extends(FirebaseSecurityRulesError, _super);
|
||||
function FirebaseSecurityRulesError(code, message) {
|
||||
return _super.call(this, 'security-rules', code, message) || this;
|
||||
}
|
||||
return FirebaseSecurityRulesError;
|
||||
}(error_1.PrefixedFirebaseError));
|
||||
exports.FirebaseSecurityRulesError = FirebaseSecurityRulesError;
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*! 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 { RulesFile as TRulesFile, Ruleset as TRuleset, RulesetMetadata as TRulesetMetadata, RulesetMetadataList as TRulesetMetadataList, SecurityRules as TSecurityRules } from './security-rules';
|
||||
/**
|
||||
* Gets the {@link firebase-admin.security-rules#SecurityRules} service for the default
|
||||
* app or a given app.
|
||||
*
|
||||
* `admin.securityRules()` can be called with no arguments to access the
|
||||
* default app's {@link firebase-admin.security-rules#SecurityRules}
|
||||
* service, or as `admin.securityRules(app)` to access
|
||||
* the {@link firebase-admin.security-rules#SecurityRules}
|
||||
* service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the SecurityRules service for the default app
|
||||
* var defaultSecurityRules = admin.securityRules();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the SecurityRules service for a given app
|
||||
* var otherSecurityRules = admin.securityRules(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app to return the `SecurityRules` service
|
||||
* for. If not provided, the default `SecurityRules` service
|
||||
* is returned.
|
||||
* @returns The default `SecurityRules` service if no app is provided, or the
|
||||
* `SecurityRules` service associated with the provided app.
|
||||
*/
|
||||
export declare function securityRules(app?: App): securityRules.SecurityRules;
|
||||
export declare namespace securityRules {
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.security-rules#RulesFile}.
|
||||
*/
|
||||
type RulesFile = TRulesFile;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.security-rules#Ruleset}.
|
||||
*/
|
||||
type Ruleset = TRuleset;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.security-rules#RulesetMetadata}.
|
||||
*/
|
||||
type RulesetMetadata = TRulesetMetadata;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.security-rules#RulesetMetadataList}.
|
||||
*/
|
||||
type RulesetMetadataList = TRulesetMetadataList;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.security-rules#SecurityRules}.
|
||||
*/
|
||||
type SecurityRules = TSecurityRules;
|
||||
}
|
||||
+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 });
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
/*!
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
/// <reference types="node" />
|
||||
import { App } from '../app';
|
||||
/**
|
||||
* A source file containing some Firebase security rules. The content includes raw
|
||||
* source code including text formatting, indentation and comments. Use the
|
||||
* {@link SecurityRules.createRulesFileFromSource} method to create new instances of this type.
|
||||
*/
|
||||
export interface RulesFile {
|
||||
readonly name: string;
|
||||
readonly content: string;
|
||||
}
|
||||
/**
|
||||
* Required metadata associated with a ruleset.
|
||||
*/
|
||||
export interface RulesetMetadata {
|
||||
/**
|
||||
* Name of the `Ruleset` as a short string. This can be directly passed into APIs
|
||||
* like {@link SecurityRules.getRuleset} and {@link SecurityRules.deleteRuleset}.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* Creation time of the `Ruleset` as a UTC timestamp string.
|
||||
*/
|
||||
readonly createTime: string;
|
||||
}
|
||||
/**
|
||||
* A page of ruleset metadata.
|
||||
*/
|
||||
export declare class RulesetMetadataList {
|
||||
/**
|
||||
* A batch of ruleset metadata.
|
||||
*/
|
||||
readonly rulesets: RulesetMetadata[];
|
||||
/**
|
||||
* The next page token if available. This is needed to retrieve the next batch.
|
||||
*/
|
||||
readonly nextPageToken?: string;
|
||||
}
|
||||
/**
|
||||
* A set of Firebase security rules.
|
||||
*/
|
||||
export declare class Ruleset implements RulesetMetadata {
|
||||
/**
|
||||
* {@inheritdoc RulesetMetadata.name}
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* {@inheritdoc RulesetMetadata.createTime}
|
||||
*/
|
||||
readonly createTime: string;
|
||||
readonly source: RulesFile[];
|
||||
}
|
||||
/**
|
||||
* The Firebase `SecurityRules` service interface.
|
||||
*/
|
||||
export declare class SecurityRules {
|
||||
readonly app: App;
|
||||
private static readonly CLOUD_FIRESTORE;
|
||||
private static readonly FIREBASE_STORAGE;
|
||||
private readonly client;
|
||||
/**
|
||||
* Gets the {@link Ruleset} identified by the given
|
||||
* name. The input name should be the short name string without the project ID
|
||||
* prefix. For example, to retrieve the `projects/project-id/rulesets/my-ruleset`,
|
||||
* pass the short name "my-ruleset". Rejects with a `not-found` error if the
|
||||
* specified `Ruleset` cannot be found.
|
||||
*
|
||||
* @param name - Name of the `Ruleset` to retrieve.
|
||||
* @returns A promise that fulfills with the specified `Ruleset`.
|
||||
*/
|
||||
getRuleset(name: string): Promise<Ruleset>;
|
||||
/**
|
||||
* Gets the {@link Ruleset} currently applied to
|
||||
* Cloud Firestore. Rejects with a `not-found` error if no ruleset is applied
|
||||
* on Firestore.
|
||||
*
|
||||
* @returns A promise that fulfills with the Firestore ruleset.
|
||||
*/
|
||||
getFirestoreRuleset(): Promise<Ruleset>;
|
||||
/**
|
||||
* Creates a new {@link Ruleset} from the given
|
||||
* source, and applies it to Cloud Firestore.
|
||||
*
|
||||
* @param source - Rules source to apply.
|
||||
* @returns A promise that fulfills when the ruleset is created and released.
|
||||
*/
|
||||
releaseFirestoreRulesetFromSource(source: string | Buffer): Promise<Ruleset>;
|
||||
/**
|
||||
* Applies the specified {@link Ruleset} ruleset
|
||||
* to Cloud Firestore.
|
||||
*
|
||||
* @param ruleset - Name of the ruleset to apply or a `RulesetMetadata` object
|
||||
* containing the name.
|
||||
* @returns A promise that fulfills when the ruleset is released.
|
||||
*/
|
||||
releaseFirestoreRuleset(ruleset: string | RulesetMetadata): Promise<void>;
|
||||
/**
|
||||
* Gets the {@link Ruleset} currently applied to a
|
||||
* Cloud Storage bucket. Rejects with a `not-found` error if no ruleset is applied
|
||||
* on the bucket.
|
||||
*
|
||||
* @param bucket - Optional name of the Cloud Storage bucket to be retrieved. If not
|
||||
* specified, retrieves the ruleset applied on the default bucket configured via
|
||||
* `AppOptions`.
|
||||
* @returns A promise that fulfills with the Cloud Storage ruleset.
|
||||
*/
|
||||
getStorageRuleset(bucket?: string): Promise<Ruleset>;
|
||||
/**
|
||||
* Creates a new {@link Ruleset} from the given
|
||||
* source, and applies it to a Cloud Storage bucket.
|
||||
*
|
||||
* @param source - Rules source to apply.
|
||||
* @param bucket - Optional name of the Cloud Storage bucket to apply the rules on. If
|
||||
* not specified, applies the ruleset on the default bucket configured via
|
||||
* {@link firebase-admin.app#AppOptions}.
|
||||
* @returns A promise that fulfills when the ruleset is created and released.
|
||||
*/
|
||||
releaseStorageRulesetFromSource(source: string | Buffer, bucket?: string): Promise<Ruleset>;
|
||||
/**
|
||||
* Applies the specified {@link Ruleset} ruleset
|
||||
* to a Cloud Storage bucket.
|
||||
*
|
||||
* @param ruleset - Name of the ruleset to apply or a `RulesetMetadata` object
|
||||
* containing the name.
|
||||
* @param bucket - Optional name of the Cloud Storage bucket to apply the rules on. If
|
||||
* not specified, applies the ruleset on the default bucket configured via
|
||||
* {@link firebase-admin.app#AppOptions}.
|
||||
* @returns A promise that fulfills when the ruleset is released.
|
||||
*/
|
||||
releaseStorageRuleset(ruleset: string | RulesetMetadata, bucket?: string): Promise<void>;
|
||||
/**
|
||||
* Creates a {@link RulesFile} with the given name
|
||||
* and source. Throws an error if any of the arguments are invalid. This is a local
|
||||
* operation, and does not involve any network API calls.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* const source = '// Some rules source';
|
||||
* const rulesFile = admin.securityRules().createRulesFileFromSource(
|
||||
* 'firestore.rules', source);
|
||||
* ```
|
||||
*
|
||||
* @param name - Name to assign to the rules file. This is usually a short file name that
|
||||
* helps identify the file in a ruleset.
|
||||
* @param source - Contents of the rules file.
|
||||
* @returns A new rules file instance.
|
||||
*/
|
||||
createRulesFileFromSource(name: string, source: string | Buffer): RulesFile;
|
||||
/**
|
||||
* Creates a new {@link Ruleset} from the given {@link RulesFile}.
|
||||
*
|
||||
* @param file - Rules file to include in the new `Ruleset`.
|
||||
* @returns A promise that fulfills with the newly created `Ruleset`.
|
||||
*/
|
||||
createRuleset(file: RulesFile): Promise<Ruleset>;
|
||||
/**
|
||||
* Deletes the {@link Ruleset} identified by the given
|
||||
* name. The input name should be the short name string without the project ID
|
||||
* prefix. For example, to delete the `projects/project-id/rulesets/my-ruleset`,
|
||||
* pass the short name "my-ruleset". Rejects with a `not-found` error if the
|
||||
* specified `Ruleset` cannot be found.
|
||||
*
|
||||
* @param name - Name of the `Ruleset` to delete.
|
||||
* @returns A promise that fulfills when the `Ruleset` is deleted.
|
||||
*/
|
||||
deleteRuleset(name: string): Promise<void>;
|
||||
/**
|
||||
* Retrieves a page of ruleset metadata.
|
||||
*
|
||||
* @param pageSize - The page size, 100 if undefined. This is also the maximum allowed
|
||||
* limit.
|
||||
* @param nextPageToken - The next page token. If not specified, returns rulesets
|
||||
* starting without any offset.
|
||||
* @returns A promise that fulfills with a page of rulesets.
|
||||
*/
|
||||
listRulesetMetadata(pageSize?: number, nextPageToken?: string): Promise<RulesetMetadataList>;
|
||||
private getRulesetForRelease;
|
||||
private releaseRuleset;
|
||||
private getBucketName;
|
||||
}
|
||||
+328
@@ -0,0 +1,328 @@
|
||||
/*! firebase-admin v10.0.1 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2019 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.SecurityRules = exports.Ruleset = exports.RulesetMetadataList = void 0;
|
||||
var validator = require("../utils/validator");
|
||||
var security_rules_api_client_internal_1 = require("./security-rules-api-client-internal");
|
||||
var security_rules_internal_1 = require("./security-rules-internal");
|
||||
/**
|
||||
* A page of ruleset metadata.
|
||||
*/
|
||||
var RulesetMetadataList = /** @class */ (function () {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function RulesetMetadataList(response) {
|
||||
if (!validator.isNonNullObject(response) || !validator.isArray(response.rulesets)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', "Invalid ListRulesets response: " + JSON.stringify(response));
|
||||
}
|
||||
this.rulesets = response.rulesets.map(function (rs) {
|
||||
return {
|
||||
name: stripProjectIdPrefix(rs.name),
|
||||
createTime: new Date(rs.createTime).toUTCString(),
|
||||
};
|
||||
});
|
||||
if (response.nextPageToken) {
|
||||
this.nextPageToken = response.nextPageToken;
|
||||
}
|
||||
}
|
||||
return RulesetMetadataList;
|
||||
}());
|
||||
exports.RulesetMetadataList = RulesetMetadataList;
|
||||
/**
|
||||
* A set of Firebase security rules.
|
||||
*/
|
||||
var Ruleset = /** @class */ (function () {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function Ruleset(ruleset) {
|
||||
if (!validator.isNonNullObject(ruleset) ||
|
||||
!validator.isNonEmptyString(ruleset.name) ||
|
||||
!validator.isNonEmptyString(ruleset.createTime) ||
|
||||
!validator.isNonNullObject(ruleset.source)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', "Invalid Ruleset response: " + JSON.stringify(ruleset));
|
||||
}
|
||||
this.name = stripProjectIdPrefix(ruleset.name);
|
||||
this.createTime = new Date(ruleset.createTime).toUTCString();
|
||||
this.source = ruleset.source.files || [];
|
||||
}
|
||||
return Ruleset;
|
||||
}());
|
||||
exports.Ruleset = Ruleset;
|
||||
/**
|
||||
* The Firebase `SecurityRules` service interface.
|
||||
*/
|
||||
var SecurityRules = /** @class */ (function () {
|
||||
/**
|
||||
* @param app - The app for this SecurityRules service.
|
||||
* @constructor
|
||||
* @internal
|
||||
*/
|
||||
function SecurityRules(app) {
|
||||
this.app = app;
|
||||
this.client = new security_rules_api_client_internal_1.SecurityRulesApiClient(app);
|
||||
}
|
||||
/**
|
||||
* Gets the {@link Ruleset} identified by the given
|
||||
* name. The input name should be the short name string without the project ID
|
||||
* prefix. For example, to retrieve the `projects/project-id/rulesets/my-ruleset`,
|
||||
* pass the short name "my-ruleset". Rejects with a `not-found` error if the
|
||||
* specified `Ruleset` cannot be found.
|
||||
*
|
||||
* @param name - Name of the `Ruleset` to retrieve.
|
||||
* @returns A promise that fulfills with the specified `Ruleset`.
|
||||
*/
|
||||
SecurityRules.prototype.getRuleset = function (name) {
|
||||
return this.client.getRuleset(name)
|
||||
.then(function (rulesetResponse) {
|
||||
return new Ruleset(rulesetResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Gets the {@link Ruleset} currently applied to
|
||||
* Cloud Firestore. Rejects with a `not-found` error if no ruleset is applied
|
||||
* on Firestore.
|
||||
*
|
||||
* @returns A promise that fulfills with the Firestore ruleset.
|
||||
*/
|
||||
SecurityRules.prototype.getFirestoreRuleset = function () {
|
||||
return this.getRulesetForRelease(SecurityRules.CLOUD_FIRESTORE);
|
||||
};
|
||||
/**
|
||||
* Creates a new {@link Ruleset} from the given
|
||||
* source, and applies it to Cloud Firestore.
|
||||
*
|
||||
* @param source - Rules source to apply.
|
||||
* @returns A promise that fulfills when the ruleset is created and released.
|
||||
*/
|
||||
SecurityRules.prototype.releaseFirestoreRulesetFromSource = function (source) {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
var rulesFile = _this.createRulesFileFromSource('firestore.rules', source);
|
||||
return _this.createRuleset(rulesFile);
|
||||
})
|
||||
.then(function (ruleset) {
|
||||
return _this.releaseFirestoreRuleset(ruleset)
|
||||
.then(function () {
|
||||
return ruleset;
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Applies the specified {@link Ruleset} ruleset
|
||||
* to Cloud Firestore.
|
||||
*
|
||||
* @param ruleset - Name of the ruleset to apply or a `RulesetMetadata` object
|
||||
* containing the name.
|
||||
* @returns A promise that fulfills when the ruleset is released.
|
||||
*/
|
||||
SecurityRules.prototype.releaseFirestoreRuleset = function (ruleset) {
|
||||
return this.releaseRuleset(ruleset, SecurityRules.CLOUD_FIRESTORE);
|
||||
};
|
||||
/**
|
||||
* Gets the {@link Ruleset} currently applied to a
|
||||
* Cloud Storage bucket. Rejects with a `not-found` error if no ruleset is applied
|
||||
* on the bucket.
|
||||
*
|
||||
* @param bucket - Optional name of the Cloud Storage bucket to be retrieved. If not
|
||||
* specified, retrieves the ruleset applied on the default bucket configured via
|
||||
* `AppOptions`.
|
||||
* @returns A promise that fulfills with the Cloud Storage ruleset.
|
||||
*/
|
||||
SecurityRules.prototype.getStorageRuleset = function (bucket) {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
return _this.getBucketName(bucket);
|
||||
})
|
||||
.then(function (bucketName) {
|
||||
return _this.getRulesetForRelease(SecurityRules.FIREBASE_STORAGE + "/" + bucketName);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Creates a new {@link Ruleset} from the given
|
||||
* source, and applies it to a Cloud Storage bucket.
|
||||
*
|
||||
* @param source - Rules source to apply.
|
||||
* @param bucket - Optional name of the Cloud Storage bucket to apply the rules on. If
|
||||
* not specified, applies the ruleset on the default bucket configured via
|
||||
* {@link firebase-admin.app#AppOptions}.
|
||||
* @returns A promise that fulfills when the ruleset is created and released.
|
||||
*/
|
||||
SecurityRules.prototype.releaseStorageRulesetFromSource = function (source, bucket) {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
// Bucket name is not required until the last step. But since there's a createRuleset step
|
||||
// before then, make sure to run this check and fail early if the bucket name is invalid.
|
||||
_this.getBucketName(bucket);
|
||||
var rulesFile = _this.createRulesFileFromSource('storage.rules', source);
|
||||
return _this.createRuleset(rulesFile);
|
||||
})
|
||||
.then(function (ruleset) {
|
||||
return _this.releaseStorageRuleset(ruleset, bucket)
|
||||
.then(function () {
|
||||
return ruleset;
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Applies the specified {@link Ruleset} ruleset
|
||||
* to a Cloud Storage bucket.
|
||||
*
|
||||
* @param ruleset - Name of the ruleset to apply or a `RulesetMetadata` object
|
||||
* containing the name.
|
||||
* @param bucket - Optional name of the Cloud Storage bucket to apply the rules on. If
|
||||
* not specified, applies the ruleset on the default bucket configured via
|
||||
* {@link firebase-admin.app#AppOptions}.
|
||||
* @returns A promise that fulfills when the ruleset is released.
|
||||
*/
|
||||
SecurityRules.prototype.releaseStorageRuleset = function (ruleset, bucket) {
|
||||
var _this = this;
|
||||
return Promise.resolve()
|
||||
.then(function () {
|
||||
return _this.getBucketName(bucket);
|
||||
})
|
||||
.then(function (bucketName) {
|
||||
return _this.releaseRuleset(ruleset, SecurityRules.FIREBASE_STORAGE + "/" + bucketName);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Creates a {@link RulesFile} with the given name
|
||||
* and source. Throws an error if any of the arguments are invalid. This is a local
|
||||
* operation, and does not involve any network API calls.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* const source = '// Some rules source';
|
||||
* const rulesFile = admin.securityRules().createRulesFileFromSource(
|
||||
* 'firestore.rules', source);
|
||||
* ```
|
||||
*
|
||||
* @param name - Name to assign to the rules file. This is usually a short file name that
|
||||
* helps identify the file in a ruleset.
|
||||
* @param source - Contents of the rules file.
|
||||
* @returns A new rules file instance.
|
||||
*/
|
||||
SecurityRules.prototype.createRulesFileFromSource = function (name, source) {
|
||||
if (!validator.isNonEmptyString(name)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Name must be a non-empty string.');
|
||||
}
|
||||
var content;
|
||||
if (validator.isNonEmptyString(source)) {
|
||||
content = source;
|
||||
}
|
||||
else if (validator.isBuffer(source)) {
|
||||
content = source.toString('utf-8');
|
||||
}
|
||||
else {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Source must be a non-empty string or a Buffer.');
|
||||
}
|
||||
return {
|
||||
name: name,
|
||||
content: content,
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Creates a new {@link Ruleset} from the given {@link RulesFile}.
|
||||
*
|
||||
* @param file - Rules file to include in the new `Ruleset`.
|
||||
* @returns A promise that fulfills with the newly created `Ruleset`.
|
||||
*/
|
||||
SecurityRules.prototype.createRuleset = function (file) {
|
||||
var ruleset = {
|
||||
source: {
|
||||
files: [file],
|
||||
},
|
||||
};
|
||||
return this.client.createRuleset(ruleset)
|
||||
.then(function (rulesetResponse) {
|
||||
return new Ruleset(rulesetResponse);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Deletes the {@link Ruleset} identified by the given
|
||||
* name. The input name should be the short name string without the project ID
|
||||
* prefix. For example, to delete the `projects/project-id/rulesets/my-ruleset`,
|
||||
* pass the short name "my-ruleset". Rejects with a `not-found` error if the
|
||||
* specified `Ruleset` cannot be found.
|
||||
*
|
||||
* @param name - Name of the `Ruleset` to delete.
|
||||
* @returns A promise that fulfills when the `Ruleset` is deleted.
|
||||
*/
|
||||
SecurityRules.prototype.deleteRuleset = function (name) {
|
||||
return this.client.deleteRuleset(name);
|
||||
};
|
||||
/**
|
||||
* Retrieves a page of ruleset metadata.
|
||||
*
|
||||
* @param pageSize - The page size, 100 if undefined. This is also the maximum allowed
|
||||
* limit.
|
||||
* @param nextPageToken - The next page token. If not specified, returns rulesets
|
||||
* starting without any offset.
|
||||
* @returns A promise that fulfills with a page of rulesets.
|
||||
*/
|
||||
SecurityRules.prototype.listRulesetMetadata = function (pageSize, nextPageToken) {
|
||||
if (pageSize === void 0) { pageSize = 100; }
|
||||
return this.client.listRulesets(pageSize, nextPageToken)
|
||||
.then(function (response) {
|
||||
return new RulesetMetadataList(response);
|
||||
});
|
||||
};
|
||||
SecurityRules.prototype.getRulesetForRelease = function (releaseName) {
|
||||
var _this = this;
|
||||
return this.client.getRelease(releaseName)
|
||||
.then(function (release) {
|
||||
var rulesetName = release.rulesetName;
|
||||
if (!validator.isNonEmptyString(rulesetName)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('not-found', "Ruleset name not found for " + releaseName + ".");
|
||||
}
|
||||
return _this.getRuleset(stripProjectIdPrefix(rulesetName));
|
||||
});
|
||||
};
|
||||
SecurityRules.prototype.releaseRuleset = function (ruleset, releaseName) {
|
||||
if (!validator.isNonEmptyString(ruleset) &&
|
||||
(!validator.isNonNullObject(ruleset) || !validator.isNonEmptyString(ruleset.name))) {
|
||||
var err = new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'ruleset must be a non-empty name or a RulesetMetadata object.');
|
||||
return Promise.reject(err);
|
||||
}
|
||||
var rulesetName = validator.isString(ruleset) ? ruleset : ruleset.name;
|
||||
return this.client.updateRelease(releaseName, rulesetName)
|
||||
.then(function () {
|
||||
return;
|
||||
});
|
||||
};
|
||||
SecurityRules.prototype.getBucketName = function (bucket) {
|
||||
var bucketName = (typeof bucket !== 'undefined') ? bucket : this.app.options.storageBucket;
|
||||
if (!validator.isNonEmptyString(bucketName)) {
|
||||
throw new security_rules_internal_1.FirebaseSecurityRulesError('invalid-argument', 'Bucket name not specified or invalid. Specify a default bucket name via the ' +
|
||||
'storageBucket option when initializing the app, or specify the bucket name ' +
|
||||
'explicitly when calling the rules API.');
|
||||
}
|
||||
return bucketName;
|
||||
};
|
||||
SecurityRules.CLOUD_FIRESTORE = 'cloud.firestore';
|
||||
SecurityRules.FIREBASE_STORAGE = 'firebase.storage';
|
||||
return SecurityRules;
|
||||
}());
|
||||
exports.SecurityRules = SecurityRules;
|
||||
function stripProjectIdPrefix(name) {
|
||||
return name.split('/').pop();
|
||||
}
|
||||
Reference in New Issue
Block a user