The Firebase SecurityRules service interface.

Signature:

export declare class SecurityRules 

Properties

Property Modifiers Type Description
app App

Methods

Method Modifiers Description
createRuleset(file) Creates a new from the given .
createRulesFileFromSource(name, source) Creates a 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.
deleteRuleset(name) Deletes the 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.
getFirestoreRuleset() Gets the currently applied to Cloud Firestore. Rejects with a not-found error if no ruleset is applied on Firestore. A promise that fulfills with the Firestore ruleset.
getRuleset(name) Gets the 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.
getStorageRuleset(bucket) Gets the currently applied to a Cloud Storage bucket. Rejects with a not-found error if no ruleset is applied on the bucket.
listRulesetMetadata(pageSize, nextPageToken) Retrieves a page of ruleset metadata.
releaseFirestoreRuleset(ruleset) Applies the specified ruleset to Cloud Firestore.
releaseFirestoreRulesetFromSource(source) Creates a new from the given source, and applies it to Cloud Firestore.
releaseStorageRuleset(ruleset, bucket) Applies the specified ruleset to a Cloud Storage bucket.
releaseStorageRulesetFromSource(source, bucket) Creates a new from the given source, and applies it to a Cloud Storage bucket.

SecurityRules.app

Signature:

readonly app: App;

SecurityRules.createRuleset()

Creates a new from the given .

Signature:

createRuleset(file: RulesFile): Promise<Ruleset>;

Parameters

Parameter Type Description
file RulesFile Rules file to include in the new Ruleset.

Returns:

Promise<Ruleset>

A promise that fulfills with the newly created Ruleset.

SecurityRules.createRulesFileFromSource()

Creates a 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.

Signature:

createRulesFileFromSource(name: string, source: string | Buffer): RulesFile;

Parameters

Parameter Type Description
name string Name to assign to the rules file. This is usually a short file name that helps identify the file in a ruleset.
source string | Buffer Contents of the rules file. A new rules file instance.

Returns:

RulesFile

Example

const source = '// Some rules source';
const rulesFile = admin.securityRules().createRulesFileFromSource(
  'firestore.rules', source);

SecurityRules.deleteRuleset()

Deletes the 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.

Signature:

deleteRuleset(name: string): Promise<void>;

Parameters

Parameter Type Description
name string Name of the Ruleset to delete. A promise that fulfills when the Ruleset is deleted.

Returns:

Promise<void>

SecurityRules.getFirestoreRuleset()

Gets the currently applied to Cloud Firestore. Rejects with a not-found error if no ruleset is applied on Firestore.

A promise that fulfills with the Firestore ruleset.

Signature:

getFirestoreRuleset(): Promise<Ruleset>;

Returns:

Promise<Ruleset>

SecurityRules.getRuleset()

Gets the 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.

Signature:

getRuleset(name: string): Promise<Ruleset>;

Parameters

Parameter Type Description
name string Name of the Ruleset to retrieve. A promise that fulfills with the specified Ruleset.

Returns:

Promise<Ruleset>

SecurityRules.getStorageRuleset()

Gets the currently applied to a Cloud Storage bucket. Rejects with a not-found error if no ruleset is applied on the bucket.

Signature:

getStorageRuleset(bucket?: string): Promise<Ruleset>;

Parameters

Parameter Type Description
bucket string Optional name of the Cloud Storage bucket to be retrieved. If not specified, retrieves the ruleset applied on the default bucket configured via AppOptions. A promise that fulfills with the Cloud Storage ruleset.

Returns:

Promise<Ruleset>

SecurityRules.listRulesetMetadata()

Retrieves a page of ruleset metadata.

Signature:

listRulesetMetadata(pageSize?: number, nextPageToken?: string): Promise<RulesetMetadataList>;

Parameters

Parameter Type Description
pageSize number The page size, 100 if undefined. This is also the maximum allowed limit.
nextPageToken string The next page token. If not specified, returns rulesets starting without any offset. A promise that fulfills with a page of rulesets.

Returns:

Promise<RulesetMetadataList>

SecurityRules.releaseFirestoreRuleset()

Applies the specified ruleset to Cloud Firestore.

Signature:

releaseFirestoreRuleset(ruleset: string | RulesetMetadata): Promise<void>;

Parameters

Parameter Type Description
ruleset string | RulesetMetadata Name of the ruleset to apply or a RulesetMetadata object containing the name. A promise that fulfills when the ruleset is released.

Returns:

Promise<void>

SecurityRules.releaseFirestoreRulesetFromSource()

Creates a new from the given source, and applies it to Cloud Firestore.

Signature:

releaseFirestoreRulesetFromSource(source: string | Buffer): Promise<Ruleset>;

Parameters

Parameter Type Description
source string | Buffer Rules source to apply. A promise that fulfills when the ruleset is created and released.

Returns:

Promise<Ruleset>

SecurityRules.releaseStorageRuleset()

Applies the specified ruleset to a Cloud Storage bucket.

Signature:

releaseStorageRuleset(ruleset: string | RulesetMetadata, bucket?: string): Promise<void>;

Parameters

Parameter Type Description
ruleset string | RulesetMetadata Name of the ruleset to apply or a RulesetMetadata object containing the name.
bucket string Optional name of the Cloud Storage bucket to apply the rules on. If not specified, applies the ruleset on the default bucket configured via . A promise that fulfills when the ruleset is released.

Returns:

Promise<void>

SecurityRules.releaseStorageRulesetFromSource()

Creates a new from the given source, and applies it to a Cloud Storage bucket.

Signature:

releaseStorageRulesetFromSource(source: string | Buffer, bucket?: string): Promise<Ruleset>;

Parameters

Parameter Type Description
source string | Buffer Rules source to apply.
bucket string Optional name of the Cloud Storage bucket to apply the rules on. If not specified, applies the ruleset on the default bucket configured via . A promise that fulfills when the ruleset is created and released.

Returns:

Promise<Ruleset>