@@ -19,30 +19,47 @@ import { FirebaseApp } from '../firebase-app';
19
19
import * as validator from '../utils/validator' ;
20
20
import {
21
21
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 ' ;
24
24
25
25
/**
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.
27
30
*/
28
31
export interface RulesFile {
29
32
readonly name : string ;
30
33
readonly content : string ;
31
34
}
32
35
33
36
/**
34
- * Additional metadata associated with a Ruleset .
37
+ * Required metadata associated with a ruleset .
35
38
*/
36
39
export 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
+ */
37
45
readonly name : string ;
46
+ /**
47
+ * Creation time of the `Ruleset` as a UTC timestamp string.
48
+ */
38
49
readonly createTime : string ;
39
50
}
40
51
41
52
/**
42
53
* A page of ruleset metadata.
43
54
*/
44
55
export interface RulesetMetadataList {
56
+ /**
57
+ * A batch of ruleset metadata.
58
+ */
45
59
readonly rulesets : RulesetMetadata [ ] ;
60
+ /**
61
+ * The next page token if available. This is needed to retrieve the next batch.
62
+ */
46
63
readonly nextPageToken ?: string ;
47
64
}
48
65
@@ -97,7 +114,10 @@ export class Ruleset implements RulesetMetadata {
97
114
}
98
115
99
116
/**
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).
101
121
*/
102
122
export class SecurityRules implements FirebaseServiceInterface {
103
123
@@ -235,12 +255,21 @@ export class SecurityRules implements FirebaseServiceInterface {
235
255
}
236
256
237
257
/**
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.
240
261
*
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.
244
273
*/
245
274
public createRulesFileFromSource ( name : string , source : string | Buffer ) : RulesFile {
246
275
if ( ! validator . isNonEmptyString ( name ) ) {
@@ -265,10 +294,11 @@ export class SecurityRules implements FirebaseServiceInterface {
265
294
}
266
295
267
296
/**
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`}.
269
299
*
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` .
272
302
*/
273
303
public createRuleset ( file : RulesFile ) : Promise < Ruleset > {
274
304
const ruleset : RulesetContent = {
@@ -284,24 +314,27 @@ export class SecurityRules implements FirebaseServiceInterface {
284
314
}
285
315
286
316
/**
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.
290
322
*
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.
293
325
*/
294
326
public deleteRuleset ( name : string ) : Promise < void > {
295
327
return this . client . deleteRuleset ( name ) ;
296
328
}
297
329
298
330
/**
299
- * Retrieves a page of rulesets .
331
+ * Retrieves a page of ruleset metadata .
300
332
*
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.
305
338
*/
306
339
public listRulesetMetadata ( pageSize = 100 , nextPageToken ?: string ) : Promise < RulesetMetadataList > {
307
340
return this . client . listRulesets ( pageSize , nextPageToken )
0 commit comments