@@ -19,30 +19,47 @@ import { FirebaseApp } from '../firebase-app';
1919import * as validator from '../utils/validator' ;
2020import {
2121 SecurityRulesApiClient , RulesetResponse , RulesetContent , ListRulesetsResponse ,
22- } from './security-rules-api-client' ;
23- import { FirebaseSecurityRulesError } from './security-rules-utils ' ;
22+ } from './security-rules-api-client-internal ' ;
23+ import { FirebaseSecurityRulesError } from './security-rules-internal ' ;
2424
2525/**
26- * A source file containing some Firebase security rules.
26+ * A source file containing some Firebase security rules. The content includes raw
27+ * source code including text formatting, indentation and comments. Use the
28+ * [`securityRules.createRulesFileFromSource()`](admin.securityRules.SecurityRules#createRulesFileFromSource)
29+ * method to create new instances of this type.
2730 */
2831export interface RulesFile {
2932 readonly name : string ;
3033 readonly content : string ;
3134}
3235
3336/**
34- * Additional metadata associated with a Ruleset .
37+ * Required metadata associated with a ruleset .
3538 */
3639export interface RulesetMetadata {
40+ /**
41+ * Name of the `Ruleset` as a short string. This can be directly passed into APIs
42+ * like [`securityRules.getRuleset()`](admin.securityRules.SecurityRules#getRuleset)
43+ * and [`securityRules.deleteRuleset()`](admin.securityRules.SecurityRules#deleteRuleset).
44+ */
3745 readonly name : string ;
46+ /**
47+ * Creation time of the `Ruleset` as a UTC timestamp string.
48+ */
3849 readonly createTime : string ;
3950}
4051
4152/**
4253 * A page of ruleset metadata.
4354 */
4455export interface RulesetMetadataList {
56+ /**
57+ * A batch of ruleset metadata.
58+ */
4559 readonly rulesets : RulesetMetadata [ ] ;
60+ /**
61+ * The next page token if available. This is needed to retrieve the next batch.
62+ */
4663 readonly nextPageToken ?: string ;
4764}
4865
@@ -97,7 +114,10 @@ export class Ruleset implements RulesetMetadata {
97114}
98115
99116/**
100- * SecurityRules service bound to the provided app.
117+ * The Firebase `SecurityRules` service interface.
118+ *
119+ * Do not call this constructor directly. Instead, use
120+ * [`admin.securityRules()`](admin.securityRules#securityRules).
101121 */
102122export class SecurityRules implements FirebaseServiceInterface {
103123
@@ -235,12 +255,21 @@ export class SecurityRules implements FirebaseServiceInterface {
235255 }
236256
237257 /**
238- * Creates a `RulesFile` with the given name and source. Throws if any of the arguments are invalid. This is a
239- * local operation, and does not involve any network API calls.
258+ * Creates a {@link admin.securityRules.RulesFile `RuleFile`} with the given name
259+ * and source. Throws an error if any of the arguments are invalid. This is a local
260+ * operation, and does not involve any network API calls.
240261 *
241- * @param {string } name Name to assign to the rules file.
242- * @param {string|Buffer } source Contents of the rules file.
243- * @returns {RulesFile } A new rules file instance.
262+ * @example
263+ * ```javascript
264+ * const source = '// Some rules source';
265+ * const rulesFile = admin.securityRules().createRulesFileFromSource(
266+ * 'firestore.rules', source);
267+ * ```
268+ *
269+ * @param name Name to assign to the rules file. This is usually a short file name that
270+ * helps identify the file in a ruleset.
271+ * @param source Contents of the rules file.
272+ * @return A new rules file instance.
244273 */
245274 public createRulesFileFromSource ( name : string , source : string | Buffer ) : RulesFile {
246275 if ( ! validator . isNonEmptyString ( name ) ) {
@@ -265,10 +294,11 @@ export class SecurityRules implements FirebaseServiceInterface {
265294 }
266295
267296 /**
268- * Creates a new `Ruleset` from the given `RulesFile`.
297+ * Creates a new {@link admin.securityRules.Ruleset `Ruleset`} from the given
298+ * {@link admin.securityRules.RulesFile `RuleFile`}.
269299 *
270- * @param { RulesFile } file Rules file to include in the new Ruleset.
271- * @returns { Promise<Ruleset> } A promise that fulfills with the newly created Ruleset.
300+ * @param file Rules file to include in the new ` Ruleset` .
301+ * @returns A promise that fulfills with the newly created ` Ruleset` .
272302 */
273303 public createRuleset ( file : RulesFile ) : Promise < Ruleset > {
274304 const ruleset : RulesetContent = {
@@ -284,24 +314,27 @@ export class SecurityRules implements FirebaseServiceInterface {
284314 }
285315
286316 /**
287- * Deletes the Ruleset identified by the given name. The input name should be the short name string without
288- * the project ID prefix. For example, to delete the `projects/project-id/rulesets/my-ruleset`, pass the
289- * short name "my-ruleset". Rejects with a `not-found` error if the specified Ruleset cannot be found.
317+ * Deletes the {@link admin.securityRules.Ruleset `Ruleset`} identified by the given
318+ * name. The input name should be the short name string without the project ID
319+ * prefix. For example, to delete the `projects/project-id/rulesets/my-ruleset`,
320+ * pass the short name "my-ruleset". Rejects with a `not-found` error if the
321+ * specified `Ruleset` cannot be found.
290322 *
291- * @param { string } name Name of the Ruleset to delete.
292- * @returns { Promise<Ruleset> } A promise that fulfills when the Ruleset is deleted.
323+ * @param name Name of the ` Ruleset` to delete.
324+ * @return A promise that fulfills when the ` Ruleset` is deleted.
293325 */
294326 public deleteRuleset ( name : string ) : Promise < void > {
295327 return this . client . deleteRuleset ( name ) ;
296328 }
297329
298330 /**
299- * Retrieves a page of rulesets .
331+ * Retrieves a page of ruleset metadata .
300332 *
301- * @param {number= } pageSize The page size, 100 if undefined. This is also the maximum allowed limit.
302- * @param {string= } nextPageToken The next page token. If not specified, returns rulesets starting
303- * without any offset.
304- * @returns {Promise<RulesetMetadataList> } A promise that fulfills a page of rulesets.
333+ * @param pageSize The page size, 100 if undefined. This is also the maximum allowed
334+ * limit.
335+ * @param nextPageToken The next page token. If not specified, returns rulesets
336+ * starting without any offset.
337+ * @return A promise that fulfills with a page of rulesets.
305338 */
306339 public listRulesetMetadata ( pageSize = 100 , nextPageToken ?: string ) : Promise < RulesetMetadataList > {
307340 return this . client . listRulesets ( pageSize , nextPageToken )
0 commit comments