1 | /**
|
2 | * @license
|
3 | * Copyright 2017 Google LLC
|
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 |
|
18 | /**
|
19 | * <code>firebase</code> is a global namespace from which all Firebase
|
20 | * services are accessed.
|
21 | */
|
22 | declare namespace firebase {
|
23 | /**
|
24 | * @hidden
|
25 | */
|
26 | type NextFn<T> = (value: T) => void;
|
27 | /**
|
28 | * @hidden
|
29 | */
|
30 | type ErrorFn<E = Error> = (error: E) => void;
|
31 | /**
|
32 | * @hidden
|
33 | */
|
34 | type CompleteFn = () => void;
|
35 |
|
36 | /**
|
37 | * `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
|
38 | * addition to a message string and stack trace, it contains a string code.
|
39 | */
|
40 | interface FirebaseError {
|
41 | /**
|
42 | * Error codes are strings using the following format: `"service/string-code"`.
|
43 | * Some examples include `"app/no-app"` and `"auth/user-not-found"`.
|
44 | *
|
45 | * While the message for a given error can change, the code will remain the same
|
46 | * between backward-compatible versions of the Firebase SDK.
|
47 | */
|
48 | code: string;
|
49 | /**
|
50 | * An explanatory message for the error that just occurred.
|
51 | *
|
52 | * This message is designed to be helpful to you, the developer. Because
|
53 | * it generally does not convey meaningful information to end users,
|
54 | * this message should not be displayed in your application.
|
55 | */
|
56 | message: string;
|
57 | /**
|
58 | * The name of the class of errors, which is `"FirebaseError"`.
|
59 | */
|
60 | name: string;
|
61 | /**
|
62 | * A string value containing the execution backtrace when the error originally
|
63 | * occurred. This may not always be available.
|
64 | *
|
65 | * When it is available, this information can be sent to
|
66 | * {@link https://firebase.google.com/support/ Firebase Support} to help
|
67 | * explain the cause of an error.
|
68 | */
|
69 | stack?: string;
|
70 | }
|
71 |
|
72 | /**
|
73 | * @hidden
|
74 | */
|
75 | interface Observer<T, E = Error> {
|
76 | next: NextFn<T>;
|
77 | error: ErrorFn<E>;
|
78 | complete: CompleteFn;
|
79 | }
|
80 |
|
81 | /**
|
82 | * The JS SDK supports 5 log levels and also allows a user the ability to
|
83 | * silence the logs altogether.
|
84 | *
|
85 | * The order is as follows:
|
86 | * silent < debug < verbose < info < warn < error
|
87 | */
|
88 | type LogLevel = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
|
89 |
|
90 | /**
|
91 | * The current SDK version.
|
92 | */
|
93 | var SDK_VERSION: string;
|
94 |
|
95 | /**
|
96 | * Registers a library's name and version for platform logging purposes.
|
97 | * @param library Name of 1p or 3p library (e.g. firestore, angularfire)
|
98 | * @param version Current version of that library.
|
99 | * @param variant Bundle variant, e.g., node, rn, etc.
|
100 | */
|
101 | function registerVersion(
|
102 | library: string,
|
103 | version: string,
|
104 | variant?: string
|
105 | ): void;
|
106 |
|
107 | /**
|
108 | * Sets log level for all Firebase packages.
|
109 | *
|
110 | * All of the log types above the current log level are captured (i.e. if
|
111 | * you set the log level to `info`, errors are logged, but `debug` and
|
112 | * `verbose` logs are not).
|
113 | */
|
114 | function setLogLevel(logLevel: LogLevel): void;
|
115 |
|
116 | /**
|
117 | * Sets log handler for all Firebase packages.
|
118 | * @param logCallback An optional custom log handler that executes user code whenever
|
119 | * the Firebase SDK makes a logging call.
|
120 | */
|
121 | function onLog(
|
122 | logCallback: (callbackParams: {
|
123 | /**
|
124 | * Level of event logged.
|
125 | */
|
126 | level: LogLevel;
|
127 | /**
|
128 | * Any text from logged arguments joined into one string.
|
129 | */
|
130 | message: string;
|
131 | /**
|
132 | * The raw arguments passed to the log call.
|
133 | */
|
134 | args: any[];
|
135 | /**
|
136 | * A string indicating the name of the package that made the log call,
|
137 | * such as `@firebase/firestore`.
|
138 | */
|
139 | type: string;
|
140 | }) => void,
|
141 | options?: {
|
142 | /**
|
143 | * Threshhold log level. Only logs at or above this level trigger the `logCallback`
|
144 | * passed to `onLog`.
|
145 | */
|
146 | level: LogLevel;
|
147 | }
|
148 | ): void;
|
149 |
|
150 | /**
|
151 | * @hidden
|
152 | */
|
153 | type Unsubscribe = () => void;
|
154 |
|
155 | /**
|
156 | * A user account.
|
157 | */
|
158 | interface User extends firebase.UserInfo {
|
159 | /**
|
160 | * Deletes and signs out the user.
|
161 | *
|
162 | * <b>Important:</b> this is a security-sensitive operation that requires the
|
163 | * user to have recently signed in. If this requirement isn't met, ask the user
|
164 | * to authenticate again and then call
|
165 | * {@link firebase.User.reauthenticateWithCredential}.
|
166 | *
|
167 | * <h4>Error Codes</h4>
|
168 | * <dl>
|
169 | * <dt>auth/requires-recent-login</dt>
|
170 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
171 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
172 | * resolve. This does not apply if the user is anonymous.</dd>
|
173 | * </dl>
|
174 | */
|
175 | delete(): Promise<void>;
|
176 | emailVerified: boolean;
|
177 | getIdTokenResult(
|
178 | forceRefresh?: boolean
|
179 | ): Promise<firebase.auth.IdTokenResult>;
|
180 | /**
|
181 | * Returns a JSON Web Token (JWT) used to identify the user to a Firebase
|
182 | * service.
|
183 | *
|
184 | * Returns the current token if it has not expired. Otherwise, this will
|
185 | * refresh the token and return a new one.
|
186 | *
|
187 | * @param forceRefresh Force refresh regardless of token
|
188 | * expiration.
|
189 | */
|
190 | getIdToken(forceRefresh?: boolean): Promise<string>;
|
191 | isAnonymous: boolean;
|
192 | /**
|
193 | * Links the user account with the given credentials and returns any available
|
194 | * additional user information, such as user name.
|
195 | *
|
196 | * <h4>Error Codes</h4>
|
197 | * <dl>
|
198 | * <dt>auth/provider-already-linked</dt>
|
199 | * <dd>Thrown if the provider has already been linked to the user. This error is
|
200 | * thrown even if this is not the same provider's account that is currently
|
201 | * linked to the user.</dd>
|
202 | * <dt>auth/invalid-credential</dt>
|
203 | * <dd>Thrown if the provider's credential is not valid. This can happen if it
|
204 | * has already expired when calling link, or if it used invalid token(s).
|
205 | * See the Firebase documentation for your provider, and make sure you pass
|
206 | * in the correct parameters to the credential method.</dd>
|
207 | * <dt>auth/credential-already-in-use</dt>
|
208 | * <dd>Thrown if the account corresponding to the credential already exists
|
209 | * among your users, or is already linked to a Firebase User.
|
210 | * For example, this error could be thrown if you are upgrading an anonymous
|
211 | * user to a Google user by linking a Google credential to it and the Google
|
212 | * credential used is already associated with an existing Firebase Google
|
213 | * user.
|
214 | * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
|
215 | * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
|
216 | * may be provided, depending on the type of credential. You can recover
|
217 | * from this error by signing in with <code>error.credential</code> directly
|
218 | * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
219 | * <dt>auth/email-already-in-use</dt>
|
220 | * <dd>Thrown if the email corresponding to the credential already exists
|
221 | * among your users. When thrown while linking a credential to an existing
|
222 | * user, an <code>error.email</code> and <code>error.credential</code>
|
223 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
224 | * You have to link the credential to the existing user with that email if
|
225 | * you wish to continue signing in with that credential. To do so, call
|
226 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
227 | * <code>error.email</code> via one of the providers returned and then
|
228 | * {@link firebase.User.linkWithCredential} the original credential to that
|
229 | * newly signed in user.</dd>
|
230 | * <dt>auth/operation-not-allowed</dt>
|
231 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
232 | * to the Firebase Console for your project, in the Auth section and the
|
233 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
234 | * <dt>auth/invalid-email</dt>
|
235 | * <dd>Thrown if the email used in a
|
236 | * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
|
237 | * <dt>auth/wrong-password</dt>
|
238 | * <dd>Thrown if the password used in a
|
239 | * {@link firebase.auth.EmailAuthProvider.credential} is not correct or
|
240 | * when the user associated with the email does not have a password.</dd>
|
241 | * <dt>auth/invalid-verification-code</dt>
|
242 | * <dd>Thrown if the credential is a
|
243 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
244 | * code of the credential is not valid.</dd>
|
245 | * <dt>auth/invalid-verification-id</dt>
|
246 | * <dd>Thrown if the credential is a
|
247 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
248 | * ID of the credential is not valid.</dd>
|
249 | * </dl>
|
250 | *
|
251 | * @deprecated This method is deprecated. Use
|
252 | * {@link firebase.User.linkWithCredential} instead.
|
253 | *
|
254 | * @param credential The auth credential.
|
255 | */
|
256 | linkAndRetrieveDataWithCredential(
|
257 | credential: firebase.auth.AuthCredential
|
258 | ): Promise<firebase.auth.UserCredential>;
|
259 | /**
|
260 | * Links the user account with the given credentials.
|
261 | *
|
262 | * <h4>Error Codes</h4>
|
263 | * <dl>
|
264 | * <dt>auth/provider-already-linked</dt>
|
265 | * <dd>Thrown if the provider has already been linked to the user. This error is
|
266 | * thrown even if this is not the same provider's account that is currently
|
267 | * linked to the user.</dd>
|
268 | * <dt>auth/invalid-credential</dt>
|
269 | * <dd>Thrown if the provider's credential is not valid. This can happen if it
|
270 | * has already expired when calling link, or if it used invalid token(s).
|
271 | * See the Firebase documentation for your provider, and make sure you pass
|
272 | * in the correct parameters to the credential method.</dd>
|
273 | * <dt>auth/credential-already-in-use</dt>
|
274 | * <dd>Thrown if the account corresponding to the credential already exists
|
275 | * among your users, or is already linked to a Firebase User.
|
276 | * For example, this error could be thrown if you are upgrading an anonymous
|
277 | * user to a Google user by linking a Google credential to it and the Google
|
278 | * credential used is already associated with an existing Firebase Google
|
279 | * user.
|
280 | * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
|
281 | * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
|
282 | * may be provided, depending on the type of credential. You can recover
|
283 | * from this error by signing in with <code>error.credential</code> directly
|
284 | * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
285 | * <dt>auth/email-already-in-use</dt>
|
286 | * <dd>Thrown if the email corresponding to the credential already exists
|
287 | * among your users. When thrown while linking a credential to an existing
|
288 | * user, an <code>error.email</code> and <code>error.credential</code>
|
289 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
290 | * You have to link the credential to the existing user with that email if
|
291 | * you wish to continue signing in with that credential. To do so, call
|
292 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
293 | * <code>error.email</code> via one of the providers returned and then
|
294 | * {@link firebase.User.linkWithCredential} the original credential to that
|
295 | * newly signed in user.</dd>
|
296 | * <dt>auth/operation-not-allowed</dt>
|
297 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
298 | * to the Firebase Console for your project, in the Auth section and the
|
299 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
300 | * <dt>auth/invalid-email</dt>
|
301 | * <dd>Thrown if the email used in a
|
302 | * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
|
303 | * <dt>auth/wrong-password</dt>
|
304 | * <dd>Thrown if the password used in a
|
305 | * {@link firebase.auth.EmailAuthProvider.credential} is not correct or
|
306 | * when the user associated with the email does not have a password.</dd>
|
307 | * <dt>auth/invalid-verification-code</dt>
|
308 | * <dd>Thrown if the credential is a
|
309 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
310 | * code of the credential is not valid.</dd>
|
311 | * <dt>auth/invalid-verification-id</dt>
|
312 | * <dd>Thrown if the credential is a
|
313 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
314 | * ID of the credential is not valid.</dd>
|
315 | * </dl>
|
316 | *
|
317 | * @param credential The auth credential.
|
318 | */
|
319 | linkWithCredential(
|
320 | credential: firebase.auth.AuthCredential
|
321 | ): Promise<firebase.auth.UserCredential>;
|
322 | /**
|
323 | * Links the user account with the given phone number.
|
324 | *
|
325 | * <h4>Error Codes</h4>
|
326 | * <dl>
|
327 | * <dt>auth/provider-already-linked</dt>
|
328 | * <dd>Thrown if the provider has already been linked to the user. This error is
|
329 | * thrown even if this is not the same provider's account that is currently
|
330 | * linked to the user.</dd>
|
331 | * <dt>auth/captcha-check-failed</dt>
|
332 | * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
|
333 | * this method was called from a non-whitelisted domain.</dd>
|
334 | * <dt>auth/invalid-phone-number</dt>
|
335 | * <dd>Thrown if the phone number has an invalid format.</dd>
|
336 | * <dt>auth/missing-phone-number</dt>
|
337 | * <dd>Thrown if the phone number is missing.</dd>
|
338 | * <dt>auth/quota-exceeded</dt>
|
339 | * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
|
340 | * <dt>auth/user-disabled</dt>
|
341 | * <dd>Thrown if the user corresponding to the given phone number has been
|
342 | * disabled.</dd>
|
343 | * <dt>auth/credential-already-in-use</dt>
|
344 | * <dd>Thrown if the account corresponding to the phone number already exists
|
345 | * among your users, or is already linked to a Firebase User.
|
346 | * The fields <code>error.phoneNumber</code> and
|
347 | * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
|
348 | * are provided in this case. You can recover from this error by signing in
|
349 | * with that credential directly via
|
350 | * {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
351 | * <dt>auth/operation-not-allowed</dt>
|
352 | * <dd>Thrown if you have not enabled the phone authentication provider in the
|
353 | * Firebase Console. Go to the Firebase Console for your project, in the
|
354 | * Auth section and the <strong>Sign in Method</strong> tab and configure
|
355 | * the provider.</dd>
|
356 | * </dl>
|
357 | *
|
358 | * @param phoneNumber The user's phone number in E.164 format (e.g.
|
359 | * +16505550101).
|
360 | * @param applicationVerifier
|
361 | */
|
362 | linkWithPhoneNumber(
|
363 | phoneNumber: string,
|
364 | applicationVerifier: firebase.auth.ApplicationVerifier
|
365 | ): Promise<firebase.auth.ConfirmationResult>;
|
366 | /**
|
367 | * Links the authenticated provider to the user account using a pop-up based
|
368 | * OAuth flow.
|
369 | *
|
370 | * If the linking is successful, the returned result will contain the user
|
371 | * and the provider's credential.
|
372 | *
|
373 | * <h4>Error Codes</h4>
|
374 | * <dl>
|
375 | * <dt>auth/auth-domain-config-required</dt>
|
376 | * <dd>Thrown if authDomain configuration is not provided when calling
|
377 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
378 | * determining and passing that field.</dd>
|
379 | * <dt>auth/cancelled-popup-request</dt>
|
380 | * <dd>Thrown if successive popup operations are triggered. Only one popup
|
381 | * request is allowed at one time on a user or an auth instance. All the
|
382 | * popups would fail with this error except for the last one.</dd>
|
383 | * <dt>auth/credential-already-in-use</dt>
|
384 | * <dd>Thrown if the account corresponding to the credential already exists
|
385 | * among your users, or is already linked to a Firebase User.
|
386 | * For example, this error could be thrown if you are upgrading an anonymous
|
387 | * user to a Google user by linking a Google credential to it and the Google
|
388 | * credential used is already associated with an existing Firebase Google
|
389 | * user.
|
390 | * An <code>error.email</code> and <code>error.credential</code>
|
391 | * ({@link firebase.auth.AuthCredential}) fields are also provided. You can
|
392 | * recover from this error by signing in with that credential directly via
|
393 | * {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
394 | * <dt>auth/email-already-in-use</dt>
|
395 | * <dd>Thrown if the email corresponding to the credential already exists
|
396 | * among your users. When thrown while linking a credential to an existing
|
397 | * user, an <code>error.email</code> and <code>error.credential</code>
|
398 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
399 | * You have to link the credential to the existing user with that email if
|
400 | * you wish to continue signing in with that credential. To do so, call
|
401 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
402 | * <code>error.email</code> via one of the providers returned and then
|
403 | * {@link firebase.User.linkWithCredential} the original credential to that
|
404 | * newly signed in user.</dd>
|
405 | * <dt>auth/operation-not-allowed</dt>
|
406 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
407 | * to the Firebase Console for your project, in the Auth section and the
|
408 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
409 | * <dt>auth/popup-blocked</dt>
|
410 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
411 | * <dd>Thrown if this operation is not supported in the environment your
|
412 | * application is running on. "location.protocol" must be http or https.
|
413 | * </dd>
|
414 | * <dd>Thrown if the popup was blocked by the browser, typically when this
|
415 | * operation is triggered outside of a click handler.</dd>
|
416 | * <dt>auth/popup-closed-by-user</dt>
|
417 | * <dd>Thrown if the popup window is closed by the user without completing the
|
418 | * sign in to the provider.</dd>
|
419 | * <dt>auth/provider-already-linked</dt>
|
420 | * <dd>Thrown if the provider has already been linked to the user. This error is
|
421 | * thrown even if this is not the same provider's account that is currently
|
422 | * linked to the user.</dd>
|
423 | * <dt>auth/unauthorized-domain</dt>
|
424 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
425 | * Firebase project. Edit the list of authorized domains from the Firebase
|
426 | * console.</dd>
|
427 | * </dl>
|
428 | *
|
429 | * @webonly
|
430 | *
|
431 | * @example
|
432 | * ```javascript
|
433 | * // Creates the provider object.
|
434 | * var provider = new firebase.auth.FacebookAuthProvider();
|
435 | * // You can add additional scopes to the provider:
|
436 | * provider.addScope('email');
|
437 | * provider.addScope('user_friends');
|
438 | * // Link with popup:
|
439 | * user.linkWithPopup(provider).then(function(result) {
|
440 | * // The firebase.User instance:
|
441 | * var user = result.user;
|
442 | * // The Facebook firebase.auth.AuthCredential containing the Facebook
|
443 | * // access token:
|
444 | * var credential = result.credential;
|
445 | * }, function(error) {
|
446 | * // An error happened.
|
447 | * });
|
448 | * ```
|
449 | *
|
450 | * @param provider The provider to authenticate.
|
451 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
452 | * firebase.auth.EmailAuthProvider} will throw an error.
|
453 | */
|
454 | linkWithPopup(
|
455 | provider: firebase.auth.AuthProvider
|
456 | ): Promise<firebase.auth.UserCredential>;
|
457 | /**
|
458 | * Links the authenticated provider to the user account using a full-page
|
459 | * redirect flow.
|
460 | *
|
461 | * <h4>Error Codes</h4>
|
462 | * <dl>
|
463 | * <dt>auth/auth-domain-config-required</dt>
|
464 | * <dd>Thrown if authDomain configuration is not provided when calling
|
465 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
466 | * determining and passing that field.</dd>
|
467 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
468 | * <dd>Thrown if this operation is not supported in the environment your
|
469 | * application is running on. "location.protocol" must be http or https.
|
470 | * </dd>
|
471 | * <dt>auth/provider-already-linked</dt>
|
472 | * <dd>Thrown if the provider has already been linked to the user. This error is
|
473 | * thrown even if this is not the same provider's account that is currently
|
474 | * linked to the user.</dd>
|
475 | * <dt>auth/unauthorized-domain</dt>
|
476 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
477 | * Firebase project. Edit the list of authorized domains from the Firebase
|
478 | * console.</dd>
|
479 | * </dl>
|
480 | *
|
481 | * @param provider The provider to authenticate.
|
482 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
483 | * firebase.auth.EmailAuthProvider} will throw an error.
|
484 | */
|
485 | linkWithRedirect(provider: firebase.auth.AuthProvider): Promise<void>;
|
486 | metadata: firebase.auth.UserMetadata;
|
487 | /**
|
488 | * The {@link firebase.User.MultiFactor} object corresponding to the current user.
|
489 | * This is used to access all multi-factor properties and operations related to the
|
490 | * current user.
|
491 | */
|
492 |
|
493 | multiFactor: firebase.User.MultiFactorUser;
|
494 | /**
|
495 | * The phone number normalized based on the E.164 standard (e.g. +16505550101)
|
496 | * for the current user. This is null if the user has no phone credential linked
|
497 | * to the account.
|
498 | */
|
499 | phoneNumber: string | null;
|
500 | providerData: (firebase.UserInfo | null)[];
|
501 | /**
|
502 | * Re-authenticates a user using a fresh credential, and returns any available
|
503 | * additional user information, such as user name. Use before operations
|
504 | * such as {@link firebase.User.updatePassword} that require tokens from recent
|
505 | * sign-in attempts.
|
506 | *
|
507 | * <h4>Error Codes</h4>
|
508 | * <dl>
|
509 | * <dt>auth/user-mismatch</dt>
|
510 | * <dd>Thrown if the credential given does not correspond to the user.</dd>
|
511 | * <dt>auth/user-not-found</dt>
|
512 | * <dd>Thrown if the credential given does not correspond to any existing user.
|
513 | * </dd>
|
514 | * <dt>auth/invalid-credential</dt>
|
515 | * <dd>Thrown if the provider's credential is not valid. This can happen if it
|
516 | * has already expired when calling link, or if it used invalid token(s).
|
517 | * See the Firebase documentation for your provider, and make sure you pass
|
518 | * in the correct parameters to the credential method.</dd>
|
519 | * <dt>auth/invalid-email</dt>
|
520 | * <dd>Thrown if the email used in a
|
521 | * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
|
522 | * <dt>auth/wrong-password</dt>
|
523 | * <dd>Thrown if the password used in a
|
524 | * {@link firebase.auth.EmailAuthProvider.credential} is not correct or when
|
525 | * the user associated with the email does not have a password.</dd>
|
526 | * <dt>auth/invalid-verification-code</dt>
|
527 | * <dd>Thrown if the credential is a
|
528 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
529 | * code of the credential is not valid.</dd>
|
530 | * <dt>auth/invalid-verification-id</dt>
|
531 | * <dd>Thrown if the credential is a
|
532 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
533 | * ID of the credential is not valid.</dd>
|
534 | * </dl>
|
535 | *
|
536 | * @deprecated
|
537 | * This method is deprecated. Use
|
538 | * {@link firebase.User.reauthenticateWithCredential} instead.
|
539 | *
|
540 | * @param credential
|
541 | */
|
542 | reauthenticateAndRetrieveDataWithCredential(
|
543 | credential: firebase.auth.AuthCredential
|
544 | ): Promise<firebase.auth.UserCredential>;
|
545 | /**
|
546 | * Re-authenticates a user using a fresh credential. Use before operations
|
547 | * such as {@link firebase.User.updatePassword} that require tokens from recent
|
548 | * sign-in attempts.
|
549 | *
|
550 | * <h4>Error Codes</h4>
|
551 | * <dl>
|
552 | * <dt>auth/user-mismatch</dt>
|
553 | * <dd>Thrown if the credential given does not correspond to the user.</dd>
|
554 | * <dt>auth/user-not-found</dt>
|
555 | * <dd>Thrown if the credential given does not correspond to any existing user.
|
556 | * </dd>
|
557 | * <dt>auth/invalid-credential</dt>
|
558 | * <dd>Thrown if the provider's credential is not valid. This can happen if it
|
559 | * has already expired when calling link, or if it used invalid token(s).
|
560 | * See the Firebase documentation for your provider, and make sure you pass
|
561 | * in the correct parameters to the credential method.</dd>
|
562 | * <dt>auth/invalid-email</dt>
|
563 | * <dd>Thrown if the email used in a
|
564 | * {@link firebase.auth.EmailAuthProvider.credential} is invalid.</dd>
|
565 | * <dt>auth/wrong-password</dt>
|
566 | * <dd>Thrown if the password used in a
|
567 | * {@link firebase.auth.EmailAuthProvider.credential} is not correct or when
|
568 | * the user associated with the email does not have a password.</dd>
|
569 | * <dt>auth/invalid-verification-code</dt>
|
570 | * <dd>Thrown if the credential is a
|
571 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
572 | * code of the credential is not valid.</dd>
|
573 | * <dt>auth/invalid-verification-id</dt>
|
574 | * <dd>Thrown if the credential is a
|
575 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
576 | * ID of the credential is not valid.</dd>
|
577 | * </dl>
|
578 | *
|
579 | * @param credential
|
580 | */
|
581 | reauthenticateWithCredential(
|
582 | credential: firebase.auth.AuthCredential
|
583 | ): Promise<firebase.auth.UserCredential>;
|
584 | /**
|
585 | * Re-authenticates a user using a fresh credential. Use before operations
|
586 | * such as {@link firebase.User.updatePassword} that require tokens from recent
|
587 | * sign-in attempts.
|
588 | *
|
589 | * <h4>Error Codes</h4>
|
590 | * <dl>
|
591 | * <dt>auth/user-mismatch</dt>
|
592 | * <dd>Thrown if the credential given does not correspond to the user.</dd>
|
593 | * <dt>auth/user-not-found</dt>
|
594 | * <dd>Thrown if the credential given does not correspond to any existing user.
|
595 | * </dd>
|
596 | * <dt>auth/captcha-check-failed</dt>
|
597 | * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
|
598 | * this method was called from a non-whitelisted domain.</dd>
|
599 | * <dt>auth/invalid-phone-number</dt>
|
600 | * <dd>Thrown if the phone number has an invalid format.</dd>
|
601 | * <dt>auth/missing-phone-number</dt>
|
602 | * <dd>Thrown if the phone number is missing.</dd>
|
603 | * <dt>auth/quota-exceeded</dt>
|
604 | * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
|
605 | * </dl>
|
606 | *
|
607 | * @param phoneNumber The user's phone number in E.164 format (e.g.
|
608 | * +16505550101).
|
609 | * @param applicationVerifier
|
610 | */
|
611 | reauthenticateWithPhoneNumber(
|
612 | phoneNumber: string,
|
613 | applicationVerifier: firebase.auth.ApplicationVerifier
|
614 | ): Promise<firebase.auth.ConfirmationResult>;
|
615 | /**
|
616 | * Reauthenticates the current user with the specified provider using a pop-up
|
617 | * based OAuth flow.
|
618 | *
|
619 | * If the reauthentication is successful, the returned result will contain the
|
620 | * user and the provider's credential.
|
621 | *
|
622 | * <h4>Error Codes</h4>
|
623 | * <dl>
|
624 | * <dt>auth/auth-domain-config-required</dt>
|
625 | * <dd>Thrown if authDomain configuration is not provided when calling
|
626 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
627 | * determining and passing that field.</dd>
|
628 | * <dt>auth/cancelled-popup-request</dt>
|
629 | * <dd>Thrown if successive popup operations are triggered. Only one popup
|
630 | * request is allowed at one time on a user or an auth instance. All the
|
631 | * popups would fail with this error except for the last one.</dd>
|
632 | * <dt>auth/user-mismatch</dt>
|
633 | * <dd>Thrown if the credential given does not correspond to the user.</dd>
|
634 | * <dt>auth/operation-not-allowed</dt>
|
635 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
636 | * to the Firebase Console for your project, in the Auth section and the
|
637 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
638 | * <dt>auth/popup-blocked</dt>
|
639 | * <dd>Thrown if the popup was blocked by the browser, typically when this
|
640 | * operation is triggered outside of a click handler.</dd>
|
641 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
642 | * <dd>Thrown if this operation is not supported in the environment your
|
643 | * application is running on. "location.protocol" must be http or https.
|
644 | * </dd>
|
645 | * <dt>auth/popup-closed-by-user</dt>
|
646 | * <dd>Thrown if the popup window is closed by the user without completing the
|
647 | * sign in to the provider.</dd>
|
648 | * <dt>auth/unauthorized-domain</dt>
|
649 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
650 | * Firebase project. Edit the list of authorized domains from the Firebase
|
651 | * console.</dd>
|
652 | * </dl>
|
653 | *
|
654 | * @webonly
|
655 | *
|
656 | * @example
|
657 | * ```javascript
|
658 | * // Creates the provider object.
|
659 | * var provider = new firebase.auth.FacebookAuthProvider();
|
660 | * // You can add additional scopes to the provider:
|
661 | * provider.addScope('email');
|
662 | * provider.addScope('user_friends');
|
663 | * // Reauthenticate with popup:
|
664 | * user.reauthenticateWithPopup(provider).then(function(result) {
|
665 | * // The firebase.User instance:
|
666 | * var user = result.user;
|
667 | * // The Facebook firebase.auth.AuthCredential containing the Facebook
|
668 | * // access token:
|
669 | * var credential = result.credential;
|
670 | * }, function(error) {
|
671 | * // An error happened.
|
672 | * });
|
673 | * ```
|
674 | *
|
675 | * @param provider The provider to authenticate.
|
676 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
677 | * firebase.auth.EmailAuthProvider} will throw an error.
|
678 | */
|
679 | reauthenticateWithPopup(
|
680 | provider: firebase.auth.AuthProvider
|
681 | ): Promise<firebase.auth.UserCredential>;
|
682 | /**
|
683 | * Reauthenticates the current user with the specified OAuth provider using a
|
684 | * full-page redirect flow.
|
685 | *
|
686 | * <h4>Error Codes</h4>
|
687 | * <dl>
|
688 | * <dt>auth/auth-domain-config-required</dt>
|
689 | * <dd>Thrown if authDomain configuration is not provided when calling
|
690 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
691 | * determining and passing that field.</dd>
|
692 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
693 | * <dd>Thrown if this operation is not supported in the environment your
|
694 | * application is running on. "location.protocol" must be http or https.
|
695 | * </dd>
|
696 | * <dt>auth/user-mismatch</dt>
|
697 | * <dd>Thrown if the credential given does not correspond to the user.</dd>
|
698 | * <dt>auth/unauthorized-domain</dt>
|
699 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
700 | * Firebase project. Edit the list of authorized domains from the Firebase
|
701 | * console.</dd>
|
702 | * </dl>
|
703 | *
|
704 | * @webonly
|
705 | *
|
706 | * @param provider The provider to authenticate.
|
707 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
708 | * firebase.auth.EmailAuthProvider} will throw an error.
|
709 | */
|
710 | reauthenticateWithRedirect(
|
711 | provider: firebase.auth.AuthProvider
|
712 | ): Promise<void>;
|
713 | refreshToken: string;
|
714 | /**
|
715 | * Refreshes the current user, if signed in.
|
716 | *
|
717 | */
|
718 | reload(): Promise<void>;
|
719 | /**
|
720 | * Sends a verification email to a user.
|
721 | *
|
722 | * The verification process is completed by calling
|
723 | * {@link firebase.auth.Auth.applyActionCode}
|
724 | *
|
725 | * <h4>Error Codes</h4>
|
726 | * <dl>
|
727 | * <dt>auth/missing-android-pkg-name</dt>
|
728 | * <dd>An Android package name must be provided if the Android app is required
|
729 | * to be installed.</dd>
|
730 | * <dt>auth/missing-continue-uri</dt>
|
731 | * <dd>A continue URL must be provided in the request.</dd>
|
732 | * <dt>auth/missing-ios-bundle-id</dt>
|
733 | * <dd>An iOS bundle ID must be provided if an App Store ID is provided.</dd>
|
734 | * <dt>auth/invalid-continue-uri</dt>
|
735 | * <dd>The continue URL provided in the request is invalid.</dd>
|
736 | * <dt>auth/unauthorized-continue-uri</dt>
|
737 | * <dd>The domain of the continue URL is not whitelisted. Whitelist
|
738 | * the domain in the Firebase console.</dd>
|
739 | * </dl>
|
740 | *
|
741 | * @example
|
742 | * ```javascript
|
743 | * var actionCodeSettings = {
|
744 | * url: 'https://www.example.com/cart?email=user@example.com&cartId=123',
|
745 | * iOS: {
|
746 | * bundleId: 'com.example.ios'
|
747 | * },
|
748 | * android: {
|
749 | * packageName: 'com.example.android',
|
750 | * installApp: true,
|
751 | * minimumVersion: '12'
|
752 | * },
|
753 | * handleCodeInApp: true
|
754 | * };
|
755 | * firebase.auth().currentUser.sendEmailVerification(actionCodeSettings)
|
756 | * .then(function() {
|
757 | * // Verification email sent.
|
758 | * })
|
759 | * .catch(function(error) {
|
760 | * // Error occurred. Inspect error.code.
|
761 | * });
|
762 | * ```
|
763 | *
|
764 | * @param actionCodeSettings The action
|
765 | * code settings. If specified, the state/continue URL will be set as the
|
766 | * "continueUrl" parameter in the email verification link. The default email
|
767 | * verification landing page will use this to display a link to go back to
|
768 | * the app if it is installed.
|
769 | * If the actionCodeSettings is not specified, no URL is appended to the
|
770 | * action URL.
|
771 | * The state URL provided must belong to a domain that is whitelisted by the
|
772 | * developer in the console. Otherwise an error will be thrown.
|
773 | * Mobile app redirects will only be applicable if the developer configures
|
774 | * and accepts the Firebase Dynamic Links terms of condition.
|
775 | * The Android package name and iOS bundle ID will be respected only if they
|
776 | * are configured in the same Firebase Auth project used.
|
777 | */
|
778 | sendEmailVerification(
|
779 | actionCodeSettings?: firebase.auth.ActionCodeSettings | null
|
780 | ): Promise<void>;
|
781 | /**
|
782 | * The current user's tenant ID. This is a read-only property, which indicates
|
783 | * the tenant ID used to sign in the current user. This is null if the user is
|
784 | * signed in from the parent project.
|
785 | *
|
786 | * @example
|
787 | * ```javascript
|
788 | * // Set the tenant ID on Auth instance.
|
789 | * firebase.auth().tenantId = ‘TENANT_PROJECT_ID’;
|
790 | *
|
791 | * // All future sign-in request now include tenant ID.
|
792 | * firebase.auth().signInWithEmailAndPassword(email, password)
|
793 | * .then(function(result) {
|
794 | * // result.user.tenantId should be ‘TENANT_PROJECT_ID’.
|
795 | * }).catch(function(error) {
|
796 | * // Handle error.
|
797 | * });
|
798 | * ```
|
799 | */
|
800 | tenantId: string | null;
|
801 | /**
|
802 | * Returns a JSON-serializable representation of this object.
|
803 | *
|
804 | * @return A JSON-serializable representation of this object.
|
805 | */
|
806 | toJSON(): Object;
|
807 | /**
|
808 | * Unlinks a provider from a user account.
|
809 | *
|
810 | * <h4>Error Codes</h4>
|
811 | * <dl>
|
812 | * <dt>auth/no-such-provider</dt>
|
813 | * <dd>Thrown if the user does not have this provider linked or when the
|
814 | * provider ID given does not exist.</dd>
|
815 | * </dt>
|
816 | *
|
817 | * @param providerId
|
818 | */
|
819 | unlink(providerId: string): Promise<firebase.User>;
|
820 | /**
|
821 | * Updates the user's email address.
|
822 | *
|
823 | * An email will be sent to the original email address (if it was set) that
|
824 | * allows to revoke the email address change, in order to protect them from
|
825 | * account hijacking.
|
826 | *
|
827 | * <b>Important:</b> this is a security sensitive operation that requires the
|
828 | * user to have recently signed in. If this requirement isn't met, ask the user
|
829 | * to authenticate again and then call
|
830 | * {@link firebase.User.reauthenticateWithCredential}.
|
831 | *
|
832 | * <h4>Error Codes</h4>
|
833 | * <dl>
|
834 | * <dt>auth/invalid-email</dt>
|
835 | * <dd>Thrown if the email used is invalid.</dd>
|
836 | * <dt>auth/email-already-in-use</dt>
|
837 | * <dd>Thrown if the email is already used by another user.</dd>
|
838 | * <dt>auth/requires-recent-login</dt>
|
839 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
840 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
841 | * resolve. This does not apply if the user is anonymous.</dd>
|
842 | * </dl>
|
843 | *
|
844 | * @param newEmail The new email address.
|
845 | */
|
846 | updateEmail(newEmail: string): Promise<void>;
|
847 | /**
|
848 | * Updates the user's password.
|
849 | *
|
850 | * <b>Important:</b> this is a security sensitive operation that requires the
|
851 | * user to have recently signed in. If this requirement isn't met, ask the user
|
852 | * to authenticate again and then call
|
853 | * {@link firebase.User.reauthenticateWithCredential}.
|
854 | *
|
855 | * <h4>Error Codes</h4>
|
856 | * <dl>
|
857 | * <dt>auth/weak-password</dt>
|
858 | * <dd>Thrown if the password is not strong enough.</dd>
|
859 | * <dt>auth/requires-recent-login</dt>
|
860 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
861 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
862 | * resolve. This does not apply if the user is anonymous.</dd>
|
863 | * </dl>
|
864 | *
|
865 | * @param newPassword
|
866 | */
|
867 | updatePassword(newPassword: string): Promise<void>;
|
868 | /**
|
869 | * Updates the user's phone number.
|
870 | *
|
871 | * <h4>Error Codes</h4>
|
872 | * <dl>
|
873 | * <dt>auth/invalid-verification-code</dt>
|
874 | * <dd>Thrown if the verification code of the credential is not valid.</dd>
|
875 | * <dt>auth/invalid-verification-id</dt>
|
876 | * <dd>Thrown if the verification ID of the credential is not valid.</dd>
|
877 | * </dl>
|
878 | *
|
879 | * @param phoneCredential
|
880 | */
|
881 | updatePhoneNumber(
|
882 | phoneCredential: firebase.auth.AuthCredential
|
883 | ): Promise<void>;
|
884 | /**
|
885 | * Updates a user's profile data.
|
886 | *
|
887 | * @example
|
888 | * ```javascript
|
889 | * // Updates the user attributes:
|
890 | * user.updateProfile({
|
891 | * displayName: "Jane Q. User",
|
892 | * photoURL: "https://example.com/jane-q-user/profile.jpg"
|
893 | * }).then(function() {
|
894 | * // Profile updated successfully!
|
895 | * // "Jane Q. User"
|
896 | * var displayName = user.displayName;
|
897 | * // "https://example.com/jane-q-user/profile.jpg"
|
898 | * var photoURL = user.photoURL;
|
899 | * }, function(error) {
|
900 | * // An error happened.
|
901 | * });
|
902 | *
|
903 | * // Passing a null value will delete the current attribute's value, but not
|
904 | * // passing a property won't change the current attribute's value:
|
905 | * // Let's say we're using the same user than before, after the update.
|
906 | * user.updateProfile({photoURL: null}).then(function() {
|
907 | * // Profile updated successfully!
|
908 | * // "Jane Q. User", hasn't changed.
|
909 | * var displayName = user.displayName;
|
910 | * // Now, this is null.
|
911 | * var photoURL = user.photoURL;
|
912 | * }, function(error) {
|
913 | * // An error happened.
|
914 | * });
|
915 | * ```
|
916 | *
|
917 | * @param profile The profile's
|
918 | * displayName and photoURL to update.
|
919 | */
|
920 | updateProfile(profile: {
|
921 | displayName?: string | null;
|
922 | photoURL?: string | null;
|
923 | }): Promise<void>;
|
924 | /**
|
925 | * Sends a verification email to a new email address. The user's email will be
|
926 | * updated to the new one after being verified.
|
927 | *
|
928 | * If you have a custom email action handler, you can complete the verification
|
929 | * process by calling {@link firebase.auth.Auth.applyActionCode}.
|
930 | *
|
931 | * <h4>Error Codes</h4>
|
932 | * <dl>
|
933 | * <dt>auth/missing-android-pkg-name</dt>
|
934 | * <dd>An Android package name must be provided if the Android app is required
|
935 | * to be installed.</dd>
|
936 | * <dt>auth/missing-continue-uri</dt>
|
937 | * <dd>A continue URL must be provided in the request.</dd>
|
938 | * <dt>auth/missing-ios-bundle-id</dt>
|
939 | * <dd>An iOS bundle ID must be provided if an App Store ID is provided.</dd>
|
940 | * <dt>auth/invalid-continue-uri</dt>
|
941 | * <dd>The continue URL provided in the request is invalid.</dd>
|
942 | * <dt>auth/unauthorized-continue-uri</dt>
|
943 | * <dd>The domain of the continue URL is not whitelisted. Whitelist
|
944 | * the domain in the Firebase console.</dd>
|
945 | * </dl>
|
946 | *
|
947 | * @example
|
948 | * ```javascript
|
949 | * var actionCodeSettings = {
|
950 | * url: 'https://www.example.com/cart?email=user@example.com&cartId=123',
|
951 | * iOS: {
|
952 | * bundleId: 'com.example.ios'
|
953 | * },
|
954 | * android: {
|
955 | * packageName: 'com.example.android',
|
956 | * installApp: true,
|
957 | * minimumVersion: '12'
|
958 | * },
|
959 | * handleCodeInApp: true
|
960 | * };
|
961 | * firebase.auth().currentUser.verifyBeforeUpdateEmail(
|
962 | * 'user@example.com', actionCodeSettings)
|
963 | * .then(function() {
|
964 | * // Verification email sent.
|
965 | * })
|
966 | * .catch(function(error) {
|
967 | * // Error occurred. Inspect error.code.
|
968 | * });
|
969 | * ```
|
970 | *
|
971 | * @param newEmail The email address to be verified and updated to.
|
972 | * @param actionCodeSettings The action
|
973 | * code settings. If specified, the state/continue URL will be set as the
|
974 | * "continueUrl" parameter in the email verification link. The default email
|
975 | * verification landing page will use this to display a link to go back to
|
976 | * the app if it is installed.
|
977 | * If the actionCodeSettings is not specified, no URL is appended to the
|
978 | * action URL.
|
979 | * The state URL provided must belong to a domain that is whitelisted by the
|
980 | * developer in the console. Otherwise an error will be thrown.
|
981 | * Mobile app redirects will only be applicable if the developer configures
|
982 | * and accepts the Firebase Dynamic Links terms of condition.
|
983 | * The Android package name and iOS bundle ID will be respected only if they
|
984 | * are configured in the same Firebase Auth project used.
|
985 | */
|
986 | verifyBeforeUpdateEmail(
|
987 | newEmail: string,
|
988 | actionCodeSettings?: firebase.auth.ActionCodeSettings | null
|
989 | ): Promise<void>;
|
990 | }
|
991 |
|
992 | /**
|
993 | * User profile information, visible only to the Firebase project's
|
994 | * apps.
|
995 | *
|
996 | */
|
997 | interface UserInfo {
|
998 | displayName: string | null;
|
999 | email: string | null;
|
1000 | phoneNumber: string | null;
|
1001 | photoURL: string | null;
|
1002 | providerId: string;
|
1003 | /**
|
1004 | * The user's unique ID.
|
1005 | */
|
1006 | uid: string;
|
1007 | }
|
1008 |
|
1009 | /**
|
1010 | * Retrieves a Firebase {@link firebase.app.App app} instance.
|
1011 | *
|
1012 | * When called with no arguments, the default app is returned. When an app name
|
1013 | * is provided, the app corresponding to that name is returned.
|
1014 | *
|
1015 | * An exception is thrown if the app being retrieved has not yet been
|
1016 | * initialized.
|
1017 | *
|
1018 | * @example
|
1019 | * ```javascript
|
1020 | * // Return the default app
|
1021 | * var app = firebase.app();
|
1022 | * ```
|
1023 | *
|
1024 | * @example
|
1025 | * ```javascript
|
1026 | * // Return a named app
|
1027 | * var otherApp = firebase.app("otherApp");
|
1028 | * ```
|
1029 | *
|
1030 | * @param name Optional name of the app to return. If no name is
|
1031 | * provided, the default is `"[DEFAULT]"`.
|
1032 | *
|
1033 | * @return The app corresponding to the provided app name.
|
1034 | * If no app name is provided, the default app is returned.
|
1035 | */
|
1036 | function app(name?: string): firebase.app.App;
|
1037 |
|
1038 | /**
|
1039 | * A (read-only) array of all initialized apps.
|
1040 | */
|
1041 | var apps: firebase.app.App[];
|
1042 |
|
1043 | /**
|
1044 | * Gets the {@link firebase.auth.Auth `Auth`} service for the default app or a
|
1045 | * given app.
|
1046 | *
|
1047 | * `firebase.auth()` can be called with no arguments to access the default app's
|
1048 | * {@link firebase.auth.Auth `Auth`} service or as `firebase.auth(app)` to
|
1049 | * access the {@link firebase.auth.Auth `Auth`} service associated with a
|
1050 | * specific app.
|
1051 | *
|
1052 | * @example
|
1053 | * ```javascript
|
1054 | *
|
1055 | * // Get the Auth service for the default app
|
1056 | * var defaultAuth = firebase.auth();
|
1057 | * ```
|
1058 | * @example
|
1059 | * ```javascript
|
1060 | *
|
1061 | * // Get the Auth service for a given app
|
1062 | * var otherAuth = firebase.auth(otherApp);
|
1063 | * ```
|
1064 | * @param app
|
1065 | */
|
1066 | function auth(app?: firebase.app.App): firebase.auth.Auth;
|
1067 |
|
1068 | /**
|
1069 | * Gets the {@link firebase.database.Database `Database`} service for the
|
1070 | * default app or a given app.
|
1071 | *
|
1072 | * `firebase.database()` can be called with no arguments to access the default
|
1073 | * app's {@link firebase.database.Database `Database`} service or as
|
1074 | * `firebase.database(app)` to access the
|
1075 | * {@link firebase.database.Database `Database`} service associated with a
|
1076 | * specific app.
|
1077 | *
|
1078 | * `firebase.database` is also a namespace that can be used to access global
|
1079 | * constants and methods associated with the `Database` service.
|
1080 | *
|
1081 | * @example
|
1082 | * ```javascript
|
1083 | * // Get the Database service for the default app
|
1084 | * var defaultDatabase = firebase.database();
|
1085 | * ```
|
1086 | *
|
1087 | * @example
|
1088 | * ```javascript
|
1089 | * // Get the Database service for a specific app
|
1090 | * var otherDatabase = firebase.database(app);
|
1091 | * ```
|
1092 | *
|
1093 | * @namespace
|
1094 | * @param app Optional app whose Database service to
|
1095 | * return. If not provided, the default Database service will be returned.
|
1096 | * @return The default Database service if no app
|
1097 | * is provided or the Database service associated with the provided app.
|
1098 | */
|
1099 | function database(app?: firebase.app.App): firebase.database.Database;
|
1100 |
|
1101 | /**
|
1102 | * Creates and initializes a Firebase {@link firebase.app.App app} instance.
|
1103 | *
|
1104 | * See
|
1105 | * {@link
|
1106 | * https://firebase.google.com/docs/web/setup#add_firebase_to_your_app
|
1107 | * Add Firebase to your app} and
|
1108 | * {@link
|
1109 | * https://firebase.google.com/docs/web/setup#multiple-projects
|
1110 | * Initialize multiple projects} for detailed documentation.
|
1111 | *
|
1112 | * @example
|
1113 | * ```javascript
|
1114 | *
|
1115 | * // Initialize default app
|
1116 | * // Retrieve your own options values by adding a web app on
|
1117 | * // https://console.firebase.google.com
|
1118 | * firebase.initializeApp({
|
1119 | * apiKey: "AIza....", // Auth / General Use
|
1120 | * authDomain: "YOUR_APP.firebaseapp.com", // Auth with popup/redirect
|
1121 | * databaseURL: "https://YOUR_APP.firebaseio.com", // Realtime Database
|
1122 | * storageBucket: "YOUR_APP.appspot.com", // Storage
|
1123 | * messagingSenderId: "123456789" // Cloud Messaging
|
1124 | * });
|
1125 | * ```
|
1126 | *
|
1127 | * @example
|
1128 | * ```javascript
|
1129 | *
|
1130 | * // Initialize another app
|
1131 | * var otherApp = firebase.initializeApp({
|
1132 | * databaseURL: "https://<OTHER_DATABASE_NAME>.firebaseio.com",
|
1133 | * storageBucket: "<OTHER_STORAGE_BUCKET>.appspot.com"
|
1134 | * }, "otherApp");
|
1135 | * ```
|
1136 | *
|
1137 | * @param options Options to configure the app's services.
|
1138 | * @param name Optional name of the app to initialize. If no name
|
1139 | * is provided, the default is `"[DEFAULT]"`.
|
1140 | *
|
1141 | * @return {!firebase.app.App} The initialized app.
|
1142 | */
|
1143 | function initializeApp(options: Object, name?: string): firebase.app.App;
|
1144 |
|
1145 | /**
|
1146 | * Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
|
1147 | * default app or a given app.
|
1148 | *
|
1149 | * `firebase.messaging()` can be called with no arguments to access the default
|
1150 | * app's {@link firebase.messaging.Messaging `Messaging`} service or as
|
1151 | * `firebase.messaging(app)` to access the
|
1152 | * {@link firebase.messaging.Messaging `Messaging`} service associated with a
|
1153 | * specific app.
|
1154 | *
|
1155 | * Calling `firebase.messaging()` in a service worker results in Firebase
|
1156 | * generating notifications if the push message payload has a `notification`
|
1157 | * parameter.
|
1158 | *
|
1159 | * @webonly
|
1160 | *
|
1161 | * @example
|
1162 | * ```javascript
|
1163 | * // Get the Messaging service for the default app
|
1164 | * var defaultMessaging = firebase.messaging();
|
1165 | * ```
|
1166 | *
|
1167 | * @example
|
1168 | * ```javascript
|
1169 | * // Get the Messaging service for a given app
|
1170 | * var otherMessaging = firebase.messaging(otherApp);
|
1171 | * ```
|
1172 | *
|
1173 | * @namespace
|
1174 | * @param app The app to create a Messaging service for.
|
1175 | * If not passed, uses the default app.
|
1176 | */
|
1177 | function messaging(app?: firebase.app.App): firebase.messaging.Messaging;
|
1178 |
|
1179 | /**
|
1180 | * Gets the {@link firebase.storage.Storage `Storage`} service for the default
|
1181 | * app or a given app.
|
1182 | *
|
1183 | * `firebase.storage()` can be called with no arguments to access the default
|
1184 | * app's {@link firebase.storage.Storage `Storage`} service or as
|
1185 | * `firebase.storage(app)` to access the
|
1186 | * {@link firebase.storage.Storage `Storage`} service associated with a
|
1187 | * specific app.
|
1188 | *
|
1189 | * @webonly
|
1190 | *
|
1191 | * @example
|
1192 | * ```javascript
|
1193 | * // Get the Storage service for the default app
|
1194 | * var defaultStorage = firebase.storage();
|
1195 | * ```
|
1196 | *
|
1197 | * @example
|
1198 | * ```javascript
|
1199 | * // Get the Storage service for a given app
|
1200 | * var otherStorage = firebase.storage(otherApp);
|
1201 | * ```
|
1202 | *
|
1203 | * @param app The app to create a storage service for.
|
1204 | * If not passed, uses the default app.
|
1205 | */
|
1206 | function storage(app?: firebase.app.App): firebase.storage.Storage;
|
1207 |
|
1208 | function firestore(app?: firebase.app.App): firebase.firestore.Firestore;
|
1209 |
|
1210 | function functions(app?: firebase.app.App): firebase.functions.Functions;
|
1211 |
|
1212 | /**
|
1213 | * Gets the {@link firebase.performance.Performance `Performance`} service.
|
1214 | *
|
1215 | * `firebase.performance()` can be called with no arguments to access the default
|
1216 | * app's { firebase.performance.Performance `Performance`} service.
|
1217 | * The {`Performance`} service does not work with
firebase.performance.Performance |
1218 | * any other app.
|
1219 | *
|
1220 | *
|
1221 | *
|
1222 | *
|
1223 | * ```javascript
|
1224 | * // Get the Performance service for the default app
|
1225 | * const defaultPerformance = firebase.performance();
|
1226 | * ```
|
1227 | *
|
1228 | * for. Performance Monitoring only works with
app The app to create a performance service |
1229 | * the default app.
|
1230 | * If not passed, uses the default app.
|
1231 | */
|
1232 | function performance(
|
1233 | app?: firebase.app.App
|
1234 | ): firebase.performance.Performance;
|
1235 |
|
1236 | /**
|
1237 | * Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
|
1238 | *
|
1239 | * @webonly
|
1240 | *
|
1241 | * @example
|
1242 | * ```javascript
|
1243 | * // Get the RemoteConfig instance for the default app
|
1244 | * const defaultRemoteConfig = firebase.remoteConfig();
|
1245 | * ```
|
1246 | *
|
1247 | * @param app The app to create a Remote Config service for. If not passed, uses the default app.
|
1248 | */
|
1249 | function remoteConfig(
|
1250 | app?: firebase.app.App
|
1251 | ): firebase.remoteConfig.RemoteConfig;
|
1252 |
|
1253 | /**
|
1254 | * Gets the {@link firebase.analytics.Analytics `Analytics`} service.
|
1255 | *
|
1256 | * `firebase.analytics()` can be called with no arguments to access the default
|
1257 | * app's {@link firebase.analytics.Analytics `Analytics`} service.
|
1258 | *
|
1259 | * @webonly
|
1260 | *
|
1261 | * @example
|
1262 | * ```javascript
|
1263 | * // Get the Analytics service for the default app
|
1264 | * const defaultAnalytics = firebase.analytics();
|
1265 | * ```
|
1266 | *
|
1267 | * @param app The app to create an analytics service for.
|
1268 | * If not passed, uses the default app.
|
1269 | */
|
1270 | function analytics(app?: firebase.app.App): firebase.analytics.Analytics;
|
1271 | }
|
1272 |
|
1273 | declare namespace firebase.app {
|
1274 | /**
|
1275 | * A Firebase App holds the initialization information for a collection of
|
1276 | * services.
|
1277 | *
|
1278 | * Do not call this constructor directly. Instead, use
|
1279 | * {@link firebase.initializeApp|`firebase.initializeApp()`} to create an app.
|
1280 | *
|
1281 | */
|
1282 | interface App {
|
1283 | /**
|
1284 | * Gets the {@link firebase.auth.Auth `Auth`} service for the current app.
|
1285 | *
|
1286 | * @example
|
1287 | * ```javascript
|
1288 | * var auth = app.auth();
|
1289 | * // The above is shorthand for:
|
1290 | * // var auth = firebase.auth(app);
|
1291 | * ```
|
1292 | */
|
1293 | auth(): firebase.auth.Auth;
|
1294 | /**
|
1295 | * Gets the {@link firebase.database.Database `Database`} service for the
|
1296 | * current app.
|
1297 | *
|
1298 | * @example
|
1299 | * ```javascript
|
1300 | * var database = app.database();
|
1301 | * // The above is shorthand for:
|
1302 | * // var database = firebase.database(app);
|
1303 | * ```
|
1304 | */
|
1305 | database(url?: string): firebase.database.Database;
|
1306 | /**
|
1307 | * Renders this app unusable and frees the resources of all associated
|
1308 | * services.
|
1309 | *
|
1310 | * @example
|
1311 | * ```javascript
|
1312 | * app.delete()
|
1313 | * .then(function() {
|
1314 | * console.log("App deleted successfully");
|
1315 | * })
|
1316 | * .catch(function(error) {
|
1317 | * console.log("Error deleting app:", error);
|
1318 | * });
|
1319 | * ```
|
1320 | */
|
1321 | delete(): Promise<any>;
|
1322 | /**
|
1323 | * Gets the {@link firebase.installations.Installations `Installations`} service for the
|
1324 | * current app.
|
1325 | *
|
1326 | * @webonly
|
1327 | *
|
1328 | * @example
|
1329 | * ```javascript
|
1330 | * const installations = app.installations();
|
1331 | * // The above is shorthand for:
|
1332 | * // const installations = firebase.installations(app);
|
1333 | * ```
|
1334 | */
|
1335 | installations(): firebase.installations.Installations;
|
1336 | /**
|
1337 | * Gets the {@link firebase.messaging.Messaging `Messaging`} service for the
|
1338 | * current app.
|
1339 | *
|
1340 | * @webonly
|
1341 | *
|
1342 | * @example
|
1343 | * ```javascript
|
1344 | * var messaging = app.messaging();
|
1345 | * // The above is shorthand for:
|
1346 | * // var messaging = firebase.messaging(app);
|
1347 | * ```
|
1348 | */
|
1349 | messaging(): firebase.messaging.Messaging;
|
1350 | /**
|
1351 | * The (read-only) name for this app.
|
1352 | *
|
1353 | * The default app's name is `"[DEFAULT]"`.
|
1354 | *
|
1355 | * @example
|
1356 | * ```javascript
|
1357 | * // The default app's name is "[DEFAULT]"
|
1358 | * firebase.initializeApp(defaultAppConfig);
|
1359 | * console.log(firebase.app().name); // "[DEFAULT]"
|
1360 | * ```
|
1361 | *
|
1362 | * @example
|
1363 | * ```javascript
|
1364 | * // A named app's name is what you provide to initializeApp()
|
1365 | * var otherApp = firebase.initializeApp(otherAppConfig, "other");
|
1366 | * console.log(otherApp.name); // "other"
|
1367 | * ```
|
1368 | */
|
1369 | name: string;
|
1370 | /**
|
1371 | * The (read-only) configuration options for this app. These are the original
|
1372 | * parameters given in
|
1373 | * {@link firebase.initializeApp `firebase.initializeApp()`}.
|
1374 | *
|
1375 | * @example
|
1376 | * ```javascript
|
1377 | * var app = firebase.initializeApp(config);
|
1378 | * console.log(app.options.databaseURL === config.databaseURL); // true
|
1379 | * ```
|
1380 | */
|
1381 | options: Object;
|
1382 | /**
|
1383 | * Gets the {@link firebase.storage.Storage `Storage`} service for the current
|
1384 | * app, optionally initialized with a custom storage bucket.
|
1385 | *
|
1386 | * @webonly
|
1387 | *
|
1388 | * @example
|
1389 | * ```javascript
|
1390 | * var storage = app.storage();
|
1391 | * // The above is shorthand for:
|
1392 | * // var storage = firebase.storage(app);
|
1393 | * ```
|
1394 | *
|
1395 | * @example
|
1396 | * ```javascript
|
1397 | * var storage = app.storage("gs://your-app.appspot.com");
|
1398 | * ```
|
1399 | *
|
1400 | * @param url The gs:// url to your Firebase Storage Bucket.
|
1401 | * If not passed, uses the app's default Storage Bucket.
|
1402 | */
|
1403 | storage(url?: string): firebase.storage.Storage;
|
1404 | firestore(): firebase.firestore.Firestore;
|
1405 | functions(region?: string): firebase.functions.Functions;
|
1406 | /**
|
1407 | * Gets the { firebase.performance.Performance `Performance`} service for the
|
1408 | * current app. If the current app is not the default one, throws an error.
|
1409 | *
|
1410 | *
|
1411 | *
|
1412 | *
|
1413 | * ```javascript
|
1414 | * const perf = app.performance();
|
1415 | * // The above is shorthand for:
|
1416 | * // const perf = firebase.performance(app);
|
1417 | * ```
|
1418 | */
|
1419 | performance(): firebase.performance.Performance;
|
1420 | /**
|
1421 | * Gets the {@link firebase.remoteConfig.RemoteConfig `RemoteConfig`} instance.
|
1422 | *
|
1423 | * @webonly
|
1424 | *
|
1425 | * @example
|
1426 | * ```javascript
|
1427 | * const rc = app.remoteConfig();
|
1428 | * // The above is shorthand for:
|
1429 | * // const rc = firebase.remoteConfig(app);
|
1430 | * ```
|
1431 | */
|
1432 | remoteConfig(): firebase.remoteConfig.RemoteConfig;
|
1433 | /**
|
1434 | * Gets the {@link firebase.analytics.Analytics `Analytics`} service for the
|
1435 | * current app. If the current app is not the default one, throws an error.
|
1436 | *
|
1437 | * @webonly
|
1438 | *
|
1439 | * @example
|
1440 | * ```javascript
|
1441 | * const analytics = app.analytics();
|
1442 | * // The above is shorthand for:
|
1443 | * // const analytics = firebase.analytics(app);
|
1444 | * ```
|
1445 | */
|
1446 | analytics(): firebase.analytics.Analytics;
|
1447 | }
|
1448 | }
|
1449 |
|
1450 | /**
|
1451 | * @webonly
|
1452 | */
|
1453 | declare namespace firebase.installations {
|
1454 | /**
|
1455 | * The Firebase Installations service interface.
|
1456 | *
|
1457 | * Do not call this constructor directly. Instead, use
|
1458 | * {@link firebase.installations `firebase.installations()`}.
|
1459 | */
|
1460 | export interface Installations {
|
1461 | /**
|
1462 | * Creates a Firebase Installation if there isn't one for the app and
|
1463 | * returns the Installation ID.
|
1464 | *
|
1465 | * @return Firebase Installation ID
|
1466 | */
|
1467 | getId(): Promise<string>;
|
1468 |
|
1469 | /**
|
1470 | * Returns an Authentication Token for the current Firebase Installation.
|
1471 | *
|
1472 | * @return Firebase Installation Authentication Token
|
1473 | */
|
1474 | getToken(forceRefresh?: boolean): Promise<string>;
|
1475 |
|
1476 | /**
|
1477 | * Deletes the Firebase Installation and all associated data.
|
1478 | */
|
1479 | delete(): Promise<void>;
|
1480 |
|
1481 | /**
|
1482 | * Sets a new callback that will get called when Installlation ID changes.
|
1483 | * Returns an unsubscribe function that will remove the callback when called.
|
1484 | */
|
1485 | onIdChange(callback: (installationId: string) => void): () => void;
|
1486 | }
|
1487 | }
|
1488 |
|
1489 | /**
|
1490 | * @webonly
|
1491 | */
|
1492 | declare namespace firebase.performance {
|
1493 | /**
|
1494 | * The Firebase Performance Monitoring service interface.
|
1495 | *
|
1496 | * Do not call this constructor directly. Instead, use
|
1497 | * {@link firebase.performance `firebase.performance()`}.
|
1498 | */
|
1499 | export interface Performance {
|
1500 | /**
|
1501 | * Creates an uninitialized instance of {@link firebase.performance.Trace `trace`} and returns
|
1502 | * it.
|
1503 | *
|
1504 | * @param traceName The name of the trace instance.
|
1505 | * @return The Trace instance.
|
1506 | */
|
1507 | trace(traceName: string): Trace;
|
1508 |
|
1509 | /**
|
1510 | * Controls the logging of automatic traces and HTTP/S network monitoring.
|
1511 | */
|
1512 | instrumentationEnabled: boolean;
|
1513 | /**
|
1514 | * Controls the logging of custom traces.
|
1515 | */
|
1516 | dataCollectionEnabled: boolean;
|
1517 | }
|
1518 |
|
1519 | export interface Trace {
|
1520 | /**
|
1521 | * Starts the timing for the {@link firebase.performance.Trace `trace`} instance.
|
1522 | */
|
1523 | start(): void;
|
1524 | /**
|
1525 | * Stops the timing of the {@link firebase.performance.Trace `trace`} instance and logs the
|
1526 | * data of the instance.
|
1527 | */
|
1528 | stop(): void;
|
1529 | /**
|
1530 | * Records a {@link firebase.performance.Trace `trace`} from given parameters. This provides a
|
1531 | * direct way to use {@link firebase.performance.Trace `trace`} without a need to start/stop.
|
1532 | * This is useful for use cases in which the {@link firebase.performance.Trace `trace`} cannot
|
1533 | * directly be used (e.g. if the duration was captured before the Performance SDK was loaded).
|
1534 | *
|
1535 | * @param startTime Trace start time since epoch in millisec.
|
1536 | * @param duration The duraction of the trace in millisec.
|
1537 | * @param options An object which can optionally hold maps of custom metrics and
|
1538 | * custom attributes.
|
1539 | */
|
1540 | record(
|
1541 | startTime: number,
|
1542 | duration: number,
|
1543 | options?: {
|
1544 | metrics?: { [key: string]: number };
|
1545 | attributes?: { [key: string]: string };
|
1546 | }
|
1547 | ): void;
|
1548 | /**
|
1549 | * Adds to the value of a custom metric. If a custom metric with the provided name does not
|
1550 | * exist, it creates one with that name and the value equal to the given number.
|
1551 | *
|
1552 | * @param metricName The name of the custom metric.
|
1553 | * @param num The number to be added to the value of the custom metric. If not provided, it
|
1554 | * uses a default value of one.
|
1555 | */
|
1556 | incrementMetric(metricName: string, num?: number): void;
|
1557 | /**
|
1558 | * Sets the value of the specified custom metric to the given number regardless of whether
|
1559 | * a metric with that name already exists on the {@link firebase.performance.Trace `trace`}
|
1560 | * instance or not.
|
1561 | *
|
1562 | * @param metricName Name of the custom metric.
|
1563 | * @param num Value to of the custom metric.
|
1564 | */
|
1565 | putMetric(metricName: string, num: number): void;
|
1566 | /**
|
1567 | * Returns the value of the custom metric by that name. If a custom metric with that name does
|
1568 | * not exist returns zero.
|
1569 | *
|
1570 | * @param metricName Name of the custom metric.
|
1571 | */
|
1572 | getMetric(metricName: string): number;
|
1573 | /**
|
1574 | * Set a custom attribute of a {@link firebase.performance.Trace `trace`} to a certain value.
|
1575 | *
|
1576 | * @param attr Name of the custom attribute.
|
1577 | * @param value Value of the custom attribute.
|
1578 | */
|
1579 | putAttribute(attr: string, value: string): void;
|
1580 | /**
|
1581 | * Retrieves the value that the custom attribute is set to.
|
1582 | *
|
1583 | * @param attr Name of the custom attribute.
|
1584 | */
|
1585 | getAttribute(attr: string): string | undefined;
|
1586 | /**
|
1587 | * Removes the specified custom attribute from a {@link firebase.performance.Trace `trace`}
|
1588 | * instance.
|
1589 | *
|
1590 | * @param attr Name of the custom attribute.
|
1591 | */
|
1592 |
|
1593 | removeAttribute(attr: string): void;
|
1594 | /**
|
1595 | * Returns a map of all custom attributes of a {@link firebase.performance.Trace `trace`}
|
1596 | * instance.
|
1597 | */
|
1598 | getAttributes(): { [key: string]: string };
|
1599 | }
|
1600 | }
|
1601 |
|
1602 | /**
|
1603 | * @webonly
|
1604 | */
|
1605 | declare namespace firebase.remoteConfig {
|
1606 | /**
|
1607 | * The Firebase Remote Config service interface.
|
1608 | *
|
1609 | * Do not call this constructor directly. Instead, use
|
1610 | * {@link firebase.remoteConfig `firebase.remoteConfig()`}.
|
1611 | */
|
1612 | export interface RemoteConfig {
|
1613 | /**
|
1614 | * Defines configuration for the Remote Config SDK.
|
1615 | */
|
1616 | settings: Settings;
|
1617 |
|
1618 | /**
|
1619 | * Object containing default values for conigs.
|
1620 | */
|
1621 | defaultConfig: { [key: string]: string | number | boolean };
|
1622 |
|
1623 | /**
|
1624 | * The Unix timestamp in milliseconds of the last <i>successful</i> fetch, or negative one if
|
1625 | * the {@link RemoteConfig} instance either hasn't fetched or initialization
|
1626 | * is incomplete.
|
1627 | */
|
1628 | fetchTimeMillis: number;
|
1629 |
|
1630 | /**
|
1631 | * The status of the last fetch <i>attempt</i>.
|
1632 | */
|
1633 | lastFetchStatus: FetchStatus;
|
1634 |
|
1635 | /**
|
1636 | * Makes the last fetched config available to the getters.
|
1637 | * Returns a promise which resolves to true if the current call activated the fetched configs.
|
1638 | * If the fetched configs were already activated, the promise will resolve to false.
|
1639 | */
|
1640 | activate(): Promise<boolean>;
|
1641 |
|
1642 | /**
|
1643 | * Ensures the last activated config are available to the getters.
|
1644 | */
|
1645 | ensureInitialized(): Promise<void>;
|
1646 |
|
1647 | /**
|
1648 | * Fetches and caches configuration from the Remote Config service.
|
1649 | */
|
1650 | fetch(): Promise<void>;
|
1651 |
|
1652 | /**
|
1653 | * Performs fetch and activate operations, as a convenience.
|
1654 | * Returns a promise which resolves to true if the current call activated the fetched configs.
|
1655 | * If the fetched configs were already activated, the promise will resolve to false.
|
1656 | */
|
1657 | fetchAndActivate(): Promise<boolean>;
|
1658 |
|
1659 | /**
|
1660 | * Gets all config.
|
1661 | */
|
1662 | getAll(): { [key: string]: Value };
|
1663 |
|
1664 | /**
|
1665 | * Gets the value for the given key as a boolean.
|
1666 | *
|
1667 | * Convenience method for calling <code>remoteConfig.getValue(key).asBoolean()</code>.
|
1668 | */
|
1669 | getBoolean(key: string): boolean;
|
1670 |
|
1671 | /**
|
1672 | * Gets the value for the given key as a number.
|
1673 | *
|
1674 | * Convenience method for calling <code>remoteConfig.getValue(key).asNumber()</code>.
|
1675 | */
|
1676 | getNumber(key: string): number;
|
1677 |
|
1678 | /**
|
1679 | * Gets the value for the given key as a String.
|
1680 | *
|
1681 | * Convenience method for calling <code>remoteConfig.getValue(key).asString()</code>.
|
1682 | */
|
1683 | getString(key: string): string;
|
1684 |
|
1685 | /**
|
1686 | * Gets the {@link Value} for the given key.
|
1687 | */
|
1688 | getValue(key: string): Value;
|
1689 |
|
1690 | /**
|
1691 | * Defines the log level to use.
|
1692 | */
|
1693 | setLogLevel(logLevel: LogLevel): void;
|
1694 | }
|
1695 |
|
1696 | /**
|
1697 | * Indicates the source of a value.
|
1698 | *
|
1699 | * <ul>
|
1700 | * <li>"static" indicates the value was defined by a static constant.</li>
|
1701 | * <li>"default" indicates the value was defined by default config.</li>
|
1702 | * <li>"remote" indicates the value was defined by fetched config.</li>
|
1703 | * </ul>
|
1704 | */
|
1705 | export type ValueSource = 'static' | 'default' | 'remote';
|
1706 |
|
1707 | /**
|
1708 | * Wraps a value with metadata and type-safe getters.
|
1709 | */
|
1710 | export interface Value {
|
1711 | /**
|
1712 | * Gets the value as a boolean.
|
1713 | *
|
1714 | * The following values (case insensitive) are interpreted as true:
|
1715 | * "1", "true", "t", "yes", "y", "on". Other values are interpreted as false.
|
1716 | */
|
1717 | asBoolean(): boolean;
|
1718 |
|
1719 | /**
|
1720 | * Gets the value as a number. Comparable to calling <code>Number(value) || 0</code>.
|
1721 | */
|
1722 | asNumber(): number;
|
1723 |
|
1724 | /**
|
1725 | * Gets the value as a string.
|
1726 | */
|
1727 | asString(): string;
|
1728 |
|
1729 | /**
|
1730 | * Gets the {@link ValueSource} for the given key.
|
1731 | */
|
1732 | getSource(): ValueSource;
|
1733 | }
|
1734 |
|
1735 | /**
|
1736 | * Defines configuration options for the Remote Config SDK.
|
1737 | */
|
1738 | export interface Settings {
|
1739 | /**
|
1740 | * Defines the maximum age in milliseconds of an entry in the config cache before
|
1741 | * it is considered stale. Defaults to 43200000 (Twelve hours).
|
1742 | */
|
1743 | minimumFetchIntervalMillis: number;
|
1744 |
|
1745 | /**
|
1746 | * Defines the maximum amount of milliseconds to wait for a response when fetching
|
1747 | * configuration from the Remote Config server. Defaults to 60000 (One minute).
|
1748 | */
|
1749 | fetchTimeoutMillis: number;
|
1750 | }
|
1751 |
|
1752 | /**
|
1753 | * Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
|
1754 | *
|
1755 | * <ul>
|
1756 | * <li>"no-fetch-yet" indicates the {@link RemoteConfig} instance has not yet attempted
|
1757 | * to fetch config, or that SDK initialization is incomplete.</li>
|
1758 | * <li>"success" indicates the last attempt succeeded.</li>
|
1759 | * <li>"failure" indicates the last attempt failed.</li>
|
1760 | * <li>"throttle" indicates the last attempt was rate-limited.</li>
|
1761 | * </ul>
|
1762 | */
|
1763 | export type FetchStatus = 'no-fetch-yet' | 'success' | 'failure' | 'throttle';
|
1764 |
|
1765 | /**
|
1766 | * Defines levels of Remote Config logging.
|
1767 | */
|
1768 | export type LogLevel = 'debug' | 'error' | 'silent';
|
1769 | }
|
1770 |
|
1771 | declare namespace firebase.functions {
|
1772 | /**
|
1773 | * An HttpsCallableResult wraps a single result from a function call.
|
1774 | */
|
1775 | export interface HttpsCallableResult {
|
1776 | readonly data: any;
|
1777 | }
|
1778 | /**
|
1779 | * An HttpsCallable is a reference to a "callable" http trigger in
|
1780 | * Google Cloud Functions.
|
1781 | */
|
1782 | export interface HttpsCallable {
|
1783 | (data?: any): Promise<HttpsCallableResult>;
|
1784 | }
|
1785 | export interface HttpsCallableOptions {
|
1786 | timeout?: number;
|
1787 | }
|
1788 | /**
|
1789 | * The Cloud Functions for Firebase service interface.
|
1790 | *
|
1791 | * Do not call this constructor directly. Instead, use
|
1792 | * {@link firebase.functions `firebase.functions()`}.
|
1793 | */
|
1794 | export class Functions {
|
1795 | private constructor();
|
1796 | /**
|
1797 | * Changes this instance to point to a Cloud Functions emulator running
|
1798 | * locally. See https://firebase.google.com/docs/functions/local-emulator
|
1799 | *
|
1800 | * @param origin The origin of the local emulator, such as
|
1801 | * "http://localhost:5005".
|
1802 | */
|
1803 | useFunctionsEmulator(url: string): void;
|
1804 | /**
|
1805 | * Gets an `HttpsCallable` instance that refers to the function with the given
|
1806 | * name.
|
1807 | *
|
1808 | * @param name The name of the https callable function.
|
1809 | * @param options The options for this HttpsCallable instance.
|
1810 | * @return The `HttpsCallable` instance.
|
1811 | */
|
1812 | httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable;
|
1813 | }
|
1814 | /**
|
1815 | * The set of Firebase Functions status codes. The codes are the same at the
|
1816 | * ones exposed by gRPC here:
|
1817 | * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
|
1818 | *
|
1819 | * Possible values:
|
1820 | * - 'cancelled': The operation was cancelled (typically by the caller).
|
1821 | * - 'unknown': Unknown error or an error from a different error domain.
|
1822 | * - 'invalid-argument': Client specified an invalid argument. Note that this
|
1823 | * differs from 'failed-precondition'. 'invalid-argument' indicates
|
1824 | * arguments that are problematic regardless of the state of the system
|
1825 | * (e.g. an invalid field name).
|
1826 | * - 'deadline-exceeded': Deadline expired before operation could complete.
|
1827 | * For operations that change the state of the system, this error may be
|
1828 | * returned even if the operation has completed successfully. For example,
|
1829 | * a successful response from a server could have been delayed long enough
|
1830 | * for the deadline to expire.
|
1831 | * - 'not-found': Some requested document was not found.
|
1832 | * - 'already-exists': Some document that we attempted to create already
|
1833 | * exists.
|
1834 | * - 'permission-denied': The caller does not have permission to execute the
|
1835 | * specified operation.
|
1836 | * - 'resource-exhausted': Some resource has been exhausted, perhaps a
|
1837 | * per-user quota, or perhaps the entire file system is out of space.
|
1838 | * - 'failed-precondition': Operation was rejected because the system is not
|
1839 | * in a state required for the operation's execution.
|
1840 | * - 'aborted': The operation was aborted, typically due to a concurrency
|
1841 | * issue like transaction aborts, etc.
|
1842 | * - 'out-of-range': Operation was attempted past the valid range.
|
1843 | * - 'unimplemented': Operation is not implemented or not supported/enabled.
|
1844 | * - 'internal': Internal errors. Means some invariants expected by
|
1845 | * underlying system has been broken. If you see one of these errors,
|
1846 | * something is very broken.
|
1847 | * - 'unavailable': The service is currently unavailable. This is most likely
|
1848 | * a transient condition and may be corrected by retrying with a backoff.
|
1849 | * - 'data-loss': Unrecoverable data loss or corruption.
|
1850 | * - 'unauthenticated': The request does not have valid authentication
|
1851 | * credentials for the operation.
|
1852 | */
|
1853 | export type FunctionsErrorCode =
|
1854 | | 'ok'
|
1855 | | 'cancelled'
|
1856 | | 'unknown'
|
1857 | | 'invalid-argument'
|
1858 | | 'deadline-exceeded'
|
1859 | | 'not-found'
|
1860 | | 'already-exists'
|
1861 | | 'permission-denied'
|
1862 | | 'resource-exhausted'
|
1863 | | 'failed-precondition'
|
1864 | | 'aborted'
|
1865 | | 'out-of-range'
|
1866 | | 'unimplemented'
|
1867 | | 'internal'
|
1868 | | 'unavailable'
|
1869 | | 'data-loss'
|
1870 | | 'unauthenticated';
|
1871 | export interface HttpsError extends Error {
|
1872 | /**
|
1873 | * A standard error code that will be returned to the client. This also
|
1874 | * determines the HTTP status code of the response, as defined in code.proto.
|
1875 | */
|
1876 | readonly code: FunctionsErrorCode;
|
1877 | /**
|
1878 | * Extra data to be converted to JSON and included in the error response.
|
1879 | */
|
1880 | readonly details?: any;
|
1881 | }
|
1882 | }
|
1883 |
|
1884 | declare namespace firebase.auth {
|
1885 | /**
|
1886 | * A utility class to parse email action URLs.
|
1887 | */
|
1888 | class ActionCodeURL {
|
1889 | private constructor();
|
1890 | /**
|
1891 | * The API key of the email action link.
|
1892 | */
|
1893 | apiKey: string;
|
1894 | /**
|
1895 | * The action code of the email action link.
|
1896 | */
|
1897 | code: string;
|
1898 | /**
|
1899 | * The continue URL of the email action link. Null if not provided.
|
1900 | */
|
1901 | continueUrl: string | null;
|
1902 | /**
|
1903 | * The language code of the email action link. Null if not provided.
|
1904 | */
|
1905 | languageCode: string | null;
|
1906 | /**
|
1907 | * The action performed by the email action link. It returns from one
|
1908 | * of the types from { firebase.auth.ActionCodeInfo}.
|
1909 | */
|
1910 | operation: firebase.auth.ActionCodeInfo.Operation;
|
1911 | /**
|
1912 | * Parses the email action link string and returns an ActionCodeURL object
|
1913 | * if the link is valid, otherwise returns null.
|
1914 | *
|
1915 | * @param link The email action link string.
|
1916 | * @return The ActionCodeURL object, or null if the link is invalid.
|
1917 | */
|
1918 | static parseLink(link: string): firebase.auth.ActionCodeURL | null;
|
1919 | /**
|
1920 | * The tenant ID of the email action link. Null if the email action
|
1921 | * is from the parent project.
|
1922 | */
|
1923 | tenantId: string | null;
|
1924 | }
|
1925 | /**
|
1926 | * A response from {@link firebase.auth.Auth.checkActionCode}.
|
1927 | */
|
1928 | interface ActionCodeInfo {
|
1929 | /**
|
1930 | * The data associated with the action code.
|
1931 | *
|
1932 | * For the `PASSWORD_RESET`, `VERIFY_EMAIL`, and `RECOVER_EMAIL` actions, this object
|
1933 | * contains an `email` field with the address the email was sent to.
|
1934 | *
|
1935 | * For the RECOVER_EMAIL action, which allows a user to undo an email address
|
1936 | * change, this object also contains a `previousEmail` field with the user account's
|
1937 | * current email address. After the action completes, the user's email address will
|
1938 | * revert to the value in the `email` field from the value in `previousEmail` field.
|
1939 | *
|
1940 | * For the VERIFY_AND_CHANGE_EMAIL action, which allows a user to verify the email
|
1941 | * before updating it, this object contains a `previousEmail` field with the user
|
1942 | * account's email address before updating. After the action completes, the user's
|
1943 | * email address will be updated to the value in the `email` field from the value
|
1944 | * in `previousEmail` field.
|
1945 | *
|
1946 | * For the REVERT_SECOND_FACTOR_ADDITION action, which allows a user to unenroll
|
1947 | * a newly added second factor, this object contains a `multiFactorInfo` field with
|
1948 | * the information about the second factor. For phone second factor, the
|
1949 | * `multiFactorInfo` is a {@link firebase.auth.Auth.PhoneMultiFactorInfo} object,
|
1950 | * which contains the phone number.
|
1951 | */
|
1952 | data: {
|
1953 | email?: string | null;
|
1954 | /**
|
1955 | * @deprecated
|
1956 | * This field is deprecated in favor of previousEmail.
|
1957 | */
|
1958 | fromEmail?: string | null;
|
1959 | multiFactorInfo?: firebase.auth.MultiFactorInfo | null;
|
1960 | previousEmail?: string | null;
|
1961 | };
|
1962 | /**
|
1963 | * The type of operation that generated the action code. This could be:
|
1964 | * <ul>
|
1965 | * <li>`EMAIL_SIGNIN`: email sign in code generated via
|
1966 | * {@link firebase.auth.Auth.sendSignInLinkToEmail}.</li>
|
1967 | * <li>`PASSWORD_RESET`: password reset code generated via
|
1968 | * {@link firebase.auth.Auth.sendPasswordResetEmail}.</li>
|
1969 | * <li>`RECOVER_EMAIL`: email change revocation code generated via
|
1970 | * {@link firebase.User.updateEmail}.</li>
|
1971 | * <li>`REVERT_SECOND_FACTOR_ADDITION`: revert second factor addition
|
1972 | * code generated via
|
1973 | * {@link firebase.User.MultiFactorUser.enroll}.</li>
|
1974 | * <li>`VERIFY_AND_CHANGE_EMAIL`: verify and change email code generated
|
1975 | * via {@link firebase.User.verifyBeforeUpdateEmail}.</li>
|
1976 | * <li>`VERIFY_EMAIL`: email verification code generated via
|
1977 | * {@link firebase.User.sendEmailVerification}.</li>
|
1978 | * </ul>
|
1979 | */
|
1980 | operation: string;
|
1981 | }
|
1982 |
|
1983 | /**
|
1984 | * This is the interface that defines the required continue/state URL with
|
1985 | * optional Android and iOS bundle identifiers.
|
1986 | * The action code setting fields are:
|
1987 | * <ul>
|
1988 | * <li><p>url: Sets the link continue/state URL, which has different meanings
|
1989 | * in different contexts:</p>
|
1990 | * <ul>
|
1991 | * <li>When the link is handled in the web action widgets, this is the deep
|
1992 | * link in the continueUrl query parameter.</li>
|
1993 | * <li>When the link is handled in the app directly, this is the continueUrl
|
1994 | * query parameter in the deep link of the Dynamic Link.</li>
|
1995 | * </ul>
|
1996 | * </li>
|
1997 | * <li>iOS: Sets the iOS bundle ID. This will try to open the link in an iOS app
|
1998 | * if it is installed.</li>
|
1999 | * <li>android: Sets the Android package name. This will try to open the link in
|
2000 | * an android app if it is installed. If installApp is passed, it specifies
|
2001 | * whether to install the Android app if the device supports it and the app
|
2002 | * is not already installed. If this field is provided without a
|
2003 | * packageName, an error is thrown explaining that the packageName must be
|
2004 | * provided in conjunction with this field.
|
2005 | * If minimumVersion is specified, and an older version of the app is
|
2006 | * installed, the user is taken to the Play Store to upgrade the app.</li>
|
2007 | * <li>handleCodeInApp: The default is false. When set to true, the action code
|
2008 | * link will be be sent as a Universal Link or Android App Link and will be
|
2009 | * opened by the app if installed. In the false case, the code will be sent
|
2010 | * to the web widget first and then on continue will redirect to the app if
|
2011 | * installed.</li>
|
2012 | * </ul>
|
2013 | */
|
2014 | type ActionCodeSettings = {
|
2015 | android?: {
|
2016 | installApp?: boolean;
|
2017 | minimumVersion?: string;
|
2018 | packageName: string;
|
2019 | };
|
2020 | handleCodeInApp?: boolean;
|
2021 | iOS?: { bundleId: string };
|
2022 | url: string;
|
2023 | dynamicLinkDomain?: string;
|
2024 | };
|
2025 |
|
2026 | /**
|
2027 | * A structure containing additional user information from a federated identity
|
2028 | * provider.
|
2029 | */
|
2030 | type AdditionalUserInfo = {
|
2031 | isNewUser: boolean;
|
2032 | profile: Object | null;
|
2033 | providerId: string;
|
2034 | username?: string | null;
|
2035 | };
|
2036 |
|
2037 | /**
|
2038 | * A verifier for domain verification and abuse prevention. Currently, the
|
2039 | * only implementation is {@link firebase.auth.RecaptchaVerifier}.
|
2040 | */
|
2041 | interface ApplicationVerifier {
|
2042 | /**
|
2043 | * Identifies the type of application verifier (e.g. "recaptcha").
|
2044 | */
|
2045 | type: string;
|
2046 | /**
|
2047 | * Executes the verification process.
|
2048 | * @return A Promise for a token that can be used to
|
2049 | * assert the validity of a request.
|
2050 | */
|
2051 | verify(): Promise<string>;
|
2052 | }
|
2053 |
|
2054 | /**
|
2055 | * Interface representing an Auth instance's settings, currently used for
|
2056 | * enabling/disabling app verification for phone Auth testing.
|
2057 | */
|
2058 | interface AuthSettings {
|
2059 | /**
|
2060 | * When set, this property disables app verification for the purpose of testing
|
2061 | * phone authentication. For this property to take effect, it needs to be set
|
2062 | * before rendering a reCAPTCHA app verifier. When this is disabled, a
|
2063 | * mock reCAPTCHA is rendered instead. This is useful for manual testing during
|
2064 | * development or for automated integration tests.
|
2065 | *
|
2066 | * In order to use this feature, you will need to
|
2067 | * {@link https://firebase.google.com/docs/auth/web/phone-auth#test-with-whitelisted-phone-numbers
|
2068 | * whitelist your phone number} via the
|
2069 | * Firebase Console.
|
2070 | *
|
2071 | * The default value is false (app verification is enabled).
|
2072 | */
|
2073 | appVerificationDisabledForTesting: boolean;
|
2074 | }
|
2075 |
|
2076 | /**
|
2077 | * The Firebase Auth service interface.
|
2078 | *
|
2079 | * Do not call this constructor directly. Instead, use
|
2080 | * {@link firebase.auth `firebase.auth()`}.
|
2081 | *
|
2082 | * See
|
2083 | * {@link https://firebase.google.com/docs/auth/ Firebase Authentication}
|
2084 | * for a full guide on how to use the Firebase Auth service.
|
2085 | *
|
2086 | */
|
2087 | interface Auth {
|
2088 | /**
|
2089 | * The {@link firebase.app.App app} associated with the `Auth` service
|
2090 | * instance.
|
2091 | *
|
2092 | * @example
|
2093 | * ```javascript
|
2094 | * var app = auth.app;
|
2095 | * ```
|
2096 | */
|
2097 | app: firebase.app.App;
|
2098 | /**
|
2099 | * Applies a verification code sent to the user by email or other out-of-band
|
2100 | * mechanism.
|
2101 | *
|
2102 | * <h4>Error Codes</h4>
|
2103 | * <dl>
|
2104 | * <dt>auth/expired-action-code</dt>
|
2105 | * <dd>Thrown if the action code has expired.</dd>
|
2106 | * <dt>auth/invalid-action-code</dt>
|
2107 | * <dd>Thrown if the action code is invalid. This can happen if the code is
|
2108 | * malformed or has already been used.</dd>
|
2109 | * <dt>auth/user-disabled</dt>
|
2110 | * <dd>Thrown if the user corresponding to the given action code has been
|
2111 | * disabled.</dd>
|
2112 | * <dt>auth/user-not-found</dt>
|
2113 | * <dd>Thrown if there is no user corresponding to the action code. This may
|
2114 | * have happened if the user was deleted between when the action code was
|
2115 | * issued and when this method was called.</dd>
|
2116 | * </dl>
|
2117 | *
|
2118 | * @param code A verification code sent to the user.
|
2119 | */
|
2120 | applyActionCode(code: string): Promise<void>;
|
2121 | /**
|
2122 | * Checks a verification code sent to the user by email or other out-of-band
|
2123 | * mechanism.
|
2124 | *
|
2125 | * Returns metadata about the code.
|
2126 | *
|
2127 | * <h4>Error Codes</h4>
|
2128 | * <dl>
|
2129 | * <dt>auth/expired-action-code</dt>
|
2130 | * <dd>Thrown if the action code has expired.</dd>
|
2131 | * <dt>auth/invalid-action-code</dt>
|
2132 | * <dd>Thrown if the action code is invalid. This can happen if the code is
|
2133 | * malformed or has already been used.</dd>
|
2134 | * <dt>auth/user-disabled</dt>
|
2135 | * <dd>Thrown if the user corresponding to the given action code has been
|
2136 | * disabled.</dd>
|
2137 | * <dt>auth/user-not-found</dt>
|
2138 | * <dd>Thrown if there is no user corresponding to the action code. This may
|
2139 | * have happened if the user was deleted between when the action code was
|
2140 | * issued and when this method was called.</dd>
|
2141 | * </dl>
|
2142 | *
|
2143 | * @param code A verification code sent to the user.
|
2144 | */
|
2145 | checkActionCode(code: string): Promise<firebase.auth.ActionCodeInfo>;
|
2146 | /**
|
2147 | * Completes the password reset process, given a confirmation code and new
|
2148 | * password.
|
2149 | *
|
2150 | * <h4>Error Codes</h4>
|
2151 | * <dl>
|
2152 | * <dt>auth/expired-action-code</dt>
|
2153 | * <dd>Thrown if the password reset code has expired.</dd>
|
2154 | * <dt>auth/invalid-action-code</dt>
|
2155 | * <dd>Thrown if the password reset code is invalid. This can happen if the
|
2156 | * code is malformed or has already been used.</dd>
|
2157 | * <dt>auth/user-disabled</dt>
|
2158 | * <dd>Thrown if the user corresponding to the given password reset code has
|
2159 | * been disabled.</dd>
|
2160 | * <dt>auth/user-not-found</dt>
|
2161 | * <dd>Thrown if there is no user corresponding to the password reset code. This
|
2162 | * may have happened if the user was deleted between when the code was
|
2163 | * issued and when this method was called.</dd>
|
2164 | * <dt>auth/weak-password</dt>
|
2165 | * <dd>Thrown if the new password is not strong enough.</dd>
|
2166 | * </dl>
|
2167 | *
|
2168 | * @param code The confirmation code send via email to the user.
|
2169 | * @param newPassword The new password.
|
2170 | */
|
2171 | confirmPasswordReset(code: string, newPassword: string): Promise<void>;
|
2172 |
|
2173 | /**
|
2174 | * Creates a new user account associated with the specified email address and
|
2175 | * password.
|
2176 | *
|
2177 | * On successful creation of the user account, this user will also be
|
2178 | * signed in to your application.
|
2179 | *
|
2180 | * User account creation can fail if the account already exists or the password
|
2181 | * is invalid.
|
2182 | *
|
2183 | * Note: The email address acts as a unique identifier for the user and
|
2184 | * enables an email-based password reset. This function will create
|
2185 | * a new user account and set the initial user password.
|
2186 | *
|
2187 | * <h4>Error Codes</h4>
|
2188 | * <dl>
|
2189 | * <dt>auth/email-already-in-use</dt>
|
2190 | * <dd>Thrown if there already exists an account with the given email
|
2191 | * address.</dd>
|
2192 | * <dt>auth/invalid-email</dt>
|
2193 | * <dd>Thrown if the email address is not valid.</dd>
|
2194 | * <dt>auth/operation-not-allowed</dt>
|
2195 | * <dd>Thrown if email/password accounts are not enabled. Enable email/password
|
2196 | * accounts in the Firebase Console, under the Auth tab.</dd>
|
2197 | * <dt>auth/weak-password</dt>
|
2198 | * <dd>Thrown if the password is not strong enough.</dd>
|
2199 | * </dl>
|
2200 | *
|
2201 | * @example
|
2202 | * ```javascript
|
2203 | * firebase.auth().createUserWithEmailAndPassword(email, password)
|
2204 | * .catch(function(error) {
|
2205 | * // Handle Errors here.
|
2206 | * var errorCode = error.code;
|
2207 | * var errorMessage = error.message;
|
2208 | * if (errorCode == 'auth/weak-password') {
|
2209 | * alert('The password is too weak.');
|
2210 | * } else {
|
2211 | * alert(errorMessage);
|
2212 | * }
|
2213 | * console.log(error);
|
2214 | * });
|
2215 | * ```
|
2216 | * @param email The user's email address.
|
2217 | * @param password The user's chosen password.
|
2218 | */
|
2219 | createUserWithEmailAndPassword(
|
2220 | email: string,
|
2221 | password: string
|
2222 | ): Promise<firebase.auth.UserCredential>;
|
2223 | /**
|
2224 | * The currently signed-in user (or null).
|
2225 | */
|
2226 | currentUser: firebase.User | null;
|
2227 |
|
2228 | /**
|
2229 | * Gets the list of possible sign in methods for the given email address. This
|
2230 | * is useful to differentiate methods of sign-in for the same provider,
|
2231 | * eg. `EmailAuthProvider` which has 2 methods of sign-in, email/password and
|
2232 | * email/link.
|
2233 | *
|
2234 | * <h4>Error Codes</h4>
|
2235 | * <dl>
|
2236 | * <dt>auth/invalid-email</dt>
|
2237 | * <dd>Thrown if the email address is not valid.</dd>
|
2238 | * </dl>
|
2239 | */
|
2240 | fetchSignInMethodsForEmail(email: string): Promise<Array<string>>;
|
2241 |
|
2242 | /**
|
2243 | * Checks if an incoming link is a sign-in with email link.
|
2244 | */
|
2245 | isSignInWithEmailLink(emailLink: string): boolean;
|
2246 | /**
|
2247 | * Returns a UserCredential from the redirect-based sign-in flow.
|
2248 | *
|
2249 | * If sign-in succeeded, returns the signed in user. If sign-in was
|
2250 | * unsuccessful, fails with an error. If no redirect operation was called,
|
2251 | * returns a UserCredential with a null User.
|
2252 | *
|
2253 | * <h4>Error Codes</h4>
|
2254 | * <dl>
|
2255 | * <dt>auth/account-exists-with-different-credential</dt>
|
2256 | * <dd>Thrown if there already exists an account with the email address
|
2257 | * asserted by the credential. Resolve this by calling
|
2258 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
|
2259 | * and then asking the user to sign in using one of the returned providers.
|
2260 | * Once the user is signed in, the original credential retrieved from the
|
2261 | * error.credential can be linked to the user with
|
2262 | * {@link firebase.User.linkWithCredential} to prevent the user from signing
|
2263 | * in again to the original provider via popup or redirect. If you are using
|
2264 | * redirects for sign in, save the credential in session storage and then
|
2265 | * retrieve on redirect and repopulate the credential using for example
|
2266 | * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
|
2267 | * credential provider id and complete the link.</dd>
|
2268 | * <dt>auth/auth-domain-config-required</dt>
|
2269 | * <dd>Thrown if authDomain configuration is not provided when calling
|
2270 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
2271 | * determining and passing that field.</dd>
|
2272 | * <dt>auth/credential-already-in-use</dt>
|
2273 | * <dd>Thrown if the account corresponding to the credential already exists
|
2274 | * among your users, or is already linked to a Firebase User.
|
2275 | * For example, this error could be thrown if you are upgrading an anonymous
|
2276 | * user to a Google user by linking a Google credential to it and the Google
|
2277 | * credential used is already associated with an existing Firebase Google
|
2278 | * user.
|
2279 | * An <code>error.email</code> and <code>error.credential</code>
|
2280 | * ({@link firebase.auth.AuthCredential}) fields are also provided. You can
|
2281 | * recover from this error by signing in with that credential directly via
|
2282 | * {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
2283 | * <dt>auth/email-already-in-use</dt>
|
2284 | * <dd>Thrown if the email corresponding to the credential already exists
|
2285 | * among your users. When thrown while linking a credential to an existing
|
2286 | * user, an <code>error.email</code> and <code>error.credential</code>
|
2287 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
2288 | * You have to link the credential to the existing user with that email if
|
2289 | * you wish to continue signing in with that credential. To do so, call
|
2290 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
2291 | * <code>error.email</code> via one of the providers returned and then
|
2292 | * {@link firebase.User.linkWithCredential} the original credential to that
|
2293 | * newly signed in user.</dd>
|
2294 | * <dt>auth/operation-not-allowed</dt>
|
2295 | * <dd>Thrown if the type of account corresponding to the credential
|
2296 | * is not enabled. Enable the account type in the Firebase Console, under
|
2297 | * the Auth tab.</dd>
|
2298 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
2299 | * <dd>Thrown if this operation is not supported in the environment your
|
2300 | * application is running on. "location.protocol" must be http or https.
|
2301 | * </dd>
|
2302 | * <dt>auth/timeout</dt>
|
2303 | * <dd>Thrown typically if the app domain is not authorized for OAuth operations
|
2304 | * for your Firebase project. Edit the list of authorized domains from the
|
2305 | * Firebase console.</dd>
|
2306 | * </dl>
|
2307 | *
|
2308 | * @webonly
|
2309 | *
|
2310 | * @example
|
2311 | * ```javascript
|
2312 | * // First, we perform the signInWithRedirect.
|
2313 | * // Creates the provider object.
|
2314 | * var provider = new firebase.auth.FacebookAuthProvider();
|
2315 | * // You can add additional scopes to the provider:
|
2316 | * provider.addScope('email');
|
2317 | * provider.addScope('user_friends');
|
2318 | * // Sign in with redirect:
|
2319 | * auth.signInWithRedirect(provider)
|
2320 | * ////////////////////////////////////////////////////////////
|
2321 | * // The user is redirected to the provider's sign in flow...
|
2322 | * ////////////////////////////////////////////////////////////
|
2323 | * // Then redirected back to the app, where we check the redirect result:
|
2324 | * auth.getRedirectResult().then(function(result) {
|
2325 | * // The firebase.User instance:
|
2326 | * var user = result.user;
|
2327 | * // The Facebook firebase.auth.AuthCredential containing the Facebook
|
2328 | * // access token:
|
2329 | * var credential = result.credential;
|
2330 | * // As this API can be used for sign-in, linking and reauthentication,
|
2331 | * // check the operationType to determine what triggered this redirect
|
2332 | * // operation.
|
2333 | * var operationType = result.operationType;
|
2334 | * }, function(error) {
|
2335 | * // The provider's account email, can be used in case of
|
2336 | * // auth/account-exists-with-different-credential to fetch the providers
|
2337 | * // linked to the email:
|
2338 | * var email = error.email;
|
2339 | * // The provider's credential:
|
2340 | * var credential = error.credential;
|
2341 | * // In case of auth/account-exists-with-different-credential error,
|
2342 | * // you can fetch the providers using this:
|
2343 | * if (error.code === 'auth/account-exists-with-different-credential') {
|
2344 | * auth.fetchSignInMethodsForEmail(email).then(function(providers) {
|
2345 | * // The returned 'providers' is a list of the available providers
|
2346 | * // linked to the email address. Please refer to the guide for a more
|
2347 | * // complete explanation on how to recover from this error.
|
2348 | * });
|
2349 | * }
|
2350 | * });
|
2351 | * ```
|
2352 | */
|
2353 | getRedirectResult(): Promise<firebase.auth.UserCredential>;
|
2354 | /**
|
2355 | * The current Auth instance's language code. This is a readable/writable
|
2356 | * property. When set to null, the default Firebase Console language setting
|
2357 | * is applied. The language code will propagate to email action templates
|
2358 | * (password reset, email verification and email change revocation), SMS
|
2359 | * templates for phone authentication, reCAPTCHA verifier and OAuth
|
2360 | * popup/redirect operations provided the specified providers support
|
2361 | * localization with the language code specified.
|
2362 | */
|
2363 | languageCode: string | null;
|
2364 | /**
|
2365 | * The current Auth instance's settings. This is used to edit/read configuration
|
2366 | * related options like app verification mode for phone authentication.
|
2367 | */
|
2368 | settings: firebase.auth.AuthSettings;
|
2369 | /**
|
2370 | * Adds an observer for changes to the user's sign-in state.
|
2371 | *
|
2372 | * Prior to 4.0.0, this triggered the observer when users were signed in,
|
2373 | * signed out, or when the user's ID token changed in situations such as token
|
2374 | * expiry or password change. After 4.0.0, the observer is only triggered
|
2375 | * on sign-in or sign-out.
|
2376 | *
|
2377 | * To keep the old behavior, see {@link firebase.auth.Auth.onIdTokenChanged}.
|
2378 | *
|
2379 | * @example
|
2380 | * ```javascript
|
2381 | * firebase.auth().onAuthStateChanged(function(user) {
|
2382 | * if (user) {
|
2383 | * // User is signed in.
|
2384 | * }
|
2385 | * });
|
2386 | * ```
|
2387 | */
|
2388 | onAuthStateChanged(
|
2389 | nextOrObserver:
|
2390 | | firebase.Observer<any>
|
2391 | | ((a: firebase.User | null) => any),
|
2392 | error?: (a: firebase.auth.Error) => any,
|
2393 | completed?: firebase.Unsubscribe
|
2394 | ): firebase.Unsubscribe;
|
2395 | /**
|
2396 | * Adds an observer for changes to the signed-in user's ID token, which includes
|
2397 | * sign-in, sign-out, and token refresh events. This method has the same
|
2398 | * behavior as {@link firebase.auth.Auth.onAuthStateChanged} had prior to 4.0.0.
|
2399 | *
|
2400 | * @example
|
2401 | * ```javascript
|
2402 | * firebase.auth().onIdTokenChanged(function(user) {
|
2403 | * if (user) {
|
2404 | * // User is signed in or token was refreshed.
|
2405 | * }
|
2406 | * });
|
2407 | * ```
|
2408 | * @param
|
2409 | * nextOrObserver An observer object or a function triggered on change.
|
2410 | * @param error Optional A function
|
2411 | * triggered on auth error.
|
2412 | * @param completed Optional A function triggered when the
|
2413 | * observer is removed.
|
2414 | */
|
2415 | onIdTokenChanged(
|
2416 | nextOrObserver:
|
2417 | | firebase.Observer<any>
|
2418 | | ((a: firebase.User | null) => any),
|
2419 | error?: (a: firebase.auth.Error) => any,
|
2420 | completed?: firebase.Unsubscribe
|
2421 | ): firebase.Unsubscribe;
|
2422 | /**
|
2423 | * Sends a sign-in email link to the user with the specified email.
|
2424 | *
|
2425 | * The sign-in operation has to always be completed in the app unlike other out
|
2426 | * of band email actions (password reset and email verifications). This is
|
2427 | * because, at the end of the flow, the user is expected to be signed in and
|
2428 | * their Auth state persisted within the app.
|
2429 | *
|
2430 | * To complete sign in with the email link, call
|
2431 | * {@link firebase.auth.Auth.signInWithEmailLink} with the email address and
|
2432 | * the email link supplied in the email sent to the user.
|
2433 | *
|
2434 | * <h4>Error Codes</h4>
|
2435 | * <dl>
|
2436 | * <dt>auth/argument-error</dt>
|
2437 | * <dd>Thrown if handleCodeInApp is false.</dd>
|
2438 | * <dt>auth/invalid-email</dt>
|
2439 | * <dd>Thrown if the email address is not valid.</dd>
|
2440 | * <dt>auth/missing-android-pkg-name</dt>
|
2441 | * <dd>An Android package name must be provided if the Android app is required
|
2442 | * to be installed.</dd>
|
2443 | * <dt>auth/missing-continue-uri</dt>
|
2444 | * <dd>A continue URL must be provided in the request.</dd>
|
2445 | * <dt>auth/missing-ios-bundle-id</dt>
|
2446 | * <dd>An iOS Bundle ID must be provided if an App Store ID is provided.</dd>
|
2447 | * <dt>auth/invalid-continue-uri</dt>
|
2448 | * <dd>The continue URL provided in the request is invalid.</dd>
|
2449 | * <dt>auth/unauthorized-continue-uri</dt>
|
2450 | * <dd>The domain of the continue URL is not whitelisted. Whitelist
|
2451 | * the domain in the Firebase console.</dd>
|
2452 | * </dl>
|
2453 | *
|
2454 | * @example
|
2455 | * ```javascript
|
2456 | * var actionCodeSettings = {
|
2457 | * // The URL to redirect to for sign-in completion. This is also the deep
|
2458 | * // link for mobile redirects. The domain (www.example.com) for this URL
|
2459 | * // must be whitelisted in the Firebase Console.
|
2460 | * url: 'https://www.example.com/finishSignUp?cartId=1234',
|
2461 | * iOS: {
|
2462 | * bundleId: 'com.example.ios'
|
2463 | * },
|
2464 | * android: {
|
2465 | * packageName: 'com.example.android',
|
2466 | * installApp: true,
|
2467 | * minimumVersion: '12'
|
2468 | * },
|
2469 | * // This must be true.
|
2470 | * handleCodeInApp: true
|
2471 | * };
|
2472 | * firebase.auth().sendSignInLinkToEmail('user@example.com', actionCodeSettings)
|
2473 | * .then(function() {
|
2474 | * // The link was successfully sent. Inform the user. Save the email
|
2475 | * // locally so you don't need to ask the user for it again if they open
|
2476 | * // the link on the same device.
|
2477 | * })
|
2478 | * .catch(function(error) {
|
2479 | * // Some error occurred, you can inspect the code: error.code
|
2480 | * });
|
2481 | * ```
|
2482 | * @param email The email account to sign in with.
|
2483 | * @param actionCodeSettings The action
|
2484 | * code settings. The action code settings which provides Firebase with
|
2485 | * instructions on how to construct the email link. This includes the
|
2486 | * sign in completion URL or the deep link for mobile redirects, the mobile
|
2487 | * apps to use when the sign-in link is opened on an Android or iOS device.
|
2488 | * Mobile app redirects will only be applicable if the developer configures
|
2489 | * and accepts the Firebase Dynamic Links terms of condition.
|
2490 | * The Android package name and iOS bundle ID will be respected only if they
|
2491 | * are configured in the same Firebase Auth project used.
|
2492 | */
|
2493 | sendSignInLinkToEmail(
|
2494 | email: string,
|
2495 | actionCodeSettings: firebase.auth.ActionCodeSettings
|
2496 | ): Promise<void>;
|
2497 |
|
2498 | /**
|
2499 | * Sends a password reset email to the given email address.
|
2500 | *
|
2501 | * To complete the password reset, call
|
2502 | * {@link firebase.auth.Auth.confirmPasswordReset} with the code supplied in the
|
2503 | * email sent to the user, along with the new password specified by the user.
|
2504 | *
|
2505 | * <h4>Error Codes</h4>
|
2506 | * <dl>
|
2507 | * <dt>auth/invalid-email</dt>
|
2508 | * <dd>Thrown if the email address is not valid.</dd>
|
2509 | * <dt>auth/missing-android-pkg-name</dt>
|
2510 | * <dd>An Android package name must be provided if the Android app is required
|
2511 | * to be installed.</dd>
|
2512 | * <dt>auth/missing-continue-uri</dt>
|
2513 | * <dd>A continue URL must be provided in the request.</dd>
|
2514 | * <dt>auth/missing-ios-bundle-id</dt>
|
2515 | * <dd>An iOS Bundle ID must be provided if an App Store ID is provided.</dd>
|
2516 | * <dt>auth/invalid-continue-uri</dt>
|
2517 | * <dd>The continue URL provided in the request is invalid.</dd>
|
2518 | * <dt>auth/unauthorized-continue-uri</dt>
|
2519 | * <dd>The domain of the continue URL is not whitelisted. Whitelist
|
2520 | * the domain in the Firebase console.</dd>
|
2521 | * <dt>auth/user-not-found</dt>
|
2522 | * <dd>Thrown if there is no user corresponding to the email address.</dd>
|
2523 | * </dl>
|
2524 | *
|
2525 | * @example
|
2526 | * ```javascript
|
2527 | * var actionCodeSettings = {
|
2528 | * url: 'https://www.example.com/?email=user@example.com',
|
2529 | * iOS: {
|
2530 | * bundleId: 'com.example.ios'
|
2531 | * },
|
2532 | * android: {
|
2533 | * packageName: 'com.example.android',
|
2534 | * installApp: true,
|
2535 | * minimumVersion: '12'
|
2536 | * },
|
2537 | * handleCodeInApp: true
|
2538 | * };
|
2539 | * firebase.auth().sendPasswordResetEmail(
|
2540 | * 'user@example.com', actionCodeSettings)
|
2541 | * .then(function() {
|
2542 | * // Password reset email sent.
|
2543 | * })
|
2544 | * .catch(function(error) {
|
2545 | * // Error occurred. Inspect error.code.
|
2546 | * });
|
2547 | * ```
|
2548 | *
|
2549 | * @param email The email address with the password to be reset.
|
2550 | * @param actionCodeSettings The action
|
2551 | * code settings. If specified, the state/continue URL will be set as the
|
2552 | * "continueUrl" parameter in the password reset link. The default password
|
2553 | * reset landing page will use this to display a link to go back to the app
|
2554 | * if it is installed.
|
2555 | * If the actionCodeSettings is not specified, no URL is appended to the
|
2556 | * action URL.
|
2557 | * The state URL provided must belong to a domain that is whitelisted by the
|
2558 | * developer in the console. Otherwise an error will be thrown.
|
2559 | * Mobile app redirects will only be applicable if the developer configures
|
2560 | * and accepts the Firebase Dynamic Links terms of condition.
|
2561 | * The Android package name and iOS bundle ID will be respected only if they
|
2562 | * are configured in the same Firebase Auth project used.
|
2563 | */
|
2564 | sendPasswordResetEmail(
|
2565 | email: string,
|
2566 | actionCodeSettings?: firebase.auth.ActionCodeSettings | null
|
2567 | ): Promise<void>;
|
2568 |
|
2569 | /**
|
2570 | * Changes the current type of persistence on the current Auth instance for the
|
2571 | * currently saved Auth session and applies this type of persistence for
|
2572 | * future sign-in requests, including sign-in with redirect requests. This will
|
2573 | * return a promise that will resolve once the state finishes copying from one
|
2574 | * type of storage to the other.
|
2575 | * Calling a sign-in method after changing persistence will wait for that
|
2576 | * persistence change to complete before applying it on the new Auth state.
|
2577 | *
|
2578 | * This makes it easy for a user signing in to specify whether their session
|
2579 | * should be remembered or not. It also makes it easier to never persist the
|
2580 | * Auth state for applications that are shared by other users or have sensitive
|
2581 | * data.
|
2582 | *
|
2583 | * The default for web browser apps and React Native apps is 'local' (provided
|
2584 | * the browser supports this mechanism) whereas it is 'none' for Node.js backend
|
2585 | * apps.
|
2586 | *
|
2587 | * <h4>Error Codes (thrown synchronously)</h4>
|
2588 | * <dl>
|
2589 | * <dt>auth/invalid-persistence-type</dt>
|
2590 | * <dd>Thrown if the specified persistence type is invalid.</dd>
|
2591 | * <dt>auth/unsupported-persistence-type</dt>
|
2592 | * <dd>Thrown if the current environment does not support the specified
|
2593 | * persistence type.</dd>
|
2594 | * </dl>
|
2595 | *
|
2596 | * @example
|
2597 | * ```javascript
|
2598 | * firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
|
2599 | * .then(function() {
|
2600 | * // Existing and future Auth states are now persisted in the current
|
2601 | * // session only. Closing the window would clear any existing state even if
|
2602 | * // a user forgets to sign out.
|
2603 | * });
|
2604 | * ```
|
2605 | */
|
2606 | setPersistence(persistence: firebase.auth.Auth.Persistence): Promise<void>;
|
2607 |
|
2608 | /**
|
2609 | * Asynchronously signs in with the given credentials, and returns any available
|
2610 | * additional user information, such as user name.
|
2611 | *
|
2612 | * <h4>Error Codes</h4>
|
2613 | * <dl>
|
2614 | * <dt>auth/account-exists-with-different-credential</dt>
|
2615 | * <dd>Thrown if there already exists an account with the email address
|
2616 | * asserted by the credential. Resolve this by calling
|
2617 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} and then asking the
|
2618 | * user to sign in using one of the returned providers. Once the user is
|
2619 | * signed in, the original credential can be linked to the user with
|
2620 | * {@link firebase.User.linkWithCredential}.</dd>
|
2621 | * <dt>auth/invalid-credential</dt>
|
2622 | * <dd>Thrown if the credential is malformed or has expired.</dd>
|
2623 | * <dt>auth/operation-not-allowed</dt>
|
2624 | * <dd>Thrown if the type of account corresponding to the credential
|
2625 | * is not enabled. Enable the account type in the Firebase Console, under
|
2626 | * the Auth tab.</dd>
|
2627 | * <dt>auth/user-disabled</dt>
|
2628 | * <dd>Thrown if the user corresponding to the given credential has been
|
2629 | * disabled.</dd>
|
2630 | * <dt>auth/user-not-found</dt>
|
2631 | * <dd>Thrown if signing in with a credential from
|
2632 | * {@link firebase.auth.EmailAuthProvider.credential} and there is no user
|
2633 | * corresponding to the given email. </dd>
|
2634 | * <dt>auth/wrong-password</dt>
|
2635 | * <dd>Thrown if signing in with a credential from
|
2636 | * {@link firebase.auth.EmailAuthProvider.credential} and the password is
|
2637 | * invalid for the given email, or if the account corresponding to the email
|
2638 | * does not have a password set.</dd>
|
2639 | * <dt>auth/invalid-verification-code</dt>
|
2640 | * <dd>Thrown if the credential is a
|
2641 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
2642 | * code of the credential is not valid.</dd>
|
2643 | * <dt>auth/invalid-verification-id</dt>
|
2644 | * <dd>Thrown if the credential is a
|
2645 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
2646 | * ID of the credential is not valid.</dd>
|
2647 | * </dl>
|
2648 | *
|
2649 | * @deprecated
|
2650 | * This method is deprecated. Use
|
2651 | * {@link firebase.auth.Auth.signInWithCredential} instead.
|
2652 | *
|
2653 | * @example
|
2654 | * ```javascript
|
2655 | * firebase.auth().signInAndRetrieveDataWithCredential(credential)
|
2656 | * .then(function(userCredential) {
|
2657 | * console.log(userCredential.additionalUserInfo.username);
|
2658 | * });
|
2659 | * ```
|
2660 | * @param credential The auth credential.
|
2661 | */
|
2662 | signInAndRetrieveDataWithCredential(
|
2663 | credential: firebase.auth.AuthCredential
|
2664 | ): Promise<firebase.auth.UserCredential>;
|
2665 | /**
|
2666 | * Asynchronously signs in as an anonymous user.
|
2667 | *
|
2668 | *
|
2669 | * If there is already an anonymous user signed in, that user will be returned;
|
2670 | * otherwise, a new anonymous user identity will be created and returned.
|
2671 | *
|
2672 | * <h4>Error Codes</h4>
|
2673 | * <dl>
|
2674 | * <dt>auth/operation-not-allowed</dt>
|
2675 | * <dd>Thrown if anonymous accounts are not enabled. Enable anonymous accounts
|
2676 | * in the Firebase Console, under the Auth tab.</dd>
|
2677 | * </dl>
|
2678 | *
|
2679 | * @example
|
2680 | * ```javascript
|
2681 | * firebase.auth().signInAnonymously().catch(function(error) {
|
2682 | * // Handle Errors here.
|
2683 | * var errorCode = error.code;
|
2684 | * var errorMessage = error.message;
|
2685 | *
|
2686 | * if (errorCode === 'auth/operation-not-allowed') {
|
2687 | * alert('You must enable Anonymous auth in the Firebase Console.');
|
2688 | * } else {
|
2689 | * console.error(error);
|
2690 | * }
|
2691 | * });
|
2692 | * ```
|
2693 | */
|
2694 | signInAnonymously(): Promise<firebase.auth.UserCredential>;
|
2695 |
|
2696 | /**
|
2697 | * Asynchronously signs in with the given credentials.
|
2698 | *
|
2699 | * <h4>Error Codes</h4>
|
2700 | * <dl>
|
2701 | * <dt>auth/account-exists-with-different-credential</dt>
|
2702 | * <dd>Thrown if there already exists an account with the email address
|
2703 | * asserted by the credential. Resolve this by calling
|
2704 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} and then asking the
|
2705 | * user to sign in using one of the returned providers. Once the user is
|
2706 | * signed in, the original credential can be linked to the user with
|
2707 | * {@link firebase.User.linkWithCredential}.</dd>
|
2708 | * <dt>auth/invalid-credential</dt>
|
2709 | * <dd>Thrown if the credential is malformed or has expired.</dd>
|
2710 | * <dt>auth/operation-not-allowed</dt>
|
2711 | * <dd>Thrown if the type of account corresponding to the credential
|
2712 | * is not enabled. Enable the account type in the Firebase Console, under
|
2713 | * the Auth tab.</dd>
|
2714 | * <dt>auth/user-disabled</dt>
|
2715 | * <dd>Thrown if the user corresponding to the given credential has been
|
2716 | * disabled.</dd>
|
2717 | * <dt>auth/user-not-found</dt>
|
2718 | * <dd>Thrown if signing in with a credential from
|
2719 | * {@link firebase.auth.EmailAuthProvider.credential} and there is no user
|
2720 | * corresponding to the given email. </dd>
|
2721 | * <dt>auth/wrong-password</dt>
|
2722 | * <dd>Thrown if signing in with a credential from
|
2723 | * {@link firebase.auth.EmailAuthProvider.credential} and the password is
|
2724 | * invalid for the given email, or if the account corresponding to the email
|
2725 | * does not have a password set.</dd>
|
2726 | * <dt>auth/invalid-verification-code</dt>
|
2727 | * <dd>Thrown if the credential is a
|
2728 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
2729 | * code of the credential is not valid.</dd>
|
2730 | * <dt>auth/invalid-verification-id</dt>
|
2731 | * <dd>Thrown if the credential is a
|
2732 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
2733 | * ID of the credential is not valid.</dd>
|
2734 | * </dl>
|
2735 | *
|
2736 | * @example
|
2737 | * ```javascript
|
2738 | * firebase.auth().signInWithCredential(credential).catch(function(error) {
|
2739 | * // Handle Errors here.
|
2740 | * var errorCode = error.code;
|
2741 | * var errorMessage = error.message;
|
2742 | * // The email of the user's account used.
|
2743 | * var email = error.email;
|
2744 | * // The firebase.auth.AuthCredential type that was used.
|
2745 | * var credential = error.credential;
|
2746 | * if (errorCode === 'auth/account-exists-with-different-credential') {
|
2747 | * alert('Email already associated with another account.');
|
2748 | * // Handle account linking here, if using.
|
2749 | * } else {
|
2750 | * console.error(error);
|
2751 | * }
|
2752 | * });
|
2753 | * ```
|
2754 | *
|
2755 | * @param credential The auth credential.
|
2756 | */
|
2757 | signInWithCredential(
|
2758 | credential: firebase.auth.AuthCredential
|
2759 | ): Promise<firebase.auth.UserCredential>;
|
2760 | /**
|
2761 | * Asynchronously signs in using a custom token.
|
2762 | *
|
2763 | * Custom tokens are used to integrate Firebase Auth with existing auth systems,
|
2764 | * and must be generated by the auth backend.
|
2765 | *
|
2766 | * Fails with an error if the token is invalid, expired, or not accepted by the
|
2767 | * Firebase Auth service.
|
2768 | *
|
2769 | * <h4>Error Codes</h4>
|
2770 | * <dl>
|
2771 | * <dt>auth/custom-token-mismatch</dt>
|
2772 | * <dd>Thrown if the custom token is for a different Firebase App.</dd>
|
2773 | * <dt>auth/invalid-custom-token</dt>
|
2774 | * <dd>Thrown if the custom token format is incorrect.</dd>
|
2775 | * </dl>
|
2776 | *
|
2777 | * @example
|
2778 | * ```javascript
|
2779 | * firebase.auth().signInWithCustomToken(token).catch(function(error) {
|
2780 | * // Handle Errors here.
|
2781 | * var errorCode = error.code;
|
2782 | * var errorMessage = error.message;
|
2783 | * if (errorCode === 'auth/invalid-custom-token') {
|
2784 | * alert('The token you provided is not valid.');
|
2785 | * } else {
|
2786 | * console.error(error);
|
2787 | * }
|
2788 | * });
|
2789 | * ```
|
2790 | *
|
2791 | * @param token The custom token to sign in with.
|
2792 | */
|
2793 | signInWithCustomToken(token: string): Promise<firebase.auth.UserCredential>;
|
2794 | /**
|
2795 | * Asynchronously signs in using an email and password.
|
2796 | *
|
2797 | * Fails with an error if the email address and password do not match.
|
2798 | *
|
2799 | * Note: The user's password is NOT the password used to access the user's email
|
2800 | * account. The email address serves as a unique identifier for the user, and
|
2801 | * the password is used to access the user's account in your Firebase project.
|
2802 | *
|
2803 | * See also: {@link firebase.auth.Auth.createUserWithEmailAndPassword}.
|
2804 | *
|
2805 | * <h4>Error Codes</h4>
|
2806 | * <dl>
|
2807 | * <dt>auth/invalid-email</dt>
|
2808 | * <dd>Thrown if the email address is not valid.</dd>
|
2809 | * <dt>auth/user-disabled</dt>
|
2810 | * <dd>Thrown if the user corresponding to the given email has been
|
2811 | * disabled.</dd>
|
2812 | * <dt>auth/user-not-found</dt>
|
2813 | * <dd>Thrown if there is no user corresponding to the given email.</dd>
|
2814 | * <dt>auth/wrong-password</dt>
|
2815 | * <dd>Thrown if the password is invalid for the given email, or the account
|
2816 | * corresponding to the email does not have a password set.</dd>
|
2817 | * </dl>
|
2818 | *
|
2819 | * @example
|
2820 | * ```javascript
|
2821 | * firebase.auth().signInWithEmailAndPassword(email, password)
|
2822 | * .catch(function(error) {
|
2823 | * // Handle Errors here.
|
2824 | * var errorCode = error.code;
|
2825 | * var errorMessage = error.message;
|
2826 | * if (errorCode === 'auth/wrong-password') {
|
2827 | * alert('Wrong password.');
|
2828 | * } else {
|
2829 | * alert(errorMessage);
|
2830 | * }
|
2831 | * console.log(error);
|
2832 | * });
|
2833 | * ```
|
2834 | *
|
2835 | * @param email The users email address.
|
2836 | * @param password The users password.
|
2837 | */
|
2838 | signInWithEmailAndPassword(
|
2839 | email: string,
|
2840 | password: string
|
2841 | ): Promise<firebase.auth.UserCredential>;
|
2842 |
|
2843 | /**
|
2844 | * Asynchronously signs in using a phone number. This method sends a code via
|
2845 | * SMS to the given phone number, and returns a
|
2846 | * {@link firebase.auth.ConfirmationResult}. After the user provides the code
|
2847 | * sent to their phone, call {@link firebase.auth.ConfirmationResult.confirm}
|
2848 | * with the code to sign the user in.
|
2849 | *
|
2850 | * For abuse prevention, this method also requires a
|
2851 | * {@link firebase.auth.ApplicationVerifier}. The Firebase Auth SDK includes
|
2852 | * a reCAPTCHA-based implementation, {@link firebase.auth.RecaptchaVerifier}.
|
2853 | *
|
2854 | * <h4>Error Codes</h4>
|
2855 | * <dl>
|
2856 | * <dt>auth/captcha-check-failed</dt>
|
2857 | * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
|
2858 | * this method was called from a non-whitelisted domain.</dd>
|
2859 | * <dt>auth/invalid-phone-number</dt>
|
2860 | * <dd>Thrown if the phone number has an invalid format.</dd>
|
2861 | * <dt>auth/missing-phone-number</dt>
|
2862 | * <dd>Thrown if the phone number is missing.</dd>
|
2863 | * <dt>auth/quota-exceeded</dt>
|
2864 | * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
|
2865 | * <dt>auth/user-disabled</dt>
|
2866 | * <dd>Thrown if the user corresponding to the given phone number has been
|
2867 | * disabled.</dd>
|
2868 | * <dt>auth/operation-not-allowed</dt>
|
2869 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
2870 | * to the Firebase Console for your project, in the Auth section and the
|
2871 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
2872 | * </dl>
|
2873 | *
|
2874 | * @example
|
2875 | * ```javascript
|
2876 | * // 'recaptcha-container' is the ID of an element in the DOM.
|
2877 | * var applicationVerifier = new firebase.auth.RecaptchaVerifier(
|
2878 | * 'recaptcha-container');
|
2879 | * firebase.auth().signInWithPhoneNumber(phoneNumber, applicationVerifier)
|
2880 | * .then(function(confirmationResult) {
|
2881 | * var verificationCode = window.prompt('Please enter the verification ' +
|
2882 | * 'code that was sent to your mobile device.');
|
2883 | * return confirmationResult.confirm(verificationCode);
|
2884 | * })
|
2885 | * .catch(function(error) {
|
2886 | * // Handle Errors here.
|
2887 | * });
|
2888 | * ```
|
2889 | *
|
2890 | * @param phoneNumber The user's phone number in E.164 format (e.g.
|
2891 | * +16505550101).
|
2892 | * @param applicationVerifier
|
2893 | */
|
2894 | signInWithPhoneNumber(
|
2895 | phoneNumber: string,
|
2896 | applicationVerifier: firebase.auth.ApplicationVerifier
|
2897 | ): Promise<firebase.auth.ConfirmationResult>;
|
2898 | /**
|
2899 | * Asynchronously signs in using an email and sign-in email link. If no link
|
2900 | * is passed, the link is inferred from the current URL.
|
2901 | *
|
2902 | * Fails with an error if the email address is invalid or OTP in email link
|
2903 | * expires.
|
2904 | *
|
2905 | * Note: Confirm the link is a sign-in email link before calling this method
|
2906 | * {@link firebase.auth.Auth.isSignInWithEmailLink}.
|
2907 | *
|
2908 | * <h4>Error Codes</h4>
|
2909 | * <dl>
|
2910 | * <dt>auth/expired-action-code</dt>
|
2911 | * <dd>Thrown if OTP in email link expires.</dd>
|
2912 | * <dt>auth/invalid-email</dt>
|
2913 | * <dd>Thrown if the email address is not valid.</dd>
|
2914 | * <dt>auth/user-disabled</dt>
|
2915 | * <dd>Thrown if the user corresponding to the given email has been
|
2916 | * disabled.</dd>
|
2917 | * </dl>
|
2918 | *
|
2919 | * @example
|
2920 | * ```javascript
|
2921 | * firebase.auth().signInWithEmailLink(email, emailLink)
|
2922 | * .catch(function(error) {
|
2923 | * // Some error occurred, you can inspect the code: error.code
|
2924 | * // Common errors could be invalid email and invalid or expired OTPs.
|
2925 | * });
|
2926 | * ```
|
2927 | *
|
2928 | * @param email The email account to sign in with.
|
2929 | * @param emailLink The optional link which contains the OTP needed
|
2930 | * to complete the sign in with email link. If not specified, the current
|
2931 | * URL is used instead.
|
2932 | */
|
2933 | signInWithEmailLink(
|
2934 | email: string,
|
2935 | emailLink?: string
|
2936 | ): Promise<firebase.auth.UserCredential>;
|
2937 | /**
|
2938 | * Authenticates a Firebase client using a popup-based OAuth authentication
|
2939 | * flow.
|
2940 | *
|
2941 | * If succeeds, returns the signed in user along with the provider's credential.
|
2942 | * If sign in was unsuccessful, returns an error object containing additional
|
2943 | * information about the error.
|
2944 | *
|
2945 | * <h4>Error Codes</h4>
|
2946 | * <dl>
|
2947 | * <dt>auth/account-exists-with-different-credential</dt>
|
2948 | * <dd>Thrown if there already exists an account with the email address
|
2949 | * asserted by the credential. Resolve this by calling
|
2950 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
|
2951 | * and then asking the user to sign in using one of the returned providers.
|
2952 | * Once the user is signed in, the original credential retrieved from the
|
2953 | * error.credential can be linked to the user with
|
2954 | * {@link firebase.User.linkWithCredential} to prevent the user from signing
|
2955 | * in again to the original provider via popup or redirect. If you are using
|
2956 | * redirects for sign in, save the credential in session storage and then
|
2957 | * retrieve on redirect and repopulate the credential using for example
|
2958 | * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
|
2959 | * credential provider id and complete the link.</dd>
|
2960 | * <dt>auth/auth-domain-config-required</dt>
|
2961 | * <dd>Thrown if authDomain configuration is not provided when calling
|
2962 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
2963 | * determining and passing that field.</dd>
|
2964 | * <dt>auth/cancelled-popup-request</dt>
|
2965 | * <dd>Thrown if successive popup operations are triggered. Only one popup
|
2966 | * request is allowed at one time. All the popups would fail with this error
|
2967 | * except for the last one.</dd>
|
2968 | * <dt>auth/operation-not-allowed</dt>
|
2969 | * <dd>Thrown if the type of account corresponding to the credential
|
2970 | * is not enabled. Enable the account type in the Firebase Console, under
|
2971 | * the Auth tab.</dd>
|
2972 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
2973 | * <dd>Thrown if this operation is not supported in the environment your
|
2974 | * application is running on. "location.protocol" must be http or https.
|
2975 | * </dd>
|
2976 | * <dt>auth/popup-blocked</dt>
|
2977 | * <dd>Thrown if the popup was blocked by the browser, typically when this
|
2978 | * operation is triggered outside of a click handler.</dd>
|
2979 | * <dt>auth/popup-closed-by-user</dt>
|
2980 | * <dd>Thrown if the popup window is closed by the user without completing the
|
2981 | * sign in to the provider.</dd>
|
2982 | * <dt>auth/unauthorized-domain</dt>
|
2983 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
2984 | * Firebase project. Edit the list of authorized domains from the Firebase
|
2985 | * console.</dd>
|
2986 | * </dl>
|
2987 | *
|
2988 | * @webonly
|
2989 | *
|
2990 | * @example
|
2991 | * ```javascript
|
2992 | * // Creates the provider object.
|
2993 | * var provider = new firebase.auth.FacebookAuthProvider();
|
2994 | * // You can add additional scopes to the provider:
|
2995 | * provider.addScope('email');
|
2996 | * provider.addScope('user_friends');
|
2997 | * // Sign in with popup:
|
2998 | * auth.signInWithPopup(provider).then(function(result) {
|
2999 | * // The firebase.User instance:
|
3000 | * var user = result.user;
|
3001 | * // The Facebook firebase.auth.AuthCredential containing the Facebook
|
3002 | * // access token:
|
3003 | * var credential = result.credential;
|
3004 | * }, function(error) {
|
3005 | * // The provider's account email, can be used in case of
|
3006 | * // auth/account-exists-with-different-credential to fetch the providers
|
3007 | * // linked to the email:
|
3008 | * var email = error.email;
|
3009 | * // The provider's credential:
|
3010 | * var credential = error.credential;
|
3011 | * // In case of auth/account-exists-with-different-credential error,
|
3012 | * // you can fetch the providers using this:
|
3013 | * if (error.code === 'auth/account-exists-with-different-credential') {
|
3014 | * auth.fetchSignInMethodsForEmail(email).then(function(providers) {
|
3015 | * // The returned 'providers' is a list of the available providers
|
3016 | * // linked to the email address. Please refer to the guide for a more
|
3017 | * // complete explanation on how to recover from this error.
|
3018 | * });
|
3019 | * }
|
3020 | * });
|
3021 | * ```
|
3022 | *
|
3023 | * @param provider The provider to authenticate.
|
3024 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
3025 | * firebase.auth.EmailAuthProvider} will throw an error.
|
3026 | */
|
3027 | signInWithPopup(
|
3028 | provider: firebase.auth.AuthProvider
|
3029 | ): Promise<firebase.auth.UserCredential>;
|
3030 | /**
|
3031 | * Authenticates a Firebase client using a full-page redirect flow. To handle
|
3032 | * the results and errors for this operation, refer to {@link
|
3033 | * firebase.auth.Auth.getRedirectResult}.
|
3034 | *
|
3035 | * <h4>Error Codes</h4>
|
3036 | * <dl>
|
3037 | * <dt>auth/auth-domain-config-required</dt>
|
3038 | * <dd>Thrown if authDomain configuration is not provided when calling
|
3039 | * firebase.initializeApp(). Check Firebase Console for instructions on
|
3040 | * determining and passing that field.</dd>
|
3041 | * <dt>auth/operation-not-supported-in-this-environment</dt>
|
3042 | * <dd>Thrown if this operation is not supported in the environment your
|
3043 | * application is running on. "location.protocol" must be http or https.
|
3044 | * </dd>
|
3045 | * <dt>auth/unauthorized-domain</dt>
|
3046 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
3047 | * Firebase project. Edit the list of authorized domains from the Firebase
|
3048 | * console.</dd>
|
3049 | * </dl>
|
3050 | *
|
3051 | * @webonly
|
3052 | *
|
3053 | * @param provider The provider to authenticate.
|
3054 | * The provider has to be an OAuth provider. Non-OAuth providers like {@link
|
3055 | * firebase.auth.EmailAuthProvider} will throw an error.
|
3056 | */
|
3057 | signInWithRedirect(provider: firebase.auth.AuthProvider): Promise<void>;
|
3058 | /**
|
3059 | * Signs out the current user.
|
3060 | */
|
3061 | signOut(): Promise<void>;
|
3062 | /**
|
3063 | * The current Auth instance's tenant ID. This is a readable/writable
|
3064 | * property. When you set the tenant ID of an Auth instance, all future
|
3065 | * sign-in/sign-up operations will pass this tenant ID and sign in or
|
3066 | * sign up users to the specified tenant project.
|
3067 | * When set to null, users are signed in to the parent project. By default,
|
3068 | * this is set to null.
|
3069 | *
|
3070 | * @example
|
3071 | * ```javascript
|
3072 | * // Set the tenant ID on Auth instance.
|
3073 | * firebase.auth().tenantId = ‘TENANT_PROJECT_ID’;
|
3074 | *
|
3075 | * // All future sign-in request now include tenant ID.
|
3076 | * firebase.auth().signInWithEmailAndPassword(email, password)
|
3077 | * .then(function(result) {
|
3078 | * // result.user.tenantId should be ‘TENANT_PROJECT_ID’.
|
3079 | * }).catch(function(error) {
|
3080 | * // Handle error.
|
3081 | * });
|
3082 | * ```
|
3083 | */
|
3084 | tenantId: string | null;
|
3085 | /**
|
3086 | * Asynchronously sets the provided user as `currentUser` on the current Auth
|
3087 | * instance. A new instance copy of the user provided will be made and set as
|
3088 | * `currentUser`.
|
3089 | *
|
3090 | * This will trigger {@link firebase.auth.Auth.onAuthStateChanged} and
|
3091 | * {@link firebase.auth.Auth.onIdTokenChanged} listeners like other sign in
|
3092 | * methods.
|
3093 | *
|
3094 | * The operation fails with an error if the user to be updated belongs to a
|
3095 | * different Firebase project.
|
3096 | *
|
3097 | * <h4>Error Codes</h4>
|
3098 | * <dl>
|
3099 | * <dt>auth/invalid-user-token</dt>
|
3100 | * <dd>Thrown if the user to be updated belongs to a diffent Firebase
|
3101 | * project.</dd>
|
3102 | * <dt>auth/user-token-expired</dt>
|
3103 | * <dd>Thrown if the token of the user to be updated is expired.</dd>
|
3104 | * <dt>auth/null-user</dt>
|
3105 | * <dd>Thrown if the user to be updated is null.</dd>
|
3106 | * <dt>auth/tenant-id-mismatch</dt>
|
3107 | * <dd>Thrown if the provided user's tenant ID does not match the
|
3108 | * underlying Auth instance's configured tenant ID</dd>
|
3109 | * </dl>
|
3110 | */
|
3111 | updateCurrentUser(user: firebase.User | null): Promise<void>;
|
3112 | /**
|
3113 | * Sets the current language to the default device/browser preference.
|
3114 | */
|
3115 | useDeviceLanguage(): void;
|
3116 | /**
|
3117 | * Checks a password reset code sent to the user by email or other out-of-band
|
3118 | * mechanism.
|
3119 | *
|
3120 | * Returns the user's email address if valid.
|
3121 | *
|
3122 | * <h4>Error Codes</h4>
|
3123 | * <dl>
|
3124 | * <dt>auth/expired-action-code</dt>
|
3125 | * <dd>Thrown if the password reset code has expired.</dd>
|
3126 | * <dt>auth/invalid-action-code</dt>
|
3127 | * <dd>Thrown if the password reset code is invalid. This can happen if the code
|
3128 | * is malformed or has already been used.</dd>
|
3129 | * <dt>auth/user-disabled</dt>
|
3130 | * <dd>Thrown if the user corresponding to the given password reset code has
|
3131 | * been disabled.</dd>
|
3132 | * <dt>auth/user-not-found</dt>
|
3133 | * <dd>Thrown if there is no user corresponding to the password reset code. This
|
3134 | * may have happened if the user was deleted between when the code was
|
3135 | * issued and when this method was called.</dd>
|
3136 | * </dl>
|
3137 | *
|
3138 | * @param code A verification code sent to the user.
|
3139 | */
|
3140 | verifyPasswordResetCode(code: string): Promise<string>;
|
3141 | }
|
3142 |
|
3143 | /**
|
3144 | * Interface that represents the credentials returned by an auth provider.
|
3145 | * Implementations specify the details about each auth provider's credential
|
3146 | * requirements.
|
3147 | *
|
3148 | */
|
3149 | abstract class AuthCredential {
|
3150 | /**
|
3151 | * The authentication provider ID for the credential.
|
3152 | * For example, 'facebook.com', or 'google.com'.
|
3153 | */
|
3154 | providerId: string;
|
3155 | /**
|
3156 | * The authentication sign in method for the credential.
|
3157 | * For example, 'password', or 'emailLink. This corresponds to the sign-in
|
3158 | * method identifier as returned in
|
3159 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3160 | */
|
3161 | signInMethod: string;
|
3162 | /**
|
3163 | * Returns a JSON-serializable representation of this object.
|
3164 | */
|
3165 | toJSON(): Object;
|
3166 | /**
|
3167 | * Static method to deserialize a JSON representation of an object into an
|
3168 | * {@link firebase.auth.AuthCredential}. Input can be either Object or the
|
3169 | * stringified representation of the object. When string is provided,
|
3170 | * JSON.parse would be called first. If the JSON input does not represent
|
3171 | * an`AuthCredential`, null is returned.
|
3172 | * @param json The plain object representation of an
|
3173 | * AuthCredential.
|
3174 | */
|
3175 | static fromJSON(json: Object | string): AuthCredential | null;
|
3176 | }
|
3177 |
|
3178 | /**
|
3179 | * Interface that represents the OAuth credentials returned by an OAuth
|
3180 | * provider. Implementations specify the details about each auth provider's
|
3181 | * credential requirements.
|
3182 | *
|
3183 | */
|
3184 | class OAuthCredential extends AuthCredential {
|
3185 | private constructor();
|
3186 | /**
|
3187 | * The OAuth ID token associated with the credential if it belongs to an
|
3188 | * OIDC provider, such as `google.com`.
|
3189 | */
|
3190 | idToken?: string;
|
3191 | /**
|
3192 | * The OAuth access token associated with the credential if it belongs to
|
3193 | * an OAuth provider, such as `facebook.com`, `twitter.com`, etc.
|
3194 | */
|
3195 | accessToken?: string;
|
3196 | /**
|
3197 | * The OAuth access token secret associated with the credential if it
|
3198 | * belongs to an OAuth 1.0 provider, such as `twitter.com`.
|
3199 | */
|
3200 | secret?: string;
|
3201 | }
|
3202 |
|
3203 | /**
|
3204 | * Interface that represents an auth provider.
|
3205 | */
|
3206 | interface AuthProvider {
|
3207 | providerId: string;
|
3208 | }
|
3209 |
|
3210 | /**
|
3211 | * A result from a phone number sign-in, link, or reauthenticate call.
|
3212 | */
|
3213 | interface ConfirmationResult {
|
3214 | /**
|
3215 | * Finishes a phone number sign-in, link, or reauthentication, given the code
|
3216 | * that was sent to the user's mobile device.
|
3217 | *
|
3218 | * <h4>Error Codes</h4>
|
3219 | * <dl>
|
3220 | * <dt>auth/invalid-verification-code</dt>
|
3221 | * <dd>Thrown if the verification code is not valid.</dd>
|
3222 | * <dt>auth/missing-verification-code</dt>
|
3223 | * <dd>Thrown if the verification code is missing.</dd>
|
3224 | * </dl>
|
3225 | */
|
3226 | confirm(verificationCode: string): Promise<firebase.auth.UserCredential>;
|
3227 | /**
|
3228 | * The phone number authentication operation's verification ID. This can be used
|
3229 | * along with the verification code to initialize a phone auth credential.
|
3230 | */
|
3231 | verificationId: string;
|
3232 | }
|
3233 |
|
3234 | /**
|
3235 | * Email and password auth provider implementation.
|
3236 | *
|
3237 | * To authenticate: {@link firebase.auth.Auth.createUserWithEmailAndPassword}
|
3238 | * and {@link firebase.auth.Auth.signInWithEmailAndPassword}.
|
3239 | */
|
3240 | class EmailAuthProvider extends EmailAuthProvider_Instance {
|
3241 | static PROVIDER_ID: string;
|
3242 | /**
|
3243 | * This corresponds to the sign-in method identifier as returned in
|
3244 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3245 | */
|
3246 | static EMAIL_PASSWORD_SIGN_IN_METHOD: string;
|
3247 | /**
|
3248 | * This corresponds to the sign-in method identifier as returned in
|
3249 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3250 | */
|
3251 | static EMAIL_LINK_SIGN_IN_METHOD: string;
|
3252 | /**
|
3253 | * @example
|
3254 | * ```javascript
|
3255 | * var cred = firebase.auth.EmailAuthProvider.credential(
|
3256 | * email,
|
3257 | * password
|
3258 | * );
|
3259 | * ```
|
3260 | *
|
3261 | * @param email Email address.
|
3262 | * @param password User account password.
|
3263 | * @return The auth provider credential.
|
3264 | */
|
3265 | static credential(
|
3266 | email: string,
|
3267 | password: string
|
3268 | ): firebase.auth.AuthCredential;
|
3269 | /**
|
3270 | * Initialize an `EmailAuthProvider` credential using an email and an email link
|
3271 | * after a sign in with email link operation.
|
3272 | *
|
3273 | * @example
|
3274 | * ```javascript
|
3275 | * var cred = firebase.auth.EmailAuthProvider.credentialWithLink(
|
3276 | * email,
|
3277 | * emailLink
|
3278 | * );
|
3279 | * ```
|
3280 | *
|
3281 | * @param email Email address.
|
3282 | * @param emailLink Sign-in email link.
|
3283 | * @return The auth provider credential.
|
3284 | */
|
3285 | static credentialWithLink(
|
3286 | email: string,
|
3287 | emailLink: string
|
3288 | ): firebase.auth.AuthCredential;
|
3289 | }
|
3290 | /**
|
3291 | * @hidden
|
3292 | */
|
3293 | class EmailAuthProvider_Instance implements firebase.auth.AuthProvider {
|
3294 | providerId: string;
|
3295 | }
|
3296 |
|
3297 | /**
|
3298 | * An authentication error.
|
3299 | * For method-specific error codes, refer to the specific methods in the
|
3300 | * documentation. For common error codes, check the reference below. Use {@link
|
3301 | * firebase.auth.Error#code} to get the specific error code. For a detailed
|
3302 | * message, use {@link firebase.auth.Error.message}.
|
3303 | * Errors with the code <strong>auth/account-exists-with-different-credential
|
3304 | * </strong> will have the additional fields <strong>email</strong> and <strong>
|
3305 | * credential</strong> which are needed to provide a way to resolve these
|
3306 | * specific errors. Refer to {@link firebase.auth.Auth.signInWithPopup} for more
|
3307 | * information.
|
3308 | *
|
3309 | * <h4>Common Error Codes</h4>
|
3310 | * <dl>
|
3311 | * <dt>auth/app-deleted</dt>
|
3312 | * <dd>Thrown if the instance of FirebaseApp has been deleted.</dd>
|
3313 | * <dt>auth/app-not-authorized</dt>
|
3314 | * <dd>Thrown if the app identified by the domain where it's hosted, is not
|
3315 | * authorized to use Firebase Authentication with the provided API key.
|
3316 | * Review your key configuration in the Google API console.</dd>
|
3317 | * <dt>auth/argument-error</dt>
|
3318 | * <dd>Thrown if a method is called with incorrect arguments.</dd>
|
3319 | * <dt>auth/invalid-api-key</dt>
|
3320 | * <dd>Thrown if the provided API key is invalid. Please check that you have
|
3321 | * copied it correctly from the Firebase Console.</dd>
|
3322 | * <dt>auth/invalid-user-token</dt>
|
3323 | * <dd>Thrown if the user's credential is no longer valid. The user must sign in
|
3324 | * again.</dd>
|
3325 | * <dt>auth/invalid-tenant-id</dt>
|
3326 | * <dd>Thrown if the tenant ID provided is invalid.</dd>
|
3327 | * <dt>auth/network-request-failed</dt>
|
3328 | * <dd>Thrown if a network error (such as timeout, interrupted connection or
|
3329 | * unreachable host) has occurred.</dd>
|
3330 | * <dt>auth/operation-not-allowed</dt>
|
3331 | * <dd>Thrown if you have not enabled the provider in the Firebase Console. Go
|
3332 | * to the Firebase Console for your project, in the Auth section and the
|
3333 | * <strong>Sign in Method</strong> tab and configure the provider.</dd>
|
3334 | * <dt>auth/requires-recent-login</dt>
|
3335 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
3336 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
3337 | * resolve. This does not apply if the user is anonymous.</dd>
|
3338 | * <dt>auth/too-many-requests</dt>
|
3339 | * <dd>Thrown if requests are blocked from a device due to unusual activity.
|
3340 | * Trying again after some delay would unblock.</dd>
|
3341 | * <dt>auth/unauthorized-domain</dt>
|
3342 | * <dd>Thrown if the app domain is not authorized for OAuth operations for your
|
3343 | * Firebase project. Edit the list of authorized domains from the Firebase
|
3344 | * console.</dd>
|
3345 | * <dt>auth/user-disabled</dt>
|
3346 | * <dd>Thrown if the user account has been disabled by an administrator.
|
3347 | * Accounts can be enabled or disabled in the Firebase Console, the Auth
|
3348 | * section and Users subsection.</dd>
|
3349 | * <dt>auth/user-token-expired</dt>
|
3350 | * <dd>Thrown if the user's credential has expired. This could also be thrown if
|
3351 | * a user has been deleted. Prompting the user to sign in again should
|
3352 | * resolve this for either case.</dd>
|
3353 | * <dt>auth/web-storage-unsupported</dt>
|
3354 | * <dd>Thrown if the browser does not support web storage or if the user
|
3355 | * disables them.</dd>
|
3356 | * </dl>
|
3357 | */
|
3358 | interface Error {
|
3359 | /**
|
3360 | * Unique error code.
|
3361 | */
|
3362 | code: string;
|
3363 | /**
|
3364 | * Complete error message.
|
3365 | */
|
3366 | message: string;
|
3367 | }
|
3368 |
|
3369 | /**
|
3370 | * The account conflict error.
|
3371 | * Refer to {@link firebase.auth.Auth.signInWithPopup} for more information.
|
3372 | *
|
3373 | * <h4>Common Error Codes</h4>
|
3374 | * <dl>
|
3375 | * <dt>auth/account-exists-with-different-credential</dt>
|
3376 | * <dd>Thrown if there already exists an account with the email address
|
3377 | * asserted by the credential. Resolve this by calling
|
3378 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail} with the error.email
|
3379 | * and then asking the user to sign in using one of the returned providers.
|
3380 | * Once the user is signed in, the original credential retrieved from the
|
3381 | * error.credential can be linked to the user with
|
3382 | * {@link firebase.User.linkWithCredential} to prevent the user from signing
|
3383 | * in again to the original provider via popup or redirect. If you are using
|
3384 | * redirects for sign in, save the credential in session storage and then
|
3385 | * retrieve on redirect and repopulate the credential using for example
|
3386 | * {@link firebase.auth.GoogleAuthProvider.credential} depending on the
|
3387 | * credential provider id and complete the link.</dd>
|
3388 | * <dt>auth/credential-already-in-use</dt>
|
3389 | * <dd>Thrown if the account corresponding to the credential already exists
|
3390 | * among your users, or is already linked to a Firebase User.
|
3391 | * For example, this error could be thrown if you are upgrading an anonymous
|
3392 | * user to a Google user by linking a Google credential to it and the Google
|
3393 | * credential used is already associated with an existing Firebase Google
|
3394 | * user.
|
3395 | * The fields <code>error.email</code>, <code>error.phoneNumber</code>, and
|
3396 | * <code>error.credential</code> ({@link firebase.auth.AuthCredential})
|
3397 | * may be provided, depending on the type of credential. You can recover
|
3398 | * from this error by signing in with <code>error.credential</code> directly
|
3399 | * via {@link firebase.auth.Auth.signInWithCredential}.</dd>
|
3400 | * <dt>auth/email-already-in-use</dt>
|
3401 | * <dd>Thrown if the email corresponding to the credential already exists
|
3402 | * among your users. When thrown while linking a credential to an existing
|
3403 | * user, an <code>error.email</code> and <code>error.credential</code>
|
3404 | * ({@link firebase.auth.AuthCredential}) fields are also provided.
|
3405 | * You have to link the credential to the existing user with that email if
|
3406 | * you wish to continue signing in with that credential. To do so, call
|
3407 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
|
3408 | * <code>error.email</code> via one of the providers returned and then
|
3409 | * {@link firebase.User.linkWithCredential} the original credential to that
|
3410 | * newly signed in user.</dd>
|
3411 | * </dl>
|
3412 | */
|
3413 | interface AuthError extends firebase.auth.Error {
|
3414 | /**
|
3415 | * The {@link firebase.auth.AuthCredential} that can be used to resolve the
|
3416 | * error.
|
3417 | */
|
3418 | credential?: firebase.auth.AuthCredential;
|
3419 | /**
|
3420 | * The email of the user's account used for sign-in/linking.
|
3421 | */
|
3422 | email?: string;
|
3423 | /**
|
3424 | * The phone number of the user's account used for sign-in/linking.
|
3425 | */
|
3426 | phoneNumber?: string;
|
3427 | /**
|
3428 | * The tenant ID being used for sign-in/linking. If you use
|
3429 | * {@link firebase.auth.signInWithRedirect} to sign in, you have to
|
3430 | * set the tenant ID on Auth instanace again as the tenant ID is not
|
3431 | * persisted after redirection.
|
3432 | */
|
3433 | tenantId?: string;
|
3434 | }
|
3435 |
|
3436 | /**
|
3437 | * The error thrown when the user needs to provide a second factor to sign in
|
3438 | * successfully.
|
3439 | * The error code for this error is <code>auth/multi-factor-auth-required</code>.
|
3440 | * This error provides a {@link firebase.auth.MultiFactorResolver} object,
|
3441 | * which you can use to get the second sign-in factor from the user.
|
3442 | *
|
3443 | * @example
|
3444 | * ```javascript
|
3445 | * firebase.auth().signInWithEmailAndPassword()
|
3446 | * .then(function(result) {
|
3447 | * // User signed in. No 2nd factor challenge is needed.
|
3448 | * })
|
3449 | * .catch(function(error) {
|
3450 | * if (error.code == 'auth/multi-factor-auth-required') {
|
3451 | * var resolver = error.resolver;
|
3452 | * var multiFactorHints = resolver.hints;
|
3453 | * } else {
|
3454 | * // Handle other errors.
|
3455 | * }
|
3456 | * });
|
3457 | *
|
3458 | * resolver.resolveSignIn(multiFactorAssertion)
|
3459 | * .then(function(userCredential) {
|
3460 | * // User signed in.
|
3461 | * });
|
3462 | * ```
|
3463 | */
|
3464 | interface MultiFactorError extends firebase.auth.AuthError {
|
3465 | /**
|
3466 | * The multi-factor resolver to complete second factor sign-in.
|
3467 | */
|
3468 | resolver: firebase.auth.MultiFactorResolver;
|
3469 | }
|
3470 |
|
3471 | /**
|
3472 | * Facebook auth provider.
|
3473 | *
|
3474 | * @example
|
3475 | * ```javascript
|
3476 | * // Sign in using a redirect.
|
3477 | * firebase.auth().getRedirectResult().then(function(result) {
|
3478 | * if (result.credential) {
|
3479 | * // This gives you a Google Access Token.
|
3480 | * var token = result.credential.accessToken;
|
3481 | * }
|
3482 | * var user = result.user;
|
3483 | * })
|
3484 | * // Start a sign in process for an unauthenticated user.
|
3485 | * var provider = new firebase.auth.FacebookAuthProvider();
|
3486 | * provider.addScope('user_birthday');
|
3487 | * firebase.auth().signInWithRedirect(provider);
|
3488 | * ```
|
3489 | *
|
3490 | * @example
|
3491 | * ```javascript
|
3492 | * // Sign in using a popup.
|
3493 | * var provider = new firebase.auth.FacebookAuthProvider();
|
3494 | * provider.addScope('user_birthday');
|
3495 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
3496 | * // This gives you a Facebook Access Token.
|
3497 | * var token = result.credential.accessToken;
|
3498 | * // The signed-in user info.
|
3499 | * var user = result.user;
|
3500 | * });
|
3501 | * ```
|
3502 | *
|
3503 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
3504 | * changes.
|
3505 | */
|
3506 | class FacebookAuthProvider extends FacebookAuthProvider_Instance {
|
3507 | static PROVIDER_ID: string;
|
3508 | /**
|
3509 | * This corresponds to the sign-in method identifier as returned in
|
3510 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3511 | */
|
3512 | static FACEBOOK_SIGN_IN_METHOD: string;
|
3513 | /**
|
3514 | * @example
|
3515 | * ```javascript
|
3516 | * var cred = firebase.auth.FacebookAuthProvider.credential(
|
3517 | * // `event` from the Facebook auth.authResponseChange callback.
|
3518 | * event.authResponse.accessToken
|
3519 | * );
|
3520 | * ```
|
3521 | *
|
3522 | * @param token Facebook access token.
|
3523 | */
|
3524 | static credential(token: string): firebase.auth.OAuthCredential;
|
3525 | }
|
3526 | /**
|
3527 | * @hidden
|
3528 | */
|
3529 | class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider {
|
3530 | /**
|
3531 | * @param scope Facebook OAuth scope.
|
3532 | * @return The provider instance itself.
|
3533 | */
|
3534 | addScope(scope: string): firebase.auth.AuthProvider;
|
3535 | providerId: string;
|
3536 | /**
|
3537 | * Sets the OAuth custom parameters to pass in a Facebook OAuth request for
|
3538 | * popup and redirect sign-in operations.
|
3539 | * Valid parameters include 'auth_type', 'display' and 'locale'.
|
3540 | * For a detailed list, check the
|
3541 | * {@link https://goo.gl/pve4fo Facebook}
|
3542 | * documentation.
|
3543 | * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
|
3544 | * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
|
3545 | * @param customOAuthParameters The custom OAuth parameters to pass
|
3546 | * in the OAuth request.
|
3547 | * @return The provider instance itself.
|
3548 | */
|
3549 | setCustomParameters(
|
3550 | customOAuthParameters: Object
|
3551 | ): firebase.auth.AuthProvider;
|
3552 | }
|
3553 |
|
3554 | /**
|
3555 | * GitHub auth provider.
|
3556 | *
|
3557 | * GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect
|
3558 | * directly, or use the signInWithPopup handler:
|
3559 | *
|
3560 | * @example
|
3561 | * ```javascript
|
3562 | * // Using a redirect.
|
3563 | * firebase.auth().getRedirectResult().then(function(result) {
|
3564 | * if (result.credential) {
|
3565 | * // This gives you a GitHub Access Token.
|
3566 | * var token = result.credential.accessToken;
|
3567 | * }
|
3568 | * var user = result.user;
|
3569 | * }).catch(function(error) {
|
3570 | * // Handle Errors here.
|
3571 | * var errorCode = error.code;
|
3572 | * var errorMessage = error.message;
|
3573 | * // The email of the user's account used.
|
3574 | * var email = error.email;
|
3575 | * // The firebase.auth.AuthCredential type that was used.
|
3576 | * var credential = error.credential;
|
3577 | * if (errorCode === 'auth/account-exists-with-different-credential') {
|
3578 | * alert('You have signed up with a different provider for that email.');
|
3579 | * // Handle linking here if your app allows it.
|
3580 | * } else {
|
3581 | * console.error(error);
|
3582 | * }
|
3583 | * });
|
3584 | *
|
3585 | * // Start a sign in process for an unauthenticated user.
|
3586 | * var provider = new firebase.auth.GithubAuthProvider();
|
3587 | * provider.addScope('repo');
|
3588 | * firebase.auth().signInWithRedirect(provider);
|
3589 | * ```
|
3590 | *
|
3591 | * @example
|
3592 | * ```javascript
|
3593 | * // With popup.
|
3594 | * var provider = new firebase.auth.GithubAuthProvider();
|
3595 | * provider.addScope('repo');
|
3596 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
3597 | * // This gives you a GitHub Access Token.
|
3598 | * var token = result.credential.accessToken;
|
3599 | * // The signed-in user info.
|
3600 | * var user = result.user;
|
3601 | * }).catch(function(error) {
|
3602 | * // Handle Errors here.
|
3603 | * var errorCode = error.code;
|
3604 | * var errorMessage = error.message;
|
3605 | * // The email of the user's account used.
|
3606 | * var email = error.email;
|
3607 | * // The firebase.auth.AuthCredential type that was used.
|
3608 | * var credential = error.credential;
|
3609 | * if (errorCode === 'auth/account-exists-with-different-credential') {
|
3610 | * alert('You have signed up with a different provider for that email.');
|
3611 | * // Handle linking here if your app allows it.
|
3612 | * } else {
|
3613 | * console.error(error);
|
3614 | * }
|
3615 | * });
|
3616 | * ```
|
3617 | *
|
3618 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
3619 | * changes.
|
3620 | */
|
3621 | class GithubAuthProvider extends GithubAuthProvider_Instance {
|
3622 | static PROVIDER_ID: string;
|
3623 | /**
|
3624 | * This corresponds to the sign-in method identifier as returned in
|
3625 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3626 | */
|
3627 | static GITHUB_SIGN_IN_METHOD: string;
|
3628 | /**
|
3629 | * @example
|
3630 | * ```javascript
|
3631 | * var cred = firebase.auth.FacebookAuthProvider.credential(
|
3632 | * // `event` from the Facebook auth.authResponseChange callback.
|
3633 | * event.authResponse.accessToken
|
3634 | * );
|
3635 | * ```
|
3636 | *
|
3637 | * @param token Github access token.
|
3638 | * @return {!firebase.auth.OAuthCredential} The auth provider credential.
|
3639 | */
|
3640 | static credential(token: string): firebase.auth.OAuthCredential;
|
3641 | }
|
3642 | /**
|
3643 | * @hidden
|
3644 | */
|
3645 | class GithubAuthProvider_Instance implements firebase.auth.AuthProvider {
|
3646 | /**
|
3647 | * @param scope Github OAuth scope.
|
3648 | * @return The provider instance itself.
|
3649 | */
|
3650 | addScope(scope: string): firebase.auth.AuthProvider;
|
3651 | providerId: string;
|
3652 | /**
|
3653 | * Sets the OAuth custom parameters to pass in a GitHub OAuth request for popup
|
3654 | * and redirect sign-in operations.
|
3655 | * Valid parameters include 'allow_signup'.
|
3656 | * For a detailed list, check the
|
3657 | * {@link https://developer.github.com/v3/oauth/ GitHub} documentation.
|
3658 | * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
|
3659 | * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
|
3660 | * @param customOAuthParameters The custom OAuth parameters to pass
|
3661 | * in the OAuth request.
|
3662 | * @return The provider instance itself.
|
3663 | */
|
3664 | setCustomParameters(
|
3665 | customOAuthParameters: Object
|
3666 | ): firebase.auth.AuthProvider;
|
3667 | }
|
3668 |
|
3669 | /**
|
3670 | * Google auth provider.
|
3671 | *
|
3672 | * @example
|
3673 | * ```javascript
|
3674 | * // Using a redirect.
|
3675 | * firebase.auth().getRedirectResult().then(function(result) {
|
3676 | * if (result.credential) {
|
3677 | * // This gives you a Google Access Token.
|
3678 | * var token = result.credential.accessToken;
|
3679 | * }
|
3680 | * var user = result.user;
|
3681 | * });
|
3682 | *
|
3683 | * // Start a sign in process for an unauthenticated user.
|
3684 | * var provider = new firebase.auth.GoogleAuthProvider();
|
3685 | * provider.addScope('profile');
|
3686 | * provider.addScope('email');
|
3687 | * firebase.auth().signInWithRedirect(provider);
|
3688 | * ```
|
3689 | *
|
3690 | * @example
|
3691 | * ```javascript
|
3692 | * // Using a popup.
|
3693 | * var provider = new firebase.auth.GoogleAuthProvider();
|
3694 | * provider.addScope('profile');
|
3695 | * provider.addScope('email');
|
3696 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
3697 | * // This gives you a Google Access Token.
|
3698 | * var token = result.credential.accessToken;
|
3699 | * // The signed-in user info.
|
3700 | * var user = result.user;
|
3701 | * });
|
3702 | * ```
|
3703 | *
|
3704 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
3705 | * changes.
|
3706 | */
|
3707 | class GoogleAuthProvider extends GoogleAuthProvider_Instance {
|
3708 | static PROVIDER_ID: string;
|
3709 | /**
|
3710 | * This corresponds to the sign-in method identifier as returned in
|
3711 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
3712 | */
|
3713 | static GOOGLE_SIGN_IN_METHOD: string;
|
3714 | /**
|
3715 | * Creates a credential for Google. At least one of ID token and access token
|
3716 | * is required.
|
3717 | *
|
3718 | * @example
|
3719 | * ```javascript
|
3720 | * // \`googleUser\` from the onsuccess Google Sign In callback.
|
3721 | * var credential = firebase.auth.GoogleAuthProvider.credential(
|
3722 | googleUser.getAuthResponse().id_token);
|
3723 | * firebase.auth().signInWithCredential(credential)
|
3724 | * ```
|
3725 | * @param idToken Google ID token.
|
3726 | * @param accessToken Google access token.
|
3727 | * @return The auth provider credential.
|
3728 | */
|
3729 | static credential(
|
3730 | idToken?: string | null,
|
3731 | accessToken?: string | null
|
3732 | ): firebase.auth.OAuthCredential;
|
3733 | }
|
3734 | /**
|
3735 | * @hidden
|
3736 | */
|
3737 | class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider {
|
3738 | /**
|
3739 | * @param scope Google OAuth scope.
|
3740 | * @return The provider instance itself.
|
3741 | */
|
3742 | addScope(scope: string): firebase.auth.AuthProvider;
|
3743 | providerId: string;
|
3744 | /**
|
3745 | * Sets the OAuth custom parameters to pass in a Google OAuth request for popup
|
3746 | * and redirect sign-in operations.
|
3747 | * Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint'
|
3748 | * and 'prompt'.
|
3749 | * For a detailed list, check the
|
3750 | * {@link https://goo.gl/Xo01Jm Google}
|
3751 | * documentation.
|
3752 | * Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
|
3753 | * 'scope', 'response_type' and 'state' are not allowed and will be ignored.
|
3754 | * @param customOAuthParameters The custom OAuth parameters to pass
|
3755 | * in the OAuth request.
|
3756 | * @return The provider instance itself.
|
3757 | */
|
3758 | setCustomParameters(
|
3759 | customOAuthParameters: Object
|
3760 | ): firebase.auth.AuthProvider;
|
3761 | }
|
3762 |
|
3763 | /**
|
3764 | * Generic OAuth provider.
|
3765 | *
|
3766 | * @example
|
3767 | * ```javascript
|
3768 | * // Using a redirect.
|
3769 | * firebase.auth().getRedirectResult().then(function(result) {
|
3770 | * if (result.credential) {
|
3771 | * // This gives you the OAuth Access Token for that provider.
|
3772 | * var token = result.credential.accessToken;
|
3773 | * }
|
3774 | * var user = result.user;
|
3775 | * });
|
3776 | *
|
3777 | * // Start a sign in process for an unauthenticated user.
|
3778 | * var provider = new firebase.auth.OAuthProvider('google.com');
|
3779 | * provider.addScope('profile');
|
3780 | * provider.addScope('email');
|
3781 | * firebase.auth().signInWithRedirect(provider);
|
3782 | * ```
|
3783 | * @example
|
3784 | * ```javascript
|
3785 | * // Using a popup.
|
3786 | * var provider = new firebase.auth.OAuthProvider('google.com');
|
3787 | * provider.addScope('profile');
|
3788 | * provider.addScope('email');
|
3789 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
3790 | * // This gives you the OAuth Access Token for that provider.
|
3791 | * var token = result.credential.accessToken;
|
3792 | * // The signed-in user info.
|
3793 | * var user = result.user;
|
3794 | * });
|
3795 | * ```
|
3796 | *
|
3797 | * @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
|
3798 | * changes.
|
3799 | * @param providerId The associated provider ID, such as `github.com`.
|
3800 | */
|
3801 | class OAuthProvider implements firebase.auth.AuthProvider {
|
3802 | constructor(providerId: string);
|
3803 | providerId: string;
|
3804 | /**
|
3805 | * @param scope Provider OAuth scope to add.
|
3806 | */
|
3807 | addScope(scope: string): firebase.auth.AuthProvider;
|
3808 | /**
|
3809 | * Creates a Firebase credential from a generic OAuth provider's access token or
|
3810 | * ID token. The raw nonce is required when an ID token with a nonce field is
|
3811 | * provided. The SHA-256 hash of the raw nonce must match the nonce field in
|
3812 | * the ID token.
|
3813 | *
|
3814 | * @example
|
3815 | * ```javascript
|
3816 | * // `googleUser` from the onsuccess Google Sign In callback.
|
3817 | * // Initialize a generate OAuth provider with a `google.com` providerId.
|
3818 | * var provider = new firebase.auth.OAuthProvider('google.com');
|
3819 | * var credential = provider.credential({
|
3820 | * idToken: googleUser.getAuthResponse().id_token,
|
3821 | * });
|
3822 | * firebase.auth().signInWithCredential(credential)
|
3823 | * ```
|
3824 | *
|
3825 | * @param optionsOrIdToken Either the options object containing
|
3826 | * the ID token, access token and raw nonce or the ID token string.
|
3827 | * @param accessToken The OAuth access token.
|
3828 | */
|
3829 | credential(
|
3830 | optionsOrIdToken: firebase.auth.OAuthCredentialOptions | string | null,
|
3831 | accessToken?: string
|
3832 | ): firebase.auth.OAuthCredential;
|
3833 | /**
|
3834 | * Sets the OAuth custom parameters to pass in an OAuth request for popup
|
3835 | * and redirect sign-in operations.
|
3836 | * For a detailed list, check the
|
3837 | * reserved required OAuth 2.0 parameters such as `client_id`, `redirect_uri`,
|
3838 | * `scope`, `response_type` and `state` are not allowed and will be ignored.
|
3839 | * @param customOAuthParameters The custom OAuth parameters to pass
|
3840 | * in the OAuth request.
|
3841 | */
|
3842 | setCustomParameters(
|
3843 | customOAuthParameters: Object
|
3844 | ): firebase.auth.AuthProvider;
|
3845 | }
|
3846 |
|
3847 | class SAMLAuthProvider implements firebase.auth.AuthProvider {
|
3848 | constructor(providerId: string);
|
3849 | providerId: string;
|
3850 | }
|
3851 |
|
3852 | /**
|
3853 | * Interface representing ID token result obtained from
|
3854 | * {string
firebase.User.getIdTokenResult}. It contains the ID token JWT |
3855 | * and other helper properties for getting different data associated with the
|
3856 | * token as well as all the decoded payload claims.
|
3857 | *
|
3858 | * Note that these claims are not to be trusted as they are parsed client side.
|
3859 | * Only server side verification can guarantee the integrity of the token
|
3860 | * claims.
|
3861 | */
|
3862 | interface IdTokenResult {
|
3863 | /**
|
3864 | * The Firebase Auth ID token JWT string.
|
3865 | */
|
3866 | token: string;
|
3867 | /**
|
3868 | * The ID token expiration time formatted as a UTC string.
|
3869 | */
|
3870 | expirationTime: string;
|
3871 | /**
|
3872 | * The authentication time formatted as a UTC string. This is the time the
|
3873 | * user authenticated (signed in) and not the time the token was refreshed.
|
3874 | */
|
3875 | authTime: string;
|
3876 | /**
|
3877 | * The ID token issued at time formatted as a UTC string.
|
3878 | */
|
3879 | issuedAtTime: string;
|
3880 | /**
|
3881 | * The sign-in provider through which the ID token was obtained (anonymous,
|
3882 | * custom, phone, password, etc). Note, this does not map to provider IDs.
|
3883 | */
|
3884 | signInProvider: string | null;
|
3885 | /**
|
3886 | * The type of second factor associated with this session, provided the user
|
3887 | * was multi-factor authenticated (eg. phone, etc).
|
3888 | */
|
3889 | signInSecondFactor: string | null;
|
3890 | /**
|
3891 | * The entire payload claims of the ID token including the standard reserved
|
3892 | * claims as well as the custom claims.
|
3893 | */
|
3894 | claims: {
|
3895 | [key: string]: any;
|
3896 | };
|
3897 | }
|
3898 |
|
3899 | /**
|
3900 | * Defines the options for initializing an
|
3901 | * {@link firebase.auth.OAuthCredential}. For ID tokens with nonce claim,
|
3902 | * the raw nonce has to also be provided.
|
3903 | */
|
3904 | interface OAuthCredentialOptions {
|
3905 | /**
|
3906 | * The OAuth ID token used to initialize the OAuthCredential.
|
3907 | */
|
3908 | idToken?: string;
|
3909 | /**
|
3910 | * The OAuth access token used to initialize the OAuthCredential.
|
3911 | */
|
3912 | accessToken?: string;
|
3913 | /**
|
3914 | * The raw nonce associated with the ID token. It is required when an ID token
|
3915 | * with a nonce field is provided. The SHA-256 hash of the raw nonce must match
|
3916 | * the nonce field in the ID token.
|
3917 | */
|
3918 | rawNonce?: string;
|
3919 | }
|
3920 |
|
3921 | /**
|
3922 | * The base class for asserting ownership of a second factor. This is used to
|
3923 | * facilitate enrollment of a second factor on an existing user
|
3924 | * or sign-in of a user who already verified the first factor.
|
3925 | *
|
3926 | */
|
3927 | abstract class MultiFactorAssertion {
|
3928 | /**
|
3929 | * The identifier of the second factor.
|
3930 | */
|
3931 | factorId: string;
|
3932 | }
|
3933 |
|
3934 | /**
|
3935 | * The class for asserting ownership of a phone second factor.
|
3936 | */
|
3937 | class PhoneMultiFactorAssertion extends firebase.auth.MultiFactorAssertion {
|
3938 | private constructor();
|
3939 | }
|
3940 |
|
3941 | /**
|
3942 | * The class used to initialize { firebase.auth.PhoneMultiFactorAssertion}.
|
3943 | */
|
3944 | class PhoneMultiFactorGenerator {
|
3945 | private constructor();
|
3946 | /**
|
3947 | * The identifier of the phone second factor: `phone`.
|
3948 | */
|
3949 | static FACTOR_ID: string;
|
3950 | /**
|
3951 | * Initializes the { firebase.auth.PhoneMultiFactorAssertion} to confirm ownership
|
3952 | * of the phone second factor.
|
3953 | */
|
3954 | static assertion(
|
3955 | phoneAuthCredential: firebase.auth.PhoneAuthCredential
|
3956 | ): firebase.auth.PhoneMultiFactorAssertion;
|
3957 | }
|
3958 |
|
3959 | /**
|
3960 | * A structure containing the information of a second factor entity.
|
3961 | */
|
3962 | interface MultiFactorInfo {
|
3963 | /**
|
3964 | * The multi-factor enrollment ID.
|
3965 | */
|
3966 | uid: string;
|
3967 | /**
|
3968 | * The user friendly name of the current second factor.
|
3969 | */
|
3970 | displayName?: string | null;
|
3971 | /**
|
3972 | * The enrollment date of the second factor formatted as a UTC string.
|
3973 | */
|
3974 | enrollmentTime: string;
|
3975 | /**
|
3976 | * The identifier of the second factor.
|
3977 | */
|
3978 | factorId: string;
|
3979 | }
|
3980 |
|
3981 | /**
|
3982 | * The subclass of the MultiFactorInfo interface for phone number second factors.
|
3983 | * The factorId of this second factor is
|
3984 | * {@link firebase.auth.PhoneMultiFactorGenerator.FACTOR_ID}.
|
3985 | */
|
3986 | interface PhoneMultiFactorInfo extends firebase.auth.MultiFactorInfo {
|
3987 | /**
|
3988 | * The phone number associated with the current second factor.
|
3989 | */
|
3990 | phoneNumber: string;
|
3991 | }
|
3992 |
|
3993 | /**
|
3994 | * The information required to verify the ownership of a phone number. The
|
3995 | * information that's required depends on whether you are doing single-factor
|
3996 | * sign-in, multi-factor enrollment or multi-factor sign-in.
|
3997 | */
|
3998 | type PhoneInfoOptions =
|
3999 | | firebase.auth.PhoneSingleFactorInfoOptions
|
4000 | | firebase.auth.PhoneMultiFactorEnrollInfoOptions
|
4001 | | firebase.auth.PhoneMultiFactorSignInInfoOptions;
|
4002 | /**
|
4003 | * The phone info options for single-factor sign-in. Only phone number is
|
4004 | * required.
|
4005 | */
|
4006 | interface PhoneSingleFactorInfoOptions {
|
4007 | phoneNumber: string;
|
4008 | }
|
4009 |
|
4010 | /**
|
4011 | * The phone info options for multi-factor enrollment. Phone number and
|
4012 | * multi-factor session are required.
|
4013 | */
|
4014 | interface PhoneMultiFactorEnrollInfoOptions {
|
4015 | phoneNumber: string;
|
4016 | session: firebase.auth.MultiFactorSession;
|
4017 | }
|
4018 |
|
4019 | /**
|
4020 | * The phone info options for multi-factor sign-in. Either multi-factor hint or
|
4021 | * multi-factor UID and multi-factor session are required.
|
4022 | */
|
4023 | interface PhoneMultiFactorSignInInfoOptions {
|
4024 | multiFactorHint?: firebase.auth.MultiFactorInfo;
|
4025 | multiFactorUid?: string;
|
4026 | session: firebase.auth.MultiFactorSession;
|
4027 | }
|
4028 |
|
4029 | /**
|
4030 | * The class used to facilitate recovery from
|
4031 | * {@link firebase.auth.MultiFactorError} when a user needs to provide a second
|
4032 | * factor to sign in.
|
4033 | *
|
4034 | * @example
|
4035 | * ```javascript
|
4036 | * firebase.auth().signInWithEmailAndPassword()
|
4037 | * .then(function(result) {
|
4038 | * // User signed in. No 2nd factor challenge is needed.
|
4039 | * })
|
4040 | * .catch(function(error) {
|
4041 | * if (error.code == 'auth/multi-factor-auth-required') {
|
4042 | * var resolver = error.resolver;
|
4043 | * // Show UI to let user select second factor.
|
4044 | * var multiFactorHints = resolver.hints;
|
4045 | * } else {
|
4046 | * // Handle other errors.
|
4047 | * }
|
4048 | * });
|
4049 | *
|
4050 | * // The enrolled second factors that can be used to complete
|
4051 | * // sign-in are returned in the `MultiFactorResolver.hints` list.
|
4052 | * // UI needs to be presented to allow the user to select a second factor
|
4053 | * // from that list.
|
4054 | *
|
4055 | * var selectedHint = // ; selected from multiFactorHints
|
4056 | * var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
|
4057 | * var phoneInfoOptions = {
|
4058 | * multiFactorHint: selectedHint,
|
4059 | * session: resolver.session
|
4060 | * };
|
4061 | * phoneAuthProvider.verifyPhoneNumber(
|
4062 | * phoneInfoOptions,
|
4063 | * appVerifier
|
4064 | * ).then(function(verificationId) {
|
4065 | * // store verificationID and show UI to let user enter verification code.
|
4066 | * });
|
4067 | *
|
4068 | * // UI to enter verification code and continue.
|
4069 | * // Continue button click handler
|
4070 | * var phoneAuthCredential =
|
4071 | * firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
|
4072 | * var multiFactorAssertion =
|
4073 | * firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
|
4074 | * resolver.resolveSignIn(multiFactorAssertion)
|
4075 | * .then(function(userCredential) {
|
4076 | * // User signed in.
|
4077 | * });
|
4078 | * ```
|
4079 | */
|
4080 | class MultiFactorResolver {
|
4081 | private constructor();
|
4082 | /**
|
4083 | * The Auth instance used to sign in with the first factor.
|
4084 | */
|
4085 | auth: firebase.auth.Auth;
|
4086 | /**
|
4087 | * The session identifier for the current sign-in flow, which can be used
|
4088 | * to complete the second factor sign-in.
|
4089 | */
|
4090 | session: firebase.auth.MultiFactorSession;
|
4091 | /**
|
4092 | * The list of hints for the second factors needed to complete the sign-in
|
4093 | * for the current session.
|
4094 | */
|
4095 | hints: firebase.auth.MultiFactorInfo[];
|
4096 | /**
|
4097 | * A helper function to help users complete sign in with a second factor
|
4098 | * using an { firebase.auth.MultiFactorAssertion} confirming the user
|
4099 | * successfully completed the second factor challenge.
|
4100 | *
|
4101 | * <h4>Error Codes</h4>
|
4102 | * <dl>
|
4103 | * <dt>auth/invalid-verification-code</dt>
|
4104 | * <dd>Thrown if the verification code is not valid.</dd>
|
4105 | * <dt>auth/missing-verification-code</dt>
|
4106 | * <dd>Thrown if the verification code is missing.</dd>
|
4107 | * <dt>auth/invalid-verification-id</dt>
|
4108 | * <dd>Thrown if the credential is a
|
4109 | * { firebase.auth.PhoneAuthProvider.credential} and the verification
|
4110 | * ID of the credential is not valid.</dd>
|
4111 | * <dt>auth/missing-verification-id</dt>
|
4112 | * <dd>Thrown if the verification ID is missing.</dd>
|
4113 | * <dt>auth/code-expired</dt>
|
4114 | * <dd>Thrown if the verification code has expired.</dd>
|
4115 | * <dt>auth/invalid-multi-factor-session</dt>
|
4116 | * <dd>Thrown if the request does not contain a valid proof of first factor
|
4117 | * successful sign-in.</dd>
|
4118 | * <dt>auth/missing-multi-factor-session</dt>
|
4119 | * <dd>Thrown if The request is missing proof of first factor successful
|
4120 | * sign-in.</dd>
|
4121 | * </dl>
|
4122 | *
|
4123 | * in with.
assertion The multi-factor assertion to resolve sign- |
4124 | * with the user credential object.
The promise that resolves |
4125 | */
|
4126 | resolveSignIn(
|
4127 | assertion: firebase.auth.MultiFactorAssertion
|
4128 | ): Promise<firebase.auth.UserCredential>;
|
4129 | }
|
4130 |
|
4131 | /**
|
4132 | * The multi-factor session object used for enrolling a second factor on a
|
4133 | * user or helping sign in an enrolled user with a second factor.
|
4134 | */
|
4135 | class MultiFactorSession {
|
4136 | private constructor();
|
4137 | }
|
4138 |
|
4139 | /**
|
4140 | * Classes that represents the Phone Auth credentials returned by a
|
4141 | * { firebase.auth.PhoneAuthProvider}.
|
4142 | *
|
4143 | */
|
4144 | class PhoneAuthCredential extends AuthCredential {
|
4145 | private constructor();
|
4146 | }
|
4147 |
|
4148 | /**
|
4149 | * Phone number auth provider.
|
4150 | *
|
4151 | * @example
|
4152 | * ```javascript
|
4153 | * // 'recaptcha-container' is the ID of an element in the DOM.
|
4154 | * var applicationVerifier = new firebase.auth.RecaptchaVerifier(
|
4155 | * 'recaptcha-container');
|
4156 | * var provider = new firebase.auth.PhoneAuthProvider();
|
4157 | * provider.verifyPhoneNumber('+16505550101', applicationVerifier)
|
4158 | * .then(function(verificationId) {
|
4159 | * var verificationCode = window.prompt('Please enter the verification ' +
|
4160 | * 'code that was sent to your mobile device.');
|
4161 | * return firebase.auth.PhoneAuthProvider.credential(verificationId,
|
4162 | * verificationCode);
|
4163 | * })
|
4164 | * .then(function(phoneCredential) {
|
4165 | * return firebase.auth().signInWithCredential(phoneCredential);
|
4166 | * });
|
4167 | * ```
|
4168 | * @param auth The Firebase Auth instance in which
|
4169 | * sign-ins should occur. Uses the default Auth instance if unspecified.
|
4170 | */
|
4171 | class PhoneAuthProvider extends PhoneAuthProvider_Instance {
|
4172 | static PROVIDER_ID: string;
|
4173 | /**
|
4174 | * This corresponds to the sign-in method identifier as returned in
|
4175 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
4176 | */
|
4177 | static PHONE_SIGN_IN_METHOD: string;
|
4178 | /**
|
4179 | * Creates a phone auth credential, given the verification ID from
|
4180 | * {@link firebase.auth.PhoneAuthProvider.verifyPhoneNumber} and the code
|
4181 | * that was sent to the user's mobile device.
|
4182 | *
|
4183 | * <h4>Error Codes</h4>
|
4184 | * <dl>
|
4185 | * <dt>auth/missing-verification-code</dt>
|
4186 | * <dd>Thrown if the verification code is missing.</dd>
|
4187 | * <dt>auth/missing-verification-id</dt>
|
4188 | * <dd>Thrown if the verification ID is missing.</dd>
|
4189 | * </dl>
|
4190 | *
|
4191 | * @param verificationId The verification ID returned from
|
4192 | * {@link firebase.auth.PhoneAuthProvider.verifyPhoneNumber}.
|
4193 | * @param verificationCode The verification code sent to the user's
|
4194 | * mobile device.
|
4195 | * @return The auth provider credential.
|
4196 | */
|
4197 | static credential(
|
4198 | verificationId: string,
|
4199 | verificationCode: string
|
4200 | ): firebase.auth.AuthCredential;
|
4201 | }
|
4202 | /**
|
4203 | * @hidden
|
4204 | */
|
4205 | class PhoneAuthProvider_Instance implements firebase.auth.AuthProvider {
|
4206 | constructor(auth?: firebase.auth.Auth | null);
|
4207 | providerId: string;
|
4208 | /**
|
4209 | * Starts a phone number authentication flow by sending a verification code to
|
4210 | * the given phone number. Returns an ID that can be passed to
|
4211 | * {this flow.
firebase.auth.PhoneAuthProvider.credential} to identify |
4212 | *
|
4213 | * For abuse prevention, this method also requires a
|
4214 | * { firebase.auth.ApplicationVerifier}. The Firebase Auth SDK includes
|
4215 | * a reCAPTCHA-based implementation, { firebase.auth.RecaptchaVerifier}.
|
4216 | *
|
4217 | * <h4>Error Codes</h4>
|
4218 | * <dl>
|
4219 | * <dt>auth/captcha-check-failed</dt>
|
4220 | * <dd>Thrown if the reCAPTCHA response token was invalid, expired, or if
|
4221 | * this method was called from a non-whitelisted domain.</dd>
|
4222 | * <dt>auth/invalid-phone-number</dt>
|
4223 | * <dd>Thrown if the phone number has an invalid format.</dd>
|
4224 | * <dt>auth/missing-phone-number</dt>
|
4225 | * <dd>Thrown if the phone number is missing.</dd>
|
4226 | * <dt>auth/quota-exceeded</dt>
|
4227 | * <dd>Thrown if the SMS quota for the Firebase project has been exceeded.</dd>
|
4228 | * <dt>auth/user-disabled</dt>
|
4229 | * <dd>Thrown if the user corresponding to the given phone number has been
|
4230 | * disabled.</dd>
|
4231 | * <dt>auth/maximum-second-factor-count-exceeded</dt>
|
4232 | * <dd>Thrown if The maximum allowed number of second factors on a user
|
4233 | * has been exceeded.</dd>
|
4234 | * <dt>auth/second-factor-already-in-use</dt>
|
4235 | * <dd>Thrown if the second factor is already enrolled on this account.</dd>
|
4236 | * <dt>auth/unsupported-first-factor</dt>
|
4237 | * <dd>Thrown if the first factor being used to sign in is not supported.</dd>
|
4238 | * <dt>auth/unverified-email</dt>
|
4239 | * <dd>Thrown if the email of the account is not verified.</dd>
|
4240 | * </dl>
|
4241 | *
|
4242 | * @param phoneInfoOptions The user's {@link firebase.auth.PhoneInfoOptions}.
|
4243 | * The phone number should be in E.164 format (e.g. +16505550101).
|
4244 | * applicationVerifier
|
4245 | * Promise for the verification ID.
A |
4246 | */
|
4247 | verifyPhoneNumber(
|
4248 | phoneInfoOptions: firebase.auth.PhoneInfoOptions | string,
|
4249 | applicationVerifier: firebase.auth.ApplicationVerifier
|
4250 | ): Promise<string>;
|
4251 | }
|
4252 |
|
4253 | /**
|
4254 | * An {@link https://www.google.com/recaptcha/ reCAPTCHA}-based application
|
4255 | * verifier.
|
4256 | *
|
4257 | * @webonly
|
4258 | *
|
4259 | * @param container The reCAPTCHA container parameter. This
|
4260 | * has different meaning depending on whether the reCAPTCHA is hidden or
|
4261 | * visible. For a visible reCAPTCHA the container must be empty. If a string
|
4262 | * is used, it has to correspond to an element ID. The corresponding element
|
4263 | * must also must be in the DOM at the time of initialization.
|
4264 | * @param parameters The optional reCAPTCHA parameters. Check the
|
4265 | * reCAPTCHA docs for a comprehensive list. All parameters are accepted
|
4266 | * except for the sitekey. Firebase Auth backend provisions a reCAPTCHA for
|
4267 | * each project and will configure this upon rendering. For an invisible
|
4268 | * reCAPTCHA, a size key must have the value 'invisible'.
|
4269 | * @param app The corresponding Firebase app. If none is
|
4270 | * provided, the default Firebase App instance is used. A Firebase App
|
4271 | * instance must be initialized with an API key, otherwise an error will be
|
4272 | * thrown.
|
4273 | */
|
4274 | class RecaptchaVerifier extends RecaptchaVerifier_Instance {}
|
4275 | /**
|
4276 | * @webonly
|
4277 | * @hidden
|
4278 | */
|
4279 | class RecaptchaVerifier_Instance
|
4280 | implements firebase.auth.ApplicationVerifier {
|
4281 | constructor(
|
4282 | container: any | string,
|
4283 | parameters?: Object | null,
|
4284 | app?: firebase.app.App | null
|
4285 | );
|
4286 | /**
|
4287 | * Clears the reCAPTCHA widget from the page and destroys the current instance.
|
4288 | */
|
4289 | clear(): void;
|
4290 | /**
|
4291 | * Renders the reCAPTCHA widget on the page.
|
4292 | * @return A Promise that resolves with the
|
4293 | * reCAPTCHA widget ID.
|
4294 | */
|
4295 | render(): Promise<number>;
|
4296 | /**
|
4297 | * The application verifier type. For a reCAPTCHA verifier, this is 'recaptcha'.
|
4298 | */
|
4299 | type: string;
|
4300 | /**
|
4301 | * Waits for the user to solve the reCAPTCHA and resolves with the reCAPTCHA
|
4302 | * token.
|
4303 | * @return A Promise for the reCAPTCHA token.
|
4304 | */
|
4305 | verify(): Promise<string>;
|
4306 | }
|
4307 |
|
4308 | /**
|
4309 | * Twitter auth provider.
|
4310 | *
|
4311 | * @example
|
4312 | * ```javascript
|
4313 | * // Using a redirect.
|
4314 | * firebase.auth().getRedirectResult().then(function(result) {
|
4315 | * if (result.credential) {
|
4316 | * // For accessing the Twitter API.
|
4317 | * var token = result.credential.accessToken;
|
4318 | * var secret = result.credential.secret;
|
4319 | * }
|
4320 | * var user = result.user;
|
4321 | * });
|
4322 | *
|
4323 | * // Start a sign in process for an unauthenticated user.
|
4324 | * var provider = new firebase.auth.TwitterAuthProvider();
|
4325 | * firebase.auth().signInWithRedirect(provider);
|
4326 | * ```
|
4327 | * @example
|
4328 | * ```javascript
|
4329 | * // Using a popup.
|
4330 | * var provider = new firebase.auth.TwitterAuthProvider();
|
4331 | * firebase.auth().signInWithPopup(provider).then(function(result) {
|
4332 | * // For accessing the Twitter API.
|
4333 | * var token = result.credential.accessToken;
|
4334 | * var secret = result.credential.secret;
|
4335 | * // The signed-in user info.
|
4336 | * var user = result.user;
|
4337 | * });
|
4338 | * ```
|
4339 | *
|
4340 | * @see {in state
firebase.auth.Auth.onAuthStateChanged} to receive sign |
4341 | * changes.
|
4342 | */
|
4343 | class TwitterAuthProvider extends TwitterAuthProvider_Instance {
|
4344 | static PROVIDER_ID: string;
|
4345 | /**
|
4346 | * This corresponds to the sign-in method identifier as returned in
|
4347 | * {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
|
4348 | *
|
4349 | */
|
4350 | static TWITTER_SIGN_IN_METHOD: string;
|
4351 | /**
|
4352 | * @param token Twitter access token.
|
4353 | * @param secret Twitter secret.
|
4354 | * @return The auth provider credential.
|
4355 | */
|
4356 | static credential(
|
4357 | token: string,
|
4358 | secret: string
|
4359 | ): firebase.auth.OAuthCredential;
|
4360 | }
|
4361 | /**
|
4362 | * @hidden
|
4363 | */
|
4364 | class TwitterAuthProvider_Instance implements firebase.auth.AuthProvider {
|
4365 | providerId: string;
|
4366 | /**
|
4367 | * Sets the OAuth custom parameters to pass in a Twitter OAuth request for popup
|
4368 | * and redirect sign-in operations.
|
4369 | * Valid parameters include 'lang'.
|
4370 | * Reserved required OAuth 1.0 parameters such as 'oauth_consumer_key',
|
4371 | * 'oauth_token', 'oauth_signature', etc are not allowed and will be ignored.
|
4372 | * @param customOAuthParameters The custom OAuth parameters to pass
|
4373 | * in the OAuth request.
|
4374 | * @return The provider instance itself.
|
4375 | */
|
4376 | setCustomParameters(
|
4377 | customOAuthParameters: Object
|
4378 | ): firebase.auth.AuthProvider;
|
4379 | }
|
4380 |
|
4381 | /**
|
4382 | * A structure containing a User, an AuthCredential, the operationType, and
|
4383 | * any additional user information that was returned from the identity provider.
|
4384 | * operationType could be 'signIn' for a sign-in operation, 'link' for a linking
|
4385 | * operation and 'reauthenticate' for a reauthentication operation.
|
4386 | */
|
4387 | type UserCredential = {
|
4388 | additionalUserInfo?: firebase.auth.AdditionalUserInfo | null;
|
4389 | credential: firebase.auth.AuthCredential | null;
|
4390 | operationType?: string | null;
|
4391 | user: firebase.User | null;
|
4392 | };
|
4393 |
|
4394 | /**
|
4395 | * Interface representing a user's metadata.
|
4396 | */
|
4397 | interface UserMetadata {
|
4398 | creationTime?: string;
|
4399 | lastSignInTime?: string;
|
4400 | }
|
4401 | }
|
4402 |
|
4403 | /**
|
4404 | * @webonly
|
4405 | */
|
4406 | declare namespace firebase.analytics {
|
4407 | /**
|
4408 | * The Firebase Analytics service interface.
|
4409 | *
|
4410 | * Do not call this constructor directly. Instead, use
|
4411 | * {@link firebase.analytics `firebase.analytics()`}.
|
4412 | */
|
4413 | export interface Analytics {
|
4414 | /**
|
4415 | * The {@link firebase.app.App app} associated with the `Analytics` service
|
4416 | * instance.
|
4417 | *
|
4418 | * @example
|
4419 | * ```javascript
|
4420 | * var app = analytics.app;
|
4421 | * ```
|
4422 | */
|
4423 | app: firebase.app.App;
|
4424 |
|
4425 | /**
|
4426 | * Sends analytics event with given `eventParams`. This method
|
4427 | * automatically associates this logged event with this Firebase web
|
4428 | * app instance on this device.
|
4429 | * List of recommended event parameters can be found in
|
4430 | * {@link https://developers.google.com/gtagjs/reference/event
|
4431 | * the gtag.js reference documentation}.
|
4432 | */
|
4433 | logEvent(
|
4434 | eventName: 'add_payment_info',
|
4435 | eventParams?: {
|
4436 | coupon?: EventParams['coupon'];
|
4437 | currency?: EventParams['currency'];
|
4438 | items?: EventParams['items'];
|
4439 | payment_type?: EventParams['payment_type'];
|
4440 | value?: EventParams['value'];
|
4441 | [key: string]: any;
|
4442 | },
|
4443 | options?: firebase.analytics.AnalyticsCallOptions
|
4444 | ): void;
|
4445 |
|
4446 | /**
|
4447 | * Sends analytics event with given `eventParams`. This method
|
4448 | * automatically associates this logged event with this Firebase web
|
4449 | * app instance on this device.
|
4450 | * List of recommended event parameters can be found in
|
4451 | * {@link https://developers.google.com/gtagjs/reference/event
|
4452 | * the gtag.js reference documentation}.
|
4453 | */
|
4454 | logEvent(
|
4455 | eventName: 'add_shipping_info',
|
4456 | eventParams: {
|
4457 | coupon?: EventParams['coupon'];
|
4458 | currency?: EventParams['currency'];
|
4459 | items?: EventParams['items'];
|
4460 | shipping_tier?: EventParams['shipping_tier'];
|
4461 | value?: EventParams['value'];
|
4462 | [key: string]: any;
|
4463 | },
|
4464 | options?: firebase.analytics.AnalyticsCallOptions
|
4465 | ): void;
|
4466 |
|
4467 | /**
|
4468 | * Sends analytics event with given `eventParams`. This method
|
4469 | * automatically associates this logged event with this Firebase web
|
4470 | * app instance on this device.
|
4471 | * List of recommended event parameters can be found in
|
4472 | * {@link https://developers.google.com/gtagjs/reference/event
|
4473 | * the gtag.js reference documentation}.
|
4474 | */
|
4475 | logEvent(
|
4476 | eventName: 'add_to_cart' | 'add_to_wishlist' | 'remove_from_cart',
|
4477 | eventParams: {
|
4478 | currency?: EventParams['currency'];
|
4479 | value?: EventParams['value'];
|
4480 | items?: EventParams['items'];
|
4481 | [key: string]: any;
|
4482 | },
|
4483 | options?: firebase.analytics.AnalyticsCallOptions
|
4484 | ): void;
|
4485 |
|
4486 | /**
|
4487 | * Sends analytics event with given `eventParams`. This method
|
4488 | * automatically associates this logged event with this Firebase web
|
4489 | * app instance on this device.
|
4490 | * List of recommended event parameters can be found in
|
4491 | * {@link https://developers.google.com/gtagjs/reference/event
|
4492 | * the gtag.js reference documentation}.
|
4493 | */
|
4494 | logEvent(
|
4495 | eventName: 'begin_checkout',
|
4496 | eventParams: {
|
4497 | currency?: EventParams['currency'];
|
4498 | coupon?: EventParams['coupon'];
|
4499 | value?: EventParams['value'];
|
4500 | items?: EventParams['items'];
|
4501 | [key: string]: any;
|
4502 | },
|
4503 | options?: firebase.analytics.AnalyticsCallOptions
|
4504 | ): void;
|
4505 |
|
4506 | /**
|
4507 | * Sends analytics event with given `eventParams`. This method
|
4508 | * automatically associates this logged event with this Firebase web
|
4509 | * app instance on this device.
|
4510 | * List of recommended event parameters can be found in
|
4511 | * {@link https://developers.google.com/gtagjs/reference/event
|
4512 | * the gtag.js reference documentation}.
|
4513 | */
|
4514 | logEvent(
|
4515 | eventName: 'checkout_progress',
|
4516 | eventParams: {
|
4517 | currency?: EventParams['currency'];
|
4518 | coupon?: EventParams['coupon'];
|
4519 | value?: EventParams['value'];
|
4520 | items?: EventParams['items'];
|
4521 | checkout_step?: EventParams['checkout_step'];
|
4522 | checkout_option?: EventParams['checkout_option'];
|
4523 | [key: string]: any;
|
4524 | },
|
4525 | options?: firebase.analytics.AnalyticsCallOptions
|
4526 | ): void;
|
4527 |
|
4528 | /**
|
4529 | * Sends analytics event with given `eventParams`. This method
|
4530 | * automatically associates this logged event with this Firebase web
|
4531 | * app instance on this device.
|
4532 | * List of recommended event parameters can be found in
|
4533 | * {@link https://developers.google.com/gtagjs/reference/event
|
4534 | * the gtag.js reference documentation}.
|
4535 | */
|
4536 | logEvent(
|
4537 | eventName: 'exception',
|
4538 | eventParams: {
|
4539 | description?: EventParams['description'];
|
4540 | fatal?: EventParams['fatal'];
|
4541 | [key: string]: any;
|
4542 | },
|
4543 | options?: firebase.analytics.AnalyticsCallOptions
|
4544 | ): void;
|
4545 |
|
4546 | /**
|
4547 | * Sends analytics event with given `eventParams`. This method
|
4548 | * automatically associates this logged event with this Firebase web
|
4549 | * app instance on this device.
|
4550 | * List of recommended event parameters can be found in
|
4551 | * {@link https://developers.google.com/gtagjs/reference/event
|
4552 | * the gtag.js reference documentation}.
|
4553 | */
|
4554 | logEvent(
|
4555 | eventName: 'generate_lead',
|
4556 | eventParams: {
|
4557 | value?: EventParams['value'];
|
4558 | currency?: EventParams['currency'];
|
4559 | transaction_id?: EventParams['transaction_id'];
|
4560 | [key: string]: any;
|
4561 | },
|
4562 | options?: firebase.analytics.AnalyticsCallOptions
|
4563 | ): void;
|
4564 |
|
4565 | /**
|
4566 | * Sends analytics event with given `eventParams`. This method
|
4567 | * automatically associates this logged event with this Firebase web
|
4568 | * app instance on this device.
|
4569 | * List of recommended event parameters can be found in
|
4570 | * {@link https://developers.google.com/gtagjs/reference/event
|
4571 | * the gtag.js reference documentation}.
|
4572 | */
|
4573 | logEvent(
|
4574 | eventName: 'login',
|
4575 | eventParams: {
|
4576 | method?: EventParams['method'];
|
4577 | [key: string]: any;
|
4578 | },
|
4579 | options?: firebase.analytics.AnalyticsCallOptions
|
4580 | ): void;
|
4581 |
|
4582 | /**
|
4583 | * Sends analytics event with given `eventParams`. This method
|
4584 | * automatically associates this logged event with this Firebase web
|
4585 | * app instance on this device.
|
4586 | * List of recommended event parameters can be found in
|
4587 | * {@link https://developers.google.com/gtagjs/reference/event
|
4588 | * the gtag.js reference documentation}.
|
4589 | */
|
4590 | logEvent(
|
4591 | eventName: 'page_view',
|
4592 | eventParams: {
|
4593 | page_title?: string;
|
4594 | page_location?: string;
|
4595 | page_path?: string;
|
4596 | [key: string]: any;
|
4597 | },
|
4598 | options?: firebase.analytics.AnalyticsCallOptions
|
4599 | ): void;
|
4600 |
|
4601 | /**
|
4602 | * Sends analytics event with given `eventParams`. This method
|
4603 | * automatically associates this logged event with this Firebase web
|
4604 | * app instance on this device.
|
4605 | * List of recommended event parameters can be found in
|
4606 | * {@link https://developers.google.com/gtagjs/reference/event
|
4607 | * the gtag.js reference documentation}.
|
4608 | */
|
4609 | logEvent(
|
4610 | eventName: 'purchase' | 'refund',
|
4611 | eventParams: {
|
4612 | value?: EventParams['value'];
|
4613 | currency?: EventParams['currency'];
|
4614 | transaction_id: EventParams['transaction_id'];
|
4615 | tax?: EventParams['tax'];
|
4616 | shipping?: EventParams['shipping'];
|
4617 | items?: EventParams['items'];
|
4618 | coupon?: EventParams['coupon'];
|
4619 | affiliation?: EventParams['affiliation'];
|
4620 | [key: string]: any;
|
4621 | },
|
4622 | options?: firebase.analytics.AnalyticsCallOptions
|
4623 | ): void;
|
4624 |
|
4625 | /**
|
4626 | * Sends analytics event with given `eventParams`. This method
|
4627 | * automatically associates this logged event with this Firebase web
|
4628 | * app instance on this device.
|
4629 | * List of recommended event parameters can be found in
|
4630 | * {@link https://developers.google.com/gtagjs/reference/event
|
4631 | * the gtag.js reference documentation}.
|
4632 | */
|
4633 | logEvent(
|
4634 | eventName: 'screen_view',
|
4635 | eventParams: {
|
4636 | app_name: string;
|
4637 | screen_name: EventParams['screen_name'];
|
4638 | app_id?: string;
|
4639 | app_version?: string;
|
4640 | app_installer_id?: string;
|
4641 | [key: string]: any;
|
4642 | },
|
4643 | options?: firebase.analytics.AnalyticsCallOptions
|
4644 | ): void;
|
4645 |
|
4646 | /**
|
4647 | * Sends analytics event with given `eventParams`. This method
|
4648 | * automatically associates this logged event with this Firebase web
|
4649 | * app instance on this device.
|
4650 | * List of recommended event parameters can be found in
|
4651 | * {@link https://developers.google.com/gtagjs/reference/event
|
4652 | * the gtag.js reference documentation}.
|
4653 | */
|
4654 | logEvent(
|
4655 | eventName: 'search' | 'view_search_results',
|
4656 | eventParams: {
|
4657 | search_term?: EventParams['search_term'];
|
4658 | [key: string]: any;
|
4659 | },
|
4660 | options?: firebase.analytics.AnalyticsCallOptions
|
4661 | ): void;
|
4662 |
|
4663 | /**
|
4664 | * Sends analytics event with given `eventParams`. This method
|
4665 | * automatically associates this logged event with this Firebase web
|
4666 | * app instance on this device.
|
4667 | * List of recommended event parameters can be found in
|
4668 | * {@link https://developers.google.com/gtagjs/reference/event
|
4669 | * the gtag.js reference documentation}.
|
4670 | */
|
4671 | logEvent(
|
4672 | eventName: 'select_content',
|
4673 | eventParams: {
|
4674 | items?: EventParams['items'];
|
4675 | promotions?: EventParams['promotions'];
|
4676 | content_type?: EventParams['content_type'];
|
4677 | content_id?: EventParams['content_id'];
|
4678 | [key: string]: any;
|
4679 | },
|
4680 | options?: firebase.analytics.AnalyticsCallOptions
|
4681 | ): void;
|
4682 |
|
4683 | /**
|
4684 | * Sends analytics event with given `eventParams`. This method
|
4685 | * automatically associates this logged event with this Firebase web
|
4686 | * app instance on this device.
|
4687 | * List of recommended event parameters can be found in
|
4688 | * {@link https://developers.google.com/gtagjs/reference/event
|
4689 | * the gtag.js reference documentation}.
|
4690 | */
|
4691 | logEvent(
|
4692 | eventName: 'select_item',
|
4693 | eventParams: {
|
4694 | items?: EventParams['items'];
|
4695 | item_list_name?: EventParams['item_list_name'];
|
4696 | item_list_id?: EventParams['item_list_id'];
|
4697 | [key: string]: any;
|
4698 | },
|
4699 | options?: firebase.analytics.AnalyticsCallOptions
|
4700 | ): void;
|
4701 |
|
4702 | /**
|
4703 | * Sends analytics event with given `eventParams`. This method
|
4704 | * automatically associates this logged event with this Firebase web
|
4705 | * app instance on this device.
|
4706 | * List of recommended event parameters can be found in
|
4707 | * {@link https://developers.google.com/gtagjs/reference/event
|
4708 | * the gtag.js reference documentation}.
|
4709 | */
|
4710 | logEvent(
|
4711 | eventName: 'select_promotion' | 'view_promotion',
|
4712 | eventParams: {
|
4713 | items?: EventParams['items'];
|
4714 | promotion_id?: EventParams['promotion_id'];
|
4715 | promotion_name?: EventParams['promotion_name'];
|
4716 | [key: string]: any;
|
4717 | },
|
4718 | options?: firebase.analytics.AnalyticsCallOptions
|
4719 | ): void;
|
4720 |
|
4721 | /**
|
4722 | * Sends analytics event with given `eventParams`. This method
|
4723 | * automatically associates this logged event with this Firebase web
|
4724 | * app instance on this device.
|
4725 | * List of recommended event parameters can be found in
|
4726 | * {@link https://developers.google.com/gtagjs/reference/event
|
4727 | * the gtag.js reference documentation}.
|
4728 | */
|
4729 | logEvent(
|
4730 | eventName: 'set_checkout_option',
|
4731 | eventParams: {
|
4732 | checkout_step?: EventParams['checkout_step'];
|
4733 | checkout_option?: EventParams['checkout_option'];
|
4734 | [key: string]: any;
|
4735 | },
|
4736 | options?: firebase.analytics.AnalyticsCallOptions
|
4737 | ): void;
|
4738 |
|
4739 | /**
|
4740 | * Sends analytics event with given `eventParams`. This method
|
4741 | * automatically associates this logged event with this Firebase web
|
4742 | * app instance on this device.
|
4743 | * List of recommended event parameters can be found in
|
4744 | * {@link https://developers.google.com/gtagjs/reference/event
|
4745 | * the gtag.js reference documentation}.
|
4746 | */
|
4747 | logEvent(
|
4748 | eventName: 'share',
|
4749 | eventParams: {
|
4750 | method?: EventParams['method'];
|
4751 | content_type?: EventParams['content_type'];
|
4752 | content_id?: EventParams['content_id'];
|
4753 | [key: string]: any;
|
4754 | },
|
4755 | options?: firebase.analytics.AnalyticsCallOptions
|
4756 | ): void;
|
4757 |
|
4758 | /**
|
4759 | * Sends analytics event with given `eventParams`. This method
|
4760 | * automatically associates this logged event with this Firebase web
|
4761 | * app instance on this device.
|
4762 | * List of recommended event parameters can be found in
|
4763 | * {@link https://developers.google.com/gtagjs/reference/event
|
4764 | * the gtag.js reference documentation}.
|
4765 | */
|
4766 | logEvent(
|
4767 | eventName: 'sign_up',
|
4768 | eventParams: {
|
4769 | method?: EventParams['method'];
|
4770 | [key: string]: any;
|
4771 | },
|
4772 | options?: firebase.analytics.AnalyticsCallOptions
|
4773 | ): void;
|
4774 |
|
4775 | /**
|
4776 | * Sends analytics event with given `eventParams`. This method
|
4777 | * automatically associates this logged event with this Firebase web
|
4778 | * app instance on this device.
|
4779 | * List of recommended event parameters can be found in
|
4780 | * {@link https://developers.google.com/gtagjs/reference/event
|
4781 | * the gtag.js reference documentation}.
|
4782 | */
|
4783 | logEvent(
|
4784 | eventName: 'timing_complete',
|
4785 | eventParams: {
|
4786 | name: string;
|
4787 | value: number;
|
4788 | event_category?: string;
|
4789 | event_label?: string;
|
4790 | [key: string]: any;
|
4791 | },
|
4792 | options?: firebase.analytics.AnalyticsCallOptions
|
4793 | ): void;
|
4794 |
|
4795 | /**
|
4796 | * Sends analytics event with given `eventParams`. This method
|
4797 | * automatically associates this logged event with this Firebase web
|
4798 | * app instance on this device.
|
4799 | * List of recommended event parameters can be found in
|
4800 | * {@link https://developers.google.com/gtagjs/reference/event
|
4801 | * the gtag.js reference documentation}.
|
4802 | */
|
4803 | logEvent(
|
4804 | eventName: 'view_cart' | 'view_item',
|
4805 | eventParams: {
|
4806 | currency?: EventParams['currency'];
|
4807 | items?: EventParams['items'];
|
4808 | value?: EventParams['value'];
|
4809 | [key: string]: any;
|
4810 | },
|
4811 | options?: firebase.analytics.AnalyticsCallOptions
|
4812 | ): void;
|
4813 |
|
4814 | /**
|
4815 | * Sends analytics event with given `eventParams`. This method
|
4816 | * automatically associates this logged event with this Firebase web
|
4817 | * app instance on this device.
|
4818 | * List of recommended event parameters can be found in
|
4819 | * {@link https://developers.google.com/gtagjs/reference/event
|
4820 | * the gtag.js reference documentation}.
|
4821 | */
|
4822 | logEvent(
|
4823 | eventName: 'view_item_list',
|
4824 | eventParams: {
|
4825 | items?: EventParams['items'];
|
4826 | item_list_name?: EventParams['item_list_name'];
|
4827 | item_list_id?: EventParams['item_list_id'];
|
4828 | [key: string]: any;
|
4829 | },
|
4830 | options?: firebase.analytics.AnalyticsCallOptions
|
4831 | ): void;
|
4832 |
|
4833 | /**
|
4834 | * Sends analytics event with given `eventParams`. This method
|
4835 | * automatically associates this logged event with this Firebase web
|
4836 | * app instance on this device.
|
4837 | * List of recommended event parameters can be found in
|
4838 | * {@link https://developers.google.com/gtagjs/reference/event
|
4839 | * the gtag.js reference documentation}.
|
4840 | */
|
4841 | logEvent<T extends string>(
|
4842 | eventName: CustomEventName<T>,
|
4843 | eventParams?: { [key: string]: any },
|
4844 | options?: firebase.analytics.AnalyticsCallOptions
|
4845 | ): void;
|
4846 |
|
4847 | /**
|
4848 | * Use gtag 'config' command to set 'screen_name'.
|
4849 | */
|
4850 | setCurrentScreen(
|
4851 | screenName: string,
|
4852 | options?: firebase.analytics.AnalyticsCallOptions
|
4853 | ): void;
|
4854 |
|
4855 | /**
|
4856 | * Use gtag 'config' command to set 'user_id'.
|
4857 | */
|
4858 | setUserId(
|
4859 | id: string,
|
4860 | options?: firebase.analytics.AnalyticsCallOptions
|
4861 | ): void;
|
4862 |
|
4863 | /**
|
4864 | * Use gtag 'config' command to set all params specified.
|
4865 | */
|
4866 | setUserProperties(
|
4867 | properties: firebase.analytics.CustomParams,
|
4868 | options?: firebase.analytics.AnalyticsCallOptions
|
4869 | ): void;
|
4870 |
|
4871 | /**
|
4872 | * Sets whether analytics collection is enabled for this app on this device.
|
4873 | * window['ga-disable-analyticsId'] = true;
|
4874 | */
|
4875 | setAnalyticsCollectionEnabled(enabled: boolean): void;
|
4876 | }
|
4877 |
|
4878 | export type CustomEventName<T> = T extends EventNameString ? never : T;
|
4879 |
|
4880 | /**
|
4881 | * Additional options that can be passed to Firebase Analytics method
|
4882 | * calls such as `logEvent`, `setCurrentScreen`, etc.
|
4883 | */
|
4884 | export interface AnalyticsCallOptions {
|
4885 | /**
|
4886 | * If true, this config or event call applies globally to all
|
4887 | * analytics properties on the page.
|
4888 | */
|
4889 | global: boolean;
|
4890 | }
|
4891 |
|
4892 | /**
|
4893 | * Specifies custom options for your Firebase Analytics instance.
|
4894 | * You must set these before initializing `firebase.analytics()`.
|
4895 | */
|
4896 | export interface SettingsOptions {
|
4897 | /** Sets custom name for `gtag` function. */
|
4898 | gtagName?: string;
|
4899 | /** Sets custom name for `dataLayer` array used by gtag. */
|
4900 | dataLayerName?: string;
|
4901 | }
|
4902 |
|
4903 | /**
|
4904 | * Configures Firebase Analytics to use custom `gtag` or `dataLayer` names.
|
4905 | * Intended to be used if `gtag.js` script has been installed on
|
4906 | * this page independently of Firebase Analytics, and is using non-default
|
4907 | * names for either the `gtag` function or for `dataLayer`.
|
4908 | * Must be called before calling `firebase.analytics()` or it won't
|
4909 | * have any effect.
|
4910 | */
|
4911 | export function settings(settings: firebase.analytics.SettingsOptions): void;
|
4912 |
|
4913 | /**
|
4914 | * Standard gtag.js control parameters.
|
4915 | * For more information, see
|
4916 | * {@link https://developers.google.com/gtagjs/reference/parameter
|
4917 | * the gtag.js documentation on parameters}.
|
4918 | */
|
4919 | export interface ControlParams {
|
4920 | groups?: string | string[];
|
4921 | send_to?: string | string[];
|
4922 | event_callback?: () => void;
|
4923 | event_timeout?: number;
|
4924 | }
|
4925 |
|
4926 | /**
|
4927 | * Standard gtag.js event parameters.
|
4928 | * For more information, see
|
4929 | * {@link https://developers.google.com/gtagjs/reference/parameter
|
4930 | * the gtag.js documentation on parameters}.
|
4931 | */
|
4932 | export interface EventParams {
|
4933 | checkout_option?: string;
|
4934 | checkout_step?: number;
|
4935 | content_id?: string;
|
4936 | content_type?: string;
|
4937 | coupon?: string;
|
4938 | currency?: string;
|
4939 | description?: string;
|
4940 | fatal?: boolean;
|
4941 | items?: Item[];
|
4942 | method?: string;
|
4943 | number?: string;
|
4944 | promotions?: Promotion[];
|
4945 | screen_name?: string;
|
4946 | search_term?: string;
|
4947 | shipping?: Currency;
|
4948 | tax?: Currency;
|
4949 | transaction_id?: string;
|
4950 | value?: number;
|
4951 | event_label?: string;
|
4952 | event_category: string;
|
4953 | shipping_tier?: string;
|
4954 | item_list_id?: string;
|
4955 | item_list_name?: string;
|
4956 | promotion_id?: string;
|
4957 | promotion_name?: string;
|
4958 | payment_type?: string;
|
4959 | affiliation?: string;
|
4960 | }
|
4961 |
|
4962 | /**
|
4963 | * Any custom params the user may pass to gtag.js.
|
4964 | */
|
4965 | export interface CustomParams {
|
4966 | [key: string]: any;
|
4967 | }
|
4968 |
|
4969 | /**
|
4970 | * Type for standard gtag.js event names. `logEvent` also accepts any
|
4971 | * custom string and interprets it as a custom event name.
|
4972 | */
|
4973 | export type EventNameString =
|
4974 | | 'add_payment_info'
|
4975 | | 'add_shipping_info'
|
4976 | | 'add_to_cart'
|
4977 | | 'add_to_wishlist'
|
4978 | | 'begin_checkout'
|
4979 | | 'checkout_progress'
|
4980 | | 'exception'
|
4981 | | 'generate_lead'
|
4982 | | 'login'
|
4983 | | 'page_view'
|
4984 | | 'purchase'
|
4985 | | 'refund'
|
4986 | | 'remove_from_cart'
|
4987 | | 'screen_view'
|
4988 | | 'search'
|
4989 | | 'select_content'
|
4990 | | 'select_item'
|
4991 | | 'select_promotion'
|
4992 | | 'set_checkout_option'
|
4993 | | 'share'
|
4994 | | 'sign_up'
|
4995 | | 'timing_complete'
|
4996 | | 'view_cart'
|
4997 | | 'view_item'
|
4998 | | 'view_item_list'
|
4999 | | 'view_promotion'
|
5000 | | 'view_search_results';
|
5001 |
|
5002 | /**
|
5003 | * Enum of standard gtag.js event names provided for convenient
|
5004 | * developer usage. `logEvent` will also accept any custom string
|
5005 | * and interpret it as a custom event name.
|
5006 | */
|
5007 | export enum EventName {
|
5008 | ADD_PAYMENT_INFO = 'add_payment_info',
|
5009 | ADD_SHIPPING_INFO = 'add_shipping_info',
|
5010 | ADD_TO_CART = 'add_to_cart',
|
5011 | ADD_TO_WISHLIST = 'add_to_wishlist',
|
5012 | BEGIN_CHECKOUT = 'begin_checkout',
|
5013 | /** @deprecated */
|
5014 | CHECKOUT_PROGRESS = 'checkout_progress',
|
5015 | EXCEPTION = 'exception',
|
5016 | GENERATE_LEAD = 'generate_lead',
|
5017 | LOGIN = 'login',
|
5018 | PAGE_VIEW = 'page_view',
|
5019 | PURCHASE = 'purchase',
|
5020 | REFUND = 'refund',
|
5021 | REMOVE_FROM_CART = 'remove_from_cart',
|
5022 | SCREEN_VIEW = 'screen_view',
|
5023 | SEARCH = 'search',
|
5024 | SELECT_CONTENT = 'select_content',
|
5025 | SELECT_ITEM = 'select_item',
|
5026 | SELECT_PROMOTION = 'select_promotion',
|
5027 | /** @deprecated */
|
5028 | SET_CHECKOUT_OPTION = 'set_checkout_option',
|
5029 | SHARE = 'share',
|
5030 | SIGN_UP = 'sign_up',
|
5031 | TIMING_COMPLETE = 'timing_complete',
|
5032 | VIEW_CART = 'view_cart',
|
5033 | VIEW_ITEM = 'view_item',
|
5034 | VIEW_ITEM_LIST = 'view_item_list',
|
5035 | VIEW_PROMOTION = 'view_promotion',
|
5036 | VIEW_SEARCH_RESULTS = 'view_search_results'
|
5037 | }
|
5038 |
|
5039 | export type Currency = string | number;
|
5040 |
|
5041 | export interface Item {
|
5042 | item_id?: string;
|
5043 | item_name?: string;
|
5044 | item_brand?: string;
|
5045 | item_category?: string;
|
5046 | item_category2?: string;
|
5047 | item_category3?: string;
|
5048 | item_category4?: string;
|
5049 | item_category5?: string;
|
5050 | item_variant?: string;
|
5051 | price?: Currency;
|
5052 | quantity?: number;
|
5053 | index?: number;
|
5054 | coupon?: string;
|
5055 | item_list_name?: string;
|
5056 | item_list_id?: string;
|
5057 | discount?: Currency;
|
5058 | affiliation?: string;
|
5059 | creative_name?: string;
|
5060 | creative_slot?: string;
|
5061 | promotion_id?: string;
|
5062 | promotion_name?: string;
|
5063 | location_id?: string;
|
5064 | /** @deprecated Use item_brand instead. */
|
5065 | brand?: string;
|
5066 | /** @deprecated Use item_category instead. */
|
5067 | category?: string;
|
5068 | /** @deprecated Use item_id instead. */
|
5069 | id?: string;
|
5070 | /** @deprecated Use item_name instead. */
|
5071 | name?: string;
|
5072 | }
|
5073 |
|
5074 | /** @deprecated Use Item instead. */
|
5075 | export interface Promotion {
|
5076 | creative_name?: string;
|
5077 | creative_slot?: string;
|
5078 | id?: string;
|
5079 | name?: string;
|
5080 | }
|
5081 | }
|
5082 |
|
5083 | declare namespace firebase.auth.Auth {
|
5084 | type Persistence = string;
|
5085 | /**
|
5086 | * An enumeration of the possible persistence mechanism types.
|
5087 | */
|
5088 | var Persistence: {
|
5089 | /**
|
5090 | * Indicates that the state will be persisted even when the browser window is
|
5091 | * closed or the activity is destroyed in react-native.
|
5092 | */
|
5093 | LOCAL: Persistence;
|
5094 | /**
|
5095 | * Indicates that the state will only be stored in memory and will be cleared
|
5096 | * when the window or activity is refreshed.
|
5097 | */
|
5098 | NONE: Persistence;
|
5099 | /**
|
5100 | * Indicates that the state will only persist in current session/tab, relevant
|
5101 | * to web only, and will be cleared when the tab is closed.
|
5102 | */
|
5103 | SESSION: Persistence;
|
5104 | };
|
5105 | }
|
5106 |
|
5107 | declare namespace firebase.User {
|
5108 | /**
|
5109 | * This is the interface that defines the multi-factor related properties and
|
5110 | * operations pertaining to a {@link firebase.User}.
|
5111 | */
|
5112 | interface MultiFactorUser {
|
5113 | /**
|
5114 | * Returns a list of the user's enrolled second factors.
|
5115 | */
|
5116 | enrolledFactors: firebase.auth.MultiFactorInfo[];
|
5117 | /**
|
5118 | * Enrolls a second factor as identified by the
|
5119 | * {@link firebase.auth.MultiFactorAssertion} for the current user.
|
5120 | * On resolution, the user tokens are updated to reflect the change in the
|
5121 | * JWT payload.
|
5122 | * Accepts an additional display name parameter used to identify the second
|
5123 | * factor to the end user.
|
5124 | * Recent re-authentication is required for this operation to succeed.
|
5125 | * On successful enrollment, existing Firebase sessions (refresh tokens) are
|
5126 | * revoked. When a new factor is enrolled, an email notification is sent
|
5127 | * to the user’s email.
|
5128 | *
|
5129 | * <h4>Error Codes</h4>
|
5130 | * <dl>
|
5131 | * <dt>auth/invalid-verification-code</dt>
|
5132 | * <dd>Thrown if the verification code is not valid.</dd>
|
5133 | * <dt>auth/missing-verification-code</dt>
|
5134 | * <dd>Thrown if the verification code is missing.</dd>
|
5135 | * <dt>auth/invalid-verification-id</dt>
|
5136 | * <dd>Thrown if the credential is a
|
5137 | * {@link firebase.auth.PhoneAuthProvider.credential} and the verification
|
5138 | * ID of the credential is not valid.</dd>
|
5139 | * <dt>auth/missing-verification-id</dt>
|
5140 | * <dd>Thrown if the verification ID is missing.</dd>
|
5141 | * <dt>auth/code-expired</dt>
|
5142 | * <dd>Thrown if the verification code has expired.</dd>
|
5143 | * <dt>auth/maximum-second-factor-count-exceeded</dt>
|
5144 | * <dd>Thrown if The maximum allowed number of second factors on a user
|
5145 | * has been exceeded.</dd>
|
5146 | * <dt>auth/second-factor-already-in-use</dt>
|
5147 | * <dd>Thrown if the second factor is already enrolled on this account.</dd>
|
5148 | * <dt>auth/unsupported-first-factor</dt>
|
5149 | * <dd>Thrown if the first factor being used to sign in is not supported.</dd>
|
5150 | * <dt>auth/unverified-email</dt>
|
5151 | * <dd>Thrown if the email of the account is not verified.</dd>
|
5152 | * <dt>auth/requires-recent-login</dt>
|
5153 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
5154 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
5155 | * resolve.</dd>
|
5156 | * </dl>
|
5157 | *
|
5158 | * @example
|
5159 | * ```javascript
|
5160 | * firebase.auth().currentUser.multiFactor.getSession()
|
5161 | * .then(function(multiFactorSession) {
|
5162 | * // Send verification code
|
5163 | * var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
|
5164 | * var phoneInfoOptions = {
|
5165 | * phoneNumber: phoneNumber,
|
5166 | * session: multiFactorSession
|
5167 | * };
|
5168 | * return phoneAuthProvider.verifyPhoneNumber(
|
5169 | * phoneInfoOptions, appVerifier);
|
5170 | * }).then(function(verificationId) {
|
5171 | * // Store verificationID and show UI to let user enter verification code.
|
5172 | * });
|
5173 | *
|
5174 | * var phoneAuthCredential =
|
5175 | * firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
|
5176 | * var multiFactorAssertion =
|
5177 | * firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
|
5178 | * firebase.auth().currentUser.multiFactor.enroll(multiFactorAssertion)
|
5179 | * .then(function() {
|
5180 | * // Second factor enrolled.
|
5181 | * });
|
5182 | * ```
|
5183 | *
|
5184 | * @param assertion The multi-factor assertion to enroll with.
|
5185 | * @param displayName The display name of the second factor.
|
5186 | */
|
5187 | enroll(
|
5188 | assertion: firebase.auth.MultiFactorAssertion,
|
5189 | displayName?: string | null
|
5190 | ): Promise<void>;
|
5191 | /**
|
5192 | * Returns the session identifier for a second factor enrollment operation.
|
5193 | * This is used to identify the current user trying to enroll a second factor.
|
5194 | * @return The promise that resolves with the
|
5195 | * {@link firebase.auth.MultiFactorSession}.
|
5196 | *
|
5197 | * <h4>Error Codes</h4>
|
5198 | * <dl>
|
5199 | * <dt>auth/user-token-expired</dt>
|
5200 | * <dd>Thrown if the token of the user is expired.</dd>
|
5201 | * </dl>
|
5202 | */
|
5203 | getSession(): Promise<firebase.auth.MultiFactorSession>;
|
5204 | /**
|
5205 | * Unenrolls the specified second factor. To specify the factor to remove, pass
|
5206 | * a {@link firebase.auth.MultiFactorInfo} object
|
5207 | * (retrieved from <code>enrolledFactors()</code>)
|
5208 | * or the factor's UID string.
|
5209 | * Sessions are not revoked when the account is downgraded. An email
|
5210 | * notification is likely to be sent to the user notifying them of the change.
|
5211 | * Recent re-authentication is required for this operation to succeed.
|
5212 | * When an existing factor is unenrolled, an email notification is sent to the
|
5213 | * user’s email.
|
5214 | *
|
5215 | * <h4>Error Codes</h4>
|
5216 | * <dl>
|
5217 | * <dt>auth/multi-factor-info-not-found</dt>
|
5218 | * <dd>Thrown if the user does not have a second factor matching the
|
5219 | * identifier provided.</dd>
|
5220 | * <dt>auth/requires-recent-login</dt>
|
5221 | * <dd>Thrown if the user's last sign-in time does not meet the security
|
5222 | * threshold. Use {@link firebase.User.reauthenticateWithCredential} to
|
5223 | * resolve.</dd>
|
5224 | * </dl>
|
5225 | *
|
5226 | * @example
|
5227 | * ```javascript
|
5228 | * var options = firebase.auth().currentUser.multiFactor.enrolledFactors;
|
5229 | * // Present user the option to unenroll.
|
5230 | * return firebase.auth().currentUser.multiFactor.unenroll(options[i])
|
5231 | * .then(function() {
|
5232 | * // User successfully unenrolled selected factor.
|
5233 | * }).catch(function(error) {
|
5234 | * // Handler error.
|
5235 | * });
|
5236 | * ```
|
5237 | *
|
5238 | * @param option The multi-factor option to unenroll.
|
5239 | */
|
5240 | unenroll(option: firebase.auth.MultiFactorInfo | string): Promise<void>;
|
5241 | }
|
5242 | }
|
5243 |
|
5244 | declare namespace firebase.auth.ActionCodeInfo {
|
5245 | type Operation = string;
|
5246 | /**
|
5247 | * An enumeration of the possible email action types.
|
5248 | */
|
5249 | var Operation: {
|
5250 | /**
|
5251 | * The email link sign-in action.
|
5252 | */
|
5253 | EMAIL_SIGNIN: Operation;
|
5254 | /**
|
5255 | * The password reset action.
|
5256 | */
|
5257 | PASSWORD_RESET: Operation;
|
5258 | /**
|
5259 | * The email revocation action.
|
5260 | */
|
5261 | RECOVER_EMAIL: Operation;
|
5262 | /**
|
5263 | * The revert second factor addition email action.
|
5264 | */
|
5265 | REVERT_SECOND_FACTOR_ADDITION: Operation;
|
5266 | /**
|
5267 | * The verify and update email action.
|
5268 | */
|
5269 | VERIFY_AND_CHANGE_EMAIL: Operation;
|
5270 | /**
|
5271 | * The email verification action.
|
5272 | */
|
5273 | VERIFY_EMAIL: Operation;
|
5274 | };
|
5275 | }
|
5276 |
|
5277 | declare namespace firebase.database {
|
5278 | /**
|
5279 | * A `DataSnapshot` contains data from a Database location.
|
5280 | *
|
5281 | * Any time you read data from the Database, you receive the data as a
|
5282 | * `DataSnapshot`. A `DataSnapshot` is passed to the event callbacks you attach
|
5283 | * with `on()` or `once()`. You can extract the contents of the snapshot as a
|
5284 | * JavaScript object by calling the `val()` method. Alternatively, you can
|
5285 | * traverse into the snapshot by calling `child()` to return child snapshots
|
5286 | * (which you could then call `val()` on).
|
5287 | *
|
5288 | * A `DataSnapshot` is an efficiently generated, immutable copy of the data at
|
5289 | * a Database location. It cannot be modified and will never change (to modify
|
5290 | * data, you always call the `set()` method on a `Reference` directly).
|
5291 | *
|
5292 | */
|
5293 | interface DataSnapshot {
|
5294 | /**
|
5295 | * Gets another `DataSnapshot` for the location at the specified relative path.
|
5296 | *
|
5297 | * Passing a relative path to the `child()` method of a DataSnapshot returns
|
5298 | * another `DataSnapshot` for the location at the specified relative path. The
|
5299 | * relative path can either be a simple child name (for example, "ada") or a
|
5300 | * deeper, slash-separated path (for example, "ada/name/first"). If the child
|
5301 | * location has no data, an empty `DataSnapshot` (that is, a `DataSnapshot`
|
5302 | * whose value is `null`) is returned.
|
5303 | *
|
5304 | * @example
|
5305 | * ```javascript
|
5306 | * // Assume we have the following data in the Database:
|
5307 | * {
|
5308 | * "name": {
|
5309 | * "first": "Ada",
|
5310 | * "last": "Lovelace"
|
5311 | * }
|
5312 | * }
|
5313 | *
|
5314 | * // Test for the existence of certain keys within a DataSnapshot
|
5315 | * var ref = firebase.database().ref("users/ada");
|
5316 | * ref.once("value")
|
5317 | * .then(function(snapshot) {
|
5318 | * var name = snapshot.child("name").val(); // {first:"Ada",last:"Lovelace"}
|
5319 | * var firstName = snapshot.child("name/first").val(); // "Ada"
|
5320 | * var lastName = snapshot.child("name").child("last").val(); // "Lovelace"
|
5321 | * var age = snapshot.child("age").val(); // null
|
5322 | * });
|
5323 | * ```
|
5324 | *
|
5325 | * @param path A relative path to the location of child data.
|
5326 | */
|
5327 | child(path: string): firebase.database.DataSnapshot;
|
5328 | /**
|
5329 | * Returns true if this `DataSnapshot` contains any data. It is slightly more
|
5330 | * efficient than using `snapshot.val() !== null`.
|
5331 | *
|
5332 | * @example
|
5333 | * ```javascript
|
5334 | * // Assume we have the following data in the Database:
|
5335 | * {
|
5336 | * "name": {
|
5337 | * "first": "Ada",
|
5338 | * "last": "Lovelace"
|
5339 | * }
|
5340 | * }
|
5341 | *
|
5342 | * // Test for the existence of certain keys within a DataSnapshot
|
5343 | * var ref = firebase.database().ref("users/ada");
|
5344 | * ref.once("value")
|
5345 | * .then(function(snapshot) {
|
5346 | * var a = snapshot.exists(); // true
|
5347 | * var b = snapshot.child("name").exists(); // true
|
5348 | * var c = snapshot.child("name/first").exists(); // true
|
5349 | * var d = snapshot.child("name/middle").exists(); // false
|
5350 | * });
|
5351 | * ```
|
5352 | */
|
5353 | exists(): boolean;
|
5354 | /**
|
5355 | * Exports the entire contents of the DataSnapshot as a JavaScript object.
|
5356 | *
|
5357 | * The `exportVal()` method is similar to `val()`, except priority information
|
5358 | * is included (if available), making it suitable for backing up your data.
|
5359 | *
|
5360 | * @return The DataSnapshot's contents as a JavaScript value (Object,
|
5361 | * Array, string, number, boolean, or `null`).
|
5362 | */
|
5363 | exportVal(): any;
|
5364 | /**
|
5365 | * Enumerates the top-level children in the `DataSnapshot`.
|
5366 | *
|
5367 | * Because of the way JavaScript objects work, the ordering of data in the
|
5368 | * JavaScript object returned by `val()` is not guaranteed to match the ordering
|
5369 | * on the server nor the ordering of `child_added` events. That is where
|
5370 | * `forEach()` comes in handy. It guarantees the children of a `DataSnapshot`
|
5371 | * will be iterated in their query order.
|
5372 | *
|
5373 | * If no explicit `orderBy*()` method is used, results are returned
|
5374 | * ordered by key (unless priorities are used, in which case, results are
|
5375 | * returned by priority).
|
5376 | *
|
5377 | * @example
|
5378 | * ```javascript
|
5379 | * // Assume we have the following data in the Database:
|
5380 | * {
|
5381 | * "users": {
|
5382 | * "ada": {
|
5383 | * "first": "Ada",
|
5384 | * "last": "Lovelace"
|
5385 | * },
|
5386 | * "alan": {
|
5387 | * "first": "Alan",
|
5388 | * "last": "Turing"
|
5389 | * }
|
5390 | * }
|
5391 | * }
|
5392 | *
|
5393 | * // Loop through users in order with the forEach() method. The callback
|
5394 | * // provided to forEach() will be called synchronously with a DataSnapshot
|
5395 | * // for each child:
|
5396 | * var query = firebase.database().ref("users").orderByKey();
|
5397 | * query.once("value")
|
5398 | * .then(function(snapshot) {
|
5399 | * snapshot.forEach(function(childSnapshot) {
|
5400 | * // key will be "ada" the first time and "alan" the second time
|
5401 | * var key = childSnapshot.key;
|
5402 | * // childData will be the actual contents of the child
|
5403 | * var childData = childSnapshot.val();
|
5404 | * });
|
5405 | * });
|
5406 | * ```
|
5407 | *
|
5408 | * @example
|
5409 | * ```javascript
|
5410 | * // You can cancel the enumeration at any point by having your callback
|
5411 | * // function return true. For example, the following code sample will only
|
5412 | * // fire the callback function one time:
|
5413 | * var query = firebase.database().ref("users").orderByKey();
|
5414 | * query.once("value")
|
5415 | * .then(function(snapshot) {
|
5416 | * snapshot.forEach(function(childSnapshot) {
|
5417 | * var key = childSnapshot.key; // "ada"
|
5418 | *
|
5419 | * // Cancel enumeration
|
5420 | * return true;
|
5421 | * });
|
5422 | * });
|
5423 | * ```
|
5424 | *
|
5425 | * @param action A function
|
5426 | * that will be called for each child DataSnapshot. The callback can return
|
5427 | * true to cancel further enumeration.
|
5428 | * @return true if enumeration was canceled due to your callback
|
5429 | * returning true.
|
5430 | */
|
5431 | forEach(
|
5432 | action: (a: firebase.database.DataSnapshot) => boolean | void
|
5433 | ): boolean;
|
5434 | /**
|
5435 | * Gets the priority value of the data in this `DataSnapshot`.
|
5436 | *
|
5437 | * Applications need not use priority but can order collections by
|
5438 | * ordinary properties (see
|
5439 | * {@link
|
5440 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
5441 | * Sorting and filtering data}).
|
5442 | */
|
5443 | getPriority(): string | number | null;
|
5444 | /**
|
5445 | * Returns true if the specified child path has (non-null) data.
|
5446 | *
|
5447 | * @example
|
5448 | * ```javascript
|
5449 | * // Assume we have the following data in the Database:
|
5450 | * {
|
5451 | * "name": {
|
5452 | * "first": "Ada",
|
5453 | * "last": "Lovelace"
|
5454 | * }
|
5455 | * }
|
5456 | *
|
5457 | * // Determine which child keys in DataSnapshot have data.
|
5458 | * var ref = firebase.database().ref("users/ada");
|
5459 | * ref.once("value")
|
5460 | * .then(function(snapshot) {
|
5461 | * var hasName = snapshot.hasChild("name"); // true
|
5462 | * var hasAge = snapshot.hasChild("age"); // false
|
5463 | * });
|
5464 | * ```
|
5465 | *
|
5466 | * @param path A relative path to the location of a potential child.
|
5467 | * @return `true` if data exists at the specified child path; else
|
5468 | * `false`.
|
5469 | */
|
5470 | hasChild(path: string): boolean;
|
5471 | /**
|
5472 | * Returns whether or not the `DataSnapshot` has any non-`null` child
|
5473 | * properties.
|
5474 | *
|
5475 | * You can use `hasChildren()` to determine if a `DataSnapshot` has any
|
5476 | * children. If it does, you can enumerate them using `forEach()`. If it
|
5477 | * doesn't, then either this snapshot contains a primitive value (which can be
|
5478 | * retrieved with `val()`) or it is empty (in which case, `val()` will return
|
5479 | * `null`).
|
5480 | *
|
5481 | * @example
|
5482 | * ```javascript
|
5483 | * // Assume we have the following data in the Database:
|
5484 | * {
|
5485 | * "name": {
|
5486 | * "first": "Ada",
|
5487 | * "last": "Lovelace"
|
5488 | * }
|
5489 | * }
|
5490 | *
|
5491 | * var ref = firebase.database().ref("users/ada");
|
5492 | * ref.once("value")
|
5493 | * .then(function(snapshot) {
|
5494 | * var a = snapshot.hasChildren(); // true
|
5495 | * var b = snapshot.child("name").hasChildren(); // true
|
5496 | * var c = snapshot.child("name/first").hasChildren(); // false
|
5497 | * });
|
5498 | * ```
|
5499 | *
|
5500 | * @return true if this snapshot has any children; else false.
|
5501 | */
|
5502 | hasChildren(): boolean;
|
5503 | /**
|
5504 | * The key (last part of the path) of the location of this `DataSnapshot`.
|
5505 | *
|
5506 | * The last token in a Database location is considered its key. For example,
|
5507 | * "ada" is the key for the /users/ada/ node. Accessing the key on any
|
5508 | * `DataSnapshot` will return the key for the location that generated it.
|
5509 | * However, accessing the key on the root URL of a Database will return `null`.
|
5510 | *
|
5511 | * @example
|
5512 | * ```javascript
|
5513 | * // Assume we have the following data in the Database:
|
5514 | * {
|
5515 | * "name": {
|
5516 | * "first": "Ada",
|
5517 | * "last": "Lovelace"
|
5518 | * }
|
5519 | * }
|
5520 | *
|
5521 | * var ref = firebase.database().ref("users/ada");
|
5522 | * ref.once("value")
|
5523 | * .then(function(snapshot) {
|
5524 | * var key = snapshot.key; // "ada"
|
5525 | * var childKey = snapshot.child("name/last").key; // "last"
|
5526 | * });
|
5527 | * ```
|
5528 | *
|
5529 | * @example
|
5530 | * ```javascript
|
5531 | * var rootRef = firebase.database().ref();
|
5532 | * rootRef.once("value")
|
5533 | * .then(function(snapshot) {
|
5534 | * var key = snapshot.key; // null
|
5535 | * var childKey = snapshot.child("users/ada").key; // "ada"
|
5536 | * });
|
5537 | * ```
|
5538 | */
|
5539 | key: string | null;
|
5540 | /**
|
5541 | * Returns the number of child properties of this `DataSnapshot`.
|
5542 | *
|
5543 | * @example
|
5544 | * ```javascript
|
5545 | * // Assume we have the following data in the Database:
|
5546 | * {
|
5547 | * "name": {
|
5548 | * "first": "Ada",
|
5549 | * "last": "Lovelace"
|
5550 | * }
|
5551 | * }
|
5552 | *
|
5553 | * var ref = firebase.database().ref("users/ada");
|
5554 | * ref.once("value")
|
5555 | * .then(function(snapshot) {
|
5556 | * var a = snapshot.numChildren(); // 1 ("name")
|
5557 | * var b = snapshot.child("name").numChildren(); // 2 ("first", "last")
|
5558 | * var c = snapshot.child("name/first").numChildren(); // 0
|
5559 | * });
|
5560 | * ```
|
5561 | */
|
5562 | numChildren(): number;
|
5563 | /**
|
5564 | * Extracts a JavaScript value from a `DataSnapshot`.
|
5565 | *
|
5566 | * Depending on the data in a `DataSnapshot`, the `val()` method may return a
|
5567 | * scalar type (string, number, or boolean), an array, or an object. It may also
|
5568 | * return null, indicating that the `DataSnapshot` is empty (contains no data).
|
5569 | *
|
5570 | * @example
|
5571 | * ```javascript
|
5572 | * // Write and then read back a string from the Database.
|
5573 | * ref.set("hello")
|
5574 | * .then(function() {
|
5575 | * return ref.once("value");
|
5576 | * })
|
5577 | * .then(function(snapshot) {
|
5578 | * var data = snapshot.val(); // data === "hello"
|
5579 | * });
|
5580 | * ```
|
5581 | *
|
5582 | * @example
|
5583 | * ```javascript
|
5584 | * // Write and then read back a JavaScript object from the Database.
|
5585 | * ref.set({ name: "Ada", age: 36 })
|
5586 | * .then(function() {
|
5587 | * return ref.once("value");
|
5588 | * })
|
5589 | * .then(function(snapshot) {
|
5590 | * var data = snapshot.val();
|
5591 | * // data is { "name": "Ada", "age": 36 }
|
5592 | * // data.name === "Ada"
|
5593 | * // data.age === 36
|
5594 | * });
|
5595 | * ```
|
5596 | *
|
5597 | * @return The DataSnapshot's contents as a JavaScript value (Object,
|
5598 | * Array, string, number, boolean, or `null`).
|
5599 | */
|
5600 | val(): any;
|
5601 | /**
|
5602 | * The `Reference` for the location that generated this `DataSnapshot`.
|
5603 | */
|
5604 | ref: firebase.database.Reference;
|
5605 | /**
|
5606 | * Returns a JSON-serializable representation of this object.
|
5607 | */
|
5608 | toJSON(): Object | null;
|
5609 | }
|
5610 |
|
5611 | /**
|
5612 | * The Firebase Database service interface.
|
5613 | *
|
5614 | * Do not call this constructor directly. Instead, use
|
5615 | * {@link firebase.database `firebase.database()`}.
|
5616 | *
|
5617 | * See
|
5618 | * {@link
|
5619 | * https://firebase.google.com/docs/database/web/start/
|
5620 | * Installation & Setup in JavaScript}
|
5621 | * for a full guide on how to use the Firebase Database service.
|
5622 | */
|
5623 | interface Database {
|
5624 | /**
|
5625 | * The {@link firebase.app.App app} associated with the `Database` service
|
5626 | * instance.
|
5627 | *
|
5628 | * @example
|
5629 | * ```javascript
|
5630 | * var app = database.app;
|
5631 | * ```
|
5632 | */
|
5633 | app: firebase.app.App;
|
5634 | /**
|
5635 | * Disconnects from the server (all Database operations will be completed
|
5636 | * offline).
|
5637 | *
|
5638 | * The client automatically maintains a persistent connection to the Database
|
5639 | * server, which will remain active indefinitely and reconnect when
|
5640 | * disconnected. However, the `goOffline()` and `goOnline()` methods may be used
|
5641 | * to control the client connection in cases where a persistent connection is
|
5642 | * undesirable.
|
5643 | *
|
5644 | * While offline, the client will no longer receive data updates from the
|
5645 | * Database. However, all Database operations performed locally will continue to
|
5646 | * immediately fire events, allowing your application to continue behaving
|
5647 | * normally. Additionally, each operation performed locally will automatically
|
5648 | * be queued and retried upon reconnection to the Database server.
|
5649 | *
|
5650 | * To reconnect to the Database and begin receiving remote events, see
|
5651 | * `goOnline()`.
|
5652 | *
|
5653 | * @example
|
5654 | * ```javascript
|
5655 | * firebase.database().goOffline();
|
5656 | * ```
|
5657 | */
|
5658 | goOffline(): any;
|
5659 | /**
|
5660 | * Reconnects to the server and synchronizes the offline Database state
|
5661 | * with the server state.
|
5662 | *
|
5663 | * This method should be used after disabling the active connection with
|
5664 | * `goOffline()`. Once reconnected, the client will transmit the proper data
|
5665 | * and fire the appropriate events so that your client "catches up"
|
5666 | * automatically.
|
5667 | *
|
5668 | * @example
|
5669 | * ```javascript
|
5670 | * firebase.database().goOnline();
|
5671 | * ```
|
5672 | */
|
5673 | goOnline(): any;
|
5674 | /**
|
5675 | * Returns a `Reference` representing the location in the Database
|
5676 | * corresponding to the provided path. If no path is provided, the `Reference`
|
5677 | * will point to the root of the Database.
|
5678 | *
|
5679 | * @example
|
5680 | * ```javascript
|
5681 | * // Get a reference to the root of the Database
|
5682 | * var rootRef = firebase.database().ref();
|
5683 | * ```
|
5684 | *
|
5685 | * @example
|
5686 | * ```javascript
|
5687 | * // Get a reference to the /users/ada node
|
5688 | * var adaRef = firebase.database().ref("users/ada");
|
5689 | * // The above is shorthand for the following operations:
|
5690 | * //var rootRef = firebase.database().ref();
|
5691 | * //var adaRef = rootRef.child("users/ada");
|
5692 | * ```
|
5693 | *
|
5694 | * @param path Optional path representing the location the returned
|
5695 | * `Reference` will point. If not provided, the returned `Reference` will
|
5696 | * point to the root of the Database.
|
5697 | * @return If a path is provided, a `Reference`
|
5698 | * pointing to the provided path. Otherwise, a `Reference` pointing to the
|
5699 | * root of the Database.
|
5700 | */
|
5701 | ref(path?: string): firebase.database.Reference;
|
5702 | /**
|
5703 | * Returns a `Reference` representing the location in the Database
|
5704 | * corresponding to the provided Firebase URL.
|
5705 | *
|
5706 | * An exception is thrown if the URL is not a valid Firebase Database URL or it
|
5707 | * has a different domain than the current `Database` instance.
|
5708 | *
|
5709 | * Note that all query parameters (`orderBy`, `limitToLast`, etc.) are ignored
|
5710 | * and are not applied to the returned `Reference`.
|
5711 | *
|
5712 | * @example
|
5713 | * ```javascript
|
5714 | * // Get a reference to the root of the Database
|
5715 | * var rootRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com");
|
5716 | * ```
|
5717 | *
|
5718 | * @example
|
5719 | * ```javascript
|
5720 | * // Get a reference to the /users/ada node
|
5721 | * var adaRef = firebase.database().ref("https://<DATABASE_NAME>.firebaseio.com/users/ada");
|
5722 | * ```
|
5723 | *
|
5724 | * @param url The Firebase URL at which the returned `Reference` will
|
5725 | * point.
|
5726 | * @return A `Reference` pointing to the provided
|
5727 | * Firebase URL.
|
5728 | */
|
5729 | refFromURL(url: string): firebase.database.Reference;
|
5730 | }
|
5731 |
|
5732 | /**
|
5733 | * The `onDisconnect` class allows you to write or clear data when your client
|
5734 | * disconnects from the Database server. These updates occur whether your
|
5735 | * client disconnects cleanly or not, so you can rely on them to clean up data
|
5736 | * even if a connection is dropped or a client crashes.
|
5737 | *
|
5738 | * The `onDisconnect` class is most commonly used to manage presence in
|
5739 | * applications where it is useful to detect how many clients are connected and
|
5740 | * when other clients disconnect. See
|
5741 | * {@link
|
5742 | * https://firebase.google.com/docs/database/web/offline-capabilities
|
5743 | * Enabling Offline Capabilities in JavaScript} for more information.
|
5744 | *
|
5745 | * To avoid problems when a connection is dropped before the requests can be
|
5746 | * transferred to the Database server, these functions should be called before
|
5747 | * writing any data.
|
5748 | *
|
5749 | * Note that `onDisconnect` operations are only triggered once. If you want an
|
5750 | * operation to occur each time a disconnect occurs, you'll need to re-establish
|
5751 | * the `onDisconnect` operations each time you reconnect.
|
5752 | */
|
5753 | interface OnDisconnect {
|
5754 | /**
|
5755 | * Cancels all previously queued `onDisconnect()` set or update events for this
|
5756 | * location and all children.
|
5757 | *
|
5758 | * If a write has been queued for this location via a `set()` or `update()` at a
|
5759 | * parent location, the write at this location will be canceled, though writes
|
5760 | * to sibling locations will still occur.
|
5761 | *
|
5762 | * @example
|
5763 | * ```javascript
|
5764 | * var ref = firebase.database().ref("onlineState");
|
5765 | * ref.onDisconnect().set(false);
|
5766 | * // ... sometime later
|
5767 | * ref.onDisconnect().cancel();
|
5768 | * ```
|
5769 | *
|
5770 | * @param onComplete An optional callback function that will
|
5771 | * be called when synchronization to the server has completed. The callback
|
5772 | * will be passed a single parameter: null for success, or an Error object
|
5773 | * indicating a failure.
|
5774 | * @return Resolves when synchronization to the server
|
5775 | * is complete.
|
5776 | */
|
5777 | cancel(onComplete?: (a: Error | null) => any): Promise<any>;
|
5778 | /**
|
5779 | * Ensures the data at this location is deleted when the client is disconnected
|
5780 | * (due to closing the browser, navigating to a new page, or network issues).
|
5781 | *
|
5782 | * @param onComplete An optional callback function that will
|
5783 | * be called when synchronization to the server has completed. The callback
|
5784 | * will be passed a single parameter: null for success, or an Error object
|
5785 | * indicating a failure.
|
5786 | * @return Resolves when synchronization to the server
|
5787 | * is complete.
|
5788 | */
|
5789 | remove(onComplete?: (a: Error | null) => any): Promise<any>;
|
5790 | /**
|
5791 | * Ensures the data at this location is set to the specified value when the
|
5792 | * client is disconnected (due to closing the browser, navigating to a new page,
|
5793 | * or network issues).
|
5794 | *
|
5795 | * `set()` is especially useful for implementing "presence" systems, where a
|
5796 | * value should be changed or cleared when a user disconnects so that they
|
5797 | * appear "offline" to other users. See
|
5798 | * {@link
|
5799 | * https://firebase.google.com/docs/database/web/offline-capabilities
|
5800 | * Enabling Offline Capabilities in JavaScript} for more information.
|
5801 | *
|
5802 | * Note that `onDisconnect` operations are only triggered once. If you want an
|
5803 | * operation to occur each time a disconnect occurs, you'll need to re-establish
|
5804 | * the `onDisconnect` operations each time.
|
5805 | *
|
5806 | * @example
|
5807 | * ```javascript
|
5808 | * var ref = firebase.database().ref("users/ada/status");
|
5809 | * ref.onDisconnect().set("I disconnected!");
|
5810 | * ```
|
5811 | *
|
5812 | * @param value The value to be written to this location on
|
5813 | * disconnect (can be an object, array, string, number, boolean, or null).
|
5814 | * @param onComplete An optional callback function that
|
5815 | * will be called when synchronization to the Database server has completed.
|
5816 | * The callback will be passed a single parameter: null for success, or an
|
5817 | * `Error` object indicating a failure.
|
5818 | * @return Resolves when synchronization to the
|
5819 | * Database is complete.
|
5820 | */
|
5821 | set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
|
5822 | /**
|
5823 | * Ensures the data at this location is set to the specified value and priority
|
5824 | * when the client is disconnected (due to closing the browser, navigating to a
|
5825 | * new page, or network issues).
|
5826 | */
|
5827 | setWithPriority(
|
5828 | value: any,
|
5829 | priority: number | string | null,
|
5830 | onComplete?: (a: Error | null) => any
|
5831 | ): Promise<any>;
|
5832 | /**
|
5833 | * Writes multiple values at this location when the client is disconnected (due
|
5834 | * to closing the browser, navigating to a new page, or network issues).
|
5835 | *
|
5836 | * The `values` argument contains multiple property-value pairs that will be
|
5837 | * written to the Database together. Each child property can either be a simple
|
5838 | * property (for example, "name") or a relative path (for example, "name/first")
|
5839 | * from the current location to the data to update.
|
5840 | *
|
5841 | * As opposed to the `set()` method, `update()` can be use to selectively update
|
5842 | * only the referenced properties at the current location (instead of replacing
|
5843 | * all the child properties at the current location).
|
5844 | *
|
5845 | * See more examples using the connected version of
|
5846 | * {@link firebase.database.Reference.update `update()`}.
|
5847 | *
|
5848 | * @example
|
5849 | * ```javascript
|
5850 | * var ref = firebase.database().ref("users/ada");
|
5851 | * ref.update({
|
5852 | * onlineState: true,
|
5853 | * status: "I'm online."
|
5854 | * });
|
5855 | * ref.onDisconnect().update({
|
5856 | * onlineState: false,
|
5857 | * status: "I'm offline."
|
5858 | * });
|
5859 | * ```
|
5860 | *
|
5861 | * @param values Object containing multiple values.
|
5862 | * @param onComplete An optional callback function that will
|
5863 | * be called when synchronization to the server has completed. The
|
5864 | * callback will be passed a single parameter: null for success, or an Error
|
5865 | * object indicating a failure.
|
5866 | * @return Resolves when synchronization to the
|
5867 | * Database is complete.
|
5868 | */
|
5869 | update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
|
5870 | }
|
5871 |
|
5872 | type EventType =
|
5873 | | 'value'
|
5874 | | 'child_added'
|
5875 | | 'child_changed'
|
5876 | | 'child_moved'
|
5877 | | 'child_removed';
|
5878 |
|
5879 | /**
|
5880 | * A `Query` sorts and filters the data at a Database location so only a subset
|
5881 | * of the child data is included. This can be used to order a collection of
|
5882 | * data by some attribute (for example, height of dinosaurs) as well as to
|
5883 | * restrict a large list of items (for example, chat messages) down to a number
|
5884 | * suitable for synchronizing to the client. Queries are created by chaining
|
5885 | * together one or more of the filter methods defined here.
|
5886 | *
|
5887 | * Just as with a `Reference`, you can receive data from a `Query` by using the
|
5888 | * `on()` method. You will only receive events and `DataSnapshot`s for the
|
5889 | * subset of the data that matches your query.
|
5890 | *
|
5891 | * Read our documentation on
|
5892 | * {@link
|
5893 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
5894 | * Sorting and filtering data} for more information.
|
5895 | */
|
5896 | interface Query {
|
5897 | /**
|
5898 | * Creates a `Query` with the specified ending point.
|
5899 | *
|
5900 | * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
|
5901 | * starting and ending points for your queries.
|
5902 | *
|
5903 | * The ending point is inclusive, so children with exactly the specified value
|
5904 | * will be included in the query. The optional key argument can be used to
|
5905 | * further limit the range of the query. If it is specified, then children that
|
5906 | * have exactly the specified value must also have a key name less than or equal
|
5907 | * to the specified key.
|
5908 | *
|
5909 | * You can read more about `endAt()` in
|
5910 | * {@link
|
5911 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
5912 | * Filtering data}.
|
5913 | *
|
5914 | * @example
|
5915 | * ```javascript
|
5916 | * // Find all dinosaurs whose names come before Pterodactyl lexicographically.
|
5917 | * var ref = firebase.database().ref("dinosaurs");
|
5918 | * ref.orderByKey().endAt("pterodactyl").on("child_added", function(snapshot) {
|
5919 | * console.log(snapshot.key);
|
5920 | * });
|
5921 | * ```
|
5922 | *
|
5923 | * @param value The value to end at. The argument
|
5924 | * type depends on which `orderBy*()` function was used in this query.
|
5925 | * Specify a value that matches the `orderBy*()` type. When used in
|
5926 | * combination with `orderByKey()`, the value must be a string.
|
5927 | * @param key The child key to end at, among the children with the
|
5928 | * previously specified priority. This argument is only allowed if ordering by
|
5929 | * child, value, or priority.
|
5930 | */
|
5931 | endAt(
|
5932 | value: number | string | boolean | null,
|
5933 | key?: string
|
5934 | ): firebase.database.Query;
|
5935 | /**
|
5936 | * Creates a `Query` that includes children that match the specified value.
|
5937 | *
|
5938 | * Using `startAt()`, `endAt()`, and `equalTo()` allows us to choose arbitrary
|
5939 | * starting and ending points for our queries.
|
5940 | *
|
5941 | * The optional key argument can be used to further limit the range of the
|
5942 | * query. If it is specified, then children that have exactly the specified
|
5943 | * value must also have exactly the specified key as their key name. This can be
|
5944 | * used to filter result sets with many matches for the same value.
|
5945 | *
|
5946 | * You can read more about `equalTo()` in
|
5947 | * {@link
|
5948 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
5949 | * Filtering data}.
|
5950 | *
|
5951 | * @example
|
5952 | * ```javascript
|
5953 | * // Find all dinosaurs whose height is exactly 25 meters.
|
5954 | * var ref = firebase.database().ref("dinosaurs");
|
5955 | * ref.orderByChild("height").equalTo(25).on("child_added", function(snapshot) {
|
5956 | * console.log(snapshot.key);
|
5957 | * });
|
5958 | * ```
|
5959 | *
|
5960 | * @param value The value to match for. The
|
5961 | * argument type depends on which `orderBy*()` function was used in this
|
5962 | * query. Specify a value that matches the `orderBy*()` type. When used in
|
5963 | * combination with `orderByKey()`, the value must be a string.
|
5964 | * @param key The child key to start at, among the children with the
|
5965 | * previously specified priority. This argument is only allowed if ordering by
|
5966 | * child, value, or priority.
|
5967 | */
|
5968 | equalTo(
|
5969 | value: number | string | boolean | null,
|
5970 | key?: string
|
5971 | ): firebase.database.Query;
|
5972 | /**
|
5973 | * Returns whether or not the current and provided queries represent the same
|
5974 | * location, have the same query parameters, and are from the same instance of
|
5975 | * `firebase.app.App`.
|
5976 | *
|
5977 | * Two `Reference` objects are equivalent if they represent the same location
|
5978 | * and are from the same instance of `firebase.app.App`.
|
5979 | *
|
5980 | * Two `Query` objects are equivalent if they represent the same location, have
|
5981 | * the same query parameters, and are from the same instance of
|
5982 | * `firebase.app.App`. Equivalent queries share the same sort order, limits, and
|
5983 | * starting and ending points.
|
5984 | *
|
5985 | * @example
|
5986 | * ```javascript
|
5987 | * var rootRef = firebase.database.ref();
|
5988 | * var usersRef = rootRef.child("users");
|
5989 | *
|
5990 | * usersRef.isEqual(rootRef); // false
|
5991 | * usersRef.isEqual(rootRef.child("users")); // true
|
5992 | * usersRef.parent.isEqual(rootRef); // true
|
5993 | * ```
|
5994 | *
|
5995 | * @example
|
5996 | * ```javascript
|
5997 | * var rootRef = firebase.database.ref();
|
5998 | * var usersRef = rootRef.child("users");
|
5999 | * var usersQuery = usersRef.limitToLast(10);
|
6000 | *
|
6001 | * usersQuery.isEqual(usersRef); // false
|
6002 | * usersQuery.isEqual(usersRef.limitToLast(10)); // true
|
6003 | * usersQuery.isEqual(rootRef.limitToLast(10)); // false
|
6004 | * usersQuery.isEqual(usersRef.orderByKey().limitToLast(10)); // false
|
6005 | * ```
|
6006 | *
|
6007 | * @param other The query to compare against.
|
6008 | * @return Whether or not the current and provided queries are
|
6009 | * equivalent.
|
6010 | */
|
6011 | isEqual(other: firebase.database.Query | null): boolean;
|
6012 | /**
|
6013 | * Generates a new `Query` limited to the first specific number of children.
|
6014 | *
|
6015 | * The `limitToFirst()` method is used to set a maximum number of children to be
|
6016 | * synced for a given callback. If we set a limit of 100, we will initially only
|
6017 | * receive up to 100 `child_added` events. If we have fewer than 100 messages
|
6018 | * stored in our Database, a `child_added` event will fire for each message.
|
6019 | * However, if we have over 100 messages, we will only receive a `child_added`
|
6020 | * event for the first 100 ordered messages. As items change, we will receive
|
6021 | * `child_removed` events for each item that drops out of the active list so
|
6022 | * that the total number stays at 100.
|
6023 | *
|
6024 | * You can read more about `limitToFirst()` in
|
6025 | * {@link
|
6026 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6027 | * Filtering data}.
|
6028 | *
|
6029 | * @example
|
6030 | * ```javascript
|
6031 | * // Find the two shortest dinosaurs.
|
6032 | * var ref = firebase.database().ref("dinosaurs");
|
6033 | * ref.orderByChild("height").limitToFirst(2).on("child_added", function(snapshot) {
|
6034 | * // This will be called exactly two times (unless there are less than two
|
6035 | * // dinosaurs in the Database).
|
6036 | *
|
6037 | * // It will also get fired again if one of the first two dinosaurs is
|
6038 | * // removed from the data set, as a new dinosaur will now be the second
|
6039 | * // shortest.
|
6040 | * console.log(snapshot.key);
|
6041 | * });
|
6042 | * ```
|
6043 | *
|
6044 | * @param limit The maximum number of nodes to include in this query.
|
6045 | */
|
6046 | limitToFirst(limit: number): firebase.database.Query;
|
6047 | /**
|
6048 | * Generates a new `Query` object limited to the last specific number of
|
6049 | * children.
|
6050 | *
|
6051 | * The `limitToLast()` method is used to set a maximum number of children to be
|
6052 | * synced for a given callback. If we set a limit of 100, we will initially only
|
6053 | * receive up to 100 `child_added` events. If we have fewer than 100 messages
|
6054 | * stored in our Database, a `child_added` event will fire for each message.
|
6055 | * However, if we have over 100 messages, we will only receive a `child_added`
|
6056 | * event for the last 100 ordered messages. As items change, we will receive
|
6057 | * `child_removed` events for each item that drops out of the active list so
|
6058 | * that the total number stays at 100.
|
6059 | *
|
6060 | * You can read more about `limitToLast()` in
|
6061 | * {@link
|
6062 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6063 | * Filtering data}.
|
6064 | *
|
6065 | * @example
|
6066 | * ```javascript
|
6067 | * // Find the two heaviest dinosaurs.
|
6068 | * var ref = firebase.database().ref("dinosaurs");
|
6069 | * ref.orderByChild("weight").limitToLast(2).on("child_added", function(snapshot) {
|
6070 | * // This callback will be triggered exactly two times, unless there are
|
6071 | * // fewer than two dinosaurs stored in the Database. It will also get fired
|
6072 | * // for every new, heavier dinosaur that gets added to the data set.
|
6073 | * console.log(snapshot.key);
|
6074 | * });
|
6075 | * ```
|
6076 | *
|
6077 | * @param limit The maximum number of nodes to include in this query.
|
6078 | */
|
6079 | limitToLast(limit: number): firebase.database.Query;
|
6080 | /**
|
6081 | * Detaches a callback previously attached with `on()`.
|
6082 | *
|
6083 | * Detach a callback previously attached with `on()`. Note that if `on()` was
|
6084 | * called multiple times with the same eventType and callback, the callback
|
6085 | * will be called multiple times for each event, and `off()` must be called
|
6086 | * multiple times to remove the callback. Calling `off()` on a parent listener
|
6087 | * will not automatically remove listeners registered on child nodes, `off()`
|
6088 | * must also be called on any child listeners to remove the callback.
|
6089 | *
|
6090 | * If a callback is not specified, all callbacks for the specified eventType
|
6091 | * will be removed. Similarly, if no eventType is specified, all callbacks
|
6092 | * for the `Reference` will be removed.
|
6093 | *
|
6094 | * @example
|
6095 | * ```javascript
|
6096 | * var onValueChange = function(dataSnapshot) { ... };
|
6097 | * ref.on('value', onValueChange);
|
6098 | * ref.child('meta-data').on('child_added', onChildAdded);
|
6099 | * // Sometime later...
|
6100 | * ref.off('value', onValueChange);
|
6101 | *
|
6102 | * // You must also call off() for any child listeners on ref
|
6103 | * // to cancel those callbacks
|
6104 | * ref.child('meta-data').off('child_added', onValueAdded);
|
6105 | * ```
|
6106 | *
|
6107 | * @example
|
6108 | * ```javascript
|
6109 | * // Or you can save a line of code by using an inline function
|
6110 | * // and on()'s return value.
|
6111 | * var onValueChange = ref.on('value', function(dataSnapshot) { ... });
|
6112 | * // Sometime later...
|
6113 | * ref.off('value', onValueChange);
|
6114 | * ```
|
6115 | *
|
6116 | * @param eventType One of the following strings: "value",
|
6117 | * "child_added", "child_changed", "child_removed", or "child_moved." If
|
6118 | * omitted, all callbacks for the `Reference` will be removed.
|
6119 | * @param callback The callback function that was passed to `on()` or
|
6120 | * `undefined` to remove all callbacks.
|
6121 | * @param context The context that was passed to `on()`.
|
6122 | */
|
6123 | off(
|
6124 | eventType?: EventType,
|
6125 | callback?: (a: firebase.database.DataSnapshot, b?: string | null) => any,
|
6126 | context?: Object | null
|
6127 | ): void;
|
6128 |
|
6129 | /**
|
6130 | * Listens for data changes at a particular location.
|
6131 | *
|
6132 | * This is the primary way to read data from a Database. Your callback
|
6133 | * will be triggered for the initial data and again whenever the data changes.
|
6134 | * Use `off( )` to stop receiving updates. See
|
6135 | * {@link https://firebase.google.com/docs/database/web/retrieve-data
|
6136 | * Retrieve Data on the Web}
|
6137 | * for more details.
|
6138 | *
|
6139 | * <h4>value event</h4>
|
6140 | *
|
6141 | * This event will trigger once with the initial data stored at this location,
|
6142 | * and then trigger again each time the data changes. The `DataSnapshot` passed
|
6143 | * to the callback will be for the location at which `on()` was called. It
|
6144 | * won't trigger until the entire contents has been synchronized. If the
|
6145 | * location has no data, it will be triggered with an empty `DataSnapshot`
|
6146 | * (`val()` will return `null`).
|
6147 | *
|
6148 | * <h4>child_added event</h4>
|
6149 | *
|
6150 | * This event will be triggered once for each initial child at this location,
|
6151 | * and it will be triggered again every time a new child is added. The
|
6152 | * `DataSnapshot` passed into the callback will reflect the data for the
|
6153 | * relevant child. For ordering purposes, it is passed a second argument which
|
6154 | * is a string containing the key of the previous sibling child by sort order,
|
6155 | * or `null` if it is the first child.
|
6156 | *
|
6157 | * <h4>child_removed event</h4>
|
6158 | *
|
6159 | * This event will be triggered once every time a child is removed. The
|
6160 | * `DataSnapshot` passed into the callback will be the old data for the child
|
6161 | * that was removed. A child will get removed when either:
|
6162 | *
|
6163 | * - a client explicitly calls `remove()` on that child or one of its ancestors
|
6164 | * - a client calls `set(null)` on that child or one of its ancestors
|
6165 | * - that child has all of its children removed
|
6166 | * - there is a query in effect which now filters out the child (because it's
|
6167 | * sort order changed or the max limit was hit)
|
6168 | *
|
6169 | * <h4>child_changed event</h4>
|
6170 | *
|
6171 | * This event will be triggered when the data stored in a child (or any of its
|
6172 | * descendants) changes. Note that a single `child_changed` event may represent
|
6173 | * multiple changes to the child. The `DataSnapshot` passed to the callback will
|
6174 | * contain the new child contents. For ordering purposes, the callback is also
|
6175 | * passed a second argument which is a string containing the key of the previous
|
6176 | * sibling child by sort order, or `null` if it is the first child.
|
6177 | *
|
6178 | * <h4>child_moved event</h4>
|
6179 | *
|
6180 | * This event will be triggered when a child's sort order changes such that its
|
6181 | * position relative to its siblings changes. The `DataSnapshot` passed to the
|
6182 | * callback will be for the data of the child that has moved. It is also passed
|
6183 | * a second argument which is a string containing the key of the previous
|
6184 | * sibling child by sort order, or `null` if it is the first child.
|
6185 | *
|
6186 | * @example **Handle a new value:**
|
6187 | * ```javascript
|
6188 | * ref.on('value', function(dataSnapshot) {
|
6189 | * ...
|
6190 | * });
|
6191 | * ```
|
6192 | *
|
6193 | * @example **Handle a new child:**
|
6194 | * ```javascript
|
6195 | * ref.on('child_added', function(childSnapshot, prevChildKey) {
|
6196 | * ...
|
6197 | * });
|
6198 | * ```
|
6199 | *
|
6200 | * @example **Handle child removal:**
|
6201 | * ```javascript
|
6202 | * ref.on('child_removed', function(oldChildSnapshot) {
|
6203 | * ...
|
6204 | * });
|
6205 | * ```
|
6206 | *
|
6207 | * @example **Handle child data changes:**
|
6208 | * ```javascript
|
6209 | * ref.on('child_changed', function(childSnapshot, prevChildKey) {
|
6210 | * ...
|
6211 | * });
|
6212 | * ```
|
6213 | *
|
6214 | * @example **Handle child ordering changes:**
|
6215 | * ```javascript
|
6216 | * ref.on('child_moved', function(childSnapshot, prevChildKey) {
|
6217 | * ...
|
6218 | * });
|
6219 | * ```
|
6220 | *
|
6221 | * @param eventType One of the following strings: "value",
|
6222 | * "child_added", "child_changed", "child_removed", or "child_moved."
|
6223 | * @param callback A
|
6224 | * callback that fires when the specified event occurs. The callback will be
|
6225 | * passed a DataSnapshot. For ordering purposes, "child_added",
|
6226 | * "child_changed", and "child_moved" will also be passed a string containing
|
6227 | * the key of the previous child, by sort order, or `null` if it is the
|
6228 | * first child.
|
6229 | * @param cancelCallbackOrContext An optional
|
6230 | * callback that will be notified if your event subscription is ever canceled
|
6231 | * because your client does not have permission to read this data (or it had
|
6232 | * permission but has now lost it). This callback will be passed an `Error`
|
6233 | * object indicating why the failure occurred.
|
6234 | * @param context If provided, this object will be used as `this`
|
6235 | * when calling your callback(s).
|
6236 | * @return The provided
|
6237 | * callback function is returned unmodified. This is just for convenience if
|
6238 | * you want to pass an inline function to `on()` but store the callback
|
6239 | * function for later passing to `off()`.
|
6240 | */
|
6241 | on(
|
6242 | eventType: EventType,
|
6243 | callback: (a: firebase.database.DataSnapshot, b?: string | null) => any,
|
6244 | cancelCallbackOrContext?: Object | null,
|
6245 | context?: Object | null
|
6246 | ): (a: firebase.database.DataSnapshot | null, b?: string | null) => any;
|
6247 |
|
6248 | /**
|
6249 | * Listens for exactly one event of the specified event type, and then stops
|
6250 | * listening.
|
6251 | *
|
6252 | * This is equivalent to calling {@link firebase.database.Query.on `on()`}, and
|
6253 | * then calling {@link firebase.database.Query.off `off()`} inside the callback
|
6254 | * function. See {@link firebase.database.Query.on `on()`} for details on the
|
6255 | * event types.
|
6256 | *
|
6257 | * @example
|
6258 | * ```javascript
|
6259 | * // Basic usage of .once() to read the data located at ref.
|
6260 | * ref.once('value')
|
6261 | * .then(function(dataSnapshot) {
|
6262 | * // handle read data.
|
6263 | * });
|
6264 | * ```
|
6265 | *
|
6266 | * @param eventType One of the following strings: "value",
|
6267 | * "child_added", "child_changed", "child_removed", or "child_moved."
|
6268 | * @param successCallback A
|
6269 | * callback that fires when the specified event occurs. The callback will be
|
6270 | * passed a DataSnapshot. For ordering purposes, "child_added",
|
6271 | * "child_changed", and "child_moved" will also be passed a string containing
|
6272 | * the key of the previous child by sort order, or `null` if it is the
|
6273 | * first child.
|
6274 | * @param failureCallbackOrContext An optional
|
6275 | * callback that will be notified if your client does not have permission to
|
6276 | * read the data. This callback will be passed an `Error` object indicating
|
6277 | * why the failure occurred.
|
6278 | * @param context If provided, this object will be used as `this`
|
6279 | * when calling your callback(s).
|
6280 | */
|
6281 | once(
|
6282 | eventType: EventType,
|
6283 | successCallback?: (
|
6284 | a: firebase.database.DataSnapshot,
|
6285 | b?: string | null
|
6286 | ) => any,
|
6287 | failureCallbackOrContext?: ((a: Error) => void) | Object | null,
|
6288 | context?: Object | null
|
6289 | ): Promise<firebase.database.DataSnapshot>;
|
6290 | /**
|
6291 | * Generates a new `Query` object ordered by the specified child key.
|
6292 | *
|
6293 | * Queries can only order by one key at a time. Calling `orderByChild()`
|
6294 | * multiple times on the same query is an error.
|
6295 | *
|
6296 | * Firebase queries allow you to order your data by any child key on the fly.
|
6297 | * However, if you know in advance what your indexes will be, you can define
|
6298 | * them via the .indexOn rule in your Security Rules for better performance. See
|
6299 | * the {@link https://firebase.google.com/docs/database/security/indexing-data
|
6300 | * .indexOn} rule for more information.
|
6301 | *
|
6302 | * You can read more about `orderByChild()` in
|
6303 | * {@link
|
6304 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6305 | * Sort data}.
|
6306 | *
|
6307 | * @example
|
6308 | * ```javascript
|
6309 | * var ref = firebase.database().ref("dinosaurs");
|
6310 | * ref.orderByChild("height").on("child_added", function(snapshot) {
|
6311 | * console.log(snapshot.key + " was " + snapshot.val().height + " m tall");
|
6312 | * });
|
6313 | * ```
|
6314 | */
|
6315 | orderByChild(path: string): firebase.database.Query;
|
6316 | /**
|
6317 | * Generates a new `Query` object ordered by key.
|
6318 | *
|
6319 | * Sorts the results of a query by their (ascending) key values.
|
6320 | *
|
6321 | * You can read more about `orderByKey()` in
|
6322 | * {@link
|
6323 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6324 | * Sort data}.
|
6325 | *
|
6326 | * @example
|
6327 | * ```javascript
|
6328 | * var ref = firebase.database().ref("dinosaurs");
|
6329 | * ref.orderByKey().on("child_added", function(snapshot) {
|
6330 | * console.log(snapshot.key);
|
6331 | * });
|
6332 | * ```
|
6333 | */
|
6334 | orderByKey(): firebase.database.Query;
|
6335 | /**
|
6336 | * Generates a new `Query` object ordered by priority.
|
6337 | *
|
6338 | * Applications need not use priority but can order collections by
|
6339 | * ordinary properties (see
|
6340 | * {@link
|
6341 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6342 | * Sort data} for alternatives to priority.
|
6343 | */
|
6344 | orderByPriority(): firebase.database.Query;
|
6345 | /**
|
6346 | * Generates a new `Query` object ordered by value.
|
6347 | *
|
6348 | * If the children of a query are all scalar values (string, number, or
|
6349 | * boolean), you can order the results by their (ascending) values.
|
6350 | *
|
6351 | * You can read more about `orderByValue()` in
|
6352 | * {@link
|
6353 | * https://firebase.google.com/docs/database/web/lists-of-data#sort_data
|
6354 | * Sort data}.
|
6355 | *
|
6356 | * @example
|
6357 | * ```javascript
|
6358 | * var scoresRef = firebase.database().ref("scores");
|
6359 | * scoresRef.orderByValue().limitToLast(3).on("value", function(snapshot) {
|
6360 | * snapshot.forEach(function(data) {
|
6361 | * console.log("The " + data.key + " score is " + data.val());
|
6362 | * });
|
6363 | * });
|
6364 | * ```
|
6365 | */
|
6366 | orderByValue(): firebase.database.Query;
|
6367 | /**
|
6368 | * Returns a `Reference` to the `Query`'s location.
|
6369 | */
|
6370 | ref: firebase.database.Reference;
|
6371 | /**
|
6372 | * Creates a `Query` with the specified starting point.
|
6373 | *
|
6374 | * Using `startAt()`, `endAt()`, and `equalTo()` allows you to choose arbitrary
|
6375 | * starting and ending points for your queries.
|
6376 | *
|
6377 | * The starting point is inclusive, so children with exactly the specified value
|
6378 | * will be included in the query. The optional key argument can be used to
|
6379 | * further limit the range of the query. If it is specified, then children that
|
6380 | * have exactly the specified value must also have a key name greater than or
|
6381 | * equal to the specified key.
|
6382 | *
|
6383 | * You can read more about `startAt()` in
|
6384 | * {@link
|
6385 | * https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
|
6386 | * Filtering data}.
|
6387 | *
|
6388 | * @example
|
6389 | * ```javascript
|
6390 | * // Find all dinosaurs that are at least three meters tall.
|
6391 | * var ref = firebase.database().ref("dinosaurs");
|
6392 | * ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
|
6393 | * console.log(snapshot.key)
|
6394 | * });
|
6395 | * ```
|
6396 | *
|
6397 | * @param value The value to start at. The argument
|
6398 | * type depends on which `orderBy*()` function was used in this query.
|
6399 | * Specify a value that matches the `orderBy*()` type. When used in
|
6400 | * combination with `orderByKey()`, the value must be a string.
|
6401 | * @param key The child key to start at. This argument is only allowed
|
6402 | * if ordering by child, value, or priority.
|
6403 | */
|
6404 | startAt(
|
6405 | value: number | string | boolean | null,
|
6406 | key?: string
|
6407 | ): firebase.database.Query;
|
6408 | /**
|
6409 | * Returns a JSON-serializable representation of this object.
|
6410 | *
|
6411 | * @return A JSON-serializable representation of this object.
|
6412 | */
|
6413 | toJSON(): Object;
|
6414 | /**
|
6415 | * Gets the absolute URL for this location.
|
6416 | *
|
6417 | * The `toString()` method returns a URL that is ready to be put into a browser,
|
6418 | * curl command, or a `firebase.database().refFromURL()` call. Since all of
|
6419 | * those expect the URL to be url-encoded, `toString()` returns an encoded URL.
|
6420 | *
|
6421 | * Append '.json' to the returned URL when typed into a browser to download
|
6422 | * JSON-formatted data. If the location is secured (that is, not publicly
|
6423 | * readable), you will get a permission-denied error.
|
6424 | *
|
6425 | * @example
|
6426 | * ```javascript
|
6427 | * // Calling toString() on a root Firebase reference returns the URL where its
|
6428 | * // data is stored within the Database:
|
6429 | * var rootRef = firebase.database().ref();
|
6430 | * var rootUrl = rootRef.toString();
|
6431 | * // rootUrl === "https://sample-app.firebaseio.com/".
|
6432 | *
|
6433 | * // Calling toString() at a deeper Firebase reference returns the URL of that
|
6434 | * // deep path within the Database:
|
6435 | * var adaRef = rootRef.child('users/ada');
|
6436 | * var adaURL = adaRef.toString();
|
6437 | * // adaURL === "https://sample-app.firebaseio.com/users/ada".
|
6438 | * ```
|
6439 | *
|
6440 | * @return The absolute URL for this location.
|
6441 | */
|
6442 | toString(): string;
|
6443 | }
|
6444 |
|
6445 | /**
|
6446 | * A `Reference` represents a specific location in your Database and can be used
|
6447 | * for reading or writing data to that Database location.
|
6448 | *
|
6449 | * You can reference the root or child location in your Database by calling
|
6450 | * `firebase.database().ref()` or `firebase.database().ref("child/path")`.
|
6451 | *
|
6452 | * Writing is done with the `set()` method and reading can be done with the
|
6453 | * `on()` method. See
|
6454 | * {@link
|
6455 | * https://firebase.google.com/docs/database/web/read-and-write
|
6456 | * Read and Write Data on the Web}
|
6457 | */
|
6458 | interface Reference extends firebase.database.Query {
|
6459 | /**
|
6460 | * Gets a `Reference` for the location at the specified relative path.
|
6461 | *
|
6462 | * The relative path can either be a simple child name (for example, "ada") or
|
6463 | * a deeper slash-separated path (for example, "ada/name/first").
|
6464 | *
|
6465 | * @example
|
6466 | * ```javascript
|
6467 | * var usersRef = firebase.database().ref('users');
|
6468 | * var adaRef = usersRef.child('ada');
|
6469 | * var adaFirstNameRef = adaRef.child('name/first');
|
6470 | * var path = adaFirstNameRef.toString();
|
6471 | * // path is now 'https://sample-app.firebaseio.com/users/ada/name/first'
|
6472 | * ```
|
6473 | *
|
6474 | * @param path A relative path from this location to the desired child
|
6475 | * location.
|
6476 | * @return The specified child location.
|
6477 | */
|
6478 | child(path: string): firebase.database.Reference;
|
6479 | /**
|
6480 | * The last part of the `Reference`'s path.
|
6481 | *
|
6482 | * For example, `"ada"` is the key for
|
6483 | * `https://<DATABASE_NAME>.firebaseio.com/users/ada`.
|
6484 | *
|
6485 | * The key of a root `Reference` is `null`.
|
6486 | *
|
6487 | * @example
|
6488 | * ```javascript
|
6489 | * // The key of a root reference is null
|
6490 | * var rootRef = firebase.database().ref();
|
6491 | * var key = rootRef.key; // key === null
|
6492 | * ```
|
6493 | *
|
6494 | * @example
|
6495 | * ```javascript
|
6496 | * // The key of any non-root reference is the last token in the path
|
6497 | * var adaRef = firebase.database().ref("users/ada");
|
6498 | * var key = adaRef.key; // key === "ada"
|
6499 | * key = adaRef.child("name/last").key; // key === "last"
|
6500 | * ```
|
6501 | */
|
6502 | key: string | null;
|
6503 | /**
|
6504 | * Returns an `OnDisconnect` object - see
|
6505 | * {@link
|
6506 | * https://firebase.google.com/docs/database/web/offline-capabilities
|
6507 | * Enabling Offline Capabilities in JavaScript} for more information on how
|
6508 | * to use it.
|
6509 | */
|
6510 | onDisconnect(): firebase.database.OnDisconnect;
|
6511 | /**
|
6512 | * The parent location of a `Reference`.
|
6513 | *
|
6514 | * The parent of a root `Reference` is `null`.
|
6515 | *
|
6516 | * @example
|
6517 | * ```javascript
|
6518 | * // The parent of a root reference is null
|
6519 | * var rootRef = firebase.database().ref();
|
6520 | * parent = rootRef.parent; // parent === null
|
6521 | * ```
|
6522 | *
|
6523 | * @example
|
6524 | * ```javascript
|
6525 | * // The parent of any non-root reference is the parent location
|
6526 | * var usersRef = firebase.database().ref("users");
|
6527 | * var adaRef = firebase.database().ref("users/ada");
|
6528 | * // usersRef and adaRef.parent represent the same location
|
6529 | * ```
|
6530 | */
|
6531 | parent: firebase.database.Reference | null;
|
6532 | /**
|
6533 | * Generates a new child location using a unique key and returns its
|
6534 | * `Reference`.
|
6535 | *
|
6536 | * This is the most common pattern for adding data to a collection of items.
|
6537 | *
|
6538 | * If you provide a value to `push()`, the value is written to the
|
6539 | * generated location. If you don't pass a value, nothing is written to the
|
6540 | * database and the child remains empty (but you can use the `Reference`
|
6541 | * elsewhere).
|
6542 | *
|
6543 | * The unique keys generated by `push()` are ordered by the current time, so the
|
6544 | * resulting list of items is chronologically sorted. The keys are also
|
6545 | * designed to be unguessable (they contain 72 random bits of entropy).
|
6546 | *
|
6547 | *
|
6548 | * See
|
6549 | * {@link
|
6550 | * https://firebase.google.com/docs/database/web/lists-of-data#append_to_a_list_of_data
|
6551 | * Append to a list of data}
|
6552 | * </br>See
|
6553 | * {@link
|
6554 | * https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
|
6555 | * The 2^120 Ways to Ensure Unique Identifiers}
|
6556 | *
|
6557 | * @example
|
6558 | * ```javascript
|
6559 | * var messageListRef = firebase.database().ref('message_list');
|
6560 | * var newMessageRef = messageListRef.push();
|
6561 | * newMessageRef.set({
|
6562 | * 'user_id': 'ada',
|
6563 | * 'text': 'The Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.'
|
6564 | * });
|
6565 | * // We've appended a new message to the message_list location.
|
6566 | * var path = newMessageRef.toString();
|
6567 | * // path will be something like
|
6568 | * // 'https://sample-app.firebaseio.com/message_list/-IKo28nwJLH0Nc5XeFmj'
|
6569 | * ```
|
6570 | *
|
6571 | * @param value Optional value to be written at the generated location.
|
6572 | * @param onComplete Callback called when write to server is
|
6573 | * complete.
|
6574 | * @return Combined `Promise` and `Reference`; resolves when write is complete, but can be
|
6575 | * used immediately as the `Reference` to the child location.
|
6576 | */
|
6577 | push(
|
6578 | value?: any,
|
6579 | onComplete?: (a: Error | null) => any
|
6580 | ): firebase.database.ThenableReference;
|
6581 | /**
|
6582 | * Removes the data at this Database location.
|
6583 | *
|
6584 | * Any data at child locations will also be deleted.
|
6585 | *
|
6586 | * The effect of the remove will be visible immediately and the corresponding
|
6587 | * event 'value' will be triggered. Synchronization of the remove to the
|
6588 | * Firebase servers will also be started, and the returned Promise will resolve
|
6589 | * when complete. If provided, the onComplete callback will be called
|
6590 | * asynchronously after synchronization has finished.
|
6591 | *
|
6592 | * @example
|
6593 | * ```javascript
|
6594 | * var adaRef = firebase.database().ref('users/ada');
|
6595 | * adaRef.remove()
|
6596 | * .then(function() {
|
6597 | * console.log("Remove succeeded.")
|
6598 | * })
|
6599 | * .catch(function(error) {
|
6600 | * console.log("Remove failed: " + error.message)
|
6601 | * });
|
6602 | * ```
|
6603 | *
|
6604 | * @param onComplete Callback called when write to server is
|
6605 | * complete.
|
6606 | * @return Resolves when remove on server is complete.
|
6607 | */
|
6608 | remove(onComplete?: (a: Error | null) => any): Promise<any>;
|
6609 | /**
|
6610 | * The root `Reference` of the Database.
|
6611 | *
|
6612 | * @example
|
6613 | * ```javascript
|
6614 | * // The root of a root reference is itself
|
6615 | * var rootRef = firebase.database().ref();
|
6616 | * // rootRef and rootRef.root represent the same location
|
6617 | * ```
|
6618 | *
|
6619 | * @example
|
6620 | * ```javascript
|
6621 | * // The root of any non-root reference is the root location
|
6622 | * var adaRef = firebase.database().ref("users/ada");
|
6623 | * // rootRef and adaRef.root represent the same location
|
6624 | * ```
|
6625 | */
|
6626 | root: firebase.database.Reference;
|
6627 | /**
|
6628 | * Writes data to this Database location.
|
6629 | *
|
6630 | * This will overwrite any data at this location and all child locations.
|
6631 | *
|
6632 | * The effect of the write will be visible immediately, and the corresponding
|
6633 | * events ("value", "child_added", etc.) will be triggered. Synchronization of
|
6634 | * the data to the Firebase servers will also be started, and the returned
|
6635 | * Promise will resolve when complete. If provided, the `onComplete` callback
|
6636 | * will be called asynchronously after synchronization has finished.
|
6637 | *
|
6638 | * Passing `null` for the new value is equivalent to calling `remove()`; namely,
|
6639 | * all data at this location and all child locations will be deleted.
|
6640 | *
|
6641 | * `set()` will remove any priority stored at this location, so if priority is
|
6642 | * meant to be preserved, you need to use `setWithPriority()` instead.
|
6643 | *
|
6644 | * Note that modifying data with `set()` will cancel any pending transactions
|
6645 | * at that location, so extreme care should be taken if mixing `set()` and
|
6646 | * `transaction()` to modify the same data.
|
6647 | *
|
6648 | * A single `set()` will generate a single "value" event at the location where
|
6649 | * the `set()` was performed.
|
6650 | *
|
6651 | * @example
|
6652 | * ```javascript
|
6653 | * var adaNameRef = firebase.database().ref('users/ada/name');
|
6654 | * adaNameRef.child('first').set('Ada');
|
6655 | * adaNameRef.child('last').set('Lovelace');
|
6656 | * // We've written 'Ada' to the Database location storing Ada's first name,
|
6657 | * // and 'Lovelace' to the location storing her last name.
|
6658 | * ```
|
6659 | *
|
6660 | * @example
|
6661 | * ```javascript
|
6662 | * adaNameRef.set({ first: 'Ada', last: 'Lovelace' });
|
6663 | * // Exact same effect as the previous example, except we've written
|
6664 | * // Ada's first and last name simultaneously.
|
6665 | * ```
|
6666 | *
|
6667 | * @example
|
6668 | * ```javascript
|
6669 | * adaNameRef.set({ first: 'Ada', last: 'Lovelace' })
|
6670 | * .then(function() {
|
6671 | * console.log('Synchronization succeeded');
|
6672 | * })
|
6673 | * .catch(function(error) {
|
6674 | * console.log('Synchronization failed');
|
6675 | * });
|
6676 | * // Same as the previous example, except we will also log a message
|
6677 | * // when the data has finished synchronizing.
|
6678 | * ```
|
6679 | *
|
6680 | * @param value The value to be written (string, number, boolean, object,
|
6681 | * array, or null).
|
6682 | * @param onComplete Callback called when write to server is
|
6683 | * complete.
|
6684 | * @return Resolves when write to server is complete.
|
6685 | */
|
6686 | set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
|
6687 | /**
|
6688 | * Sets a priority for the data at this Database location.
|
6689 | *
|
6690 | * Applications need not use priority but can order collections by
|
6691 | * ordinary properties (see
|
6692 | * {@link
|
6693 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
6694 | * Sorting and filtering data}).
|
6695 | */
|
6696 | setPriority(
|
6697 | priority: string | number | null,
|
6698 | onComplete: (a: Error | null) => any
|
6699 | ): Promise<any>;
|
6700 | /**
|
6701 | * Writes data the Database location. Like `set()` but also specifies the
|
6702 | * priority for that data.
|
6703 | *
|
6704 | * Applications need not use priority but can order collections by
|
6705 | * ordinary properties (see
|
6706 | * {@link
|
6707 | * https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data
|
6708 | * Sorting and filtering data}).
|
6709 | */
|
6710 | setWithPriority(
|
6711 | newVal: any,
|
6712 | newPriority: string | number | null,
|
6713 | onComplete?: (a: Error | null) => any
|
6714 | ): Promise<any>;
|
6715 | /**
|
6716 | * Atomically modifies the data at this location.
|
6717 | *
|
6718 | * Atomically modify the data at this location. Unlike a normal `set()`, which
|
6719 | * just overwrites the data regardless of its previous value, `transaction()` is
|
6720 | * used to modify the existing value to a new value, ensuring there are no
|
6721 | * conflicts with other clients writing to the same location at the same time.
|
6722 | *
|
6723 | * To accomplish this, you pass `transaction()` an update function which is used
|
6724 | * to transform the current value into a new value. If another client writes to
|
6725 | * the location before your new value is successfully written, your update
|
6726 | * function will be called again with the new current value, and the write will
|
6727 | * be retried. This will happen repeatedly until your write succeeds without
|
6728 | * conflict or you abort the transaction by not returning a value from your
|
6729 | * update function.
|
6730 | *
|
6731 | * Note: Modifying data with `set()` will cancel any pending transactions at
|
6732 | * that location, so extreme care should be taken if mixing `set()` and
|
6733 | * `transaction()` to update the same data.
|
6734 | *
|
6735 | * Note: When using transactions with Security and Firebase Rules in place, be
|
6736 | * aware that a client needs `.read` access in addition to `.write` access in
|
6737 | * order to perform a transaction. This is because the client-side nature of
|
6738 | * transactions requires the client to read the data in order to transactionally
|
6739 | * update it.
|
6740 | *
|
6741 | * @example
|
6742 | * ```javascript
|
6743 | * // Increment Ada's rank by 1.
|
6744 | * var adaRankRef = firebase.database().ref('users/ada/rank');
|
6745 | * adaRankRef.transaction(function(currentRank) {
|
6746 | * // If users/ada/rank has never been set, currentRank will be `null`.
|
6747 | * return currentRank + 1;
|
6748 | * });
|
6749 | * ```
|
6750 | *
|
6751 | * @example
|
6752 | * ```javascript
|
6753 | * // Try to create a user for ada, but only if the user id 'ada' isn't
|
6754 | * // already taken
|
6755 | * var adaRef = firebase.database().ref('users/ada');
|
6756 | * adaRef.transaction(function(currentData) {
|
6757 | * if (currentData === null) {
|
6758 | * return { name: { first: 'Ada', last: 'Lovelace' } };
|
6759 | * } else {
|
6760 | * console.log('User ada already exists.');
|
6761 | * return; // Abort the transaction.
|
6762 | * }
|
6763 | * }, function(error, committed, snapshot) {
|
6764 | * if (error) {
|
6765 | * console.log('Transaction failed abnormally!', error);
|
6766 | * } else if (!committed) {
|
6767 | * console.log('We aborted the transaction (because ada already exists).');
|
6768 | * } else {
|
6769 | * console.log('User ada added!');
|
6770 | * }
|
6771 | * console.log("Ada's data: ", snapshot.val());
|
6772 | * });
|
6773 | * ```
|
6774 | *
|
6775 | * @param transactionUpdate A developer-supplied function which
|
6776 | * will be passed the current data stored at this location (as a JavaScript
|
6777 | * object). The function should return the new value it would like written (as
|
6778 | * a JavaScript object). If `undefined` is returned (i.e. you return with no
|
6779 | * arguments) the transaction will be aborted and the data at this location
|
6780 | * will not be modified.
|
6781 | * @param onComplete A callback
|
6782 | * function that will be called when the transaction completes. The callback
|
6783 | * is passed three arguments: a possibly-null `Error`, a `boolean` indicating
|
6784 | * whether the transaction was committed, and a `DataSnapshot` indicating the
|
6785 | * final result. If the transaction failed abnormally, the first argument will
|
6786 | * be an `Error` object indicating the failure cause. If the transaction
|
6787 | * finished normally, but no data was committed because no data was returned
|
6788 | * from `transactionUpdate`, then second argument will be false. If the
|
6789 | * transaction completed and committed data to Firebase, the second argument
|
6790 | * will be true. Regardless, the third argument will be a `DataSnapshot`
|
6791 | * containing the resulting data in this location.
|
6792 | * @param applyLocally By default, events are raised each time the
|
6793 | * transaction update function runs. So if it is run multiple times, you may
|
6794 | * see intermediate states. You can set this to false to suppress these
|
6795 | * intermediate states and instead wait until the transaction has completed
|
6796 | * before events are raised.
|
6797 | * @return Returns a Promise that can optionally be used instead of the onComplete
|
6798 | * callback to handle success and failure.
|
6799 | */
|
6800 | transaction(
|
6801 | transactionUpdate: (a: any) => any,
|
6802 | onComplete?: (
|
6803 | a: Error | null,
|
6804 | b: boolean,
|
6805 | c: firebase.database.DataSnapshot | null
|
6806 | ) => any,
|
6807 | applyLocally?: boolean
|
6808 | ): Promise<any>;
|
6809 | /**
|
6810 | * Writes multiple values to the Database at once.
|
6811 | *
|
6812 | * The `values` argument contains multiple property-value pairs that will be
|
6813 | * written to the Database together. Each child property can either be a simple
|
6814 | * property (for example, "name") or a relative path (for example,
|
6815 | * "name/first") from the current location to the data to update.
|
6816 | *
|
6817 | * As opposed to the `set()` method, `update()` can be use to selectively update
|
6818 | * only the referenced properties at the current location (instead of replacing
|
6819 | * all the child properties at the current location).
|
6820 | *
|
6821 | * The effect of the write will be visible immediately, and the corresponding
|
6822 | * events ('value', 'child_added', etc.) will be triggered. Synchronization of
|
6823 | * the data to the Firebase servers will also be started, and the returned
|
6824 | * Promise will resolve when complete. If provided, the `onComplete` callback
|
6825 | * will be called asynchronously after synchronization has finished.
|
6826 | *
|
6827 | * A single `update()` will generate a single "value" event at the location
|
6828 | * where the `update()` was performed, regardless of how many children were
|
6829 | * modified.
|
6830 | *
|
6831 | * Note that modifying data with `update()` will cancel any pending
|
6832 | * transactions at that location, so extreme care should be taken if mixing
|
6833 | * `update()` and `transaction()` to modify the same data.
|
6834 | *
|
6835 | * Passing `null` to `update()` will remove the data at this location.
|
6836 | *
|
6837 | * See
|
6838 | * {@link
|
6839 | * https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html
|
6840 | * Introducing multi-location updates and more}.
|
6841 | *
|
6842 | * @example
|
6843 | * ```javascript
|
6844 | * var adaNameRef = firebase.database().ref('users/ada/name');
|
6845 | * // Modify the 'first' and 'last' properties, but leave other data at
|
6846 | * // adaNameRef unchanged.
|
6847 | * adaNameRef.update({ first: 'Ada', last: 'Lovelace' });
|
6848 | * ```
|
6849 | *
|
6850 | * @param values Object containing multiple values.
|
6851 | * @param onComplete Callback called when write to server is
|
6852 | * complete.
|
6853 | * @return Resolves when update on server is complete.
|
6854 | */
|
6855 | update(values: Object, onComplete?: (a: Error | null) => any): Promise<any>;
|
6856 | }
|
6857 |
|
6858 | interface ThenableReference
|
6859 | extends firebase.database.Reference,
|
6860 | Promise<Reference> {}
|
6861 |
|
6862 | /**
|
6863 | * Logs debugging information to the console.
|
6864 | *
|
6865 | * @example
|
6866 | * ```javascript
|
6867 | * // Enable logging
|
6868 | * firebase.database.enableLogging(true);
|
6869 | * ```
|
6870 | *
|
6871 | * @example
|
6872 | * ```javascript
|
6873 | * // Disable logging
|
6874 | * firebase.database.enableLogging(false);
|
6875 | * ```
|
6876 | *
|
6877 | * @example
|
6878 | * ```javascript
|
6879 | * // Enable logging across page refreshes
|
6880 | * firebase.database.enableLogging(true, true);
|
6881 | * ```
|
6882 | *
|
6883 | * @example
|
6884 | * ```javascript
|
6885 | * // Provide custom logger which prefixes log statements with "[FIREBASE]"
|
6886 | * firebase.database.enableLogging(function(message) {
|
6887 | * console.log("[FIREBASE]", message);
|
6888 | * });
|
6889 | * ```
|
6890 | *
|
6891 | * @param logger Enables logging if `true`;
|
6892 | * disables logging if `false`. You can also provide a custom logger function
|
6893 | * to control how things get logged.
|
6894 | * @param persistent Remembers the logging state between page
|
6895 | * refreshes if `true`.
|
6896 | */
|
6897 | function enableLogging(
|
6898 | logger?: boolean | ((a: string) => any),
|
6899 | persistent?: boolean
|
6900 | ): any;
|
6901 | }
|
6902 |
|
6903 | declare namespace firebase.database.ServerValue {
|
6904 | /**
|
6905 | * A placeholder value for auto-populating the current timestamp (time
|
6906 | * since the Unix epoch, in milliseconds) as determined by the Firebase
|
6907 | * servers.
|
6908 | *
|
6909 | * @example
|
6910 | * ```javascript
|
6911 | * var sessionsRef = firebase.database().ref("sessions");
|
6912 | * sessionsRef.push({
|
6913 | * startedAt: firebase.database.ServerValue.TIMESTAMP
|
6914 | * });
|
6915 | * ```
|
6916 | */
|
6917 | var TIMESTAMP: Object;
|
6918 | }
|
6919 |
|
6920 | /**
|
6921 | * @webonly
|
6922 | */
|
6923 | declare namespace firebase.messaging {
|
6924 | /**
|
6925 | * The Firebase Messaging service interface.
|
6926 | *
|
6927 | * Do not call this constructor directly. Instead, use
|
6928 | * {@link firebase.messaging `firebase.messaging()`}.
|
6929 | *
|
6930 | * See
|
6931 | * {@link
|
6932 | * https://firebase.google.com/docs/cloud-messaging/js/client
|
6933 | * Set Up a JavaScript Firebase Cloud Messaging Client App}
|
6934 | * for a full guide on how to use the Firebase Messaging service.
|
6935 | *
|
6936 | */
|
6937 | interface Messaging {
|
6938 | /**
|
6939 | * To forcibly stop a registration token from being used, delete it
|
6940 | * by calling this method.
|
6941 | *
|
6942 | * @param token The token to delete.
|
6943 | * @return The promise resolves when the token has been
|
6944 | * successfully deleted.
|
6945 | */
|
6946 | deleteToken(token: string): Promise<boolean>;
|
6947 | /**
|
6948 | * Subscribes the user to push notifications and returns an FCM registration
|
6949 | * token that can be used to send push messages to the user.
|
6950 | *
|
6951 | * If notification permission isn't already granted, this method asks the
|
6952 | * user for permission. The returned promise rejects if the user does not
|
6953 | * allow the app to show notifications.
|
6954 | *
|
6955 | * @return The promise resolves with the FCM token string.
|
6956 | */
|
6957 | getToken(): Promise<string>;
|
6958 | /**
|
6959 | * When a push message is received and the user is currently on a page
|
6960 | * for your origin, the message is passed to the page and an `onMessage()`
|
6961 | * event is dispatched with the payload of the push message.
|
6962 | *
|
6963 | * NOTE: These events are dispatched when you have called
|
6964 | * `setBackgroundMessageHandler()` in your service worker.
|
6965 | *
|
6966 | * @param
|
6967 | * nextOrObserver This function, or observer object with `next` defined,
|
6968 | * is called when a message is received and the user is currently viewing your page.
|
6969 | * @return To stop listening for messages
|
6970 | * execute this returned function.
|
6971 | */
|
6972 | onMessage(
|
6973 | nextOrObserver: firebase.NextFn<any> | firebase.Observer<any>,
|
6974 | error?: firebase.ErrorFn,
|
6975 | completed?: firebase.CompleteFn
|
6976 | ): firebase.Unsubscribe;
|
6977 | /**
|
6978 | * You should listen for token refreshes so your web app knows when FCM
|
6979 | * has invalidated your existing token and you need to call `getToken()`
|
6980 | * to get a new token.
|
6981 | *
|
6982 | * @param
|
6983 | * nextOrObserver This function, or observer object with `next` defined,
|
6984 | * is called when a token refresh has occurred.
|
6985 | * @return To stop listening for token
|
6986 | * refresh events execute this returned function.
|
6987 | */
|
6988 | onTokenRefresh(
|
6989 | nextOrObserver: firebase.NextFn<any> | firebase.Observer<any>,
|
6990 | error?: firebase.ErrorFn,
|
6991 | completed?: firebase.CompleteFn
|
6992 | ): firebase.Unsubscribe;
|
6993 | /**
|
6994 | * Notification permissions are required to send a user push messages.
|
6995 | * Calling this method displays the permission dialog to the user and
|
6996 | * resolves if the permission is granted. It is not necessary to call this
|
6997 | * method, as `getToken()` will do this automatically if required.
|
6998 | *
|
6999 | * @return The promise resolves if permission is
|
7000 | * granted. Otherwise, the promise is rejected with an error.
|
7001 | *
|
7002 | * @deprecated Use Notification.requestPermission() instead.
|
7003 | * https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission
|
7004 | */
|
7005 | requestPermission(): Promise<void>;
|
7006 | /**
|
7007 | * FCM directs push messages to your web page's `onMessage()` callback
|
7008 | * if the user currently has it open. Otherwise, it calls
|
7009 | * your callback passed into `setBackgroundMessageHandler()`.
|
7010 | *
|
7011 | * Your callback should return a promise that, once resolved, has
|
7012 | * shown a notification.
|
7013 | *
|
7014 | * @param callback The function to handle the push message.
|
7015 | */
|
7016 | setBackgroundMessageHandler(
|
7017 | callback: (payload: any) => Promise<any> | void
|
7018 | ): void;
|
7019 | /**
|
7020 | * To use your own service worker for receiving push messages, you
|
7021 | * can pass in your service worker registration in this method.
|
7022 | *
|
7023 | * @param registration The service worker
|
7024 | * registration you wish to use for push messaging.
|
7025 | */
|
7026 | useServiceWorker(registration: ServiceWorkerRegistration): void;
|
7027 | usePublicVapidKey(b64PublicKey: string): void;
|
7028 | }
|
7029 |
|
7030 | function isSupported(): boolean;
|
7031 | }
|
7032 |
|
7033 | /**
|
7034 | * @webonly
|
7035 | */
|
7036 | declare namespace firebase.storage {
|
7037 | /**
|
7038 | * The full set of object metadata, including read-only properties.
|
7039 | */
|
7040 | interface FullMetadata extends firebase.storage.UploadMetadata {
|
7041 | /**
|
7042 | * The bucket this object is contained in.
|
7043 | */
|
7044 | bucket: string;
|
7045 | /**
|
7046 | * @deprecated
|
7047 | * Use Reference.getDownloadURL instead. This property will be removed in a
|
7048 | * future release.
|
7049 | */
|
7050 | downloadURLs: string[];
|
7051 | /**
|
7052 | * The full path of this object.
|
7053 | */
|
7054 | fullPath: string;
|
7055 | /**
|
7056 | * The object's generation.
|
7057 | * @see {@link https://cloud.google.com/storage/docs/generations-preconditions}
|
7058 | */
|
7059 | generation: string;
|
7060 | /**
|
7061 | * The object's metageneration.
|
7062 | * @see {@link https://cloud.google.com/storage/docs/generations-preconditions}
|
7063 | */
|
7064 | metageneration: string;
|
7065 | /**
|
7066 | * The short name of this object, which is the last component of the full path.
|
7067 | * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
7068 | */
|
7069 | name: string;
|
7070 | /**
|
7071 | * The size of this object, in bytes.
|
7072 | */
|
7073 | size: number;
|
7074 | /**
|
7075 | * A date string representing when this object was created.
|
7076 | */
|
7077 | timeCreated: string;
|
7078 | /**
|
7079 | * A date string representing when this object was last updated.
|
7080 | */
|
7081 | updated: string;
|
7082 | }
|
7083 |
|
7084 | /**
|
7085 | * Represents a reference to a Google Cloud Storage object. Developers can
|
7086 | * upload, download, and delete objects, as well as get/set object metadata.
|
7087 | */
|
7088 | interface Reference {
|
7089 | /**
|
7090 | * The name of the bucket containing this reference's object.
|
7091 | */
|
7092 | bucket: string;
|
7093 | /**
|
7094 | * Returns a reference to a relative path from this reference.
|
7095 | * @param path The relative path from this reference.
|
7096 | * Leading, trailing, and consecutive slashes are removed.
|
7097 | * @return The reference to the given path.
|
7098 | */
|
7099 | child(path: string): firebase.storage.Reference;
|
7100 | /**
|
7101 | * Deletes the object at this reference's location.
|
7102 | * @return A Promise that resolves if the deletion
|
7103 | * succeeded and rejects if it failed, including if the object didn't exist.
|
7104 | */
|
7105 | delete(): Promise<any>;
|
7106 | /**
|
7107 | * The full path of this object.
|
7108 | */
|
7109 | fullPath: string;
|
7110 | /**
|
7111 | * Fetches a long lived download URL for this object.
|
7112 | * @return A Promise that resolves with the download
|
7113 | * URL or rejects if the fetch failed, including if the object did not
|
7114 | * exist.
|
7115 | */
|
7116 | getDownloadURL(): Promise<any>;
|
7117 | /**
|
7118 | * Fetches metadata for the object at this location, if one exists.
|
7119 | * @return A Promise that
|
7120 | * resolves with the metadata, or rejects if the fetch failed, including if
|
7121 | * the object did not exist.
|
7122 | */
|
7123 | getMetadata(): Promise<any>;
|
7124 | /**
|
7125 | * The short name of this object, which is the last component of the full path.
|
7126 | * For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
7127 | */
|
7128 | name: string;
|
7129 | /**
|
7130 | * A reference pointing to the parent location of this reference, or null if
|
7131 | * this reference is the root.
|
7132 | */
|
7133 | parent: firebase.storage.Reference | null;
|
7134 | /**
|
7135 | * Uploads data to this reference's location.
|
7136 | * @param data The data to upload.
|
7137 | * @param metadata Metadata for the newly
|
7138 | * uploaded object.
|
7139 | * @return An object that can be used to monitor
|
7140 | * and manage the upload.
|
7141 | */
|
7142 | put(
|
7143 | data: Blob | Uint8Array | ArrayBuffer,
|
7144 | metadata?: firebase.storage.UploadMetadata
|
7145 | ): firebase.storage.UploadTask;
|
7146 | /**
|
7147 | * Uploads string data to this reference's location.
|
7148 | * @param data The string to upload.
|
7149 | * @param format The format of the string to
|
7150 | * upload.
|
7151 | * @param metadata Metadata for the newly
|
7152 | * uploaded object.
|
7153 | * @throws If the format is not an allowed format, or if the given string
|
7154 | * doesn't conform to the specified format.
|
7155 | */
|
7156 | putString(
|
7157 | data: string,
|
7158 | format?: firebase.storage.StringFormat,
|
7159 | metadata?: firebase.storage.UploadMetadata
|
7160 | ): firebase.storage.UploadTask;
|
7161 | /**
|
7162 | * A reference to the root of this reference's bucket.
|
7163 | */
|
7164 | root: firebase.storage.Reference;
|
7165 | /**
|
7166 | * The storage service associated with this reference.
|
7167 | */
|
7168 | storage: firebase.storage.Storage;
|
7169 | /**
|
7170 | * Returns a gs:// URL for this object in the form
|
7171 | * `gs://<bucket>/<path>/<to>/<object>`
|
7172 | * @return The gs:// URL.
|
7173 | */
|
7174 | toString(): string;
|
7175 | /**
|
7176 | * Updates the metadata for the object at this location, if one exists.
|
7177 | * @param metadata The new metadata.
|
7178 | * Setting a property to 'null' removes it on the server, while leaving
|
7179 | * a property as 'undefined' has no effect.
|
7180 | * @return A Promise that
|
7181 | * resolves with the full updated metadata or rejects if the updated failed,
|
7182 | * including if the object did not exist.
|
7183 | */
|
7184 | updateMetadata(metadata: firebase.storage.SettableMetadata): Promise<any>;
|
7185 | /**
|
7186 | * List all items (files) and prefixes (folders) under this storage reference.
|
7187 | *
|
7188 | * This is a helper method for calling `list()` repeatedly until there are
|
7189 | * no more results. The default pagination size is 1000.
|
7190 | *
|
7191 | * Note: The results may not be consistent if objects are changed while this
|
7192 | * operation is running.
|
7193 | *
|
7194 | * Warning: `listAll` may potentially consume too many resources if there are
|
7195 | * too many results.
|
7196 | *
|
7197 | * @return A Promise that resolves with all the items and prefixes under
|
7198 | * the current storage reference. `prefixes` contains references to
|
7199 | * sub-directories and `items` contains references to objects in this
|
7200 | * folder. `nextPageToken` is never returned.
|
7201 | */
|
7202 | listAll(): Promise<ListResult>;
|
7203 | /**
|
7204 | * List items (files) and prefixes (folders) under this storage reference.
|
7205 | *
|
7206 | * List API is only available for Firebase Rules Version 2.
|
7207 | *
|
7208 | * GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
|
7209 | * delimited folder structure.
|
7210 | * Refer to GCS's List API if you want to learn more.
|
7211 | *
|
7212 | * To adhere to Firebase Rules's Semantics, Firebase Storage does not
|
7213 | * support objects whose paths end with "/" or contain two consecutive
|
7214 | * "/"s. Firebase Storage List API will filter these unsupported objects.
|
7215 | * `list()` may fail if there are too many unsupported objects in the bucket.
|
7216 | *
|
7217 | * @param options See `ListOptions` for details.
|
7218 | * @return A Promise that resolves with the items and prefixes.
|
7219 | * `prefixes` contains references to sub-folders and `items`
|
7220 | * contains references to objects in this folder. `nextPageToken`
|
7221 | * can be used to get the rest of the results.
|
7222 | */
|
7223 | list(options?: ListOptions): Promise<ListResult>;
|
7224 | }
|
7225 |
|
7226 | /**
|
7227 | * Result returned by list().
|
7228 | */
|
7229 | interface ListResult {
|
7230 | /**
|
7231 | * References to prefixes (sub-folders). You can call list() on them to
|
7232 | * get its contents.
|
7233 | *
|
7234 | * Folders are implicit based on '/' in the object paths.
|
7235 | * For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
|
7236 | * will return '/a/b' as a prefix.
|
7237 | */
|
7238 | prefixes: Reference[];
|
7239 | /**
|
7240 | * Objects in this directory.
|
7241 | * You can call getMetadate() and getDownloadUrl() on them.
|
7242 | */
|
7243 | items: Reference[];
|
7244 | /**
|
7245 | * If set, there might be more results for this list. Use this token to resume the list.
|
7246 | */
|
7247 | nextPageToken: string | null;
|
7248 | }
|
7249 |
|
7250 | /**
|
7251 | * The options `list()` accepts.
|
7252 | */
|
7253 | interface ListOptions {
|
7254 | /**
|
7255 | * If set, limits the total number of `prefixes` and `items` to return.
|
7256 | * The default and maximum maxResults is 1000.
|
7257 | */
|
7258 | maxResults?: number | null;
|
7259 | /**
|
7260 | * The `nextPageToken` from a previous call to `list()`. If provided,
|
7261 | * listing is resumed from the previous position.
|
7262 | */
|
7263 | pageToken?: string | null;
|
7264 | }
|
7265 |
|
7266 | /**
|
7267 | * Object metadata that can be set at any time.
|
7268 | */
|
7269 | interface SettableMetadata {
|
7270 | /**
|
7271 | * Served as the 'Cache-Control' header on object download.
|
7272 | */
|
7273 | cacheControl?: string | null;
|
7274 | contentDisposition?: string | null;
|
7275 | /**
|
7276 | * Served as the 'Content-Encoding' header on object download.
|
7277 | */
|
7278 | contentEncoding?: string | null;
|
7279 | /**
|
7280 | * Served as the 'Content-Language' header on object download.
|
7281 | */
|
7282 | contentLanguage?: string | null;
|
7283 | /**
|
7284 | * Served as the 'Content-Type' header on object download.
|
7285 | */
|
7286 | contentType?: string | null;
|
7287 | /**
|
7288 | * Additional user-defined custom metadata.
|
7289 | */
|
7290 | customMetadata?: {
|
7291 | [/* warning: coerced from ? */ key: string]: string;
|
7292 | } | null;
|
7293 | }
|
7294 |
|
7295 | /**
|
7296 | * The Firebase Storage service interface.
|
7297 | *
|
7298 | * Do not call this constructor directly. Instead, use
|
7299 | * {@link firebase.storage `firebase.storage()`}.
|
7300 | *
|
7301 | * See
|
7302 | * {@link
|
7303 | * https://firebase.google.com/docs/storage/web/start/
|
7304 | * Get Started on Web}
|
7305 | * for a full guide on how to use the Firebase Storage service.
|
7306 | */
|
7307 | interface Storage {
|
7308 | /**
|
7309 | * The {@link firebase.app.App app} associated with the `Storage` service
|
7310 | * instance.
|
7311 | *
|
7312 | * @example
|
7313 | * ```javascript
|
7314 | * var app = storage.app;
|
7315 | * ```
|
7316 | */
|
7317 | app: firebase.app.App;
|
7318 | /**
|
7319 | * The maximum time to retry operations other than uploads or downloads in
|
7320 | * milliseconds.
|
7321 | */
|
7322 | maxOperationRetryTime: number;
|
7323 | /**
|
7324 | * The maximum time to retry uploads in milliseconds.
|
7325 | */
|
7326 | maxUploadRetryTime: number;
|
7327 | /**
|
7328 | * Returns a reference for the given path in the default bucket.
|
7329 | * @param path A relative path to initialize the reference with,
|
7330 | * for example `path/to/image.jpg`. If not passed, the returned reference
|
7331 | * points to the bucket root.
|
7332 | * @return A reference for the given path.
|
7333 | */
|
7334 | ref(path?: string): firebase.storage.Reference;
|
7335 | /**
|
7336 | * Returns a reference for the given absolute URL.
|
7337 | * @param url A URL in the form: <br />
|
7338 | * 1) a gs:// URL, for example `gs://bucket/files/image.png` <br />
|
7339 | * 2) a download URL taken from object metadata. <br />
|
7340 | * @see {@link firebase.storage.FullMetadata.prototype.downloadURLs}
|
7341 | * @return A reference for the given URL.
|
7342 | */
|
7343 | refFromURL(url: string): firebase.storage.Reference;
|
7344 | /**
|
7345 | * @param time The new maximum operation retry time in milliseconds.
|
7346 | * @see {@link firebase.storage.Storage.prototype.maxOperationRetryTime}
|
7347 | */
|
7348 | setMaxOperationRetryTime(time: number): any;
|
7349 | /**
|
7350 | * @param time The new maximum upload retry time in milliseconds.
|
7351 | * @see {@link firebase.storage.Storage.prototype.maxUploadRetryTime}
|
7352 | */
|
7353 | setMaxUploadRetryTime(time: number): any;
|
7354 | }
|
7355 |
|
7356 | /**
|
7357 | * @enum {string}
|
7358 | * An enumeration of the possible string formats for upload.
|
7359 | */
|
7360 | type StringFormat = string;
|
7361 | var StringFormat: {
|
7362 | /**
|
7363 | * Indicates the string should be interpreted as base64-encoded data.
|
7364 | * Padding characters (trailing '='s) are optional.
|
7365 | * Example: The string 'rWmO++E6t7/rlw==' becomes the byte sequence
|
7366 | * ad 69 8e fb e1 3a b7 bf eb 97
|
7367 | */
|
7368 | BASE64: StringFormat;
|
7369 | /**
|
7370 | * Indicates the string should be interpreted as base64url-encoded data.
|
7371 | * Padding characters (trailing '='s) are optional.
|
7372 | * Example: The string 'rWmO--E6t7_rlw==' becomes the byte sequence
|
7373 | * ad 69 8e fb e1 3a b7 bf eb 97
|
7374 | */
|
7375 | BASE64URL: StringFormat;
|
7376 | /**
|
7377 | * Indicates the string is a data URL, such as one obtained from
|
7378 | * canvas.toDataURL().
|
7379 | * Example: the string 'data:application/octet-stream;base64,aaaa'
|
7380 | * becomes the byte sequence
|
7381 | * 69 a6 9a
|
7382 | * (the content-type "application/octet-stream" is also applied, but can
|
7383 | * be overridden in the metadata object).
|
7384 | */
|
7385 | DATA_URL: StringFormat;
|
7386 | /**
|
7387 | * Indicates the string should be interpreted "raw", that is, as normal text.
|
7388 | * The string will be interpreted as UTF-16, then uploaded as a UTF-8 byte
|
7389 | * sequence.
|
7390 | * Example: The string 'Hello! \ud83d\ude0a' becomes the byte sequence
|
7391 | * 48 65 6c 6c 6f 21 20 f0 9f 98 8a
|
7392 | */
|
7393 | RAW: StringFormat;
|
7394 | };
|
7395 |
|
7396 | /**
|
7397 | * An event that is triggered on a task.
|
7398 | * @enum {string}
|
7399 | * @see {@link firebase.storage.UploadTask.prototype.on}
|
7400 | */
|
7401 | type TaskEvent = string;
|
7402 | var TaskEvent: {
|
7403 | /**
|
7404 | * For this event,
|
7405 | * <ul>
|
7406 | * <li>The `next` function is triggered on progress updates and when the
|
7407 | * task is paused/resumed with a
|
7408 | * {@link firebase.storage.UploadTaskSnapshot} as the first
|
7409 | * argument.</li>
|
7410 | * <li>The `error` function is triggered if the upload is canceled or fails
|
7411 | * for another reason.</li>
|
7412 | * <li>The `complete` function is triggered if the upload completes
|
7413 | * successfully.</li>
|
7414 | * </ul>
|
7415 | */
|
7416 | STATE_CHANGED: TaskEvent;
|
7417 | };
|
7418 |
|
7419 | /**
|
7420 | * Represents the current state of a running upload.
|
7421 | * @enum {string}
|
7422 | */
|
7423 | type TaskState = string;
|
7424 | var TaskState: {
|
7425 | CANCELED: TaskState;
|
7426 | ERROR: TaskState;
|
7427 | PAUSED: TaskState;
|
7428 | RUNNING: TaskState;
|
7429 | SUCCESS: TaskState;
|
7430 | };
|
7431 |
|
7432 | /**
|
7433 | * Object metadata that can be set at upload.
|
7434 | */
|
7435 | interface UploadMetadata extends firebase.storage.SettableMetadata {
|
7436 | /**
|
7437 | * A Base64-encoded MD5 hash of the object being uploaded.
|
7438 | */
|
7439 | md5Hash?: string | null;
|
7440 | }
|
7441 |
|
7442 | /**
|
7443 | * Represents the process of uploading an object. Allows you to monitor and
|
7444 | * manage the upload.
|
7445 | */
|
7446 | interface UploadTask {
|
7447 | /**
|
7448 | * Cancels a running task. Has no effect on a complete or failed task.
|
7449 | * @return True if the cancel had an effect.
|
7450 | */
|
7451 | cancel(): boolean;
|
7452 | /**
|
7453 | * Equivalent to calling `then(null, onRejected)`.
|
7454 | */
|
7455 | catch(onRejected: (a: Error) => any): Promise<any>;
|
7456 | /**
|
7457 | * Listens for events on this task.
|
7458 | *
|
7459 | * Events have three callback functions (referred to as `next`, `error`, and
|
7460 | * `complete`).
|
7461 | *
|
7462 | * If only the event is passed, a function that can be used to register the
|
7463 | * callbacks is returned. Otherwise, the callbacks are passed after the event.
|
7464 | *
|
7465 | * Callbacks can be passed either as three separate arguments <em>or</em> as the
|
7466 | * `next`, `error`, and `complete` properties of an object. Any of the three
|
7467 | * callbacks is optional, as long as at least one is specified. In addition,
|
7468 | * when you add your callbacks, you get a function back. You can call this
|
7469 | * function to unregister the associated callbacks.
|
7470 | *
|
7471 | * @example **Pass callbacks separately or in an object.**
|
7472 | * ```javascript
|
7473 | * var next = function(snapshot) {};
|
7474 | * var error = function(error) {};
|
7475 | * var complete = function() {};
|
7476 | *
|
7477 | * // The first example.
|
7478 | * uploadTask.on(
|
7479 | * firebase.storage.TaskEvent.STATE_CHANGED,
|
7480 | * next,
|
7481 | * error,
|
7482 | * complete);
|
7483 | *
|
7484 | * // This is equivalent to the first example.
|
7485 | * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
|
7486 | * 'next': next,
|
7487 | * 'error': error,
|
7488 | * 'complete': complete
|
7489 | * });
|
7490 | *
|
7491 | * // This is equivalent to the first example.
|
7492 | * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
7493 | * subscribe(next, error, complete);
|
7494 | *
|
7495 | * // This is equivalent to the first example.
|
7496 | * var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
7497 | * subscribe({
|
7498 | * 'next': next,
|
7499 | * 'error': error,
|
7500 | * 'complete': complete
|
7501 | * });
|
7502 | * ```
|
7503 | *
|
7504 | * @example **Any callback is optional.**
|
7505 | * ```javascript
|
7506 | * // Just listening for completion, this is legal.
|
7507 | * uploadTask.on(
|
7508 | * firebase.storage.TaskEvent.STATE_CHANGED,
|
7509 | * null,
|
7510 | * null,
|
7511 | * function() {
|
7512 | * console.log('upload complete!');
|
7513 | * });
|
7514 | *
|
7515 | * // Just listening for progress/state changes, this is legal.
|
7516 | * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
|
7517 | * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
7518 | * console.log(percent + "% done");
|
7519 | * });
|
7520 | *
|
7521 | * // This is also legal.
|
7522 | * uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
|
7523 | * 'complete': function() {
|
7524 | * console.log('upload complete!');
|
7525 | * }
|
7526 | * });
|
7527 | * ```
|
7528 | *
|
7529 | * @example **Use the returned function to remove callbacks.**
|
7530 | * ```javascript
|
7531 | * var unsubscribe = uploadTask.on(
|
7532 | * firebase.storage.TaskEvent.STATE_CHANGED,
|
7533 | * function(snapshot) {
|
7534 | * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
7535 | * console.log(percent + "% done");
|
7536 | * // Stop after receiving one update.
|
7537 | * unsubscribe();
|
7538 | * });
|
7539 | *
|
7540 | * // This code is equivalent to the above.
|
7541 | * var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
7542 | * unsubscribe = handle(function(snapshot) {
|
7543 | * var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
7544 | * console.log(percent + "% done");
|
7545 | * // Stop after receiving one update.
|
7546 | * unsubscribe();
|
7547 | * });
|
7548 | * ```
|
7549 | *
|
7550 | * @param event The event to listen for.
|
7551 | * @param nextOrObserver
|
7552 | * The `next` function, which gets called for each item in
|
7553 | * the event stream, or an observer object with some or all of these three
|
7554 | * properties (`next`, `error`, `complete`).
|
7555 | * @param error A function that gets called with an Error
|
7556 | * if the event stream ends due to an error.
|
7557 | * @param complete A function that gets called if the
|
7558 | * event stream ends normally.
|
7559 | * @return
|
7560 | * If only the event argument is passed, returns a function you can use to
|
7561 | * add callbacks (see the examples above). If more than just the event
|
7562 | * argument is passed, returns a function you can call to unregister the
|
7563 | * callbacks.
|
7564 | */
|
7565 | on(
|
7566 | event: firebase.storage.TaskEvent,
|
7567 | nextOrObserver?:
|
7568 | | firebase.Observer<UploadTaskSnapshot>
|
7569 | | null
|
7570 | | ((a: UploadTaskSnapshot) => any),
|
7571 | error?: ((a: Error) => any) | null,
|
7572 | complete?: firebase.Unsubscribe | null
|
7573 | ): Function;
|
7574 | /**
|
7575 | * Pauses a running task. Has no effect on a paused or failed task.
|
7576 | * @return True if the pause had an effect.
|
7577 | */
|
7578 | pause(): boolean;
|
7579 | /**
|
7580 | * Resumes a paused task. Has no effect on a running or failed task.
|
7581 | * @return True if the resume had an effect.
|
7582 | */
|
7583 | resume(): boolean;
|
7584 | /**
|
7585 | * A snapshot of the current task state.
|
7586 | */
|
7587 | snapshot: firebase.storage.UploadTaskSnapshot;
|
7588 | /**
|
7589 | * This object behaves like a Promise, and resolves with its snapshot data when
|
7590 | * the upload completes.
|
7591 | * @param onFulfilled
|
7592 | * The fulfillment callback. Promise chaining works as normal.
|
7593 | * @param onRejected The rejection callback.
|
7594 | */
|
7595 | then(
|
7596 | onFulfilled?: ((a: firebase.storage.UploadTaskSnapshot) => any) | null,
|
7597 | onRejected?: ((a: Error) => any) | null
|
7598 | ): Promise<any>;
|
7599 | }
|
7600 |
|
7601 | /**
|
7602 | * Holds data about the current state of the upload task.
|
7603 | */
|
7604 | interface UploadTaskSnapshot {
|
7605 | /**
|
7606 | * The number of bytes that have been successfully uploaded so far.
|
7607 | */
|
7608 | bytesTransferred: number;
|
7609 | /**
|
7610 | * @deprecated
|
7611 | * Use Reference.getDownloadURL instead. This property will be removed in a
|
7612 | * future release.
|
7613 | */
|
7614 | downloadURL: string | null;
|
7615 | /**
|
7616 | * Before the upload completes, contains the metadata sent to the server.
|
7617 | * After the upload completes, contains the metadata sent back from the server.
|
7618 | */
|
7619 | metadata: firebase.storage.FullMetadata;
|
7620 | /**
|
7621 | * The reference that spawned this snapshot's upload task.
|
7622 | */
|
7623 | ref: firebase.storage.Reference;
|
7624 | /**
|
7625 | * The current state of the task.
|
7626 | */
|
7627 | state: firebase.storage.TaskState;
|
7628 | /**
|
7629 | * The task of which this is a snapshot.
|
7630 | */
|
7631 | task: firebase.storage.UploadTask;
|
7632 | /**
|
7633 | * The total number of bytes to be uploaded.
|
7634 | */
|
7635 | totalBytes: number;
|
7636 | }
|
7637 | }
|
7638 |
|
7639 | declare namespace firebase.firestore {
|
7640 | /**
|
7641 | * Document data (for use with `DocumentReference.set()`) consists of fields
|
7642 | * mapped to values.
|
7643 | */
|
7644 | export type DocumentData = { [field: string]: any };
|
7645 |
|
7646 | /**
|
7647 | * Update data (for use with `DocumentReference.update()`) consists of field
|
7648 | * paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
|
7649 | * reference nested fields within the document.
|
7650 | */
|
7651 | export type UpdateData = { [fieldPath: string]: any };
|
7652 |
|
7653 | /**
|
7654 | * Constant used to indicate the LRU garbage collection should be disabled.
|
7655 | * Set this value as the `cacheSizeBytes` on the settings passed to the
|
7656 | * `Firestore` instance.
|
7657 | */
|
7658 | export const CACHE_SIZE_UNLIMITED: number;
|
7659 |
|
7660 | /**
|
7661 | * Specifies custom configurations for your Cloud Firestore instance.
|
7662 | * You must set these before invoking any other methods.
|
7663 | */
|
7664 | export interface Settings {
|
7665 | /** The hostname to connect to. */
|
7666 | host?: string;
|
7667 | /** Whether to use SSL when connecting. */
|
7668 | ssl?: boolean;
|
7669 |
|
7670 | /**
|
7671 | * Specifies whether to use `Timestamp` objects for timestamp fields in
|
7672 | * `DocumentSnapshot`s. This is enabled by default and should not be
|
7673 | * disabled.
|
7674 | *
|
7675 | * Previously, Firestore returned timestamp fields as `Date` but `Date`
|
7676 | * only supports millisecond precision, which leads to truncation and
|
7677 | * causes unexpected behavior when using a timestamp from a snapshot as a
|
7678 | * part of a subsequent query.
|
7679 | *
|
7680 | * So now Firestore returns `Timestamp` values instead of `Date`, avoiding
|
7681 | * this kind of problem.
|
7682 | *
|
7683 | * To opt into the old behavior of returning `Date` objects, you can
|
7684 | * temporarily set `timestampsInSnapshots` to false.
|
7685 | *
|
7686 | * @deprecated This setting will be removed in a future release. You should
|
7687 | * update your code to expect `Timestamp` objects and stop using the
|
7688 | * `timestampsInSnapshots` setting.
|
7689 | */
|
7690 | timestampsInSnapshots?: boolean;
|
7691 |
|
7692 | /**
|
7693 | * An approximate cache size threshold for the on-disk data. If the cache grows beyond this
|
7694 | * size, Firestore will start removing data that hasn't been recently used. The size is not a
|
7695 | * guarantee that the cache will stay below that size, only that if the cache exceeds the given
|
7696 | * size, cleanup will be attempted.
|
7697 | *
|
7698 | * The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to
|
7699 | * CACHE_SIZE_UNLIMITED to disable garbage collection.
|
7700 | */
|
7701 | cacheSizeBytes?: number;
|
7702 |
|
7703 | /**
|
7704 | * Forces the SDK’s underlying network transport (WebChannel) to use
|
7705 | * long-polling. Each response from the backend will be closed immediately
|
7706 | * after the backend sends data (by default responses are kept open in
|
7707 | * case the backend has more data to send). This avoids incompatibility
|
7708 | * issues with certain proxies, antivirus software, etc. that incorrectly
|
7709 | * buffer traffic indefinitely. Use of this option will cause some
|
7710 | * performance degradation though.
|
7711 | *
|
7712 | * This setting may be removed in a future release. If you find yourself
|
7713 | * using it to work around a specific network reliability issue, please
|
7714 | * tell us about it in
|
7715 | * https://github.com/firebase/firebase-js-sdk/issues/1674.
|
7716 | *
|
7717 | * @webonly
|
7718 | */
|
7719 | experimentalForceLongPolling?: boolean;
|
7720 | }
|
7721 |
|
7722 | /**
|
7723 | * Settings that can be passed to Firestore.enablePersistence() to configure
|
7724 | * Firestore persistence.
|
7725 | */
|
7726 | export interface PersistenceSettings {
|
7727 | /**
|
7728 | * Whether to synchronize the in-memory state of multiple tabs. Setting this
|
7729 | * to 'true' in all open tabs enables shared access to local persistence,
|
7730 | * shared execution of queries and latency-compensated local document updates
|
7731 | * across all connected instances.
|
7732 | *
|
7733 | * To enable this mode, `synchronizeTabs:true` needs to be set globally in all
|
7734 | * active tabs. If omitted or set to 'false', `enablePersistence()` will fail
|
7735 | * in all but the first tab.
|
7736 | */
|
7737 | synchronizeTabs?: boolean;
|
7738 |
|
7739 | /**
|
7740 | * Whether to synchronize the in-memory state of multiple tabs. Setting this
|
7741 | * to 'true' in all open tabs enables shared access to local persistence,
|
7742 | * shared execution of queries and latency-compensated local document updates
|
7743 | * across all connected instances.
|
7744 | *
|
7745 | * @deprecated This setting is deprecated. To enabled synchronization between
|
7746 | * multiple tabs, please use `synchronizeTabs: true` instead.
|
7747 | */
|
7748 | experimentalTabSynchronization?: boolean;
|
7749 | }
|
7750 |
|
7751 | export type LogLevel = 'debug' | 'error' | 'silent';
|
7752 |
|
7753 | /**
|
7754 | * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
|
7755 | *
|
7756 | * @param logLevel
|
7757 | * The verbosity you set for activity and error logging. Can be any of
|
7758 | * the following values:
|
7759 | *
|
7760 | * <ul>
|
7761 | * <li><code>debug</code> for the most verbose logging level, primarily for
|
7762 | * debugging.</li>
|
7763 | * <li><code>error</code> to log errors only.</li>
|
7764 | * <li><code>silent</code> to turn off logging.</li>
|
7765 | * </ul>
|
7766 | */
|
7767 | export function setLogLevel(logLevel: LogLevel): void;
|
7768 |
|
7769 | /**
|
7770 | * Converter used by `withConverter()` to transform user objects of type T
|
7771 | * into Firestore data.
|
7772 | *
|
7773 | * Using the converter allows you to specify generic type arguments when
|
7774 | * storing and retrieving objects from Firestore.
|
7775 | *
|
7776 | * @example
|
7777 | * ```typescript
|
7778 | * class Post {
|
7779 | * constructor(readonly title: string, readonly author: string) {}
|
7780 | *
|
7781 | * toString(): string {
|
7782 | * return this.title + ', by ' + this.author;
|
7783 | * }
|
7784 | * }
|
7785 | *
|
7786 | * const postConverter = {
|
7787 | * toFirestore(post: Post): firebase.firestore.DocumentData {
|
7788 | * return {title: post.title, author: post.author};
|
7789 | * },
|
7790 | * fromFirestore(
|
7791 | * snapshot: firebase.firestore.QueryDocumentSnapshot,
|
7792 | * options: firebase.firestore.SnapshotOptions
|
7793 | * ): Post {
|
7794 | * const data = snapshot.data(options)!;
|
7795 | * return new Post(data.title, data.author);
|
7796 | * }
|
7797 | * };
|
7798 | *
|
7799 | * const postSnap = await firebase.firestore()
|
7800 | * .collection('posts')
|
7801 | * .withConverter(postConverter)
|
7802 | * .doc().get();
|
7803 | * const post = postSnap.data();
|
7804 | * if (post !== undefined) {
|
7805 | * post.title; // string
|
7806 | * post.toString(); // Should be defined
|
7807 | * post.someNonExistentProperty; // TS error
|
7808 | * }
|
7809 | * ```
|
7810 | */
|
7811 | export interface FirestoreDataConverter<T> {
|
7812 | /**
|
7813 | * Called by the Firestore SDK to convert a custom model object of type T
|
7814 | * into a plain Javascript object (suitable for writing directly to the
|
7815 | * Firestore database).
|
7816 | */
|
7817 | toFirestore(modelObject: T): DocumentData;
|
7818 |
|
7819 | /**
|
7820 | * Called by the Firestore SDK to convert Firestore data into an object of
|
7821 | * type T. You can access your data by calling: `snapshot.data(options)`.
|
7822 | *
|
7823 | * @param snapshot A QueryDocumentSnapshot containing your data and metadata.
|
7824 | * @param options The SnapshotOptions from the initial call to `data()`.
|
7825 | */
|
7826 | fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): T;
|
7827 | }
|
7828 |
|
7829 | /**
|
7830 | * The Cloud Firestore service interface.
|
7831 | *
|
7832 | * Do not call this constructor directly. Instead, use
|
7833 | * {@link firebase.firestore `firebase.firestore()`}.
|
7834 | */
|
7835 | export class Firestore {
|
7836 | private constructor();
|
7837 | /**
|
7838 | * Specifies custom settings to be used to configure the `Firestore`
|
7839 | * instance. Must be set before invoking any other methods.
|
7840 | *
|
7841 | * @param settings The settings to use.
|
7842 | */
|
7843 | settings(settings: Settings): void;
|
7844 |
|
7845 | /**
|
7846 | * Attempts to enable persistent storage, if possible.
|
7847 | *
|
7848 | * Must be called before any other methods (other than settings() and
|
7849 | * clearPersistence()).
|
7850 | *
|
7851 | * If this fails, enablePersistence() will reject the promise it returns.
|
7852 | * Note that even after this failure, the firestore instance will remain
|
7853 | * usable, however offline persistence will be disabled.
|
7854 | *
|
7855 | * There are several reasons why this can fail, which can be identified by
|
7856 | * the `code` on the error.
|
7857 | *
|
7858 | * * failed-precondition: The app is already open in another browser tab.
|
7859 | * * unimplemented: The browser is incompatible with the offline
|
7860 | * persistence implementation.
|
7861 | *
|
7862 | * @param settings Optional settings object to configure persistence.
|
7863 | * @return A promise that represents successfully enabling persistent
|
7864 | * storage.
|
7865 | */
|
7866 | enablePersistence(settings?: PersistenceSettings): Promise<void>;
|
7867 |
|
7868 | /**
|
7869 | * Gets a `CollectionReference` instance that refers to the collection at
|
7870 | * the specified path.
|
7871 | *
|
7872 | * @param collectionPath A slash-separated path to a collection.
|
7873 | * @return The `CollectionReference` instance.
|
7874 | */
|
7875 | collection(collectionPath: string): CollectionReference<DocumentData>;
|
7876 |
|
7877 | /**
|
7878 | * Gets a `DocumentReference` instance that refers to the document at the
|
7879 | * specified path.
|
7880 | *
|
7881 | * @param documentPath A slash-separated path to a document.
|
7882 | * @return The `DocumentReference` instance.
|
7883 | */
|
7884 | doc(documentPath: string): DocumentReference<DocumentData>;
|
7885 |
|
7886 | /**
|
7887 | * Creates and returns a new Query that includes all documents in the
|
7888 | * database that are contained in a collection or subcollection with the
|
7889 | * given collectionId.
|
7890 | *
|
7891 | * @param collectionId Identifies the collections to query over. Every
|
7892 | * collection or subcollection with this ID as the last segment of its path
|
7893 | * will be included. Cannot contain a slash.
|
7894 | * @return The created Query.
|
7895 | */
|
7896 | collectionGroup(collectionId: string): Query<DocumentData>;
|
7897 |
|
7898 | /**
|
7899 | * Executes the given `updateFunction` and then attempts to commit the changes
|
7900 | * applied within the transaction. If any document read within the transaction
|
7901 | * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
|
7902 | * commit after 5 attempts, the transaction fails.
|
7903 | *
|
7904 | * The maximum number of writes allowed in a single transaction is 500, but
|
7905 | * note that each usage of `FieldValue.serverTimestamp()`,
|
7906 | * `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
|
7907 | * `FieldValue.increment()` inside a transaction counts as an additional write.
|
7908 | *
|
7909 | * @param updateFunction
|
7910 | * The function to execute within the transaction context.
|
7911 | *
|
7912 | * @return
|
7913 | * If the transaction completed successfully or was explicitly aborted
|
7914 | * (the `updateFunction` returned a failed promise),
|
7915 | * the promise returned by the updateFunction is returned here. Else, if the
|
7916 | * transaction failed, a rejected promise with the corresponding failure
|
7917 | * error will be returned.
|
7918 | */
|
7919 | runTransaction<T>(
|
7920 | updateFunction: (transaction: Transaction) => Promise<T>
|
7921 | ): Promise<T>;
|
7922 |
|
7923 | /**
|
7924 | * Creates a write batch, used for performing multiple writes as a single
|
7925 | * atomic operation. The maximum number of writes allowed in a single WriteBatch
|
7926 | * is 500, but note that each usage of `FieldValue.serverTimestamp()`,
|
7927 | * `FieldValue.arrayUnion()`, `FieldValue.arrayRemove()`, or
|
7928 | * `FieldValue.increment()` inside a WriteBatch counts as an additional write.
|
7929 | *
|
7930 | * @return
|
7931 | * A `WriteBatch` that can be used to atomically execute multiple writes.
|
7932 | */
|
7933 | batch(): WriteBatch;
|
7934 |
|
7935 | /**
|
7936 | * The {@link firebase.app.App app} associated with this `Firestore` service
|
7937 | * instance.
|
7938 | */
|
7939 | app: firebase.app.App;
|
7940 |
|
7941 | /**
|
7942 | * Clears the persistent storage. This includes pending writes and cached
|
7943 | * documents.
|
7944 | *
|
7945 | * Must be called while the firestore instance is not started (after the app
|
7946 | * is shutdown or when the app is first initialized). On startup, this
|
7947 | * method must be called before other methods (other than settings()). If
|
7948 | * the firestore instance is still running, the promise will be rejected
|
7949 | * with the error code of `failed-precondition`.
|
7950 | *
|
7951 | * Note: clearPersistence() is primarily intended to help write reliable
|
7952 | * tests that use Cloud Firestore. It uses an efficient mechanism for
|
7953 | * dropping existing data but does not attempt to securely overwrite or
|
7954 | * otherwise make cached data unrecoverable. For applications that are
|
7955 | * sensitive to the disclosure of cached data in between user sessions, we
|
7956 | * strongly recommend not enabling persistence at all.
|
7957 | *
|
7958 | * @return A promise that is resolved when the persistent storage is
|
7959 | * cleared. Otherwise, the promise is rejected with an error.
|
7960 | */
|
7961 | clearPersistence(): Promise<void>;
|
7962 |
|
7963 | /**
|
7964 | * Re-enables use of the network for this Firestore instance after a prior
|
7965 | * call to {@link firebase.firestore.Firestore.disableNetwork
|
7966 | * `disableNetwork()`}.
|
7967 | *
|
7968 | * @return A promise that is resolved once the network has been
|
7969 | * enabled.
|
7970 | */
|
7971 | enableNetwork(): Promise<void>;
|
7972 |
|
7973 | /**
|
7974 | * Disables network usage for this instance. It can be re-enabled via
|
7975 | * {@link firebase.firestore.Firestore.enableNetwork `enableNetwork()`}. While
|
7976 | * the network is disabled, any snapshot listeners or get() calls will return
|
7977 | * results from cache, and any write operations will be queued until the network
|
7978 | * is restored.
|
7979 | *
|
7980 | * @return A promise that is resolved once the network has been
|
7981 | * disabled.
|
7982 | */
|
7983 | disableNetwork(): Promise<void>;
|
7984 |
|
7985 | /**
|
7986 | * Waits until all currently pending writes for the active user have been acknowledged by the
|
7987 | * backend.
|
7988 | *
|
7989 | * The returned Promise resolves immediately if there are no outstanding writes. Otherwise, the
|
7990 | * Promise waits for all previously issued writes (including those written in a previous app
|
7991 | * session), but it does not wait for writes that were added after the method is called. If you
|
7992 | * want to wait for additional writes, call `waitForPendingWrites()` again.
|
7993 | *
|
7994 | * Any outstanding `waitForPendingWrites()` Promises are rejected during user changes.
|
7995 | *
|
7996 | * @return A Promise which resolves when all currently pending writes have been
|
7997 | * acknowledged by the backend.
|
7998 | */
|
7999 | waitForPendingWrites(): Promise<void>;
|
8000 |
|
8001 | /**
|
8002 | * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
|
8003 | * event indicates that all listeners affected by a given change have fired,
|
8004 | * even if a single server-generated change affects multiple listeners.
|
8005 | *
|
8006 | * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
|
8007 | * with each other, but does not relate to whether those snapshots are in sync
|
8008 | * with the server. Use SnapshotMetadata in the individual listeners to
|
8009 | * determine if a snapshot is from the cache or the server.
|
8010 | *
|
8011 | * @param observer A single object containing `next` and `error` callbacks.
|
8012 | * @return An unsubscribe function that can be called to cancel the snapshot
|
8013 | * listener.
|
8014 | */
|
8015 | onSnapshotsInSync(observer: {
|
8016 | next?: (value: void) => void;
|
8017 | error?: (error: Error) => void;
|
8018 | complete?: () => void;
|
8019 | }): () => void;
|
8020 |
|
8021 | /**
|
8022 | * Attaches a listener for a snapshots-in-sync event. The snapshots-in-sync
|
8023 | * event indicates that all listeners affected by a given change have fired,
|
8024 | * even if a single server-generated change affects multiple listeners.
|
8025 | *
|
8026 | * NOTE: The snapshots-in-sync event only indicates that listeners are in sync
|
8027 | * with each other, but does not relate to whether those snapshots are in sync
|
8028 | * with the server. Use SnapshotMetadata in the individual listeners to
|
8029 | * determine if a snapshot is from the cache or the server.
|
8030 | *
|
8031 | * @param onSync A callback to be called every time all snapshot listeners are
|
8032 | * in sync with each other.
|
8033 | * @return An unsubscribe function that can be called to cancel the snapshot
|
8034 | * listener.
|
8035 | */
|
8036 | onSnapshotsInSync(onSync: () => void): () => void;
|
8037 |
|
8038 | /**
|
8039 | * Terminates this Firestore instance.
|
8040 | *
|
8041 | * After calling `terminate()` only the `clearPersistence()` method may be used. Any other method
|
8042 | * will throw a `FirestoreError`.
|
8043 | *
|
8044 | * To restart after termination, create a new instance of FirebaseFirestore with
|
8045 | * `firebase.firestore()`.
|
8046 | *
|
8047 | * Termination does not cancel any pending writes, and any promises that are awaiting a response
|
8048 | * from the server will not be resolved. If you have persistence enabled, the next time you
|
8049 | * start this instance, it will resume sending these writes to the server.
|
8050 | *
|
8051 | * Note: Under normal circumstances, calling `terminate()` is not required. This
|
8052 | * method is useful only when you want to force this instance to release all of its resources or
|
8053 | * in combination with `clearPersistence()` to ensure that all local state is destroyed
|
8054 | * between test runs.
|
8055 | *
|
8056 | * @return A promise that is resolved when the instance has been successfully terminated.
|
8057 | */
|
8058 | terminate(): Promise<void>;
|
8059 |
|
8060 | /**
|
8061 | * @hidden
|
8062 | */
|
8063 | INTERNAL: { delete: () => Promise<void> };
|
8064 | }
|
8065 |
|
8066 | /**
|
8067 | * An immutable object representing a geo point in Firestore. The geo point
|
8068 | * is represented as latitude/longitude pair.
|
8069 | *
|
8070 | * Latitude values are in the range of [-90, 90].
|
8071 | * Longitude values are in the range of [-180, 180].
|
8072 | */
|
8073 | export class GeoPoint {
|
8074 | /**
|
8075 | * Creates a new immutable GeoPoint object with the provided latitude and
|
8076 | * longitude values.
|
8077 | * @param latitude The latitude as number between -90 and 90.
|
8078 | * @param longitude The longitude as number between -180 and 180.
|
8079 | */
|
8080 | constructor(latitude: number, longitude: number);
|
8081 |
|
8082 | /**
|
8083 | * The latitude of this GeoPoint instance.
|
8084 | */
|
8085 | readonly latitude: number;
|
8086 | /**
|
8087 | * The longitude of this GeoPoint instance.
|
8088 | */
|
8089 | readonly longitude: number;
|
8090 |
|
8091 | /**
|
8092 | * Returns true if this `GeoPoint` is equal to the provided one.
|
8093 | *
|
8094 | * @param other The `GeoPoint` to compare against.
|
8095 | * @return true if this `GeoPoint` is equal to the provided one.
|
8096 | */
|
8097 | isEqual(other: GeoPoint): boolean;
|
8098 | }
|
8099 |
|
8100 | /**
|
8101 | * A Timestamp represents a point in time independent of any time zone or
|
8102 | * calendar, represented as seconds and fractions of seconds at nanosecond
|
8103 | * resolution in UTC Epoch time.
|
8104 | *
|
8105 | * It is encoded using the Proleptic Gregorian
|
8106 | * Calendar which extends the Gregorian calendar backwards to year one. It is
|
8107 | * encoded assuming all minutes are 60 seconds long, i.e. leap seconds are
|
8108 | * "smeared" so that no leap second table is needed for interpretation. Range is
|
8109 | * from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
|
8110 | *
|
8111 | * @see https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto
|
8112 | */
|
8113 | export class Timestamp {
|
8114 | /**
|
8115 | * Creates a new timestamp.
|
8116 | *
|
8117 | * @param seconds The number of seconds of UTC time since Unix epoch
|
8118 | * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
|
8119 | * 9999-12-31T23:59:59Z inclusive.
|
8120 | * @param nanoseconds The non-negative fractions of a second at nanosecond
|
8121 | * resolution. Negative second values with fractions must still have
|
8122 | * non-negative nanoseconds values that count forward in time. Must be
|
8123 | * from 0 to 999,999,999 inclusive.
|
8124 | */
|
8125 | constructor(seconds: number, nanoseconds: number);
|
8126 |
|
8127 | /**
|
8128 | * Creates a new timestamp with the current date, with millisecond precision.
|
8129 | *
|
8130 | * @return a new timestamp representing the current date.
|
8131 | */
|
8132 | static now(): Timestamp;
|
8133 |
|
8134 | /**
|
8135 | * Creates a new timestamp from the given date.
|
8136 | *
|
8137 | * @param date The date to initialize the `Timestamp` from.
|
8138 | * @return A new `Timestamp` representing the same point in time as the given
|
8139 | * date.
|
8140 | */
|
8141 | static fromDate(date: Date): Timestamp;
|
8142 |
|
8143 | /**
|
8144 | * Creates a new timestamp from the given number of milliseconds.
|
8145 | *
|
8146 | * @param milliseconds Number of milliseconds since Unix epoch
|
8147 | * 1970-01-01T00:00:00Z.
|
8148 | * @return A new `Timestamp` representing the same point in time as the given
|
8149 | * number of milliseconds.
|
8150 | */
|
8151 | static fromMillis(milliseconds: number): Timestamp;
|
8152 |
|
8153 | readonly seconds: number;
|
8154 | readonly nanoseconds: number;
|
8155 |
|
8156 | /**
|
8157 | * Convert a Timestamp to a JavaScript `Date` object. This conversion causes
|
8158 | * a loss of precision since `Date` objects only support millisecond precision.
|
8159 | *
|
8160 | * @return JavaScript `Date` object representing the same point in time as
|
8161 | * this `Timestamp`, with millisecond precision.
|
8162 | */
|
8163 | toDate(): Date;
|
8164 |
|
8165 | /**
|
8166 | * Convert a timestamp to a numeric timestamp (in milliseconds since epoch).
|
8167 | * This operation causes a loss of precision.
|
8168 | *
|
8169 | * @return The point in time corresponding to this timestamp, represented as
|
8170 | * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
|
8171 | */
|
8172 | toMillis(): number;
|
8173 |
|
8174 | /**
|
8175 | * Returns true if this `Timestamp` is equal to the provided one.
|
8176 | *
|
8177 | * @param other The `Timestamp` to compare against.
|
8178 | * @return true if this `Timestamp` is equal to the provided one.
|
8179 | */
|
8180 | isEqual(other: Timestamp): boolean;
|
8181 |
|
8182 | /**
|
8183 | * Converts this object to a primitive string, which allows Timestamp objects to be compared
|
8184 | * using the `>`, `<=`, `>=` and `>` operators.
|
8185 | */
|
8186 | valueOf(): string;
|
8187 | }
|
8188 |
|
8189 | /**
|
8190 | * An immutable object representing an array of bytes.
|
8191 | */
|
8192 | export class Blob {
|
8193 | private constructor();
|
8194 |
|
8195 | /**
|
8196 | * Creates a new Blob from the given Base64 string, converting it to
|
8197 | * bytes.
|
8198 | *
|
8199 | * @param base64
|
8200 | * The Base64 string used to create the Blob object.
|
8201 | */
|
8202 | static fromBase64String(base64: string): Blob;
|
8203 |
|
8204 | /**
|
8205 | * Creates a new Blob from the given Uint8Array.
|
8206 | *
|
8207 | * @param array
|
8208 | * The Uint8Array used to create the Blob object.
|
8209 | */
|
8210 | static fromUint8Array(array: Uint8Array): Blob;
|
8211 |
|
8212 | /**
|
8213 | * Returns the bytes of a Blob as a Base64-encoded string.
|
8214 | *
|
8215 | * @return
|
8216 | * The Base64-encoded string created from the Blob object.
|
8217 | */
|
8218 | public toBase64(): string;
|
8219 |
|
8220 | /**
|
8221 | * Returns the bytes of a Blob in a new Uint8Array.
|
8222 | *
|
8223 | * @return
|
8224 | * The Uint8Array created from the Blob object.
|
8225 | */
|
8226 | public toUint8Array(): Uint8Array;
|
8227 |
|
8228 | /**
|
8229 | * Returns true if this `Blob` is equal to the provided one.
|
8230 | *
|
8231 | * @param other The `Blob` to compare against.
|
8232 | * @return true if this `Blob` is equal to the provided one.
|
8233 | */
|
8234 | isEqual(other: Blob): boolean;
|
8235 | }
|
8236 |
|
8237 | /**
|
8238 | * A reference to a transaction.
|
8239 | * The `Transaction` object passed to a transaction's updateFunction provides
|
8240 | * the methods to read and write data within the transaction context. See
|
8241 | * `Firestore.runTransaction()`.
|
8242 | */
|
8243 | export class Transaction {
|
8244 | private constructor();
|
8245 |
|
8246 | /**
|
8247 | * Reads the document referenced by the provided `DocumentReference.`
|
8248 | *
|
8249 | * @param documentRef A reference to the document to be read.
|
8250 | * @return A DocumentSnapshot for the read data.
|
8251 | */
|
8252 | get<T>(documentRef: DocumentReference<T>): Promise<DocumentSnapshot<T>>;
|
8253 |
|
8254 | /**
|
8255 | * Writes to the document referred to by the provided `DocumentReference`.
|
8256 | * If the document does not exist yet, it will be created. If you pass
|
8257 | * `SetOptions`, the provided data can be merged into the existing document.
|
8258 | *
|
8259 | * @param documentRef A reference to the document to be set.
|
8260 | * @param data An object of the fields and values for the document.
|
8261 | * @param options An object to configure the set behavior.
|
8262 | * @return This `Transaction` instance. Used for chaining method calls.
|
8263 | */
|
8264 | set<T>(
|
8265 | documentRef: DocumentReference<T>,
|
8266 | data: T,
|
8267 | options?: SetOptions
|
8268 | ): Transaction;
|
8269 |
|
8270 | /**
|
8271 | * Updates fields in the document referred to by the provided
|
8272 | * `DocumentReference`. The update will fail if applied to a document that
|
8273 | * does not exist.
|
8274 | *
|
8275 | * @param documentRef A reference to the document to be updated.
|
8276 | * @param data An object containing the fields and values with which to
|
8277 | * update the document. Fields can contain dots to reference nested fields
|
8278 | * within the document.
|
8279 | * @return This `Transaction` instance. Used for chaining method calls.
|
8280 | */
|
8281 | update(documentRef: DocumentReference<any>, data: UpdateData): Transaction;
|
8282 |
|
8283 | /**
|
8284 | * Updates fields in the document referred to by the provided
|
8285 | * `DocumentReference`. The update will fail if applied to a document that
|
8286 | * does not exist.
|
8287 | *
|
8288 | * Nested fields can be updated by providing dot-separated field path
|
8289 | * strings or by providing FieldPath objects.
|
8290 | *
|
8291 | * @param documentRef A reference to the document to be updated.
|
8292 | * @param field The first field to update.
|
8293 | * @param value The first value.
|
8294 | * @param moreFieldsAndValues Additional key/value pairs.
|
8295 | * @return A Promise resolved once the data has been successfully written
|
8296 | * to the backend (Note that it won't resolve while you're offline).
|
8297 | */
|
8298 | update(
|
8299 | documentRef: DocumentReference<any>,
|
8300 | field: string | FieldPath,
|
8301 | value: any,
|
8302 | ...moreFieldsAndValues: any[]
|
8303 | ): Transaction;
|
8304 |
|
8305 | /**
|
8306 | * Deletes the document referred to by the provided `DocumentReference`.
|
8307 | *
|
8308 | * @param documentRef A reference to the document to be deleted.
|
8309 | * @return This `Transaction` instance. Used for chaining method calls.
|
8310 | */
|
8311 | delete(documentRef: DocumentReference<any>): Transaction;
|
8312 | }
|
8313 |
|
8314 | /**
|
8315 | * A write batch, used to perform multiple writes as a single atomic unit.
|
8316 | *
|
8317 | * A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It
|
8318 | * provides methods for adding writes to the write batch. None of the
|
8319 | * writes will be committed (or visible locally) until `WriteBatch.commit()`
|
8320 | * is called.
|
8321 | *
|
8322 | * Unlike transactions, write batches are persisted offline and therefore are
|
8323 | * preferable when you don't need to condition your writes on read data.
|
8324 | */
|
8325 | export class WriteBatch {
|
8326 | private constructor();
|
8327 |
|
8328 | /**
|
8329 | * Writes to the document referred to by the provided `DocumentReference`.
|
8330 | * If the document does not exist yet, it will be created. If you pass
|
8331 | * `SetOptions`, the provided data can be merged into the existing document.
|
8332 | *
|
8333 | * @param documentRef A reference to the document to be set.
|
8334 | * @param data An object of the fields and values for the document.
|
8335 | * @param options An object to configure the set behavior.
|
8336 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
8337 | */
|
8338 | set<T>(
|
8339 | documentRef: DocumentReference<T>,
|
8340 | data: T,
|
8341 | options?: SetOptions
|
8342 | ): WriteBatch;
|
8343 |
|
8344 | /**
|
8345 | * Updates fields in the document referred to by the provided
|
8346 | * `DocumentReference`. The update will fail if applied to a document that
|
8347 | * does not exist.
|
8348 | *
|
8349 | * @param documentRef A reference to the document to be updated.
|
8350 | * @param data An object containing the fields and values with which to
|
8351 | * update the document. Fields can contain dots to reference nested fields
|
8352 | * within the document.
|
8353 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
8354 | */
|
8355 | update(documentRef: DocumentReference<any>, data: UpdateData): WriteBatch;
|
8356 |
|
8357 | /**
|
8358 | * Updates fields in the document referred to by this `DocumentReference`.
|
8359 | * The update will fail if applied to a document that does not exist.
|
8360 | *
|
8361 | * Nested fields can be update by providing dot-separated field path strings
|
8362 | * or by providing FieldPath objects.
|
8363 | *
|
8364 | * @param documentRef A reference to the document to be updated.
|
8365 | * @param field The first field to update.
|
8366 | * @param value The first value.
|
8367 | * @param moreFieldsAndValues Additional key value pairs.
|
8368 | * @return A Promise resolved once the data has been successfully written
|
8369 | * to the backend (Note that it won't resolve while you're offline).
|
8370 | */
|
8371 | update(
|
8372 | documentRef: DocumentReference<any>,
|
8373 | field: string | FieldPath,
|
8374 | value: any,
|
8375 | ...moreFieldsAndValues: any[]
|
8376 | ): WriteBatch;
|
8377 |
|
8378 | /**
|
8379 | * Deletes the document referred to by the provided `DocumentReference`.
|
8380 | *
|
8381 | * @param documentRef A reference to the document to be deleted.
|
8382 | * @return This `WriteBatch` instance. Used for chaining method calls.
|
8383 | */
|
8384 | delete(documentRef: DocumentReference<any>): WriteBatch;
|
8385 |
|
8386 | /**
|
8387 | * Commits all of the writes in this write batch as a single atomic unit.
|
8388 | *
|
8389 | * @return A Promise resolved once all of the writes in the batch have been
|
8390 | * successfully written to the backend as an atomic unit. Note that it won't
|
8391 | * resolve while you're offline.
|
8392 | */
|
8393 | commit(): Promise<void>;
|
8394 | }
|
8395 |
|
8396 | /**
|
8397 | * An options object that can be passed to `DocumentReference.onSnapshot()`,
|
8398 | * `Query.onSnapshot()` and `QuerySnapshot.docChanges()` to control which
|
8399 | * types of changes to include in the result set.
|
8400 | */
|
8401 | export interface SnapshotListenOptions {
|
8402 | /**
|
8403 | * Include a change even if only the metadata of the query or of a document
|
8404 | * changed. Default is false.
|
8405 | */
|
8406 | readonly includeMetadataChanges?: boolean;
|
8407 | }
|
8408 |
|
8409 | /**
|
8410 | * An options object that configures the behavior of `set()` calls in
|
8411 | * {@link firebase.firestore.DocumentReference.set DocumentReference}, {@link
|
8412 | * firebase.firestore.WriteBatch.set WriteBatch} and {@link
|
8413 | * firebase.firestore.Transaction.set Transaction}. These calls can be
|
8414 | * configured to perform granular merges instead of overwriting the target
|
8415 | * documents in their entirety by providing a `SetOptions` with `merge: true`.
|
8416 | */
|
8417 | export interface SetOptions {
|
8418 | /**
|
8419 | * Changes the behavior of a set() call to only replace the values specified
|
8420 | * in its data argument. Fields omitted from the set() call remain
|
8421 | * untouched.
|
8422 | */
|
8423 | readonly merge?: boolean;
|
8424 |
|
8425 | /**
|
8426 | * Changes the behavior of set() calls to only replace the specified field
|
8427 | * paths. Any field path that is not specified is ignored and remains
|
8428 | * untouched.
|
8429 | */
|
8430 | readonly mergeFields?: (string | FieldPath)[];
|
8431 | }
|
8432 |
|
8433 | /**
|
8434 | * An options object that configures the behavior of `get()` calls on
|
8435 | * `DocumentReference` and `Query`. By providing a `GetOptions` object, these
|
8436 | * methods can be configured to fetch results only from the server, only from
|
8437 | * the local cache or attempt to fetch results from the server and fall back to
|
8438 | * the cache (which is the default).
|
8439 | */
|
8440 | export interface GetOptions {
|
8441 | /**
|
8442 | * Describes whether we should get from server or cache.
|
8443 | *
|
8444 | * Setting to `default` (or not setting at all), causes Firestore to try to
|
8445 | * retrieve an up-to-date (server-retrieved) snapshot, but fall back to
|
8446 | * returning cached data if the server can't be reached.
|
8447 | *
|
8448 | * Setting to `server` causes Firestore to avoid the cache, generating an
|
8449 | * error if the server cannot be reached. Note that the cache will still be
|
8450 | * updated if the server request succeeds. Also note that latency-compensation
|
8451 | * still takes effect, so any pending write operations will be visible in the
|
8452 | * returned data (merged into the server-provided data).
|
8453 | *
|
8454 | * Setting to `cache` causes Firestore to immediately return a value from the
|
8455 | * cache, ignoring the server completely (implying that the returned value
|
8456 | * may be stale with respect to the value on the server.) If there is no data
|
8457 | * in the cache to satisfy the `get()` call, `DocumentReference.get()` will
|
8458 | * return an error and `QuerySnapshot.get()` will return an empty
|
8459 | * `QuerySnapshot` with no documents.
|
8460 | */
|
8461 | readonly source?: 'default' | 'server' | 'cache';
|
8462 | }
|
8463 |
|
8464 | /**
|
8465 | * A `DocumentReference` refers to a document location in a Firestore database
|
8466 | * and can be used to write, read, or listen to the location. The document at
|
8467 | * the referenced location may or may not exist. A `DocumentReference` can
|
8468 | * also be used to create a `CollectionReference` to a subcollection.
|
8469 | */
|
8470 | export class DocumentReference<T = DocumentData> {
|
8471 | private constructor();
|
8472 |
|
8473 | /**
|
8474 | * The document's identifier within its collection.
|
8475 | */
|
8476 | readonly id: string;
|
8477 |
|
8478 | /**
|
8479 | * The {@link firebase.firestore.Firestore} the document is in.
|
8480 | * This is useful for performing transactions, for example.
|
8481 | */
|
8482 | readonly firestore: Firestore;
|
8483 |
|
8484 | /**
|
8485 | * The Collection this `DocumentReference` belongs to.
|
8486 | */
|
8487 | readonly parent: CollectionReference<T>;
|
8488 |
|
8489 | /**
|
8490 | * A string representing the path of the referenced document (relative
|
8491 | * to the root of the database).
|
8492 | */
|
8493 | readonly path: string;
|
8494 |
|
8495 | /**
|
8496 | * Gets a `CollectionReference` instance that refers to the collection at
|
8497 | * the specified path.
|
8498 | *
|
8499 | * @param collectionPath A slash-separated path to a collection.
|
8500 | * @return The `CollectionReference` instance.
|
8501 | */
|
8502 | collection(collectionPath: string): CollectionReference<DocumentData>;
|
8503 |
|
8504 | /**
|
8505 | * Returns true if this `DocumentReference` is equal to the provided one.
|
8506 | *
|
8507 | * @param other The `DocumentReference` to compare against.
|
8508 | * @return true if this `DocumentReference` is equal to the provided one.
|
8509 | */
|
8510 | isEqual(other: DocumentReference<T>): boolean;
|
8511 |
|
8512 | /**
|
8513 | * Writes to the document referred to by this `DocumentReference`. If the
|
8514 | * document does not yet exist, it will be created. If you pass
|
8515 | * `SetOptions`, the provided data can be merged into an existing document.
|
8516 | *
|
8517 | * @param data A map of the fields and values for the document.
|
8518 | * @param options An object to configure the set behavior.
|
8519 | * @return A Promise resolved once the data has been successfully written
|
8520 | * to the backend (Note that it won't resolve while you're offline).
|
8521 | */
|
8522 | set(data: T, options?: SetOptions): Promise<void>;
|
8523 |
|
8524 | /**
|
8525 | * Updates fields in the document referred to by this `DocumentReference`.
|
8526 | * The update will fail if applied to a document that does not exist.
|
8527 | *
|
8528 | * @param data An object containing the fields and values with which to
|
8529 | * update the document. Fields can contain dots to reference nested fields
|
8530 | * within the document.
|
8531 | * @return A Promise resolved once the data has been successfully written
|
8532 | * to the backend (Note that it won't resolve while you're offline).
|
8533 | */
|
8534 | update(data: UpdateData): Promise<void>;
|
8535 |
|
8536 | /**
|
8537 | * Updates fields in the document referred to by this `DocumentReference`.
|
8538 | * The update will fail if applied to a document that does not exist.
|
8539 | *
|
8540 | * Nested fields can be updated by providing dot-separated field path
|
8541 | * strings or by providing FieldPath objects.
|
8542 | *
|
8543 | * @param field The first field to update.
|
8544 | * @param value The first value.
|
8545 | * @param moreFieldsAndValues Additional key value pairs.
|
8546 | * @return A Promise resolved once the data has been successfully written
|
8547 | * to the backend (Note that it won't resolve while you're offline).
|
8548 | */
|
8549 | update(
|
8550 | field: string | FieldPath,
|
8551 | value: any,
|
8552 | ...moreFieldsAndValues: any[]
|
8553 | ): Promise<void>;
|
8554 |
|
8555 | /**
|
8556 | * Deletes the document referred to by this `DocumentReference`.
|
8557 | *
|
8558 | * @return A Promise resolved once the document has been successfully
|
8559 | * deleted from the backend (Note that it won't resolve while you're
|
8560 | * offline).
|
8561 | */
|
8562 | delete(): Promise<void>;
|
8563 |
|
8564 | /**
|
8565 | * Reads the document referred to by this `DocumentReference`.
|
8566 | *
|
8567 | * Note: By default, get() attempts to provide up-to-date data when possible
|
8568 | * by waiting for data from the server, but it may return cached data or fail
|
8569 | * if you are offline and the server cannot be reached. This behavior can be
|
8570 | * altered via the `GetOptions` parameter.
|
8571 | *
|
8572 | * @param options An object to configure the get behavior.
|
8573 | * @return A Promise resolved with a DocumentSnapshot containing the
|
8574 | * current document contents.
|
8575 | */
|
8576 | get(options?: GetOptions): Promise<DocumentSnapshot<T>>;
|
8577 |
|
8578 | /**
|
8579 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
8580 | * individual `onNext` and `onError` callbacks or pass a single observer
|
8581 | * object with `next` and `error` callbacks.
|
8582 | *
|
8583 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
8584 | * never be called because the snapshot stream is never-ending.
|
8585 | *
|
8586 | * @param observer A single object containing `next` and `error` callbacks.
|
8587 | * @return An unsubscribe function that can be called to cancel
|
8588 | * the snapshot listener.
|
8589 | */
|
8590 | onSnapshot(observer: {
|
8591 | next?: (snapshot: DocumentSnapshot<T>) => void;
|
8592 | error?: (error: FirestoreError) => void;
|
8593 | complete?: () => void;
|
8594 | }): () => void;
|
8595 | /**
|
8596 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
8597 | * individual `onNext` and `onError` callbacks or pass a single observer
|
8598 | * object with `next` and `error` callbacks.
|
8599 | *
|
8600 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
8601 | * never be called because the snapshot stream is never-ending.
|
8602 | *
|
8603 | * @param options Options controlling the listen behavior.
|
8604 | * @param observer A single object containing `next` and `error` callbacks.
|
8605 | * @return An unsubscribe function that can be called to cancel
|
8606 | * the snapshot listener.
|
8607 | */
|
8608 | onSnapshot(
|
8609 | options: SnapshotListenOptions,
|
8610 | observer: {
|
8611 | next?: (snapshot: DocumentSnapshot<T>) => void;
|
8612 | error?: (error: Error) => void;
|
8613 | complete?: () => void;
|
8614 | }
|
8615 | ): () => void;
|
8616 | /**
|
8617 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
8618 | * individual `onNext` and `onError` callbacks or pass a single observer
|
8619 | * object with `next` and `error` callbacks.
|
8620 | *
|
8621 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
8622 | * never be called because the snapshot stream is never-ending.
|
8623 | *
|
8624 | * @param onNext A callback to be called every time a new `DocumentSnapshot`
|
8625 | * is available.
|
8626 | * @param onError A callback to be called if the listen fails or is
|
8627 | * cancelled. No further callbacks will occur.
|
8628 | * @return An unsubscribe function that can be called to cancel
|
8629 | * the snapshot listener.
|
8630 | */
|
8631 | onSnapshot(
|
8632 | onNext: (snapshot: DocumentSnapshot<T>) => void,
|
8633 | onError?: (error: Error) => void,
|
8634 | onCompletion?: () => void
|
8635 | ): () => void;
|
8636 | /**
|
8637 | * Attaches a listener for DocumentSnapshot events. You may either pass
|
8638 | * individual `onNext` and `onError` callbacks or pass a single observer
|
8639 | * object with `next` and `error` callbacks.
|
8640 | *
|
8641 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
8642 | * never be called because the snapshot stream is never-ending.
|
8643 | *
|
8644 | * @param options Options controlling the listen behavior.
|
8645 | * @param onNext A callback to be called every time a new `DocumentSnapshot`
|
8646 | * is available.
|
8647 | * @param onError A callback to be called if the listen fails or is
|
8648 | * cancelled. No further callbacks will occur.
|
8649 | * @return An unsubscribe function that can be called to cancel
|
8650 | * the snapshot listener.
|
8651 | */
|
8652 | onSnapshot(
|
8653 | options: SnapshotListenOptions,
|
8654 | onNext: (snapshot: DocumentSnapshot<T>) => void,
|
8655 | onError?: (error: Error) => void,
|
8656 | onCompletion?: () => void
|
8657 | ): () => void;
|
8658 |
|
8659 | /**
|
8660 | * Applies a custom data converter to this DocumentReference, allowing you
|
8661 | * to use your own custom model objects with Firestore. When you call
|
8662 | * set(), get(), etc. on the returned DocumentReference instance, the
|
8663 | * provided converter will convert between Firestore data and your custom
|
8664 | * type U.
|
8665 | *
|
8666 | * @param converter Converts objects to and from Firestore.
|
8667 | * @return A DocumentReference<U> that uses the provided converter.
|
8668 | */
|
8669 | withConverter<U>(
|
8670 | converter: FirestoreDataConverter<U>
|
8671 | ): DocumentReference<U>;
|
8672 | }
|
8673 |
|
8674 | /**
|
8675 | * Options that configure how data is retrieved from a `DocumentSnapshot`
|
8676 | * (e.g. the desired behavior for server timestamps that have not yet been set
|
8677 | * to their final value).
|
8678 | */
|
8679 | export interface SnapshotOptions {
|
8680 | /**
|
8681 | * If set, controls the return value for server timestamps that have not yet
|
8682 | * been set to their final value.
|
8683 | *
|
8684 | * By specifying 'estimate', pending server timestamps return an estimate
|
8685 | * based on the local clock. This estimate will differ from the final value
|
8686 | * and cause these values to change once the server result becomes available.
|
8687 | *
|
8688 | * By specifying 'previous', pending timestamps will be ignored and return
|
8689 | * their previous value instead.
|
8690 | *
|
8691 | * If omitted or set to 'none', `null` will be returned by default until the
|
8692 | * server value becomes available.
|
8693 | */
|
8694 | readonly serverTimestamps?: 'estimate' | 'previous' | 'none';
|
8695 | }
|
8696 |
|
8697 | /**
|
8698 | * Metadata about a snapshot, describing the state of the snapshot.
|
8699 | */
|
8700 | export interface SnapshotMetadata {
|
8701 | /**
|
8702 | * True if the snapshot contains the result of local writes (e.g. set() or
|
8703 | * update() calls) that have not yet been committed to the backend.
|
8704 | * If your listener has opted into metadata updates (via
|
8705 | * `SnapshotListenOptions`) you will receive another
|
8706 | * snapshot with `hasPendingWrites` equal to false once the writes have been
|
8707 | * committed to the backend.
|
8708 | */
|
8709 | readonly hasPendingWrites: boolean;
|
8710 |
|
8711 | /**
|
8712 | * True if the snapshot was created from cached data rather than guaranteed
|
8713 | * up-to-date server data. If your listener has opted into metadata updates
|
8714 | * (via `SnapshotListenOptions`)
|
8715 | * you will receive another snapshot with `fromCache` set to false once
|
8716 | * the client has received up-to-date data from the backend.
|
8717 | */
|
8718 | readonly fromCache: boolean;
|
8719 |
|
8720 | /**
|
8721 | * Returns true if this `SnapshotMetadata` is equal to the provided one.
|
8722 | *
|
8723 | * @param other The `SnapshotMetadata` to compare against.
|
8724 | * @return true if this `SnapshotMetadata` is equal to the provided one.
|
8725 | */
|
8726 | isEqual(other: SnapshotMetadata): boolean;
|
8727 | }
|
8728 |
|
8729 | /**
|
8730 | * A `DocumentSnapshot` contains data read from a document in your Firestore
|
8731 | * database. The data can be extracted with `.data()` or `.get(<field>)` to
|
8732 | * get a specific field.
|
8733 | *
|
8734 | * For a `DocumentSnapshot` that points to a non-existing document, any data
|
8735 | * access will return 'undefined'. You can use the `exists` property to
|
8736 | * explicitly verify a document's existence.
|
8737 | */
|
8738 | export class DocumentSnapshot<T = DocumentData> {
|
8739 | protected constructor();
|
8740 |
|
8741 | /**
|
8742 | * Property of the `DocumentSnapshot` that signals whether or not the data
|
8743 | * exists. True if the document exists.
|
8744 | */
|
8745 | readonly exists: boolean;
|
8746 | /**
|
8747 | * The `DocumentReference` for the document included in the `DocumentSnapshot`.
|
8748 | */
|
8749 | readonly ref: DocumentReference<T>;
|
8750 | /**
|
8751 | * Property of the `DocumentSnapshot` that provides the document's ID.
|
8752 | */
|
8753 | readonly id: string;
|
8754 | /**
|
8755 | * Metadata about the `DocumentSnapshot`, including information about its
|
8756 | * source and local modifications.
|
8757 | */
|
8758 | readonly metadata: SnapshotMetadata;
|
8759 |
|
8760 | /**
|
8761 | * Retrieves all fields in the document as an Object. Returns 'undefined' if
|
8762 | * the document doesn't exist.
|
8763 | *
|
8764 | * By default, `FieldValue.serverTimestamp()` values that have not yet been
|
8765 | * set to their final value will be returned as `null`. You can override
|
8766 | * this by passing an options object.
|
8767 | *
|
8768 | * @param options An options object to configure how data is retrieved from
|
8769 | * the snapshot (e.g. the desired behavior for server timestamps that have
|
8770 | * not yet been set to their final value).
|
8771 | * @return An Object containing all fields in the document or 'undefined' if
|
8772 | * the document doesn't exist.
|
8773 | */
|
8774 | data(options?: SnapshotOptions): T | undefined;
|
8775 |
|
8776 | /**
|
8777 | * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
|
8778 | * document or field doesn't exist.
|
8779 | *
|
8780 | * By default, a `FieldValue.serverTimestamp()` that has not yet been set to
|
8781 | * its final value will be returned as `null`. You can override this by
|
8782 | * passing an options object.
|
8783 | *
|
8784 | * @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field.
|
8785 | * @param options An options object to configure how the field is retrieved
|
8786 | * from the snapshot (e.g. the desired behavior for server timestamps that have
|
8787 | * not yet been set to their final value).
|
8788 | * @return The data at the specified field location or undefined if no such
|
8789 | * field exists in the document.
|
8790 | */
|
8791 | get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
|
8792 |
|
8793 | /**
|
8794 | * Returns true if this `DocumentSnapshot` is equal to the provided one.
|
8795 | *
|
8796 | * @param other The `DocumentSnapshot` to compare against.
|
8797 | * @return true if this `DocumentSnapshot` is equal to the provided one.
|
8798 | */
|
8799 | isEqual(other: DocumentSnapshot<T>): boolean;
|
8800 | }
|
8801 |
|
8802 | /**
|
8803 | * A `QueryDocumentSnapshot` contains data read from a document in your
|
8804 | * Firestore database as part of a query. The document is guaranteed to exist
|
8805 | * and its data can be extracted with `.data()` or `.get(<field>)` to get a
|
8806 | * specific field.
|
8807 | *
|
8808 | * A `QueryDocumentSnapshot` offers the same API surface as a
|
8809 | * `DocumentSnapshot`. Since query results contain only existing documents, the
|
8810 | * `exists` property will always be true and `data()` will never return
|
8811 | * 'undefined'.
|
8812 | */
|
8813 | export class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<
|
8814 | T
|
8815 | > {
|
8816 | private constructor();
|
8817 |
|
8818 | /**
|
8819 | * Retrieves all fields in the document as an Object.
|
8820 | *
|
8821 | * By default, `FieldValue.serverTimestamp()` values that have not yet been
|
8822 | * set to their final value will be returned as `null`. You can override
|
8823 | * this by passing an options object.
|
8824 | *
|
8825 | * @override
|
8826 | * @param options An options object to configure how data is retrieved from
|
8827 | * the snapshot (e.g. the desired behavior for server timestamps that have
|
8828 | * not yet been set to their final value).
|
8829 | * @return An Object containing all fields in the document.
|
8830 | */
|
8831 | data(options?: SnapshotOptions): T;
|
8832 | }
|
8833 |
|
8834 | /**
|
8835 | * The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc'
|
8836 | * (descending or ascending).
|
8837 | */
|
8838 | export type OrderByDirection = 'desc' | 'asc';
|
8839 |
|
8840 | /**
|
8841 | * Filter conditions in a `Query.where()` clause are specified using the
|
8842 | * strings '<', '<=', '==', '>=', '>', 'array-contains', 'in', and 'array-contains-any'.
|
8843 | */
|
8844 | export type WhereFilterOp =
|
8845 | | '<'
|
8846 | | '<='
|
8847 | | '=='
|
8848 | | '>='
|
8849 | | '>'
|
8850 | | 'array-contains'
|
8851 | | 'in'
|
8852 | | 'array-contains-any';
|
8853 |
|
8854 | /**
|
8855 | * A `Query` refers to a Query which you can read or listen to. You can also
|
8856 | * construct refined `Query` objects by adding filters and ordering.
|
8857 | */
|
8858 | export class Query<T = DocumentData> {
|
8859 | protected constructor();
|
8860 |
|
8861 | /**
|
8862 | * The `Firestore` for the Firestore database (useful for performing
|
8863 | * transactions, etc.).
|
8864 | */
|
8865 | readonly firestore: Firestore;
|
8866 |
|
8867 | /**
|
8868 | * Creates and returns a new Query with the additional filter that documents
|
8869 | * must contain the specified field and the value should satisfy the
|
8870 | * relation constraint provided.
|
8871 | *
|
8872 | * @param fieldPath The path to compare
|
8873 | * @param opStr The operation string (e.g "<", "<=", "==", ">", ">=").
|
8874 | * @param value The value for comparison
|
8875 | * @return The created Query.
|
8876 | */
|
8877 | where(
|
8878 | fieldPath: string | FieldPath,
|
8879 | opStr: WhereFilterOp,
|
8880 | value: any
|
8881 | ): Query<T>;
|
8882 |
|
8883 | /**
|
8884 | * Creates and returns a new Query that's additionally sorted by the
|
8885 | * specified field, optionally in descending order instead of ascending.
|
8886 | *
|
8887 | * @param fieldPath The field to sort by.
|
8888 | * @param directionStr Optional direction to sort by (`asc` or `desc`). If
|
8889 | * not specified, order will be ascending.
|
8890 | * @return The created Query.
|
8891 | */
|
8892 | orderBy(
|
8893 | fieldPath: string | FieldPath,
|
8894 | directionStr?: OrderByDirection
|
8895 | ): Query<T>;
|
8896 |
|
8897 | /**
|
8898 | * Creates and returns a new Query that only returns the first matching
|
8899 | * documents.
|
8900 | *
|
8901 | * @param limit The maximum number of items to return.
|
8902 | * @return The created Query.
|
8903 | */
|
8904 | limit(limit: number): Query<T>;
|
8905 |
|
8906 | /**
|
8907 | * Creates and returns a new Query that only returns the last matching
|
8908 | * documents.
|
8909 | *
|
8910 | * You must specify at least one `orderBy` clause for `limitToLast` queries,
|
8911 | * otherwise an exception will be thrown during execution.
|
8912 | *
|
8913 | * @param limit The maximum number of items to return.
|
8914 | * @return The created Query.
|
8915 | */
|
8916 | limitToLast(limit: number): Query<T>;
|
8917 |
|
8918 | /**
|
8919 | * Creates and returns a new Query that starts at the provided document
|
8920 | * (inclusive). The starting position is relative to the order of the query.
|
8921 | * The document must contain all of the fields provided in the `orderBy` of
|
8922 | * this query.
|
8923 | *
|
8924 | * @param snapshot The snapshot of the document to start at.
|
8925 | * @return The created Query.
|
8926 | */
|
8927 | startAt(snapshot: DocumentSnapshot<any>): Query<T>;
|
8928 |
|
8929 | /**
|
8930 | * Creates and returns a new Query that starts at the provided fields
|
8931 | * relative to the order of the query. The order of the field values
|
8932 | * must match the order of the order by clauses of the query.
|
8933 | *
|
8934 | * @param fieldValues The field values to start this query at, in order
|
8935 | * of the query's order by.
|
8936 | * @return The created Query.
|
8937 | */
|
8938 | startAt(...fieldValues: any[]): Query<T>;
|
8939 |
|
8940 | /**
|
8941 | * Creates and returns a new Query that starts after the provided document
|
8942 | * (exclusive). The starting position is relative to the order of the query.
|
8943 | * The document must contain all of the fields provided in the orderBy of
|
8944 | * this query.
|
8945 | *
|
8946 | * @param snapshot The snapshot of the document to start after.
|
8947 | * @return The created Query.
|
8948 | */
|
8949 | startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
|
8950 |
|
8951 | /**
|
8952 | * Creates and returns a new Query that starts after the provided fields
|
8953 | * relative to the order of the query. The order of the field values
|
8954 | * must match the order of the order by clauses of the query.
|
8955 | *
|
8956 | * @param fieldValues The field values to start this query after, in order
|
8957 | * of the query's order by.
|
8958 | * @return The created Query.
|
8959 | */
|
8960 | startAfter(...fieldValues: any[]): Query<T>;
|
8961 |
|
8962 | /**
|
8963 | * Creates and returns a new Query that ends before the provided document
|
8964 | * (exclusive). The end position is relative to the order of the query. The
|
8965 | * document must contain all of the fields provided in the orderBy of this
|
8966 | * query.
|
8967 | *
|
8968 | * @param snapshot The snapshot of the document to end before.
|
8969 | * @return The created Query.
|
8970 | */
|
8971 | endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
|
8972 |
|
8973 | /**
|
8974 | * Creates and returns a new Query that ends before the provided fields
|
8975 | * relative to the order of the query. The order of the field values
|
8976 | * must match the order of the order by clauses of the query.
|
8977 | *
|
8978 | * @param fieldValues The field values to end this query before, in order
|
8979 | * of the query's order by.
|
8980 | * @return The created Query.
|
8981 | */
|
8982 | endBefore(...fieldValues: any[]): Query<T>;
|
8983 |
|
8984 | /**
|
8985 | * Creates and returns a new Query that ends at the provided document
|
8986 | * (inclusive). The end position is relative to the order of the query. The
|
8987 | * document must contain all of the fields provided in the orderBy of this
|
8988 | * query.
|
8989 | *
|
8990 | * @param snapshot The snapshot of the document to end at.
|
8991 | * @return The created Query.
|
8992 | */
|
8993 | endAt(snapshot: DocumentSnapshot<any>): Query<T>;
|
8994 |
|
8995 | /**
|
8996 | * Creates and returns a new Query that ends at the provided fields
|
8997 | * relative to the order of the query. The order of the field values
|
8998 | * must match the order of the order by clauses of the query.
|
8999 | *
|
9000 | * @param fieldValues The field values to end this query at, in order
|
9001 | * of the query's order by.
|
9002 | * @return The created Query.
|
9003 | */
|
9004 | endAt(...fieldValues: any[]): Query<T>;
|
9005 |
|
9006 | /**
|
9007 | * Returns true if this `Query` is equal to the provided one.
|
9008 | *
|
9009 | * @param other The `Query` to compare against.
|
9010 | * @return true if this `Query` is equal to the provided one.
|
9011 | */
|
9012 | isEqual(other: Query<T>): boolean;
|
9013 |
|
9014 | /**
|
9015 | * Executes the query and returns the results as a `QuerySnapshot`.
|
9016 | *
|
9017 | * Note: By default, get() attempts to provide up-to-date data when possible
|
9018 | * by waiting for data from the server, but it may return cached data or fail
|
9019 | * if you are offline and the server cannot be reached. This behavior can be
|
9020 | * altered via the `GetOptions` parameter.
|
9021 | *
|
9022 | * @param options An object to configure the get behavior.
|
9023 | * @return A Promise that will be resolved with the results of the Query.
|
9024 | */
|
9025 | get(options?: GetOptions): Promise<QuerySnapshot<T>>;
|
9026 |
|
9027 | /**
|
9028 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9029 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9030 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9031 | * calling the function that is returned when `onSnapshot` is called.
|
9032 | *
|
9033 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9034 | * never be called because the snapshot stream is never-ending.
|
9035 | *
|
9036 | * @param observer A single object containing `next` and `error` callbacks.
|
9037 | * @return An unsubscribe function that can be called to cancel
|
9038 | * the snapshot listener.
|
9039 | */
|
9040 | onSnapshot(observer: {
|
9041 | next?: (snapshot: QuerySnapshot<T>) => void;
|
9042 | error?: (error: Error) => void;
|
9043 | complete?: () => void;
|
9044 | }): () => void;
|
9045 | /**
|
9046 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9047 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9048 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9049 | * calling the function that is returned when `onSnapshot` is called.
|
9050 | *
|
9051 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9052 | * never be called because the snapshot stream is never-ending.
|
9053 | *
|
9054 | * @param options Options controlling the listen behavior.
|
9055 | * @param observer A single object containing `next` and `error` callbacks.
|
9056 | * @return An unsubscribe function that can be called to cancel
|
9057 | * the snapshot listener.
|
9058 | */
|
9059 | onSnapshot(
|
9060 | options: SnapshotListenOptions,
|
9061 | observer: {
|
9062 | next?: (snapshot: QuerySnapshot<T>) => void;
|
9063 | error?: (error: Error) => void;
|
9064 | complete?: () => void;
|
9065 | }
|
9066 | ): () => void;
|
9067 | /**
|
9068 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9069 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9070 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9071 | * calling the function that is returned when `onSnapshot` is called.
|
9072 | *
|
9073 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9074 | * never be called because the snapshot stream is never-ending.
|
9075 | *
|
9076 | * @param onNext A callback to be called every time a new `QuerySnapshot`
|
9077 | * is available.
|
9078 | * @param onError A callback to be called if the listen fails or is
|
9079 | * cancelled. No further callbacks will occur.
|
9080 | * @return An unsubscribe function that can be called to cancel
|
9081 | * the snapshot listener.
|
9082 | */
|
9083 | onSnapshot(
|
9084 | onNext: (snapshot: QuerySnapshot<T>) => void,
|
9085 | onError?: (error: Error) => void,
|
9086 | onCompletion?: () => void
|
9087 | ): () => void;
|
9088 | /**
|
9089 | * Attaches a listener for QuerySnapshot events. You may either pass
|
9090 | * individual `onNext` and `onError` callbacks or pass a single observer
|
9091 | * object with `next` and `error` callbacks. The listener can be cancelled by
|
9092 | * calling the function that is returned when `onSnapshot` is called.
|
9093 | *
|
9094 | * NOTE: Although an `onCompletion` callback can be provided, it will
|
9095 | * never be called because the snapshot stream is never-ending.
|
9096 | *
|
9097 | * @param options Options controlling the listen behavior.
|
9098 | * @param onNext A callback to be called every time a new `QuerySnapshot`
|
9099 | * is available.
|
9100 | * @param onError A callback to be called if the listen fails or is
|
9101 | * cancelled. No further callbacks will occur.
|
9102 | * @return An unsubscribe function that can be called to cancel
|
9103 | * the snapshot listener.
|
9104 | */
|
9105 | onSnapshot(
|
9106 | options: SnapshotListenOptions,
|
9107 | onNext: (snapshot: QuerySnapshot<T>) => void,
|
9108 | onError?: (error: Error) => void,
|
9109 | onCompletion?: () => void
|
9110 | ): () => void;
|
9111 |
|
9112 | /**
|
9113 | * Applies a custom data converter to this Query, allowing you to use your
|
9114 | * own custom model objects with Firestore. When you call get() on the
|
9115 | * returned Query, the provided converter will convert between Firestore
|
9116 | * data and your custom type U.
|
9117 | *
|
9118 | * @param converter Converts objects to and from Firestore.
|
9119 | * @return A Query<U> that uses the provided converter.
|
9120 | */
|
9121 | withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
|
9122 | }
|
9123 |
|
9124 | /**
|
9125 | * A `QuerySnapshot` contains zero or more `DocumentSnapshot` objects
|
9126 | * representing the results of a query. The documents can be accessed as an
|
9127 | * array via the `docs` property or enumerated using the `forEach` method. The
|
9128 | * number of documents can be determined via the `empty` and `size`
|
9129 | * properties.
|
9130 | */
|
9131 | export class QuerySnapshot<T = DocumentData> {
|
9132 | private constructor();
|
9133 |
|
9134 | /**
|
9135 | * The query on which you called `get` or `onSnapshot` in order to get this
|
9136 | * `QuerySnapshot`.
|
9137 | */
|
9138 | readonly query: Query<T>;
|
9139 | /**
|
9140 | * Metadata about this snapshot, concerning its source and if it has local
|
9141 | * modifications.
|
9142 | */
|
9143 | readonly metadata: SnapshotMetadata;
|
9144 |
|
9145 | /** An array of all the documents in the `QuerySnapshot`. */
|
9146 | readonly docs: Array<QueryDocumentSnapshot<T>>;
|
9147 |
|
9148 | /** The number of documents in the `QuerySnapshot`. */
|
9149 | readonly size: number;
|
9150 |
|
9151 | /** True if there are no documents in the `QuerySnapshot`. */
|
9152 | readonly empty: boolean;
|
9153 |
|
9154 | /**
|
9155 | * Returns an array of the documents changes since the last snapshot. If this
|
9156 | * is the first snapshot, all documents will be in the list as added changes.
|
9157 | *
|
9158 | * @param options `SnapshotListenOptions` that control whether metadata-only
|
9159 | * changes (i.e. only `DocumentSnapshot.metadata` changed) should trigger
|
9160 | * snapshot events.
|
9161 | */
|
9162 | docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
|
9163 |
|
9164 | /**
|
9165 | * Enumerates all of the documents in the `QuerySnapshot`.
|
9166 | *
|
9167 | * @param callback A callback to be called with a `QueryDocumentSnapshot` for
|
9168 | * each document in the snapshot.
|
9169 | * @param thisArg The `this` binding for the callback.
|
9170 | */
|
9171 | forEach(
|
9172 | callback: (result: QueryDocumentSnapshot<T>) => void,
|
9173 | thisArg?: any
|
9174 | ): void;
|
9175 |
|
9176 | /**
|
9177 | * Returns true if this `QuerySnapshot` is equal to the provided one.
|
9178 | *
|
9179 | * @param other The `QuerySnapshot` to compare against.
|
9180 | * @return true if this `QuerySnapshot` is equal to the provided one.
|
9181 | */
|
9182 | isEqual(other: QuerySnapshot<T>): boolean;
|
9183 | }
|
9184 |
|
9185 | /**
|
9186 | * The type of a `DocumentChange` may be 'added', 'removed', or 'modified'.
|
9187 | */
|
9188 | export type DocumentChangeType = 'added' | 'removed' | 'modified';
|
9189 |
|
9190 | /**
|
9191 | * A `DocumentChange` represents a change to the documents matching a query.
|
9192 | * It contains the document affected and the type of change that occurred.
|
9193 | */
|
9194 | export interface DocumentChange<T = DocumentData> {
|
9195 | /** The type of change ('added', 'modified', or 'removed'). */
|
9196 | readonly type: DocumentChangeType;
|
9197 |
|
9198 | /** The document affected by this change. */
|
9199 | readonly doc: QueryDocumentSnapshot<T>;
|
9200 |
|
9201 | /**
|
9202 | * The index of the changed document in the result set immediately prior to
|
9203 | * this `DocumentChange` (i.e. supposing that all prior `DocumentChange` objects
|
9204 | * have been applied). Is -1 for 'added' events.
|
9205 | */
|
9206 | readonly oldIndex: number;
|
9207 |
|
9208 | /**
|
9209 | * The index of the changed document in the result set immediately after
|
9210 | * this `DocumentChange` (i.e. supposing that all prior `DocumentChange`
|
9211 | * objects and the current `DocumentChange` object have been applied).
|
9212 | * Is -1 for 'removed' events.
|
9213 | */
|
9214 | readonly newIndex: number;
|
9215 | }
|
9216 |
|
9217 | /**
|
9218 | * A `CollectionReference` object can be used for adding documents, getting
|
9219 | * document references, and querying for documents (using the methods
|
9220 | * inherited from `Query`).
|
9221 | */
|
9222 | export class CollectionReference<T = DocumentData> extends Query<T> {
|
9223 | private constructor();
|
9224 |
|
9225 | /** The collection's identifier. */
|
9226 | readonly id: string;
|
9227 |
|
9228 | /**
|
9229 | * A reference to the containing `DocumentReference` if this is a subcollection.
|
9230 | * If this isn't a subcollection, the reference is null.
|
9231 | */
|
9232 | readonly parent: DocumentReference<DocumentData> | null;
|
9233 |
|
9234 | /**
|
9235 | * A string representing the path of the referenced collection (relative
|
9236 | * to the root of the database).
|
9237 | */
|
9238 | readonly path: string;
|
9239 |
|
9240 | /**
|
9241 | * Get a `DocumentReference` for the document within the collection at the
|
9242 | * specified path. If no path is specified, an automatically-generated
|
9243 | * unique ID will be used for the returned DocumentReference.
|
9244 | *
|
9245 | * @param documentPath A slash-separated path to a document.
|
9246 | * @return The `DocumentReference` instance.
|
9247 | */
|
9248 | doc(documentPath?: string): DocumentReference<T>;
|
9249 |
|
9250 | /**
|
9251 | * Add a new document to this collection with the specified data, assigning
|
9252 | * it a document ID automatically.
|
9253 | *
|
9254 | * @param data An Object containing the data for the new document.
|
9255 | * @return A Promise resolved with a `DocumentReference` pointing to the
|
9256 | * newly created document after it has been written to the backend.
|
9257 | */
|
9258 | add(data: T): Promise<DocumentReference<T>>;
|
9259 |
|
9260 | /**
|
9261 | * Returns true if this `CollectionReference` is equal to the provided one.
|
9262 | *
|
9263 | * @param other The `CollectionReference` to compare against.
|
9264 | * @return true if this `CollectionReference` is equal to the provided one.
|
9265 | */
|
9266 | isEqual(other: CollectionReference<T>): boolean;
|
9267 |
|
9268 | /**
|
9269 | * Applies a custom data converter to this CollectionReference, allowing you
|
9270 | * to use your own custom model objects with Firestore. When you call add()
|
9271 | * on the returned CollectionReference instance, the provided converter will
|
9272 | * convert between Firestore data and your custom type U.
|
9273 | *
|
9274 | * @param converter Converts objects to and from Firestore.
|
9275 | * @return A CollectionReference<U> that uses the provided converter.
|
9276 | */
|
9277 | withConverter<U>(
|
9278 | converter: FirestoreDataConverter<U>
|
9279 | ): CollectionReference<U>;
|
9280 | }
|
9281 |
|
9282 | /**
|
9283 | * Sentinel values that can be used when writing document fields with `set()`
|
9284 | * or `update()`.
|
9285 | */
|
9286 | export class FieldValue {
|
9287 | private constructor();
|
9288 |
|
9289 | /**
|
9290 | * Returns a sentinel used with `set()` or `update()` to include a
|
9291 | * server-generated timestamp in the written data.
|
9292 | */
|
9293 | static serverTimestamp(): FieldValue;
|
9294 |
|
9295 | /**
|
9296 | * Returns a sentinel for use with `update()` to mark a field for deletion.
|
9297 | */
|
9298 | static delete(): FieldValue;
|
9299 |
|
9300 | /**
|
9301 | * Returns a special value that can be used with `set()` or `update()` that tells
|
9302 | * the server to union the given elements with any array value that already
|
9303 | * exists on the server. Each specified element that doesn't already exist in
|
9304 | * the array will be added to the end. If the field being modified is not
|
9305 | * already an array it will be overwritten with an array containing exactly
|
9306 | * the specified elements.
|
9307 | *
|
9308 | * @param elements The elements to union into the array.
|
9309 | * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
|
9310 | */
|
9311 | static arrayUnion(...elements: any[]): FieldValue;
|
9312 |
|
9313 | /**
|
9314 | * Returns a special value that can be used with `set()` or `update()` that tells
|
9315 | * the server to remove the given elements from any array value that already
|
9316 | * exists on the server. All instances of each element specified will be
|
9317 | * removed from the array. If the field being modified is not already an
|
9318 | * array it will be overwritten with an empty array.
|
9319 | *
|
9320 | * @param elements The elements to remove from the array.
|
9321 | * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
|
9322 | */
|
9323 | static arrayRemove(...elements: any[]): FieldValue;
|
9324 |
|
9325 | /**
|
9326 | * Returns a special value that can be used with `set()` or `update()` that tells
|
9327 | * the server to increment the field's current value by the given value.
|
9328 | *
|
9329 | * If either the operand or the current field value uses floating point precision,
|
9330 | * all arithmetic follows IEEE 754 semantics. If both values are integers,
|
9331 | * values outside of JavaScript's safe number range (`Number.MIN_SAFE_INTEGER` to
|
9332 | * `Number.MAX_SAFE_INTEGER`) are also subject to precision loss. Furthermore,
|
9333 | * once processed by the Firestore backend, all integer operations are capped
|
9334 | * between -2^63 and 2^63-1.
|
9335 | *
|
9336 | * If the current field value is not of type `number`, or if the field does not
|
9337 | * yet exist, the transformation sets the field to the given value.
|
9338 | *
|
9339 | * @param n The value to increment by.
|
9340 | * @return The FieldValue sentinel for use in a call to `set()` or `update()`.
|
9341 | */
|
9342 | static increment(n: number): FieldValue;
|
9343 |
|
9344 | /**
|
9345 | * Returns true if this `FieldValue` is equal to the provided one.
|
9346 | *
|
9347 | * @param other The `FieldValue` to compare against.
|
9348 | * @return true if this `FieldValue` is equal to the provided one.
|
9349 | */
|
9350 | isEqual(other: FieldValue): boolean;
|
9351 | }
|
9352 |
|
9353 | /**
|
9354 | * A FieldPath refers to a field in a document. The path may consist of a
|
9355 | * single field name (referring to a top-level field in the document), or a
|
9356 | * list of field names (referring to a nested field in the document).
|
9357 | *
|
9358 | * Create a FieldPath by providing field names. If more than one field
|
9359 | * name is provided, the path will point to a nested field in a document.
|
9360 | *
|
9361 | */
|
9362 | export class FieldPath {
|
9363 | /**
|
9364 | * Creates a FieldPath from the provided field names. If more than one field
|
9365 | * name is provided, the path will point to a nested field in a document.
|
9366 | *
|
9367 | * @param fieldNames A list of field names.
|
9368 | */
|
9369 | constructor(...fieldNames: string[]);
|
9370 |
|
9371 | /**
|
9372 | * Returns a special sentinel `FieldPath` to refer to the ID of a document.
|
9373 | * It can be used in queries to sort or filter by the document ID.
|
9374 | */
|
9375 | static documentId(): FieldPath;
|
9376 |
|
9377 | /**
|
9378 | * Returns true if this `FieldPath` is equal to the provided one.
|
9379 | *
|
9380 | * @param other The `FieldPath` to compare against.
|
9381 | * @return true if this `FieldPath` is equal to the provided one.
|
9382 | */
|
9383 | isEqual(other: FieldPath): boolean;
|
9384 | }
|
9385 |
|
9386 | /**
|
9387 | * The set of Firestore status codes. The codes are the same at the ones
|
9388 | * exposed by gRPC here:
|
9389 | * https://github.com/grpc/grpc/blob/master/doc/statuscodes.md
|
9390 | *
|
9391 | * Possible values:
|
9392 | * - 'cancelled': The operation was cancelled (typically by the caller).
|
9393 | * - 'unknown': Unknown error or an error from a different error domain.
|
9394 | * - 'invalid-argument': Client specified an invalid argument. Note that this
|
9395 | * differs from 'failed-precondition'. 'invalid-argument' indicates
|
9396 | * arguments that are problematic regardless of the state of the system
|
9397 | * (e.g. an invalid field name).
|
9398 | * - 'deadline-exceeded': Deadline expired before operation could complete.
|
9399 | * For operations that change the state of the system, this error may be
|
9400 | * returned even if the operation has completed successfully. For example,
|
9401 | * a successful response from a server could have been delayed long enough
|
9402 | * for the deadline to expire.
|
9403 | * - 'not-found': Some requested document was not found.
|
9404 | * - 'already-exists': Some document that we attempted to create already
|
9405 | * exists.
|
9406 | * - 'permission-denied': The caller does not have permission to execute the
|
9407 | * specified operation.
|
9408 | * - 'resource-exhausted': Some resource has been exhausted, perhaps a
|
9409 | * per-user quota, or perhaps the entire file system is out of space.
|
9410 | * - 'failed-precondition': Operation was rejected because the system is not
|
9411 | * in a state required for the operation's execution.
|
9412 | * - 'aborted': The operation was aborted, typically due to a concurrency
|
9413 | * issue like transaction aborts, etc.
|
9414 | * - 'out-of-range': Operation was attempted past the valid range.
|
9415 | * - 'unimplemented': Operation is not implemented or not supported/enabled.
|
9416 | * - 'internal': Internal errors. Means some invariants expected by
|
9417 | * underlying system has been broken. If you see one of these errors,
|
9418 | * something is very broken.
|
9419 | * - 'unavailable': The service is currently unavailable. This is most likely
|
9420 | * a transient condition and may be corrected by retrying with a backoff.
|
9421 | * - 'data-loss': Unrecoverable data loss or corruption.
|
9422 | * - 'unauthenticated': The request does not have valid authentication
|
9423 | * credentials for the operation.
|
9424 | */
|
9425 | export type FirestoreErrorCode =
|
9426 | | 'cancelled'
|
9427 | | 'unknown'
|
9428 | | 'invalid-argument'
|
9429 | | 'deadline-exceeded'
|
9430 | | 'not-found'
|
9431 | | 'already-exists'
|
9432 | | 'permission-denied'
|
9433 | | 'resource-exhausted'
|
9434 | | 'failed-precondition'
|
9435 | | 'aborted'
|
9436 | | 'out-of-range'
|
9437 | | 'unimplemented'
|
9438 | | 'internal'
|
9439 | | 'unavailable'
|
9440 | | 'data-loss'
|
9441 | | 'unauthenticated';
|
9442 |
|
9443 | /** An error returned by a Firestore operation. */
|
9444 | // TODO(b/63008957): FirestoreError should extend firebase.FirebaseError
|
9445 | export interface FirestoreError {
|
9446 | code: FirestoreErrorCode;
|
9447 | message: string;
|
9448 | name: string;
|
9449 | stack?: string;
|
9450 | }
|
9451 | }
|
9452 |
|
9453 | export = firebase;
|
9454 | export as namespace firebase;
|
9455 |
|
\ | No newline at end of file |