The Firebase SecurityRules service interface.

Do not call this constructor directly. Instead, use admin.securityRules().

Index

Properties

app

app: App

Methods

createRulesFileFromSource

  • createRulesFileFromSource(name: string, source: string | Buffer): RulesFile
  • Creates a RuleFile 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
    const source = '// Some rules source';
    const rulesFile = admin.securityRules().createRulesFileFromSource(
      'firestore.rules', source);

    Parameters

    • 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.

    Returns RulesFile

    A new rules file instance.

createRuleset

  • Creates a new Ruleset from the given RuleFile.

    Parameters

    • file: RulesFile

      Rules file to include in the new Ruleset.

    Returns Promise<Ruleset>

    A promise that fulfills with the newly created Ruleset.

deleteRuleset

  • deleteRuleset(name: string): Promise<void>
  • Deletes the 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.

    Parameters

    • name: string

      Name of the Ruleset to delete.

    Returns Promise<void>

    A promise that fulfills when the Ruleset is deleted.

getFirestoreRuleset

  • getFirestoreRuleset(): Promise<Ruleset>
  • Gets the Ruleset currently applied to Cloud Firestore. Rejects with a not-found error if no ruleset is applied on Firestore.

    Returns Promise<Ruleset>

    A promise that fulfills with the Firestore ruleset.

getRuleset

  • getRuleset(name: string): Promise<Ruleset>
  • Gets the 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.

    Parameters

    • name: string

      Name of the Ruleset to retrieve.

    Returns Promise<Ruleset>

    A promise that fulfills with the specified Ruleset.

getStorageRuleset

  • getStorageRuleset(bucket?: string): Promise<Ruleset>
  • Gets the Ruleset currently applied to a Cloud Storage bucket. Rejects with a not-found error if no ruleset is applied on the bucket.

    Parameters

    • Optional 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.

    Returns Promise<Ruleset>

    A promise that fulfills with the Cloud Storage ruleset.

listRulesetMetadata

  • Retrieves a page of ruleset metadata.

    Parameters

    • Optional pageSize: number

      The page size, 100 if undefined. This is also the maximum allowed limit.

    • Optional nextPageToken: string

      The next page token. If not specified, returns rulesets starting without any offset.

    Returns Promise<RulesetMetadataList>

    A promise that fulfills with a page of rulesets.

releaseFirestoreRuleset

  • releaseFirestoreRuleset(ruleset: string | RulesetMetadata): Promise<void>
  • Applies the specified Ruleset ruleset to Cloud Firestore.

    Parameters

    • ruleset: string | RulesetMetadata

      Name of the ruleset to apply or a RulesetMetadata object containing the name.

    Returns Promise<void>

    A promise that fulfills when the ruleset is released.

releaseFirestoreRulesetFromSource

  • releaseFirestoreRulesetFromSource(source: string | Buffer): Promise<Ruleset>
  • Creates a new Ruleset from the given source, and applies it to Cloud Firestore.

    Parameters

    • source: string | Buffer

      Rules source to apply.

    Returns Promise<Ruleset>

    A promise that fulfills when the ruleset is created and released.

releaseStorageRuleset

  • releaseStorageRuleset(ruleset: string | RulesetMetadata, bucket?: string): Promise<void>
  • Applies the specified Ruleset ruleset to a Cloud Storage bucket.

    Parameters

    • ruleset: string | RulesetMetadata

      Name of the ruleset to apply or a RulesetMetadata object containing the name.

    • Optional 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 AppOptions.

    Returns Promise<void>

    A promise that fulfills when the ruleset is released.

releaseStorageRulesetFromSource

  • releaseStorageRulesetFromSource(source: string | Buffer, bucket?: string): Promise<Ruleset>
  • Creates a new Ruleset from the given source, and applies it to a Cloud Storage bucket.

    Parameters

    • source: string | Buffer

      Rules source to apply.

    • Optional 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 AppOptions.

    Returns Promise<Ruleset>

    A promise that fulfills when the ruleset is created and released.