UNPKG

7.72 kBTypeScriptView Raw
1/*! firebase-admin v10.0.0 */
2/*!
3 * Copyright 2019 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/// <reference types="node" />
18import { App } from '../app';
19/**
20 * A source file containing some Firebase security rules. The content includes raw
21 * source code including text formatting, indentation and comments. Use the
22 * {@link SecurityRules.createRulesFileFromSource} method to create new instances of this type.
23 */
24export interface RulesFile {
25 readonly name: string;
26 readonly content: string;
27}
28/**
29 * Required metadata associated with a ruleset.
30 */
31export interface RulesetMetadata {
32 /**
33 * Name of the `Ruleset` as a short string. This can be directly passed into APIs
34 * like {@link SecurityRules.getRuleset} and {@link SecurityRules.deleteRuleset}.
35 */
36 readonly name: string;
37 /**
38 * Creation time of the `Ruleset` as a UTC timestamp string.
39 */
40 readonly createTime: string;
41}
42/**
43 * A page of ruleset metadata.
44 */
45export declare class RulesetMetadataList {
46 /**
47 * A batch of ruleset metadata.
48 */
49 readonly rulesets: RulesetMetadata[];
50 /**
51 * The next page token if available. This is needed to retrieve the next batch.
52 */
53 readonly nextPageToken?: string;
54}
55/**
56 * A set of Firebase security rules.
57 */
58export declare class Ruleset implements RulesetMetadata {
59 /**
60 * {@inheritdoc RulesetMetadata.name}
61 */
62 readonly name: string;
63 /**
64 * {@inheritdoc RulesetMetadata.createTime}
65 */
66 readonly createTime: string;
67 readonly source: RulesFile[];
68}
69/**
70 * The Firebase `SecurityRules` service interface.
71 */
72export declare class SecurityRules {
73 readonly app: App;
74 private static readonly CLOUD_FIRESTORE;
75 private static readonly FIREBASE_STORAGE;
76 private readonly client;
77 /**
78 * Gets the {@link Ruleset} identified by the given
79 * name. The input name should be the short name string without the project ID
80 * prefix. For example, to retrieve the `projects/project-id/rulesets/my-ruleset`,
81 * pass the short name "my-ruleset". Rejects with a `not-found` error if the
82 * specified `Ruleset` cannot be found.
83 *
84 * @param name - Name of the `Ruleset` to retrieve.
85 * @returns A promise that fulfills with the specified `Ruleset`.
86 */
87 getRuleset(name: string): Promise<Ruleset>;
88 /**
89 * Gets the {@link Ruleset} currently applied to
90 * Cloud Firestore. Rejects with a `not-found` error if no ruleset is applied
91 * on Firestore.
92 *
93 * @returns A promise that fulfills with the Firestore ruleset.
94 */
95 getFirestoreRuleset(): Promise<Ruleset>;
96 /**
97 * Creates a new {@link Ruleset} from the given
98 * source, and applies it to Cloud Firestore.
99 *
100 * @param source - Rules source to apply.
101 * @returns A promise that fulfills when the ruleset is created and released.
102 */
103 releaseFirestoreRulesetFromSource(source: string | Buffer): Promise<Ruleset>;
104 /**
105 * Applies the specified {@link Ruleset} ruleset
106 * to Cloud Firestore.
107 *
108 * @param ruleset - Name of the ruleset to apply or a `RulesetMetadata` object
109 * containing the name.
110 * @returns A promise that fulfills when the ruleset is released.
111 */
112 releaseFirestoreRuleset(ruleset: string | RulesetMetadata): Promise<void>;
113 /**
114 * Gets the {@link Ruleset} currently applied to a
115 * Cloud Storage bucket. Rejects with a `not-found` error if no ruleset is applied
116 * on the bucket.
117 *
118 * @param bucket - Optional name of the Cloud Storage bucket to be retrieved. If not
119 * specified, retrieves the ruleset applied on the default bucket configured via
120 * `AppOptions`.
121 * @returns A promise that fulfills with the Cloud Storage ruleset.
122 */
123 getStorageRuleset(bucket?: string): Promise<Ruleset>;
124 /**
125 * Creates a new {@link Ruleset} from the given
126 * source, and applies it to a Cloud Storage bucket.
127 *
128 * @param source - Rules source to apply.
129 * @param bucket - Optional name of the Cloud Storage bucket to apply the rules on. If
130 * not specified, applies the ruleset on the default bucket configured via
131 * {@link firebase-admin.app#AppOptions}.
132 * @returns A promise that fulfills when the ruleset is created and released.
133 */
134 releaseStorageRulesetFromSource(source: string | Buffer, bucket?: string): Promise<Ruleset>;
135 /**
136 * Applies the specified {@link Ruleset} ruleset
137 * to a Cloud Storage bucket.
138 *
139 * @param ruleset - Name of the ruleset to apply or a `RulesetMetadata` object
140 * containing the name.
141 * @param bucket - Optional name of the Cloud Storage bucket to apply the rules on. If
142 * not specified, applies the ruleset on the default bucket configured via
143 * {@link firebase-admin.app#AppOptions}.
144 * @returns A promise that fulfills when the ruleset is released.
145 */
146 releaseStorageRuleset(ruleset: string | RulesetMetadata, bucket?: string): Promise<void>;
147 /**
148 * Creates a {@link RulesFile} with the given name
149 * and source. Throws an error if any of the arguments are invalid. This is a local
150 * operation, and does not involve any network API calls.
151 *
152 * @example
153 * ```javascript
154 * const source = '// Some rules source';
155 * const rulesFile = admin.securityRules().createRulesFileFromSource(
156 * 'firestore.rules', source);
157 * ```
158 *
159 * @param name - Name to assign to the rules file. This is usually a short file name that
160 * helps identify the file in a ruleset.
161 * @param source - Contents of the rules file.
162 * @returns A new rules file instance.
163 */
164 createRulesFileFromSource(name: string, source: string | Buffer): RulesFile;
165 /**
166 * Creates a new {@link Ruleset} from the given {@link RulesFile}.
167 *
168 * @param file - Rules file to include in the new `Ruleset`.
169 * @returns A promise that fulfills with the newly created `Ruleset`.
170 */
171 createRuleset(file: RulesFile): Promise<Ruleset>;
172 /**
173 * Deletes the {@link Ruleset} identified by the given
174 * name. The input name should be the short name string without the project ID
175 * prefix. For example, to delete the `projects/project-id/rulesets/my-ruleset`,
176 * pass the short name "my-ruleset". Rejects with a `not-found` error if the
177 * specified `Ruleset` cannot be found.
178 *
179 * @param name - Name of the `Ruleset` to delete.
180 * @returns A promise that fulfills when the `Ruleset` is deleted.
181 */
182 deleteRuleset(name: string): Promise<void>;
183 /**
184 * Retrieves a page of ruleset metadata.
185 *
186 * @param pageSize - The page size, 100 if undefined. This is also the maximum allowed
187 * limit.
188 * @param nextPageToken - The next page token. If not specified, returns rulesets
189 * starting without any offset.
190 * @returns A promise that fulfills with a page of rulesets.
191 */
192 listRulesetMetadata(pageSize?: number, nextPageToken?: string): Promise<RulesetMetadataList>;
193 private getRulesetForRelease;
194 private releaseRuleset;
195 private getBucketName;
196}